From nobody Tue Oct 28 01:56:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516075010063571.5636848612419; Mon, 15 Jan 2018 19:56:50 -0800 (PST) Received: from localhost ([::1]:59836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebIMj-0006yT-7Z for importer@patchew.org; Mon, 15 Jan 2018 22:56:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebIBW-0005yu-8l for qemu-devel@nongnu.org; Mon, 15 Jan 2018 22:45:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebIBT-00076f-8O for qemu-devel@nongnu.org; Mon, 15 Jan 2018 22:45:14 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:41441) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebIBT-00075y-13 for qemu-devel@nongnu.org; Mon, 15 Jan 2018 22:45:11 -0500 Received: by mail-pg0-x241.google.com with SMTP id 136so8296275pgd.8 for ; Mon, 15 Jan 2018 19:45:10 -0800 (PST) Received: from cloudburst.twiddle.net.com (24-181-135-63.dhcp.knwc.wa.charter.com. [24.181.135.63]) by smtp.gmail.com with ESMTPSA id z19sm1139528pfh.185.2018.01.15.19.45.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jan 2018 19:45:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OTc2EOXjQ947rr0vX2JBzG3mJ1qYF2o6AyfM522fGus=; b=HEFNwfrMGSTAeOMwIaGUlguIUE6LS7yDiIW9zTF4z/SUkhBtP3RSU5pUtxRiJLoW/X iTvRSeCmMYsiAsUTPxtzphPIuvQfprqP8B+GueQnII8iEqUytmtYrHp9RLWRxyyFFjGE ztdI9qjzglmoP4RhX+6W9hlvvpWiSeDkf6OLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OTc2EOXjQ947rr0vX2JBzG3mJ1qYF2o6AyfM522fGus=; b=DWwMLePzBrBIBAOSIXPhBwamq5ODLRoRv7xX9Kc3kln1kjEs8gISijERlRMeWVJAaU QOqyIgFSyBGayn48R0Yhii6BlFbsqRyNsjmHbkpHpYhUm77juYOQ6AaCjGajEfqVzGXZ ZNtFvzXTAJUVY9eCdMGH+BrzkEk2ThnPkQs1lgxKSmy5tfev8asvwVf7j97Yp44xHVzp jwKMCLCHv/knMqIJneFUOSg4SLiVGr5mL8PWPTuYL4HX2elCgZYaBxvwLkdNFzIcCTsl DVdxwnQR+5LXhbUQXRMnXX9r1ASPmgkiXH7a0SLfiFXSI1n4T90MbeSrEpdL4KjExbpi 2jXg== X-Gm-Message-State: AKwxytfkQJZTe2FMzumwBeiysoUhuoRD8Ij3snVNHh/rS2H9c4vgk2xi yFgTyNzanJ0GzMaRIWI+4fFs1WZdxjw= X-Google-Smtp-Source: ACJfBov37yYP/WB6x4jKe1JfXbTTiCLMc5ava6jGCI8YwOU4oAdUa0VwtT0dKEUDsK/StefqzPsJQg== X-Received: by 10.99.172.25 with SMTP id v25mr12066010pge.148.1516074309621; Mon, 15 Jan 2018 19:45:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 15 Jan 2018 19:45:02 -0800 Message-Id: <20180116034503.31926-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180116034503.31926-1-richard.henderson@linaro.org> References: <20180116034503.31926-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v2 1/4] tcg/arm: Fix double-word comparisons X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The code sequence we were generating was only good for unsigned comparisons. For signed comparisions, use the sequence from gcc. Fixes booting of ppc64 firmware, with a patch changing the code sequence for ppc comparisons. Tested-by: Michael Roth Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- tcg/arm/tcg-target.inc.c | 97 ++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 98a12535a5..0ff283d84f 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -239,10 +239,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int = type, } } =20 -#define TCG_CT_CONST_ARM 0x100 -#define TCG_CT_CONST_INV 0x200 -#define TCG_CT_CONST_NEG 0x400 -#define TCG_CT_CONST_ZERO 0x800 +#define TCG_CT_CONST_ARM 0x0100 +#define TCG_CT_CONST_INV 0x0200 +#define TCG_CT_CONST_NEG 0x0400 +#define TCG_CT_CONST_ZERO 0x1000 =20 /* parse target specific constraints */ static const char *target_parse_constraint(TCGArgConstraint *ct, @@ -351,8 +351,7 @@ static inline int check_fit_imm(uint32_t imm) static inline int tcg_target_const_match(tcg_target_long val, TCGType type, const TCGArgConstraint *arg_ct) { - int ct; - ct =3D arg_ct->ct; + int ct =3D arg_ct->ct; if (ct & TCG_CT_CONST) { return 1; } else if ((ct & TCG_CT_CONST_ARM) && check_fit_imm(val)) { @@ -1103,6 +1102,56 @@ static inline void tcg_out_mb(TCGContext *s, TCGArg = a0) } } =20 +static TCGCond tcg_out_cmp2(TCGContext *s, const TCGArg *args, + const int *const_args) +{ + TCGReg al =3D args[0]; + TCGReg ah =3D args[1]; + TCGArg bl =3D args[2]; + TCGArg bh =3D args[3]; + TCGCond cond =3D args[4]; + int const_bl =3D const_args[2]; + int const_bh =3D const_args[3]; + + switch (cond) { + case TCG_COND_EQ: + case TCG_COND_NE: + case TCG_COND_LTU: + case TCG_COND_LEU: + case TCG_COND_GTU: + case TCG_COND_GEU: + /* We perform a conditional comparision. If the high half is + equal, then overwrite the flags with the comparison of the + low half. The resulting flags cover the whole. */ + tcg_out_dat_rI(s, COND_AL, ARITH_CMP, 0, ah, bh, const_bh); + tcg_out_dat_rI(s, COND_EQ, ARITH_CMP, 0, al, bl, const_bl); + return cond; + + case TCG_COND_LT: + case TCG_COND_GE: + /* We perform a double-word subtraction and examine the result. + We do not actually need the result of the subtract, so the + low part "subtract" is a compare. For the high half we have + no choice but to compute into a temporary. */ + tcg_out_dat_rI(s, COND_AL, ARITH_CMP, 0, al, bl, const_bl); + tcg_out_dat_rI(s, COND_AL, ARITH_SBC | TO_CPSR, + TCG_REG_TMP, ah, bh, const_bh); + return cond; + + case TCG_COND_LE: + case TCG_COND_GT: + /* Similar, but with swapped arguments, via reversed subtract. */ + tcg_out_dat_rI(s, COND_AL, ARITH_RSB | TO_CPSR, + TCG_REG_TMP, al, bl, const_bl); + tcg_out_dat_rI(s, COND_AL, ARITH_RSC | TO_CPSR, + TCG_REG_TMP, ah, bh, const_bh); + return tcg_swap_cond(cond); + + default: + g_assert_not_reached(); + } +} + #ifdef CONFIG_SOFTMMU #include "tcg-ldst.inc.c" =20 @@ -1964,22 +2013,6 @@ static inline void tcg_out_op(TCGContext *s, TCGOpco= de opc, tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[2]], arg_label(args[3])); break; - case INDEX_op_brcond2_i32: - /* The resulting conditions are: - * TCG_COND_EQ --> a0 =3D=3D a2 && a1 =3D=3D a3, - * TCG_COND_NE --> (a0 !=3D a2 && a1 =3D=3D a3) || a1 !=3D a3, - * TCG_COND_LT(U) --> (a0 < a2 && a1 =3D=3D a3) || a1 < a3, - * TCG_COND_GE(U) --> (a0 >=3D a2 && a1 =3D=3D a3) || (a1 >=3D a3 = && a1 !=3D a3), - * TCG_COND_LE(U) --> (a0 <=3D a2 && a1 =3D=3D a3) || (a1 <=3D a3 = && a1 !=3D a3), - * TCG_COND_GT(U) --> (a0 > a2 && a1 =3D=3D a3) || a1 > a3, - */ - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[1], args[3], const_args[3]); - tcg_out_dat_rIN(s, COND_EQ, ARITH_CMP, ARITH_CMN, 0, - args[0], args[2], const_args[2]); - tcg_out_goto_label(s, tcg_cond_to_arm_cond[args[4]], - arg_label(args[5])); - break; case INDEX_op_setcond_i32: tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, args[1], args[2], const_args[2]); @@ -1988,15 +2021,15 @@ static inline void tcg_out_op(TCGContext *s, TCGOpc= ode opc, tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[3])], ARITH_MOV, args[0], 0, 0); break; + + case INDEX_op_brcond2_i32: + c =3D tcg_out_cmp2(s, args, const_args); + tcg_out_goto_label(s, tcg_cond_to_arm_cond[c], arg_label(args[5])); + break; case INDEX_op_setcond2_i32: - /* See brcond2_i32 comment */ - tcg_out_dat_rIN(s, COND_AL, ARITH_CMP, ARITH_CMN, 0, - args[2], args[4], const_args[4]); - tcg_out_dat_rIN(s, COND_EQ, ARITH_CMP, ARITH_CMN, 0, - args[1], args[3], const_args[3]); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[args[5]], - ARITH_MOV, args[0], 0, 1); - tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(args[5])], + c =3D tcg_out_cmp2(s, args + 1, const_args + 1); + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[c], ARITH_MOV, args[0], 0,= 1); + tcg_out_dat_imm(s, tcg_cond_to_arm_cond[tcg_invert_cond(c)], ARITH_MOV, args[0], 0, 0); break; =20 @@ -2093,9 +2126,9 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) static const TCGTargetOpDef sub2 =3D { .args_ct_str =3D { "r", "r", "rI", "rI", "rIN", "rIK" } }; static const TCGTargetOpDef br2 - =3D { .args_ct_str =3D { "r", "r", "rIN", "rIN" } }; + =3D { .args_ct_str =3D { "r", "r", "rI", "rI" } }; static const TCGTargetOpDef setc2 - =3D { .args_ct_str =3D { "r", "r", "r", "rIN", "rIN" } }; + =3D { .args_ct_str =3D { "r", "r", "r", "rI", "rI" } }; =20 switch (op) { case INDEX_op_goto_ptr: --=20 2.14.3