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:
https://github.com/golang/go/issues/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.
This commit is contained in:
Ayke van Laethem
2021-08-06 01:37:41 +02:00
committed by Ron Evans
parent 6c1301688b
commit ca7c849da3
5 changed files with 10 additions and 3 deletions
+3
View File
@@ -16,6 +16,9 @@ type calleeSavedRegs struct {
ebp uintptr
pc uintptr
// Pad this struct so that tasks start on a 16-byte aligned stack.
_ [3]uintptr
}
// archInit runs architecture-specific setup for the goroutine startup.
+1 -1
View File
@@ -9,7 +9,7 @@ const TargetBits = 32
// Align on word boundary.
func align(ptr uintptr) uintptr {
return (ptr + 3) &^ 3
return (ptr + 15) &^ 15
}
func getCurrentStackPointer() uintptr {
+2 -1
View File
@@ -13,10 +13,11 @@ tinygo_scanCurrentStack:
pushl %ebp
// Scan the stack.
subl $8, %esp // adjust the stack before the call to maintain 16-byte alignment
pushl %esp
calll tinygo_scanstack
// Restore the stack pointer. Registers do not need to be restored as they
// were only pushed to be discoverable by the GC.
addl $20, %esp
addl $28, %esp
retl
+1 -1
View File
@@ -217,7 +217,7 @@ func math_sinh(x float64) float64
//go:linkname math_Sqrt math.Sqrt
func math_Sqrt(x float64) float64 {
if GOARCH == "x86" || GOARCH == "amd64" || GOARCH == "wasm" {
if GOARCH == "386" || GOARCH == "amd64" || GOARCH == "wasm" {
return llvm_sqrt(x)
}
return math_sqrt(x)