diff options
| author | David Chase <drchase@google.com> | 2025-10-14 12:13:14 -0700 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2025-10-14 12:46:22 -0700 |
| commit | 6d5b13793f51c77e7ea730ca140d5c1cb583af92 (patch) | |
| tree | d9358db73da9aa1588e65772cd5fd7d75c6ee3d4 /src/runtime | |
| parent | bb2a14252b989f89665d17b66417eff815200e3b (diff) | |
| download | go-6d5b13793f51c77e7ea730ca140d5c1cb583af92.tar.xz | |
Revert "cmd/compile: make 386 float-to-int conversions match amd64"
This reverts commit 78d75b37992be01326b9bd2666195aaba9bf2ae2.
Reason for revert: we need to do this more carefully, at minimum gated by a module version
(This should follow the softfloat FP conversion revert)
Change-Id: I736bec6cd860285dcc3b11fac85b377a149435c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/711842
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/asm_386.s | 10 | ||||
| -rw-r--r-- | src/runtime/stubs_386.go | 1 | ||||
| -rw-r--r-- | src/runtime/vlrt.go | 63 |
3 files changed, 15 insertions, 59 deletions
diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index 2a6de64f9f..df32e90fda 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -1407,6 +1407,16 @@ TEXT runtime·uint32tofloat64(SB),NOSPLIT,$8-12 FMOVDP F0, ret+4(FP) RET +TEXT runtime·float64touint32(SB),NOSPLIT,$12-12 + FMOVD a+0(FP), F0 + FSTCW 0(SP) + FLDCW runtime·controlWord64trunc(SB) + FMOVVP F0, 4(SP) + FLDCW 0(SP) + MOVL 4(SP), AX + MOVL AX, ret+8(FP) + RET + // gcWriteBarrier informs the GC about heap pointer writes. // // gcWriteBarrier returns space in a write barrier buffer which diff --git a/src/runtime/stubs_386.go b/src/runtime/stubs_386.go index 4f3dcd4fd9..a1dd023974 100644 --- a/src/runtime/stubs_386.go +++ b/src/runtime/stubs_386.go @@ -6,6 +6,7 @@ package runtime import "unsafe" +func float64touint32(a float64) uint32 func uint32tofloat64(a uint32) float64 // stackcheck checks that SP is in range [g->stack.lo, g->stack.hi). diff --git a/src/runtime/vlrt.go b/src/runtime/vlrt.go index 511eb0dd4e..4b12f593c8 100644 --- a/src/runtime/vlrt.go +++ b/src/runtime/vlrt.go @@ -40,17 +40,10 @@ func float64toint64(d float64) (y uint64) { } func float64touint64(d float64) (y uint64) { - _d2vu(&y, d) + _d2v(&y, d) return } -func float64touint32(a float64) uint32 { - if a >= 0xffffffff { - return 0xffffffff - } - return uint32(float64touint64(a)) -} - func int64tofloat64(y int64) float64 { if y < 0 { return -uint64tofloat64(-uint64(y)) @@ -124,16 +117,12 @@ func _d2v(y *uint64, d float64) { } else { /* v = (hi||lo) << -sh */ sh := uint32(-sh) - if sh <= 10 { + if sh <= 11 { ylo = xlo << sh yhi = xhi<<sh | xlo>>(32-sh) } else { - if x&sign64 != 0 { - *y = 0x8000000000000000 - } else { - *y = 0x7fffffffffffffff - } - return + /* overflow */ + yhi = uint32(d) /* causes something awful */ } } if x&sign64 != 0 { @@ -147,50 +136,6 @@ func _d2v(y *uint64, d float64) { *y = uint64(yhi)<<32 | uint64(ylo) } -func _d2vu(y *uint64, d float64) { - x := *(*uint64)(unsafe.Pointer(&d)) - if x&sign64 != 0 { - *y = 0 - return - } - - xhi := uint32(x>>32)&0xfffff | 0x100000 - xlo := uint32(x) - sh := 1075 - int32(uint32(x>>52)&0x7ff) - - var ylo, yhi uint32 - if sh >= 0 { - sh := uint32(sh) - /* v = (hi||lo) >> sh */ - if sh < 32 { - if sh == 0 { - ylo = xlo - yhi = xhi - } else { - ylo = xlo>>sh | xhi<<(32-sh) - yhi = xhi >> sh - } - } else { - if sh == 32 { - ylo = xhi - } else if sh < 64 { - ylo = xhi >> (sh - 32) - } - } - } else { - /* v = (hi||lo) << -sh */ - sh := uint32(-sh) - if sh <= 11 { - ylo = xlo << sh - yhi = xhi<<sh | xlo>>(32-sh) - } else { - /* overflow */ - *y = 0xffffffffffffffff - return - } - } - *y = uint64(yhi)<<32 | uint64(ylo) -} func uint64div(n, d uint64) uint64 { // Check for 32 bit operands if uint32(n>>32) == 0 && uint32(d>>32) == 0 { |
