This patch to libgo adds the runtime/internal/sys package that is in
the gc toolchain.  In the gc toolchain this package is mostly a
collection of generated files, one for each GOARCH value and one for
each GOOS value.  Rather than doing it in the gofrontend, we record
the information in configure.ac and write it out in Makefile.  My hope
is that this will make it easier to add new ports: people will have to
change the information in one place, configure.ac.

This change also removes the automake GOARCH conditionals, which are
no longer used.  The GOOS conditionals remain, as they are currently
used while building the C runtime code.

The new package includes intrinsics for ctz and bswap, so I have added
definitions of the builtin functions to the Gcc_backend constructor
along with the other builtin function definitions.  This is in the GCC
Go interface, not the gofrontend proper.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Because the file version.go is moving from the runtime package to the
sys package as part of this change, people with existing working
directories may need to remove their libgo directories before
rebuilding.  The automatic dependencies won't handle that change
correctly.

Ian

2016-09-11  Ian Lance Taylor  <i...@golang.org>

* go-gcc.cc (Gcc_backend::Gcc_backend): Add builtin versions of
ctz, ctzll, bswap32, bswap64.
Index: gcc/go/go-gcc.cc
===================================================================
--- gcc/go/go-gcc.cc    (revision 240053)
+++ gcc/go/go-gcc.cc    (working copy)
@@ -692,6 +692,28 @@ Gcc_backend::Gcc_backend()
                                                NULL_TREE),
                       false, false);
 
+  // Used by runtime/internal/sys.
+  this->define_builtin(BUILT_IN_CTZ, "__builtin_ctz", "ctz",
+                      build_function_type_list(integer_type_node,
+                                               unsigned_type_node,
+                                               NULL_TREE),
+                      true, false);
+  this->define_builtin(BUILT_IN_CTZLL, "__builtin_ctzll", "ctzll",
+                      build_function_type_list(integer_type_node,
+                                               long_long_unsigned_type_node,
+                                               NULL_TREE),
+                      true, false);
+  this->define_builtin(BUILT_IN_BSWAP32, "__builtin_bswap32", "bswap32",
+                      build_function_type_list(uint32_type_node,
+                                               uint32_type_node,
+                                               NULL_TREE),
+                      true, false);
+  this->define_builtin(BUILT_IN_BSWAP64, "__builtin_bswap64", "bswap64",
+                      build_function_type_list(uint64_type_node,
+                                               uint64_type_node,
+                                               NULL_TREE),
+                      true, false);
+
   // We provide some functions for the math library.
   tree math_function_type = build_function_type_list(double_type_node,
                                                     double_type_node,
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 240071)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-d3a145b111a4f4ea772b812c6a0b3a853c207819
+841bea960b1f097e2cff5ad2618800296dcd4ec2
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/Makefile.am
===================================================================
--- libgo/Makefile.am   (revision 240070)
+++ libgo/Makefile.am   (working copy)
@@ -586,12 +586,54 @@ time.c: $(srcdir)/runtime/time.goc goc2c
 version.go: s-version; @true
 s-version: Makefile
        rm -f version.go.tmp
-       echo "package runtime" > version.go.tmp
-       echo 'const defaultGoroot = "$(prefix)"' >> version.go.tmp
-       echo 'const theVersion = "'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) 
--version | sed 1q`'"' >> version.go.tmp
-       echo 'const theGoarch = "'$(GOARCH)'"' >> version.go.tmp
-       echo 'const theGoos = "'$(GOOS)'"' >> version.go.tmp
-       echo 'const theGccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
+       echo "package sys" > version.go.tmp
+       echo 'const DefaultGoroot = "$(prefix)"' >> version.go.tmp
+       echo 'const TheVersion = "'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) 
--version | sed 1q`'"' >> version.go.tmp
+       echo 'const GOARCH = "'$(GOARCH)'"' >> version.go.tmp
+       echo 'const GOOS = "'$(GOOS)'"' >> version.go.tmp
+       echo 'const GccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
+       echo >> version.go.tmp
+       echo "type ArchFamilyType int" >> version.go.tmp
+       echo >> version.go.tmp
+       echo "const (" >> version.go.tmp
+       echo "  UNKNOWN ArchFamilyType = iota" >> version.go.tmp
+       for a in $(ALLGOARCHFAMILY); do \
+         echo "        $${a}" >> version.go.tmp; \
+       done
+       echo ")" >> version.go.tmp
+       echo >> version.go.tmp
+       for a in $(ALLGOARCH); do \
+         f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 
'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
+         n="$${f}`echo $${a} | sed -e 's/.//'`"; \
+         if test "$${a}" = "$(GOARCH)"; then \
+           echo "const Goarch$${n} = 1" >> version.go.tmp; \
+         else \
+           echo "const Goarch$${n} = 0" >> version.go.tmp; \
+         fi; \
+       done
+       echo >> version.go.tmp
+       echo "const (" >> version.go.tmp
+       echo "  ArchFamily = $(GOARCH_FAMILY)" >> version.go.tmp
+       echo "  BigEndian = $(GOARCH_BIGENDIAN)" >> version.go.tmp
+       echo "  CacheLineSize = $(GOARCH_CACHELINESIZE)" >> version.go.tmp
+       echo "  PhysPageSize = $(GOARCH_PHYSPAGESIZE)" >> version.go.tmp
+       echo "  PCQuantum = $(GOARCH_PCQUANTUM)" >> version.go.tmp
+       echo "  Int64Align = $(GOARCH_INT64ALIGN)" >> version.go.tmp
+       echo "  HugePageSize = $(GOARCH_HUGEPAGESIZE)" >> version.go.tmp
+       echo "  MinFrameSize = $(GOARCH_MINFRAMESIZE)" >> version.go.tmp
+       echo ")" >> version.go.tmp
+       echo >> version.go.tmp
+       for a in $(ALLGOOS); do \
+         f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 
'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
+         n="$${f}`echo $${a} | sed -e 's/.//'`"; \
+         if test "$${a}" = "$(GOOS)"; then \
+           echo "const Goos$${n} = 1" >> version.go.tmp; \
+         else \
+           echo "const Goos$${n} = 0" >> version.go.tmp; \
+         fi; \
+       done
+       echo >> version.go.tmp
+       echo "type Uintreg uintptr" >> version.go.tmp
        $(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
        $(STAMP) $@
 
@@ -845,6 +887,7 @@ libgo_go_objs = \
        runtime/pprof.lo \
        runtime/internal/atomic.lo \
        runtime/internal/atomic_c.lo \
+       runtime/internal/sys.lo \
        sync/atomic.lo \
        sync/atomic_c.lo \
        text/scanner.lo \
@@ -1224,7 +1267,7 @@ regexp/check: $(CHECK_DEPS)
        @$(CHECK)
 .PHONY: regexp/check
 
-extra_go_files_runtime = runtime_sysinfo.go version.go
+extra_go_files_runtime = runtime_sysinfo.go
 
 @go_include@ runtime-go.lo.dep
 runtime-go.lo.dep: $(srcdir)/go/runtime/*.go $(extra_go_files_runtime)
@@ -2379,6 +2422,18 @@ runtime/internal/atomic/check: $(CHECK_D
        @$(CHECK)
 .PHONY: runtime/internal/atomic/check
 
+extra_go_files_runtime_internal_sys = version.go
+
+@go_include@ runtime/internal/sys.lo.dep
+runtime/internal/sys.lo.dep: $(srcdir)/go/runtime/internal/sys/*.go
+       $(BUILDDEPS)
+runtime_internal_sys_lo_GOCFLAGS = -fgo-compiling-runtime
+runtime/internal/sys.lo:
+       $(BUILDPACKAGE)
+runtime/internal/sys/check: $(CHECK_DEPS)
+       @$(CHECK)
+.PHONY: runtime/internal/sys/check
+
 @go_include@ sync/atomic.lo.dep
 sync/atomic.lo.dep: $(srcdir)/go/sync/atomic/*.go
        $(BUILDDEPS)
@@ -2816,6 +2871,8 @@ runtime/pprof.gox: runtime/pprof.lo
        $(BUILDGOX)
 runtime/internal/atomic.gox: runtime/internal/atomic.lo
        $(BUILDGOX)
+runtime/internal/sys.gox: runtime/internal/sys.lo
+       $(BUILDGOX)
 
 sync/atomic.gox: sync/atomic.lo
        $(BUILDGOX)
@@ -2971,6 +3028,7 @@ TEST_PACKAGES = \
        regexp/syntax/check \
        runtime/pprof/check \
        runtime/internal/atomic/check \
+       runtime/internal/sys/check \
        sync/atomic/check \
        text/scanner/check \
        text/tabwriter/check \
Index: libgo/configure.ac
===================================================================
--- libgo/configure.ac  (revision 240053)
+++ libgo/configure.ac  (working copy)
@@ -142,6 +142,11 @@ AC_SUBST(LIBATOMIC)
 go_include="-include"
 AC_SUBST(go_include)
 
+# All known GOOS values.  This is the union of all operating systems
+# supported by the gofrontend and all operating systems supported by
+# the gc toolchain.
+ALLGOOS="android darwin dragonfly freebsd irix linux netbsd openbsd plan9 
rtems solaris windows"
+
 is_darwin=no
 is_freebsd=no
 is_irix=no
@@ -174,6 +179,7 @@ AM_CONDITIONAL(LIBGO_IS_RTEMS, test $is_
 AM_CONDITIONAL(LIBGO_IS_SOLARIS, test $is_solaris = yes)
 AM_CONDITIONAL(LIBGO_IS_BSD, test $is_darwin = yes -o $is_dragonfly = yes -o 
$is_freebsd = yes -o $is_netbsd = yes -o $is_openbsd = yes)
 AC_SUBST(GOOS)
+AC_SUBST(ALLGOOS)
 
 dnl Test whether we need to use DejaGNU or whether we can use the
 dnl simpler gotest approach.  We can only use gotest for a native
@@ -186,35 +192,46 @@ case ${host} in
 esac
 AC_SUBST(USE_DEJAGNU)
 
-dnl N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
-is_386=no
-is_alpha=no
-is_arm=no
-is_arm64=no
-is_ia64=no
-is_m68k=no
-mips_abi=unknown
-is_ppc=no
-is_ppc64=no
-is_ppc64le=no
-is_s390=no
-is_s390x=no
-is_sparc=no
-is_sparc64=no
-is_x86_64=no
+# All known GOARCH values.  This is the union of all architectures
+# supported by the gofrontend and all architectures supported by the
+# gc toolchain.
+# N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
+ALLGOARCH="386 alpha amd64 amd64p32 arm armbe arm64 arm64be ia64 m68k mipso32 
mipsn32 mipso64 mipsn64 mips mipsle mips64 mips64le mips64p32 mips64pe32le ppc 
ppc64 ppc64le s390 s390x sparc sparc64"
+
+# All known GOARCH_FAMILY values.
+ALLGOARCHFAMILY="I386 ALPHA AMD64 ARM ARM64 IA64 M68K MIPS MIPS64 PPC PPC64 
S390 S390X SPARC SPARC64"
+
 GOARCH=unknown
+GOARCH_FAMILY=unknown
+GOARCH_BIGENDIAN=0
+GOARCH_CACHELINESIZE=64
+GOARCH_PHYSPAGESIZE=4096
+GOARCH_PCQUANTUM=1
+GOARCH_INT64ALIGN=8
+GOARCH_HUGEPAGESIZE=0
+GOARCH_MINFRAMESIZE=0
 case ${host} in
   alpha*-*-*)
-    is_alpha=yes
     GOARCH=alpha
+    GOARCH_FAMILY=ALPHA
+    GOARCH_PHYSPAGESIZE=8192
+    GOARCH_PCQUANTUM=4
     ;;
   aarch64-*-*)
-    is_arm64=yes
     GOARCH=arm64
+    GOARCH_FAMILY=ARM64
+    GOARCH_CACHELINESIZE=32
+    GOARCH_PHYSPAGESIZE=65536
+    GOARCH_PCQUANTUm=4
+    GOARCH_MINFRAMESIZE=8
     ;;
   arm*-*-* | strongarm*-*-* | ep9312*-*-* | xscale-*-*)
-    is_arm=yes
     GOARCH=arm
+    GOARCH_FAMILY=ARM
+    GOARCH_CACHELINESIZE=32
+    GOARCH_PCQUANTUM=4
+    GOARCH_INT64ALIGN=4
+    GOARCH_MINFRAMESIZE=4
     ;;
 changequote(,)dnl
   i[34567]86-*-* | x86_64-*-*)
@@ -223,20 +240,29 @@ changequote([,])dnl
 #ifdef __x86_64__
 #error 64-bit
 #endif],
-[is_386=yes], [is_x86_64=yes])
-    if test "$is_386" = "yes"; then
-      GOARCH=386
-    else
-      GOARCH=amd64
-    fi
+[GOARCH=386
+GOARCH_FAMILY=I386
+GOARCH_INT64ALIGN=4
+GOARCH_HUGEPAGESIZE="1 << 21"
+],
+[GOARCH=amd64
+GOARCH_FAMILY=AMD64
+GOARCH_HUGEPAGESIZE="1 << 21"
+])
     ;;
   ia64-*-*)
-    is_ia64=yes
     GOARCH=ia64
+    GOARCH_FAMILY=IA64
+    GOARCH_CACHELINESIZE=16384
+    GOARCH_PHYSPAGESIZE=8192
     ;;
   m68k*-*-*)
-    is_m68k=yes
     GOARCH=m68k
+    GOARCH_FAMILY=M68K
+    GOARCH_BIGENDIAN=1
+    GOARCH_CACHELINESIZE=16
+    GOARCH_PCQUANTUM=4
+    GOARCH_INT64ALIGN=4
     ;;
   mips*-*-*)
     AC_COMPILE_IFELSE([
@@ -267,72 +293,98 @@ changequote([,])dnl
     "n64") GOARCH=mipsn64 ;;
     "o64") GOARCH=mipso64 ;;
     esac
+    case "$mips_abi" in
+    "o32" | "n32")
+        GOARCH_FAMILY=MIPS
+       GOARCH_INT64ALIGN=4
+       GOARCH_MINFRAMESIZE=4
+        ;;
+    "n64" | "o64")
+        GOARCH_FAMILY=MIPS64
+       GOARCH_MINFRAMESIZE=8
+        ;;
+    esac
+    case "${host}" in
+    mips*el)
+        ;;
+    *)
+       GOARCH_BIGENDIAN=1
+        ;;
+    esac
+    GOARCH_CACHELINESIZE=32
+    GOARCH_PHYSPAGESIZE=16384
+    GOARCH_PCQUANTUM=4
     ;;
   rs6000*-*-* | powerpc*-*-*)
     AC_COMPILE_IFELSE([
 #ifdef _ARCH_PPC64
 #error 64-bit
 #endif],
-[is_ppc=yes],
-    [AC_COMPILE_IFELSE([
+[GOARCH=ppc
+GOARCH_FAMILY=PPC
+GOARCH_BIGENDIAN=1
+GOARCH_INT64ALIGN=4
+],
+    [
+GOARCH_FAMILY=PPC64
+AC_COMPILE_IFELSE([
 #if defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
 #error 64be
 #endif],
-[is_ppc64le=yes],[is_ppc64=yes])])
-    if test "$is_ppc" = "yes"; then
-      GOARCH=ppc
-    elif test "$is_ppc64" = "yes"; then
-      GOARCH=ppc64
-    else
-      GOARCH=ppc64le
-    fi
+[GOARCH=ppc64le
+],
+[GOARCH=ppc64
+GOARCH_BIGENDIAN=1
+])])
+    GOARCH_PHYSPAGESIZE=65536
+    GOARCH_PCQUANTUM=4
+    GOARCH_MINFRAMESIZE=32
     ;;
   s390*-*-*)
     AC_COMPILE_IFELSE([
 #if defined(__s390x__)
 #error 64-bit
 #endif],
-[is_s390=yes], [is_s390x=yes])
-    if test "$is_s390" = "yes"; then
-      GOARCH=s390
-    else
-      GOARCH=s390x
-    fi
+[GOARCH=s390
+GOARCH_FAMILY=S390
+GOARCH_INT64ALIGN=4
+GOARCH_MINFRAMESIZE=4
+], [GOARCH=s390x
+GOARCH_FAMILY=S390X
+GOARCH_MINFRAMESIZE=8
+])
+    GOARCH_BIGENDIAN=1
+    GOARCH_CACHELINESIZE=256
+    GOARCH_PCQUANTUM=2
     ;;
   sparc*-*-*)
     AC_COMPILE_IFELSE([
 #if defined(__sparcv9) || defined(__arch64__)
 #error 64-bit
 #endif],
-[is_sparc=yes], [is_sparc64=yes])
-    if test "$is_sparc" = "yes"; then
-      GOARCH=sparc
-    else
-      GOARCH=sparc64
-    fi
+[GOARCH=sparc
+GOARCH_FAMILY=SPARC
+GOARCH_INT64ALIGN=4
+],
+[GOARCH=sparc64
+GOARCH_FAMILY=SPARC64
+])
+    GOARCH_BIGENDIAN=1
+    GOARCH_PHYSPAGESIZE=8192
+    GOARCH_PCQUANTUM=4
     ;;
 esac
-AM_CONDITIONAL(LIBGO_IS_386, test $is_386 = yes)
-AM_CONDITIONAL(LIBGO_IS_ALPHA, test $is_alpha = yes)
-AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
-AM_CONDITIONAL(LIBGO_IS_ARM64, test $is_arm64 = yes)
-AM_CONDITIONAL(LIBGO_IS_IA64, test $is_ia64 = yes)
-AM_CONDITIONAL(LIBGO_IS_M68K, test $is_m68k = yes)
-AM_CONDITIONAL(LIBGO_IS_MIPS, test $mips_abi != unknown)
-AM_CONDITIONAL(LIBGO_IS_MIPSO32, test $mips_abi = o32)
-AM_CONDITIONAL(LIBGO_IS_MIPSN32, test $mips_abi = n32)
-AM_CONDITIONAL(LIBGO_IS_MIPSN64, test $mips_abi = n64)
-AM_CONDITIONAL(LIBGO_IS_MIPSO64, test $mips_abi = o64)
-AM_CONDITIONAL(LIBGO_IS_MIPS64, test $mips_abi = n64 -o $mips_abi = o64)
-AM_CONDITIONAL(LIBGO_IS_PPC, test $is_ppc = yes)
-AM_CONDITIONAL(LIBGO_IS_PPC64, test $is_ppc64 = yes)
-AM_CONDITIONAL(LIBGO_IS_PPC64LE, test $is_ppc64le = yes)
-AM_CONDITIONAL(LIBGO_IS_S390, test $is_s390 = yes)
-AM_CONDITIONAL(LIBGO_IS_S390X, test $is_s390x = yes)
-AM_CONDITIONAL(LIBGO_IS_SPARC, test $is_sparc = yes)
-AM_CONDITIONAL(LIBGO_IS_SPARC64, test $is_sparc64 = yes)
-AM_CONDITIONAL(LIBGO_IS_X86_64, test $is_x86_64 = yes)
 AC_SUBST(GOARCH)
+AC_SUBST(GOARCH_FAMILY)
+AC_SUBST(GOARCH_BIGENDIAN)
+AC_SUBST(GOARCH_CACHELINESIZE)
+AC_SUBST(GOARCH_PHYSPAGESIZE)
+AC_SUBST(GOARCH_PCQUANTUM)
+AC_SUBST(GOARCH_INT64ALIGN)
+AC_SUBST(GOARCH_HUGEPAGESIZE)
+AC_SUBST(GOARCH_MINFRAMESIZE)
+AC_SUBST(ALLGOARCH)
+AC_SUBST(ALLGOARCHFAMILY)
 
 dnl Some files are only present when needed for specific architectures.
 GO_LIBCALL_OS_FILE=
Index: libgo/go/runtime/extern.go
===================================================================
--- libgo/go/runtime/extern.go  (revision 240053)
+++ libgo/go/runtime/extern.go  (working copy)
@@ -157,6 +157,8 @@ of the run-time system.
 */
 package runtime
 
+import "runtime/internal/sys"
+
 // Gosched yields the processor, allowing other goroutines to run.  It does not
 // suspend the current goroutine, so execution resumes automatically.
 func Gosched()
@@ -282,23 +284,23 @@ func GOROOT() string {
        if s != "" {
                return s
        }
-       return defaultGoroot
+       return sys.DefaultGoroot
 }
 
 // Version returns the Go tree's version string.
 // It is either the commit hash and date at the time of the build or,
 // when possible, a release tag like "go1.3".
 func Version() string {
-       return theVersion
+       return sys.TheVersion
 }
 
 // GOOS is the running program's operating system target:
 // one of darwin, freebsd, linux, and so on.
-const GOOS string = theGoos
+const GOOS string = sys.GOOS
 
 // GOARCH is the running program's architecture target:
 // 386, amd64, arm, or s390x.
-const GOARCH string = theGoarch
+const GOARCH string = sys.GOARCH
 
 // GCCGOTOOLDIR is the Tool Dir for the gccgo build
-const GCCGOTOOLDIR string = theGccgoToolDir
+const GCCGOTOOLDIR string = sys.GccgoToolDir
Index: libgo/go/runtime/internal/sys/intrinsics.go
===================================================================
--- libgo/go/runtime/internal/sys/intrinsics.go (revision 0)
+++ libgo/go/runtime/internal/sys/intrinsics.go (working copy)
@@ -0,0 +1,77 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sys
+
+//extern __builtin_ctz
+func builtinCtz32(uint32) int32
+
+//extern __builtin_ctzll
+func builtinCtz64(uint64) int32
+
+//go:nosplit
+
+// Ctz64 counts trailing (low-order) zeroes,
+// and if all are zero, then 64.
+func Ctz64(x uint64) uint64 {
+       if x == 0 {
+               return 64
+       }
+       return uint64(builtinCtz64(x))
+}
+
+//go:nosplit
+
+// Ctz32 counts trailing (low-order) zeroes,
+// and if all are zero, then 32.
+func Ctz32(x uint32) uint32 {
+       if x == 0 {
+               return 32
+       }
+       return uint32(builtinCtz32(x))
+}
+
+//go:nosplit
+
+// Ctz16 counts trailing (low-order) zeroes,
+// and if all are zero, then 16.
+func Ctz16(x uint16) uint16 {
+       if x == 0 {
+               return 16
+       }
+       return uint16(builtinCtz32(uint32(x)))
+}
+
+//go:nosplit
+
+// Ctz8 counts trailing (low-order) zeroes,
+// and if all are zero, then 8.
+func Ctz8(x uint8) uint8 {
+       if x == 0 {
+               return 8
+       }
+       return uint8(builtinCtz32(uint32(x)))
+}
+
+//extern __builtin_bswap64
+func bswap64(uint64) uint64
+
+//go:nosplit
+
+// Bswap64 returns its input with byte order reversed
+// 0x0102030405060708 -> 0x0807060504030201
+func Bswap64(x uint64) uint64 {
+       return bswap64(x)
+}
+
+//extern __builtin_bswap32
+func bswap32(uint32) uint32
+
+//go:nosplit
+
+// Bswap32 returns its input with byte order reversed
+// 0x01020304 -> 0x04030201
+func Bswap32(x uint32) uint32 {
+       return bswap32(x)
+}
Index: libgo/go/runtime/internal/sys/intrinsics_test.go
===================================================================
--- libgo/go/runtime/internal/sys/intrinsics_test.go    (revision 0)
+++ libgo/go/runtime/internal/sys/intrinsics_test.go    (working copy)
@@ -0,0 +1,54 @@
+package sys_test
+
+import (
+       "runtime/internal/sys"
+       "testing"
+)
+
+func TestCtz64(t *testing.T) {
+       for i := uint(0); i <= 64; i++ {
+               x := uint64(5) << i
+               if got := sys.Ctz64(x); got != uint64(i) {
+                       t.Errorf("Ctz64(%d)=%d, want %d", x, got, i)
+               }
+       }
+}
+func TestCtz32(t *testing.T) {
+       for i := uint(0); i <= 32; i++ {
+               x := uint32(5) << i
+               if got := sys.Ctz32(x); got != uint32(i) {
+                       t.Errorf("Ctz32(%d)=%d, want %d", x, got, i)
+               }
+       }
+}
+func TestCtz16(t *testing.T) {
+       for i := uint(0); i <= 16; i++ {
+               x := uint16(5) << i
+               if got := sys.Ctz16(x); got != uint16(i) {
+                       t.Errorf("Ctz16(%d)=%d, want %d", x, got, i)
+               }
+       }
+}
+func TestCtz8(t *testing.T) {
+       for i := uint(0); i <= 8; i++ {
+               x := uint8(5) << i
+               if got := sys.Ctz8(x); got != uint8(i) {
+                       t.Errorf("Ctz8(%d)=%d, want %d", x, got, i)
+               }
+       }
+}
+
+func TestBswap64(t *testing.T) {
+       x := uint64(0x1122334455667788)
+       y := sys.Bswap64(x)
+       if y != 0x8877665544332211 {
+               t.Errorf("Bswap(%x)=%x, want 0x8877665544332211", x, y)
+       }
+}
+func TestBswap32(t *testing.T) {
+       x := uint32(0x11223344)
+       y := sys.Bswap32(x)
+       if y != 0x44332211 {
+               t.Errorf("Bswap(%x)=%x, want 0x44332211", x, y)
+       }
+}
Index: libgo/go/runtime/internal/sys/stubs.go
===================================================================
--- libgo/go/runtime/internal/sys/stubs.go      (revision 0)
+++ libgo/go/runtime/internal/sys/stubs.go      (working copy)
@@ -0,0 +1,11 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sys
+
+// Declarations for runtime services implemented in C or assembly.
+
+const PtrSize = 4 << (^uintptr(0) >> 63)           // 
unsafe.Sizeof(uintptr(0)) but an ideal const
+const RegSize = 4 << (^Uintreg(0) >> 63)           // 
unsafe.Sizeof(uintreg(0)) but an ideal const
+const SpAlign = 1*(1-GoarchArm64) + 16*GoarchArm64 // SP alignment: 1 
normally, 16 for ARM64
Index: libgo/go/runtime/internal/sys/sys.go
===================================================================
--- libgo/go/runtime/internal/sys/sys.go        (revision 0)
+++ libgo/go/runtime/internal/sys/sys.go        (working copy)
@@ -0,0 +1,15 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// package sys contains system- and configuration- and architecture-specific
+// constants used by the runtime.
+package sys
+
+// The next line makes 'go generate' write the zgen_*.go files with
+// per-OS and per-arch information, including constants
+// named goos_$GOOS and goarch_$GOARCH for every
+// known GOOS and GOARCH. The constant is 1 on the
+// current system, 0 otherwise; multiplying by them is
+// useful for defining GOOS- or GOARCH-specific constants.
+//go:generate go run gengoos.go
Index: libgo/testsuite/Makefile.in
===================================================================
--- libgo/testsuite/Makefile.in (revision 240053)
+++ libgo/testsuite/Makefile.in (working copy)
@@ -79,6 +79,9 @@ am__can_run_installinfo = \
 DEJATOOL = $(PACKAGE)
 RUNTESTDEFAULTFLAGS = --tool $$tool --srcdir $$srcdir
 ACLOCAL = @ACLOCAL@
+ALLGOARCH = @ALLGOARCH@
+ALLGOARCHFAMILY = @ALLGOARCHFAMILY@
+ALLGOOS = @ALLGOOS@
 AMTAR = @AMTAR@
 AR = @AR@
 AUTOCONF = @AUTOCONF@
@@ -103,6 +106,14 @@ EGREP = @EGREP@
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GOARCH = @GOARCH@
+GOARCH_BIGENDIAN = @GOARCH_BIGENDIAN@
+GOARCH_CACHELINESIZE = @GOARCH_CACHELINESIZE@
+GOARCH_FAMILY = @GOARCH_FAMILY@
+GOARCH_HUGEPAGESIZE = @GOARCH_HUGEPAGESIZE@
+GOARCH_INT64ALIGN = @GOARCH_INT64ALIGN@
+GOARCH_MINFRAMESIZE = @GOARCH_MINFRAMESIZE@
+GOARCH_PCQUANTUM = @GOARCH_PCQUANTUM@
+GOARCH_PHYSPAGESIZE = @GOARCH_PHYSPAGESIZE@
 GOC = @GOC@
 GOCFLAGS = @GOCFLAGS@
 GOOS = @GOOS@

Reply via email to