From patchwork Tue Jan 16 03:45:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 124604 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp879481lje; Mon, 15 Jan 2018 19:55:33 -0800 (PST) X-Google-Smtp-Source: ACJfBovEJRPYZ7nTbsCvGgmZL5DeNdMHlUuFfX4AUXNgn4fnqFpBPfn2eaqbG1t/pGOueYkOqfiU X-Received: by 10.37.188.8 with SMTP id i8mr18786428ybh.404.1516074933853; Mon, 15 Jan 2018 19:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516074933; cv=none; d=google.com; s=arc-20160816; b=RbFiP32C0vspXpWa1IlMVUo+23tQcJHSvyVHpgWa8HNHM6tAgyB8d5vtk7kRFBU0UI xzbZZLjuSVi+NqnrajSglxBnqucEyW3oPhGBs5UIcKnLSw+YJcbHQGy57A8+AWMDzeVM n6ed0d5YBdF0WuoXQSslnpm0W8SHA4NFZGk3ZXlGGMzFyf10JtrrkpbRMSaaU2hVZAWq bh6qLeyuk+tK062IT/PGrkiAoD/9Kkx368unBhyf/Q1UycPrcdxNOXKmWmRyDK/A2U5E dHvn3ytJTmv3JlfHo80NLg6mwDa3WHAnKLYv4fE1xR7NlzCzsjIAY8N5ARDsZs29aaku EviQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=OTc2EOXjQ947rr0vX2JBzG3mJ1qYF2o6AyfM522fGus=; b=ZQ0QwwTCBccrZYivOYHaDlIr4K7DIvmVYODMbD2rfC2GU3Ph5O5Z+fOId/bUqFTR2o rrP+fnWfPG//j7yan98c8OSpzPZv9Wm4QNPnUYT7Z3/SDlmlMo6gAeUdX4Zn8++Yfd8+ zne74i7GVHERVsa0mY7E7v/fktcSZk585AklzRvEWuPUygK5eBMgJUgW0uqpIlDkpRih L8HDcvWLCjTlSe5H1FqSoOvVD9bGYujT70gmD9koLQ7aLsLZvL7sVVMaNX9EBgq1yEvX AuShinYW3a6lFuw2g6A3YGm8uiJHxYQCuexviUaYcfeOXqsJl/HxKgtRYSx63t85tHWz hjgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HEFNwfrM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l67si268498ywf.739.2018.01.15.19.55.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 15 Jan 2018 19:55:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HEFNwfrM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebILV-0005lB-58 for patch@linaro.org; Mon, 15 Jan 2018 22:55:33 -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) 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-Received: by 10.99.172.25 with SMTP id v25mr12066010pge.148.1516074309621; Mon, 15 Jan 2018 19:45:09 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- tcg/arm/tcg-target.inc.c | 97 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 32 deletions(-) -- 2.14.3 Reviewed-by: Peter Maydell 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, } } -#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 /* 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 = arg_ct->ct; + int ct = 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) } } +static TCGCond tcg_out_cmp2(TCGContext *s, const TCGArg *args, + const int *const_args) +{ + TCGReg al = args[0]; + TCGReg ah = args[1]; + TCGArg bl = args[2]; + TCGArg bh = args[3]; + TCGCond cond = args[4]; + int const_bl = const_args[2]; + int const_bh = 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" @@ -1964,22 +2013,6 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode 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 == a2 && a1 == a3, - * TCG_COND_NE --> (a0 != a2 && a1 == a3) || a1 != a3, - * TCG_COND_LT(U) --> (a0 < a2 && a1 == a3) || a1 < a3, - * TCG_COND_GE(U) --> (a0 >= a2 && a1 == a3) || (a1 >= a3 && a1 != a3), - * TCG_COND_LE(U) --> (a0 <= a2 && a1 == a3) || (a1 <= a3 && a1 != a3), - * TCG_COND_GT(U) --> (a0 > a2 && a1 == 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, TCGOpcode 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 = 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 = 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; @@ -2093,9 +2126,9 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) static const TCGTargetOpDef sub2 = { .args_ct_str = { "r", "r", "rI", "rI", "rIN", "rIK" } }; static const TCGTargetOpDef br2 - = { .args_ct_str = { "r", "r", "rIN", "rIN" } }; + = { .args_ct_str = { "r", "r", "rI", "rI" } }; static const TCGTargetOpDef setc2 - = { .args_ct_str = { "r", "r", "r", "rIN", "rIN" } }; + = { .args_ct_str = { "r", "r", "r", "rI", "rI" } }; switch (op) { case INDEX_op_goto_ptr: From patchwork Tue Jan 16 03:45:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 124608 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp880541lje; Mon, 15 Jan 2018 20:00:53 -0800 (PST) X-Google-Smtp-Source: ACJfBotOnkf661Scjib2u6+CLP0UvjzHwcc7bi4MjAqAy/7gWWSzuxWEme++yB4ohX5Dg/ND0QVm X-Received: by 10.129.237.20 with SMTP id k20mr20364310ywm.502.1516075253339; Mon, 15 Jan 2018 20:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516075253; cv=none; d=google.com; s=arc-20160816; b=wvngcoD3hcE5xiynhI3DODHzkjIJeGiCSutA3XslKFeY+Yjvy6AqxqQaVR0a6C4FD8 XZhY2zEFjl6UUJHzFaamNx0SAv1Wx2SWB2m5PhH3oomoz4OIS1H7aAkzy9rqpQklVIuk qmdoazp7SCeaH3z7PfEmmGbmPnaaY0rb58/T3/z7nWqU6fAuw84hHmrlv7TE/7RFNz/F zSNvQSJQ7aSfLsI1jJ45H1yH44hs9vV1PPuchJE46WSmdbk9JAtrj4cfGdeCVjjRrX5x v0FgWLO8EgW60jGSfqGA2xH+mojZC/u7/snPXP24N/RPrOJ022f7F0PUvCRRCQK365cM QzUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=kcgN9QYcD//AttPkT0aCUwSVYh6TH6r/0nhC8YAp0oU=; b=0oanb35m3F8uWt5bcic4rNUg/REEW/N1WfueDMEkyHpP+CwQqw0dm0yKtrO12CL6bW SVXfV+Cs2s/jhWVIuIWcJ3E9Cs1CKLB2+r95ZrRQZNxXGWJCmC3A5lqq+nM0I4kICqyg EhJSHM9LUlgXN0HshymAdv8qHWFLHCmVkD0/5D7hiyutmhHAqnfEL2yK8i2v+d0s3eOA ur0dOaf/eawZ8BMxrbt0rUR72H0ioqbQFMLUWHf2uCoy7mn6QqqtM8KoWl3PI/ekhWgj zm2iTZJeLv+jHT/3vkzDd+fI5HjumB2dl3IadklK+lHYbLaZk05/A0A0rv1t4gllLRfx x+wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Pkp8cJBo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h1si282736ywm.264.2018.01.15.20.00.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 15 Jan 2018 20:00:53 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Pkp8cJBo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebIQe-0001Fo-Ql for patch@linaro.org; Mon, 15 Jan 2018 23:00:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebIBW-0005z9-Gc 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 1ebIBV-00078s-Ju for qemu-devel@nongnu.org; Mon, 15 Jan 2018 22:45:14 -0500 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:39996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebIBV-00078J-Cb for qemu-devel@nongnu.org; Mon, 15 Jan 2018 22:45:13 -0500 Received: by mail-pl0-x241.google.com with SMTP id 62so5141614pld.7 for ; Mon, 15 Jan 2018 19:45:13 -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=kcgN9QYcD//AttPkT0aCUwSVYh6TH6r/0nhC8YAp0oU=; b=Pkp8cJBokYpTrsfpV+xgsLDuYKdlh3EFumUXJOSzCHcUBMG9k5KGrQvSYvVlyMjqcV /YDUBhGJUwQet0SJs0mXwxnfZ1lcCQXNorvV/C0HxpVrobShNtyWWOV1MOuui4WvtOcH fFcZyL3fep6Sq6x7I6up1Wq24paEcVp+sM8Lw= 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=kcgN9QYcD//AttPkT0aCUwSVYh6TH6r/0nhC8YAp0oU=; b=tYmPM9cRBbnP+Q1sPAy/OJVNPXV7Xswq6FK13txARATdp76kWa3ZEE0XPSmIYg6Sk/ TBSy5zVF6GezgS7PXNQXRlG/8jzQJaz4MKcNv7PY64FD2L07pU9gfqjrmyIcaxVxAT4r IH4wTELB7xqTXitQC58bZqOwds6Xfp9z8jfz3P8eF2NypkLhy+L8MF8/qr+pXP1RzPns O1xeEDhhqBXeNaaL11laEJoFE+DP9Vq2bYZb3ussoaDqDV1jGCCnc5Ltoa4+9NWW/eWo DzZ//sWvjqRxPVT3Pv/B1+u7tpUzk+0REBwre5ocxW2IwWQTZBuw+pysBMowoSEhMF1K lRWg== X-Gm-Message-State: AKGB3mKG0HKZ0iwZIiJtLzJO8hTgob+8zfGad9qpaaXuf9dJED2ZtJbO Kn4QB1MY3wNCXssoujOE2HvZrhlt2gE= X-Received: by 10.159.252.197 with SMTP id o5mr26434311pls.67.1516074312100; Mon, 15 Jan 2018 19:45:12 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jan 2018 19:45:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 15 Jan 2018 19:45:03 -0800 Message-Id: <20180116034503.31926-3-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:c01::241 Subject: [Qemu-devel] [PATCH v2 2/4] tcg/arm: Support tlb offsets larger than 64k 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" AArch64 with SVE has an offset of 80k to the 8th TLB. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) -- 2.14.3 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 0ff283d84f..8f5d4f208d 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1246,12 +1246,6 @@ static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg, /* We're expecting to use an 8-bit immediate and to mask. */ QEMU_BUILD_BUG_ON(CPU_TLB_BITS > 8); -/* We're expecting to use an 8-bit immediate add + 8-bit ldrd offset. - Using the offset of the second entry in the last tlb table ensures - that we can index all of the elements of the first entry. */ -QEMU_BUILD_BUG_ON(offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) - > 0xffff); - /* Load and compare a TLB entry, leaving the flags set. Returns the register containing the addend of the tlb entry. Clobbers R0, R1, R2, TMP. */ @@ -1264,6 +1258,7 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, ? offsetof(CPUArchState, tlb_table[mem_index][0].addr_read) : offsetof(CPUArchState, tlb_table[mem_index][0].addr_write)); int add_off = offsetof(CPUArchState, tlb_table[mem_index][0].addend); + int mask_off; unsigned s_bits = opc & MO_SIZE; unsigned a_bits = get_alignment_bits(opc); @@ -1295,16 +1290,25 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); } - /* We checked that the offset is contained within 16 bits above. */ - if (add_off > 0xfff - || (use_armv6_instructions && TARGET_LONG_BITS == 64 - && cmp_off > 0xff)) { + /* Add portions of the offset until the memory access is in range. + * If we plan on using ldrd, reduce to an 8-bit offset; otherwise + * we can use a 12-bit offset. */ + if (use_armv6_instructions && TARGET_LONG_BITS == 64) { + mask_off = 0xff; + } else { + mask_off = 0xfff; + } + while (cmp_off > mask_off) { + int shift = ctz32(cmp_off & ~mask_off) & ~1; + int rot = ((32 - shift) << 7) & 0xf00; + int addend = cmp_off & (0xff << shift); tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R2, base, - (24 << 7) | (cmp_off >> 8)); + rot | ((cmp_off >> shift) & 0xff)); base = TCG_REG_R2; - add_off -= cmp_off & 0xff00; - cmp_off &= 0xff; + add_off -= addend; + cmp_off -= addend; } + if (!use_armv7_instructions) { tcg_out_dat_imm(s, COND_AL, ARITH_AND, TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1);