Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp273950pxb; Wed, 25 Aug 2021 02:58:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz11yvz4xAnhMAEzAgK2gRA5fIitrkXPWqQ7jef59HMyoCEe7eEoAoSmqjJyS3jsp+ui6P8 X-Received: by 2002:a05:6402:1c1e:: with SMTP id ck30mr753527edb.103.1629885531687; Wed, 25 Aug 2021 02:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629885531; cv=none; d=google.com; s=arc-20160816; b=QcMCL9PODpZECMRvd7Q7+qTdnwMFDjKxXDGtLnSoqD4ZK2PKY7CNRWmPZKZfEdV1ia jsmx5hKWEm+4KDFZiH19CTYMN5YcyU4yfw6cyQZkWY18no3pBYVFxXc57gEd0va59QDL 2xNELwjDuBCfxfS2KTWJjehud+/QB4ohqS3gCdJwGvXiDf6tQkrrS43iG4YOIUCHiccL CcJFmn0hqQY3/A5kNMdvIKtOqyoCgRFBEZqlk/CLkjxHNfteUiQJ8qWskiIcDS9KUVa7 tRibXGhTdCod8FNmuNSGUwVaFlzSNHpsT2XHZS6jtZ4qZ8c34mPPUNqV0pQCWxT4O4VD N4oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=HiFCz+wXlwpW6uRLJDurwjjCmjNHR6BjrnMVWxL3upU=; b=OxFmKXjLwVS/JQP8CRW1rNyXUyNxJg1JF2DisH+GPN6kp9iV5fEr8hedrA7QIP60kX TeEkb4CxEx2CdSsjCp1/mYiSGRd1VGv2OSqaEDSZZ9h48i/iVjeQPf9WF6q8XUSZwmqJ sBDdMnS3YzR4tKPEe/Y34r71Vjr/NSOu/nlHQd5qTEFTf1CJguQHBH2FlKSYZ1INUVJ5 LFWyvZhrEePF6ycoMGXsGpUVplJbjTp7OjzmGNsUPdk7JGdFcZGrcQ6KjzlJoFsGPst3 QYwrwAwKKLLrmhjGM0U6giAhpFzzjPSZ8mo98cgeo7pLJrEUfLUUmOT5sjPcbJ/1xOj9 0Mgg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s4si19647409eji.269.2021.08.25.02.58.28; Wed, 25 Aug 2021 02:58:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239769AbhHYJ4s (ORCPT + 99 others); Wed, 25 Aug 2021 05:56:48 -0400 Received: from mga07.intel.com ([134.134.136.100]:17563 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234372AbhHYJ4s (ORCPT ); Wed, 25 Aug 2021 05:56:48 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10086"; a="281207662" X-IronPort-AV: E=Sophos;i="5.84,350,1620716400"; d="scan'208";a="281207662" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2021 02:56:02 -0700 X-IronPort-AV: E=Sophos;i="5.84,350,1620716400"; d="scan'208";a="507952381" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2021 02:55:59 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1mIpdS-00DWAR-0Q; Wed, 25 Aug 2021 12:55:54 +0300 Date: Wed, 25 Aug 2021 12:55:53 +0300 From: Andy Shevchenko To: Rasmus Villemoes Cc: Sakari Ailus , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Yong Zhi , Bingbu Cao , Dan Scally , Tianshu Qiu , Mauro Carvalho Chehab Subject: Re: [PATCH v1 2/3] lib/sort: Introduce rotate() to circular shift an array of elements Message-ID: References: <20210824133351.88179-1-andriy.shevchenko@linux.intel.com> <20210824133351.88179-2-andriy.shevchenko@linux.intel.com> <4078b7a3-2ec2-ba87-d23c-b8daed7386fe@rasmusvillemoes.dk> <20210825080832.GN3@paasikivi.fi.intel.com> <8bc8d977-5204-6f5b-8a1c-f2338c141993@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8bc8d977-5204-6f5b-8a1c-f2338c141993@rasmusvillemoes.dk> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 25, 2021 at 11:29:12AM +0200, Rasmus Villemoes wrote: > On 25/08/2021 10.08, Sakari Ailus wrote: ... > Well, Andy hasn't actually shown that it would be useful anywhere else. > I think I'd like to see another user. I have found another potential user, but in their case (it's networking) the simple for-loop with swap() in use seems efficient enough (the element size is 8 bytes there). I haven't check for really custom implementations of entire rotate (where no swap() macro is in use), it might be another user lurking around. > Just doing "move this helper to > lib/ because we can reuse choose-a-proper-swap-func and thus implement > this perhaps a tiny bit faster" without considering whether it's even > performance-critical in the sole user is not a good idea IMO. I agree with you. > Especially since it can affect code generation of the much more > important (at least, has many more users) sort() function - the > do_swap() function grows another user, so could make the compiler end up > choosing not to inline it anymore. This can be fixed by always inlining? > There's another slightly simpler way to implement rotate(), which might > end up having more users (though I can't find any currently): Add a > reverse() helper, then rotate() can be done as reverse(a, 0, n); > reverse(a, 0, k); reverse(a, k, n-k);. If my math is right, the current > suggested rotate() ends up doing n-gcd(n,k) swaps, while the > implementation in terms of a reverse() would do n-1 if either n or k is > odd, otherwise n, calls to swap(). Interesting idea. And this, btw, may have more users per se. -- With Best Regards, Andy Shevchenko