All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: matheus.ferst@eldorado.org.br, qemu-devel@nongnu.org,
	qemu-ppc@nongnu.org
Cc: groug@kaod.org, danielhb413@gmail.com, clg@kaod.org,
	david@gibson.dropbear.id.au
Subject: Re: [PATCH v2 2/3] target/ppc: Implement Vector Extract Mask
Date: Fri, 3 Dec 2021 05:21:22 -0800	[thread overview]
Message-ID: <21871d3f-b1d6-8ac2-ddda-c8c356726785@linaro.org> (raw)
In-Reply-To: <8b929a58-efaa-08af-2183-de4fe1a8389d@linaro.org>

On 12/3/21 5:00 AM, Richard Henderson wrote:
> On 11/12/21 6:14 AM, matheus.ferst@eldorado.org.br wrote:
>> From: Matheus Ferst <matheus.ferst@eldorado.org.br>
>>
>> Implement the following PowerISA v3.1 instructions:
>> vextractbm: Vector Extract Byte Mask
>> vextracthm: Vector Extract Halfword Mask
>> vextractwm: Vector Extract Word Mask
>> vextractdm: Vector Extract Doubleword Mask
>> vextractqm: Vector Extract Quadword Mask
>>
>> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Matheus Ferst <matheus.ferst@eldorado.org.br>
>> ---
>> v2:
>> - Applied rth suggestion to do_vextractm
>> ---
>>   target/ppc/insn32.decode            |  6 +++
>>   target/ppc/translate/vmx-impl.c.inc | 60 +++++++++++++++++++++++++++++
>>   2 files changed, 66 insertions(+)
>>
>> diff --git a/target/ppc/insn32.decode b/target/ppc/insn32.decode
>> index 9a28f1d266..639ac22bf0 100644
>> --- a/target/ppc/insn32.decode
>> +++ b/target/ppc/insn32.decode
>> @@ -419,6 +419,12 @@ VEXPANDWM       000100 ..... 00010 ..... 11001000010    @VX_tb
>>   VEXPANDDM       000100 ..... 00011 ..... 11001000010    @VX_tb
>>   VEXPANDQM       000100 ..... 00100 ..... 11001000010    @VX_tb
>> +VEXTRACTBM      000100 ..... 01000 ..... 11001000010    @VX_tb
>> +VEXTRACTHM      000100 ..... 01001 ..... 11001000010    @VX_tb
>> +VEXTRACTWM      000100 ..... 01010 ..... 11001000010    @VX_tb
>> +VEXTRACTDM      000100 ..... 01011 ..... 11001000010    @VX_tb
>> +VEXTRACTQM      000100 ..... 01100 ..... 11001000010    @VX_tb
>> +
>>   # VSX Load/Store Instructions
>>   LXV             111101 ..... ..... ............ . 001   @DQ_TSX
>> diff --git a/target/ppc/translate/vmx-impl.c.inc b/target/ppc/translate/vmx-impl.c.inc
>> index 58aca58f0f..dd7337c2f2 100644
>> --- a/target/ppc/translate/vmx-impl.c.inc
>> +++ b/target/ppc/translate/vmx-impl.c.inc
>> @@ -1539,6 +1539,66 @@ static bool trans_VEXPANDQM(DisasContext *ctx, arg_VX_tb *a)
>>       return true;
>>   }
>> +static bool do_vextractm(DisasContext *ctx, arg_VX_tb *a, unsigned vece)
>> +{
>> +    const uint64_t elem_width = 8 << vece, elem_count_half = 8 >> vece;
>> +    TCGv_i64 t, b, tmp;
>> +
>> +    REQUIRE_INSNS_FLAGS2(ctx, ISA310);
>> +    REQUIRE_VECTOR(ctx);
>> +
>> +    t = tcg_const_i64(0);
>> +    b = tcg_temp_new_i64();
>> +    tmp = tcg_temp_new_i64();
>> +
>> +    for (int w = 0; w < 2; w++) {
>> +        get_avr64(b, a->vrb, w);
>> +
>> +        for (int i = 0; i < elem_count_half; i++) {
>> +            int in_bit = (i + 1) * elem_width - 1;
>> +            int out_bit = w * elem_count_half + i;
>> +
>> +            if (in_bit > out_bit) {
>> +                tcg_gen_shri_i64(tmp, b, in_bit - out_bit);
>> +            } else {
>> +                tcg_gen_shli_i64(tmp, b, out_bit - in_bit);
>> +            }
>> +            tcg_gen_andi_i64(tmp, tmp, 1 << out_bit);
>> +            tcg_gen_or_i64(t, t, tmp);
>> +        }
>> +    }
>> +    tcg_gen_trunc_i64_tl(cpu_gpr[a->vrt], t);
> 
> Pardon me.  I realized after the fact that we can run the same algorithm as for mtvsrm (in 
> the next patch) in reverse.
> 
>    & dup(1)
> .......a.......b.......c.......d.......e.......f.......g.......h
>    >> 32 - 4
> ...................................a.......b.......c.......d....
>    |
> .......a.......b.......c.......d...a...e...b...f...c...g...d...h
>    >> 16 - 2
> .....................a.......b.......c.......d...a...e...b...f..
>    |
> .......a.......b.....a.c.....b.d...a.c.e...b.d.f.a.c.e.g.b.d.f.h
>    >> 8 - 1
> ..............a.......b.....a.c.....b.d...a.c.e...b.d.f.a.c.e.g.
>    |
> .......a......ab.....abc....abcd...abcde..abcdef.abcdefgabcdefgh
>    & 0xff
> ........................................................abcdefgh
> 
> where one of the two final masks can be done via deposit:
> 
>      tcg_gen_andi_i64(hi, hi, 0xff);
>      tcg_gen_deposit_i64(lo, lo, hi, 8, 56);
> 
> Which will reduce the instruction count of this implementation by half.

Oops, ENOCOFFEE.  Of course the input bit comes from the msb of the element, not the lsb. 
  Three different options:

(1) Begin with a shift of elem_count_half - 1, then do the above,

(2) Change the initial mask to the msb, then extract from elem_count_half - 1.

(3) Do left shifts so that we collect the bits at the msb of
     the word.  This probably results in the easiest concatenation
     in the end:

     tcg_gen_shri_i64(hi, hi, 64 - elem_count_half);
     tcg_gen_extract2_i64(lo, lo, hi, 64 - 2 * elem_count_half);


r~


  reply	other threads:[~2021-12-03 13:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12 14:14 [PATCH v2 0/3] target/ppc: Implement Vector Expand/Extract Mask and Vector Mask matheus.ferst
2021-11-12 14:14 ` [PATCH v2 1/3] target/ppc: Implement Vector Expand Mask matheus.ferst
2021-11-12 14:14 ` [PATCH v2 2/3] target/ppc: Implement Vector Extract Mask matheus.ferst
2021-12-03 13:00   ` Richard Henderson
2021-12-03 13:21     ` Richard Henderson [this message]
2021-11-12 14:14 ` [PATCH v2 3/3] target/ppc: Implement Vector Mask Move insns matheus.ferst
2021-12-03 13:01   ` Richard Henderson
2021-12-03  8:34 ` [PATCH v2 0/3] target/ppc: Implement Vector Expand/Extract Mask and Vector Mask Cédric Le Goater

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=21871d3f-b1d6-8ac2-ddda-c8c356726785@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=matheus.ferst@eldorado.org.br \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.