{
arch: "amd64",
os: "linux",
- imports: []string{"math", "math/bits", "unsafe", "runtime"},
+ imports: []string{"math/bits", "unsafe", "runtime"},
tests: linuxAMD64Tests,
},
{
- arch: "386",
- os: "linux",
- imports: []string{"math"},
- tests: linux386Tests,
+ arch: "386",
+ os: "linux",
+ tests: linux386Tests,
},
{
arch: "s390x",
os: "linux",
- imports: []string{"math", "math/bits"},
+ imports: []string{"math/bits"},
tests: linuxS390XTests,
},
{
{
arch: "arm64",
os: "linux",
- imports: []string{"math", "math/bits"},
+ imports: []string{"math/bits"},
tests: linuxARM64Tests,
},
{
arch: "mips",
os: "linux",
- imports: []string{"math/bits", "math"},
+ imports: []string{"math/bits"},
tests: linuxMIPSTests,
},
{
- arch: "mips64",
- os: "linux",
- imports: []string{"math"},
- tests: linuxMIPS64Tests,
+ arch: "mips64",
+ os: "linux",
+ tests: linuxMIPS64Tests,
},
{
arch: "ppc64le",
os: "linux",
- imports: []string{"math", "math/bits"},
+ imports: []string{"math/bits"},
tests: linuxPPC64LETests,
},
{
}`,
pos: []string{"\tPOPCNTQ\t", "support_popcnt"},
},
- {
- fn: `
- func $(x float64) float64 {
- return math.Sqrt(x)
- }
- `,
- pos: []string{"SQRTSD"},
- },
// multiplication merging tests
{
fn: `
`,
pos: []string{"TEXT\t.*, [$]0-8"},
},
- // math.Abs using integer registers
- {
- fn: `
- func $(x float64) float64 {
- return math.Abs(x)
- }
- `,
- pos: []string{"\tSHLQ\t[$]1,", "\tSHRQ\t[$]1,"},
- },
- // math.Copysign using integer registers
- {
- fn: `
- func $(x, y float64) float64 {
- return math.Copysign(x, y)
- }
- `,
- pos: []string{"\tSHLQ\t[$]1,", "\tSHRQ\t[$]1,", "\tSHRQ\t[$]63,", "\tSHLQ\t[$]63,", "\tORQ\t"},
- },
// int <-> fp moves
- {
- fn: `
- func $(x float64) uint64 {
- return math.Float64bits(x+1) + 1
- }
- `,
- pos: []string{"\tMOVQ\tX.*, [^X].*"},
- },
- {
- fn: `
- func $(x float32) uint32 {
- return math.Float32bits(x+1) + 1
- }
- `,
- pos: []string{"\tMOVL\tX.*, [^X].*"},
- },
- {
- fn: `
- func $(x uint64) float64 {
- return math.Float64frombits(x+1) + 1
- }
- `,
- pos: []string{"\tMOVQ\t[^X].*, X.*"},
- },
- {
- fn: `
- func $(x uint32) float32 {
- return math.Float32frombits(x+1) + 1
- }
- `,
- pos: []string{"\tMOVL\t[^X].*, X.*"},
- },
{
fn: `
func $(x uint32) bool {
`,
neg: []string{"memmove"},
},
-
- // Intrinsic tests for math
- {
- fn: `
- func $(x float64) float64 {
- return math.Sqrt(x)
- }
- `,
- pos: []string{"FSQRT|SQRTSD"}, // 387|sse2
- },
}
var linuxS390XTests = []*asmTest{
`,
pos: []string{"\tFLOGR\t"},
},
- // Intrinsic tests for math.
- {
- fn: `
- func ceil(x float64) float64 {
- return math.Ceil(x)
- }
- `,
- pos: []string{"\tFIDBR\t[$]6"},
- },
- {
- fn: `
- func floor(x float64) float64 {
- return math.Floor(x)
- }
- `,
- pos: []string{"\tFIDBR\t[$]7"},
- },
- {
- fn: `
- func round(x float64) float64 {
- return math.Round(x)
- }
- `,
- pos: []string{"\tFIDBR\t[$]1"},
- },
- {
- fn: `
- func trunc(x float64) float64 {
- return math.Trunc(x)
- }
- `,
- pos: []string{"\tFIDBR\t[$]5"},
- },
- {
- fn: `
- func roundToEven(x float64) float64 {
- return math.RoundToEven(x)
- }
- `,
- pos: []string{"\tFIDBR\t[$]4"},
- },
{
// check that stack store is optimized away
fn: `
`,
pos: []string{"TEXT\t.*, [$]0-8"},
},
- // Constant propagation through raw bits conversions.
- {
- // uint32 constant converted to float32 constant
- fn: `
- func $(x float32) float32 {
- if x > math.Float32frombits(0x3f800000) {
- return -x
- }
- return x
- }
- `,
- pos: []string{"\tFMOVS\t[$]f32.3f800000\\(SB\\)"},
- },
- {
- // float32 constant converted to uint32 constant
- fn: `
- func $(x uint32) uint32 {
- if x > math.Float32bits(1) {
- return -x
- }
- return x
- }
- `,
- neg: []string{"\tFMOVS\t"},
- },
- // Constant propagation through float comparisons.
- {
- fn: `
- func $() bool {
- return 0.5 == float64(uint32(1)) ||
- 1.5 > float64(uint64(1<<63)) ||
- math.NaN() == math.NaN()
- }
- `,
- pos: []string{"\tMOV(B|BZ|D)\t[$]0,"},
- neg: []string{"\tFCMPU\t", "\tMOV(B|BZ|D)\t[$]1,"},
- },
- {
- fn: `
- func $() bool {
- return float32(0.5) <= float32(int64(1)) &&
- float32(1.5) >= float32(int32(-1<<31)) &&
- float32(math.NaN()) != float32(math.NaN())
- }
- `,
- pos: []string{"\tMOV(B|BZ|D)\t[$]1,"},
- neg: []string{"\tCEBR\t", "\tMOV(B|BZ|D)\t[$]0,"},
- },
- // math tests
- {
- fn: `
- func $(x float64) float64 {
- return math.Abs(x)
- }
- `,
- pos: []string{"\tLPDFR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
- {
- fn: `
- func $(x float32) float32 {
- return float32(math.Abs(float64(x)))
- }
- `,
- pos: []string{"\tLPDFR\t"},
- neg: []string{"\tLDEBR\t", "\tLEDBR\t"}, // no float64 conversion
- },
- {
- fn: `
- func $(x float64) float64 {
- return math.Float64frombits(math.Float64bits(x)|1<<63)
- }
- `,
- pos: []string{"\tLNDFR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
- {
- fn: `
- func $(x float64) float64 {
- return -math.Abs(x)
- }
- `,
- pos: []string{"\tLNDFR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
- {
- fn: `
- func $(x, y float64) float64 {
- return math.Copysign(x, y)
- }
- `,
- pos: []string{"\tCPSDR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
- {
- fn: `
- func $(x float64) float64 {
- return math.Copysign(x, -1)
- }
- `,
- pos: []string{"\tLNDFR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
- {
- fn: `
- func $(x float64) float64 {
- return math.Copysign(-1, x)
- }
- `,
- pos: []string{"\tCPSDR\t"},
- neg: []string{"\tMOVD\t"}, // no integer loads/stores
- },
}
var linuxARMTests = []*asmTest{
pos: []string{"\tMOVHU\t\\(R[0-9]+\\)"},
neg: []string{"ORR\tR[0-9]+<<8\t"},
},
- // Intrinsic tests for math.
- {
- fn: `
- func sqrt(x float64) float64 {
- return math.Sqrt(x)
- }
- `,
- pos: []string{"FSQRTD"},
- },
- {
- fn: `
- func ceil(x float64) float64 {
- return math.Ceil(x)
- }
- `,
- pos: []string{"FRINTPD"},
- },
- {
- fn: `
- func floor(x float64) float64 {
- return math.Floor(x)
- }
- `,
- pos: []string{"FRINTMD"},
- },
- {
- fn: `
- func round(x float64) float64 {
- return math.Round(x)
- }
- `,
- pos: []string{"FRINTAD"},
- },
- {
- fn: `
- func trunc(x float64) float64 {
- return math.Trunc(x)
- }
- `,
- pos: []string{"FRINTZD"},
- },
{
// make sure that CSEL is emitted for conditional moves
fn: `
`,
pos: []string{"\tCLZ\t"},
},
- // Intrinsic tests for math.
- {
- fn: `
- func $(x float64) float64 {
- return math.Sqrt(x)
- }
- `,
- pos: []string{"SQRTD"},
- },
{
// check that stack store is optimized away
fn: `
pos: []string{"SLLV\t\\$17"},
neg: []string{"SGT"},
},
- // Intrinsic tests for math.
- {
- fn: `
- func $(x float64) float64 {
- return math.Sqrt(x)
- }
- `,
- pos: []string{"SQRTD"},
- },
}
var linuxPPC64LETests = []*asmTest{
pos: []string{"\tROTL\t"},
},
- {
- fn: `
- func f12(a, b float64) float64 {
- return math.Copysign(a, b)
- }
- `,
- pos: []string{"\tFCPSGN\t"},
- },
-
- {
- fn: `
- func f13(a float64) float64 {
- return math.Abs(a)
- }
- `,
- pos: []string{"\tFABS\t"},
- },
-
{
// check that stack store is optimized away
fn: `
`,
pos: []string{"TEXT\t.*, [$]0-8"},
},
- // Constant propagation through raw bits conversions.
- {
- // uint32 constant converted to float32 constant
- fn: `
- func $(x float32) float32 {
- if x > math.Float32frombits(0x3f800000) {
- return -x
- }
- return x
- }
- `,
- pos: []string{"\tFMOVS\t[$]f32.3f800000\\(SB\\)"},
- },
- {
- // float32 constant converted to uint32 constant
- fn: `
- func $(x uint32) uint32 {
- if x > math.Float32bits(1) {
- return -x
- }
- return x
- }
- `,
- neg: []string{"\tFMOVS\t"},
- },
}
var plan9AMD64Tests = []*asmTest{
--- /dev/null
+// asmcheck
+
+// 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) {
+ // s390x:"FIDBR\t[$]6"
+ // arm64:"FRINTPD"
+ sink64[0] = math.Ceil(x)
+
+ // s390x:"FIDBR\t[$]7"
+ // arm64:"FRINTMD"
+ sink64[1] = math.Floor(x)
+
+ // s390x:"FIDBR\t[$]1"
+ // arm64:"FRINTAD"
+ sink64[2] = math.Round(x)
+
+ // s390x:"FIDBR\t[$]5"
+ // arm64:"FRINTZD"
+ sink64[3] = math.Trunc(x)
+
+ // s390x:"FIDBR\t[$]4"
+ sink64[4] = math.RoundToEven(x)
+}
+
+func sqrt(x float64) float64 {
+ // amd64:"SQRTSD"
+ // 386:"FSQRT|SQRTSD" (387 or sse2)
+ // arm64:"FSQRTD"
+ // mips:"SQRTD" mips64:"SQRTD"
+ return math.Sqrt(x)
+}
+
+// Check that it's using integer registers
+func abs(x, y float64) {
+ // amd64:"SHLQ\t[$]1","SHRQ\t[$]1,"
+ // s390x:"LPDFR\t",-"MOVD\t" (no integer load/store)
+ // ppc64le:"FABS\t"
+ sink64[0] = math.Abs(x)
+
+ // amd64:"SHLQ\t[$]1","SHRQ\t[$]1,"
+ // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
+ // ppc64le:"FNABS\t"
+ sink64[1] = -math.Abs(y)
+}
+
+// Check that it's using integer registers
+func abs32(x float32) float32 {
+ // s390x:"LPDFR",-"LDEBR",-"LEDBR" (no float64 conversion)
+ return float32(math.Abs(float64(x)))
+}
+
+// Check that it's using integer registers
+func copysign(a, b, c float64) {
+ // amd64:"SHLQ\t[$]1","SHRQ\t[$]1","SHRQ\t[$]63","SHLQ\t[$]63","ORQ"
+ // s390x:"CPSDR",-"MOVD" (no integer load/store)
+ // ppc64le:"FCPSGN"
+ sink64[0] = math.Copysign(a, b)
+
+ // amd64:"SHLQ\t[$]1","SHRQ\t[$]1",-"SHRQ\t[$]63",-"SHLQ\t[$]63","ORQ"
+ // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
+ // ppc64le:"FCPSGN"
+ 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.
+ // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store)
+ sink64[2] = math.Float64frombits(math.Float64bits(a) | 1<<63)
+
+ // amd64:-"SHLQ\t[$]1",-"SHRQ\t[$]1","SHRQ\t[$]63","SHLQ\t[$]63","ORQ"
+ // s390x:"CPSDR\t",-"MOVD\t" (no integer load/store)
+ // ppc64le:"FCPSGN"
+ sink64[3] = math.Copysign(-1, c)
+}
+
+func fromFloat64(f64 float64) uint64 {
+ // amd64:"MOVQ\tX.*, [^X].*"
+ return math.Float64bits(f64+1) + 1
+}
+
+func fromFloat32(f32 float32) uint32 {
+ // amd64:"MOVL\tX.*, [^X].*"
+ return math.Float32bits(f32+1) + 1
+}
+
+func toFloat64(u64 uint64) float64 {
+ // amd64:"MOVQ\t[^X].*, X.*"
+ return math.Float64frombits(u64+1) + 1
+}
+
+func toFloat32(u32 uint32) float32 {
+ // amd64:"MOVL\t[^X].*, X.*"
+ return math.Float32frombits(u32+1) + 1
+}
+
+// Test that comparisons with constants converted to float
+// are evaluated at compile-time
+
+func constantCheck64() bool {
+ // amd64:"MOVB\t[$]0",-"FCMP",-"MOVB\t[$]1"
+ // s390x:"MOV(B|BZ|D)\t[$]0,",-"FCMPU",-"MOV(B|BZ|D)\t[$]1,"
+ return 0.5 == float64(uint32(1)) || 1.5 > float64(uint64(1<<63)) || math.NaN() == math.NaN()
+}
+
+func constantCheck32() bool {
+ // amd64:"MOVB\t[$]1",-"FCMP",-"MOVB\t[$]0"
+ // s390x:"MOV(B|BZ|D)\t[$]1,",-"FCMPU",-"MOV(B|BZ|D)\t[$]0,"
+ return float32(0.5) <= float32(int64(1)) && float32(1.5) >= float32(int32(-1<<31)) && float32(math.NaN()) != float32(math.NaN())
+}
+
+// Test that integer constants are converted to floating point constants
+// at compile-time
+
+func constantConvert32(x float32) float32 {
+ // amd64:"MOVSS\t[$]f32.3f800000\\(SB\\)"
+ // s390x:"FMOVS\t[$]f32.3f800000\\(SB\\)"
+ // ppc64le:"FMOVS\t[$]f32.3f800000\\(SB\\)"
+ if x > math.Float32frombits(0x3f800000) {
+ return -x
+ }
+ return x
+}
+
+func constantConvertInt32(x uint32) uint32 {
+ // amd64:-"MOVSS"
+ // s390x:-"FMOVS"
+ // ppc64le:-"FMOVS"
+ if x > math.Float32bits(1) {
+ return -x
+ }
+ return x
+}