From: Cornelia Huck <cohuck@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-s390x@nongnu.org,
Richard Henderson <richard.henderson@linaro.org>,
qemu-devel@nongnu.org, David Hildenbrand <david@redhat.com>
Subject: [Qemu-devel] [PULL 19/54] s390x/tcg: Implement VECTOR GALOIS FIELD MULTIPLY SUM (AND ACCUMULATE)
Date: Mon, 20 May 2019 19:02:27 +0200 [thread overview]
Message-ID: <20190520170302.13643-20-cohuck@redhat.com> (raw)
In-Reply-To: <20190520170302.13643-1-cohuck@redhat.com>
From: David Hildenbrand <david@redhat.com>
A galois field multiplication in field 2 is like binary multiplication,
however instead of doing ordinary binary additions, xor's are performed.
So no carries are considered.
Implement all variants via helpers. s390_vec_sar() and s390_vec_shr()
will be reused later on.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
target/s390x/helper.h | 8 ++
target/s390x/insn-data.def | 4 +
target/s390x/translate_vx.inc.c | 38 ++++++++
target/s390x/vec_int_helper.c | 167 ++++++++++++++++++++++++++++++++
4 files changed, 217 insertions(+)
diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index 60b8bd3c431a..6e6ba9bf32a2 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -154,6 +154,14 @@ DEF_HELPER_FLAGS_3(gvec_vclz8, TCG_CALL_NO_RWG, void, ptr, cptr, i32)
DEF_HELPER_FLAGS_3(gvec_vclz16, TCG_CALL_NO_RWG, void, ptr, cptr, i32)
DEF_HELPER_FLAGS_3(gvec_vctz8, TCG_CALL_NO_RWG, void, ptr, cptr, i32)
DEF_HELPER_FLAGS_3(gvec_vctz16, TCG_CALL_NO_RWG, void, ptr, cptr, i32)
+DEF_HELPER_FLAGS_4(gvec_vgfm8, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_4(gvec_vgfm16, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_4(gvec_vgfm32, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_4(gvec_vgfm64, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_5(gvec_vgfma8, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_5(gvec_vgfma16, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_5(gvec_vgfma32, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, cptr, i32)
+DEF_HELPER_FLAGS_5(gvec_vgfma64, TCG_CALL_NO_RWG, void, ptr, cptr, cptr, cptr, i32)
#ifndef CONFIG_USER_ONLY
DEF_HELPER_3(servc, i32, env, i64, i64)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index b8400c191a7f..add174b79381 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1090,6 +1090,10 @@
F(0xe752, VCTZ, VRR_a, V, 0, 0, 0, 0, vctz, 0, IF_VEC)
/* VECTOR EXCLUSIVE OR */
F(0xe76d, VX, VRR_c, V, 0, 0, 0, 0, vx, 0, IF_VEC)
+/* VECTOR GALOIS FIELD MULTIPLY SUM */
+ F(0xe7b4, VGFM, VRR_c, V, 0, 0, 0, 0, vgfm, 0, IF_VEC)
+/* VECTOR GALOIS FIELD MULTIPLY SUM AND ACCUMULATE */
+ F(0xe7bc, VGFMA, VRR_d, V, 0, 0, 0, 0, vgfma, 0, IF_VEC)
#ifndef CONFIG_USER_ONLY
/* COMPARE AND SWAP AND PURGE */
diff --git a/target/s390x/translate_vx.inc.c b/target/s390x/translate_vx.inc.c
index 0935857eff09..1db5d6d152c6 100644
--- a/target/s390x/translate_vx.inc.c
+++ b/target/s390x/translate_vx.inc.c
@@ -1483,3 +1483,41 @@ static DisasJumpType op_vx(DisasContext *s, DisasOps *o)
get_field(s->fields, v3));
return DISAS_NEXT;
}
+
+static DisasJumpType op_vgfm(DisasContext *s, DisasOps *o)
+{
+ const uint8_t es = get_field(s->fields, m4);
+ static const GVecGen3 g[4] = {
+ { .fno = gen_helper_gvec_vgfm8, },
+ { .fno = gen_helper_gvec_vgfm16, },
+ { .fno = gen_helper_gvec_vgfm32, },
+ { .fno = gen_helper_gvec_vgfm64, },
+ };
+
+ if (es > ES_64) {
+ gen_program_exception(s, PGM_SPECIFICATION);
+ return DISAS_NORETURN;
+ }
+ gen_gvec_3(get_field(s->fields, v1), get_field(s->fields, v2),
+ get_field(s->fields, v3), &g[es]);
+ return DISAS_NEXT;
+}
+
+static DisasJumpType op_vgfma(DisasContext *s, DisasOps *o)
+{
+ const uint8_t es = get_field(s->fields, m5);
+ static const GVecGen4 g[4] = {
+ { .fno = gen_helper_gvec_vgfma8, },
+ { .fno = gen_helper_gvec_vgfma16, },
+ { .fno = gen_helper_gvec_vgfma32, },
+ { .fno = gen_helper_gvec_vgfma64, },
+ };
+
+ if (es > ES_64) {
+ gen_program_exception(s, PGM_SPECIFICATION);
+ return DISAS_NORETURN;
+ }
+ gen_gvec_4(get_field(s->fields, v1), get_field(s->fields, v2),
+ get_field(s->fields, v3), get_field(s->fields, v4), &g[es]);
+ return DISAS_NEXT;
+}
diff --git a/target/s390x/vec_int_helper.c b/target/s390x/vec_int_helper.c
index d1b1f2850990..20a1034dd83e 100644
--- a/target/s390x/vec_int_helper.c
+++ b/target/s390x/vec_int_helper.c
@@ -15,6 +15,59 @@
#include "vec.h"
#include "exec/helper-proto.h"
+static bool s390_vec_is_zero(const S390Vector *v)
+{
+ return !v->doubleword[0] && !v->doubleword[1];
+}
+
+static void s390_vec_xor(S390Vector *res, const S390Vector *a,
+ const S390Vector *b)
+{
+ res->doubleword[0] = a->doubleword[0] ^ b->doubleword[0];
+ res->doubleword[1] = a->doubleword[1] ^ b->doubleword[1];
+}
+
+static void s390_vec_shl(S390Vector *d, const S390Vector *a, uint64_t count)
+{
+ uint64_t tmp;
+
+ g_assert(count < 128);
+ if (count == 0) {
+ d->doubleword[0] = a->doubleword[0];
+ d->doubleword[1] = a->doubleword[1];
+ } else if (count == 64) {
+ d->doubleword[0] = a->doubleword[1];
+ d->doubleword[1] = 0;
+ } else if (count < 64) {
+ tmp = extract64(a->doubleword[1], 64 - count, count);
+ d->doubleword[1] = a->doubleword[1] << count;
+ d->doubleword[0] = (a->doubleword[0] << count) | tmp;
+ } else {
+ d->doubleword[0] = a->doubleword[1] << (count - 64);
+ d->doubleword[1] = 0;
+ }
+}
+
+static void s390_vec_shr(S390Vector *d, const S390Vector *a, uint64_t count)
+{
+ uint64_t tmp;
+
+ g_assert(count < 128);
+ if (count == 0) {
+ d->doubleword[0] = a->doubleword[0];
+ d->doubleword[1] = a->doubleword[1];
+ } else if (count == 64) {
+ d->doubleword[1] = a->doubleword[0];
+ d->doubleword[0] = 0;
+ } else if (count < 64) {
+ tmp = a->doubleword[1] >> count;
+ d->doubleword[1] = deposit64(tmp, 64 - count, count, a->doubleword[0]);
+ d->doubleword[0] = a->doubleword[0] >> count;
+ } else {
+ d->doubleword[1] = a->doubleword[0] >> (count - 64);
+ d->doubleword[0] = 0;
+ }
+}
#define DEF_VAVG(BITS) \
void HELPER(gvec_vavg##BITS)(void *v1, const void *v2, const void *v3, \
uint32_t desc) \
@@ -74,3 +127,117 @@ void HELPER(gvec_vctz##BITS)(void *v1, const void *v2, uint32_t desc) \
}
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(8, 16)
+DEF_GALOIS_MULTIPLY(16, 32)
+DEF_GALOIS_MULTIPLY(32, 64)
+
+static S390Vector galois_multiply64(uint64_t a, uint64_t b)
+{
+ S390Vector res = {};
+ S390Vector va = {
+ .doubleword[1] = a,
+ };
+ S390Vector vb = {
+ .doubleword[1] = b,
+ };
+
+ while (!s390_vec_is_zero(&vb)) {
+ if (vb.doubleword[1] & 0x1) {
+ s390_vec_xor(&res, &res, &va);
+ }
+ s390_vec_shl(&va, &va, 1);
+ s390_vec_shr(&vb, &vb, 1);
+ }
+ return res;
+}
+
+#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); \
+ } \
+}
+DEF_VGFM(8, 16)
+DEF_VGFM(16, 32)
+DEF_VGFM(32, 64)
+
+void HELPER(gvec_vgfm64)(void *v1, const void *v2, const void *v3,
+ uint32_t desc)
+{
+ S390Vector tmp1, tmp2;
+ uint64_t a, b;
+
+ a = s390_vec_read_element64(v2, 0);
+ b = s390_vec_read_element64(v3, 0);
+ tmp1 = galois_multiply64(a, b);
+ a = s390_vec_read_element64(v2, 1);
+ b = s390_vec_read_element64(v3, 1);
+ tmp2 = galois_multiply64(a, b);
+ 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(8, 16)
+DEF_VGFMA(16, 32)
+DEF_VGFMA(32, 64)
+
+void HELPER(gvec_vgfma64)(void *v1, const void *v2, const void *v3,
+ const void *v4, uint32_t desc)
+{
+ S390Vector tmp1, tmp2;
+ uint64_t a, b;
+
+ a = s390_vec_read_element64(v2, 0);
+ b = s390_vec_read_element64(v3, 0);
+ tmp1 = galois_multiply64(a, b);
+ a = s390_vec_read_element64(v2, 1);
+ b = s390_vec_read_element64(v3, 1);
+ tmp2 = galois_multiply64(a, b);
+ s390_vec_xor(&tmp1, &tmp1, &tmp2);
+ s390_vec_xor(v1, &tmp1, v4);
+}
--
2.20.1
next prev parent reply other threads:[~2019-05-20 17:25 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-20 17:02 [Qemu-devel] [PULL 00/54] s390x update Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 01/54] pc-bios/s390-ccw: Clean up harmless misuse of isdigit() Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 02/54] s390-bios: Skip bootmap signature entries Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 03/54] pc-bios/s390: Update firmware image with "Skip bootmap signature entries" fix Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 04/54] s390/ipl: cast to SCSIDevice directly Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 05/54] s390/css: handle CCW_FLAG_SKIP Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 06/54] s390x/tcg: Implement VECTOR ADD Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 07/54] s390x/tcg: Implement VECTOR ADD COMPUTE CARRY Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 08/54] s390x/tcg: Implement VECTOR ADD WITH CARRY Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 09/54] s390x/tcg: Implement VECTOR ADD WITH CARRY COMPUTE CARRY Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 10/54] s390x/tcg: Implement VECTOR AND (WITH COMPLEMENT) Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 11/54] s390x/tcg: Implement VECTOR AVERAGE Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 12/54] s390x/tcg: Implement VECTOR AVERAGE LOGICAL Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 13/54] s390x/tcg: Implement VECTOR CHECKSUM Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 14/54] s390x/tcg: Implement VECTOR ELEMENT COMPARE * Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 15/54] s390x/tcg: Implement VECTOR " Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 16/54] s390x/tcg: Implement VECTOR COUNT LEADING ZEROS Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 17/54] s390x/tcg: Implement VECTOR COUNT TRAILING ZEROS Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 18/54] s390x/tcg: Implement VECTOR EXCLUSIVE OR Cornelia Huck
2019-05-20 17:02 ` Cornelia Huck [this message]
2019-05-30 11:22 ` [Qemu-devel] [PULL 19/54] s390x/tcg: Implement VECTOR GALOIS FIELD MULTIPLY SUM (AND ACCUMULATE) Peter Maydell
2019-05-31 9:45 ` David Hildenbrand
2019-05-31 11:32 ` David Hildenbrand
2019-05-31 12:18 ` Richard Henderson
2019-05-20 17:02 ` [Qemu-devel] [PULL 20/54] s390x/tcg: Implement VECTOR LOAD COMPLEMENT Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 21/54] s390x/tcg: Implement VECTOR LOAD POSITIVE Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 22/54] s390x/tcg: Implement VECTOR (MAXIMUM|MINIMUM) (LOGICAL) Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 23/54] s390x/tcg: Implement VECTOR MULTIPLY AND ADD * Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 24/54] s390x/tcg: Implement VECTOR MULTIPLY * Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 25/54] s390x/tcg: Implement VECTOR NAND Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 26/54] s390x/tcg: Implement VECTOR NOR Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 27/54] s390x/tcg: Implement VECTOR NOT EXCLUSIVE OR Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 28/54] s390x/tcg: Implement VECTOR OR Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 29/54] s390x/tcg: Implement VECTOR OR WITH COMPLEMENT Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 30/54] s390x/tcg: Implement VECTOR POPULATION COUNT Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 31/54] s390x/tcg: Implement VECTOR ELEMENT ROTATE LEFT LOGICAL Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 32/54] s390x/tcg: Implement VECTOR ELEMENT ROTATE AND INSERT UNDER MASK Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 33/54] s390x/tcg: Implement VECTOR ELEMENT SHIFT Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 34/54] s390x/tcg: Implement VECTOR SHIFT LEFT (BY BYTE) Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 35/54] s390x/tcg: Implement VECTOR SHIFT LEFT DOUBLE BY BYTE Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 36/54] s390x/tcg: Implement VECTOR SHIFT RIGHT ARITHMETIC Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 37/54] s390x/tcg: Implement VECTOR SHIFT RIGHT LOGICAL * Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 38/54] s390x/tcg: Implement VECTOR SUBTRACT Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 39/54] s390x/tcg: Implement VECTOR SUBTRACT COMPUTE BORROW INDICATION Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 40/54] s390x/tcg: Implement VECTOR SUBTRACT WITH " Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 41/54] s390x/tcg: Implement VECTOR SUBTRACT WITH BORROW COMPUTE " Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 42/54] s390x/tcg: Implement VECTOR SUM ACROSS DOUBLEWORD Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 43/54] s390x/tcg: Implement VECTOR SUM ACROSS QUADWORD Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 44/54] s390x/tcg: Implement VECTOR SUM ACROSS WORD Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 45/54] s390x/tcg: Implement VECTOR TEST UNDER MASK Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 46/54] linux headers: update against Linux 5.2-rc1 Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 47/54] s390x/cpumodel: ignore csske for expansion Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 48/54] s390x/cpumodel: Miscellaneous-Instruction-Extensions Facility 3 Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 49/54] s390x/cpumodel: msa9 facility Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 50/54] s390x/cpumodel: vector enhancements Cornelia Huck
2019-05-20 17:02 ` [Qemu-devel] [PULL 51/54] s390x/cpumodel: enhanced sort facility Cornelia Huck
2019-05-20 17:03 ` [Qemu-devel] [PULL 52/54] s390x/cpumodel: add Deflate-conversion facility Cornelia Huck
2019-05-20 17:03 ` [Qemu-devel] [PULL 53/54] s390x/cpumodel: add gen15 defintions Cornelia Huck
2019-05-20 17:03 ` [Qemu-devel] [PULL 54/54] s390x/cpumodel: wire up 8561 and 8562 as gen15 machines Cornelia Huck
2019-05-20 17:30 ` [Qemu-devel] [PULL 00/54] s390x update Peter Maydell
2019-05-20 19:00 ` Cornelia Huck
2019-05-21 7:20 ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
2019-05-21 8:39 ` Cornelia Huck
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=20190520170302.13643-20-cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@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).