From patchwork Tue Apr 11 01:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 672295 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:184:0:0:0:0 with SMTP id p4csp536211wrx; Mon, 10 Apr 2023 18:09:12 -0700 (PDT) X-Google-Smtp-Source: AKy350Ylhzx5pnR+wl3tnJvnHYAdqP8j3Vzbu7lm4kgANGuZYPf+2xNLwKs88NKdbo5URqK0ZxWc X-Received: by 2002:a05:6214:2128:b0:5b6:fbc5:fb43 with SMTP id r8-20020a056214212800b005b6fbc5fb43mr27244193qvc.30.1681175352580; Mon, 10 Apr 2023 18:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681175352; cv=none; d=google.com; s=arc-20160816; b=pAODMETYeTE9FSX08mNt+T+N3+R1FBjA0VB/LhfUBWiD3RpYnH22pkstsLVlEYafU0 +bzGpmqJ5+JbLGRZnjFDg27JsbPHoGPJftVpHJMLzdjzvtV5fl6JhuaDrpr0O0rLfnJp djcNG8g4gMStsY2v52cy2/ckqUFk0CL1v7O64fnwN7EErfCdS88wO/JaFW6IYOYvKGrV Pe1+3VvI/Ntyd2OfX8qwGRlOOMDvNL2hhyAdfqyUutbqtNCdMclTgTsTOlu/yHPTvYvA wFHnGRU9kwESGWAEKPBbGNwXYuRT+6K/SDpYaBRZ8uUI2mlxeNqvF1dbI05oglsohAxB 630w== 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=AN2+J7y7AxmNmsOMYHKyYOp9ao/8XF2uCunQYCIFC7g=; b=BzgDajESWkPR4m1li5kedsBw2mDZTBcDA7GKe7cJcUsTGNXE5/5lPc4100YAtRfk4H yTHoFliF5eFO1nUNzXcVlGo7UsswBWWkQQeqWEglI2u9WpWj05alnju6GAYUbw+6Ufgp SrL16BWE5wwhWGwrB8T9OqEyxRc1O/N48H0x5rS33ivdZ5VKfMjjgnfVPYw7jnmgXSw8 Zy4d+xcdFXNFIh69oPd2OphJG1jK/0849/nxZ42elWN3DFHkIf01+9DfSrXZ8yWxIEGt aN/M7FZnjw3CJQWwLquympZV6N1iL5xLqcbovqsGoBTKwrVnSn8a9uR1UxfAnKj/BAow V8sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="geTPEJL/"; 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 gc8-20020a056214230800b005ac4ea4e2b2si8309080qvb.109.2023.04.10.18.09.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Apr 2023 18:09:12 -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="geTPEJL/"; 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 1pm2TN-0007o6-Oj; Mon, 10 Apr 2023 21:07:01 -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 1pm2TB-0006Gk-39 for qemu-devel@nongnu.org; Mon, 10 Apr 2023 21:06:49 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pm2T8-0000rl-Kh for qemu-devel@nongnu.org; Mon, 10 Apr 2023 21:06:48 -0400 Received: by mail-pj1-x1029.google.com with SMTP id px4so4176489pjb.3 for ; Mon, 10 Apr 2023 18:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1681175206; 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=AN2+J7y7AxmNmsOMYHKyYOp9ao/8XF2uCunQYCIFC7g=; b=geTPEJL/CqqJwweR7DWtZ3K6wx20fayJsMnmwlJWS6hj6BeU0B3vNEO17KPzNw/cQx tLhYLGWAFsdzc5xm+UgdB9gbgdA9ZVlgrO4awMnX2bmmkP4Vh+6tWKUcvLqi96sE9V05 oC5BcVqUfV8A1kSjIPeTuTSyx5K3RYBIV3GzSQiB5PR5+fmmGG48ek1Nm44+z8YdTN8g 6Ol1cZoaFnVko5OAEcvjcxErN7pkZCZQ9BM5PpcQC51VzzFUT5WEmw7odJ/Ey8gcFBzC 8MyokTJq2G0NSVIBrMW1RCdoitW096/MhREYjCMTYYPAon1GJnkP1sN/ZukBfz8TcLTb ah7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681175206; 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=AN2+J7y7AxmNmsOMYHKyYOp9ao/8XF2uCunQYCIFC7g=; b=f9rMcYU9zkJE+ru/8+rXAuDW5KO1fHtjfCA569LjqsJI2cj4lQ/MbmyAoACHAAxFDy 06DqMtqreXHyVsUVu9TmGmXeArpU/ZEJhw9J5UHLH2+KuhQzwgI4IsOEmSf5j411i+rZ 9XBqBhDBhmfVL/R1iN99QXh41RI56cN58iaikFLQ889JNdQhpmmg1YXkChh17W6qUqbe zILg8fEHCPUbeOzbF7Uqy27xFIHS7yPKExr1P4oKsHFd1/sbbu/1YUtkk3QKvxEHbfaG P/VG+TIgAuPrKQynOMP/mqeXnqeNWTFGZGXj0DIlGwbdmRbZbusZT4z+d4KF9WISxFSy hWnw== X-Gm-Message-State: AAQBX9cK3rmKG4oNep4WDc+/b7qftSKAFgPqQS5pJsje9xv7t1oa/+hu xPYjmeKWWcDu7dky9pGnanlPJyaLeLwivWpcuvr8LQ== X-Received: by 2002:a05:6a20:af9e:b0:e0:316a:d62c with SMTP id ds30-20020a056a20af9e00b000e0316ad62cmr11861126pzb.60.1681175205827; Mon, 10 Apr 2023 18:06:45 -0700 (PDT) Received: from stoup.WiFi.IPv4InfoBelow (h146.238.133.40.static.ip.windstream.net. [40.133.238.146]) by smtp.gmail.com with ESMTPSA id s10-20020a65690a000000b0051b0e564963sm1320291pgq.49.2023.04.10.18.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 18:06:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-s390x@nongnu.org, qemu-riscv@nongnu.org, qemu-ppc@nongnu.org Subject: [PATCH v2 33/54] tcg: Introduce arg_slot_stk_ofs Date: Mon, 10 Apr 2023 18:04:51 -0700 Message-Id: <20230411010512.5375-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230411010512.5375-1-richard.henderson@linaro.org> References: <20230411010512.5375-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 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, SUSPICIOUS_RECIPS=2.51 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Unify all computation of argument stack offset in one function. This requires that we adjust ref_slot to be in the same units, by adding max_reg_slots during init_call_layout. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index fa28db0188..057423c121 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -816,6 +816,15 @@ static inline bool arg_slot_reg_p(unsigned arg_slot) return arg_slot < nreg; } +static inline int arg_slot_stk_ofs(unsigned arg_slot) +{ + unsigned max = TCG_STATIC_CALL_ARGS_SIZE / sizeof(tcg_target_long); + unsigned stk_slot = arg_slot - ARRAY_SIZE(tcg_target_call_iarg_regs); + + tcg_debug_assert(stk_slot < max); + return TCG_TARGET_CALL_STACK_OFFSET + stk_slot * sizeof(tcg_target_long); +} + typedef struct TCGCumulativeArgs { int arg_idx; /* tcg_gen_callN args[] */ int info_in_idx; /* TCGHelperInfo in[] */ @@ -1055,6 +1064,7 @@ static void init_call_layout(TCGHelperInfo *info) } } assert(ref_base + cum.ref_slot <= max_stk_slots); + ref_base += max_reg_slots; if (ref_base != 0) { for (int i = cum.info_in_idx - 1; i >= 0; --i) { @@ -4826,7 +4836,7 @@ static void load_arg_reg(TCGContext *s, TCGReg reg, TCGTemp *ts, } } -static void load_arg_stk(TCGContext *s, int stk_slot, TCGTemp *ts, +static void load_arg_stk(TCGContext *s, unsigned arg_slot, TCGTemp *ts, TCGRegSet allocated_regs) { /* @@ -4836,8 +4846,7 @@ static void load_arg_stk(TCGContext *s, int stk_slot, TCGTemp *ts, */ temp_load(s, ts, tcg_target_available_regs[ts->type], allocated_regs, 0); tcg_out_st(s, ts->type, ts->reg, TCG_REG_CALL_STACK, - TCG_TARGET_CALL_STACK_OFFSET + - stk_slot * sizeof(tcg_target_long)); + arg_slot_stk_ofs(arg_slot)); } static void load_arg_normal(TCGContext *s, const TCGCallArgumentLoc *l, @@ -4848,18 +4857,16 @@ static void load_arg_normal(TCGContext *s, const TCGCallArgumentLoc *l, load_arg_reg(s, reg, ts, *allocated_regs); tcg_regset_set_reg(*allocated_regs, reg); } else { - load_arg_stk(s, l->arg_slot - ARRAY_SIZE(tcg_target_call_iarg_regs), - ts, *allocated_regs); + load_arg_stk(s, l->arg_slot, ts, *allocated_regs); } } -static void load_arg_ref(TCGContext *s, int arg_slot, TCGReg ref_base, +static void load_arg_ref(TCGContext *s, unsigned arg_slot, TCGReg ref_base, intptr_t ref_off, TCGRegSet *allocated_regs) { TCGReg reg; - int stk_slot = arg_slot - ARRAY_SIZE(tcg_target_call_iarg_regs); - if (stk_slot < 0) { + if (arg_slot_reg_p(arg_slot)) { reg = tcg_target_call_iarg_regs[arg_slot]; tcg_reg_free(s, reg, *allocated_regs); tcg_out_addi_ptr(s, reg, ref_base, ref_off); @@ -4869,8 +4876,7 @@ static void load_arg_ref(TCGContext *s, int arg_slot, TCGReg ref_base, *allocated_regs, 0, false); tcg_out_addi_ptr(s, reg, ref_base, ref_off); tcg_out_st(s, TCG_TYPE_PTR, reg, TCG_REG_CALL_STACK, - TCG_TARGET_CALL_STACK_OFFSET - + stk_slot * sizeof(tcg_target_long)); + arg_slot_stk_ofs(arg_slot)); } } @@ -4900,8 +4906,7 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op) case TCG_CALL_ARG_BY_REF: load_arg_stk(s, loc->ref_slot, ts, allocated_regs); load_arg_ref(s, loc->arg_slot, TCG_REG_CALL_STACK, - TCG_TARGET_CALL_STACK_OFFSET - + loc->ref_slot * sizeof(tcg_target_long), + arg_slot_stk_ofs(loc->ref_slot), &allocated_regs); break; case TCG_CALL_ARG_BY_REF_N: