From patchwork Fri Aug 18 22:13:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714706 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp750181wrs; Fri, 18 Aug 2023 15:18:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOYtqgnazPvVURx9JtOzEN8zoYy53E/UJu08XbFDbUkCzTWM5okQSoqpsHV6pBroAq5Ko1 X-Received: by 2002:a0c:f009:0:b0:642:66bf:902c with SMTP id z9-20020a0cf009000000b0064266bf902cmr629823qvk.32.1692397107446; Fri, 18 Aug 2023 15:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692397107; cv=none; d=google.com; s=arc-20160816; b=uETXr7sRPToU1YhUYi9texjpGZr72uQsALZ8CcNz1J7d711OsnDK7XLaO5LcBasJ/7 miax9BExs+yJsdruetOu09uLMjI25WBJyVJojt3iqcfZUrWSgASg0/THBaeE2tF7iRUz Sj5ID6rSMV/x1F7Q1rOJBEub+G6NBT3uIfVZ7BnDBCMQm/ehm/JH1Lkpovt+kOW6teMk o2otadyIBlob6jcQw2Kds0ipjTFz0FO+s93w9H686V2lKVI3Y7rYdiMxkengpYDqpPpy FPQ8HR5Hw9rgdLJqUoJ7KCY8T8FXNKkM3wNbWm8V+X1aw0BuAbPk+Mp7JaR651KSFfd/ 3p5w== 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=fwTSAJniEJxZbT4fbmyP3S6oSlLWMsUHRkmcSVO+gJc=; fh=iKWO5kImkBaf5P/04M2d2o+fJodoyCg8YLKe8/cbiwg=; b=ol/ve6ZwtJ4mdGOr5nVd1dk8/TToqXwKlf7Kex8BNplut5cDhk1YOyUn+6NytQ51qA JSIdK9hvyy2LDMInEQPVX+B0kKhntr/Q7iW55z8mHDNL1TtuLIlqO6rpBbQDZm7FxOwM Dxnd8R1zAhtQFSbZCOOBHClf9oy2oWFiYaE4/ZYlKTRJ1pmnPSMKWzLb/rmLKlcFrvDu SSLxopqBecYhWCjzvBTJsRZExYosIHCly0/vq6pRVfcao9M1cEaulX+WmmMtmB7NP/xN iV2h4oCZzfChMn/7lUtPVlRkc8PKvMERjq6mm26bOYd+b0VGPZJgNHQFRIsewLFMwNLH /Q3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CVW+YEyg; 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 t13-20020a0cde0d000000b0063d61ec2a55si1908866qvk.328.2023.08.18.15.18.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Aug 2023 15:18:27 -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=CVW+YEyg; 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 1qX7j6-00056D-0c; Fri, 18 Aug 2023 18:13:52 -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 1qX7j4-000541-6q for qemu-devel@nongnu.org; Fri, 18 Aug 2023 18:13:50 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qX7j2-0004Qj-1l for qemu-devel@nongnu.org; Fri, 18 Aug 2023 18:13:49 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bf3a2f4528so9084335ad.2 for ; Fri, 18 Aug 2023 15:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692396826; x=1693001626; 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=fwTSAJniEJxZbT4fbmyP3S6oSlLWMsUHRkmcSVO+gJc=; b=CVW+YEyg0xu5RbEdDyDI475yAXlegsUQ0MFCshQk3/7IctOBsA8MJyRzS33DXsICGQ BSzNWADUh0msgor+7R74LXSR2DhuK/OvrOJ9XTXeHT+d/psccyeserzfen2Fy1vsnLdy +cjCQh703dFZRVZpAPA8LHynJsy9zYAb7BxDPRxOwRIJE/8BFKWCyqRLs+q0l8vo5sCB ZWQVkPGDpyYnzFpxGj2D2nhGVJLpHGm5/C/b/Z4PRQEpkyF+oH/tEsrd4yxzFZe8aisI 16bgwmui2Acdpg9/tZtOuCx09qADQSXdF46XyxKTWP9UqTgkUX+bO1wxFMxhQq6QgBnY MVVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692396826; x=1693001626; 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=fwTSAJniEJxZbT4fbmyP3S6oSlLWMsUHRkmcSVO+gJc=; b=T1CEm8w7FiRSTl5ajs9uK41OheNMAnE447A5DYdVlZSWTwKYOGomnAHd2C8xgXxMch 8402Vh9YkiZTXLpO0jlhlM3ZDRFx6k/VHX8r8L83M/dm+IbS3YhRgq9lFhYGM8cWPHt7 NhUl6ixnFDCpxEbqRQCgEZxesvZSSPW95YM7Ah/2SNuplSej3QffRfHFBZK8k/DxEwTu /D6M8RB6Th/ofFFWnF1Fo9zeK35HSVYJ9tkkDX8Txztx1rG1yFqsbETf4OpI3EluEg6v 3tZbxYrBr86PxHT2HGg4vJWe4K/53awREMSGkgTPqwqUuuOeHLYzYlx0+X6y5XUu6Ied v9yw== X-Gm-Message-State: AOJu0YzemUkWJLCimKq8NXgkEA8lMNmrMHk99YMIUF4zjgVjq0h4vT+S rUZK2xNwwj96r87bOjnrv0TufDrxrkN2DpmO0YI= X-Received: by 2002:a17:902:d214:b0:1bc:667b:63c6 with SMTP id t20-20020a170902d21400b001bc667b63c6mr320348ply.41.1692396826720; Fri, 18 Aug 2023 15:13:46 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:cf24:6daf:2b9e:7972]) by smtp.gmail.com with ESMTPSA id y7-20020a17090322c700b001bdb85291casm2231417plg.208.2023.08.18.15.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 15:13:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PATCH v2 21/23] tcg/i386: Clear dest first in tcg_out_setcond if possible Date: Fri, 18 Aug 2023 15:13:25 -0700 Message-Id: <20230818221327.150194-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818221327.150194-1-richard.henderson@linaro.org> References: <20230818221327.150194-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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 autolearn=ham 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. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 4d7b745a52..3f3c114efd 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -1532,6 +1532,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: @@ -1581,9 +1582,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, arg1, arg2, const_arg2, rexw); 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