Skip to contentSkip to conversation

tcg/s390: Support host vector operations

PATCH In review Richard Henderson 2 participants 12 messages May 8, 2020 – May 11, 2020

lore
Share & tools
lore
#0 lore raw

cover tcg/s390: Support host vector operations

I've had this floating around on a branch for a while now It is able to run arm sve tests under qemu, but I have not been able to test it against real hardware.

r~

Richard Henderson (3):
tcg/s390: Change FACILITY representation
tcg/s390: Merge TCG_AREG0 and TCG_REG_CALL_STACK into TCGReg tcg/s390: Implement vector operations

 tcg/s390/tcg-target.h     |  92 ++--
 tcg/s390/tcg-target.opc.h |   5 +
 tcg/s390/tcg-target.inc.c | 862 +++++++++++++++++++++++++++++++++++---
 3 files changed, 864 insertions(+), 95 deletions(-)
 create mode 100644 tcg/s390/tcg-target.opc.h
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 tcg/s390: Change FACILITY representation

We will shortly need to be able to check facilities beyond the first 64. Instead of explicitly masking against s390_facilities, create a FACILITY macro that indexes an array.

---
 tcg/s390/tcg-target.h     | 29 ++++++++-------
 tcg/s390/tcg-target.inc.c | 74 +++++++++++++++++++--------------------
 2 files changed, 52 insertions(+), 51 deletions(-)
tcg/s390/tcg-target.h +16 -13
index 07accabbd1..7ca48457ff 100644
@@ -52,16 +52,19 @@ typedef enum TCGReg {
 /* A list of relevant facilities used by this translator.  Some of these
    are required for proper operation, and these are checked at startup.  */
 
-#define FACILITY_ZARCH_ACTIVE         (1ULL << (63 - 2))
-#define FACILITY_LONG_DISP            (1ULL << (63 - 18))
-#define FACILITY_EXT_IMM              (1ULL << (63 - 21))
-#define FACILITY_GEN_INST_EXT         (1ULL << (63 - 34))
-#define FACILITY_LOAD_ON_COND         (1ULL << (63 - 45))
+#define FACILITY_ZARCH_ACTIVE         2
+#define FACILITY_LONG_DISP            18
+#define FACILITY_EXT_IMM              21
+#define FACILITY_GEN_INST_EXT         34
+#define FACILITY_LOAD_ON_COND         45
 #define FACILITY_FAST_BCR_SER         FACILITY_LOAD_ON_COND
 #define FACILITY_DISTINCT_OPS         FACILITY_LOAD_ON_COND
-#define FACILITY_LOAD_ON_COND2        (1ULL << (63 - 53))
+#define FACILITY_LOAD_ON_COND2        53
 
-extern uint64_t s390_facilities;
+extern uint64_t s390_facilities[1];
+
+#define FACILITY(X) \
+    ((s390_facilities[FACILITY_##X / 64] >> (63 - FACILITY_##X % 64)) & 1)
 
 /* optional instructions */
 #define TCG_TARGET_HAS_div2_i32       1
@@ -82,8 +85,8 @@ extern uint64_t s390_facilities;
 #define TCG_TARGET_HAS_clz_i32        0
 #define TCG_TARGET_HAS_ctz_i32        0
 #define TCG_TARGET_HAS_ctpop_i32      0
-#define TCG_TARGET_HAS_deposit_i32    (s390_facilities & FACILITY_GEN_INST_EXT)
-#define TCG_TARGET_HAS_extract_i32    (s390_facilities & FACILITY_GEN_INST_EXT)
+#define TCG_TARGET_HAS_deposit_i32    FACILITY(GEN_INST_EXT)
+#define TCG_TARGET_HAS_extract_i32    FACILITY(GEN_INST_EXT)
 #define TCG_TARGET_HAS_sextract_i32   0
 #define TCG_TARGET_HAS_extract2_i32   0
 #define TCG_TARGET_HAS_movcond_i32    1
@@ -96,7 +99,7 @@ extern uint64_t s390_facilities;
 #define TCG_TARGET_HAS_extrl_i64_i32  0
 #define TCG_TARGET_HAS_extrh_i64_i32  0
 #define TCG_TARGET_HAS_goto_ptr       1
-#define TCG_TARGET_HAS_direct_jump    (s390_facilities & FACILITY_GEN_INST_EXT)
+#define TCG_TARGET_HAS_direct_jump    FACILITY(GEN_INST_EXT)
 
 #define TCG_TARGET_HAS_div2_i64       1
 #define TCG_TARGET_HAS_rot_i64        1
@@ -116,11 +119,11 @@ extern uint64_t s390_facilities;
 #define TCG_TARGET_HAS_eqv_i64        0
 #define TCG_TARGET_HAS_nand_i64       0
 #define TCG_TARGET_HAS_nor_i64        0
-#define TCG_TARGET_HAS_clz_i64        (s390_facilities & FACILITY_EXT_IMM)
+#define TCG_TARGET_HAS_clz_i64        FACILITY(EXT_IMM)
 #define TCG_TARGET_HAS_ctz_i64        0
 #define TCG_TARGET_HAS_ctpop_i64      0
-#define TCG_TARGET_HAS_deposit_i64    (s390_facilities & FACILITY_GEN_INST_EXT)
-#define TCG_TARGET_HAS_extract_i64    (s390_facilities & FACILITY_GEN_INST_EXT)
+#define TCG_TARGET_HAS_deposit_i64    FACILITY(GEN_INST_EXT)
+#define TCG_TARGET_HAS_extract_i64    FACILITY(GEN_INST_EXT)
 #define TCG_TARGET_HAS_sextract_i64   0
 #define TCG_TARGET_HAS_extract2_i64   0
 #define TCG_TARGET_HAS_movcond_i64    1
tcg/s390/tcg-target.inc.c +36 -38

269 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] tcg/s390: Change FACILITY representation

Quoted 29 lines · Richard Henderson

We will shortly need to be able to check facilities beyond the first 64. Instead of explicitly masking against s390_facilities, create a FACILITY macro that indexes an array.

---
 tcg/s390/tcg-target.h     | 29 ++++++++-------
 tcg/s390/tcg-target.inc.c | 74 +++++++++++++++++++--------------------
 2 files changed, 52 insertions(+), 51 deletions(-)
tcg/s390/tcg-target.h +5 -5
index 07accabbd1..7ca48457ff 100644
@@ -52,16 +52,19 @@ typedef enum TCGReg {
 /* A list of relevant facilities used by this translator.  Some of these
    are required for proper operation, and these are checked at startup.  */
 
-#define FACILITY_ZARCH_ACTIVE         (1ULL << (63 - 2))
-#define FACILITY_LONG_DISP            (1ULL << (63 - 18))
-#define FACILITY_EXT_IMM              (1ULL << (63 - 21))
-#define FACILITY_GEN_INST_EXT         (1ULL << (63 - 34))
-#define FACILITY_LOAD_ON_COND         (1ULL << (63 - 45))
+#define FACILITY_ZARCH_ACTIVE         2
+#define FACILITY_LONG_DISP            18
+#define FACILITY_EXT_IMM              21
+#define FACILITY_GEN_INST_EXT         34
+#define FACILITY_LOAD_ON_COND         45

tcg/s390/tcg-target.h typedef enum TCGReg { · line 67

Quoted 10 lines
tcg/s390/tcg-target.h +5 -2
 #define FACILITY_FAST_BCR_SER         FACILITY_LOAD_ON_COND
 #define FACILITY_DISTINCT_OPS         FACILITY_LOAD_ON_COND
-#define FACILITY_LOAD_ON_COND2        (1ULL << (63 - 53))
+#define FACILITY_LOAD_ON_COND2        53
 
-extern uint64_t s390_facilities;
+extern uint64_t s390_facilities[1];
+
+#define FACILITY(X) \
+    ((s390_facilities[FACILITY_##X / 64] >> (63 - FACILITY_##X % 64)) & 1)

I'd have named this "HAVE_FACILITY" or similar.

Apart from that, looks good

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH 2/3 tcg/s390: Merge TCG_AREG0 and TCG_REG_CALL_STACK into TCGReg

In reply to Richard Henderson

They are rightly values in the same enumeration.

---
 tcg/s390/tcg-target.h | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)
tcg/s390/tcg-target.h +7 -21
index 7ca48457ff..1e67c90ed2 100644
@@ -29,22 +29,13 @@
 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 19
 
 typedef enum TCGReg {
-    TCG_REG_R0 = 0,
-    TCG_REG_R1,
-    TCG_REG_R2,
-    TCG_REG_R3,
-    TCG_REG_R4,
-    TCG_REG_R5,
-    TCG_REG_R6,
-    TCG_REG_R7,
-    TCG_REG_R8,
-    TCG_REG_R9,
-    TCG_REG_R10,
-    TCG_REG_R11,
-    TCG_REG_R12,
-    TCG_REG_R13,
-    TCG_REG_R14,
-    TCG_REG_R15
+    TCG_REG_R0,  TCG_REG_R1,  TCG_REG_R2,  TCG_REG_R3,
+    TCG_REG_R4,  TCG_REG_R5,  TCG_REG_R6,  TCG_REG_R7,
+    TCG_REG_R8,  TCG_REG_R9,  TCG_REG_R10, TCG_REG_R11,
+    TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15,
+
+    TCG_AREG0 = TCG_REG_R10,
+    TCG_REG_CALL_STACK = TCG_REG_R15
 } TCGReg;
 
 #define TCG_TARGET_NB_REGS 16
@@ -135,7 +126,6 @@ extern uint64_t s390_facilities[1];
 #define TCG_TARGET_HAS_mulsh_i64      0
 
 /* used for function call generation */
-#define TCG_REG_CALL_STACK		TCG_REG_R15
 #define TCG_TARGET_STACK_ALIGN		8
 #define TCG_TARGET_CALL_STACK_OFFSET	160
 
@@ -144,10 +134,6 @@ extern uint64_t s390_facilities[1];
 
 #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)
 
-enum {
-    TCG_AREG0 = TCG_REG_R10,
-};
-
 static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
 {
 }
Signature · 1 line
2.20.1
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] tcg/s390: Merge TCG_AREG0 and TCG_REG_CALL_STACK into TCGReg

Quoted 51 lines · Richard Henderson

They are rightly values in the same enumeration.

---
 tcg/s390/tcg-target.h | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)
tcg/s390/tcg-target.h +7 -17
index 7ca48457ff..1e67c90ed2 100644
@@ -29,22 +29,13 @@
 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 19
 
 typedef enum TCGReg {
-    TCG_REG_R0 = 0,
-    TCG_REG_R1,
-    TCG_REG_R2,
-    TCG_REG_R3,
-    TCG_REG_R4,
-    TCG_REG_R5,
-    TCG_REG_R6,
-    TCG_REG_R7,
-    TCG_REG_R8,
-    TCG_REG_R9,
-    TCG_REG_R10,
-    TCG_REG_R11,
-    TCG_REG_R12,
-    TCG_REG_R13,
-    TCG_REG_R14,
-    TCG_REG_R15
+    TCG_REG_R0,  TCG_REG_R1,  TCG_REG_R2,  TCG_REG_R3,
+    TCG_REG_R4,  TCG_REG_R5,  TCG_REG_R6,  TCG_REG_R7,
+    TCG_REG_R8,  TCG_REG_R9,  TCG_REG_R10, TCG_REG_R11,
+    TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15,
+
+    TCG_AREG0 = TCG_REG_R10,
+    TCG_REG_CALL_STACK = TCG_REG_R15
 } TCGReg;
 
 #define TCG_TARGET_NB_REGS 16
@@ -135,7 +126,6 @@ extern uint64_t s390_facilities[1];
 #define TCG_TARGET_HAS_mulsh_i64      0
 
 /* used for function call generation */
-#define TCG_REG_CALL_STACK		TCG_REG_R15
 #define TCG_TARGET_STACK_ALIGN		8
 #define TCG_TARGET_CALL_STACK_OFFSET	160
 

tcg/s390/tcg-target.h extern uint64_t s390_facilities[1]; · line 139

Quoted 10 lines
tcg/s390/tcg-target.h +0 -4
@@ -144,10 +134,6 @@ extern uint64_t s390_facilities[1];
 
 #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD)
 
-enum {
-    TCG_AREG0 = TCG_REG_R10,
-};
-
 static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
 {
 }
Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw
In reply to Richard Henderson
Quoted 3 lines · Richard Henderson

I've had this floating around on a branch for a while now It is able to run arm sve tests under qemu, but I have not been able to test it against real hardware.

Dangit.
I hit send right as I remembered that I should mark this as:

Based-on: [email protected] ("tcg vector rotate operations").

r~

#6 lore raw

PATCH 3/3 tcg/s390: Implement vector operations

In reply to Richard Henderson

From z13, s390x has 128-bit vectors. The ISA is quite regular and easy to support under tcg.

---
 tcg/s390/tcg-target.h     |  37 +-
 tcg/s390/tcg-target.opc.h |   5 +
 tcg/s390/tcg-target.inc.c | 790 ++++++++++++++++++++++++++++++++++++--
 3 files changed, 807 insertions(+), 25 deletions(-)
 create mode 100644 tcg/s390/tcg-target.opc.h
tcg/s390/tcg-target.h +35 -2
index 1e67c90ed2..9b98119969 100644
@@ -34,11 +34,20 @@ typedef enum TCGReg {
     TCG_REG_R8,  TCG_REG_R9,  TCG_REG_R10, TCG_REG_R11,
     TCG_REG_R12, TCG_REG_R13, TCG_REG_R14, TCG_REG_R15,
 
+    TCG_REG_V0 = 32, TCG_REG_V1,  TCG_REG_V2,  TCG_REG_V3,
+    TCG_REG_V4,  TCG_REG_V5,  TCG_REG_V6,  TCG_REG_V7,
+    TCG_REG_V8,  TCG_REG_V9,  TCG_REG_V10, TCG_REG_V11,
+    TCG_REG_V12, TCG_REG_V13, TCG_REG_V14, TCG_REG_V15,
+    TCG_REG_V16, TCG_REG_V17, TCG_REG_V18, TCG_REG_V19,
+    TCG_REG_V20, TCG_REG_V21, TCG_REG_V22, TCG_REG_V23,
+    TCG_REG_V24, TCG_REG_V25, TCG_REG_V26, TCG_REG_V27,
+    TCG_REG_V28, TCG_REG_V29, TCG_REG_V30, TCG_REG_V31,
+
     TCG_AREG0 = TCG_REG_R10,
     TCG_REG_CALL_STACK = TCG_REG_R15
 } TCGReg;
 
-#define TCG_TARGET_NB_REGS 16
+#define TCG_TARGET_NB_REGS 64
 
 /* A list of relevant facilities used by this translator.  Some of these
    are required for proper operation, and these are checked at startup.  */
@@ -51,8 +60,10 @@ typedef enum TCGReg {
 #define FACILITY_FAST_BCR_SER         FACILITY_LOAD_ON_COND
 #define FACILITY_DISTINCT_OPS         FACILITY_LOAD_ON_COND
 #define FACILITY_LOAD_ON_COND2        53
+#define FACILITY_VECTOR               129
+#define FACILITY_VECTOR_EXT1          135
 
-extern uint64_t s390_facilities[1];
+extern uint64_t s390_facilities[3];
 
 #define FACILITY(X) \
     ((s390_facilities[FACILITY_##X / 64] >> (63 - FACILITY_##X % 64)) & 1)
@@ -125,6 +136,28 @@ extern uint64_t s390_facilities[1];
 #define TCG_TARGET_HAS_muluh_i64      0
 #define TCG_TARGET_HAS_mulsh_i64      0
 
+#define TCG_TARGET_HAS_v64            FACILITY(VECTOR)
+#define TCG_TARGET_HAS_v128           FACILITY(VECTOR)
+#define TCG_TARGET_HAS_v256           0
+
+#define TCG_TARGET_HAS_andc_vec       1
+#define TCG_TARGET_HAS_orc_vec        0
+#define TCG_TARGET_HAS_not_vec        1
+#define TCG_TARGET_HAS_neg_vec        1
+#define TCG_TARGET_HAS_abs_vec        1
+#define TCG_TARGET_HAS_roti_vec       1
+#define TCG_TARGET_HAS_rots_vec       1
+#define TCG_TARGET_HAS_rotv_vec       1
+#define TCG_TARGET_HAS_shi_vec        1
+#define TCG_TARGET_HAS_shs_vec        1
+#define TCG_TARGET_HAS_shv_vec        1
+#define TCG_TARGET_HAS_cmp_vec        1
+#define TCG_TARGET_HAS_mul_vec        1
+#define TCG_TARGET_HAS_sat_vec        1
+#define TCG_TARGET_HAS_minmax_vec     1
+#define TCG_TARGET_HAS_bitsel_vec     1
+#define TCG_TARGET_HAS_cmpsel_vec     0
+
 /* used for function call generation */
 #define TCG_TARGET_STACK_ALIGN		8
 #define TCG_TARGET_CALL_STACK_OFFSET	160
tcg/s390/tcg-target.opc.h new file +5 -0
new file mode 100644
index 0000000000..fa680dd6a0
@@ -0,0 +1,5 @@
+/*
+ * Target-specific opcodes for host vector expansion.  These will be
+ * emitted by tcg_expand_vec_op.  For those familiar with GCC internals,
+ * consider these to be UNSPEC with names.
+ */
tcg/s390/tcg-target.inc.c +767 -23

903 lines not on this page · raw message

Signature · 1 line
2.20.1
#7 lore raw
In reply to Richard Henderson
Quoted 3 lines · Richard Henderson

I've had this floating around on a branch for a while now It is able to run arm sve tests under qemu, but I have not been able to test it against real hardware.

You can run qemu-system-arm under qemu-system-s390 with vx=on ;) I'll try to give this a churn one I figure out what to apply where. thanks

Quoted 16 lines

r~

Richard Henderson (3):
tcg/s390: Change FACILITY representation
tcg/s390: Merge TCG_AREG0 and TCG_REG_CALL_STACK into TCGReg tcg/s390: Implement vector operations

 tcg/s390/tcg-target.h     |  92 ++--
 tcg/s390/tcg-target.opc.h |   5 +
 tcg/s390/tcg-target.inc.c | 862 +++++++++++++++++++++++++++++++++++---
 3 files changed, 864 insertions(+), 95 deletions(-)
 create mode 100644 tcg/s390/tcg-target.opc.h
Signature · 3 lines
Thanks,

David / dhildenb
#8 lore raw
Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Richard Henderson

I've had this floating around on a branch for a while now It is able to run arm sve tests under qemu, but I have not been able to test it against real hardware.

You can run qemu-system-arm under qemu-system-s390 with vx=on

(re-reading, I assume you did exactly that already)

I'm having issues building this due to lack of HWCAP_S390_VX.

[linux1@rhkvm01 qemu]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.7 (Maipo)

Signature · 3 lines
Thanks,

David / dhildenb
#9 lore raw
Quoted 6 lines · David Hildenbrand

On 11.05.20 10:50, David Hildenbrand wrote:
I'm having issues building this due to lack of HWCAP_S390_VX.

[linux1@rhkvm01 qemu]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.7 (Maipo)

Yes, I found that when I pushed the branch to shippable.

It seems there is a disconnect between glibc and the kernel, and some distros have fixed it and some have not. It's still broken in upstream glibc.

I have added an ifndef to the branch, but you can fix it locally by changing to HWCAP_S390_VXRS.

r~

#10 lore raw
Quoted 7 lines · Richard Henderson
Quoted 6 lines · David Hildenbrand

On 11.05.20 10:50, David Hildenbrand wrote:
I'm having issues building this due to lack of HWCAP_S390_VX.

[linux1@rhkvm01 qemu]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.7 (Maipo)

Quoted 7 lines

Yes, I found that when I pushed the branch to shippable.

It seems there is a disconnect between glibc and the kernel, and some distros have fixed it and some have not. It's still broken in upstream glibc.

I have added an ifndef to the branch, but you can fix it locally by changing to HWCAP_S390_VXRS.

Yes, compiles with that. Where are the arm sve tests located, so I can run them? (are they in tests/tcg?)

thanks!

Signature · 3 lines
Thanks,

David / dhildenb
#11 lore raw
Quoted 2 lines · David Hildenbrand

Yes, compiles with that. Where are the arm sve tests located, so I can run them? (are they in tests/tcg?)

Ah, they're risu files. I'll find somewhere to share them.

r~