Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3921067rwa; Tue, 23 Aug 2022 12:32:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR4qadIoPuXKaKY+LO7MUPl1nhAJuJmZROyPLtBotkCiqXpwKJtx84EnIcRH90IdVVWQxH0s X-Received: by 2002:a05:6402:22ea:b0:445:d29c:9694 with SMTP id dn10-20020a05640222ea00b00445d29c9694mr4789290edb.359.1661283169607; Tue, 23 Aug 2022 12:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661283169; cv=none; d=google.com; s=arc-20160816; b=ajjuLT+89QWZEhRGnp1PpCqO+47YiswV/g0w5a9TmejxZPReYS3EAtZXC/suySuZne 6LLuzpgiwWm38n7zOaKB8+OP4RmVaSDrYVmVP0x51ttAyhooAVpQlVliLiRF1jsnLRFj ACVF3GS108PI9MUmpelUd1sXdghgiLNT3Gr6KkLRrqDWYxulpjlDHbkAk+p4FffjaA/v MWqt5W4Q6ZO2u3YPT+/n0X8363pEWrowoyUegZ0t+QQpVnMBfJsyLMu63PvNdWF0nE6z uasQt+Jfxs1Ljfxi0pxuxh2NlrYVuksNMK4Vqf0Rmk1ET+NZuFX+1Bm2H/MbAYg6Sahk a2JQ== 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=oJRG7uz6WGBbtCoGOSmHQY70YgBhBuqvMftRIStyMs0=; b=sAPusLnWNkaSUxmcsEZZMq4BhojfUU1BF2xOF1w0DMlKO3+5GRlPoZt7f0O1Izw+tB 5MiVhWPUPj1cZEf7qHcQJDDRa0jyUjTErW4Sc/FcyhwRGuI07mmzJlLbyfXk9EbuoZXV hbG1HORUiHi3IHt/ZDaESo0FSFCO3JPDGLOGcMTGE8H4C3sloWTW3X938wV/9owfRhct q+OMUv7+Gv59mRkPBddzUpIHae2Rorrhcvq/IFCLT3zSrcPJyP9tkE2elHdQnHTJ+Ih/ 2H/FPPepCr4nfTjvj+TiEqVEiju3ddIF3CcoI0FU/5Ev8RK457vWr4G4/DwvgH268Kll K8Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=NdGEu09r; 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 m13-20020a056402510d00b0044347b22b2bsi3077915edd.354.2022.08.23.12.32.22; Tue, 23 Aug 2022 12:32:49 -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=NdGEu09r; 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 S229687AbiHWSs4 (ORCPT + 99 others); Tue, 23 Aug 2022 14:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233617AbiHWSsS (ORCPT ); Tue, 23 Aug 2022 14:48:18 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCC5F11B010 for ; Tue, 23 Aug 2022 10:12:31 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id l19so10975052ljg.8 for ; Tue, 23 Aug 2022 10:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=oJRG7uz6WGBbtCoGOSmHQY70YgBhBuqvMftRIStyMs0=; b=NdGEu09reixZxX3m/TPNxIYeFZ7fr5WNqIF0qIYTfmeK1vx24ssEvai7OW9XAB7KNn R9TzKHZLK3CeuHeGzHjOqaD+NYMU6prJ46EAlmE/taiviOKUz4wwlVrHApU2usky32xx bvV+2KT+rjw7Zbix0OOybgaCTm4MPw59fQEmXzllwnB+ouyMhjojKx1YI1pcms4nmYuF AeX8//PGbdMgfwghAEl154yq6ojmHvjaakHMOFwWtotLye03UoWu8afnTvcSzEW3RAbW kc4PHWxpXwNxGRhgsnWIid8EnsmhRnlF6gGyBgOcL3kFt3A/EFZ2KIrXyHbgh3WRCtss CJ4g== 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; bh=oJRG7uz6WGBbtCoGOSmHQY70YgBhBuqvMftRIStyMs0=; b=rT+eZTuKyHyL7iv+YTdjD8tkzc1vCBpPo+cYVLCWEt9HP4Kw96NF9cupHR4TbenD8x fvPinJ8qQLzj3UydBIxxufRY1+EHPWPdObhcoxC4WsWeLz5MVUQZ4gGFoBIV3DFOx/Tn NED72GHahsiB3pnzLcJIOkNk47JLuMSehaLihKB1YqEamdfSRV/ZTXRc0X/sds/JW1+v wSld28f/pjPkBKRFNfjPc5/ZNojMyNOATTFpD7FHFMwKsI7IT9BcYOoPgVxrrMrfpmUU 3sLhhK4qKoJ925bERfuMoHHYB41YHK4jomVcqru0JbNZz14xbD48mBqcW1IiVLyFhlN8 1OsQ== X-Gm-Message-State: ACgBeo3i1xz7L1xltCH4Jlnl02qad7sF/cNZ0TDUFpOn+d1OhD7bjmtw i4kn1tPfIhFV/86FP3wyrZpXr69aTUcMIL3xgkbNFw== X-Received: by 2002:a05:651c:31b:b0:261:df26:53ba with SMTP id a27-20020a05651c031b00b00261df2653bamr585838ljp.513.1661274749104; Tue, 23 Aug 2022 10:12:29 -0700 (PDT) MIME-Version: 1.0 References: <20220511160319.1045812-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-3-mailhol.vincent@wanadoo.fr> In-Reply-To: From: Nick Desaulniers Date: Tue, 23 Aug 2022 10:12:17 -0700 Message-ID: Subject: Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to evaluate constant expressions To: Borislav Petkov Cc: Vincent Mailhol , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Peter Zijlstra , Dave Hansen , "H . Peter Anvin" , Nathan Chancellor , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, David Howells , Jan Beulich , Christophe Jaillet , Joe Perches , Josh Poimboeuf 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=ham 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 Tue, Aug 23, 2022 at 9:23 AM Borislav Petkov wrote: > > On Fri, Aug 12, 2022 at 08:44:38PM +0900, Vincent Mailhol wrote: > > __ffs(x) is equivalent to (unsigned long)__builtin_ctzl(x) > > Are you sure about this? > > My gcc documentation says: > > "Built-in Function: int __builtin_ctz (unsigned int x) > > Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined." > > Note the undefined part. > > Also, > > __builtin_ctzl(0): 0x40 > ffs(0): 0x0 > > I'm using the kernel ffs() version in a small program which is basically > a wrapper around BSF. Callers of these need to guard against zero input, as the pre-existing comment notes: >> Undefined if no bit exists, so code should check against 0 first. -- Thanks, ~Nick Desaulniers