Skip to content

Commit f3bc401

Browse files
committed
[release-branch.go1.24] 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 Change-Id: Ib2e4790197cab4a2df531d15545679e47c8c9084
1 parent 431f75a commit f3bc401

File tree

13 files changed

+234
-90
lines changed

13 files changed

+234
-90
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"
@@ -1739,16 +1740,32 @@ func gccMachine() []string {
17391740
case "s390x":
17401741
return []string{"-m64"}
17411742
case "mips64", "mips64le":
1742-
if gomips64 == "hardfloat" {
1743-
return []string{"-mabi=64", "-mhard-float"}
1744-
} else if gomips64 == "softfloat" {
1745-
return []string{"-mabi=64", "-msoft-float"}
1743+
args := []string{"-mabi=64"}
1744+
if buildcfg.GOMIPS64.Float == "hardfloat" {
1745+
if buildcfg.GOMIPS64.ISALevel == 5 {
1746+
args = append(args, "-mnan=2008", "-mabs=2008") // Since R5, MIPS support IEEE-754 2008
1747+
}
1748+
return append(args, "-mhard-float")
1749+
} else if buildcfg.GOMIPS64.Float == "softfloat" {
1750+
return append(args, "-msoft-float")
17461751
}
17471752
case "mips", "mipsle":
1748-
if gomips == "hardfloat" {
1749-
return []string{"-mabi=32", "-mfp32", "-mhard-float", "-mno-odd-spreg"}
1750-
} else if gomips == "softfloat" {
1751-
return []string{"-mabi=32", "-msoft-float"}
1753+
args := []string{"-mabi=32"}
1754+
if buildcfg.GOMIPS.Float == "hardfloat" {
1755+
args = append(args, "-mhard-float")
1756+
switch buildcfg.GOMIPS.ISALevel {
1757+
case 1:
1758+
args = append(args, "-mfp32", "-mno-odd-spreg")
1759+
case 2:
1760+
args = append(args, "-mfp64")
1761+
case 5:
1762+
args = append(args, "-mfp64", "-mnan=2008", "-mabs=2008") // Since R5, MIPS support IEEE-754 2008
1763+
default:
1764+
fatalf("unsupported MIPS ISA level in Elfinit: %d", buildcfg.GOMIPS.ISALevel)
1765+
}
1766+
return args
1767+
} else if buildcfg.GOMIPS.Float == "softfloat" {
1768+
return append(args, "-msoft-float")
17521769
}
17531770
case "loong64":
17541771
return []string{"-mabi=lp64d"}

src/cmd/cgo/main.go

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

284-
var goarch, goos, gomips, gomips64 string
284+
var goarch, goos string
285285
var gccBaseCmd []string
286286

287287
func main() {
@@ -518,8 +518,6 @@ func newPackage(args []string) *Package {
518518
goos = s
519519
}
520520
buildcfg.Check()
521-
gomips = buildcfg.GOMIPS
522-
gomips64 = buildcfg.GOMIPS64
523521
ptrSize := ptrSizeMap[goarch]
524522
if ptrSize == 0 {
525523
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/compile/internal/ssagen/intrinsics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type intrinsicBuildConfig struct {
3636
goamd64 int
3737
goarm buildcfg.GoarmFeatures
3838
goarm64 buildcfg.Goarm64Features
39-
gomips string
40-
gomips64 string
39+
gomips buildcfg.GomipsFeatures
40+
gomips64 buildcfg.GomipsFeatures
4141
goppc64 int
4242
goriscv64 int
4343
}

src/cmd/dist/build.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func xinit() {
168168
}
169169
gomips = b
170170

171+
// TODO: Add default ISA level after minimum Go bootstrap version includes CL 508095 (see #60072)
171172
b = os.Getenv("GOMIPS64")
172173
if b == "" {
173174
b = "hardfloat"
@@ -922,11 +923,15 @@ func runInstall(pkg string, ch chan struct{}) {
922923
}
923924
if goarch == "mips" || goarch == "mipsle" {
924925
// Define GOMIPS_value from gomips.
925-
asmArgs = append(asmArgs, "-D", "GOMIPS_"+gomips)
926+
for _, opt := range strings.Split(gomips, ",") {
927+
asmArgs = append(asmArgs, "-D", "GOMIPS_"+opt)
928+
}
926929
}
927930
if goarch == "mips64" || goarch == "mips64le" {
928931
// Define GOMIPS64_value from gomips64.
929-
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64)
932+
for _, opt := range strings.Split(gomips64, ",") {
933+
asmArgs = append(asmArgs, "-D", "GOMIPS64_"+opt)
934+
}
930935
}
931936
if goarch == "ppc64" || goarch == "ppc64le" {
932937
// 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/help/helpdoc.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,17 @@ Architecture-specific environment variables:
636636
Note that some extensions are enabled by default starting from a certain GOARM64 version;
637637
for example, lse is enabled by default starting from v8.1.
638638
GOMIPS
639-
For GOARCH=mips{,le}, whether to use floating point instructions.
640-
Valid values are hardfloat (default), softfloat.
639+
For GOARCH=mips{,le}, whether to use floating point instructions and different ISA level.
640+
Valid values are hardfloat (default), softfloat, r1 (default), r2, r5.
641+
These can be combined (as a comma separated list) with hardfloat or softfloat,
642+
whether to use floating point instructions.
643+
Default value is 'r1,hardfloat', use MIPS R1 as the target ISA with hardfloat.
641644
GOMIPS64
642-
For GOARCH=mips64{,le}, whether to use floating point instructions.
643-
Valid values are hardfloat (default), softfloat.
645+
For GOARCH=mips64{,le}, whether to use floating point instructions and different ISA level.
646+
Valid values are hardfloat (default), softfloat, iii (default), r1, r2, r5.
647+
These can be combined (as a comma separated list) with hardfloat or softfloat,
648+
whether to use floating point instructions.
649+
Default value is 'iii,hardfloat', use MIPS III as the target ISA with hardfloat.
644650
GOPPC64
645651
For GOARCH=ppc64{,le}, the target ISA (Instruction Set Architecture).
646652
Valid values are power8 (default), power9, power10.
@@ -939,12 +945,19 @@ The defined architecture feature build tags are:
939945
- For GOARCH=arm64, GOARM64=v8.{0-9} and v9.{0-5}
940946
correspond to the arm64.v8.{0-9} and arm64.v9.{0-5} feature build tags.
941947
- For GOARCH=mips or mipsle,
942-
GOMIPS=hardfloat and softfloat
943-
correspond to the mips.hardfloat and mips.softfloat
948+
GOMIPS=r1, r2 and r5
949+
correspond to the mips.r1, mips.r2 and mips.r5
950+
(or mipsle.r1, mipsle.r2 and mipsle.r5) feature build tags.
951+
These can be combined (as a comma separated list) with GOMIPS=hardfloat or softfloat,
952+
which correspond to the mips.hardfloat and mips.softfloat
944953
(or mipsle.hardfloat and mipsle.softfloat) feature build tags.
945954
- For GOARCH=mips64 or mips64le,
946-
GOMIPS64=hardfloat and softfloat
947-
correspond to the mips64.hardfloat and mips64.softfloat
955+
GOMIPS64=iii, r1, r2 and r5
956+
correspond to the mips64.iii, mips64.r1, mips64.r2 and mips64.r5
957+
(or mips64le.iii, mips64le.r1, mips64le.r2 and mips64le.r5)
958+
feature build tags.
959+
These can be combined (as a comma separated list) with GOMIPS64=hardfloat or softfloat,
960+
which correspond to the mips64.hardfloat and mips64.softfloat
948961
(or mips64le.hardfloat and mips64le.softfloat) feature build tags.
949962
- For GOARCH=ppc64 or ppc64le,
950963
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
@@ -16,6 +16,7 @@ import (
1616
"errors"
1717
"fmt"
1818
"go/token"
19+
"internal/buildcfg"
1920
"internal/lazyregexp"
2021
"io"
2122
"io/fs"
@@ -2619,15 +2620,28 @@ func (b *Builder) gccArchArgs() []string {
26192620
return []string{"-m64", "-march=z196"}
26202621
case "mips64", "mips64le":
26212622
args := []string{"-mabi=64"}
2622-
if cfg.GOMIPS64 == "hardfloat" {
2623-
return append(args, "-mhard-float")
2623+
if buildcfg.GOMIPS64.Float == "hardfloat" {
2624+
args = append(args, "-mhard-float")
2625+
if buildcfg.GOMIPS64.ISALevel == 5 {
2626+
args = append(args, "-mnan=2008", "-mabs=2008")
2627+
}
2628+
return args
26242629
} else if cfg.GOMIPS64 == "softfloat" {
26252630
return append(args, "-msoft-float")
26262631
}
26272632
case "mips", "mipsle":
2628-
args := []string{"-mabi=32", "-march=mips32"}
2629-
if cfg.GOMIPS == "hardfloat" {
2630-
return append(args, "-mhard-float", "-mfp32", "-mno-odd-spreg")
2633+
args := []string{"-mabi=32"}
2634+
if buildcfg.GOMIPS.Float == "hardfloat" {
2635+
args = append(args, "-mhard-float")
2636+
switch buildcfg.GOMIPS.ISALevel {
2637+
case 1:
2638+
args = append(args, "-mfp32", "-mno-odd-spreg")
2639+
case 2:
2640+
args = append(args, "-mfp64")
2641+
case 5:
2642+
args = append(args, "-mfp64", "-mnan=2008", "-mabs=2008")
2643+
}
2644+
return args
26312645
} else if cfg.GOMIPS == "softfloat" {
26322646
return append(args, "-msoft-float")
26332647
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ func asmArgs(a *Action, p *load.Package) []any {
335335

336336
if cfg.Goarch == "mips" || cfg.Goarch == "mipsle" {
337337
// Define GOMIPS_value from cfg.GOMIPS.
338-
args = append(args, "-D", "GOMIPS_"+cfg.GOMIPS)
338+
args = append(args, "-D", "GOMIPS_"+buildcfg.GOMIPS.Float)
339+
args = append(args, "-D", "GOMIPS_"+buildcfg.MipsIsaRevMap[buildcfg.GOMIPS.ISALevel])
339340
}
340341

341342
if cfg.Goarch == "mips64" || cfg.Goarch == "mips64le" {
342343
// Define GOMIPS64_value from cfg.GOMIPS64.
343-
args = append(args, "-D", "GOMIPS64_"+cfg.GOMIPS64)
344+
args = append(args, "-D", "GOMIPS64_"+buildcfg.GOMIPS64.Float)
345+
args = append(args, "-D", "GOMIPS64_"+buildcfg.MipsIsaRevMap[buildcfg.GOMIPS64.ISALevel])
344346
}
345347

346348
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)