]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: on 386, fix FP control word on all threads, not just initial thread
authorRuss Cox <rsc@golang.org>
Tue, 14 Feb 2012 06:23:15 +0000 (01:23 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 14 Feb 2012 06:23:15 +0000 (01:23 -0500)
It is possible that Linux and Windows copy the FP control word
from the parent thread when creating a new thread.  Empirically,
Darwin does not.  Reset the FP control world in all cases.

Enable the floating-point strconv test.

Fixes #2917 (again).

R=golang-dev, r, iant
CC=golang-dev
https://golang.org/cl/5660047

src/pkg/runtime/asm_386.s
src/pkg/runtime/asm_amd64.s
src/pkg/runtime/asm_arm.s
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.h
src/pkg/strconv/atof_test.go

index a4f94601dc3e645bfd28908fa572edfd3136ebd6..6bbec30638bd6bfd47ce34077787d186fc2f839c 100644 (file)
@@ -5,14 +5,6 @@
 #include "zasm_GOOS_GOARCH.h"
 
 TEXT _rt0_386(SB),7,$0
-       // Linux, Windows start the FPU in extended double precision.
-       // Other operating systems use double precision.
-       // Change to double precision to match them,
-       // and to match other hardware that only has double.
-       PUSHL $0x27F
-       FLDCW   0(SP)
-       POPL AX
-
        // copy arguments forward on an even stack
        MOVL    0(SP), AX               // argc
        LEAL    4(SP), BX               // argv
@@ -99,6 +91,16 @@ TEXT runtime·breakpoint(SB),7,$0
        INT $3
        RET
 
+TEXT runtime·asminit(SB),7,$0
+       // Linux, Windows start the FPU in extended double precision.
+       // Other operating systems use double precision.
+       // Change to double precision to match them,
+       // and to match other hardware that only has double.
+       PUSHL $0x27F
+       FLDCW   0(SP)
+       POPL AX
+       RET
+
 /*
  *  go-routine
  */
index 9a660b5b739fa5f24feff5c9c7635fc821628d23..2ea87a779f40d814c6770e7705f732465ab31eea 100644 (file)
@@ -80,6 +80,10 @@ TEXT runtime·breakpoint(SB),7,$0
        BYTE    $0xcc
        RET
 
+TEXT runtime·asminit(SB),7,$0
+       // No per-thread init.
+       RET
+
 /*
  *  go-routine
  */
index 58b18626fe729b30e915a7a3d802553f41ecb1d0..3d9a7a73ee5f0ccec5bf1b9bebbb1fb655d900bb 100644 (file)
@@ -74,6 +74,10 @@ TEXT runtime·breakpoint(SB),7,$0
        // no breakpoint yet; let program exit
        RET
 
+TEXT runtime·asminit(SB),7,$0
+       // No per-thread init.
+       RET
+
 /*
  *  go-routine
  */
index e008be9677549f5b68c2170c5c1101cb94775136..9a4d205901110d533652ef772abcdf61a9d84648 100644 (file)
@@ -720,6 +720,7 @@ runtime·mstart(void)
        runtime·gosave(&m->g0->sched);
        m->g0->sched.pc = (void*)-1;  // make sure it is never used
 
+       runtime·asminit();
        runtime·minit();
        schedule(nil);
 }
index d39b4bd6930287d8bbf7d65ed11fcd8f3029c427..48f6b3e34b1088e791d9489235e75ac7aa8298d1 100644 (file)
@@ -525,6 +525,7 @@ int32       runtime·atoi(byte*);
 void   runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void));
 void   runtime·signalstack(byte*, int32);
 G*     runtime·malg(int32);
+void   runtime·asminit(void);
 void   runtime·minit(void);
 Func*  runtime·findfunc(uintptr);
 int32  runtime·funcline(Func*, uintptr);
index 04bf336f45c2ab4a8100071f2ba1a8698be29694..59950238230c4e288fa9bf5f82414c1c1d5c48e3 100644 (file)
@@ -8,7 +8,6 @@ import (
        "math"
        "math/rand"
        "reflect"
-       "runtime"
        . "strconv"
        "strings"
        "testing"
@@ -232,16 +231,16 @@ var roundTripCases = []struct {
        s string
 }{
        // Issue 2917.
-       // A Darwin/386 builder failed on AtofRandom with this case.
+       // This test will break the optimized conversion if the
+       // FPU is using 80-bit registers instead of 64-bit registers,
+       // usually because the operating system initialized the
+       // thread with 80-bit precision and the Go runtime didn't
+       // fix the FP control word.
        {8865794286000691 << 39, "4.87402195346389e+27"},
        {8865794286000692 << 39, "4.8740219534638903e+27"},
 }
 
 func TestRoundTrip(t *testing.T) {
-       if runtime.GOOS == "darwin" && runtime.GOARCH == "386" {
-               t.Logf("skipping round-trip test on darwin/386 - known failure, issue 2917")
-               return
-       }
        for _, tt := range roundTripCases {
                old := SetOptimize(false)
                s := FormatFloat(tt.f, 'g', -1, 64)