qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: paul@nowt.org, richard.henderson@linaro.org
Subject: [PATCH v3 13/23] i386: Rewrite simple integer vector helpers
Date: Thu,  1 Sep 2022 09:48:32 +0200	[thread overview]
Message-ID: <20220901074842.57424-14-pbonzini@redhat.com> (raw)
In-Reply-To: <20220901074842.57424-1-pbonzini@redhat.com>

From: Paul Brook <paul@nowt.org>

Rewrite the "simple" vector integer helpers in preperation for AVX support.

While the current code is able to use the same prototype for unary
(a = F(b)) and binary (a = F(b, c)) operations, future changes will cause
them to diverge.

No functional changes to existing helpers

Signed-off-by: Paul Brook <paul@nowt.org>
Message-Id: <20220424220204.2493824-12-paul@nowt.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/ops_sse.h | 83 +++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 55 deletions(-)

diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h
index a4a09226e3..ce03362810 100644
--- a/target/i386/ops_sse.h
+++ b/target/i386/ops_sse.h
@@ -229,63 +229,36 @@ void glue(helper_pslldq, SUFFIX)(CPUX86State *env, Reg *d, Reg *c)
 }
 #endif
 
-#define SSE_HELPER_B(name, F)                                   \
+#define SSE_HELPER_1(name, elem, num, F)                        \
     void glue(name, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)   \
     {                                                           \
-        d->B(0) = F(d->B(0), s->B(0));                          \
-        d->B(1) = F(d->B(1), s->B(1));                          \
-        d->B(2) = F(d->B(2), s->B(2));                          \
-        d->B(3) = F(d->B(3), s->B(3));                          \
-        d->B(4) = F(d->B(4), s->B(4));                          \
-        d->B(5) = F(d->B(5), s->B(5));                          \
-        d->B(6) = F(d->B(6), s->B(6));                          \
-        d->B(7) = F(d->B(7), s->B(7));                          \
-        XMM_ONLY(                                               \
-                 d->B(8) = F(d->B(8), s->B(8));                 \
-                 d->B(9) = F(d->B(9), s->B(9));                 \
-                 d->B(10) = F(d->B(10), s->B(10));              \
-                 d->B(11) = F(d->B(11), s->B(11));              \
-                 d->B(12) = F(d->B(12), s->B(12));              \
-                 d->B(13) = F(d->B(13), s->B(13));              \
-                 d->B(14) = F(d->B(14), s->B(14));              \
-                 d->B(15) = F(d->B(15), s->B(15));              \
-                                                        )       \
-            }
+        int n = num;                                            \
+        for (int i = 0; i < n; i++) {                           \
+            d->elem(i) = F(s->elem(i));                         \
+        }                                                       \
+    }
+
+#define SSE_HELPER_2(name, elem, num, F)                        \
+    void glue(name, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)   \
+    {                                                           \
+        Reg *v = d;                                             \
+        int n = num;                                            \
+        for (int i = 0; i < n; i++) {                           \
+            d->elem(i) = F(v->elem(i), s->elem(i));             \
+        }                                                       \
+    }
+
+#define SSE_HELPER_B(name, F)                                   \
+    SSE_HELPER_2(name, B, 8 << SHIFT, F)
 
 #define SSE_HELPER_W(name, F)                                   \
-    void glue(name, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)   \
-    {                                                           \
-        d->W(0) = F(d->W(0), s->W(0));                          \
-        d->W(1) = F(d->W(1), s->W(1));                          \
-        d->W(2) = F(d->W(2), s->W(2));                          \
-        d->W(3) = F(d->W(3), s->W(3));                          \
-        XMM_ONLY(                                               \
-                 d->W(4) = F(d->W(4), s->W(4));                 \
-                 d->W(5) = F(d->W(5), s->W(5));                 \
-                 d->W(6) = F(d->W(6), s->W(6));                 \
-                 d->W(7) = F(d->W(7), s->W(7));                 \
-                                                        )       \
-            }
+    SSE_HELPER_2(name, W, 4 << SHIFT, F)
 
 #define SSE_HELPER_L(name, F)                                   \
-    void glue(name, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)   \
-    {                                                           \
-        d->L(0) = F(d->L(0), s->L(0));                          \
-        d->L(1) = F(d->L(1), s->L(1));                          \
-        XMM_ONLY(                                               \
-                 d->L(2) = F(d->L(2), s->L(2));                 \
-                 d->L(3) = F(d->L(3), s->L(3));                 \
-                                                        )       \
-            }
+    SSE_HELPER_2(name, L, 2 << SHIFT, F)
 
 #define SSE_HELPER_Q(name, F)                                   \
-    void glue(name, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)   \
-    {                                                           \
-        d->Q(0) = F(d->Q(0), s->Q(0));                          \
-        XMM_ONLY(                                               \
-                 d->Q(1) = F(d->Q(1), s->Q(1));                 \
-                                                        )       \
-            }
+    SSE_HELPER_2(name, Q, 1 << SHIFT, F)
 
 #if SHIFT == 0
 static inline int satub(int x)
@@ -1544,12 +1517,12 @@ void glue(helper_phsubsw, SUFFIX)(CPUX86State *env, Reg *d, Reg *s)
     MOVE(*d, r);
 }
 
-#define FABSB(_, x) (x > INT8_MAX  ? -(int8_t)x : x)
-#define FABSW(_, x) (x > INT16_MAX ? -(int16_t)x : x)
-#define FABSL(_, x) (x > INT32_MAX ? -(int32_t)x : x)
-SSE_HELPER_B(helper_pabsb, FABSB)
-SSE_HELPER_W(helper_pabsw, FABSW)
-SSE_HELPER_L(helper_pabsd, FABSL)
+#define FABSB(x) (x > INT8_MAX  ? -(int8_t)x : x)
+#define FABSW(x) (x > INT16_MAX ? -(int16_t)x : x)
+#define FABSL(x) (x > INT32_MAX ? -(int32_t)x : x)
+SSE_HELPER_1(helper_pabsb, B, 8 << SHIFT, FABSB)
+SSE_HELPER_1(helper_pabsw, W, 4 << SHIFT, FABSW)
+SSE_HELPER_1(helper_pabsd, L, 2 << SHIFT, FABSL)
 
 #define FMULHRSW(d, s) (((int16_t) d * (int16_t)s + 0x4000) >> 15)
 SSE_HELPER_W(helper_pmulhrsw, FMULHRSW)
-- 
2.37.1




  parent reply	other threads:[~2022-09-01  8:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01  7:48 [PATCH v3 00/23] target/i386: make SSE helpers generic in the vector size Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 01/23] i386: do not use MOVL to move data between SSE registers Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 02/23] i386: formatting fixes Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 03/23] i386: Add ZMM_OFFSET macro Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 04/23] i386: Rework sse_op_table1 Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 05/23] i386: Rework sse_op_table6/7 Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 06/23] i386: Move 3DNOW decoder Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 07/23] i386: check SSE table flags instead of hardcoding opcodes Paolo Bonzini
2022-09-01  8:05   ` Richard Henderson
2022-09-01  7:48 ` [PATCH v3 08/23] i386: isolate MMX code more Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 09/23] i386: Add size suffix to vector FP helpers Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 10/23] i386: do not cast gen_helper_* function pointers Paolo Bonzini
2022-09-01  8:10   ` Richard Henderson
2022-09-01  7:48 ` [PATCH v3 11/23] i386: Add CHECK_NO_VEX Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 12/23] i386: Rewrite vector shift helper Paolo Bonzini
2022-09-01  8:11   ` Richard Henderson
2022-09-01  7:48 ` Paolo Bonzini [this message]
2022-09-01  7:48 ` [PATCH v3 14/23] i386: Misc integer AVX helper prep Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 15/23] i386: Destructive vector helpers for AVX Paolo Bonzini
2022-09-01  8:16   ` Richard Henderson
2022-09-01  7:48 ` [PATCH v3 16/23] i386: Floating point arithmetic helper AVX prep Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 17/23] i386: reimplement AVX comparison helpers Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 18/23] i386: Dot product AVX helper prep Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 19/23] i386: Destructive FP helpers for AVX Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 20/23] i386: Misc AVX helper prep Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 21/23] i386: Rewrite blendv helpers Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 22/23] i386: AVX pclmulqdq prep Paolo Bonzini
2022-09-01  7:48 ` [PATCH v3 23/23] i386: AVX+AES helpers prep Paolo Bonzini
2022-09-01  8:19   ` 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=20220901074842.57424-14-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=paul@nowt.org \
    --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).