Skip to content

Commit ca7c849

Browse files
aykevldeadprogram
authored andcommitted
386: bump minimum requirement to the Pentium 4
Previously we used the i386 target, probably with all optional features disabled. However, the Pentium 4 has been released a _long_ time ago and it seems reasonable to me to take that as a minimum requirement. Upstream Go now also seems to move in this direction: golang/go#40255 The main motivation for this is that there were floating point issues when running the tests for the math package: GOARCH=386 tinygo test math I haven't investigated what's the issue, but I strongly suspect it's caused by the weird x87 80-bit floating point format. This could perhaps be fixed in a different way (by setting the FPU precision to 64 bits) but I figured that just setting the minimum requirement to the Pentium 4 would probably be fine. If needed, we can respect the GO386 environment variable to support these very old CPUs. To support this newer CPU, I had to make sure that the stack is aligned to 16 bytes everywhere. This was not yet always the case.
1 parent 6c13016 commit ca7c849

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

compileopts/target.go

+3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
253253
GDB: []string{"gdb"},
254254
PortReset: "false",
255255
}
256+
if goarch == "386" {
257+
spec.CPU = "pentium4"
258+
}
256259
if goos == "darwin" {
257260
spec.CFlags = append(spec.CFlags, "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
258261
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")

src/internal/task/task_stack_386.go

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type calleeSavedRegs struct {
1616
ebp uintptr
1717

1818
pc uintptr
19+
20+
// Pad this struct so that tasks start on a 16-byte aligned stack.
21+
_ [3]uintptr
1922
}
2023

2124
// archInit runs architecture-specific setup for the goroutine startup.

src/runtime/arch_386.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TargetBits = 32
99

1010
// Align on word boundary.
1111
func align(ptr uintptr) uintptr {
12-
return (ptr + 3) &^ 3
12+
return (ptr + 15) &^ 15
1313
}
1414

1515
func getCurrentStackPointer() uintptr {

src/runtime/gc_386.S

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ tinygo_scanCurrentStack:
1313
pushl %ebp
1414

1515
// Scan the stack.
16+
subl $8, %esp // adjust the stack before the call to maintain 16-byte alignment
1617
pushl %esp
1718
calll tinygo_scanstack
1819

1920
// Restore the stack pointer. Registers do not need to be restored as they
2021
// were only pushed to be discoverable by the GC.
21-
addl $20, %esp
22+
addl $28, %esp
2223
retl

src/runtime/math.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func math_sinh(x float64) float64
217217

218218
//go:linkname math_Sqrt math.Sqrt
219219
func math_Sqrt(x float64) float64 {
220-
if GOARCH == "x86" || GOARCH == "amd64" || GOARCH == "wasm" {
220+
if GOARCH == "386" || GOARCH == "amd64" || GOARCH == "wasm" {
221221
return llvm_sqrt(x)
222222
}
223223
return math_sqrt(x)

0 commit comments

Comments
 (0)