diff mbox series

[v2,2/8] tcg/tcg-op: Document bswap16_i64() byte pattern

Message ID 20230823145542.79633-3-philmd@linaro.org
State New
Headers show
Series tcg: Document *swap* helper implementations | expand

Commit Message

Philippe Mathieu-Daudé Aug. 23, 2023, 2:55 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tcg/tcg-op.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index c1b9a3e34c..80ec6f01c4 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1737,6 +1737,15 @@  void tcg_gen_ext32u_i64(TCGv_i64 ret, TCGv_i64 arg)
     }
 }
 
+/*
+ * bswap16_i64: 16-bit byte swap on the low bits of a 64-bit value.
+ *
+ *                                                           flags
+ * Byte pattern:  bswap16_i32(......ab) -> ......ba     (TCG_BSWAP_IZ)
+ *                bswap16_i32(xxxxxxab) -> ......ba     (TCG_BSWAP_OZ)
+ *                bswap16_i32(xxxxxxab) -> ssssssba     (TCG_BSWAP_OS)
+ *                bswap16_i32(xxxxxxab) -> xxxxxxba
+ */
 void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
 {
     /* Only one extension flag may be present. */
@@ -1755,22 +1764,28 @@  void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags)
         TCGv_i64 t0 = tcg_temp_ebb_new_i64();
         TCGv_i64 t1 = tcg_temp_ebb_new_i64();
 
-        tcg_gen_shri_i64(t0, arg, 8);
+                                            /* arg = xxxxxxab (IZ=0) */
+                                            /*     = ......ab (IZ=1) */
+        tcg_gen_shri_i64(t0, arg, 8);       /*  t0 = .xxxxxxa (IZ=0) */
+                                            /*     = .......a (IZ=1) */
         if (!(flags & TCG_BSWAP_IZ)) {
-            tcg_gen_ext8u_i64(t0, t0);
+            tcg_gen_ext8u_i64(t0, t0);      /*  t0 = .......a (IZ=0) */
         }
 
         if (flags & TCG_BSWAP_OS) {
-            tcg_gen_shli_i64(t1, arg, 56);
-            tcg_gen_sari_i64(t1, t1, 48);
+            tcg_gen_shli_i64(t1, arg, 56);  /*  t1 = b....... (OS=1) */
+            tcg_gen_sari_i64(t1, t1, 48);   /*  t1 = ssssssb. (OS=1) */
         } else if (flags & TCG_BSWAP_OZ) {
-            tcg_gen_ext8u_i64(t1, arg);
-            tcg_gen_shli_i64(t1, t1, 8);
+            tcg_gen_ext8u_i64(t1, arg);     /*  t1 = .......b (OZ=1) */
+            tcg_gen_shli_i64(t1, t1, 8);    /*  t1 = ......b. (OZ=1) */
         } else {
-            tcg_gen_shli_i64(t1, arg, 8);
+            tcg_gen_shli_i64(t1, arg, 8);   /*  t1 = xxxxxxb. (IZ=0) */
+                                            /*       ......b. (IZ=1) */
         }
 
-        tcg_gen_or_i64(ret, t0, t1);
+        tcg_gen_or_i64(ret, t0, t1);        /* ret = ......ba (IZ=1 or OZ=1) */
+                                            /*       ssssssba (OS=1)    */
+                                            /*       xxxxxxba (no flag) */
         tcg_temp_free_i64(t0);
         tcg_temp_free_i64(t1);
     }