aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-10-13 09:39:06 -0700
committerKeith Randall <khr@golang.org>2025-10-13 12:19:32 -0700
commit9b8742f2e79438b9442afa4c0a0139d3937ea33f (patch)
treebe146fe856cf0e978d90bfbcb4e62fa8f489f2d9 /test/codegen
parent0e64ee1286c092eca95b3ffcc5917d34f43d4c0f (diff)
downloadgo-9b8742f2e79438b9442afa4c0a0139d3937ea33f.tar.xz
cmd/compile: don't depend on arch-dependent conversions in the compiler
Leave those constant foldings for runtime, similar to how we do it for NaN generation. These are the only instances I could find in cmd/compile/..., using objdump -d ../pkg/tool/darwin_arm64/compile| egrep "(fcvtz|>:)" | grep -B1 fcvt (There are instances in other places, like runtime and reflect, but I don't think those places would affect compiler output.) Change-Id: I4113fe4570115e4765825cf442cb1fde97cf2f27 Reviewed-on: https://go-review.googlesource.com/c/go/+/711281 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/math.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/codegen/math.go b/test/codegen/math.go
index eadf9d7d05..5787657d2b 100644
--- a/test/codegen/math.go
+++ b/test/codegen/math.go
@@ -330,3 +330,48 @@ func nanGenerate32() float32 {
// amd64/v3:"VFMADD231SS"
return z0 + z1
}
+
+func outOfBoundsConv(i32 *[2]int32, u32 *[2]uint32, i64 *[2]int64, u64 *[2]uint64) {
+ // arm64: "FCVTZSDW"
+ // amd64: "CVTTSD2SL", "CVTSD2SS"
+ i32[0] = int32(two40())
+ // arm64: "FCVTZSDW"
+ // amd64: "CVTTSD2SL", "CVTSD2SS"
+ i32[1] = int32(-two40())
+ // arm64: "FCVTZSDW"
+ // amd64: "CVTTSD2SL", "CVTSD2SS"
+ u32[0] = uint32(two41())
+ // on arm64, this uses an explicit <0 comparison, so it constant folds.
+ // on amd64, this uses an explicit <0 comparison, so it constant folds.
+ // amd64: "MOVL\t[$]0,"
+ u32[1] = uint32(minus1())
+ // arm64: "FCVTZSD"
+ // amd64: "CVTTSD2SQ"
+ i64[0] = int64(two80())
+ // arm64: "FCVTZSD"
+ // amd64: "CVTTSD2SQ"
+ i64[1] = int64(-two80())
+ // arm64: "FCVTZUD"
+ // amd64: "CVTTSD2SQ"
+ u64[0] = uint64(two81())
+ // arm64: "FCVTZUD"
+ // on amd64, this uses an explicit <0 comparison, so it constant folds.
+ // amd64: "MOVQ\t[$]0,"
+ u64[1] = uint64(minus1())
+}
+
+func two40() float64 {
+ return 1 << 40
+}
+func two41() float64 {
+ return 1 << 41
+}
+func two80() float64 {
+ return 1 << 80
+}
+func two81() float64 {
+ return 1 << 81
+}
+func minus1() float64 {
+ return -1
+}