Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp618076rwe; Wed, 24 Aug 2022 06:34:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6fyWHEEEOvBVGCHGwoftw+Mp6qPB9U2nsAreCKJMgK0bWivwVDKgzrsP2YKZVqwzNfk8QD X-Received: by 2002:a17:902:db06:b0:16e:e5fc:56d8 with SMTP id m6-20020a170902db0600b0016ee5fc56d8mr29223902plx.100.1661348090342; Wed, 24 Aug 2022 06:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661348090; cv=none; d=google.com; s=arc-20160816; b=iQyaDILyiMPM95cFkrR2jnpIhWNnO2hAKzG+Zc+vQg9G2agqb73MEqxekAYPtV2Tm5 4pnraEgAByBSrQ1emgKEyIF/4lJxRfzyuFkNYtrhIMNmsg8r9NLyNz/9X2MVDhzwOjbJ zAhKaXca32GmeaX4dDnXO1U5aCsaB5PZaJuBov/Ufq3PYE6eh94FoCYR1B0jJl2/kf9D fV5c2Ihw454pqgkYFDV27nUZ70Eyn03nNnFfHTINjvu/tKtbJohJ/KitqpePgLnq8vv2 8LSGwy4k27Av6kkeHJ5yiyJwSUK2QtitUTkFDymSYx/zNZcOAZqU3gQLwxDR7sf9md26 pYnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hvtVxhWrztDsZXHALGXRisb9QLUwGNxxI+ykol7ovVo=; b=wyDZORmlkakMhLcJ1tn8LJbnw7+5yzXg5Da94DCOnXezJvbF+i/GIOBSUNL831dfVa oXyavwQH/2LD+KzUsa2wfmy+CH38uYRbT3QuwkGrBwTH+xsleNgI+CNE3dHQqFenBnc/ g601g6Njo8JrIHnS+i4nPOyZWhbCqoZ08iMw8cIfrmeRWxuaZkr8TpYY0LU1BBO++jbA sPrtmkc54O85XN7b3o5/Q8GWKlCN5LZwVhsrzUyRdaepN8dlZEhf2wiRMs+8iqlNcpdI AQGFsNKk4Yxkasc7nOoMp+aTMCRXJnZa5hcOjKYYemYljU5zEjGJ4QE7FX7kR73lGPn+ qIQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=Igt6T7Vs; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a63130d000000b003fea0415b5asi17305560pgl.834.2022.08.24.06.34.36; Wed, 24 Aug 2022 06:34:50 -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=@alien8.de header.s=dkim header.b=Igt6T7Vs; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238184AbiHXNZV (ORCPT + 99 others); Wed, 24 Aug 2022 09:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238130AbiHXNZS (ORCPT ); Wed, 24 Aug 2022 09:25:18 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5B5F2D1C8 for ; Wed, 24 Aug 2022 06:25:01 -0700 (PDT) Received: from zn.tnic (p200300ea971b9859329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:9859:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 4DB421EC056A; Wed, 24 Aug 2022 15:24:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1661347496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hvtVxhWrztDsZXHALGXRisb9QLUwGNxxI+ykol7ovVo=; b=Igt6T7VsheNVHQUMoO69O/uFLPp7VAdAhsrFKKwTrxalqZq+17xhfRkrVg23xurex9KpDu /MThpzGjF+UqrqaAsUToD9N6w3NsaVraXMOWKHY6egMnU98E7XsjxlbK2E9vcG1kZumei0 wsg5NuIgX4mHx+ipvBNi9wX/4rN9DQ8= Date: Wed, 24 Aug 2022 15:24:52 +0200 From: Borislav Petkov To: Vincent MAILHOL Cc: Nick Desaulniers , 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 Subject: Re: [PATCH v5 2/2] x86/asm/bitops: __ffs,ffz: use __builtin_ctzl to evaluate constant expressions Message-ID: References: <20220511160319.1045812-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-1-mailhol.vincent@wanadoo.fr> <20220812114438.1574-3-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, Aug 24, 2022 at 09:10:59PM +0900, Vincent MAILHOL wrote: > Not exactly, this is TZCNT for x86_64 but for x86, it will be BSF… Not x86 - some old models which do not understand TZCNT, I'm being told. And I'm being also told, "Intel and AMD disagree on what BSF does when passed 0". So this is more mess. > It means that __ffs() is not a x86_64 specific function. Each No, not that. The comment "Undefined if no bit exists". On my machine, __ffs(0) - the way it is implemented: rep; bsf %1,%0 is well-defined: "If the input operand is zero, CF is set to 1 and the size (in bits) of the input operand is written to the destination register. Otherwise, CF is cleared." Leading to __ffs(0): 0x40 i.e., input operand of 64 bits. So on this particular x86 implementation, TZCNT(0) is well defined. So I'd like for that "undefined" thing to be expanded upon and explained. Something along the lines of "the libc/compiler primitives' *ffs(0) is undefined. Our inline asm helpers adhere to that behavior even if the result they return for input operand of 0 is very well defined." Now, if there are some machines which do not adhere to the current hw behavior, then they should be ALTERNATIVEd. Better? > > Back to your patch: I think the text should be fixed to say that both > > ffs() and __ffs()'s kernel implementation doesn't have undefined results > > NACK. __ffs(0) is an undefined behaviour (c.f. TZCNT instruction for NACK, SCHMACK. Read my mail again: "I think the text should be fixed". The *text* - not __ffs(0) itself. The *text* should be fixed to explain what undefined means. See above too. IOW, to start explaining this humongous mess I've scratched the surface of. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette