4509de
From dce732e9fe47b44d1a985d10a0eb97aac6afa28e Mon Sep 17 00:00:00 2001
4509de
From: Andreas Arnez <arnez@linux.ibm.com>
4509de
Date: Wed, 25 Mar 2020 20:11:19 +0100
4509de
Subject: [PATCH 6/8] Add IBM z14 support
4509de
4509de
Add general support for IBM z14.  Also detect and handle the vector
4509de
enhancements facility 1, which specifically adds single-precision FP
4509de
arithmetic for vectors.
4509de
---
4509de
 CONFIG/include/atlconf.h            | 14 ++++----
4509de
 CONFIG/src/Makefile                 |  6 ++++
4509de
 CONFIG/src/atlcomp.txt              |  4 +++
4509de
 CONFIG/src/backend/Make.ext         |  4 ++-
4509de
 CONFIG/src/backend/archinfo_linux.c |  3 +-
4509de
 CONFIG/src/backend/probe_vxz2.c     | 12 +++++++
4509de
 CONFIG/src/probe_comp.c             |  3 +-
4509de
 include/atlas_prefetch.h            |  3 +-
4509de
 include/atlas_simd.h                | 53 +++++++++++++++++++++++++++++
4509de
 9 files changed, 91 insertions(+), 11 deletions(-)
4509de
 create mode 100644 CONFIG/src/backend/probe_vxz2.c
4509de
4509de
diff --git a/CONFIG/include/atlconf.h b/CONFIG/include/atlconf.h
4509de
index e51d56d..3828fdb 100644
4509de
--- a/CONFIG/include/atlconf.h
4509de
+++ b/CONFIG/include/atlconf.h
4509de
@@ -25,11 +25,11 @@ enum ARCHFAM {AFOther=0, AFPPC, AFSPARC, AFALPHA, AFX86, AFIA64, AFMIPS,
4509de
  * Corei3EP: v3 Haswell, E5-26XX
4509de
  * Corei4: skylake
4509de
  */
4509de
-#define NMACH 62
4509de
+#define NMACH 63
4509de
 static char *machnam[NMACH] =
4509de
    {"UNKNOWN", "PPCG4", "PPCG5", "POWER3", "POWER4", "POWER5",
4509de
     "POWER6", "POWER7", "POWER8", "POWERe6500",
4509de
-    "IBMz9", "IBMz10", "IBMz196", "IBMz12", "IBMz13",
4509de
+    "IBMz9", "IBMz10", "IBMz196", "IBMz12", "IBMz13", "IBMz14",
4509de
     "x86x87", "x86SSE1", "x86SSE2", "x86SSE3",
4509de
     "P5", "P5MMX", "PPRO", "PII", "PIII", "PM", "CoreSolo",
4509de
     "CoreDuo", "Core2Solo", "Core2", "Corei1", "Corei2", "Corei3",
4509de
@@ -42,7 +42,7 @@ static char *machnam[NMACH] =
4509de
     "ARM64xgene1", "ARM64a53", "ARM64a57"};
4509de
 enum MACHTYPE {MACHOther, PPCG4, PPCG5, IbmPwr3, IbmPwr4, IbmPwr5,
4509de
                IbmPwr6, IbmPwr7, IbmPwr8, Pwre6500,
4509de
-               IbmZ9, IbmZ10, IbmZ196, IbmZ12, IbmZ13, /* s390(x) in Linux */
4509de
+               IbmZ9, IbmZ10, IbmZ196, IbmZ12, IbmZ13, IbmZ14, /* s390(x) */
4509de
                x86x87, x86SSE1, x86SSE2, x86SSE3, /* generic targets */
4509de
                IntP5, IntP5MMX, IntPPRO, IntPII, IntPIII, IntPM, IntCoreS,
4509de
                IntCoreDuo, IntCore2Solo, IntCore2, IntCorei1, IntCorei2,
4509de
@@ -82,7 +82,7 @@ enum MACHTYPE {MACHOther, PPCG4, PPCG5, IbmPwr3, IbmPwr4, IbmPwr5,
4509de
 #define MachIsARM64(mach_) \
4509de
    ( (mach_) >= ARM64xg && || (mach_) <= ARM64a57)
4509de
 #define MachIsS390(mach_) \
4509de
-   ( (mach_) >= IbmZ9 && (mach_) <= IbmZ13 )
4509de
+   ( (mach_) >= IbmZ9 && (mach_) <= IbmZ14 )
4509de
 
4509de
 
4509de
 static char *f2c_namestr[5] = {"UNKNOWN","Add_", "Add__", "NoChange", "UpCase"};
4509de
@@ -96,13 +96,13 @@ enum F2CNAME {f2c_NamErr=0, f2c_Add_, f2c_Add__, f2c_NoChange, f2c_UpCase};
4509de
 enum F2CINT {f2c_IntErr=0, FintCint, FintClong, FintClonglong, FintCshort};
4509de
 enum F2CSTRING {f2c_StrErr=0, fstrSun, fstrCray, fstrStructVal, fstrStructPtr};
4509de
 
4509de
-#define NISA 15
4509de
+#define NISA 16
4509de
 static char *ISAXNAM[NISA] =
4509de
-   {"", "VSX", "VXZ", "AltiVec",
4509de
+   {"", "VSX", "VXZ2", "VXZ", "AltiVec",
4509de
     "AVXMAC", "AVXFMA4", "AVX", "SSE3", "SSE2", "SSE1", "3DNow",
4509de
     "FPV3D2MACNEON", "FPV3D16MACNEON", "FPV3D32MAC", "FPV3D16MAC"};
4509de
 enum ISAEXT
4509de
-   {ISA_None=0, ISA_VSX, ISA_VXZ, ISA_AV,
4509de
+   {ISA_None=0, ISA_VSX, ISA_VXZ2, ISA_VXZ, ISA_AV,
4509de
     ISA_AVXMAC, ISA_AVXFMA4, ISA_AVX, ISA_SSE3, ISA_SSE2, ISA_SSE1, ISA_3DNow,
4509de
     ISA_NEON, ISA_NEON16, ISA_VFP3D32MAC, ISA_VFP3D16MAC};
4509de
 
4509de
diff --git a/CONFIG/src/Makefile b/CONFIG/src/Makefile
4509de
index 212b9d7..782a4cf 100644
4509de
--- a/CONFIG/src/Makefile
4509de
+++ b/CONFIG/src/Makefile
4509de
@@ -158,6 +158,12 @@ IRun_NEON :
4509de
 	$(MAKE) $(atlrun) atldir=$(mydir) exe=xprobe_neon args="$(args)" \
4509de
                 redir=config0.out
4509de
 	- cat config0.out
4509de
+IRun_VXZ2 :
4509de
+	$(CC) $(CCFLAGS) -march=native -mvx -mzvector -o xprobe_vxz2 \
4509de
+           $(SRCdir)/backend/probe_svec.c $(SRCdir)/backend/probe_vxz2.c
4509de
+	$(MAKE) $(atlrun) atldir=$(mydir) exe=xprobe_vxz2 args="$(args)" \
4509de
+                redir=config0.out
4509de
+	- cat config0.out
4509de
 IRun_VXZ :
4509de
 	$(CC) $(CCFLAGS) -march=native -mvx -mzvector -o xprobe_vxz \
4509de
            $(SRCdir)/backend/probe_dvec.c $(SRCdir)/backend/probe_vxz.c
4509de
diff --git a/CONFIG/src/atlcomp.txt b/CONFIG/src/atlcomp.txt
4509de
index 2ac71cf..2cfacc2 100644
4509de
--- a/CONFIG/src/atlcomp.txt
4509de
+++ b/CONFIG/src/atlcomp.txt
4509de
@@ -250,6 +250,10 @@ MACH=IBMz13 OS=ALL LVL=1000 COMPS=smc,dmc,skc,dkc,icc,xcc,gcc
4509de
    'gcc' '-march=z13 -mtune=z13 -O2'
4509de
 MACH=IBMz13 OS=ALL LVL=1000 COMPS=f77
4509de
    'gfortran' '-march=z13 -mtune=z13 -O2'
4509de
+MACH=IBMz14 OS=ALL LVL=1000 COMPS=smc,dmc,skc,dkc,icc,xcc,gcc
4509de
+   'gcc' '-march=z14 -mtune=z14 -O2'
4509de
+MACH=IBMz14 OS=ALL LVL=1000 COMPS=f77
4509de
+   'gfortran' '-march=z14 -mtune=z14 -O2'
4509de
 #
4509de
 # Windows defaults ; need to make SSE/SSE2 arch dep.
4509de
 #
4509de
diff --git a/CONFIG/src/backend/Make.ext b/CONFIG/src/backend/Make.ext
4509de
index 4743353..794babf 100644
4509de
--- a/CONFIG/src/backend/Make.ext
4509de
+++ b/CONFIG/src/backend/Make.ext
4509de
@@ -39,7 +39,7 @@ files = archinfo_aix.c archinfo_freebsd.c archinfo_irix.c archinfo_linux.c \
4509de
         probe_gas_mips.S probe_gas_parisc.S probe_gas_ppc.S probe_gas_s390.S \
4509de
         probe_gas_sparc.S probe_gas_wow64.S probe_gas_x8632.S \
4509de
         probe_gas_x8664.S probe_smac.c probe_svec.c probe_this_asm.c \
4509de
-        probe_vxz.c
4509de
+        probe_vxz2.c probe_vxz.c
4509de
 
4509de
 all : $(files)
4509de
 
4509de
@@ -107,6 +107,8 @@ flibchkF.f : $(basf)
4509de
 	$(extF) -b $(basf) -o flibchkF.f rout=flibchkF.f
4509de
 probe_arm32_FPABI.c : $(basf)
4509de
 	$(extC) -b $(basf) -o probe_arm32_FPABI.c rout=probe_arm32_FPABI
4509de
+probe_vxz2.c : $(basf)
4509de
+	$(extC) -b $(basf) -o probe_vxz2.c rout=probe_vxz2
4509de
 probe_vxz.c : $(basf)
4509de
 	$(extC) -b $(basf) -o probe_vxz.c rout=probe_vxz
4509de
 probe_aff_SETAFFNP.c : $(basf)
4509de
diff --git a/CONFIG/src/backend/archinfo_linux.c b/CONFIG/src/backend/archinfo_linux.c
4509de
index cdcee92..ed6f476 100644
4509de
--- a/CONFIG/src/backend/archinfo_linux.c
4509de
+++ b/CONFIG/src/backend/archinfo_linux.c
4509de
@@ -336,7 +336,8 @@ enum MACHTYPE ProbeArch()
4509de
          else if (strstr(res, "2817") || strstr(res, "2818")) mach = IbmZ196;
4509de
          else if (strstr(res, "2827") || strstr(res, "2828")) mach = IbmZ12;
4509de
          else if (strstr(res, "2964") || strstr(res, "2965")) mach = IbmZ13;
4509de
-         else mach = IbmZ13;  /* looks risky to me, but IBM folks did it */
4509de
+         else if (strstr(res, "3906") || strstr(res, "3907")) mach = IbmZ14;
4509de
+         else mach = IbmZ14;  /* looks risky to me, but IBM folks did it */
4509de
          free(res);
4509de
       }
4509de
       break;
4509de
diff --git a/CONFIG/src/backend/probe_vxz2.c b/CONFIG/src/backend/probe_vxz2.c
4509de
new file mode 100644
4509de
index 0000000..a69d92d
4509de
--- /dev/null
4509de
+++ b/CONFIG/src/backend/probe_vxz2.c
4509de
@@ -0,0 +1,12 @@
4509de
+#include <vecintrin.h>
4509de
+void do_vsum(float *z, float *x, float *y) // RETURNS: z = x + y
4509de
+{
4509de
+   vector float vx, vy;
4509de
+   vx = (vector float) {x[0], x[1], x[2], x[3]};
4509de
+   vy = (vector float) {y[0], y[1], y[2], y[3]};
4509de
+   vy += vx;
4509de
+   z[0] = vy[0];
4509de
+   z[1] = vy[1];
4509de
+   z[2] = vy[2];
4509de
+   z[3] = vy[3];
4509de
+}
4509de
diff --git a/CONFIG/src/probe_comp.c b/CONFIG/src/probe_comp.c
4509de
index 1652e24..857ea82 100644
4509de
--- a/CONFIG/src/probe_comp.c
4509de
+++ b/CONFIG/src/probe_comp.c
4509de
@@ -452,7 +452,7 @@ COMPNODE **GetDefaultComps(enum OSTYPE OS, enum MACHTYPE arch, int verb,
4509de
       vp = "-mavx2 -mfma";
4509de
    else if (vecexts & (1<
4509de
       vp = "-mvsx";
4509de
-   else if (vecexts & (1<
4509de
+   else if ((vecexts & (1<
4509de
       vp = "-mvx -mzvector";
4509de
    else if (vecexts & (1<
4509de
       vp = "-maltivec";
4509de
@@ -1207,6 +1207,7 @@ void GetBestGccVers(enum OSTYPE OS, enum MACHTYPE arch,
4509de
    {
4509de
    case IbmZ12:
4509de
    case IbmZ13:
4509de
+   case IbmZ14:
4509de
    case IntCorei3:
4509de
    case IntCorei4:
4509de
    case IntCorei2:
4509de
diff --git a/include/atlas_prefetch.h b/include/atlas_prefetch.h
4509de
index e7988a7..fa426ac 100644
4509de
--- a/include/atlas_prefetch.h
4509de
+++ b/include/atlas_prefetch.h
4509de
@@ -155,7 +155,8 @@
4509de
    #define ATL_L1LS 32
4509de
    #define ATL_L2LS 64
4509de
 #elif defined(ATL_ARCH_IBMz196) || defined(ATL_ARCH_IBMz10) || \
4509de
-      defined(ATL_ARCH_IBMzEC12) || defined(ATL_ARCH_IBMz13)
4509de
+      defined(ATL_ARCH_IBMzEC12) || defined(ATL_ARCH_IBMz13) || \
4509de
+      defined(ATL_ARCH_IbmZ14)
4509de
    #define ATL_pfl1R(mem) __builtin_prefetch(mem, 0, 3)
4509de
    #define ATL_pfl1W(mem) __builtin_prefetch(mem, 1, 3)
4509de
    #define ATL_GOT_L1PREFETCH
4509de
diff --git a/include/atlas_simd.h b/include/atlas_simd.h
4509de
index f171933..eb75577 100644
4509de
--- a/include/atlas_simd.h
4509de
+++ b/include/atlas_simd.h
4509de
@@ -68,6 +68,11 @@
4509de
           ((defined(DREAL) || defined(DCPLX)) && ATL_VLEN != 2)
4509de
          #define ATL_FRCGNUVEC
4509de
       #endif
4509de
+   #elif defined(ATL_VXZ2)
4509de
+      #if ((defined(SREAL) || defined(SCPLX)) && ATL_VLEN != 4) || \
4509de
+          ((defined(DREAL) || defined(DCPLX)) && ATL_VLEN != 2)
4509de
+         #define ATL_FRCGNUVEC
4509de
+      #endif
4509de
    #elif defined(ATL_VXZ)
4509de
       #if ATL_VLEN != 2
4509de
          #define ATL_FRCGNUVEC
4509de
@@ -113,6 +118,12 @@
4509de
       #else
4509de
          #define ATL_VLEN 2
4509de
       #endif
4509de
+   #elif defined(ATL_VXZ2)
4509de
+      #if defined(SREAL) || defined(SCPLX)
4509de
+         #define ATL_VLEN 4
4509de
+      #else
4509de
+         #define ATL_VLEN 2
4509de
+      #endif
4509de
    #elif defined(ATL_VXZ)
4509de
       #define ATL_VLEN 2
4509de
    #elif defined(ATL_NEON)
4509de
@@ -376,6 +387,48 @@
4509de
       #define ATL_vsplat0(d_, s_) d_ = vec_splat(s_, 0)
4509de
       #define ATL_vsplat1(d_, s_) d_ = vec_splat(s_, 1)
4509de
    #endif
4509de
+#elif defined(ATL_VXZ2)
4509de
+   #include <vecintrin.h>
4509de
+
4509de
+   #define ATL_VPERMI(s_, t_, i_) \
4509de
+     ((ATL_VTYPE) vec_permi((vector double) s_, (vector double) t_, i_))
4509de
+
4509de
+   #if defined(SREAL) || defined(SCPLX)
4509de
+      #define ATL_VTYPE vector float
4509de
+      #if ATL_VLEN != 4
4509de
+         #error "VSXZ2 supports only VLEN = 4 for floats!"
4509de
+      #endif
4509de
+      #define ATL_vvrsum4(s0_, s1_, s2_, s3_) \
4509de
+      {	 ATL_VTYPE t0_, t1_; \
4509de
+         t0_ = vec_mergeh(s0_, s1_) + vec_mergel(s0_, s1_); \
4509de
+         t1_ = vec_mergeh(s2_, s3_) + vec_mergel(s2_, s3_); \
4509de
+         s0_ = ATL_VPERMI(t0_, t1_, 0) + ATL_VPERMI(t0_, t1_, 3); \
4509de
+      }
4509de
+      #define ATL_vsplat2(d_, s_) d_ = vec_splat(s_, 2)
4509de
+      #define ATL_vsplat3(d_, s_) d_ = vec_splat(s_, 3)
4509de
+   #else        /* double precision */
4509de
+      #define ATL_VTYPE vector double
4509de
+      #if ATL_VLEN != 2
4509de
+         #error "VSXZ2 supports only VLEN = 2 for doubles!"
4509de
+      #endif
4509de
+      #define ATL_vvrsum1(s0_) \
4509de
+      {  s0_ = vec_mergeh(s0_, s0_) + vec_mergel(s0_, s0_); }
4509de
+      #define ATL_vvrsum2(s0_, s1_) \
4509de
+      {  s0_ = vec_mergeh(s0_, s1_) + vec_mergel(s0_, s1_); }
4509de
+   #endif
4509de
+   #define ATL_vld(v_, p_) v_ = *(ATL_VTYPE *)(p_)
4509de
+   #define ATL_vst(p_, v_) *(ATL_VTYPE *)(p_) = v_
4509de
+   #define ATL_vzero(v_) v_ = vec_splats((TYPE)0.0)
4509de
+   #define ATL_vcopy(d_, s_) d_ = s_
4509de
+   #define ATL_vbcast(v_, p_) v_ = vec_splats(*((TYPE*)(p_)))
4509de
+   #define ATL_vuld(v_, p_) v_ = vec_xl(0, (TYPE *)(p_))
4509de
+   #define ATL_vust(p_, v_) vec_xst(v_, 0, (TYPE *)(p_))
4509de
+   #define ATL_vadd(d_, s1_, s2_) d_ =  s1_ + s2_
4509de
+   #define ATL_vsub(d_, s1_, s2_) d_ =  s1_ - s2_
4509de
+   #define ATL_vmul(d_, s1_, s2_) d_ =  s1_ * s2_
4509de
+   #define ATL_vmac(d_, s1_, s2_) d_ = __builtin_s390_vec_madd(s1_, s2_, d_)
4509de
+   #define ATL_vsplat0(d_, s_) d_ = vec_splat(s_, 0)
4509de
+   #define ATL_vsplat1(d_, s_) d_ = vec_splat(s_, 1)
4509de
 #elif defined(ATL_VXZ)
4509de
    #include <vecintrin.h>
4509de
 
4509de
-- 
4509de
2.23.0
4509de