Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1763209pxb; Wed, 9 Feb 2022 04:05:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJytjv8dSzFMFUsbnPkKrOZiNhbYdR2OY3nW7jlUBXtSezae3PcThqTCeELrHMPnhliIsSGo X-Received: by 2002:aa7:8c4a:: with SMTP id e10mr1921847pfd.43.1644408323977; Wed, 09 Feb 2022 04:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644408323; cv=none; d=google.com; s=arc-20160816; b=fOXtONAWA5LBmWZozheka65WNJ6Irz+6Fr7RbUPp2w8uek4Wb+M4j8N0iBgEesA+X0 SNrJLyX6KJP8fCGSF2TsNSBDzovpG9JrQzCQfyXeq7O+8wWO2hrEgAgIEcPlokyUoYoA lYTP28/gVeTjFQasj632gB6iZ29y03iC5Ee2m2Wy7axWa49212sM1SUMjaD9fpSnDXlO ssQ23rJVU2mdKJ8mk+bT5ZGhmKlsepzUV2koZPuc2fHLpSvbf9qKFyb7hxC2xJ7pFRvq D37xbWWV0fZgqgfxOx6IGuBKSN5CYRRxSVyofp3mruvDDr+U9MBly8seDLpiU9nY3W9l w2+g== 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=dUmxDI5gH962mcf35zRHyi1vHGoo0+FBECSduCqHJtU=; b=GM13qcQDhYdEVXQE8d4tkn000Aacwf9SjP0xvxWXfVmGNtlTTWA7xLpG5wxUKuqGXC 7Xap1KJgYOfbEq/Q0rL80kc6h0QT5xjJoCqTsd3+FhmKL3z1GvCQJKG2Y7MCo1ylYHmc obdl8ON06wW2wVUOW2cX4NjFUtFYw97m2ulNyjJiysgzLzE8yVreXZSib8pbErjucsfa EqFCojszGE8V7kRMLfQeDK/rNBugcOtgIJelUkCeN9bVg4TGK5umERKqvHQS5o3Yryx4 nWOciojVGWWSlB0GxwRcLOyNGdKTXl/S0RqAZ93TFEZJcyXg/xlvdmzwh6d5GfySopQB n/+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mxfWHtMl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 14si4642157pjz.150.2022.02.09.04.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:05:23 -0800 (PST) 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=@google.com header.s=20210112 header.b=mxfWHtMl; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2A56E02E46A; Wed, 9 Feb 2022 02:05:20 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236064AbiBHXTF (ORCPT + 99 others); Tue, 8 Feb 2022 18:19:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235952AbiBHXTD (ORCPT ); Tue, 8 Feb 2022 18:19:03 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC9EC061578 for ; Tue, 8 Feb 2022 15:19:03 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id d10so1998843eje.10 for ; Tue, 08 Feb 2022 15:19:02 -0800 (PST) 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=dUmxDI5gH962mcf35zRHyi1vHGoo0+FBECSduCqHJtU=; b=mxfWHtMl7cXEGtgGJKRHvUKUFcTVd8kAqKacHbU8yN2dIBYcwIkI+PhC6SZuYlzKN+ NIt4QxpAkYGAfYDHAjZ/8uf6pbNQKQWB0xhkwQN+AqE0k9dUwbhD294ElHbOitKdnm2w JxCjkqEeMEG+SJqu8B2sgzNubuatscgFicOCuWqK6u1KcYOOcWwVs0vG+OXWiBKwUADG i0XHxUxAizbxZExazKBsp9X3BU7ozTT3BILvLNEpnsIJaS63vbkJlhOodXfnuVedLWoR OaxsDtvA/gPuSLeERKAtgOAqCMWzleIt6nhsYp8wlDlTGh7RsdnRnNoU50+CooKaeVbI rgsA== 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=dUmxDI5gH962mcf35zRHyi1vHGoo0+FBECSduCqHJtU=; b=djvE+kAL3Ub0guZMUA8JKMDAUsgqvmw7SFWYsSXoaQY0TXd1Ek9sotvndTx+WCChYV QHd0WjPOg7Dao5vZkaiyApejNxMBsWL/9XLyW/S8yZ+ELT9bYVRnIyvvciWq3mT7+BQi f/5aRLnSqO+1cPhq75HZCDBzGA8e4I7/+mq0WF6j3k6A2CEAPaBKvE5k3gL3TuQKBAHO JEng4++PhS1ExrSiDYu99p/Ucetoh57CzTutLcwnmbT7L//zzQ00cJCrYB0epJvInGC7 LYIc6rPJxTbVpz8foqHOo9j4TZbKg2q04fCfxKs6bkQzCmipe13uPdnRC15CrxmNaebN CQIw== X-Gm-Message-State: AOAM5303JOsJ5Mb2JyniuvTIFYmyKbU3CR8r4OUycWwmT0k934nlEgGy o5g/XPpXSF5QzRD80zZ4nTIoQhFEftY7EkuRZpmx X-Received: by 2002:a17:907:7b9b:: with SMTP id ne27mr5603709ejc.486.1644362341362; Tue, 08 Feb 2022 15:19:01 -0800 (PST) MIME-Version: 1.0 References: <20211229021258.176670-1-morbo@google.com> <20220204005742.1222997-1-morbo@google.com> <0d93ea4d847b42ca9c5603cb97cbda8a@AcuMS.aculab.com> In-Reply-To: <0d93ea4d847b42ca9c5603cb97cbda8a@AcuMS.aculab.com> From: Bill Wendling Date: Tue, 8 Feb 2022 15:18:50 -0800 Message-ID: Subject: Re: [PATCH v3] x86: use builtins to read eflags To: David Laight Cc: Nick Desaulniers , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "H . Peter Anvin" , Nathan Chancellor , Juergen Gross , Peter Zijlstra , Andy Lutomirski , "llvm@lists.linux.dev" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Tue, Feb 8, 2022 at 1:14 AM David Laight wrote: > > From: Nick Desaulniers > > Sent: 07 February 2022 22:12 > > > > On Thu, Feb 3, 2022 at 4:57 PM Bill Wendling wrote: > > > > > > GCC and Clang both have builtins to read and write the EFLAGS register. > > > This allows the compiler to determine the best way to generate this > > > code, which can improve code generation. > > > > > > This issue arose due to Clang's issue with the "=rm" constraint. Clang > > > chooses to be conservative in these situations, and so uses memory > > > instead of registers. This is a known issue, which is currently being > > > addressed. > > How much performance would be lost by just using "=r"? > > You get two instructions if the actual target is memory. > This might be a marginal code size increase - but not much, > It might also slow things down if the execution is limited > by the instruction decoder. > > But on Intel cpu 'pop memory' is 2 uops, exactly the same > as 'pop register' 'store register' (and I think amd is similar). > So the actual execution time is exactly the same for both. > > Also it looks like clang's builtin is effectively "=r". > Compiling: > long fl; > void native_save_fl(void) { > fl = __builtin_ia32_readeflags_u64(); > } > Not only generates a stack frame, it also generates: > pushf; pop %rax; mov mem, %rax. > It used to be "=r" (see f1f029c7bfbf4e), but was changed back to "=rm" in ab94fcf528d127. This pinging back and forth is another reason to use the builtins and be done with it. -bw