From patchwork Fri Aug 18 22:13:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714708 Delivered-To: patch@linaro.org Received: by 2002:a5d:484e:0:b0:317:ecd7:513f with SMTP id n14csp750249wrs; Fri, 18 Aug 2023 15:18:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFltt/i3GADt1c+ytONzTo/DX2+HMfbX3nk62g8ClzD3T76mBHBVq6l2kxXfnKq+37RUjER X-Received: by 2002:ac8:58cf:0:b0:401:e2b1:d28d with SMTP id u15-20020ac858cf000000b00401e2b1d28dmr590130qta.20.1692397121619; Fri, 18 Aug 2023 15:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692397121; cv=none; d=google.com; s=arc-20160816; b=eGE8X53VcHHKJLh7U5yg4g1+Jn/wGN0q2Y57KRBEcs36NdKjm4B61n0v6VhvL6P+P4 cukllams7OATqY9EumI7k+tfCU7O4Yaph0rVfn3n5R5nJbMHV5T7UxcuV8ssrGzTyv0d kH/VINMq2+G3pDLSFU7qGXwWm1l+RaeZiP5tX7eRYo46etR5utf91A/cqyD07oUWaQIB x7o9mbicv1iMqjvtTY4OpTe+arNkXC+gDdfgPzMj4c50vdRilmDB4jqKHB+f7/ok4Jht eeT5k9lxyPjtr1PAEJD1L0m1emz/ow86yp8FdKA+luf38UnNoTm1qbKeqoPjZ5EIHfGT iXIA== 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=9xk1+CqOJWdeIJliIlUjmMI38qlOB1/l73hqKwcbuPU=; fh=iKWO5kImkBaf5P/04M2d2o+fJodoyCg8YLKe8/cbiwg=; b=vR5bHlu6eF0nD4sTMmGpJU+Bp15XzHu//jpsOV5Ze2FqBL0jXhRvj767fA/uPs8gWs eG3FD6KGwHh9QhCgD+XNCE6Ur4TI1ME/h0j1Ufbi5veglvqLASgZclI/2yT2+wryAkDo sMHSRPfrmlmAAmuxBZqVWZyEVHhORvwEoYX7l5Bv2Z20QNLKGkwUNT/fpk+m+Mim7neE miFIpphLhSxBpa015JtQ2dN6Nm8R2AKCZjpxgPfg3ILwgsaR0vVkHBwBWM3MB7XJeLai OWtvpyivov5HWswA8slLm80Esmqg9pMhhG9li0GHRcTYI3Zv5P32KS0Tw3orGe/RpyOg Pahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Uz/9wao+"; 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 r1-20020ac85c81000000b004039e763238si1923912qta.42.2023.08.18.15.18.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Aug 2023 15:18:41 -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="Uz/9wao+"; 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 1qX7j5-000553-Bj; Fri, 18 Aug 2023 18:13:51 -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 1qX7j3-00053g-CQ for qemu-devel@nongnu.org; Fri, 18 Aug 2023 18:13:49 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qX7j1-0004QL-58 for qemu-devel@nongnu.org; Fri, 18 Aug 2023 18:13:49 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1bc3d94d40fso11714225ad.3 for ; Fri, 18 Aug 2023 15:13:46 -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=9xk1+CqOJWdeIJliIlUjmMI38qlOB1/l73hqKwcbuPU=; b=Uz/9wao+QN6xeWY7DgKT813uvyuyTxRiRY8Um5R8HtizH1fgH6ZXlL8sYx2ZRrjjNm FU9ldiOXCaaYfLL6x68s6ceagb2SzhUghYgofJnc164acVlsb2G1Th2tv7sn6kyrvGUz gn99I0MwjCRAP1VQlPq8fgv2r3/WGd/x0M3+Dsu9Y4vCjClKi5o0YRZz62WJtxQjw1xX /OI1u6wEEErzxMWV45Dv71H4MUpydTV7XTq1hSnk4/B6wtlJif+l9NL4XjmvMSzv4KS/ Kpgz754l07pq/yOGiPOtM81D1ozoegIAqiYPAeCYzsYMtF3ylW1cyYu+PM/lB+OKdyqI fE2Q== 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=9xk1+CqOJWdeIJliIlUjmMI38qlOB1/l73hqKwcbuPU=; b=Nlqnj6a1eMj7tKAl8R62BKoYx8iyvSaHr1+Ka7MquQuyPsjor5s9/XYenM3Zku8Hy0 Kz7cDhv3zuKyVt693SkGMCGQp6rlLF6FPaH8geOHlP1B+6ndW+huhXPFEzoEwnR/6WCc vvZeQ+ndq/3yBUSTXK1asVLx0wqt9D0RW8nbpJf7TK2G6LZO/maYsScWgL37PtRrSsPU 0FVF18Bv+twQ6we6LVkxpvsB2hWig23ymxNC+xhh3IC0+DcfehCjugIJsPItGJRyM4ZG dgPZzDF05reUlezGXJmRf/ieEcc2zEhwpgAwXTQbtWdAXv6RcKdjyrUoy/C3TMO5MoJ7 ll3A== X-Gm-Message-State: AOJu0YzES7krSr6nwnroK/DnDTZYNOWRqk5PB523C6usaIWr2gC7G8AG SaS39UoIty+VdtkSRnMeNn+Yty110x9+hj+DYuE= X-Received: by 2002:a17:903:18e:b0:1b8:9461:6729 with SMTP id z14-20020a170903018e00b001b894616729mr645690plg.2.1692396825911; Fri, 18 Aug 2023 15:13:45 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 15:13:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PATCH v2 20/23] tcg/i386: Use CMP+SBB in tcg_out_setcond Date: Fri, 18 Aug 2023 15:13:24 -0700 Message-Id: <20230818221327.150194-21-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::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 Use the carry bit to optimize some forms of setcond. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.c.inc | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index 1542afd94d..4d7b745a52 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -1531,6 +1531,56 @@ static void tcg_out_setcond(TCGContext *s, int rexw, TCGCond cond, TCGArg dest, TCGArg arg1, TCGArg arg2, int const_arg2) { + bool inv = false; + + switch (cond) { + case TCG_COND_NE: + inv = true; + /* fall through */ + case TCG_COND_EQ: + /* If arg2 is 0, convert to LTU/GEU vs 1. */ + if (const_arg2 && arg2 == 0) { + arg2 = 1; + goto do_ltu; + } + break; + + case TCG_COND_LEU: + inv = true; + /* fall through */ + case TCG_COND_GTU: + /* If arg2 is a register, swap for LTU/GEU. */ + if (!const_arg2) { + TCGReg t = arg1; + arg1 = arg2; + arg2 = t; + goto do_ltu; + } + break; + + case TCG_COND_GEU: + inv = true; + /* fall through */ + case TCG_COND_LTU: + do_ltu: + /* + * Relying on the carry bit, use SBB to produce -1 if LTU, 0 if GEU. + * We can then use NEG or INC to produce the desired result. + * This is always smaller than the SETCC expansion. + */ + tcg_out_cmp(s, arg1, arg2, const_arg2, rexw); + tgen_arithr(s, ARITH_SBB, dest, dest); /* T:-1 F:0 */ + if (inv) { + tgen_arithi(s, ARITH_ADD, dest, 1, 0); /* T:0 F:1 */ + } else { + tcg_out_modrm(s, OPC_GRP3_Ev, EXT3_NEG, dest); /* T:1 F:0 */ + } + return; + + default: + break; + } + 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);