Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3695874imc; Thu, 14 Mar 2019 03:13:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzDhZTw2pliRpakoANRIBwyPxdg1uh0gishw/N2lTg7eBanlqqmrDPPmPfVGOlNuizM23x X-Received: by 2002:a17:902:be02:: with SMTP id r2mr51316000pls.209.1552558397431; Thu, 14 Mar 2019 03:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552558397; cv=none; d=google.com; s=arc-20160816; b=nf+6xxf140p6yh8JMGWb2TVgXm7bngJq8K6c5SUEpuC8JemrcE7RY4lFrzm3JeZQ0A PZcoeCXjuQJMLzjsRTD/LvizISLBTpeZlWcSHtiAFxPWWsza7FObYo3zhwlQTJdCAuBo BnqCV0IisUTFMfALSW1cv45dpz6uRZhHoE1byX5nfkOXxNerD0keoQVfE5xN4yowupwF ikwotaf1ZqkFP8DdTfNOftxIFRdDh9dIycK7bjR5LuoPqYGCRHmooxeOvM6q+GipW5hQ v4x2mkYVEsTtPOl/e/UheN6eI5NoGiAhy9HqBPzFGkLqJ9xHCxq/hIFFRtzBIgL01DAl 8mIA== 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=Ve53wcQKpD7I5DqUKRhciBhY1Xetrv/u99ZfZP8cX4A=; b=NksN5TEnLDSLgV41kLxMqVlxodMTXJykMJ8l8h5/mcFKtg1A4uyXE//syFhmyRNeyT 22RghtMTZIhbcZtFe+4vKeC9OXXRUFLZoh4xog5ZIEZHaLZw0z0cUWVzhYkjGGJTdEXN AYP5YER3k82QSY4NSssqF58iM8qQgfcZj7aBvqLKXUuoRHmaiLFD2zJSFlhBjJEtnoUR 4b+jP8TnkgDeI4ryACy1rrFv1G9RqAEXBHkuH9aVfbFUf78k5uDqKcdo0UimVRkmaMf4 BfKbvh9lOv8amLxIO7lM3YhqofXbFTlc1paeqZ/9K3sdW33YRVgXpZpHrY2skicujlJA hHUA== 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 n19si12298277pff.18.2019.03.14.03.13.02; Thu, 14 Mar 2019 03:13:17 -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 S1727115AbfCNKLW (ORCPT + 99 others); Thu, 14 Mar 2019 06:11:22 -0400 Received: from ol.sdf.org ([205.166.94.20]:49214 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbfCNKLW (ORCPT ); Thu, 14 Mar 2019 06:11:22 -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 x2EA9rGt024533 (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits) verified NO); Thu, 14 Mar 2019 10:09:53 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id x2EA9q1Z025888; Thu, 14 Mar 2019 10:09:52 GMT Date: Thu, 14 Mar 2019 10:09:52 GMT From: George Spelvin Message-Id: <201903141009.x2EA9q1Z025888@sdf.org> To: 13@sdf.org, andriy.shevchenko@linux.intel.com, lkml@sdf.org, st5pub@yandex.ru Subject: Re: [PATCH 1/5] lib/sort: Make swap functions more generic 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 In-Reply-To: <20190314092958.GV9224@smile.fi.intel.com> References: , , <20190309140653.GO9224@smile.fi.intel.com>, <201903091553.x29FrfMR018600@sdf.org>, <20190314092958.GV9224@smile.fi.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 09 Mar 2019 at 23:19:49 +0300, Andrey Abramov wrote: >> Although I'm thinking of: >> >> static bool __attribute_const__ >> is_aligned(const void *base, size_t size, unsigned char align) >> { >> unsigned char lsbits = (unsigned char)size; >> >> (void)base; >> #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >> lsbits |= (unsigned char)(uintptr_t)base; >> #endif >> return (lsbits & (align - 1)) == 0; >> } >> >> Any preference? > I think it would be better. >> I find "u32s" confusing; I keep reading the "s" as "signed" rather >> than a plural. >> >> How about one of: >> swap_bytes / swap_ints / swap_longs >> swap_1 / swap_4 / swap_8 > > In my opinion "swap_bytes / swap_ints / swap_longs" are the most readable. On Thu, 14 Mar 2019 at 11:29:58 +0200, Andy Shevchenko wrote: > On Sat, Mar 09, 2019 at 03:53:41PM +0000, lkml@sdf.org wrote: >> static bool __attribute_const__ >> is_aligned(const void *base, size_t size, unsigned char align) >> { >> unsigned char lsbits = (unsigned char)size; >> #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >> (void)base; >> #else >> lsbits |= (unsigned char)(uintptr_t)base; >> #endif >> return (lsbits & (align - 1)) == 0; >> } > >> Any preference? > > This one looks better in a sense we don't suppress the warnings when it's > not needed. >>> For such primitives that operates on top of an arrays we usually >>> append 's' to the name. Currently the name is misleading. >>> >>> Perhaps u32s_swap(). >> >> I don't worry much about the naming of static helper functions. >> If they were exported, it would be a whole lot more important! >> >> I find "u32s" confusing; I keep reading the "s" as "signed" rather >> than a plural. > > For signedness we use prefixes; for plural, suffixes. I don't see the point of > confusion. And this is in use in kernel a lot. > >> How about one of: >> swap_bytes / swap_ints / swap_longs >> swap_1 / swap_4 / swap_8 > > longs are ambiguous, so I would prefer bit-sized types. I already implemented Andrey's suggestions, which were the exact opposite of yours. Pistols at dawn? >>>> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >>> >>> Why #ifdef is better than if (IS_ENABLED()) ? >> >> Because CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is bool and not >> tristate. IS_ENABLED tests for 'y' or 'm' but we don't need it >> for something that's only on or off. > > There is IS_BUILTIN(), though it's a common practice to use IS_ENABLED() > even for boolean options (I think because of naming of the macro). Well, as I said earlier, #ifdef is the most common form in the kernel. It's also the shortest to write, and I like the fact that it slightly simpler. (Admittedly, "IS_ENABLED" does not take a lot of brain power to interpret, but it *is* one more macro that might be hiding magic.) So I'm not inclined to change it without a substantial reason.