public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* libgo patch committed: Add S/390 support to internal/cpu package
@ 2019-02-15 14:52 Ian Lance Taylor
  2019-02-15 19:59 ` Matthias Klose
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2019-02-15 14:52 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev; +Cc: rdapp

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

This patch by Robin Dapp adds S/390 support to the internal/cpu
package.  This partially addresses PR 89123.  I bootstrapped it on
x86_64-pc-linux-gnu, which means little.  Committed to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6778 bytes --]

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268940)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@
-6877c95a5f44c3ab4f492d2000ce07771341d7b7
+0563f2d018cdb2cd685c254bac5ceb38396d0a27
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/internal/cpu/cpu_gccgo.c
===================================================================
--- libgo/go/internal/cpu/cpu_gccgo.c	(revision 268369)
+++ libgo/go/internal/cpu/cpu_gccgo.c	(working copy)
@@ -70,3 +70,118 @@ struct xgetbv_ret xgetbv(void) {
 #pragma GCC pop_options
 
 #endif /* defined(__i386__) || defined(__x86_64__)  */
+
+#ifdef __s390__
+
+struct facilityList {
+	uint64_t bits[4];
+};
+
+struct queryResult {
+	uint64_t bits[2];
+};
+
+struct facilityList stfle(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.stfle")
+  __attribute__((no_split_stack));
+
+struct facilityList stfle(void) {
+    struct facilityList ret;
+    __asm__ ("la    %%r1, %[ret]\t\n"
+	     "lghi  %%r0, 3\t\n" // last doubleword index to store
+	     "xc    0(32,%%r1), 0(%%r1)\t\n" // clear 4 doublewords (32 bytes)
+	     ".long 0xb2b01000\t\n"  // store facility list extended (STFLE)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+    return ret;
+}
+
+struct queryResult kmQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.kmQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult kmQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n" // set function code to 0 (KM-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb92e0024\t\n" // cipher message (KM)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+    return ret;
+}
+
+struct queryResult kmcQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.kmcQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult kmcQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n" // set function code to 0 (KMC-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb92f0024\t\n"  // cipher message with chaining (KMC)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+
+    return ret;
+}
+
+struct queryResult kmctrQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.kmctrQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult kmctrQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n" // set function code to 0 (KMCTR-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb92d4024\t\n" // cipher message with counter (KMCTR)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+
+    return ret;
+}
+
+struct queryResult kmaQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.kmaQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult kmaQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n" // set function code to 0 (KMA-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb9296024\t\n" // cipher message with authentication (KMA)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+
+    return ret;
+}
+
+struct queryResult kimdQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.kimdQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult kimdQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n"  // set function code to 0 (KIMD-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb93e0024\t\n"  // compute intermediate message digest (KIMD)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+
+    return ret;
+}
+
+struct queryResult klmdQuery(void)
+  __asm__(GOSYM_PREFIX "internal..z2fcpu.klmdQuery")
+  __attribute__((no_split_stack));
+
+struct queryResult klmdQuery() {
+    struct queryResult ret;
+
+    __asm__ ("lghi   %%r0, 0\t\n"  // set function code to 0 (KLMD-Query)
+	     "la     %%r1, %[ret]\t\n"
+	     ".long  0xb93f0024\t\n"  // compute last message digest (KLMD)
+	     :[ret] "=Q" (ret) : : "r0", "r1", "cc");
+
+    return ret;
+}
+
+#endif /* defined(__s390__)  */
Index: libgo/go/internal/cpu/cpu_s390x.go
===================================================================
--- libgo/go/internal/cpu/cpu_s390x.go	(revision 268369)
+++ libgo/go/internal/cpu/cpu_s390x.go	(working copy)
@@ -98,13 +98,13 @@ func (s *facilityList) Has(fs ...facilit
 
 // The following feature detection functions are defined in cpu_s390x.s.
 // They are likely to be expensive to call so the results should be cached.
-func stfle() facilityList     { panic("not implemented for gccgo") }
-func kmQuery() queryResult    { panic("not implemented for gccgo") }
-func kmcQuery() queryResult   { panic("not implemented for gccgo") }
-func kmctrQuery() queryResult { panic("not implemented for gccgo") }
-func kmaQuery() queryResult   { panic("not implemented for gccgo") }
-func kimdQuery() queryResult  { panic("not implemented for gccgo") }
-func klmdQuery() queryResult  { panic("not implemented for gccgo") }
+func stfle() facilityList
+func kmQuery() queryResult
+func kmcQuery() queryResult
+func kmctrQuery() queryResult
+func kmaQuery() queryResult
+func kimdQuery() queryResult
+func klmdQuery() queryResult
 
 func doinit() {
 	options = []option{
@@ -122,14 +122,6 @@ func doinit() {
 	aes := []function{aes128, aes192, aes256}
 	facilities := stfle()
 
-	S390X.HasZArch = facilities.Has(zarch)
-	S390X.HasSTFLE = facilities.Has(stflef)
-	S390X.HasLDisp = facilities.Has(ldisp)
-	S390X.HasEImm = facilities.Has(eimm)
-	S390X.HasDFP = facilities.Has(dfp)
-	S390X.HasETF3Enhanced = facilities.Has(etf3eh)
-	S390X.HasMSA = facilities.Has(msa)
-
 	if S390X.HasMSA {
 		// cipher message
 		km, kmc := kmQuery(), kmcQuery()
Index: libgo/go/runtime/os_linux_s390x.go
===================================================================
--- libgo/go/runtime/os_linux_s390x.go	(revision 268369)
+++ libgo/go/runtime/os_linux_s390x.go	(working copy)
@@ -8,12 +8,26 @@ import "internal/cpu"
 
 const (
 	// bit masks taken from bits/hwcap.h
-	_HWCAP_S390_VX = 2048 // vector facility
+	_HWCAP_S390_ZARCH  = 2
+	_HWCAP_S390_STFLE  = 4
+	_HWCAP_S390_MSA    = 8
+	_HWCAP_S390_LDISP  = 16
+	_HWCAP_S390_EIMM   = 32
+	_HWCAP_S390_DFP    = 64
+	_HWCAP_S390_ETF3EH = 256
+	_HWCAP_S390_VX     = 2048 // vector facility
 )
 
 func archauxv(tag, val uintptr) {
 	switch tag {
 	case _AT_HWCAP: // CPU capability bit flags
+		cpu.S390X.HasZArch = val&_HWCAP_S390_ZARCH != 0
+		cpu.S390X.HasSTFLE = val&_HWCAP_S390_STFLE != 0
+		cpu.S390X.HasMSA = val&_HWCAP_S390_MSA != 0
+		cpu.S390X.HasLDisp = val&_HWCAP_S390_LDISP != 0
+		cpu.S390X.HasEImm = val&_HWCAP_S390_EIMM != 0
+		cpu.S390X.HasDFP = val&_HWCAP_S390_DFP != 0
+		cpu.S390X.HasETF3Enhanced = val&_HWCAP_S390_ETF3EH != 0
 		cpu.S390X.HasVX = val&_HWCAP_S390_VX != 0
 	}
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgo patch committed: Add S/390 support to internal/cpu package
  2019-02-15 14:52 libgo patch committed: Add S/390 support to internal/cpu package Ian Lance Taylor
@ 2019-02-15 19:59 ` Matthias Klose
  2019-02-16  7:42   ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Klose @ 2019-02-15 19:59 UTC (permalink / raw)
  To: Ian Lance Taylor, gcc-patches, gofrontend-dev; +Cc: rdapp

On 15.02.19 15:52, Ian Lance Taylor wrote:
> This patch by Robin Dapp adds S/390 support to the internal/cpu
> package.  This partially addresses PR 89123.  I bootstrapped it on
> x86_64-pc-linux-gnu, which means little.  Committed to mainline.

fails in the -m31 multilib variant with

libtool: compile:  /<<PKGBUILDDIR>>/build/./gcc/xgcc
-B/<<PKGBUILDDIR>>/build/./gcc/ -B/usr/s390x-linux-gnu/bin/
-B/usr/s390x-linux-gnu/lib/ -isystem /usr/s390x-linux-gnu/include -isystem
/usr/s390x-linux-gnu/sys-include -isys
tem /<<PKGBUILDDIR>>/build/sys-include -m31 -DHAVE_CONFIG_H -I.
-I../../../../src/libgo -I ../../../../src/libgo/
runtime -I../../../../src/libgo/../libffi/include -I../libffi/include -pthread
-L../libatomic/.libs -fexceptions
-fnon-call-exceptions -fno-stack-protector -fsplit-stack -Wall -Wextra
-Wwrite-strings -Wcast-qual -D_GNU_SOURCE
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I ../../../../src/libgo/../libgcc -I
../../../../src/libgo/../libback
trace -I ../../../gcc/include -g -O2 -m31 -c
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c  -fPIC -DPIC -o in
ternal/cpu/.libs/cpu_gccgo.o

../../../../src/libgo/go/internal/cpu/cpu_gccgo.c: Assembler messages:
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:91: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:105: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:119: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:134: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:149: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:164: Error: Unrecognized
opcode: `lghi'
../../../../src/libgo/go/internal/cpu/cpu_gccgo.c:179: Error: Unrecognized
opcode: `lghi'
make[10]: *** [Makefile:2899: internal/cpu/cpu_gccgo.lo] Error 1

make[10]: *** Waiting for unfinished jobs....
make[10]: Leaving directory '/<<PKGBUILDDIR>>/build/s390x-linux-gnu/32/libgo'
make[9]: *** [Makefile:2242: all-recursive] Error 1
make[9]: Leaving directory '/<<PKGBUILDDIR>>/build/s390x-linux-gnu/32/libgo'
make[8]: *** [Makefile:1167: all] Error 2
make[8]: Leaving directory '/<<PKGBUILDDIR>>/build/s390x-linux-gnu/32/libgo'
make[7]: *** [Makefile:3062: multi-do] Error 1

using binutils 2.32

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgo patch committed: Add S/390 support to internal/cpu package
  2019-02-15 19:59 ` Matthias Klose
@ 2019-02-16  7:42   ` Jakub Jelinek
  2019-02-16 21:28     ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2019-02-16  7:42 UTC (permalink / raw)
  To: Ian Lance Taylor, Matthias Klose; +Cc: gcc-patches, gofrontend-dev, rdapp

On Fri, Feb 15, 2019 at 08:59:29PM +0100, Matthias Klose wrote:
> On 15.02.19 15:52, Ian Lance Taylor wrote:
> > This patch by Robin Dapp adds S/390 support to the internal/cpu
> > package.  This partially addresses PR 89123.  I bootstrapped it on
> > x86_64-pc-linux-gnu, which means little.  Committed to mainline.
> 
> fails in the -m31 multilib variant with

Indeed.  Given that there is just
libgo/go/internal/cpu/cpu_s390x.go
libgo/go/internal/cpu/cpu_s390x_test.go
(note, no s390), I think the easiest fix is:

--- libgo/go/internal/cpu/cpu_gccgo.c.jj	2019-02-16 07:57:27.882179972 +0100
+++ libgo/go/internal/cpu/cpu_gccgo.c	2019-02-16 08:36:37.241900882 +0100
@@ -71,7 +71,7 @@ struct xgetbv_ret xgetbv(void) {
 
 #endif /* defined(__i386__) || defined(__x86_64__)  */
 
-#ifdef __s390__
+#ifdef __s390x__
 
 struct facilityList {
 	uint64_t bits[4];
@@ -184,4 +184,4 @@ struct queryResult klmdQuery() {
     return ret;
 }
 
-#endif /* defined(__s390__)  */
+#endif /* defined(__s390x__)  */

If cpu_s390.go is ever added, this can be changed again and there can be say
#ifdef __s390x__
#define LHI "lghi"
#else
#define LHI "lhi"
#endif
and replace "lghi ... in the inline asm with LHI "...

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgo patch committed: Add S/390 support to internal/cpu package
  2019-02-16  7:42   ` Jakub Jelinek
@ 2019-02-16 21:28     ` Jakub Jelinek
  2019-02-21  1:45       ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2019-02-16 21:28 UTC (permalink / raw)
  To: Ian Lance Taylor, Matthias Klose; +Cc: gcc-patches, gofrontend-dev, rdapp

On Sat, Feb 16, 2019 at 08:42:11AM +0100, Jakub Jelinek wrote:
> On Fri, Feb 15, 2019 at 08:59:29PM +0100, Matthias Klose wrote:
> > On 15.02.19 15:52, Ian Lance Taylor wrote:
> > > This patch by Robin Dapp adds S/390 support to the internal/cpu
> > > package.  This partially addresses PR 89123.  I bootstrapped it on
> > > x86_64-pc-linux-gnu, which means little.  Committed to mainline.
> > 
> > fails in the -m31 multilib variant with
> 
> Indeed.  Given that there is just
> libgo/go/internal/cpu/cpu_s390x.go
> libgo/go/internal/cpu/cpu_s390x_test.go
> (note, no s390), I think the easiest fix is:

Bootstrapped/regtested on s390x-linux successfully now.

> --- libgo/go/internal/cpu/cpu_gccgo.c.jj	2019-02-16 07:57:27.882179972 +0100
> +++ libgo/go/internal/cpu/cpu_gccgo.c	2019-02-16 08:36:37.241900882 +0100
> @@ -71,7 +71,7 @@ struct xgetbv_ret xgetbv(void) {
>  
>  #endif /* defined(__i386__) || defined(__x86_64__)  */
>  
> -#ifdef __s390__
> +#ifdef __s390x__
>  
>  struct facilityList {
>  	uint64_t bits[4];
> @@ -184,4 +184,4 @@ struct queryResult klmdQuery() {
>      return ret;
>  }
>  
> -#endif /* defined(__s390__)  */
> +#endif /* defined(__s390x__)  */
> 
> If cpu_s390.go is ever added, this can be changed again and there can be say
> #ifdef __s390x__
> #define LHI "lghi"
> #else
> #define LHI "lhi"
> #endif
> and replace "lghi ... in the inline asm with LHI "...

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libgo patch committed: Add S/390 support to internal/cpu package
  2019-02-16 21:28     ` Jakub Jelinek
@ 2019-02-21  1:45       ` Ian Lance Taylor
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Lance Taylor @ 2019-02-21  1:45 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Matthias Klose, gcc-patches, gofrontend-dev, rdapp

On Sat, Feb 16, 2019 at 1:28 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Sat, Feb 16, 2019 at 08:42:11AM +0100, Jakub Jelinek wrote:
> > On Fri, Feb 15, 2019 at 08:59:29PM +0100, Matthias Klose wrote:
> > > On 15.02.19 15:52, Ian Lance Taylor wrote:
> > > > This patch by Robin Dapp adds S/390 support to the internal/cpu
> > > > package.  This partially addresses PR 89123.  I bootstrapped it on
> > > > x86_64-pc-linux-gnu, which means little.  Committed to mainline.
> > >
> > > fails in the -m31 multilib variant with
> >
> > Indeed.  Given that there is just
> > libgo/go/internal/cpu/cpu_s390x.go
> > libgo/go/internal/cpu/cpu_s390x_test.go
> > (note, no s390), I think the easiest fix is:
>
> Bootstrapped/regtested on s390x-linux successfully now.

Thanks, committed to mainline.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-02-21  1:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-15 14:52 libgo patch committed: Add S/390 support to internal/cpu package Ian Lance Taylor
2019-02-15 19:59 ` Matthias Klose
2019-02-16  7:42   ` Jakub Jelinek
2019-02-16 21:28     ` Jakub Jelinek
2019-02-21  1:45       ` Ian Lance Taylor

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 read-only IMAP folder(s) and NNTP newsgroup(s).