qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 1/7] tcg/tcg-op: Document bswap16() byte pattern
Date: Tue, 22 Aug 2023 19:22:41 +0200	[thread overview]
Message-ID: <09f4ba68-e7f3-8a90-e996-e475b760c64a@linaro.org> (raw)
In-Reply-To: <c538a498-05e4-23ed-328e-7355436f6c7a@linaro.org>

On 22/8/23 17:58, Richard Henderson wrote:
> On 8/22/23 02:37, Philippe Mathieu-Daudé wrote:
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   tcg/tcg-op.c | 48 ++++++++++++++++++++++++++++++++----------------
>>   1 file changed, 32 insertions(+), 16 deletions(-)
>>
>> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
>> index 7aadb37756..f164ddc95e 100644
>> --- a/tcg/tcg-op.c
>> +++ b/tcg/tcg-op.c
>> @@ -1021,6 +1021,13 @@ void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 
>> arg)
>>       }
>>   }
>> +/*
>> + * bswap16_i32: 16-bit byte swap on the low bits of a 32-bit value.
>> + *
>> + * Byte pattern:  bswap16_i32(xxab) -> ..ba             (TCG_BSWAP_OZ)
>> + *                bswap16_i32(xxab) -> ssba             (TCG_BSWAP_OS)
>> + *                bswap16_i32(xxab) -> xxba
>> + */
> 
> Don't forget TCG_BSWAP_IZ, which means the input is already zero-extended.
> Which makes
> 
>> +                                            /* arg = xxab */
>> +        tcg_gen_shri_i32(t0, arg, 8);       /*  t0 = .xxa */
> 
> this
> 
>>           if (!(flags & TCG_BSWAP_IZ)) {
>> -            tcg_gen_ext8u_i32(t0, t0);
>> +            tcg_gen_ext8u_i32(t0, t0);      /*  t0 = ...a */
>>           }
>>           if (flags & TCG_BSWAP_OS) {
>> -            tcg_gen_shli_i32(t1, arg, 24);
>> -            tcg_gen_sari_i32(t1, t1, 16);
>> +            tcg_gen_shli_i32(t1, arg, 24);  /*  t1 = b... */
>> +            tcg_gen_sari_i32(t1, t1, 16);   /*  t1 = ssb. */
>>           } else if (flags & TCG_BSWAP_OZ) {
>> -            tcg_gen_ext8u_i32(t1, arg);
>> -            tcg_gen_shli_i32(t1, t1, 8);
>> +            tcg_gen_ext8u_i32(t1, arg);     /*  t1 = ...b */
>> +            tcg_gen_shli_i32(t1, t1, 8);    /*  t1 = ..b. */
>>           } else {
>> -            tcg_gen_shli_i32(t1, arg, 8);
>> +            tcg_gen_shli_i32(t1, arg, 8);   /*  t1 = xab. */
> 
> and this slightly inaccurate.
> 
>>           }
>> -        tcg_gen_or_i32(ret, t0, t1);
>> +        tcg_gen_or_i32(ret, t0, t1);        /* ret = ssba */
> 
> This one is just confusing, since each of the three cases above have 
> different outputs.

Is that formatting OK with you?

/*
  * bswap16_i32: 16-bit byte swap on the low bits of a 32-bit value.
  *
  * Byte pattern:  bswap16_i32(..ab) -> ..ba             (TCG_BSWAP_IZ)
  *                bswap16_i32(xxab) -> ..ba             (TCG_BSWAP_OZ)
  *                bswap16_i32(xxab) -> ssba             (TCG_BSWAP_OS)
  *                bswap16_i32(xxab) -> xxba
  */
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
{
     /* Only one extension flag may be present. */
     tcg_debug_assert(!(flags & TCG_BSWAP_OS) || !(flags & TCG_BSWAP_OZ));

     if (TCG_TARGET_HAS_bswap16_i32) {
         tcg_gen_op3i_i32(INDEX_op_bswap16_i32, ret, arg, flags);
     } else {
         TCGv_i32 t0 = tcg_temp_ebb_new_i32();
         TCGv_i32 t1 = tcg_temp_ebb_new_i32();

                                             /* arg = xxab (IZ=0) */
                                             /*       ..ab (IZ=1) */
         tcg_gen_shri_i32(t0, arg, 8);       /*  t0 = .xxa (IZ=0) */
                                             /*       ...a (IZ=1) */
         if (!(flags & TCG_BSWAP_IZ)) {
             tcg_gen_ext8u_i32(t0, t0);      /*  t0 = ...a */
         }

         if (flags & TCG_BSWAP_OS) {
             tcg_gen_shli_i32(t1, arg, 24);  /*  t1 = b... */
             tcg_gen_sari_i32(t1, t1, 16);   /*  t1 = ssb. */
         } else if (flags & TCG_BSWAP_OZ) {
             tcg_gen_ext8u_i32(t1, arg);     /*  t1 = ...b */
             tcg_gen_shli_i32(t1, t1, 8);    /*  t1 = ..b. */
         } else {
             tcg_gen_shli_i32(t1, arg, 8);   /*  t1 = xab. (IZ=0) */
                                             /*       .ab. (IZ=1) */
         }

         tcg_gen_or_i32(ret, t0, t1);        /* ret = ..ba (IZ=1 or OZ=1) */
                                             /*     = ssba (OS=1)         */
                                             /*     = xxba (no flag)      */
         tcg_temp_free_i32(t0);
         tcg_temp_free_i32(t1);
     }
}

---


  reply	other threads:[~2023-08-22 17:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22  9:37 [PATCH 0/7] tcg: Document *swap/deposit helpers Philippe Mathieu-Daudé
2023-08-22  9:37 ` [PATCH 1/7] tcg/tcg-op: Document bswap16() byte pattern Philippe Mathieu-Daudé
2023-08-22 15:58   ` Richard Henderson
2023-08-22 17:22     ` Philippe Mathieu-Daudé [this message]
2023-08-22 17:29       ` Richard Henderson
2023-08-22 22:04         ` Philippe Mathieu-Daudé
2023-08-22  9:37 ` [PATCH 2/7] tcg/tcg-op: Document bswap32() " Philippe Mathieu-Daudé
2023-08-22 16:00   ` Richard Henderson
2023-08-23 13:14     ` Philippe Mathieu-Daudé
2023-08-23 15:54       ` Richard Henderson
2023-08-22  9:37 ` [PATCH 3/7] tcg/tcg-op: Document bswap64() " Philippe Mathieu-Daudé
2023-08-22 16:00   ` Richard Henderson
2023-08-22  9:37 ` [PATCH 4/7] tcg/tcg-op: Document hswap() " Philippe Mathieu-Daudé
2023-08-22 16:02   ` Richard Henderson
2023-08-22 16:04   ` Richard Henderson
2023-08-22  9:37 ` [PATCH 5/7] tcg/tcg-op: Document wswap() " Philippe Mathieu-Daudé
2023-08-22 16:03   ` Richard Henderson
2023-08-22  9:37 ` [PATCH 6/7] tcg/tcg-op: Document deposit_z() Philippe Mathieu-Daudé
2023-08-22 16:05   ` Richard Henderson
2023-08-22  9:37 ` [PATCH 7/7] target/cris: Fix a typo in gen_swapr() Philippe Mathieu-Daudé
2023-08-22 13:42 ` [PATCH 0/7] tcg: Document *swap/deposit helpers Alex Bennée
2023-08-22 13:58   ` Peter Maydell
2023-08-22 14:43   ` Philippe Mathieu-Daudé

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=09f4ba68-e7f3-8a90-e996-e475b760c64a@linaro.org \
    --to=philmd@linaro.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).