From patchwork Fri Feb 11 01:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 541776 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp2722260imo; Thu, 10 Feb 2022 18:12:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzihitE2CBIbdRshIiuGsYAvT/QjM/2AxiMrn+EcbOiA/T3oF6ypPQEtzzAkiVuTn9t9cpW X-Received: by 2002:a25:9907:: with SMTP id z7mr10262760ybn.679.1644545526111; Thu, 10 Feb 2022 18:12:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644545526; cv=none; d=google.com; s=arc-20160816; b=Umw6YFfXJzNqNrnbB1IKueuqqugUagRqjuedubMTZKCFG5TC+92UD8NCK6jcfFLBqq ZZRxoYb0Fo6V5xfuEpBhgtvk95mfJ7tj5Ad2lJJaIaBeynCNh/CvIUgby1saFPzDoIAZ flm6OAgFyApWcLiS3snwFWZil2JMC0C3tCXlRQ49suKoMa2uRBQwqyj1Ul4Wz0b8GeSn HVZuF4sUQZpd7vcmIXP1eE1lEprsxNFKC54xrcEuov+sdUzMFcNOuTj1hZVYLA7UQHsF eYXtix0Tt4a6dhblH5oPT3K/gCAE+c9EPHk0L/uHh91tf/+R7N4kOpLL6DqwEgnqb4g1 MmmQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=tw347i7UUzkCL2aGKWmeY7B5v0kBuROLRWuELxPT4a8=; b=Rc03MMywZ4ogECCnTi1hdebLDwgpbpeO1nY8+a+b+uawzPeOswqhNmO/E2DFEI9z6T i5uwX5YKPvm+ZuCrFJRA8YBJKoGpR1SJg6aXsnlCE3PanFt9B+flbqdJDGD7Q8Oa8+46 TsTo0u6M5/LiB8rnfslep2RGrPC6TB5Qxqc+q9LPVU5UkYIGQ27NuWw2Rxtr5C4sl+90 oehYvguRkl3agfy6/oDz83Xi+x3a3De9JYODPQUAR4QcZNZy9M6ODIltWcjP4XGZ6rP+ rxepMLVIA+GHOo4QOMsdUfILLjyT43fwFSz+b8RRUUoG59/ti0AawY8YCsHBLpGLwa9E G20Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cVsgXvF9; 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 e64si11372806ywa.66.2022.02.10.18.12.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Feb 2022 18:12:06 -0800 (PST) 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=cVsgXvF9; 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]:36394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nILPp-0005qy-LV for patch@linaro.org; Thu, 10 Feb 2022 21:12:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nIKo9-0005hA-9e for qemu-devel@nongnu.org; Thu, 10 Feb 2022 20:33:09 -0500 Received: from [2607:f8b0:4864:20::62d] (port=42610 helo=mail-pl1-x62d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nIKo0-0007V5-F2 for qemu-devel@nongnu.org; Thu, 10 Feb 2022 20:33:08 -0500 Received: by mail-pl1-x62d.google.com with SMTP id z17so3402730plb.9 for ; Thu, 10 Feb 2022 17:32:56 -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 :mime-version:content-transfer-encoding; bh=tw347i7UUzkCL2aGKWmeY7B5v0kBuROLRWuELxPT4a8=; b=cVsgXvF9zkl1aIGHj9csl8mcf3sc6EVEIOdsgdxAYHrYx3gsJxL2SIPHj6svbAOAYR g1/yjOHz4UuvX+AuLTiJK1jS+v9i18X5i4KjCWRuC2MbleE27Ygfcl5CThGXyBPHuid1 5aYoU1jtsNbjJRIYPAYFdXowPODsjaU62wGhIOgPJTi0KV4Ys76bEyJiQ+2ADkKkIwvc SUm3K3AQE+dNWbmErjNytdfVsQ8a45xYW46qYZJMq9+IT2fJppDxtvgvvZG4kggmgQ+9 k5McsFlCR8yAEGloCYSoYG7XlSxueziLW7xDKTqrwX6PoywVC7YECoy8byQOTke1iDWA b+MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tw347i7UUzkCL2aGKWmeY7B5v0kBuROLRWuELxPT4a8=; b=EtkGrlTxeFGa4iMVlPm0Xgh5Oq9AaZXXQOrP1URIr5ve/T0vlTWd05h7oJrreISuv1 7QoD39rSJkSGm5jvtbPVASa/Tgi/DrVk1EnEeADOzuPZbUk8Z5F2PSXsXZE9mNBzbgdB rtTYmJ92jSNzdgnVPkztCcVESNn61NKETq8MxGqU0geL2mxcJjLTaPBjeedk4eVpbyVX 98KpZrNUyiJgEpvfQ0LlEBU2CbylYFEW4UEGbs5QhCiDy3bKE6kv5VqcW6Lz735SohVO Ib6wB3x0OuwEO+eSoX7wc/N4ey4KcDClSNXdWi1Byx3zVrGjwn9ek7garh/50ltDZvE+ zO9g== X-Gm-Message-State: AOAM530GSdfFWxGJ5ZdOfmC7At/Xuow1bg6kYkiC4qFPkx7L4pAhRio8 cp5AGmVhSc9agNl40abZFi+55U1slIonfBms X-Received: by 2002:a17:902:b90a:: with SMTP id bf10mr10266713plb.36.1644543175639; Thu, 10 Feb 2022 17:32:55 -0800 (PST) Received: from localhost.localdomain ([124.189.222.164]) by smtp.gmail.com with ESMTPSA id h5sm25738788pfi.111.2022.02.10.17.32.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 17:32:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 32/34] tcg/sparc: Add tcg_out_jmpl_const for better tail calls Date: Fri, 11 Feb 2022 12:30:57 +1100 Message-Id: <20220211013059.17994-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220211013059.17994-1-richard.henderson@linaro.org> References: <20220211013059.17994-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::62d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Due to mapping changes, we now rarely place the code_gen_buffer near the main executable. Which means that direct calls will now rarely be in range. So, always use indirect calls for tail calls, which allows us to avoid clobbering %o7, and therefore we need not save and restore it. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/sparc/tcg-target.c.inc | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc index e78945d153..646bb462c3 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -858,6 +858,19 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh, tcg_out_mov(s, TCG_TYPE_I64, rl, tmp); } +static void tcg_out_jmpl_const(TCGContext *s, const tcg_insn_unit *dest, + bool in_prologue, bool tail_call) +{ + uintptr_t desti = (uintptr_t)dest; + + /* Be careful not to clobber %o7 for a tail call. */ + tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1, + desti & ~0xfff, in_prologue, + tail_call ? TCG_REG_G2 : TCG_REG_O7); + tcg_out_arithi(s, tail_call ? TCG_REG_G0 : TCG_REG_O7, + TCG_REG_T1, desti & 0xfff, JMPL); +} + static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest, bool in_prologue) { @@ -866,10 +879,7 @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest, if (disp == (int32_t)disp) { tcg_out32(s, CALL | (uint32_t)disp >> 2); } else { - uintptr_t desti = (uintptr_t)dest; - tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1, - desti & ~0xfff, in_prologue, TCG_REG_O7); - tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL); + tcg_out_jmpl_const(s, dest, in_prologue, false); } } @@ -960,11 +970,10 @@ static void build_trampolines(TCGContext *s) /* Set the retaddr operand. */ tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7); - /* Set the env operand. */ - tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0); /* Tail call. */ - tcg_out_call_nodelay(s, qemu_ld_helpers[i], true); - tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra); + tcg_out_jmpl_const(s, qemu_ld_helpers[i], true, true); + /* delay slot -- set the env argument */ + tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0); } for (i = 0; i < ARRAY_SIZE(qemu_st_helpers); ++i) { @@ -1006,14 +1015,14 @@ static void build_trampolines(TCGContext *s) if (ra >= TCG_REG_O6) { tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_O7, TCG_REG_CALL_STACK, TCG_TARGET_CALL_STACK_OFFSET); - ra = TCG_REG_G1; + } else { + tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7); } - tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7); - /* Set the env operand. */ - tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0); + /* Tail call. */ - tcg_out_call_nodelay(s, qemu_st_helpers[i], true); - tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra); + tcg_out_jmpl_const(s, qemu_st_helpers[i], true, true); + /* delay slot -- set the env argument */ + tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0); } } #endif