Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1199551ybi; Fri, 21 Jun 2019 16:12:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOCZL552h6zbGI7I48AK4We9lFjs8fveQl+Qyvp1O89JS3FFgwldwGLstk9zeCayuGVcIP X-Received: by 2002:a17:90a:1904:: with SMTP id 4mr9985767pjg.116.1561158747196; Fri, 21 Jun 2019 16:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561158747; cv=none; d=google.com; s=arc-20160816; b=t1I+AsancKvc+OxfgsJy8R5j0YcPf9EWQ5qPVY5SThQA4XeZiKKai+8PNrLziBTjtg YR++aSbller+7yn8Zj7Suu6vIGu4zzBVYEG9xatutoJ9y+3MFKHkX95UMdnN40K2JnhE B+S7hiGl5buJfCFjJ1NMzRRvqEuorbkUqQHYwO4qJZHI2WtDyTBSLW8yrvh7xfSW5uLV fy973ou35YX/GnkQCC4u0yuqv6BacUYWzkY/dS06By6b6oQjP2uM3Lue1/7uO/0tlFE6 MTdJaj8i9XJBufjZTLWarPtm0Qm5E0zdW1uovCjzogQo5gMzzXdVXdW4ftkRz26P69xo uzPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Z7H6a9bx7122AU0Rz3Jd1mJYrH5GHmxQkIx46qhAJi8=; b=DFAHa1cHs79LEk7GkZW116yPxNivgh+ZBYsbU0aU+2LP97opYCIejA1cO/oTSkotqG vpoFc8HgMm7pVSzQuQE9sa5LcPQ6JHx1RTbv1Qn8dbkjisBjNwaY3FnlMA22+k/dNr18 rZ+5wUGmn/O9aGtms2s4XtHoX+5w0VIzD4unw77Slr67zQtFdEWbuQSDr+RWsv2+hHXV 6zBdSPSEzT4jA28ACS1sLqA2k53K7+tzG3/ETWM0/aH3npNM5QxPp+lcPQ2qrli/G44y NhEnXWAZ/yoqeTd3mdy5I+9AI9dbD9FG/uGRq7fsqciEpmdkbxIG4V2vnE+qWQnw5ry5 MnOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=cutYK3bz; 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 n75si4022345pjc.27.2019.06.21.16.12.11; Fri, 21 Jun 2019 16:12:27 -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; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=cutYK3bz; 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 S1726083AbfFUXMI (ORCPT + 99 others); Fri, 21 Jun 2019 19:12:08 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37960 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbfFUXMH (ORCPT ); Fri, 21 Jun 2019 19:12:07 -0400 Received: by mail-lj1-f194.google.com with SMTP id r9so7347874ljg.5 for ; Fri, 21 Jun 2019 16:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Z7H6a9bx7122AU0Rz3Jd1mJYrH5GHmxQkIx46qhAJi8=; b=cutYK3bz4LqR37UCsAWgVrci6+untrhnnylnM73QR5W5hmgHX6RyqMYhVDD29TVCly sX0Z55mTs6Ar1kP7gF5rxfOBxzyWpJMjoTTmaJHgiN5q/KCrz8fpGkQeRiU4RjbIWx66 Izlz54YQatpYGfjVwfAESk9b6zdhQZPnGvOuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Z7H6a9bx7122AU0Rz3Jd1mJYrH5GHmxQkIx46qhAJi8=; b=ix8Wwwo+azU1IgYS3o5eG5nUsPh6AIPtRY3gw5tXRRy0OdKU11rfBMizj8uO9fcTrY WWrtA4UYrB7Ms54KUqr/F2IFhKkoIoAPEfuCxXKIwLfrmzZFq8Jt/dP1iaCZyAbrEe3J wye8bDc+1v+4bhHI8Zr9dIL5l8irwPya5G8WL0Gnsv/kDR0Yv0fwIBY+zgnicZwawtxW uy67nfudF0WEa5lrU0HfwVi0Uj4F6A74v9Qw1vDl51d061rKjd+wgFe9JIoBlYYZybwr pIqvUKHyH53qBKFtQt6jU9mk8F3F3+D55elD/e4/sONeVVV/uiL4ZvJ3Hr7YR89nrtna P5FA== X-Gm-Message-State: APjAAAU+iYTe8O6ihkfSPXI9gQx+iuWmRVU4Y8YAHA+/4ywWjJdNpvCG 33EMVvVFMMGTHBrCN+rf93t/hA== X-Received: by 2002:a2e:96c3:: with SMTP id d3mr12335414ljj.68.1561158725211; Fri, 21 Jun 2019 16:12:05 -0700 (PDT) Received: from [192.168.1.149] (ip-5-186-113-204.cgn.fibianet.dk. [5.186.113.204]) by smtp.gmail.com with ESMTPSA id w28sm579398ljd.12.2019.06.21.16.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Jun 2019 16:12:03 -0700 (PDT) Subject: Re: [PATCH 5/5] lib/list_sort: Optimize number of calls to comparison function To: George Spelvin , linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, daniel.wagner@siemens.com, dchinner@redhat.com, don.mullis@gmail.com, geert@linux-m68k.org, st5pub@yandex.ru References: <201903140158.x2E1wgFQ018649@sdf.org> From: Rasmus Villemoes Message-ID: Date: Sat, 22 Jun 2019 01:12:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <201903140158.x2E1wgFQ018649@sdf.org> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/03/2019 02.58, George Spelvin wrote: > On Thu, 14 Mar 2019 at 00:28:16 +0100, Rasmus Villemoes wrote: >> Similarly one could do a SORT_SIMPLE_CMP() for when sorting an array of >> structs according to a single numeric member. That sort is not stable, >> so the comparison functions would have to do a full -1,0,1 return, of >> course, but we'd still avoid indirect calls. > > Actually, while some sorts (notably fat-pivot quicksort) require > a 3-way return to avoid O(n^2) performance, heapsort is just fine > with a boolean return value. Hi George So I tried starting to implement this, and the timing results look promising. However, currently I'm doing (*(u32*)ka > *(u32*)kb) - (*(u32*)ka < *(u32*)kb); in my do_cmp. Both existing invocations of the comparison function in sort.c compare its return value >= 0, which is always true if I just return the boolean (*(u32*)ka > *(u32*)kb). So it seems the algorithm would have to be changed to allow the cmp function to return a bool. Perhaps it's as simple as changing the two >= to >, but can I get you to check that that would be ok? (Quick testing seems to suggest so, but it's possible there are some corner cases where it would break.) Thanks, Rasmus