]> Cypherpunks repositories - gostls13.git/commitdiff
all: implement GO386=softfloat
authorKeith Randall <khr@golang.org>
Tue, 6 Oct 2020 21:42:15 +0000 (14:42 -0700)
committerKeith Randall <khr@golang.org>
Tue, 6 Oct 2020 22:49:38 +0000 (22:49 +0000)
Backstop support for non-sse2 chips now that 387 is gone.

RELNOTE=yes

Change-Id: Ib10e69c4a3654c15a03568f93393437e1939e013
Reviewed-on: https://go-review.googlesource.com/c/go/+/260017
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
13 files changed:
src/cmd/compile/internal/x86/galign.go
src/cmd/dist/build.go
src/cmd/dist/buildruntime.go
src/cmd/go/alldocs.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/help/helpdoc.go
src/cmd/internal/objabi/util.go
src/internal/cfg/cfg.go
test/codegen/arithmetic.go
test/codegen/floats.go
test/codegen/math.go
test/codegen/memops.go
test/run.go

index 2d20b6a6d06967625e5a73b9c7707cf6eae7759f..e137daa3fc590c3c749723d50dff357982a66cc5 100644 (file)
@@ -7,6 +7,9 @@ package x86
 import (
        "cmd/compile/internal/gc"
        "cmd/internal/obj/x86"
+       "cmd/internal/objabi"
+       "fmt"
+       "os"
 )
 
 func Init(arch *gc.Arch) {
@@ -15,6 +18,18 @@ func Init(arch *gc.Arch) {
        arch.SSAGenValue = ssaGenValue
        arch.SSAGenBlock = ssaGenBlock
        arch.MAXWIDTH = (1 << 32) - 1
+       switch v := objabi.GO386; v {
+       case "sse2":
+       case "softfloat":
+               arch.SoftFloat = true
+       case "387":
+               fmt.Fprintf(os.Stderr, "unsupported setting GO386=387. Consider using GO386=softfloat instead.\n")
+               gc.Exit(1)
+       default:
+               fmt.Fprintf(os.Stderr, "unsupported setting GO386=%s\n", v)
+               gc.Exit(1)
+
+       }
 
        arch.ZeroRange = zerorange
        arch.Ginsnop = ginsnop
index 3b3eb113b1c04971624a77727a3a3a4dbfa9ecf8..69a66abd2d26a482e43334a404068df8d41572e2 100644 (file)
@@ -30,6 +30,7 @@ var (
        gohostos         string
        goos             string
        goarm            string
+       go386            string
        gomips           string
        gomips64         string
        goppc64          string
@@ -141,6 +142,12 @@ func xinit() {
        }
        goarm = b
 
+       b = os.Getenv("GO386")
+       if b == "" {
+               b = "sse2"
+       }
+       go386 = b
+
        b = os.Getenv("GOMIPS")
        if b == "" {
                b = "hardfloat"
@@ -212,6 +219,7 @@ func xinit() {
        defaultldso = os.Getenv("GO_LDSO")
 
        // For tools being invoked but also for os.ExpandEnv.
+       os.Setenv("GO386", go386)
        os.Setenv("GOARCH", goarch)
        os.Setenv("GOARM", goarm)
        os.Setenv("GOHOSTARCH", gohostarch)
@@ -1153,6 +1161,9 @@ func cmdenv() {
        if goarch == "arm" {
                xprintf(format, "GOARM", goarm)
        }
+       if goarch == "386" {
+               xprintf(format, "GO386", go386)
+       }
        if goarch == "mips" || goarch == "mipsle" {
                xprintf(format, "GOMIPS", gomips)
        }
index 67d1d72db464d83065debd2f2117fecb668e7d5d..27449515976b36449ecd7a92c3341d3a98fbb832 100644 (file)
@@ -41,6 +41,7 @@ func mkzversion(dir, file string) {
 //     package objabi
 //
 //     const defaultGOROOT = <goroot>
+//     const defaultGO386 = <go386>
 //     const defaultGOARM = <goarm>
 //     const defaultGOMIPS = <gomips>
 //     const defaultGOMIPS64 = <gomips64>
@@ -69,6 +70,7 @@ func mkzbootstrap(file string) {
        fmt.Fprintln(&buf)
        fmt.Fprintf(&buf, "import \"runtime\"\n")
        fmt.Fprintln(&buf)
+       fmt.Fprintf(&buf, "const defaultGO386 = `%s`\n", go386)
        fmt.Fprintf(&buf, "const defaultGOARM = `%s`\n", goarm)
        fmt.Fprintf(&buf, "const defaultGOMIPS = `%s`\n", gomips)
        fmt.Fprintf(&buf, "const defaultGOMIPS64 = `%s`\n", gomips64)
index 14840efb22c99bd94f4da04ca305fc91a8dff30f..5cb32c80e9e3b0987b996b5a7f1c5585b58071c7 100644 (file)
 //     GOARM
 //             For GOARCH=arm, the ARM architecture for which to compile.
 //             Valid values are 5, 6, 7.
+//     GO386
+//             For GOARCH=386, how to implement floating point instructions.
+//             Valid values are sse2 (default), softfloat.
 //     GOMIPS
 //             For GOARCH=mips{,le}, whether to use floating point instructions.
 //             Valid values are hardfloat (default), softfloat.
index 9169c12d8fd936b8dc695c57a6959680e390325a..67d581f6e6d75d444645368dd399238aa488f494 100644 (file)
@@ -256,6 +256,7 @@ var (
 
        // Used in envcmd.MkEnv and build ID computations.
        GOARM    = envOr("GOARM", fmt.Sprint(objabi.GOARM))
+       GO386    = envOr("GO386", objabi.GO386)
        GOMIPS   = envOr("GOMIPS", objabi.GOMIPS)
        GOMIPS64 = envOr("GOMIPS64", objabi.GOMIPS64)
        GOPPC64  = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", objabi.GOPPC64))
@@ -279,6 +280,8 @@ func GetArchEnv() (key, val string) {
        switch Goarch {
        case "arm":
                return "GOARM", GOARM
+       case "386":
+               return "GO386", GO386
        case "mips", "mipsle":
                return "GOMIPS", GOMIPS
        case "mips64", "mips64le":
index befa10a0e4c2707038124823be1a62bd9b70c36b..8dfabbaa4a0228e6feb000bfc4e731a58680372d 100644 (file)
@@ -581,6 +581,9 @@ Architecture-specific environment variables:
        GOARM
                For GOARCH=arm, the ARM architecture for which to compile.
                Valid values are 5, 6, 7.
+       GO386
+               For GOARCH=386, how to implement floating point instructions.
+               Valid values are sse2 (default), softfloat.
        GOMIPS
                For GOARCH=mips{,le}, whether to use floating point instructions.
                Valid values are hardfloat (default), softfloat.
index cedb2d0a26630d83811178ab1167bc2fa8e0bce7..b81b73a02234947d6080eb652efa84c48ac377f7 100644 (file)
@@ -24,6 +24,7 @@ var (
        GOROOT   = envOr("GOROOT", defaultGOROOT)
        GOARCH   = envOr("GOARCH", defaultGOARCH)
        GOOS     = envOr("GOOS", defaultGOOS)
+       GO386    = envOr("GO386", defaultGO386)
        GOAMD64  = goamd64()
        GOARM    = goarm()
        GOMIPS   = gomips()
@@ -135,14 +136,6 @@ func init() {
        if GOARCH != "amd64" {
                Regabi_enabled = 0
        }
-
-       if v := os.Getenv("GO386"); v != "" && v != "sse2" {
-               msg := fmt.Sprintf("unsupported setting GO386=%s", v)
-               if v == "387" {
-                       msg += ". 387 support was dropped in Go 1.16. Consider using gccgo instead."
-               }
-               log.Fatal(msg)
-       }
 }
 
 // Note: must agree with runtime.framepointer_enabled.
index 023429e4414b50a52546384f661f5431a249c075..bdbe9df3e75d13a9e4376f5471143bc6a20d6522 100644 (file)
@@ -32,6 +32,7 @@ const KnownEnv = `
        FC
        GCCGO
        GO111MODULE
+       GO386
        GOARCH
        GOARM
        GOBIN
index 30f39a8da1f9ffe22ce0ea482e995b8cd82790b2..0bdb66a376db2acd133d05a357dcd69c6e740c11 100644 (file)
@@ -125,7 +125,7 @@ func Mul_n120(n int) int {
 func MulMemSrc(a []uint32, b []float32) {
        // 386:`IMULL\s4\([A-Z]+\),\s[A-Z]+`
        a[0] *= a[1]
-       // 386:`MULSS\s4\([A-Z]+\),\sX[0-9]+`
+       // 386/sse2:`MULSS\s4\([A-Z]+\),\sX[0-9]+`
        // amd64:`MULSS\s4\([A-Z]+\),\sX[0-9]+`
        b[0] *= b[1]
 }
@@ -167,7 +167,7 @@ func MergeMuls5(a, n int) int {
 // -------------- //
 
 func DivMemSrc(a []float64) {
-       // 386:`DIVSD\s8\([A-Z]+\),\sX[0-9]+`
+       // 386/sse2:`DIVSD\s8\([A-Z]+\),\sX[0-9]+`
        // amd64:`DIVSD\s8\([A-Z]+\),\sX[0-9]+`
        a[0] /= a[1]
 }
@@ -211,7 +211,7 @@ func ConstDivs(n1 uint, n2 int) (uint, int) {
 
 func FloatDivs(a []float32) float32 {
        // amd64:`DIVSS\s8\([A-Z]+\),\sX[0-9]+`
-       // 386:`DIVSS\s8\([A-Z]+\),\sX[0-9]+`
+       // 386/sse2:`DIVSS\s8\([A-Z]+\),\sX[0-9]+`
        return a[1] / a[2]
 }
 
index d115800a67ee3aa33860dd41feb992355df38219..83b4a358a5b0610e39411072245e05a02a6ad18d 100644 (file)
@@ -15,7 +15,7 @@ package codegen
 // --------------------- //
 
 func Mul2(f float64) float64 {
-       // 386:"ADDSD",-"MULSD"
+       // 386/sse2:"ADDSD",-"MULSD"
        // amd64:"ADDSD",-"MULSD"
        // arm/7:"ADDD",-"MULD"
        // arm64:"FADDD",-"FMULD"
@@ -25,7 +25,7 @@ func Mul2(f float64) float64 {
 }
 
 func DivPow2(f1, f2, f3 float64) (float64, float64, float64) {
-       // 386:"MULSD",-"DIVSD"
+       // 386/sse2:"MULSD",-"DIVSD"
        // amd64:"MULSD",-"DIVSD"
        // arm/7:"MULD",-"DIVD"
        // arm64:"FMULD",-"FDIVD"
@@ -33,7 +33,7 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) {
        // ppc64le:"FMUL",-"FDIV"
        x := f1 / 16.0
 
-       // 386:"MULSD",-"DIVSD"
+       // 386/sse2:"MULSD",-"DIVSD"
        // amd64:"MULSD",-"DIVSD"
        // arm/7:"MULD",-"DIVD"
        // arm64:"FMULD",-"FDIVD"
@@ -41,7 +41,7 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) {
        // ppc64le:"FMUL",-"FDIVD"
        y := f2 / 0.125
 
-       // 386:"ADDSD",-"DIVSD",-"MULSD"
+       // 386/sse2:"ADDSD",-"DIVSD",-"MULSD"
        // amd64:"ADDSD",-"DIVSD",-"MULSD"
        // arm/7:"ADDD",-"MULD",-"DIVD"
        // arm64:"FADDD",-"FMULD",-"FDIVD"
index fe678eea2367960e47d99123644b2ce91188a75c..ac8071400ea103988e5dff6aa34f4883a35757b4 100644 (file)
@@ -46,7 +46,7 @@ func approx(x float64) {
 
 func sqrt(x float64) float64 {
        // amd64:"SQRTSD"
-       // 386:"SQRTSD"
+       // 386/sse2:"SQRTSD" 386/softfloat:-"SQRTD"
        // arm64:"FSQRTD"
        // arm/7:"SQRTD"
        // mips/hardfloat:"SQRTD" mips/softfloat:-"SQRTD"
index 4b003ad8610dc284dba135f8f754b75b1ce1bbe3..a2342831460281408c16b217d36c9ce85f2bafad 100644 (file)
@@ -175,33 +175,33 @@ func idxInt64(x, y []int64, i int) {
 
 func idxFloat32(x, y []float32, i int) {
        var t float32
-       // amd64: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\), X[0-9]+`
-       //   386: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\), X[0-9]+`
+       //    amd64: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\), X[0-9]+`
+       // 386/sse2: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\), X[0-9]+`
        t = x[i+1]
-       // amd64: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\)`
-       //   386: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\)`
+       //    amd64: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\)`
+       // 386/sse2: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*4\)`
        y[i+1] = t
-       // amd64: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\), X[0-9]+`
-       //   386: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\), X[0-9]+`
+       //    amd64: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\), X[0-9]+`
+       // 386/sse2: `MOVSS\t4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\), X[0-9]+`
        t = x[16*i+1]
-       // amd64: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\)`
-       //   386: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\)`
+       //    amd64: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\)`
+       // 386/sse2: `MOVSS\tX[0-9]+, 4\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[14]\)`
        y[16*i+1] = t
 }
 
 func idxFloat64(x, y []float64, i int) {
        var t float64
-       // amd64: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\), X[0-9]+`
-       //   386: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\), X[0-9]+`
+       //    amd64: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\), X[0-9]+`
+       // 386/sse2: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\), X[0-9]+`
        t = x[i+1]
-       // amd64: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\)`
-       //   386: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\)`
+       //    amd64: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\)`
+       // 386/sse2: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*8\)`
        y[i+1] = t
-       // amd64: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\), X[0-9]+`
-       //   386: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\), X[0-9]+`
+       //    amd64: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\), X[0-9]+`
+       // 386/sse2: `MOVSD\t8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\), X[0-9]+`
        t = x[16*i+1]
-       // amd64: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\)`
-       //   386: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\)`
+       //    amd64: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\)`
+       // 386/sse2: `MOVSD\tX[0-9]+, 8\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*[18]\)`
        y[16*i+1] = t
 }
 
index 77710fd89a8c82c1622ab2f0a8a9e6f00838b875..672861c8d78136364c3d8247e708c5e5a51b0288 100644 (file)
@@ -1489,7 +1489,7 @@ var (
        // value[0] is the variant-changing environment variable, and values[1:]
        // are the supported variants.
        archVariants = map[string][]string{
-               "386":     {},
+               "386":     {"GO386", "sse2", "softfloat"},
                "amd64":   {},
                "arm":     {"GOARM", "5", "6", "7"},
                "arm64":   {},
@@ -1511,12 +1511,12 @@ type wantedAsmOpcode struct {
        found    bool           // true if the opcode check matched at least one in the output
 }
 
-// A build environment triplet separated by slashes (eg: linux/arm/7).
+// A build environment triplet separated by slashes (eg: linux/386/sse2).
 // The third field can be empty if the arch does not support variants (eg: "plan9/amd64/")
 type buildEnv string
 
 // Environ returns the environment it represents in cmd.Environ() "key=val" format
-// For instance, "linux/arm/7".Environ() returns {"GOOS=linux", "GOARCH=arm", "GOARM=7"}
+// For instance, "linux/386/sse2".Environ() returns {"GOOS=linux", "GOARCH=386", "GO386=sse2"}
 func (b buildEnv) Environ() []string {
        fields := strings.Split(string(b), "/")
        if len(fields) != 3 {
@@ -1571,11 +1571,11 @@ func (t *test) wantedAsmOpcodes(fn string) asmChecks {
 
                        var arch, subarch, os string
                        switch {
-                       case archspec[2] != "": // 3 components: "linux/arm/7"
+                       case archspec[2] != "": // 3 components: "linux/386/sse2"
                                os, arch, subarch = archspec[0], archspec[1][1:], archspec[2][1:]
-                       case archspec[1] != "": // 2 components: "arm/7"
+                       case archspec[1] != "": // 2 components: "386/sse2"
                                os, arch, subarch = "linux", archspec[0], archspec[1][1:]
-                       default: // 1 component: "arm"
+                       default: // 1 component: "386"
                                os, arch, subarch = "linux", archspec[0], ""
                                if arch == "wasm" {
                                        os = "js"