Skip to content

Commit 20aea21

Browse files
committed
cmd/go: add GOMIPS32, GOMIPS64 ISA levels
This CL does not introduced any instruction after MIPS III at now. It should still behave identically to MIPS III. Updates golang#60072
1 parent 185457d commit 20aea21

File tree

13 files changed

+224
-89
lines changed

13 files changed

+224
-89
lines changed

src/cmd/cgo/gcc.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go/ast"
2121
"go/parser"
2222
"go/token"
23+
"internal/buildcfg"
2324
"internal/xcoff"
2425
"math"
2526
"os"
@@ -1744,16 +1745,32 @@ func (p *Package) gccMachine() []string {
17441745
case "s390x":
17451746
return []string{"-m64"}
17461747
case "mips64", "mips64le":
1747-
if gomips64 == "hardfloat" {
1748-
return []string{"-mabi=64", "-mhard-float"}
1749-
} else if gomips64 == "softfloat" {
1750-
return []string{"-mabi=64", "-msoft-float"}
1748+
args := []string{"-mabi=64"}
1749+
if buildcfg.GOMIPS64.Float == "hardfloat" {
1750+
if buildcfg.GOMIPS64.ISALevel == 5 {
1751+
args = append(args, "-mnan=2008", "-mabs=2008") // Since R5, MIPS support IEEE-754 2008
1752+
}
1753+
return append(args, "-mhard-float")
1754+
} else if buildcfg.GOMIPS64.Float == "softfloat" {
1755+
return append(args, "-msoft-float")
17511756
}
17521757
case "mips", "mipsle":
1753-
if gomips == "hardfloat" {
1754-
return []string{"-mabi=32", "-mfp32", "-mhard-float", "-mno-odd-spreg"}
1755-
} else if gomips == "softfloat" {
1756-
return []string{"-mabi=32", "-msoft-float"}
1758+
args := []string{"-mabi=32"}
1759+
if buildcfg.GOMIPS.Float == "hardfloat" {
1760+
args = append(args, "-mhard-float")
1761+
switch buildcfg.GOMIPS.ISALevel {
1762+
case 1:
1763+
args = append(args, "-mfp32", "-mno-odd-spreg")
1764+
case 2:
1765+
args = append(args, "-mfp64")
1766+
case 5:
1767+
args = append(args, "-mfp64", "-mnan=2008", "-mabs=2008") // Since R5, MIPS support IEEE-754 2008
1768+
default:
1769+
fatalf("unsupported MIPS ISA level in Elfinit: %d", buildcfg.GOMIPS.ISALevel)
1770+
}
1771+
return args
1772+
} else if buildcfg.GOMIPS.Float == "softfloat" {
1773+
return append(args, "-msoft-float")
17571774
}
17581775
case "loong64":
17591776
return []string{"-mabi=lp64d"}

src/cmd/cgo/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ var importRuntimeCgo = flag.Bool("import_runtime_cgo", true, "import runtime/cgo
251251
var importSyscall = flag.Bool("import_syscall", true, "import syscall in generated code")
252252
var trimpath = flag.String("trimpath", "", "applies supplied rewrites or trims prefixes to recorded source file paths")
253253

254-
var goarch, goos, gomips, gomips64 string
254+
var goarch, goos string
255255
var gccBaseCmd []string
256256

257257
func main() {
@@ -457,8 +457,6 @@ func newPackage(args []string) *Package {
457457
goos = s
458458
}
459459
buildcfg.Check()
460-
gomips = buildcfg.GOMIPS
461-
gomips64 = buildcfg.GOMIPS64
462460
ptrSize := ptrSizeMap[goarch]
463461
if ptrSize == 0 {
464462
fatalf("unknown ptrSize for $GOARCH %q", goarch)

src/cmd/compile/internal/mips/galign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Init(arch *ssagen.ArchInfo) {
1818
}
1919
arch.REGSP = mips.REGSP
2020
arch.MAXWIDTH = (1 << 31) - 1
21-
arch.SoftFloat = (buildcfg.GOMIPS == "softfloat")
21+
arch.SoftFloat = (buildcfg.GOMIPS.Float == "softfloat")
2222
arch.ZeroRange = zerorange
2323
arch.Ginsnop = ginsnop
2424
arch.SSAMarkMoves = func(s *ssagen.State, b *ssa.Block) {}

src/cmd/compile/internal/mips64/galign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Init(arch *ssagen.ArchInfo) {
1818
}
1919
arch.REGSP = mips.REGSP
2020
arch.MAXWIDTH = 1 << 50
21-
arch.SoftFloat = buildcfg.GOMIPS64 == "softfloat"
21+
arch.SoftFloat = (buildcfg.GOMIPS64.Float == "softfloat")
2222
arch.ZeroRange = zerorange
2323
arch.Ginsnop = ginsnop
2424

src/cmd/dist/build.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func xinit() {
165165
}
166166
gomips = b
167167

168+
// TODO: Add default ISA level after minimum Go bootstrap version includes CL 508095 (see #60072)
168169
b = os.Getenv("GOMIPS64")
169170
if b == "" {
170171
b = "hardfloat"
@@ -872,11 +873,15 @@ func runInstall(pkg string, ch chan struct{}) {
872873
}
873874
if goarch == "mips" || goarch == "mipsle" {
874875
// Define GOMIPS_value from gomips.
875-
asmArgs = append(asmArgs, "-D", "GOMIPS_"+gomips)
876+
for _, opt := range strings.Split(gomips, ",") {
877+
asmArgs = append(asmArgs, "-D", "GOMIPS_"+opt)
878+
}
876879
}
877880
if goarch == "mips64" || goarch == "mips64le" {
878881
// Define GOMIPS64_value from gomips64.
879-
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64)
882+
for _, opt := range strings.Split(gomips64, ",") {
883+
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+opt)
884+
}
880885
}
881886
if goarch == "ppc64" || goarch == "ppc64le" {
882887
// We treat each powerpc version as a superset of functionality.

src/cmd/go/alldocs.go

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/cfg/cfg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ var (
411411
GOARM = envOr("GOARM", fmt.Sprint(buildcfg.GOARM))
412412
GO386 = envOr("GO386", buildcfg.GO386)
413413
GOAMD64 = envOr("GOAMD64", fmt.Sprintf("%s%d", "v", buildcfg.GOAMD64))
414-
GOMIPS = envOr("GOMIPS", buildcfg.GOMIPS)
415-
GOMIPS64 = envOr("GOMIPS64", buildcfg.GOMIPS64)
414+
GOMIPS = envOr("GOMIPS", fmt.Sprint(buildcfg.GOMIPS))
415+
GOMIPS64 = envOr("GOMIPS64", fmt.Sprint(buildcfg.GOMIPS64))
416416
GOPPC64 = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", buildcfg.GOPPC64))
417417
GOWASM = envOr("GOWASM", fmt.Sprint(buildcfg.GOWASM))
418418

src/cmd/go/internal/help/helpdoc.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,17 @@ Architecture-specific environment variables:
611611
Valid values are v1 (default), v2, v3, v4.
612612
See https://golang.org/wiki/MinimumRequirements#amd64
613613
GOMIPS
614-
For GOARCH=mips{,le}, whether to use floating point instructions.
615-
Valid values are hardfloat (default), softfloat.
614+
For GOARCH=mips{,le}, whether to use floating point instructions and different ISA level.
615+
Valid values are hardfloat (default), softfloat, r1 (default), r2, r5.
616+
These can be combined (as a comma separated list) with hardfloat or softfloat,
617+
whether to use floating point instructions.
618+
Default value is 'r1,hardfloat', use MIPS R1 as the target ISA with hardfloat.
616619
GOMIPS64
617-
For GOARCH=mips64{,le}, whether to use floating point instructions.
618-
Valid values are hardfloat (default), softfloat.
620+
For GOARCH=mips64{,le}, whether to use floating point instructions and different ISA level.
621+
Valid values are hardfloat (default), softfloat, iii (default), r1, r2, r5.
622+
These can be combined (as a comma separated list) with hardfloat or softfloat,
623+
whether to use floating point instructions.
624+
Default value is 'iii,hardfloat', use MIPS III as the target ISA with hardfloat.
619625
GOPPC64
620626
For GOARCH=ppc64{,le}, the target ISA (Instruction Set Architecture).
621627
Valid values are power8 (default), power9, power10.
@@ -895,12 +901,19 @@ The defined architecture feature build tags are:
895901
- For GOARCH=arm, GOARM=5, 6, and 7
896902
correspond to the arm.5, arm.6, and arm.7 feature build tags.
897903
- For GOARCH=mips or mipsle,
898-
GOMIPS=hardfloat and softfloat
899-
correspond to the mips.hardfloat and mips.softfloat
904+
GOMIPS=r1, r2 and r5
905+
correspond to the mips.r1, mips.r2 and mips.r5
906+
(or mipsle.r1, mipsle.r2 and mipsle.r5) feature build tags.
907+
These can be combined (as a comma separated list) with GOMIPS=hardfloat or softfloat,
908+
which correspond to the mips.hardfloat and mips.softfloat
900909
(or mipsle.hardfloat and mipsle.softfloat) feature build tags.
901910
- For GOARCH=mips64 or mips64le,
902-
GOMIPS64=hardfloat and softfloat
903-
correspond to the mips64.hardfloat and mips64.softfloat
911+
GOMIPS64=iii, r1, r2 and r5
912+
correspond to the mips64.iii, mips64.r1, mips64.r2 and mips64.r5
913+
(or mips64le.iii, mips64le.r1, mips64le.r2 and mips64le.r5)
914+
feature build tags.
915+
These can be combined (as a comma separated list) with GOMIPS64=hardfloat or softfloat,
916+
which correspond to the mips64.hardfloat and mips64.softfloat
904917
(or mips64le.hardfloat and mips64le.softfloat) feature build tags.
905918
- For GOARCH=ppc64 or ppc64le,
906919
GOPPC64=power8, power9, and power10 correspond to the

src/cmd/go/internal/work/exec.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"errors"
1616
"fmt"
1717
"go/token"
18+
"internal/buildcfg"
1819
"internal/lazyregexp"
1920
"io"
2021
"io/fs"
@@ -2639,15 +2640,28 @@ func (b *Builder) gccArchArgs() []string {
26392640
return []string{"-m64", "-march=z196"}
26402641
case "mips64", "mips64le":
26412642
args := []string{"-mabi=64"}
2642-
if cfg.GOMIPS64 == "hardfloat" {
2643-
return append(args, "-mhard-float")
2643+
if buildcfg.GOMIPS64.Float == "hardfloat" {
2644+
args = append(args, "-mhard-float")
2645+
if buildcfg.GOMIPS64.ISALevel == 5 {
2646+
args = append(args, "-mnan=2008", "-mabs=2008")
2647+
}
2648+
return args
26442649
} else if cfg.GOMIPS64 == "softfloat" {
26452650
return append(args, "-msoft-float")
26462651
}
26472652
case "mips", "mipsle":
2648-
args := []string{"-mabi=32", "-march=mips32"}
2649-
if cfg.GOMIPS == "hardfloat" {
2650-
return append(args, "-mhard-float", "-mfp32", "-mno-odd-spreg")
2653+
args := []string{"-mabi=32"}
2654+
if buildcfg.GOMIPS.Float == "hardfloat" {
2655+
args = append(args, "-mhard-float")
2656+
switch buildcfg.GOMIPS.ISALevel {
2657+
case 1:
2658+
args = append(args, "-mfp32", "-mno-odd-spreg")
2659+
case 2:
2660+
args = append(args, "-mfp64")
2661+
case 5:
2662+
args = append(args, "-mfp64", "-mnan=2008", "-mabs=2008")
2663+
}
2664+
return args
26512665
} else if cfg.GOMIPS == "softfloat" {
26522666
return append(args, "-msoft-float")
26532667
}

src/cmd/go/internal/work/gc.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"bytes"
1010
"fmt"
11+
"internal/buildcfg"
1112
"internal/platform"
1213
"io"
1314
"log"
@@ -338,12 +339,14 @@ func asmArgs(a *Action, p *load.Package) []any {
338339

339340
if cfg.Goarch == "mips" || cfg.Goarch == "mipsle" {
340341
// Define GOMIPS_value from cfg.GOMIPS.
341-
args = append(args, "-D", "GOMIPS_"+cfg.GOMIPS)
342+
args = append(args, "-D", "GOMIPS_"+buildcfg.GOMIPS.Float)
343+
args = append(args, "-D", "GOMIPS_"+buildcfg.MipsIsaRevMap[buildcfg.GOMIPS.ISALevel])
342344
}
343345

344346
if cfg.Goarch == "mips64" || cfg.Goarch == "mips64le" {
345347
// Define GOMIPS64_value from cfg.GOMIPS64.
346-
args = append(args, "-D", "GOMIPS64_"+cfg.GOMIPS64)
348+
args = append(args, "-D", "GOMIPS64_"+buildcfg.GOMIPS64.Float)
349+
args = append(args, "-D", "GOMIPS64_"+buildcfg.MipsIsaRevMap[buildcfg.GOMIPS64.ISALevel])
347350
}
348351

349352
if cfg.Goarch == "ppc64" || cfg.Goarch == "ppc64le" {

src/cmd/go/testdata/script/env_cross_build.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ go build internal/abi
1313
env GOENV=ios-arm64
1414
go build internal/abi
1515

16-
env GOENV=linux-mips
16+
env GOENV=linux-mips64
1717
go build internal/abi
1818

1919
-- windows-amd64 --
@@ -24,6 +24,6 @@ GOARCH=amd64
2424
GOOS=ios
2525
GOARCH=arm64
2626

27-
-- linux-mips --
27+
-- linux-mips64 --
2828
GOOS=linux
29-
GOARCH=mips
29+
GOARCH=mips64

0 commit comments

Comments
 (0)