qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>, 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 v4 03/12] tcg/riscv: Add vset{i}vli and ld/st vec ops
Date: Wed, 11 Sep 2024 15:57:24 -0700	[thread overview]
Message-ID: <2f24a36d-8910-4eeb-9d4f-ff2c96dc41ba@linaro.org> (raw)
In-Reply-To: <20240911132630.461-4-zhiwei_liu@linux.alibaba.com>

On 9/11/24 06:26, LIU Zhiwei wrote:
> +static bool lmul_check(int lmul, MemOp vsew)
> +{
> +    /*
> +     * For a given supported fractional LMUL setting, implementations must
> +     * support SEW settings between SEW_MIN and LMUL * ELEN, inclusive.
> +     * So if ELEN = 64, LMUL = 1/2, then SEW will support e8, e16, e32,
> +     * but e64 may not be supported.
> +     */
> +    if (lmul < 0) {
> +        return (8 << vsew) <= (64 / (1 << (-lmul)));
> +    } else {
> +        return true;
> +    }
> +}

While the spec uses language like "may not be supported", but it then goes on to use an 
example of VLEN=32 and LMUL=1/8 not being valid because that leaves only one 4 bit element.

In our case...

> +
> +static void set_vtype(TCGContext *s, TCGType type, MemOp vsew)
> +{
> +    unsigned vtype, insn, avl;
> +    int lmul;
> +    RISCVVlmul vlmul;
> +    bool lmul_eq_avl;
> +
> +    s->riscv_cur_type = type;
> +    s->riscv_cur_vsew = vsew;
> +
> +    /* Match riscv_lg2_vlenb to TCG_TYPE_V64. */
> +    QEMU_BUILD_BUG_ON(TCG_TYPE_V64 != 3);
> +
> +    lmul = type - riscv_lg2_vlenb;

We know VLEN, and LMUL is bounded by TCG_TYPE_V64.  Since SEW=64 will never be smaller 
than LMUL*VLEN, I expect the lmul_check function to be entirely unneeded: all SEW should 
always work.

If for some strange reason that is not the case, the correct solution not to *assume* that 
it might not work, as you are doing, but to *probe* for it at startup.  For instance, it 
would be easy to loop over each SEW to find the minimal LMUL for which VSETVL returns a 
positive VL, i.e. VILL not set.

> +    if (lmul < -3) {
> +        /* Host VLEN >= 1024 bits. */
> +        vlmul = VLMUL_M1;
> +        lmul_eq_avl = false;
> +    } else if (lmul < 3) {
> +        /* 1/8, 1/4, 1/2, 1, 2, 4 */
> +        if (lmul_check(lmul, vsew)) {
> +            vlmul = lmul & 7;
> +        } else {
> +            vlmul = VLMUL_M1;
> +        }
> +        lmul_eq_avl = true;

lmul_eq_avl incorrectly set here for !lmul_check.

> +        if (type >= riscv_lg2_vlenb) {
> +            static const RISCVInsn whole_reg_ld[] = {
> +                OPC_VL1RE64_V, OPC_VL2RE64_V, OPC_VL4RE64_V, OPC_VL8RE64_V
> +            };
> +            unsigned idx = type - riscv_lg2_vlenb;
> +
> +            tcg_debug_assert(idx < sizeof(whole_reg_ld));
> +            insn = whole_reg_ld[idx];
> +        } else {
> +            static const RISCVInsn unit_stride_ld[] = {
> +                OPC_VLE8_V, OPC_VLE16_V, OPC_VLE32_V, OPC_VLE64_V
> +            };
> +            MemOp prev_vsew = set_vtype_len(s, type);
> +
> +            tcg_debug_assert(prev_vsew < sizeof(unit_stride_ld));

Both sizeof are incorrect; you need ARRAY_SIZE().
Likewise in tcg_out_st.

>   static void tcg_out_tb_start(TCGContext *s)
>   {
> +    s->riscv_cur_type = TCG_TYPE_COUNT;
>       /* nothing to do */
>   }

Remove the out-of-date comment.


r~


  reply	other threads:[~2024-09-11 22:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 13:26 [PATCH v4 00/12] tcg/riscv: Add support for vector LIU Zhiwei
2024-09-11 13:26 ` [PATCH v4 01/12] util: Add RISC-V vector extension probe in cpuinfo LIU Zhiwei
2024-09-11 18:34   ` Richard Henderson
2024-09-18  5:14     ` LIU Zhiwei
2024-09-18 10:14       ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 02/12] tcg/riscv: Add basic support for vector LIU Zhiwei
2024-09-11 18:41   ` Richard Henderson
2024-09-18  5:17     ` LIU Zhiwei
2024-09-18 10:11       ` Richard Henderson
2024-09-18 10:43         ` LIU Zhiwei
2024-09-18 14:27           ` Richard Henderson
2024-09-20  4:01             ` 0x48 Swung
2024-09-20  4:27               ` LIU Zhiwei
2024-09-20 14:26               ` LIU Zhiwei
2024-09-21 15:56                 ` 0x48 Swung
2024-09-21 17:17                   ` Daniel Henrique Barboza
2024-09-20 11:26   ` Daniel Henrique Barboza
2024-09-20 11:37     ` Markus Armbruster
2024-09-11 13:26 ` [PATCH v4 03/12] tcg/riscv: Add vset{i}vli and ld/st vec ops LIU Zhiwei
2024-09-11 22:57   ` Richard Henderson [this message]
2024-09-22  4:46   ` Richard Henderson
2024-09-23  4:46     ` LIU Zhiwei
2024-09-23 10:10       ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 04/12] tcg/riscv: Implement vector mov/dup{m/i} LIU Zhiwei
2024-09-11 23:07   ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 05/12] tcg/riscv: Add support for basic vector opcodes LIU Zhiwei
2024-09-11 13:26 ` [PATCH v4 06/12] tcg/riscv: Implement vector cmp/cmpsel ops LIU Zhiwei
2024-09-11 23:14   ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 07/12] tcg/riscv: Implement vector neg ops LIU Zhiwei
2024-09-11 13:26 ` [PATCH v4 08/12] tcg/riscv: Implement vector sat/mul ops LIU Zhiwei
2024-09-11 13:26 ` [PATCH v4 09/12] tcg/riscv: Implement vector min/max ops LIU Zhiwei
2024-09-11 13:26 ` [PATCH v4 10/12] tcg/riscv: Implement vector shi/s/v ops LIU Zhiwei
2024-09-11 23:15   ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 11/12] tcg/riscv: Implement vector roti/v/x ops LIU Zhiwei
2024-09-11 23:24   ` Richard Henderson
2024-09-11 13:26 ` [PATCH v4 12/12] tcg/riscv: Enable native vector support for TCG host LIU Zhiwei

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=2f24a36d-8910-4eeb-9d4f-ff2c96dc41ba@linaro.org \
    --to=richard.henderson@linaro.org \
    --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=tangtiancheng.ttc@alibaba-inc.com \
    --cc=zhiwei_liu@linux.alibaba.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).