Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1543790rwb; Thu, 10 Nov 2022 18:34:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7PBejkQhoB7b2d9mVakcuPwj5060wA896Z3Kx1JT2WUIDIX+NCLT2tyreOK6iXiEiWB65b X-Received: by 2002:aa7:8649:0:b0:53e:beae:5a9d with SMTP id a9-20020aa78649000000b0053ebeae5a9dmr394295pfo.74.1668134075218; Thu, 10 Nov 2022 18:34:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668134075; cv=none; d=google.com; s=arc-20160816; b=BA3ieBNVvt3ZxSCfFb9V2VdWjkVKk8lYnpEjcNLP63apOe/E2NKI9vMYJa2L2CDuya pDpIJAwdzwnNJ08WkPbvya9nsLgcpWY3YHhzwpuxPUlasnqfPIWGvyKDc3n06Hlu8MaV EiDgdnw3rgVMtbVJOqIpDshJuZl69T1rC07fKzO3sF2S0btvQceEwtiS+2Jp8CTLmZMt OZfVnv72punLNwpnCx+r8hgSeTnGwoJcxM013NUv/+k6hWyog2HcWrM8DkdlBX+tRb8t FIxR4atA8ri0FKQI9RYpXGQTxgbZDIjOvHV5ElRRK8P8lendZul85q4qVG+bv61Iokau cHEg== 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; bh=FxqNahmA7zR1BB5f8m8SleanQkS8j2v98m1g/ifNOXk=; b=sPGNql/JeCan1qL91qPFzpfelycFwZBgewTgP4DvjmcOGv2XjfatAuV1UlRGZzbFKn bfgs7xK+OFhE4k6n4VfC0wFk1PvYzF5DfuK5M1Uraj13LrZqcM1ErowUNBitEVCX2hT4 DO/7LxPa86kVXJAighBGV8quLKGi4i87fNvOCnwiJ4/GSvrsFt7umfrrFuAIMPJrMQ/P GyHyd8Uttjs6cDHEA7r/pkY7ArKIO2jlXWwCGvaUJHj3w393flc8t5UZMFf/Kn2yRGnT uC3NQbvO5dLDx+MUWUTSa0Fw/UwqowJiZEygrvkWkDpSQ7Gc3BQn1HDTxYbYiAsXLeH1 4akQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a170902d34500b00188881adcd7si932816plk.550.2022.11.10.18.34.23; Thu, 10 Nov 2022 18:34:35 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231895AbiKKB5e (ORCPT + 92 others); Thu, 10 Nov 2022 20:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbiKKB5b (ORCPT ); Thu, 10 Nov 2022 20:57:31 -0500 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC594D5C0 for ; Thu, 10 Nov 2022 17:57:29 -0800 (PST) Received: by mail-pj1-f42.google.com with SMTP id l22-20020a17090a3f1600b00212fbbcfb78so6515339pjc.3 for ; Thu, 10 Nov 2022 17:57:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FxqNahmA7zR1BB5f8m8SleanQkS8j2v98m1g/ifNOXk=; b=2Nwj0spzyrVmIyXdgqY6VarBJ4E3aEkmNDRR8AlTstMabtsmx9hL981RsQu81o+gtn ftRIvEhD+udpnqbAl+qE2GHljsnzP0JjCJRfhNvvYbDD3p5gELPCOQEdRqvKhnkhi2UI oGVcnGiDXedGQmFwWswwN8s/6eNG9hmg8YrplzdmDnOw6988/Rw4ELLrAZAfJe9j1hTt yrcCiDdKni+UauKPUFuUm56d4HD/a3P/kRJyZwgXlWdLW2Ua7AsTom8LA1FkGAs8L775 3GRzH0WHnvJy41ogzYtGFq6U2V0ILugc3VDBkPYbdOCGZnA6X6MLN8mpjv+UVG9dDJKJ 8Vxg== X-Gm-Message-State: ANoB5pmfJWYfNKEjQGxiuxXG3Ql1PywKmf+nwGQBnUo5hA55XNRwEQhH qT6aDbFQxq2I6Du3a8hytY+KRmDin3cm/m69jqU= X-Received: by 2002:a17:902:f34c:b0:17f:6fee:3334 with SMTP id q12-20020a170902f34c00b0017f6fee3334mr445676ple.10.1668131849126; Thu, 10 Nov 2022 17:57:29 -0800 (PST) MIME-Version: 1.0 References: <20221106095106.849154-1-mailhol.vincent@wanadoo.fr> <20221106095106.849154-3-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Vincent MAILHOL Date: Fri, 11 Nov 2022 10:57:17 +0900 Message-ID: Subject: Re: [PATCH v1 2/2] x86/asm/bitops: Use __builtin_clz*() to evaluate constant expressions To: Nick Desaulniers Cc: x86@kernel.org, Ingo Molnar , Borislav Petkov , Thomas Gleixner , linux-kernel@vger.kernel.org, Yury Norov , llvm@lists.linux.dev, Borislav Petkov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no 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. 11 Nov. 2022 at 04:01, Nick Desaulniers wrote: > On Sun, Nov 6, 2022 at 1:51 AM Vincent Mailhol > wrote: > > > > #ifdef CONFIG_X86_64 > > -static __always_inline int fls64(__u64 x) > > +static __always_inline int constant_fls64(u64 x) > > +{ > > + BUILD_BUG_ON(sizeof(unsigned long long) != sizeof(x)); > > Thanks for the patches! They LGTM; but why do we need this BUILD_BUG_ON here? There is no absolute need for sure. Call this a paranoiac check and you will be correct. My reasoning for still using it is that: 1/ It is a compile time check, so no runtime penalty. 2/ Strictly speaking, the C standard doesn't guarantee 'u64' and 'unsigned long long int' to be the same (and you can argue that in clang and gcc long long is always 64 bits on all platforms and one more time you will be correct). 3/ It serves as a documentation to say: "hey I am using the clz long long version on a u64 and I know what I am doing." If you want me to remove it, OK for me. Let me know. > > + > > + if (!x) > > + return 0; > > + > > + return BITS_PER_TYPE(x) - __builtin_clzll(x); > > +}