From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com,
alistair.francis@wdc.com, dbarboza@ventanamicro.com,
liwei1518@gmail.com, bmeng.cn@gmail.com,
TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
Subject: Re: [PATCH v1 03/15] tcg: Fix register allocation constraints
Date: Wed, 14 Aug 2024 08:58:42 +0800 [thread overview]
Message-ID: <1e61235e-1cb8-4bc1-9983-6e8dc0c3b406@linux.alibaba.com> (raw)
In-Reply-To: <2efe353a-4700-4632-b919-e43cb039c2c0@linaro.org>
On 2024/8/13 19:52, Richard Henderson wrote:
> On 8/13/24 21:34, LIU Zhiwei wrote:
>> From: TANG Tiancheng<tangtiancheng.ttc@alibaba-inc.com>
>>
>> When allocating registers for input and output, ensure they match
>> the available registers to avoid allocating illeagal registers.
>>
>> We should respect RISC-V vector extension's variable-length registers
>> and LMUL-based register grouping. Coordinate with
>> tcg_target_available_regs
>> initialization tcg_target_init (behind this commit) to ensure proper
>> handling of vector register constraints.
>>
>> Note: While mov_vec doesn't have constraints, dup_vec and other IRs do.
>> We need to strengthen constraints for all IRs except mov_vec, and this
>> is sufficient.
>>
>> Signed-off-by: TANG Tiancheng<tangtiancheng.ttc@alibaba-inc.com>
>> Fixes: 29f5e92502 (tcg: Introduce paired register allocation)
>> Reviewed-by: Liu Zhiwei<zhiwei_liu@linux.alibaba.com>
>> ---
>> tcg/tcg.c | 20 +++++++++++++-------
>> 1 file changed, 13 insertions(+), 7 deletions(-)
>>
>> diff --git a/tcg/tcg.c b/tcg/tcg.c
>> index 34e3056380..d26b42534d 100644
>> --- a/tcg/tcg.c
>> +++ b/tcg/tcg.c
>> @@ -4722,8 +4722,10 @@ static void tcg_reg_alloc_dup(TCGContext *s,
>> const TCGOp *op)
>> return;
>> }
>> - dup_out_regs = tcg_op_defs[INDEX_op_dup_vec].args_ct[0].regs;
>> - dup_in_regs = tcg_op_defs[INDEX_op_dup_vec].args_ct[1].regs;
>> + dup_out_regs = tcg_op_defs[INDEX_op_dup_vec].args_ct[0].regs &
>> + tcg_target_available_regs[ots->type];
>> + dup_in_regs = tcg_op_defs[INDEX_op_dup_vec].args_ct[1].regs &
>> + tcg_target_available_regs[its->type];
>
> Why would you ever have constraints that resolve to unavailable
> registers?
>
> If you don't want to fix this in the backend, then the next best place
> is in process_op_defs(), so that we take care of this once at startup,
> and never have to think about it again.
Hi Richard,
The constraints provided in process_op_defs() are static and tied to the
IR operations. For example, if we create constraints for add_vec, the
same constraints will apply to all types of add_vec operations
(TCG_TYPE_V64, TCG_TYPE_V128, TCG_TYPE_V256). This means the constraints
don't change based on the specific type of operation being performed.
In contrast, RISC-V's LMUL (Length Multiplier) can change at runtime
depending on the type of IR operation. Different LMUL values affect
which vector registers are available for use in RISC-V. Let's consider
an example where the host's vector register width is 128 bits:
For an add_vec operation on v256 (256-bit vectors), only even-numbered
vector registers like 0, 2, 4 can be used.
However, for an add_vec operation on v128 (128-bit vectors), all vector
registers (0, 1, 2, etc.) are available.
Thus if we want to use all registers of vectors, we have to add a
dynamic constraint on register allocation based on IR types.
Thanks,
Zhiwei
>
>
> r~
next prev parent reply other threads:[~2024-08-14 0:59 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 11:34 [PATCH v1 00/15] tcg/riscv: Add support for vector LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 01/15] util: Add RISC-V vector extension probe in cpuinfo LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 02/15] tcg/op-gvec: Fix iteration step in 32-bit operation LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 03/15] tcg: Fix register allocation constraints LIU Zhiwei
2024-08-13 11:52 ` Richard Henderson
2024-08-14 0:58 ` LIU Zhiwei [this message]
2024-08-14 2:04 ` Richard Henderson
2024-08-14 2:27 ` LIU Zhiwei
2024-08-14 3:08 ` Richard Henderson
2024-08-14 3:30 ` LIU Zhiwei
2024-08-14 4:18 ` Richard Henderson
2024-08-14 7:47 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 04/15] tcg/riscv: Add basic support for vector LIU Zhiwei
2024-08-13 12:19 ` Richard Henderson
2024-08-13 11:34 ` [PATCH v1 05/15] tcg/riscv: Add riscv vset{i}vli support LIU Zhiwei
2024-08-14 8:24 ` Richard Henderson
2024-08-19 1:34 ` LIU Zhiwei
2024-08-19 2:35 ` Richard Henderson
2024-08-19 2:53 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 06/15] tcg/riscv: Implement vector load/store LIU Zhiwei
2024-08-14 9:01 ` Richard Henderson
2024-08-19 1:41 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 07/15] tcg/riscv: Implement vector mov/dup{m/i} LIU Zhiwei
2024-08-14 9:11 ` Richard Henderson
2024-08-15 10:49 ` LIU Zhiwei
2024-08-20 9:00 ` Richard Henderson
2024-08-20 9:26 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 08/15] tcg/riscv: Add support for basic vector opcodes LIU Zhiwei
2024-08-14 9:13 ` Richard Henderson
2024-08-20 1:56 ` LIU Zhiwei
2024-08-14 9:17 ` Richard Henderson
2024-08-20 1:57 ` LIU Zhiwei
2024-08-20 5:14 ` Richard Henderson
2024-08-13 11:34 ` [PATCH v1 09/15] tcg/riscv: Implement vector cmp ops LIU Zhiwei
2024-08-14 9:39 ` Richard Henderson
2024-08-27 7:50 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 10/15] tcg/riscv: Implement vector not/neg ops LIU Zhiwei
2024-08-14 9:45 ` Richard Henderson
2024-08-27 7:55 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 11/15] tcg/riscv: Implement vector sat/mul ops LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 12/15] tcg/riscv: Implement vector min/max ops LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 13/15] tcg/riscv: Implement vector shs/v ops LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 14/15] tcg/riscv: Implement vector roti/v/x shi ops LIU Zhiwei
2024-08-14 9:55 ` Richard Henderson
2024-08-27 7:57 ` LIU Zhiwei
2024-08-13 11:34 ` [PATCH v1 15/15] tcg/riscv: Enable vector TCG host-native LIU Zhiwei
2024-08-14 10:15 ` Richard Henderson
2024-08-27 8:31 ` LIU Zhiwei
2024-08-28 23:35 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e61235e-1cb8-4bc1-9983-6e8dc0c3b406@linux.alibaba.com \
--to=zhiwei_liu@linux.alibaba.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng.cn@gmail.com \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=tangtiancheng.ttc@alibaba-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).