From patchwork Sat May 6 07:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 679569 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp744743wrs; Sat, 6 May 2023 00:25:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pLL1wDUjT33v1yIzS0X5LhCrLneyCoT1AhBRA6PQ45ifbG1SkZ6644LKwJsrOGBcREHft X-Received: by 2002:ac8:59ca:0:b0:3ef:2199:1a79 with SMTP id f10-20020ac859ca000000b003ef21991a79mr6361833qtf.5.1683357921504; Sat, 06 May 2023 00:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683357921; cv=none; d=google.com; s=arc-20160816; b=MYURHrcb2vScLsgK9/jv6RfJBeha9aqVPtOPwTxsBujYN+HAMo6oaL2LpKjU32ge+z H9z/I8rCCOVhibK0Ub7mWElcldGq4EkRyrgKdPXD2pB6E7hQthCitdARLp3VkW5XrIax qE5vTnm1kxmLwJ1D2T7T5+ouEDVJGOqfmWRIstN31/CWEOiG7enuY0rgxNkZSD5wjZ9Q L4tDVD25nOUcOdlmYQ+EV9bBAyHcNdngFpr/sdM9q+9/Xgck/kjJF6UQntP22HWmeKgB KklU7bUMogF2FDKQTtpmLLWm138B/MoI78HZHYeOdYhUz9QAH2a9dvqRlz7k0JcBC0jg tDMw== 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=64H1HdxJ2Vo9fMDDBGxTfjpGZYN3L1dEu1eUYP7zZpo=; b=yyqum8CsU9D1Q+6zMnyxmpPeDvhN7bx/J31G7dRjVzOTl8knf8gdqJlr0agBJNpyNA /EJRj0NwP6wlMDRS4RTR9deFEtOUFXnfUNN6ZVIbuSWnhCpL2ZV8UxWEH2C0jNEkRyfz l/J0dhMPoPKYIwyWAIkDIxCJVQ1RaNZvCh2dhv0qLCF+Qc4flf8Pbud6vxwPcFDaSWbR uVMihSouAf6H7nnDvdoTw4j0ok+lJd/fKHzo2JC0k6fPVZS27fgubF0oeQ0zToJOS9nP ZtD9XwrkOQZf/PDPo9Vr7vKAPQy46kZoPjXw0r2UALY17Ja9lhpDcHeL2mMwOPNC3CZH OXHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ky2YCrj7; 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 os6-20020a05620a810600b0074e090aeefasi1237489qkn.712.2023.05.06.00.25.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 06 May 2023 00:25:21 -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=ky2YCrj7; 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 1pvCGF-0004wL-KR; Sat, 06 May 2023 03:23:19 -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 1pvCGE-0004sT-31 for qemu-devel@nongnu.org; Sat, 06 May 2023 03:23:18 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pvCFr-0004Tn-1N for qemu-devel@nongnu.org; Sat, 06 May 2023 03:23:16 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-30639daee76so1725661f8f.1 for ; Sat, 06 May 2023 00:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683357773; x=1685949773; 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=64H1HdxJ2Vo9fMDDBGxTfjpGZYN3L1dEu1eUYP7zZpo=; b=ky2YCrj7nprVSv+K8+hY7vYElXahHAbysB5tyFC89LHGUxORGeWj+oLX8m9pzG6kS5 m6pGvcdZjKKtCZ6YjOVS83sAbUf4eXoeFNHbnLsLs/qfb6gpP7Ag4e+yC4ZxchR5V1lI D97gm72qSPsgcss/pA/gp9GWJHnJaO1v7E9aKTl/LNBHj6FrbLg++1ZNviZXRt5Bm4Xb Rd0dASC4qerJXjcdh6w3yaaeQr75qKmR3rVLXu4kkObz7app4mMDYBmY0b7Z4hy2OOdg FKbcEDdGTzbQpFgUvrVw0RL+m7B2uTDJxZTSKBNm7puMrXbMK948ScX9JsBke0mcRAw8 uxwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683357773; x=1685949773; 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=64H1HdxJ2Vo9fMDDBGxTfjpGZYN3L1dEu1eUYP7zZpo=; b=jhgNjfgPhaRwRh0wbyzxBB39X7cXBG0f1ZnhSXECEN8V4oVNI0TFpTtSYVmtkdD3Sr 7soUuXd/PK7c2zzmditz8Hx4OGM6r63RkEjkj5wQatTHKlnWE3KkseQeyzEuJEMBJ0vc tOx7m0ckLAtf4qvazqfCwD2Et1uSTI4pF8ZBS2zBICPgxPQrIAp7IiILajo1b3f40k2j RuXMutU0yF8yQp0zVPm0JL4VMlHaWV9zWNJYs2FIHghLCtojFTyUzjMIgW8kAVtudibm GzJhybagYSswMcz8PJ83GzJN7k+ZNPPAtQzCvLfP0QGeOBSjpvVX59w85/vgtyPfXYyB DLug== X-Gm-Message-State: AC+VfDwDwl4+PXUh6tx7t2EnA10uvDhok/Me1N9D8uhGxjNMEyRsJqNb KOs1luyjS3JviM/A+hZluDOWzySpekZKwm2l/9HpMQ== X-Received: by 2002:adf:e80e:0:b0:2f9:85ee:e031 with SMTP id o14-20020adfe80e000000b002f985eee031mr2866309wrm.26.1683357773603; Sat, 06 May 2023 00:22:53 -0700 (PDT) Received: from stoup.. ([212.241.182.8]) by smtp.gmail.com with ESMTPSA id x9-20020adfec09000000b002faaa9a1721sm4481223wrn.58.2023.05.06.00.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 00:22:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, gaosong@loongson.cn, philmd@linaro.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v5 22/30] tcg/mips: Reorg tlb load within prepare_host_addr Date: Sat, 6 May 2023 08:22:27 +0100 Message-Id: <20230506072235.597467-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230506072235.597467-1-richard.henderson@linaro.org> References: <20230506072235.597467-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 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 Compare the address vs the tlb entry with sign-extended values. This simplifies the page+alignment mask constant, and the generation of the last byte address for the misaligned test. Move the tlb addend load up, and the zero-extension down. This frees up a register, which allows us use TMP3 as the returned base address register instead of A0, which we were using as a 5th temporary. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- tcg/mips/tcg-target.c.inc | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc index 31d58e1977..695c137023 100644 --- a/tcg/mips/tcg-target.c.inc +++ b/tcg/mips/tcg-target.c.inc @@ -370,6 +370,8 @@ typedef enum { ALIAS_PADDI = sizeof(void *) == 4 ? OPC_ADDIU : OPC_DADDIU, ALIAS_TSRL = TARGET_LONG_BITS == 32 || TCG_TARGET_REG_BITS == 32 ? OPC_SRL : OPC_DSRL, + ALIAS_TADDI = TARGET_LONG_BITS == 32 || TCG_TARGET_REG_BITS == 32 + ? OPC_ADDIU : OPC_DADDIU, } MIPSInsn; /* @@ -1263,14 +1265,12 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, int add_off = offsetof(CPUTLBEntry, addend); int cmp_off = is_ld ? offsetof(CPUTLBEntry, addr_read) : offsetof(CPUTLBEntry, addr_write); - target_ulong tlb_mask; ldst = new_ldst_label(s); ldst->is_ld = is_ld; ldst->oi = oi; ldst->addrlo_reg = addrlo; ldst->addrhi_reg = addrhi; - base = TCG_REG_A0; /* Load tlb_mask[mmu_idx] and tlb_table[mmu_idx]. */ QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0); @@ -1290,15 +1290,12 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) { tcg_out_ldst(s, OPC_LW, TCG_TMP0, TCG_TMP3, cmp_off + LO_OFF); } else { - tcg_out_ldst(s, (TARGET_LONG_BITS == 64 ? OPC_LD - : TCG_TARGET_REG_BITS == 64 ? OPC_LWU : OPC_LW), - TCG_TMP0, TCG_TMP3, cmp_off); + tcg_out_ld(s, TCG_TYPE_TL, TCG_TMP0, TCG_TMP3, cmp_off); } - /* Zero extend a 32-bit guest address for a 64-bit host. */ - if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) { - tcg_out_ext32u(s, base, addrlo); - addrlo = base; + if (TCG_TARGET_REG_BITS >= TARGET_LONG_BITS) { + /* Load the tlb addend for the fast path. */ + tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP3, TCG_TMP3, add_off); } /* @@ -1306,18 +1303,18 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, * For unaligned accesses, compare against the end of the access to * verify that it does not cross a page boundary. */ - tlb_mask = (target_ulong)TARGET_PAGE_MASK | a_mask; - tcg_out_movi(s, TCG_TYPE_I32, TCG_TMP1, tlb_mask); - if (a_mask >= s_mask) { - tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, addrlo); - } else { - tcg_out_opc_imm(s, ALIAS_PADDI, TCG_TMP2, addrlo, s_mask - a_mask); + tcg_out_movi(s, TCG_TYPE_TL, TCG_TMP1, TARGET_PAGE_MASK | a_mask); + if (a_mask < s_mask) { + tcg_out_opc_imm(s, ALIAS_TADDI, TCG_TMP2, addrlo, s_mask - a_mask); tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, TCG_TMP2); + } else { + tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, addrlo); } - if (TCG_TARGET_REG_BITS >= TARGET_LONG_BITS) { - /* Load the tlb addend for the fast path. */ - tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off); + /* Zero extend a 32-bit guest address for a 64-bit host. */ + if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) { + tcg_out_ext32u(s, TCG_TMP2, addrlo); + addrlo = TCG_TMP2; } ldst->label_ptr[0] = s->code_ptr; @@ -1329,14 +1326,15 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, tcg_out_ldst(s, OPC_LW, TCG_TMP0, TCG_TMP3, cmp_off + HI_OFF); /* Load the tlb addend for the fast path. */ - tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off); + tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP3, TCG_TMP3, add_off); ldst->label_ptr[1] = s->code_ptr; tcg_out_opc_br(s, OPC_BNE, addrhi, TCG_TMP0); } /* delay slot */ - tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_TMP2, addrlo); + base = TCG_TMP3; + tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_TMP3, addrlo); #else if (a_mask && (use_mips32r6_instructions || a_bits != s_bits)) { ldst = new_ldst_label(s);