2025-10-14 16:18:49 -04:00
|
|
|
// asmcheck -gcflags=-d=converthash=qy
|
2018-03-03 19:17:20 +01:00
|
|
|
|
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package codegen
|
|
|
|
|
|
|
|
|
|
import "math"
|
|
|
|
|
|
|
|
|
|
var sink64 [8]float64
|
|
|
|
|
|
|
|
|
|
func approx(x float64) {
|
2021-09-15 10:31:05 +03:00
|
|
|
// amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"ROUNDSD [$]2"
|
|
|
|
|
// s390x:"FIDBR [$]6"
|
2018-03-03 19:17:20 +01:00
|
|
|
// arm64:"FRINTPD"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FRIP"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Ceil"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[0] = math.Ceil(x)
|
|
|
|
|
|
2021-09-15 10:31:05 +03:00
|
|
|
// amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"ROUNDSD [$]1"
|
|
|
|
|
// s390x:"FIDBR [$]7"
|
2018-03-03 19:17:20 +01:00
|
|
|
// arm64:"FRINTMD"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FRIM"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Floor"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[1] = math.Floor(x)
|
|
|
|
|
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"FIDBR [$]1"
|
2018-03-03 19:17:20 +01:00
|
|
|
// arm64:"FRINTAD"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FRIN"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[2] = math.Round(x)
|
|
|
|
|
|
2021-09-15 10:31:05 +03:00
|
|
|
// amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"ROUNDSD [$]3"
|
|
|
|
|
// s390x:"FIDBR [$]5"
|
2018-03-03 19:17:20 +01:00
|
|
|
// arm64:"FRINTZD"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FRIZ"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Trunc"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[3] = math.Trunc(x)
|
|
|
|
|
|
2021-09-15 10:31:05 +03:00
|
|
|
// amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"ROUNDSD [$]0"
|
|
|
|
|
// s390x:"FIDBR [$]4"
|
2018-05-22 06:58:32 +00:00
|
|
|
// arm64:"FRINTND"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Nearest"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[4] = math.RoundToEven(x)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sqrt(x float64) float64 {
|
|
|
|
|
// amd64:"SQRTSD"
|
2020-10-06 14:42:15 -07:00
|
|
|
// 386/sse2:"SQRTSD" 386/softfloat:-"SQRTD"
|
2018-03-03 19:17:20 +01:00
|
|
|
// arm64:"FSQRTD"
|
2018-04-15 19:00:27 +02:00
|
|
|
// arm/7:"SQRTD"
|
2025-08-21 11:36:54 +08:00
|
|
|
// loong64:"SQRTD"
|
2018-04-26 15:37:27 +02:00
|
|
|
// mips/hardfloat:"SQRTD" mips/softfloat:-"SQRTD"
|
|
|
|
|
// mips64/hardfloat:"SQRTD" mips64/softfloat:-"SQRTD"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Sqrt"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FSQRT"
|
2023-06-14 20:31:08 +08:00
|
|
|
// riscv64: "FSQRTD"
|
2018-03-03 19:17:20 +01:00
|
|
|
return math.Sqrt(x)
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 19:15:15 +08:00
|
|
|
func sqrt32(x float32) float32 {
|
|
|
|
|
// amd64:"SQRTSS"
|
|
|
|
|
// 386/sse2:"SQRTSS" 386/softfloat:-"SQRTS"
|
|
|
|
|
// arm64:"FSQRTS"
|
|
|
|
|
// arm/7:"SQRTF"
|
2025-08-21 11:36:54 +08:00
|
|
|
// loong64:"SQRTF"
|
2020-12-07 19:15:15 +08:00
|
|
|
// mips/hardfloat:"SQRTF" mips/softfloat:-"SQRTF"
|
|
|
|
|
// mips64/hardfloat:"SQRTF" mips64/softfloat:-"SQRTF"
|
|
|
|
|
// wasm:"F32Sqrt"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FSQRTS"
|
2023-06-14 20:31:08 +08:00
|
|
|
// riscv64: "FSQRTS"
|
2020-12-07 19:15:15 +08:00
|
|
|
return float32(math.Sqrt(float64(x)))
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 19:17:20 +01:00
|
|
|
// Check that it's using integer registers
|
|
|
|
|
func abs(x, y float64) {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"BTRQ [$]63"
|
|
|
|
|
// arm64:"FABSD "
|
|
|
|
|
// loong64:"ABSD "
|
|
|
|
|
// s390x:"LPDFR " -"MOVD " (no integer load/store)
|
|
|
|
|
// ppc64x:"FABS "
|
|
|
|
|
// riscv64:"FABSD "
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Abs"
|
2025-10-26 22:51:14 -04:00
|
|
|
// arm/6:"ABSD "
|
|
|
|
|
// mips64/hardfloat:"ABSD "
|
|
|
|
|
// mips/hardfloat:"ABSD "
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[0] = math.Abs(x)
|
|
|
|
|
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"BTRQ [$]63" "PXOR" (TODO: this should be BTSQ)
|
|
|
|
|
// s390x:"LNDFR " -"MOVD " (no integer load/store)
|
|
|
|
|
// ppc64x:"FNABS "
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[1] = -math.Abs(y)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that it's using integer registers
|
|
|
|
|
func abs32(x float32) float32 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"LPDFR" -"LDEBR" -"LEDBR" (no float64 conversion)
|
2018-03-03 19:17:20 +01:00
|
|
|
return float32(math.Abs(float64(x)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that it's using integer registers
|
|
|
|
|
func copysign(a, b, c float64) {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"BTRQ [$]63" "ANDQ" "ORQ"
|
2025-08-21 11:36:54 +08:00
|
|
|
// loong64:"FCOPYSGD"
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"CPSDR" -"MOVD" (no integer load/store)
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FCPSGN"
|
2021-09-09 23:47:14 +01:00
|
|
|
// riscv64:"FSGNJD"
|
2019-03-05 01:56:17 +01:00
|
|
|
// wasm:"F64Copysign"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[0] = math.Copysign(a, b)
|
|
|
|
|
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"BTSQ [$]63"
|
2025-08-21 11:36:54 +08:00
|
|
|
// loong64:"FCOPYSGD"
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"LNDFR " -"MOVD " (no integer load/store)
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FCPSGN"
|
2021-09-09 23:47:14 +01:00
|
|
|
// riscv64:"FSGNJD"
|
2018-09-12 01:43:09 +00:00
|
|
|
// arm64:"ORR", -"AND"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[1] = math.Copysign(c, -1)
|
|
|
|
|
|
|
|
|
|
// Like math.Copysign(c, -1), but with integer operations. Useful
|
|
|
|
|
// for platforms that have a copysign opcode to see if it's detected.
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"LNDFR " -"MOVD " (no integer load/store)
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[2] = math.Float64frombits(math.Float64bits(a) | 1<<63)
|
|
|
|
|
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"ANDQ" "ORQ"
|
2025-08-21 11:36:54 +08:00
|
|
|
// loong64:"FCOPYSGD"
|
2025-10-26 22:51:14 -04:00
|
|
|
// s390x:"CPSDR " -"MOVD " (no integer load/store)
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FCPSGN"
|
2021-09-09 23:47:14 +01:00
|
|
|
// riscv64:"FSGNJD"
|
2018-03-03 19:17:20 +01:00
|
|
|
sink64[3] = math.Copysign(-1, c)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 20:57:33 -04:00
|
|
|
func fma(x, y, z float64) float64 {
|
2021-09-15 10:31:05 +03:00
|
|
|
// amd64/v3:-".*x86HasFMA"
|
2018-09-25 03:10:33 -04:00
|
|
|
// amd64:"VFMADD231SD"
|
2018-10-15 03:14:57 -04:00
|
|
|
// arm/6:"FMULAD"
|
2018-08-29 20:57:33 -04:00
|
|
|
// arm64:"FMADDD"
|
2024-11-05 15:30:45 +08:00
|
|
|
// loong64:"FMADDD"
|
2018-08-29 20:57:33 -04:00
|
|
|
// s390x:"FMADD"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"FMADD"
|
2021-02-17 15:00:34 +00:00
|
|
|
// riscv64:"FMADDD"
|
math, cmd/compile: rename Fma to FMA
This API was added for #25819, where it was discussed as math.FMA.
The commit adding it used math.Fma, presumably for consistency
with the rest of the unusual names in package math
(Sincos, Acosh, Erfcinv, Float32bits, etc).
I believe that using an idiomatic Go name is more important here
than consistency with these other names, most of which are historical
baggage from C's standard library.
Early additions like Float32frombits happened before "uppercase for export"
(so they were originally like "float32frombits") and they were not properly
reconsidered when we uppercased the symbols to export them.
That's a mistake we live with.
The names of functions we have added since then, and even a few
that were legacy, are more properly Go-cased, such as IsNaN, IsInf,
and RoundToEven, rather than Isnan, Isinf, and Roundtoeven.
And also constants like MaxFloat32.
For new API, we should keep using proper Go-cased symbols
instead of minimally-upper-cased-C symbols.
So math.FMA, not math.Fma.
This API has not yet been released, so this change does not break
the compatibility promise.
This CL also modifies cmd/compile, since the compiler knows
the name of the function. I could have stopped at changing the
string constants, but it seemed to make more sense to use a
consistent casing everywhere.
Change-Id: I0f6f3407f41e99bfa8239467345c33945088896e
Reviewed-on: https://go-review.googlesource.com/c/go/+/205317
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-04 19:43:45 -05:00
|
|
|
return math.FMA(x, y, z)
|
2018-08-29 20:57:33 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 15:00:34 +00:00
|
|
|
func fms(x, y, z float64) float64 {
|
|
|
|
|
// riscv64:"FMSUBD"
|
|
|
|
|
return math.FMA(x, y, -z)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: fix FMA negative commutativity of riscv64
According to RISCV manual 11.6:
FMADD x,y,z computes x*y+z and
FNMADD x,y,z => -x*y-z
FMSUB x,y,z => x*y-z
FNMSUB x,y,z => -x*y+z respectively
However our implement of SSA convert FMADD -x,y,z to FNMADD x,y,z which
is wrong and should be convert to FNMSUB according to manual.
Change-Id: Ib297bc83824e121fd7dda171ed56ea9694a4e575
Reviewed-on: https://go-review.googlesource.com/c/go/+/506575
Run-TryBot: M Zhuo <mzh@golangcn.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-27 23:22:04 +08:00
|
|
|
func fnms(x, y, z float64) float64 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// riscv64:"FNMSUBD" -"FNMADDD"
|
2021-02-17 15:00:34 +00:00
|
|
|
return math.FMA(-x, y, z)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: fix FMA negative commutativity of riscv64
According to RISCV manual 11.6:
FMADD x,y,z computes x*y+z and
FNMADD x,y,z => -x*y-z
FMSUB x,y,z => x*y-z
FNMSUB x,y,z => -x*y+z respectively
However our implement of SSA convert FMADD -x,y,z to FNMADD x,y,z which
is wrong and should be convert to FNMSUB according to manual.
Change-Id: Ib297bc83824e121fd7dda171ed56ea9694a4e575
Reviewed-on: https://go-review.googlesource.com/c/go/+/506575
Run-TryBot: M Zhuo <mzh@golangcn.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-27 23:22:04 +08:00
|
|
|
func fnma(x, y, z float64) float64 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// riscv64:"FNMADDD" -"FNMSUBD"
|
2021-02-17 15:00:34 +00:00
|
|
|
return math.FMA(x, -y, -z)
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 13:48:48 +00:00
|
|
|
func isPosInf(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return math.IsInf(x, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isPosInfEq(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x == math.Inf(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isPosInfCmp(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x > math.MaxFloat64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotPosInf(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return !math.IsInf(x, 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotPosInfEq(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x != math.Inf(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotPosInfCmp(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x <= math.MaxFloat64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNegInf(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return math.IsInf(x, -1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNegInfEq(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x == math.Inf(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNegInfCmp(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x < -math.MaxFloat64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotNegInf(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return !math.IsInf(x, -1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotNegInfEq(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x != math.Inf(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isNotNegInfCmp(x float64) bool {
|
|
|
|
|
// riscv64:"FCLASSD"
|
|
|
|
|
return x >= -math.MaxFloat64
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-03 19:17:20 +01:00
|
|
|
func fromFloat64(f64 float64) uint64 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOVQ X.*, [^X].*"
|
|
|
|
|
// arm64:"FMOVD F.*, R.*"
|
|
|
|
|
// loong64:"MOVV F.*, R.*"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"MFVSRD"
|
2025-10-26 22:51:14 -04:00
|
|
|
// mips64/hardfloat:"MOVV F.*, R.*"
|
2024-07-17 23:54:43 +01:00
|
|
|
// riscv64:"FMVXD"
|
2018-03-03 19:17:20 +01:00
|
|
|
return math.Float64bits(f64+1) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fromFloat32(f32 float32) uint32 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOVL X.*, [^X].*"
|
|
|
|
|
// arm64:"FMOVS F.*, R.*"
|
|
|
|
|
// loong64:"MOVW F.*, R.*"
|
|
|
|
|
// mips64/hardfloat:"MOVW F.*, R.*"
|
2024-07-17 23:54:43 +01:00
|
|
|
// riscv64:"FMVXW"
|
2018-03-03 19:17:20 +01:00
|
|
|
return math.Float32bits(f32+1) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toFloat64(u64 uint64) float64 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOVQ [^X].*, X.*"
|
|
|
|
|
// arm64:"FMOVD R.*, F.*"
|
|
|
|
|
// loong64:"MOVV R.*, F.*"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:"MTVSRD"
|
2025-10-26 22:51:14 -04:00
|
|
|
// mips64/hardfloat:"MOVV R.*, F.*"
|
2024-07-17 23:54:43 +01:00
|
|
|
// riscv64:"FMVDX"
|
2018-03-03 19:17:20 +01:00
|
|
|
return math.Float64frombits(u64+1) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func toFloat32(u32 uint32) float32 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOVL [^X].*, X.*"
|
|
|
|
|
// arm64:"FMOVS R.*, F.*"
|
|
|
|
|
// loong64:"MOVW R.*, F.*"
|
|
|
|
|
// mips64/hardfloat:"MOVW R.*, F.*"
|
2024-07-17 23:54:43 +01:00
|
|
|
// riscv64:"FMVWX"
|
2018-03-03 19:17:20 +01:00
|
|
|
return math.Float32frombits(u32+1) + 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that comparisons with constants converted to float
|
|
|
|
|
// are evaluated at compile-time
|
|
|
|
|
|
|
|
|
|
func constantCheck64() bool {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"(MOVB [$]0)|(XORL [A-Z][A-Z0-9]+, [A-Z][A-Z0-9]+)" -"FCMP" -"MOVB [$]1"
|
|
|
|
|
// s390x:"MOV(B|BZ|D) [$]0," -"FCMPU" -"MOV(B|BZ|D) [$]1,"
|
2020-03-03 17:56:20 +00:00
|
|
|
return 0.5 == float64(uint32(1)) || 1.5 > float64(uint64(1<<63))
|
2018-03-03 19:17:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func constantCheck32() bool {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOV(B|L) [$]1" -"FCMP" -"MOV(B|L) [$]0"
|
|
|
|
|
// s390x:"MOV(B|BZ|D) [$]1," -"FCMPU" -"MOV(B|BZ|D) [$]0,"
|
2020-03-03 17:56:20 +00:00
|
|
|
return float32(0.5) <= float32(int64(1)) && float32(1.5) >= float32(int32(-1<<31))
|
2018-03-03 19:17:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that integer constants are converted to floating point constants
|
|
|
|
|
// at compile-time
|
|
|
|
|
|
|
|
|
|
func constantConvert32(x float32) float32 {
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64:"MOVSS [$]f32.3f800000\\(SB\\)"
|
|
|
|
|
// s390x:"FMOVS [$]f32.3f800000\\(SB\\)"
|
|
|
|
|
// ppc64x/power8:"FMOVS [$]f32.3f800000\\(SB\\)"
|
|
|
|
|
// ppc64x/power9:"FMOVS [$]f32.3f800000\\(SB\\)"
|
|
|
|
|
// ppc64x/power10:"XXSPLTIDP [$]1065353216, VS0"
|
|
|
|
|
// arm64:"FMOVS [$]\\(1.0\\)"
|
2018-03-03 19:17:20 +01:00
|
|
|
if x > math.Float32frombits(0x3f800000) {
|
|
|
|
|
return -x
|
|
|
|
|
}
|
|
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func constantConvertInt32(x uint32) uint32 {
|
|
|
|
|
// amd64:-"MOVSS"
|
|
|
|
|
// s390x:-"FMOVS"
|
2023-01-25 11:53:10 -06:00
|
|
|
// ppc64x:-"FMOVS"
|
2018-07-16 04:45:25 +00:00
|
|
|
// arm64:-"FMOVS"
|
2018-03-03 19:17:20 +01:00
|
|
|
if x > math.Float32bits(1) {
|
|
|
|
|
return -x
|
|
|
|
|
}
|
|
|
|
|
return x
|
|
|
|
|
}
|
2020-03-03 17:56:20 +00:00
|
|
|
|
|
|
|
|
func nanGenerate64() float64 {
|
|
|
|
|
// Test to make sure we don't generate a NaN while constant propagating.
|
|
|
|
|
// See issue 36400.
|
|
|
|
|
zero := 0.0
|
|
|
|
|
// amd64:-"DIVSD"
|
|
|
|
|
inf := 1 / zero // +inf. We can constant propagate this one.
|
|
|
|
|
negone := -1.0
|
|
|
|
|
|
|
|
|
|
// amd64:"DIVSD"
|
|
|
|
|
z0 := zero / zero
|
2025-02-02 23:42:43 +01:00
|
|
|
// amd64/v1,amd64/v2:"MULSD"
|
2020-03-03 17:56:20 +00:00
|
|
|
z1 := zero * inf
|
|
|
|
|
// amd64:"SQRTSD"
|
|
|
|
|
z2 := math.Sqrt(negone)
|
2025-02-02 23:42:43 +01:00
|
|
|
// amd64/v3:"VFMADD231SD"
|
2020-03-03 17:56:20 +00:00
|
|
|
return z0 + z1 + z2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func nanGenerate32() float32 {
|
|
|
|
|
zero := float32(0.0)
|
|
|
|
|
// amd64:-"DIVSS"
|
|
|
|
|
inf := 1 / zero // +inf. We can constant propagate this one.
|
|
|
|
|
|
|
|
|
|
// amd64:"DIVSS"
|
|
|
|
|
z0 := zero / zero
|
2025-02-02 23:42:43 +01:00
|
|
|
// amd64/v1,amd64/v2:"MULSS"
|
2020-03-03 17:56:20 +00:00
|
|
|
z1 := zero * inf
|
2025-02-02 23:42:43 +01:00
|
|
|
// amd64/v3:"VFMADD231SS"
|
2020-03-03 17:56:20 +00:00
|
|
|
return z0 + z1
|
|
|
|
|
}
|
2025-10-13 09:39:06 -07:00
|
|
|
|
|
|
|
|
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.
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64: "MOVL [$]0,"
|
2025-10-13 09:39:06 -07:00
|
|
|
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.
|
2025-10-26 22:51:14 -04:00
|
|
|
// amd64: "MOVQ [$]0,"
|
2025-10-13 09:39:06 -07:00
|
|
|
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
|
|
|
|
|
}
|