qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v2 1/8] tcg/tcg-op: Document bswap16_i32() byte pattern
Date: Wed, 23 Aug 2023 16:55:35 +0200	[thread overview]
Message-ID: <20230823145542.79633-2-philmd@linaro.org> (raw)
In-Reply-To: <20230823145542.79633-1-philmd@linaro.org>

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tcg/tcg-op.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 7aadb37756..c1b9a3e34c 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1021,6 +1021,15 @@ 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.
+ *
+ *                                                           flags
+ * Byte pattern:  bswap16_i32(..ab) -> .aba             (TCG_BSWAP_IZ)
+ *                bswap16_i32(xxab) -> ..ba             (TCG_BSWAP_OZ)
+ *                bswap16_i32(xxab) -> ssba             (TCG_BSWAP_OS)
+ *                bswap16_i32(xxab) -> xaba
+ */
 void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
 {
     /* Only one extension flag may be present. */
@@ -1032,22 +1041,29 @@ void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
         TCGv_i32 t0 = tcg_temp_ebb_new_i32();
         TCGv_i32 t1 = tcg_temp_ebb_new_i32();
 
-        tcg_gen_shri_i32(t0, arg, 8);
+                                            /* 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);
+            tcg_gen_ext8u_i32(t0, t0);      /*  t0 = ...a (IZ=0)    */
         }
 
         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... (OS=1)    */
+            tcg_gen_sari_i32(t1, t1, 16);   /*  t1 = ssb. (OS=1)    */
         } 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 (OZ=1)    */
+            tcg_gen_shli_i32(t1, t1, 8);    /*  t1 = ..b. (OZ=1)    */
         } else {
-            tcg_gen_shli_i32(t1, arg, 8);
+            tcg_gen_shli_i32(t1, arg, 8);   /*  t1 = xab. (IZ=0)    */
+                                            /*     = .ab. (IZ=1)    */
         }
 
-        tcg_gen_or_i32(ret, t0, t1);
+        tcg_gen_or_i32(ret, t0, t1);        /* ret = ..ba (OZ=1)    */
+                                            /*     = ssba (OS=1)    */
+                                            /*     = .aba (IZ=1)    */
+                                            /*     = xaba (no flag) */
         tcg_temp_free_i32(t0);
         tcg_temp_free_i32(t1);
     }
-- 
2.41.0



  reply	other threads:[~2023-08-23 14:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 14:55 [PATCH v2 0/8] tcg: Document *swap* helper implementations Philippe Mathieu-Daudé
2023-08-23 14:55 ` Philippe Mathieu-Daudé [this message]
2023-08-23 14:55 ` [PATCH v2 2/8] tcg/tcg-op: Document bswap16_i64() byte pattern Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 3/8] tcg/tcg-op: Document bswap32_i32() " Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 4/8] tcg/tcg-op: Document bswap32_i64() " Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 5/8] tcg/tcg-op: Document bswap64_i64() " Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 6/8] tcg/tcg-op: Document hswap_i32/64() " Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 7/8] tcg/tcg-op: Document wswap_i64() " Philippe Mathieu-Daudé
2023-08-23 14:55 ` [PATCH v2 8/8] target/cris: Fix a typo in gen_swapr() Philippe Mathieu-Daudé
2023-09-01 15:59   ` Edgar E. Iglesias
2023-08-23 18:46 ` [PATCH v2 0/8] tcg: Document *swap* helper implementations Richard Henderson
2023-08-23 21:54   ` 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=20230823145542.79633-2-philmd@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).