From patchwork Sun Feb 6 10:31:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 540402 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp4632384imr; Sun, 6 Feb 2022 02:40:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgukwU4NL75Z8yIqzIBGXXtIKuuk5kJF1gN2WesSQBp2fmaOEvk/st118nzEJxD9ubQ5gU X-Received: by 2002:a05:620a:1271:: with SMTP id b17mr3819276qkl.50.1644144017217; Sun, 06 Feb 2022 02:40:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644144017; cv=none; d=google.com; s=arc-20160816; b=0FdFF4aJx7aROJ+PbPxeQdMbzC+huMu5CMhrJzXGJ9ar+AhsfwUmd5p7wuGWUa7XCd 6JPG4I+el+C6Bj/EvRtndkMv2W03W1IScjJl17Yp9mK+/SVLEfFRujhrqI/tuzZ/whM2 5oj9KLatZfdR4y4OiXIKoGpknsfApvqPV6qwD71r/QuJcBIOoTkxJZRjdY4G4hAuDA3k ncUBukN8RvKFR3aOpgQmwgE+BRVupv5aKL8u4AInPb9feFEIU0IBc4QeiSVnNzAqR75x vlpp8RAf1+I9Dd9kFb1QsbOARv12r0ADZlRivnuC91lHQzmyr1iUoH2MWmDLYx/emVk2 wFcQ== 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=ImT7wzJBDrhz3ovMgkV3A0ihyEm0HORmcQXzqn89pPc=; b=IAz2YImg26ae44VPDzup+sXUUJoSEFcWq0RY3jnZT00gJlLCHzX/TIEfRqak7aV6aF sG92zV3hExIZiZbzFjuBbxVOJi44EBjh1oxy1C/c6oK+cRlujAi9Y5r4aG8fqk+5lrpy Xa8ulVQbIG9xKFVLci9pBdTvNXjjQcoO04V9/Hj49q/XZnVGSdllewBOYUTy/WFa9Lyv EJQoWFrhLX8YBWAAan3vDFihm3PpMyfUTYdRH7y3CejYdepbvaG0a3dVbN/FDH7sTF9Y vW/K2BcBvQQI/WiycfktGA2IJ1kPDvzEijgseOZGDd/ERLtccR7WEhemqXfT/KKPyXNO otEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uy6fJCUt; 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 21si1796800qty.602.2022.02.06.02.40.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Feb 2022 02:40:17 -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=Uy6fJCUt; 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]:39602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGexs-0004AH-Oo for patch@linaro.org; Sun, 06 Feb 2022 05:40:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGepr-0004YG-4P for qemu-devel@nongnu.org; Sun, 06 Feb 2022 05:31:59 -0500 Received: from [2607:f8b0:4864:20::1036] (port=41562 helo=mail-pj1-x1036.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGepo-0002P7-Po for qemu-devel@nongnu.org; Sun, 06 Feb 2022 05:31:58 -0500 Received: by mail-pj1-x1036.google.com with SMTP id r64-20020a17090a43c600b001b8854e682eso2682711pjg.0 for ; Sun, 06 Feb 2022 02:31: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=ImT7wzJBDrhz3ovMgkV3A0ihyEm0HORmcQXzqn89pPc=; b=Uy6fJCUthr+4oEllnEZR0mp72KfpTdEynQBulcNEnhgNPSJxQZrpz92f9Ybi6eGf8u OYkCifs/qPfqekTgTwjodAdFQOihPzYMEVkieTZnBnk6r8CKbFDQndQ9HxVWIC2xTTBT bs7DdzowX6W5WAIwe3VMlmSbyl+GU1EJT1gCix1tfsgXMwdobvcIZpwb/EsOD+zg3Hrv QB5yXGSCyJXJXOnBkxmO1L1BDAhQDOi+acv5mWt2VyGDCZY4cyZIryiESwR7KXGlgrT2 oGXok9x2Hdl0GhdUp4o3mUAPz2gBIkOKYfh7Gw4j7bfXnpfS85WCwH1SvN7p7ysSaV2T kLPQ== 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=ImT7wzJBDrhz3ovMgkV3A0ihyEm0HORmcQXzqn89pPc=; b=LYkHE7aeYjP2wWkLDP+Gb2yHS8cGFFtsWkbxBpzJV2ivmay4nnEFZ7j8RY2baBZbx2 k3uK03PVy/xt4Uy8XKlhovpIC2RMZ5DzeXrHHFHS7ny8RwLF9tmxsLk53hzbG6OMCP39 oXcFPc8yoYqQu4DJgh4X4w6EYVuM3kYXyPA3wQ5Ijmn40YttQL5vzLRW81MkU4nQHbcm 8Y3vPvh9H29KoLikBzJqhvYWkVf8Smbr0epUIQkeMLkirPxhdSrKPizptdMV3JtguiRw y+hpuskukcGKig4xIvxDrlWm47b5CluVVErj7cxI6AkJ7WZxv4i/l4iEAbYzNTa0pdXj eX6g== X-Gm-Message-State: AOAM532MWk1aJV2hnt7NQke9/T+9/VvebV1YmWqhlAjW57u3F5rg3AFT tR3yN5+GMGMovkmZcF5+clGVbPxItnoBCrFc X-Received: by 2002:a17:902:710c:: with SMTP id a12mr11515339pll.108.1644143515547; Sun, 06 Feb 2022 02:31:55 -0800 (PST) Received: from localhost.localdomain ([220.235.247.127]) by smtp.gmail.com with ESMTPSA id s2sm5605937pgl.21.2022.02.06.02.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 02:31:55 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 5/6] tcg/sparc: Add tcg_out_jmpl_const for better tail calls Date: Sun, 6 Feb 2022 21:31:37 +1100 Message-Id: <20220206103138.36105-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220206103138.36105-1-richard.henderson@linaro.org> References: <20220206103138.36105-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1036 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 074fb25af2..c81782d6ce 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -850,6 +850,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) { @@ -858,10 +871,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); } } @@ -952,11 +962,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) { @@ -998,14 +1007,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