Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3677112imc; Thu, 14 Mar 2019 02:44:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+GaKJtZLu0/d2mtYYnFF2VHBP/4jrKAUXLvg+tTw9p15Ap3ZQuLmarstiJK5LDVIMp1z2 X-Received: by 2002:a17:902:aa87:: with SMTP id d7mr48652447plr.146.1552556652958; Thu, 14 Mar 2019 02:44:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552556652; cv=none; d=google.com; s=arc-20160816; b=T0mPzP55lrug7sYfOGXKFANxvPbQYdJbQkZtrotSvwq4e4KXAAEmjpTN7qVkjVy5Uz xTXe2ccSNUk0PyhTV7Q982o7yXlgi2vUigRy1+IIih3QkqDspfcU/MhogaV7GNnZwGbl JdCNjukRWvbHnjx5PtXMZCgUJcGShLyC5SIp3XSM626SkM4z1tM1Wwyy76a+25JipWcX agPijblp8yOZzdEF0CiHdpdgE+Zy5YEKsrwehu/K7d9wfNMSTjmO9wsN+TrXMNbzQF73 2kEM2cd85yAk1JzJgGYEwg5MHNvE8qRfS1rqcKYc2W1y7poY+XYmds/E+FMg4X487mvN Q3og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:cc:subject:to :message-id:from:date; bh=9TqtBDF4LUg/TAt3IsZfeZ4XdFwd6dO7wZJ6KmPCuI8=; b=A7IDQl94jDbkNogPUx05/fjAnwLx5ZwYOjHh3RrYMEg0kbVK4p59xeRvNRIPl5kpGI 62+QjeQXdSXjhQ4Twczo+YnOh+9pwIJsnLPtn48Ip8HDp32w9scI43KMtjQl7iwn/Au3 xmmMabm7/YMAiHhwiohcH6/EaUXc08tRHmeIMCDfatCLl5iYKRQDUQEOrX/r/fcR9+HI 5qBsQ1iHKgjxvs6uTBLCt+0kU0Q9liQqfu9LFPLi5QMtQ3d3tnPUY2Upoc1RqagpCGKA vrl9pjqUcFzx6fzOcBvxfId/AHXJGFNpD0SpeudCQuZRBW4VakVWci70F6UHbfMkcqgM AiQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 193si11992162pga.251.2019.03.14.02.43.57; Thu, 14 Mar 2019 02:44:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbfCNJl7 (ORCPT + 99 others); Thu, 14 Mar 2019 05:41:59 -0400 Received: from mx.sdf.org ([205.166.94.20]:56252 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbfCNJl7 (ORCPT ); Thu, 14 Mar 2019 05:41:59 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id x2E9ffC2017873 (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO); Thu, 14 Mar 2019 09:41:41 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id x2E9ffkx024340; Thu, 14 Mar 2019 09:41:41 GMT Date: Thu, 14 Mar 2019 09:41:41 GMT From: George Spelvin Message-Id: <201903140941.x2E9ffkx024340@sdf.org> To: andriy.shevchenko@linux.intel.com, lkml@sdf.org Subject: Re: [PATCH 4/5] lib/list_sort: Simplify and remove MAX_LIST_LENGTH_BITS Cc: akpm@linux-foundation.org, daniel.wagner@siemens.com, dchinner@redhat.com, don.mullis@gmail.com, geert@linux-m68k.org, linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk, st5pub@yandex.ru In-Reply-To: <20190314091041.GU9224@smile.fi.intel.com> References: , , <20190314091041.GU9224@smile.fi.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 14 Mar 2019 at 11:10:41 +0200, Andy Shevchenko wrote: > On Tue, Mar 05, 2019 at 03:06:44AM +0000, George Spelvin wrote: >> + /* Do merges corresponding to set lsbits in count */ > >> + for (bit = 1; count & bit; bit <<= 1) { >> + cur = merge(priv, (cmp_func)cmp, pending, cur); >> + pending = pending->prev; /* Untouched by merge() */ >> } > > Wouldn't be it the same to > > bit = ffz(count); > while (bit--) { > ... > } > ? > > Though I dunno which one is generating better code. Yes, it's the same. But count is an incrementing counter, so the pattern of return values from ffz() is 01020103010201040102010301020105..., which has mean value 1/2 + 1/4 + 1/8 + 1/16 +... = 1. So spending one instruction on ffz() to save one instruction per loop iteration is an even trade, and if the processor doesn't have an ffz() instruction, it's a loss. There's a third possible implementation: >> + for (bit = count; bit & 1; bit >>= 1) { ...which works fine, too. (It even saves a few bytes of code, so I might switch to it.) I used the form I did because my test code verified that the length of the lists being merged equalled "bit". The other forms don't have that property. Thank you for looking at the code!