Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2720490iog; Mon, 20 Jun 2022 03:19:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tuFq8nEvJmF76KNOcZ7PAy11R0VHh/bUPm7o4YKiulhtFwr3t3RznF586w/pptNke5qdC4 X-Received: by 2002:a05:6402:270a:b0:431:43f6:1e02 with SMTP id y10-20020a056402270a00b0043143f61e02mr28746293edd.317.1655720370303; Mon, 20 Jun 2022 03:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655720370; cv=none; d=google.com; s=arc-20160816; b=TdjA0L5tTMEpxZ7kddzC1r6oc9VauPHrk2nq0S0FRQPInfoSKYLBLkKMucYVrsXF0I rgLjRWbXBpK+izHp/Ron4ozT88g1a9cgAAfQwCBVoEU/Q0oTwCjBKW027GK7Cl3jD9vI vgoAZN0N8EwtyBZH08VGzCiS5UZH0s8+HeY593sIzKiPRmGW1Ii1IKxa1n/FdP80EWwp sNvyQIvQpr1vl+icCvI/FWr6JlMEzx823Wtw5+7PDeXIdkW5UPXXbHNbmNA9SNSJgNfc zvxb2G3dXm86pTYmQtauY0sXtUqqfTmRwKALDShmGhYRMMyrAsmRW/cQoX4oEpn3zxgL SiyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c5v3S7Zkd9PrYC84ZzumNRLfIqFWNrQTW2/cBzQcLYg=; b=bIrrQHIJI/Ub4i/xuEwTCQ8tuHBZelvNVFb3+J6A2+3pmDhEOJe36D1OnKs3nLbXBj jnalS5uNqt8NXLHGu7CMhoaOiEkOijC+RasXxqKLuTu9aUMPgNLBN5tlJ3inI55oSXf0 t4nOdfEdTdmA+py3eiKcEFyFzX1GHbNGhfVCEfx/laWnttybePtNXbquuNTJuXk77/7V laHHW9yehGrRz+1xKh/eg0E3iPFgifq0N8pA2i7ND7WzXVre9RevjLZRQNnynXc+LENl 6AcEMdhiklE91j+sLrl4EWuWv3kvuScdJWQ3sPB+wBnfFW3I+Ko1bYIFN7KWFFc4jyz5 3hDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mIpWvLd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i16-20020a05640242d000b004355878ad42si14483371edc.624.2022.06.20.03.19.03; Mon, 20 Jun 2022 03:19:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mIpWvLd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240012AbiFTJui (ORCPT + 99 others); Mon, 20 Jun 2022 05:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239904AbiFTJu3 (ORCPT ); Mon, 20 Jun 2022 05:50:29 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FEF013E05 for ; Mon, 20 Jun 2022 02:50:27 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-317741c86fdso92891247b3.2 for ; Mon, 20 Jun 2022 02:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c5v3S7Zkd9PrYC84ZzumNRLfIqFWNrQTW2/cBzQcLYg=; b=mIpWvLd42Zk3qDlC1lJPcvqz7M92/WQXcIoyM0LykA88iAo+rdgJDoHazph31kdSjO VUG7i/8HNZaOHLdu3N7nDqHPuwIY9fq9FvuOy2YX4EQM5bkG55ZAVqX3dyMqhKkf3Zrp wdgsnCqcf5yU/1gR7FrWP0Ud1NWBTI4TQjIzmZlty8pgPxfb7xHnM8DyqjB9t4bddRHR O64X//fr0z/4HxfkqMa1L+YEzzaQ9IobIbQsg9BgYcppkG2JYM76WtyvjDHFXlKlUAJ0 15NorsK1RaWXrUbZhIe7SdlsQlOhJzxaaCKzH9GSm4bD8dAmvyeOcvf0LOG2jFT9DYh9 yfrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c5v3S7Zkd9PrYC84ZzumNRLfIqFWNrQTW2/cBzQcLYg=; b=UfMptIEMgXfaLBobp2trlndR9vgFQ2mKyf80H6LtWdzf7A3CjZEwBDitguykSzgnpg UtwYox2zrQ7VSycu0IU9THAP8nZJLFMbLfcncMPaX+lD0iN5EohKG1ksJi7vQBhL7+Ug NQuDJ+HOHZXmdOtFf3Cak5S4SXfZyfsU5TImO4XL2nt/unguz9nwZjs9H/vDeKq+JnYs GvbwDz4rnP8yVQ2BUO/R7WQeffYkjEIHWO+lSXJbSouzy0xvcfAbXcIQcnvhgbdg7hmX opOCldzkKgu3XQNodQZVhVY5L3LJ7Bb1JeVsvOetDrgLmUDUXcL3KXLLYNShsfeIl/PG QXbA== X-Gm-Message-State: AJIora+GCVX8ObkTOYlXyuN9XWdE4wgZ0rAhVmZqI6egX1buL6wTOgUh RvINApoUiGHEToLq7SqDjvTOvpsBwdplFOjG2q/b0Q== X-Received: by 2002:a05:690c:681:b0:317:e92b:7f8d with SMTP id bp1-20020a05690c068100b00317e92b7f8dmr1282353ywb.264.1655718625831; Mon, 20 Jun 2022 02:50:25 -0700 (PDT) MIME-Version: 1.0 References: <20220617144031.2549432-1-alexandr.lobakin@intel.com> <20220617144031.2549432-5-alexandr.lobakin@intel.com> In-Reply-To: <20220617144031.2549432-5-alexandr.lobakin@intel.com> From: Marco Elver Date: Mon, 20 Jun 2022 11:49:50 +0200 Message-ID: Subject: Re: [PATCH v3 4/7] bitops: define const_*() versions of the non-atomics To: Alexander Lobakin Cc: Arnd Bergmann , Yury Norov , Andy Shevchenko , Mark Rutland , Matt Turner , Brian Cain , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , "David S. Miller" , Kees Cook , "Peter Zijlstra (Intel)" , Borislav Petkov , Tony Luck , Maciej Fijalkowski , Jesse Brandeburg , Greg Kroah-Hartman , linux-alpha@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Jun 2022 at 19:21, Alexander Lobakin wrote: > > Define const_*() variants of the non-atomic bitops to be used when > the input arguments are compile-time constants, so that the compiler > will be always able to resolve those to compile-time constants as > well. Those are mostly direct aliases for generic_*() with one > exception for const_test_bit(): the original one is declared > atomic-safe and thus doesn't discard the `volatile` qualifier, so > in order to let optimize code, define it separately disregarding > the qualifier. > Add them to the compile-time type checks as well just in case. > > Suggested-by: Marco Elver > Signed-off-by: Alexander Lobakin Reviewed-by: Marco Elver > --- > .../asm-generic/bitops/generic-non-atomic.h | 31 +++++++++++++++++++ > include/linux/bitops.h | 1 + > 2 files changed, 32 insertions(+) > > diff --git a/include/asm-generic/bitops/generic-non-atomic.h b/include/asm-generic/bitops/generic-non-atomic.h > index b85b8a2ac239..3d5ebd24652b 100644 > --- a/include/asm-generic/bitops/generic-non-atomic.h > +++ b/include/asm-generic/bitops/generic-non-atomic.h > @@ -127,4 +127,35 @@ generic_test_bit(unsigned long nr, const volatile unsigned long *addr) > return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); > } > > +/* > + * const_*() definitions provide good compile-time optimizations when > + * the passed arguments can be resolved at compile time. > + */ > +#define const___set_bit generic___set_bit > +#define const___clear_bit generic___clear_bit > +#define const___change_bit generic___change_bit > +#define const___test_and_set_bit generic___test_and_set_bit > +#define const___test_and_clear_bit generic___test_and_clear_bit > +#define const___test_and_change_bit generic___test_and_change_bit > + > +/** > + * const_test_bit - Determine whether a bit is set > + * @nr: bit number to test > + * @addr: Address to start counting from > + * > + * A version of generic_test_bit() which discards the `volatile` qualifier to > + * allow a compiler to optimize code harder. Non-atomic and to be called only > + * for testing compile-time constants, e.g. by the corresponding macros, not > + * directly from "regular" code. > + */ > +static __always_inline bool > +const_test_bit(unsigned long nr, const volatile unsigned long *addr) > +{ > + const unsigned long *p = (const unsigned long *)addr + BIT_WORD(nr); > + unsigned long mask = BIT_MASK(nr); > + unsigned long val = *p; > + > + return !!(val & mask); > +} > + > #endif /* __ASM_GENERIC_BITOPS_GENERIC_NON_ATOMIC_H */ > diff --git a/include/linux/bitops.h b/include/linux/bitops.h > index 87087454a288..d393297287d5 100644 > --- a/include/linux/bitops.h > +++ b/include/linux/bitops.h > @@ -37,6 +37,7 @@ extern unsigned long __sw_hweight64(__u64 w); > /* Check that the bitops prototypes are sane */ > #define __check_bitop_pr(name) \ > static_assert(__same_type(arch_##name, generic_##name) && \ > + __same_type(const_##name, generic_##name) && \ > __same_type(name, generic_##name)) > > __check_bitop_pr(__set_bit); > -- > 2.36.1 >