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.
Этот коммит содержится в:
Ayke van Laethem 2021-08-06 01:37:41 +02:00 коммит произвёл Ron Evans
родитель 6c1301688b
коммит ca7c849da3
5 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -253,6 +253,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
GDB: []string{"gdb"},
PortReset: "false",
}
if goarch == "386" {
spec.CPU = "pentium4"
}
if goos == "darwin" {
spec.CFlags = append(spec.CFlags, "-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")

Просмотреть файл

@ -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.

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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

Просмотреть файл

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