From patchwork Tue Aug 8 03:11:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 711568 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp1916533rwb; Mon, 7 Aug 2023 20:17:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJkB69dS9RVMoaNvYlNaeVivYUdWHPrDuRVs3BB7VMpFYBMLEaGdcLBqSTbTHb7Uh1y9Tq X-Received: by 2002:a05:620a:47b0:b0:768:3bef:da86 with SMTP id dt48-20020a05620a47b000b007683befda86mr14676647qkb.37.1691464671028; Mon, 07 Aug 2023 20:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691464671; cv=none; d=google.com; s=arc-20160816; b=RkrGn4vuYEkxDoBn28XsYR+X86p/e3GImWRMtPtXoSzCd/OB5u1IjV3hcjtVUkaWAZ xCrU4lkm4fHDjmxQO0XAYbASA91CcKiGFmvUUQmuGF7+NaPS4t2dt4sc+St6tsG20Zs5 OMMikgsO6l8IuVAmmjhWE8pHun2yeuK+Dq0MSiLjvHxfcuOjlRyfu1ny1C7v5NA4RtDE lZdy+9Uf+n78ZFrmz63uaB9vjYYw2k9bcBfutTLCiGSV1YMT/3ptWqV95DTFO4/Rx/4L a9j/fLf6MYSuP4NPjNV8mEEGF0Gk9Cuof4s0GwzluGlVSZvi41WsmDvi4AUuZmK1Z3zX Lplw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kot5PEmuPDK/CyGN6ee3rwJzaEBsQpYk5OnUPUMG6UA=; fh=hqs26moy805PsHbwd88lUczy2QdlfF59ojSMxj/DeWg=; b=hoEO/EVnoaa1UV/BNLpiHHpdEbFECKsyc8SMtDx+pjat5xdlagnqHxyeVnUlrNuvst ABeUFoqx8OZKf8lXD9PtjXln+FeePtIqhcgDpzwKEmxLUPfMwahLUqXlALll0BP3LXM0 RF1vpK6DfXZj5IeGbDqCNwCfa962VANHAD+LWGLyoLb0OEOYf5gJ7GbrESTDP3Aa49iw 5oJyxxkJZXW04nzGYywSA4ojGH6ZmB4acQ5wCQ9eRugckJwklNwgMuPFQXLulkmjBlRh uk+EFISYJoQ2uFSyMpfYS3NZx+J4mk2Eh4zNPZ/3hMS7r4nvV5OqGTkExOrALDQdF4w+ rJ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H0N+6wB/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q29-20020a05620a025d00b0076ccd3dc9f2si5652070qkn.741.2023.08.07.20.17.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Aug 2023 20:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H0N+6wB/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTD9a-0003vn-AB; Mon, 07 Aug 2023 23:13:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTD8x-0001ie-Ky for qemu-devel@nongnu.org; Mon, 07 Aug 2023 23:12:27 -0400 Received: from mail-qk1-x72d.google.com ([2607:f8b0:4864:20::72d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTD8f-0000MR-HV for qemu-devel@nongnu.org; Mon, 07 Aug 2023 23:12:23 -0400 Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-7658430eb5dso504655485a.2 for ; Mon, 07 Aug 2023 20:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691464324; x=1692069124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kot5PEmuPDK/CyGN6ee3rwJzaEBsQpYk5OnUPUMG6UA=; b=H0N+6wB/55D91L4PTpoKFT2OnuU5j8OL6wf21rRD7/ElhRhjkxgLZeXS6+lGRXxs70 8oTmNS7p4OFVSizMFjF8Zch052RgqR4b6vSHzDdA1rRSq05gLWQc/AFvj8uNqmTot5hf ypU2YGUn6kIO5jzndI5UjBZvZhE+XP0+6HMWwvobAwVpr59+F27G2uMS7+9PUGB8Df8y 0s0z+f1ipIn3kV15qx9kOyylWkob8fy89sQBxFEwXCjPVT65k+1+JA8DzfkW6t4gNZqV wH4vkTc0i6G4YE+prbsf12FgN/MYTjyi89lql8gNDSGwLm2UwDBGrtVXlbVkUz/kw+0i OfwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691464324; x=1692069124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kot5PEmuPDK/CyGN6ee3rwJzaEBsQpYk5OnUPUMG6UA=; b=NomAPVvaCnSgkxJ4PbzMDcnLKfYYzTbeLU/glUuscTmrMI/xewR7R5Bofdda9F7dGq 7eIR4cp0HxV8bwbk9dEeuvoj/WlRvpDvksoOnvpDqan7Yq5PSwpuZjjfXT2vaC4VFvww uX0ps3z/P4Xp+YTY0BhcRl2YECvOxQ8mPan1h73NDT3rQn6ItSRGcwyGbbD5CBq1Y0VO /JeZKzPSRdI/fVVzMLPGH0xAB79ZkHCcaPD82R1sBDYpec5WUmdkIXuIyvp7eZQ7TLBY nxQd1hRGvZVtVe46HkqA+luPn3Ncbw1C2q7+GwCGnIgzuTkJf9YR9CWh0QpvwiM2Uu1n zVXw== X-Gm-Message-State: AOJu0YyqiB5JIFZiq1bc68uNqwzTa6d6durAC/fXfejENqKiSCoCVVu2 +NLOryaae7g+Xv+ouGtmZ8DGG5wHT5A3h1dgVsg= X-Received: by 2002:a05:620a:28d1:b0:76c:95a5:b86b with SMTP id l17-20020a05620a28d100b0076c95a5b86bmr18046091qkp.47.1691464324226; Mon, 07 Aug 2023 20:12:04 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:e306:567a:e0a1:341]) by smtp.gmail.com with ESMTPSA id g64-20020a636b43000000b0055bf96b11d9sm5639087pgc.89.2023.08.07.20.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 20:12:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH 22/24] tcg/i386: Clear dest first in tcg_out_setcond if possible Date: Mon, 7 Aug 2023 20:11:41 -0700 Message-Id: <20230808031143.50925-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808031143.50925-1-richard.henderson@linaro.org> References: <20230808031143.50925-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72d; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72d.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, SUSPICIOUS_RECIPS=2.51 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Using XOR first is both smaller and more efficient, though cannot be applied if it clobbers an input. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- tcg/i386/tcg-target.c.inc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index e06ac638b0..cca49fe63a 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -1529,6 +1529,7 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, int const_arg2) { bool inv = false; + bool cleared; switch (cond) { case TCG_COND_NE: @@ -1578,9 +1579,23 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, break; } + /* + * If dest does not overlap the inputs, clearing it first is preferred. + * The XOR breaks any false dependency for the low-byte write to dest, + * and is also one byte smaller than MOVZBL. + */ + cleared = false; + if (dest != arg1 && (const_arg2 || dest != arg2)) { + tgen_arithr(s, ARITH_XOR, dest, dest); + cleared = true; + } + tcg_out_cmp(s, rexw, arg1, arg2, const_arg2, false); tcg_out_modrm(s, OPC_SETCC | tcg_cond_to_jcc[cond], 0, dest); - tcg_out_ext8u(s, dest, dest); + + if (!cleared) { + tcg_out_ext8u(s, dest, dest); + } } #if TCG_TARGET_REG_BITS == 32