Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1703986pxp; Thu, 17 Mar 2022 15:00:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsDt6RMVS9dNMKDSzS5TWvN2HmSmt1ilZLUNO9qTHT54siSha/kyu9fruW7VjX248b8CAh X-Received: by 2002:a63:544c:0:b0:378:907d:1e37 with SMTP id e12-20020a63544c000000b00378907d1e37mr5372470pgm.394.1647554452910; Thu, 17 Mar 2022 15:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647554452; cv=none; d=google.com; s=arc-20160816; b=LY1V17aBrtUI/J25dGnnrwCS00HLt9TWnm/clOGy+iWc18jjxOrbfvYaUR6t/1h2uX 0J+4kzWYKaiu1q7Qm/DsCpHPnMcNSTYssL0gMcTCIVMFRqYzugR+MdU6s+a/rREH7VNV 3yj2o3f4NFBq2H+XUuJSsjo19HJjCY2K5EmfLbFgL55xXfFSciZnDk8XaBdg5nd6CBWs +9g9fREfaq2jnkAGbtkecBkQnrwkd5iWOUNjqnw3Te2V8DXEypgigLRw4o+CeAjD5egu cBilDfqO1Z9fPFI+kylS5UhB7LD7xeQtcaKEmLje+2/igAh1FTlJLygTmmrOcuS8ttze g3DA== 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=bPG2uGymrQaAjdz0Rd104PLEPknS8uFaRtBuaevCxHA=; b=mHTcoxdR920c6UsAoE0t9WpZe6K9VwoFBExx0DwFthl5DznohkoJKiyXPUmIlqWcxc 0786JprEDcQKFpRX25Weqxgv9anTLkqSuEyj5wZBmIadPFVz2PnO00DWvyTuwaM7jbpV +B0Rpe/ws6M6pQiLz9uPd0oFD/s7S9pkrAnw9zn66UKdHRkFfKsF9uaHiBsre/r+zpEW G3uxF+sY3tya2sUR6hrLnRhURLA+t0+K3xrStzhss7kiZzem4WHRx7Fygt9gKXqrXUmD YisIJJPIkRBpxITgrDjNO6E2GGyKpI0lPZpiq5QdRfKsk72+uMWL9cLFN/paN0kJve56 qdgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UTEyURln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d15-20020a17090a114f00b001bd24be2c41si3747535pje.54.2022.03.17.15.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 15:00:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=UTEyURln; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A2D7117B880; Thu, 17 Mar 2022 14:40:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230336AbiCQVlO (ORCPT + 99 others); Thu, 17 Mar 2022 17:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbiCQVlM (ORCPT ); Thu, 17 Mar 2022 17:41:12 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A084B17ADA9 for ; Thu, 17 Mar 2022 14:39:55 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id bn33so8989150ljb.6 for ; Thu, 17 Mar 2022 14:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bPG2uGymrQaAjdz0Rd104PLEPknS8uFaRtBuaevCxHA=; b=UTEyURlny0M3Sp02wOFqvyBlNYSNglScLLJjYWs3wxSUqoupmURo3mj/gHB5Z5k5pX HPh7nIvN1DWQ+l9DF+cwJKe+pvcdckJZl8UzsZy52K+blalTvbo7u0/7Tl3LRt1+aGoJ f+zhtUKsWIWSZtd2Flxj/uhYm1p/LwCawziUM= 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=bPG2uGymrQaAjdz0Rd104PLEPknS8uFaRtBuaevCxHA=; b=KMGCh3L4RTOUJ9vh7nD3Tom9QLImaS/PV0upq4q+jUVrebCKq83plEwPq5ttBAZeGN sS0HpySprkSe+YZWowz5I2JsXHnd5cEDcgcrSCJanwL8nThby7oHBVy7WlNFyVjoXKYL arpykKMOERhl74ABJlr6ihSXTh+RrepRLQsGi2I4YwGNkKNaf1QUE83FV05wX0TWe9Ei YXNu2AYsNvZ74+n+bDERHVYzXCOinN6/dTrVZa1NGBw3UyC8ghr8q3zE6nGK5bgg1j/b za5hPSjk0kmfdy8BnSDqF3QYYQenZoDcfSLG88D4H28NpYS5em5s9/YEmO6F+adGvNNt Lz4w== X-Gm-Message-State: AOAM531JIZ4wnLMnEgI5J7Dj+bLYczDZSzdHG6KQrUJCdeuZ64QK97aJ LjXLCeyvTttYvCmXFax0lu6XAPeKJhdQ0pICcZY= X-Received: by 2002:a2e:22c5:0:b0:249:278b:7f6d with SMTP id i188-20020a2e22c5000000b00249278b7f6dmr4387098lji.397.1647553193713; Thu, 17 Mar 2022 14:39:53 -0700 (PDT) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id h2-20020a05651c124200b002492835aa87sm554075ljh.118.2022.03.17.14.39.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Mar 2022 14:39:51 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id y17so8942813ljd.12 for ; Thu, 17 Mar 2022 14:39:50 -0700 (PDT) X-Received: by 2002:a2e:a78f:0:b0:249:21ce:6d53 with SMTP id c15-20020a2ea78f000000b0024921ce6d53mr4157427ljf.164.1647553190688; Thu, 17 Mar 2022 14:39:50 -0700 (PDT) MIME-Version: 1.0 References: <20220210223134.233757-1-morbo@google.com> <20220301201903.4113977-1-morbo@google.com> In-Reply-To: From: Linus Torvalds Date: Thu, 17 Mar 2022 14:39:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] x86: use builtins to read eflags To: Andrew Cooper Cc: Nick Desaulniers , "H. Peter Anvin" , Bill Wendling , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Nathan Chancellor , Juergen Gross , Peter Zijlstra , Andy Lutomirski , "llvm@lists.linux.dev" , LKML , linux-toolchains Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Thu, Mar 17, 2022 at 2:06 PM Andrew Cooper wrote: > > I was idly playing with this builtin in response to the thread, and > found that GCC has a far more serious bug than Clang had. Heh. Yeah, that's bad. But it kind of fits my argument: compiler intrinsics aren't necessarily such a wonderful thing. They hardly get any testing at all unless they are some very very core thing. I will personally *always* prefer some generic "escape clause" over a compiler that thinks it knows better. I think compiler people should see inline asm as a really *good* thing, because it allows people to have that "I'm going to do something that nobody normal does, look away now" kind of escape clause, letting the compiler concentrate on the things it does best. Yes, I realize inline asm isn't something compiler people love. And yes, I realize that it might not give optimal code. But think of it a bit like casts - it adds complexity to the language, and it might make some optimizations harder or even impossible - but it makes the language much more powerful and allows you to do things that you simply couldn't do without it. There's a reason people use C instead of Pascal or FORTRAN. Those casts, and that pointer arithmetic - the bane of many optimizations - are really really good things. Intrinsics should generally be shunned, not seen as a "this is an alternative to inline asm". They should only exist for situations where you can show "look, I can do so much better", and have a test-suite for it and a real-life case where it gives you a clear and undeniable uplift on a meaningful load. (And here I separate 'intrinsic' and generic compiler builtins. I love the builtins that allow me to tell the compiler something, or the compiler to tell me something about the code: __builtin_unreachable() and __builtin_constant_p() are both wonderful examples of those kinds of things) But an intrinsic for some odd target-specific thing that can't even be portably generalized? Give me inline asm any day. We can do things with inline asms that the compiler can't even _dream_ of, like the whole instruction rewriting thing we use. I'd much rather have a powerful generic concept (eg "asm goto" is lovely) than a specialized intrinsic that does only one thing, and doesn't even do it well because it's untested and badly defined. Linus