3 // Copyright 2018 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
13 func approx(x float64) {
14 // amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
15 // amd64:"ROUNDSD\t[$]2"
16 // s390x:"FIDBR\t[$]6"
20 sink64[0] = math.Ceil(x)
22 // amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
23 // amd64:"ROUNDSD\t[$]1"
24 // s390x:"FIDBR\t[$]7"
28 sink64[1] = math.Floor(x)
30 // s390x:"FIDBR\t[$]1"
33 sink64[2] = math.Round(x)
35 // amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
36 // amd64:"ROUNDSD\t[$]3"
37 // s390x:"FIDBR\t[$]5"
41 sink64[3] = math.Trunc(x)
43 // amd64/v2:-".*x86HasSSE41" amd64/v3:-".*x86HasSSE41"
44 // amd64:"ROUNDSD\t[$]0"
45 // s390x:"FIDBR\t[$]4"
48 sink64[4] = math.RoundToEven(x)
51 func sqrt(x float64) float64 {
53 // 386/sse2:"SQRTSD" 386/softfloat:-"SQRTD"
56 // mips/hardfloat:"SQRTD" mips/softfloat:-"SQRTD"
57 // mips64/hardfloat:"SQRTD" mips64/softfloat:-"SQRTD"
64 func sqrt32(x float32) float32 {
66 // 386/sse2:"SQRTSS" 386/softfloat:-"SQRTS"
69 // mips/hardfloat:"SQRTF" mips/softfloat:-"SQRTF"
70 // mips64/hardfloat:"SQRTF" mips64/softfloat:-"SQRTF"
74 return float32(math.Sqrt(float64(x)))
77 // Check that it's using integer registers
78 func abs(x, y float64) {
79 // amd64:"BTRQ\t[$]63"
81 // s390x:"LPDFR\t",-"MOVD\t" (no integer load/store)
86 // mips64/hardfloat:"ABSD\t"
87 // mips/hardfloat:"ABSD\t"
88 sink64[0] = math.Abs(x)
90 // amd64:"BTRQ\t[$]63","PXOR" (TODO: this should be BTSQ)
91 // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
93 sink64[1] = -math.Abs(y)
96 // Check that it's using integer registers
97 func abs32(x float32) float32 {
98 // s390x:"LPDFR",-"LDEBR",-"LEDBR" (no float64 conversion)
99 return float32(math.Abs(float64(x)))
102 // Check that it's using integer registers
103 func copysign(a, b, c float64) {
104 // amd64:"BTRQ\t[$]63","ANDQ","ORQ"
105 // s390x:"CPSDR",-"MOVD" (no integer load/store)
108 // wasm:"F64Copysign"
109 sink64[0] = math.Copysign(a, b)
111 // amd64:"BTSQ\t[$]63"
112 // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
115 // arm64:"ORR", -"AND"
116 sink64[1] = math.Copysign(c, -1)
118 // Like math.Copysign(c, -1), but with integer operations. Useful
119 // for platforms that have a copysign opcode to see if it's detected.
120 // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
121 sink64[2] = math.Float64frombits(math.Float64bits(a) | 1<<63)
123 // amd64:"ANDQ","ORQ"
124 // s390x:"CPSDR\t",-"MOVD\t" (no integer load/store)
127 sink64[3] = math.Copysign(-1, c)
130 func fma(x, y, z float64) float64 {
131 // amd64/v3:-".*x86HasFMA"
132 // amd64:"VFMADD231SD"
138 return math.FMA(x, y, z)
141 func fms(x, y, z float64) float64 {
143 return math.FMA(x, y, -z)
146 func fnms(x, y, z float64) float64 {
147 // riscv64:"FNMSUBD",-"FNMADDD"
148 return math.FMA(-x, y, z)
151 func fnma(x, y, z float64) float64 {
152 // riscv64:"FNMADDD",-"FNMSUBD"
153 return math.FMA(x, -y, -z)
156 func fromFloat64(f64 float64) uint64 {
157 // amd64:"MOVQ\tX.*, [^X].*"
158 // arm64:"FMOVD\tF.*, R.*"
160 // mips64/hardfloat:"MOVV\tF.*, R.*"
161 return math.Float64bits(f64+1) + 1
164 func fromFloat32(f32 float32) uint32 {
165 // amd64:"MOVL\tX.*, [^X].*"
166 // arm64:"FMOVS\tF.*, R.*"
167 // mips64/hardfloat:"MOVW\tF.*, R.*"
168 return math.Float32bits(f32+1) + 1
171 func toFloat64(u64 uint64) float64 {
172 // amd64:"MOVQ\t[^X].*, X.*"
173 // arm64:"FMOVD\tR.*, F.*"
175 // mips64/hardfloat:"MOVV\tR.*, F.*"
176 return math.Float64frombits(u64+1) + 1
179 func toFloat32(u32 uint32) float32 {
180 // amd64:"MOVL\t[^X].*, X.*"
181 // arm64:"FMOVS\tR.*, F.*"
182 // mips64/hardfloat:"MOVW\tR.*, F.*"
183 return math.Float32frombits(u32+1) + 1
186 // Test that comparisons with constants converted to float
187 // are evaluated at compile-time
189 func constantCheck64() bool {
190 // amd64:"(MOVB\t[$]0)|(XORL\t[A-Z][A-Z0-9]+, [A-Z][A-Z0-9]+)",-"FCMP",-"MOVB\t[$]1"
191 // s390x:"MOV(B|BZ|D)\t[$]0,",-"FCMPU",-"MOV(B|BZ|D)\t[$]1,"
192 return 0.5 == float64(uint32(1)) || 1.5 > float64(uint64(1<<63))
195 func constantCheck32() bool {
196 // amd64:"MOV(B|L)\t[$]1",-"FCMP",-"MOV(B|L)\t[$]0"
197 // s390x:"MOV(B|BZ|D)\t[$]1,",-"FCMPU",-"MOV(B|BZ|D)\t[$]0,"
198 return float32(0.5) <= float32(int64(1)) && float32(1.5) >= float32(int32(-1<<31))
201 // Test that integer constants are converted to floating point constants
204 func constantConvert32(x float32) float32 {
205 // amd64:"MOVSS\t[$]f32.3f800000\\(SB\\)"
206 // s390x:"FMOVS\t[$]f32.3f800000\\(SB\\)"
207 // ppc64x:"FMOVS\t[$]f32.3f800000\\(SB\\)"
208 // arm64:"FMOVS\t[$]\\(1.0\\)"
209 if x > math.Float32frombits(0x3f800000) {
215 func constantConvertInt32(x uint32) uint32 {
220 if x > math.Float32bits(1) {
226 func nanGenerate64() float64 {
227 // Test to make sure we don't generate a NaN while constant propagating.
231 inf := 1 / zero // +inf. We can constant propagate this one.
239 z2 := math.Sqrt(negone)
243 func nanGenerate32() float32 {
246 inf := 1 / zero // +inf. We can constant propagate this one.