aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2021-06-09 20:01:12 -0400
committerCherry Mui <cherryyz@google.com>2021-08-02 16:09:19 +0000
commitaa3d54da07bea208cd7c5860875b2d3fbbfeb825 (patch)
treef2c0aa61946a61a571721cdebaa90e2cc6acc7ec
parent0b8a9ccb25cd9b8f78eb47b1934522af3fb4108f (diff)
downloadgo-aa3d54da07bea208cd7c5860875b2d3fbbfeb825.tar.gz
go-aa3d54da07bea208cd7c5860875b2d3fbbfeb825.zip
[dev.typeparams] runtime: rewrite softfloat functions to avoid using floats
Currently, most softfloat functions take uint32/64 arguments (for bit representation of float32/64) and operate on uint32/64. But there are exeptions where the function take float arguments and operate on float. So they are only actually softfloat if the helper functions themselves are translated (by the compiler's softfloat mode). These are mostly fine (besides being a bit convoluted). But with register ABIs this inconsistency adds complexity to the compiler to generate such calls, because it needs to be called with the right ABI. Rewrite the functions to operate on uint32/64 directly, using other helper functions. So they all take uint32/64 arguments and return uint32/64. Change-Id: Id9383b74bcbafee44160cc5b58ab245bffbbdfd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/327273 Trust: Cherry Mui <cherryyz@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
-rw-r--r--src/runtime/softfloat64.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/runtime/softfloat64.go b/src/runtime/softfloat64.go
index 13bee6c1d7..084aa132d9 100644
--- a/src/runtime/softfloat64.go
+++ b/src/runtime/softfloat64.go
@@ -562,36 +562,38 @@ func f64toint64(x uint64) int64 {
return val
}
-func f64touint64(x float64) uint64 {
- if x < float64(1<<63) {
- return uint64(int64(x))
+func f64touint64(x uint64) uint64 {
+ var m uint64 = 0x43e0000000000000 // float64 1<<63
+ if fgt64(m, x) {
+ return uint64(f64toint64(x))
}
- y := x - float64(1<<63)
- z := uint64(int64(y))
+ y := fadd64(x, -m)
+ z := uint64(f64toint64(y))
return z | (1 << 63)
}
-func f32touint64(x float32) uint64 {
- if x < float32(1<<63) {
- return uint64(int64(x))
+func f32touint64(x uint32) uint64 {
+ var m uint32 = 0x5f000000 // float32 1<<63
+ if fgt32(m, x) {
+ return uint64(f32toint64(x))
}
- y := x - float32(1<<63)
- z := uint64(int64(y))
+ y := fadd32(x, -m)
+ z := uint64(f32toint64(y))
return z | (1 << 63)
}
-func fuint64to64(x uint64) float64 {
+func fuint64to64(x uint64) uint64 {
if int64(x) >= 0 {
- return float64(int64(x))
+ return fint64to64(int64(x))
}
- // See ../cmd/compile/internal/gc/ssa.go:uint64Tofloat
+ // See ../cmd/compile/internal/ssagen/ssa.go:uint64Tofloat
y := x & 1
z := x >> 1
z = z | y
- r := float64(int64(z))
- return r + r
+ r := fint64to64(int64(z))
+ return fadd64(r, r)
}
-func fuint64to32(x uint64) float32 {
- return float32(fuint64to64(x))
+func fuint64to32(x uint64) uint32 {
+ return f64to32(fuint64to64(x))
}