Skip to content

Commit

Permalink
target/s390x: Use clmul_32* routines
Browse files Browse the repository at this point in the history
Use generic routines for 32-bit carry-less multiply.
Remove our local version of galois_multiply32.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Sep 15, 2023
1 parent bae25f6 commit 653aab2
Showing 1 changed file with 22 additions and 53 deletions.
75 changes: 22 additions & 53 deletions target/s390x/tcg/vec_int_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,6 @@ DEF_VCTZ(8)
DEF_VCTZ(16)

/* like binary multiplication, but XOR instead of addition */
#define DEF_GALOIS_MULTIPLY(BITS, TBITS) \
static uint##TBITS##_t galois_multiply##BITS(uint##TBITS##_t a, \
uint##TBITS##_t b) \
{ \
uint##TBITS##_t res = 0; \
\
while (b) { \
if (b & 0x1) { \
res = res ^ a; \
} \
a = a << 1; \
b = b >> 1; \
} \
return res; \
}
DEF_GALOIS_MULTIPLY(32, 64)

static S390Vector galois_multiply64(uint64_t a, uint64_t b)
{
Expand Down Expand Up @@ -254,24 +238,29 @@ void HELPER(gvec_vgfma16)(void *v1, const void *v2, const void *v3,
q1[1] = do_gfma16(q2[1], q3[1], q4[1]);
}

#define DEF_VGFM(BITS, TBITS) \
void HELPER(gvec_vgfm##BITS)(void *v1, const void *v2, const void *v3, \
uint32_t desc) \
{ \
int i; \
\
for (i = 0; i < (128 / TBITS); i++) { \
uint##BITS##_t a = s390_vec_read_element##BITS(v2, i * 2); \
uint##BITS##_t b = s390_vec_read_element##BITS(v3, i * 2); \
uint##TBITS##_t d = galois_multiply##BITS(a, b); \
\
a = s390_vec_read_element##BITS(v2, i * 2 + 1); \
b = s390_vec_read_element##BITS(v3, i * 2 + 1); \
d = d ^ galois_multiply32(a, b); \
s390_vec_write_element##TBITS(v1, i, d); \
} \
static inline uint64_t do_gfma32(uint64_t n, uint64_t m, uint64_t a)
{
return clmul_32(n, m) ^ clmul_32(n >> 32, m >> 32) ^ a;
}

void HELPER(gvec_vgfm32)(void *v1, const void *v2, const void *v3, uint32_t d)
{
uint64_t *q1 = v1;
const uint64_t *q2 = v2, *q3 = v3;

q1[0] = do_gfma32(q2[0], q3[0], 0);
q1[1] = do_gfma32(q2[1], q3[1], 0);
}

void HELPER(gvec_vgfma32)(void *v1, const void *v2, const void *v3,
const void *v4, uint32_t d)
{
uint64_t *q1 = v1;
const uint64_t *q2 = v2, *q3 = v3, *q4 = v4;

q1[0] = do_gfma32(q2[0], q3[0], q4[0]);
q1[1] = do_gfma32(q2[1], q3[1], q4[1]);
}
DEF_VGFM(32, 64)

void HELPER(gvec_vgfm64)(void *v1, const void *v2, const void *v3,
uint32_t desc)
Expand All @@ -288,26 +277,6 @@ void HELPER(gvec_vgfm64)(void *v1, const void *v2, const void *v3,
s390_vec_xor(v1, &tmp1, &tmp2);
}

#define DEF_VGFMA(BITS, TBITS) \
void HELPER(gvec_vgfma##BITS)(void *v1, const void *v2, const void *v3, \
const void *v4, uint32_t desc) \
{ \
int i; \
\
for (i = 0; i < (128 / TBITS); i++) { \
uint##BITS##_t a = s390_vec_read_element##BITS(v2, i * 2); \
uint##BITS##_t b = s390_vec_read_element##BITS(v3, i * 2); \
uint##TBITS##_t d = galois_multiply##BITS(a, b); \
\
a = s390_vec_read_element##BITS(v2, i * 2 + 1); \
b = s390_vec_read_element##BITS(v3, i * 2 + 1); \
d = d ^ galois_multiply32(a, b); \
d = d ^ s390_vec_read_element##TBITS(v4, i); \
s390_vec_write_element##TBITS(v1, i, d); \
} \
}
DEF_VGFMA(32, 64)

void HELPER(gvec_vgfma64)(void *v1, const void *v2, const void *v3,
const void *v4, uint32_t desc)
{
Expand Down

0 comments on commit 653aab2

Please sign in to comment.