From patchwork Fri Feb 4 07:00:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 539864 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3039583imr; Thu, 3 Feb 2022 23:41:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsN5iMbsUJlV5PnZeFanvWKcvtKW01mkZcu+WUrtAV9pbQaT82Il7aONHCEfsBCSxiG2dQ X-Received: by 2002:a05:622a:13cb:: with SMTP id p11mr1158836qtk.210.1643960461709; Thu, 03 Feb 2022 23:41:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643960461; cv=none; d=google.com; s=arc-20160816; b=ScoW1+D2yIYV6Sozcr4s4fevMxvC9/DSb+YXDxb6U2CKNi1aw2xmszNptXxQbBsBGb 5CYjw1/FhKa/nKYPrY3mST5/My0rMhemw328B6IdOaFbaGO3ZPVATFkDqiRMqEwJ8qWS OBAwwOrzBUSJ0Bw8LYhu7FGXGMT/w9KXdNcPfdnB66ZoFhz2153ezVhih8gwaFUVDWli UplVowv0EH8ThRngloaZx13K5AzdObEvRBCVfkBJvwWNY3vJrFk+4JtsyjKyRiKODUjy Q+alEbe/7HsDESgJonI/3v2t+V/t5SyZMbldlKSvlxCMPV31wOl83HcgQHxxSDzfskCG G+QQ== 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=M0ZkQ1X6XeXxAobJERi5w3sTXAysUl6elMTzRVCZxPk=; b=k7gjVwDEhInCWKTznXGV3eWWvrOMKc10TnJ0ZyazEEZk6oZr9wJ3F5TGd9J4c0WGLO pnF5yfvCcoDGLiah7sf9vRM06beUfbcwmc+t30D4aS9U/9g3qMPDdY/sCmP8cDvIqkfB 3AFhMLnBjwX/wjicLk4gJBvyblLWWZCdRoot7ChxG4ZEQ8OShpM9+OO9lQTQcSJ8LKV/ qIQs1Lilu/sU7LR1Be0x8XrxuSGOERqLCTdxjZDkE3TFzqV6dVjYzd7g2JwmRJEIYz29 g24v4jwq7CmpgbnIyLWP42ka5G9bbqzdo7MtOdI8ZVN+Mt6Z7g6TGYb9joAwYcGTm5GZ hECA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J4CjSjDr; 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 z9si221789qtj.402.2022.02.03.23.41.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Feb 2022 23:41:01 -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=J4CjSjDr; 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]:34142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFtDD-0006xf-Q3 for patch@linaro.org; Fri, 04 Feb 2022 02:40:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFsaM-0006gv-CN for qemu-devel@nongnu.org; Fri, 04 Feb 2022 02:00:51 -0500 Received: from [2607:f8b0:4864:20::f2e] (port=42694 helo=mail-qv1-xf2e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nFsaH-0006UJ-OO for qemu-devel@nongnu.org; Fri, 04 Feb 2022 02:00:45 -0500 Received: by mail-qv1-xf2e.google.com with SMTP id k9so4637869qvv.9 for ; Thu, 03 Feb 2022 23:00:38 -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=M0ZkQ1X6XeXxAobJERi5w3sTXAysUl6elMTzRVCZxPk=; b=J4CjSjDrJ1yHaOHhu4o07+uQV9aRHBd19us2cPXqAC2n7F/Xu69tH7j5BfPfm7ndV9 IV0O2mswJYpRlIQcuPkqcBKZa+3Vq9Xc2L2mYpBa/jSPSQClBgS5AWxY7/VEK3JLUrI9 /NV53H0s9OMku7qN6ef1UaVr5wV48TaStWN862GoFLr9kYJKk1hvZAr1c+Yq35JzfreK yc7+I8UTjU2ipSmrsq9InMe7Fyd4ewNRIkYbVPgDx/lFejcFuu6Wa/phWu+dsOSiILqU ks+uumGnym54wAQOYrA5rIC8tWk0hzu0bCoBzbyeOpKw5JubnwbY1Lx+2ki7OCJwQFLO UXFg== 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=M0ZkQ1X6XeXxAobJERi5w3sTXAysUl6elMTzRVCZxPk=; b=XW5nXTwxgSxJ9J4lfXR6kCMHOYzQxHxVGsv1K4D9NuSUsnKuddwOyLBl1fueOfyBmS XYFmw6fsbBfDQ+wi6JsuXF17mPrXd67T2dR08Zf2Y15jHqL36lHkrFrUU9dUwWBXcMpJ ZfKRsBKQ/Ry9emBFx7/a3elIwXSfZcSSj1oZNPNIGqdW6H5vRgfG7/K1uQNzTZIjS681 /+f0SpvlLyxlSmM8AuKAp/x5Zl4ccGkFV/yF+gNym2GAt5UniYeYRqdbBN8DWYtrRNhq 1bXfBnJRsUmCRx2Id3zLPMyG04+5u1YC3VDn7dAOxd3CLa2eeXGmZicTT/gW16qgSmTu TBEQ== X-Gm-Message-State: AOAM533ZFsrpf/pAz046foi4E7xIZO7gS1LxjC/9ciwdjJrSDzEsJuZO TLOFt4bECq3qrpyKxslsIMOWTAqXjy3wUivO X-Received: by 2002:aa7:96c1:: with SMTP id h1mr1784274pfq.17.1643958026807; Thu, 03 Feb 2022 23:00:26 -0800 (PST) Received: from stoup.modem ([2001:8003:3a49:fd00:ed23:b22a:8415:8857]) by smtp.gmail.com with ESMTPSA id 9sm11808619pjg.50.2022.02.03.23.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 23:00:26 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 4/5] tcg/sparc: Add tcg_out_jmpl_const for better tail calls Date: Fri, 4 Feb 2022 18:00:10 +1100 Message-Id: <20220204070011.573941-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204070011.573941-1-richard.henderson@linaro.org> References: <20220204070011.573941-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f2e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2e; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2e.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: alex.bennee@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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 47bdf314a0..82a9d88816 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -845,6 +845,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) { @@ -853,10 +866,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); } } @@ -947,11 +957,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) { @@ -993,14 +1002,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