From nobody Tue Feb 10 23:54:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1666270605; cv=none; d=zohomail.com; s=zohoarc; b=SVj8Ja7jUruxBp9z5om1SINnOilXqVZJS0lkoHZfgB3RTPhn37kGYwTsuh98XLS7K/mRsoiTSavHZ155rs8jDDY4dm7UImIYvF94v2xAxoKUDqq4MhUKZKuCDrHLjiJ1NejCIJSuy/KXV+CsMvOwsdGR6Ig4/ACIEXSSrvdlsLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666270605; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k7bPKKs/aThsRZPJWHh1qzMHmjPNozKPmJgP4+3jfyA=; b=Jf0rM5AnXFH4zdjjNWY2911F9eEmR+lNs4VrcSSjUCIUjcBbRdSb7Cllu6R606GMpUX7huPk3fHUxI1ujuhr5OEyECTK/RJ76JK1rCCeZzMjn9OiZk+/Ky0I4gskrmoYh2pUqNSy79omR3zkEcFX69KJ2zdhePUr45T0MgmuCGc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666270605479179.8264835558756; Thu, 20 Oct 2022 05:56:45 -0700 (PDT) Received: from localhost ([::1]:57998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olV6H-0001hd-Ce for importer@patchew.org; Thu, 20 Oct 2022 08:56:42 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olUvf-0008L1-Gu for importer@patchew.org; Thu, 20 Oct 2022 08:45:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olU88-0005Xs-Ru for qemu-devel@nongnu.org; Thu, 20 Oct 2022 07:54:42 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:38778) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olU85-00018J-1M for qemu-devel@nongnu.org; Thu, 20 Oct 2022 07:54:32 -0400 Received: by mail-pf1-x42d.google.com with SMTP id p14so20058900pfq.5 for ; Thu, 20 Oct 2022 04:54:28 -0700 (PDT) Received: from localhost.localdomain ([149.135.10.35]) by smtp.gmail.com with ESMTPSA id w206-20020a627bd7000000b0056109e15638sm13065464pfc.54.2022.10.20.04.54.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 04:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=k7bPKKs/aThsRZPJWHh1qzMHmjPNozKPmJgP4+3jfyA=; b=sHduDF3kgPB02THemvuMv33t4O0tjgRF/TY0a3135Vpei6SKCd9Kh0ULG9XYYMA0OX +OUr786ldypbRm8+9N6DzYM4gIFNC9Z46eKn4ZgvFOXEgLV30K2WZ3zindLxVHt86Jft 3qe40v1TiobJmsd5SboixrRYiys9Wj8ldm72Az450y07jWRQRXL5EtBO/Mf3ypa+4/xh d7U4uCeDcWEQ2LVNBnVZPw5n0cLMVgNqgS8NzYPU7cSPginn4KEis4mIQA2Dh5E85GBL YHFuq2HuFAHP0leltPyenSMWpKjJNxjQqzz7F1DOhmZCarOBLzTDMCXdd9Rhx0r70Jk4 RK3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k7bPKKs/aThsRZPJWHh1qzMHmjPNozKPmJgP4+3jfyA=; b=FG5hQJ3Sr5skaveQC7Uyk2pw+P73iGdJFAFqGtJG3TQe7JqSZFFsB8tmcE8FL7b698 t0iPYzWvu++MaZtFCrylhYdPYDW9UapNwzxtGrKwQk09uvfQ0we/moxxVOf42LhXBvaz QPxQv/MbgHlBaJtLvnpQXifpkYxD6J9IHkPGBaeHATz3HPeKPiRRMB+Kk40hdL/lx1rZ u3NUWDs2iDYcXyJyMwZGGTq/cdnWYijoJUDI9SgDj3DXeWa4mXqOBCFRW9jdVB9Hb4NA 1UpwPT8TE4UnR+kvMzJ417vtrDIeBC88jVo+XuYfODZE0XK8Ayrm64hvuTwMlfXXO3yU AszA== X-Gm-Message-State: ACrzQf1uSuGx0ELjGQrybxqGfc/cLcHCoUubkLERr8hBd7HF6rPgrHOD MMxyt3nmTMtDI49nc+J5S4dQ1G/+qgK+KsDC X-Google-Smtp-Source: AMsMyM4EFOicDD2RQmc6EJmvzSO/jlkWsu4J5XCJ/5DErjd4MH2zxFpRVbLfbtkz8iYW3PjNieZreA== X-Received: by 2002:a63:1352:0:b0:469:793f:9683 with SMTP id 18-20020a631352000000b00469793f9683mr11527504pgt.128.1666266867321; Thu, 20 Oct 2022 04:54:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 25/31] tcg: Add TCG_CALL_{RET,ARG}_BY_REF Date: Thu, 20 Oct 2022 21:52:36 +1000 Message-Id: <20221020115242.2301066-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221020115242.2301066-1-richard.henderson@linaro.org> References: <20221020115242.2301066-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1666270606783100001 Content-Type: text/plain; charset="utf-8" These will be used by some hosts, 32 and 64-bit to pass and return i128. Not yet used, because allocation is not yet enabled. Signed-off-by: Richard Henderson --- tcg/tcg-internal.h | 10 ++-- tcg/tcg.c | 124 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/tcg/tcg-internal.h b/tcg/tcg-internal.h index 7d4f7049be..1fe7bd7d5d 100644 --- a/tcg/tcg-internal.h +++ b/tcg/tcg-internal.h @@ -37,6 +37,7 @@ typedef enum { TCG_CALL_RET_NORMAL, /* by registers */ TCG_CALL_RET_NORMAL_4, /* for i128, by 4 registers */ + TCG_CALL_RET_BY_REF, /* for i128, by reference as first arg */ } TCGCallReturnKind; =20 typedef enum { @@ -46,12 +47,15 @@ typedef enum { TCG_CALL_ARG_EXTEND_U, /* ... as a zero-extended i64 */ TCG_CALL_ARG_EXTEND_S, /* ... as a sign-extended i64 */ TCG_CALL_ARG_NORMAL_4, /* for i128, like normal with 4 slots */ + TCG_CALL_ARG_BY_REF, /* ... by reference, first */ + TCG_CALL_ARG_BY_REF_2, /* ... by reference, second */ } TCGCallArgumentKind; =20 typedef struct TCGCallArgumentLoc { - TCGCallArgumentKind kind : 8; - unsigned reg_slot : 8; - unsigned stk_slot : 8; + TCGCallArgumentKind kind : 4; + unsigned reg_slot : 6; + unsigned stk_slot : 6; + unsigned ref_slot : 6; unsigned reg_n : 2; unsigned arg_idx : 4; unsigned tmp_subindex : 1; diff --git a/tcg/tcg.c b/tcg/tcg.c index 390724e652..c664e3b18d 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -103,8 +103,7 @@ static void tcg_out_ld(TCGContext *s, TCGType type, TCG= Reg ret, TCGReg arg1, static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg ar= g); static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg ret, tcg_target_long arg); -static void tcg_out_addi_ptr(TCGContext *s, TCGReg, TCGReg, tcg_target_lon= g) - __attribute__((unused)); +static void tcg_out_addi_ptr(TCGContext *s, TCGReg, TCGReg, tcg_target_lon= g); static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg args[TCG_MAX_OP_ARGS], const int const_args[TCG_MAX_OP_ARGS]); @@ -684,6 +683,34 @@ static void layout_arg_normal_4(TCGCumulativeArgs *cum= , TCGHelperInfo *info) cum->op_arg_idx++; } =20 +static void layout_arg_by_ref(TCGCumulativeArgs *cum, TCGHelperInfo *info) +{ + TCGCallArgumentLoc *loc =3D &info->in[cum->info_in_idx]; + int n =3D 128 / TCG_TARGET_REG_BITS; + + /* The first subindex carries the pointer. */ + layout_arg_1(cum, info, TCG_CALL_ARG_BY_REF); + + /* + * The callee is allowed to clobber memory associated with + * structure pass by-reference. Therefore we must make copies. + * Allocate space from the top of TCG_STATIC_CALL_ARGS_SIZE. + */ + cum->max_stk_slot -=3D n; + loc[0].ref_slot =3D cum->max_stk_slot; + + /* Any other subindex is present for liveness. */ + if (TCG_TARGET_REG_BITS =3D=3D 64) { + loc[1] =3D (TCGCallArgumentLoc){ + .kind =3D TCG_CALL_ARG_BY_REF_2, + .arg_idx =3D cum->arg_idx, + .tmp_subindex =3D 1, + }; + cum->info_in_idx++; + cum->op_arg_idx++; + } +} + static void init_call_layout(TCGHelperInfo *info) { unsigned typemask =3D info->typemask; @@ -728,6 +755,18 @@ static void init_call_layout(TCGHelperInfo *info) assert(ARRAY_SIZE(tcg_target_call_oarg_regs) >=3D 2); } break; + case TCG_CALL_RET_BY_REF: + /* + * Allocate the first argument to the output. + * We don't need to store this anywhere, just make it + * unavailable for use in the input loop below. + */ + if (cum.max_reg_slot =3D=3D 0) { + cum.stk_slot =3D 1; + } else { + cum.reg_slot =3D 1; + } + break; default: g_assert_not_reached(); } @@ -765,6 +804,10 @@ static void init_call_layout(TCGHelperInfo *info) type =3D TCG_TYPE_PTR; kind =3D TCG_CALL_ARG_NORMAL; break; + case dh_typecode_i128: + type =3D TCG_TYPE_I128; + kind =3D TCG_CALL_ARG_NORMAL; /* TODO */ + break; default: g_assert_not_reached(); } @@ -809,6 +852,10 @@ static void init_call_layout(TCGHelperInfo *info) assert(type =3D=3D TCG_TYPE_I32); layout_arg_1(&cum, info, kind); break; + case TCG_CALL_ARG_BY_REF: + assert(type =3D=3D TCG_TYPE_I128); + layout_arg_by_ref(&cum, info); + break; default: g_assert_not_reached(); } @@ -1740,6 +1787,8 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int narg= s, TCGTemp **args) switch (loc->kind) { case TCG_CALL_ARG_NORMAL: case TCG_CALL_ARG_NORMAL_4: + case TCG_CALL_ARG_BY_REF: + case TCG_CALL_ARG_BY_REF_2: op->args[pi++] =3D temp_arg(ts); break; =20 @@ -4464,6 +4513,27 @@ static void load_arg_normal_4(TCGContext *s, const T= CGCallArgumentLoc *loc, } } =20 +static void load_arg_by_ref(TCGContext *s, const TCGCallArgumentLoc *loc, + TCGReg ref_base, int ref_off, + TCGRegSet *allocated_regs) +{ + TCGReg reg; + + if (loc->reg_n) { + reg =3D tcg_target_call_iarg_regs[loc->reg_slot]; + tcg_out_addi_ptr(s, reg, ref_base, ref_off); + tcg_regset_set_reg(*allocated_regs, reg); + } else { + int stk_off =3D TCG_TARGET_CALL_STACK_OFFSET + + loc->stk_slot * sizeof(tcg_target_long); + + reg =3D tcg_reg_alloc(s, tcg_target_available_regs[TCG_TYPE_PTR], + *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, stk_off); + } +} + static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op) { const int nb_oargs =3D TCGOP_CALLO(op); @@ -4473,6 +4543,19 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp = *op) TCGRegSet allocated_regs =3D s->reserved_regs; int i; =20 + /* + * The callee is allowed to clobber memory associated with + * structure pass by-reference. Therefore we must make copies. + * Do this first, before we start allocating argument regs. + */ + for (i =3D 0; i < nb_iargs; ++i) { + const TCGCallArgumentLoc *loc =3D &info->in[i]; + if (loc->kind =3D=3D TCG_CALL_ARG_BY_REF) { + TCGTemp *ts =3D arg_temp(op->args[nb_oargs + i]); + copy_to_stk_i128(s, loc->ref_slot, ts, 0, allocated_regs); + } + } + /* * Move inputs into place in reverse order, * so that we place stacked arguments first. @@ -4490,6 +4573,15 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp = *op) case TCG_CALL_ARG_NORMAL_4: load_arg_normal_4(s, loc, ts, &allocated_regs); break; + case TCG_CALL_ARG_BY_REF: + load_arg_by_ref(s, loc, TCG_REG_CALL_STACK, + TCG_TARGET_CALL_STACK_OFFSET + + loc->ref_slot * sizeof(tcg_target_long), + &allocated_regs); + break; + case TCG_CALL_ARG_BY_REF_2: + /* nothing to do */ + break; default: g_assert_not_reached(); } @@ -4521,6 +4613,26 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp = *op) save_globals(s, allocated_regs); } =20 + /* + * If the ABI passes a pointer to the returned struct as the first + * argument, load that now. Pass a pointer to the output home slot. + */ + if (info->out_kind =3D=3D TCG_CALL_RET_BY_REF) { + static const TCGCallArgumentLoc ret_loc =3D { + .reg_n =3D ARRAY_SIZE(tcg_target_call_iarg_regs) !=3D 0 + }; + TCGTemp *ts =3D arg_temp(op->args[0]); + + tcg_debug_assert(ts->base_type =3D=3D TCG_TYPE_I128); + tcg_debug_assert(ts->temp_subindex =3D=3D 0); + + if (!ts->mem_allocated) { + temp_allocate_frame(s, ts); + } + load_arg_by_ref(s, &ret_loc, ts->mem_base->reg, ts->mem_offset, + &allocated_regs); + } + tcg_out_call(s, tcg_call_func(op), info); =20 /* Assign output registers and emit moves if needed. */ @@ -4561,6 +4673,14 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp = *op) } break; =20 + case TCG_CALL_RET_BY_REF: + /* The callee has performed a write through the reference. */ + for (i =3D 0; i < nb_oargs; i++) { + TCGTemp *ts =3D arg_temp(op->args[i]); + ts->val_type =3D TEMP_VAL_MEM; + } + break; + default: g_assert_not_reached(); } --=20 2.34.1