qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Subject: Re: [PATCH v4 05/48] target/loongarch: Implement xvadd/xvsub
Date: Wed, 30 Aug 2023 08:38:09 -0700	[thread overview]
Message-ID: <c63ca74a-71ac-3fea-56d2-f8f53b0e7d8a@linaro.org> (raw)
In-Reply-To: <20230830084902.2113960-6-gaosong@loongson.cn>

On 8/30/23 01:48, Song Gao wrote:
> +#ifndef CONFIG_USER_ONLY
> + #define CHECK_VEC do { \
> +     if ((ctx->vl == LSX_LEN) && \
> +         (ctx->base.tb->flags & HW_FLAGS_EUEN_SXE) == 0) { \
> +         generate_exception(ctx, EXCCODE_SXD); \
> +         return true; \
> +     } \
> +     if ((ctx->vl == LASX_LEN) && \
> +         (ctx->base.tb->flags & HW_FLAGS_EUEN_ASXE) == 0) { \
> +         generate_exception(ctx, EXCCODE_ASXD); \
> +         return true; \
> +     } \
> + } while (0)
> +#else
> + #define CHECK_VEC
> +#endif /*!CONFIG_USER_ONLY */

I think this is wrong.  The check would seem to be determined by the instruction (oprsz) 
rather than a fixed configuration of the cpu (vl).

You're also replacing

> -#ifndef CONFIG_USER_ONLY
> -#define CHECK_ASXE do { \
> -    if ((ctx->base.tb->flags & HW_FLAGS_EUEN_ASXE) == 0) { \
> -        generate_exception(ctx, EXCCODE_ASXD); \
> -        return true; \
> -    } \
> -} while (0)
> -#else
> -#define CHECK_ASXE
> -#endif

this, the correct test, which you just added in patch 3.


> +TRANS(xvadd_b, LASX, gvec_vvv, 32, MO_8, tcg_gen_gvec_add)
> +TRANS(xvadd_h, LASX, gvec_vvv, 32, MO_16, tcg_gen_gvec_add)
> +TRANS(xvadd_w, LASX, gvec_vvv, 32, MO_32, tcg_gen_gvec_add)
> +TRANS(xvadd_d, LASX, gvec_vvv, 32, MO_64, tcg_gen_gvec_add)

The size of the changes required to add oprsz to gen_vvv would seem to be an poor choice. 
If you do go that way, all of the LSX changes would need to be a separate patch.

Perhaps better as

static bool gvec_vvv_vl(DisasContext *ctx, arg_vvv *a, uint32_t oprsz, MemOp mop,
                         void (*func)(unsigned, uint32_t, uint32_t,
                                      uint32_t, uint32_t, uint32_t))
{
     uint32_t vd_ofs = vec_full_offset(a->vd);
     uint32_t vj_ofs = vec_full_offset(a->vj);
     uint32_t vk_ofs = vec_full_offset(a->vk);

     func(mop, vd_ofs, vj_ofs, vk_ofs, oprsz, ctx->vl / 8);
     return true;
}

static bool gvec_vvv(DisasContext *ctx, arg_vvv *a, MemOp mop,
                      void (*func)(unsigned, uint32_t, uint32_t,
                                   uint32_t, uint32_t, uint32_t))
{
     CHECK_SXE;
     return gvec_vvv_vl(ctx, a, 16, mop, func);
}

static bool gvec_xxx(DisasContext *ctx, arg_vvv *a, MemOp mop,
                      void (*func)(unsigned, uint32_t, uint32_t,
                                   uint32_t, uint32_t, uint32_t))
{
     CHECK_ASXE;
     return gvec_vvv_vl(ctx, a, 32, mop, func);
}

so that you don't have to replicate "16" or "32" across each instruction.


> +#define XVADDSUB_Q(NAME)                                         \
> +static bool trans_xv## NAME ##_q(DisasContext *ctx, arg_vvv * a) \
> +{                                                                \
> +    TCGv_i64 rh, rl, ah, al, bh, bl;                             \
> +    int i;                                                       \
> +                                                                 \
> +    if (!avail_LASX(ctx)) {                                      \
> +        return false;                                            \
> +    }                                                            \
> +                                                                 \
> +    CHECK_VEC;                                                   \
> +                                                                 \
> +    rh = tcg_temp_new_i64();                                     \
> +    rl = tcg_temp_new_i64();                                     \
> +    ah = tcg_temp_new_i64();                                     \
> +    al = tcg_temp_new_i64();                                     \
> +    bh = tcg_temp_new_i64();                                     \
> +    bl = tcg_temp_new_i64();                                     \
> +                                                                 \
> +    for (i = 0; i < 2; i++) {                                    \
> +        get_vreg64(ah, a->vj, 1 + i * 2);                        \
> +        get_vreg64(al, a->vj, 0 + i * 2);                        \
> +        get_vreg64(bh, a->vk, 1 + i * 2);                        \
> +        get_vreg64(bl, a->vk, 0 + i * 2);                        \
> +                                                                 \
> +        tcg_gen_## NAME ##2_i64(rl, rh, al, ah, bl, bh);         \
> +                                                                 \
> +        set_vreg64(rh, a->vd, 1 + i * 2);                        \
> +        set_vreg64(rl, a->vd, 0 + i * 2);                        \
> +   }                                                             \
> +                                                                 \
> +    return true;                                                 \
> +}

This should be a function, not a macro, passing in tcg_gen_{add,sub}2_i64.

> +
> +XVADDSUB_Q(add)
> +XVADDSUB_Q(sub)

Which lets these be normal TRANS expansions.



r~


  reply	other threads:[~2023-08-30 15:38 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30  8:48 [PATCH v4 00/48] Add LoongArch LASX instructions Song Gao
2023-08-30  8:48 ` [PATCH v4 01/48] target/loongarch: Add LASX data support Song Gao
2023-08-30  8:48 ` [PATCH v4 02/48] target/loongarch: meson.build support build LASX Song Gao
2023-08-30  8:48 ` [PATCH v4 03/48] target/loongarch: Add CHECK_ASXE maccro for check LASX enable Song Gao
2023-08-30  8:48 ` [PATCH v4 04/48] target/loongarch: Add avail_LASX to check LASX instructions Song Gao
2023-08-30 14:20   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 05/48] target/loongarch: Implement xvadd/xvsub Song Gao
2023-08-30 15:38   ` Richard Henderson [this message]
2023-08-30  8:48 ` [PATCH v4 06/48] target/loongarch: Implement xvreplgr2vr Song Gao
2023-08-30 16:09   ` Richard Henderson
2023-08-31  7:17     ` gaosong
2023-08-30  8:48 ` [PATCH v4 07/48] target/loongarch: Implement xvaddi/xvsubi Song Gao
2023-08-30  8:48 ` [PATCH v4 08/48] target/loongarch: Implement xvneg Song Gao
2023-08-30  8:48 ` [PATCH v4 09/48] target/loongarch: Implement xvsadd/xvssub Song Gao
2023-08-30  8:48 ` [PATCH v4 10/48] target/loongarch: rename lsx_helper.c to vec_helper.c Song Gao
2023-08-30 18:06   ` Richard Henderson
2023-08-31  7:17     ` gaosong
2023-08-30  8:48 ` [PATCH v4 11/48] target/loongarch: Implement xvhaddw/xvhsubw Song Gao
2023-08-30 18:12   ` Richard Henderson
2023-08-31  7:17     ` gaosong
2023-08-31 15:06       ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 12/48] target/loongarch: Implement xvaddw/xvsubw Song Gao
2023-08-30  8:48 ` [PATCH v4 13/48] target/loongarch: Implement xavg/xvagr Song Gao
2023-08-30 18:14   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 14/48] target/loongarch: Implement xvabsd Song Gao
2023-08-30  8:48 ` [PATCH v4 15/48] target/loongarch: Implement xvadda Song Gao
2023-08-30 20:45   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 16/48] target/loongarch: Implement xvmax/xvmin Song Gao
2023-08-30 20:50   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 17/48] target/loongarch: Implement xvmul/xvmuh/xvmulw{ev/od} Song Gao
2023-08-30 18:23   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 18/48] target/loongarch: Implement xvmadd/xvmsub/xvmaddw{ev/od} Song Gao
2023-08-30 21:05   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 19/48] target/loongarch; Implement xvdiv/xvmod Song Gao
2023-08-30 22:14   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 20/48] target/loongarch: Implement xvsat Song Gao
2023-08-30 22:19   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 21/48] target/loongarch: Implement xvexth Song Gao
2023-08-30 22:34   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 22/48] target/loongarch: Implement vext2xv Song Gao
2023-08-30 22:36   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 23/48] target/loongarch: Implement xvsigncov Song Gao
2023-08-30  8:48 ` [PATCH v4 24/48] target/loongarch: Implement xvmskltz/xvmskgez/xvmsknz Song Gao
2023-08-30 22:44   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 25/48] target/loognarch: Implement xvldi Song Gao
2023-08-30  8:48 ` [PATCH v4 26/48] target/loongarch: Implement LASX logic instructions Song Gao
2023-08-30 22:46   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 27/48] target/loongarch: Implement xvsll xvsrl xvsra xvrotr Song Gao
2023-08-30  8:48 ` [PATCH v4 28/48] target/loongarch: Implement xvsllwil xvextl Song Gao
2023-08-30 22:52   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 29/48] target/loongarch: Implement xvsrlr xvsrar Song Gao
2023-08-30 22:54   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 30/48] target/loongarch: Implement xvsrln xvsran Song Gao
2023-08-30 22:57   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 31/48] target/loongarch: Implement xvsrlrn xvsrarn Song Gao
2023-08-30 23:00   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 32/48] target/loongarch: Implement xvssrln xvssran Song Gao
2023-08-30 23:22   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 33/48] target/loongarch: Implement xvssrlrn xvssrarn Song Gao
2023-08-30 23:26   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 34/48] target/loongarch: Implement xvclo xvclz Song Gao
2023-08-30 23:27   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 35/48] target/loongarch: Implement xvpcnt Song Gao
2023-08-30 23:28   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 36/48] target/loongarch: Implement xvbitclr xvbitset xvbitrev Song Gao
2023-08-30 23:30   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 37/48] target/loongarch: Implement xvfrstp Song Gao
2023-08-30 23:34   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 38/48] target/loongarch: Implement LASX fpu arith instructions Song Gao
2023-08-30 23:37   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 39/48] target/loongarch: Implement LASX fpu fcvt instructions Song Gao
2023-08-30 23:40   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 40/48] target/loongarch: Implement xvseq xvsle xvslt Song Gao
2023-08-30 23:41   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 41/48] target/loongarch: Implement xvfcmp Song Gao
2023-08-31  0:30   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 42/48] target/loongarch: Implement xvbitsel xvset Song Gao
2023-08-31  0:32   ` Richard Henderson
2023-08-30  8:48 ` [PATCH v4 43/48] target/loongarch: Implement xvinsgr2vr xvpickve2gr Song Gao
2023-08-30  8:48 ` [PATCH v4 44/48] target/loongarch: Implement xvreplve xvinsve0 xvpickve xvb{sll/srl}v Song Gao
2023-08-30  8:48 ` [PATCH v4 45/48] target/loongarch: Implement xvpack xvpick xvilv{l/h} Song Gao
2023-08-31  0:35   ` Richard Henderson
2023-08-30  8:49 ` [PATCH v4 46/48] target/loongarch: Implement xvshuf xvperm{i} xvshuf4i xvextrins Song Gao
2023-08-30  8:49 ` [PATCH v4 47/48] target/loongarch: Implement xvld xvst Song Gao
2023-08-30  8:49 ` [PATCH v4 48/48] target/loongarch: CPUCFG support LASX Song Gao
2023-08-31  0:38   ` 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=c63ca74a-71ac-3fea-56d2-f8f53b0e7d8a@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=gaosong@loongson.cn \
    --cc=qemu-devel@nongnu.org \
    /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).