arm.ATST: {gc.SizeL | gc.LeftRead | gc.RightRead, 0, 0, 0},
// Floating point.
- arm.AADDD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.AADDF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.ACMPD: {gc.SizeD | gc.LeftRead | gc.RightRead, 0, 0, 0},
- arm.ACMPF: {gc.SizeF | gc.LeftRead | gc.RightRead, 0, 0, 0},
- arm.ADIVD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.ADIVF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.AMULD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.AMULF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.ASUBD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
- arm.ASUBF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.AADDD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.AADDF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.ACMPD: {gc.SizeD | gc.LeftRead | gc.RightRead, 0, 0, 0},
+ arm.ACMPF: {gc.SizeF | gc.LeftRead | gc.RightRead, 0, 0, 0},
+ arm.ADIVD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.ADIVF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.AMULD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.AMULF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.ASUBD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.ASUBF: {gc.SizeF | gc.LeftRead | RightRdwr, 0, 0, 0},
+ arm.ASQRTD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
// Conversions.
arm.AMOVWD: {gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv, 0, 0, 0},
x86.ASHRL: {gc.SizeL | gc.LeftRead | RightRdwr | gc.ShiftCX | gc.SetCarry, 0, 0, 0},
x86.ASHRQ: {gc.SizeQ | gc.LeftRead | RightRdwr | gc.ShiftCX | gc.SetCarry, 0, 0, 0},
x86.ASHRW: {gc.SizeW | gc.LeftRead | RightRdwr | gc.ShiftCX | gc.SetCarry, 0, 0, 0},
+ x86.ASQRTSD: {gc.SizeD | gc.LeftRead | RightRdwr, 0, 0, 0},
x86.ASTOSB: {gc.OK, AX | DI, DI, 0},
x86.ASTOSL: {gc.OK, AX | DI, DI, 0},
x86.ASTOSQ: {gc.OK, AX | DI, DI, 0},
}
}
+var Global float64
+
func BenchmarkSqrt(b *testing.B) {
+ x, y := 0.0, 10.0
+ for i := 0; i < b.N; i++ {
+ x += Sqrt(y)
+ }
+ Global = x
+}
+
+func BenchmarkSqrtIndirect(b *testing.B) {
+ x, y := 0.0, 10.0
+ f := Sqrt
for i := 0; i < b.N; i++ {
- Sqrt(10)
+ x += f(y)
}
+ Global = x
}
func BenchmarkSqrtGo(b *testing.B) {
+ x, y := 0.0, 10.0
for i := 0; i < b.N; i++ {
- SqrtGo(10)
+ x += SqrtGo(y)
+ }
+ Global = x
+}
+
+func isPrime(i int) bool {
+ // Yes, this is a dumb way to write this code,
+ // but calling Sqrt repeatedly in this way demonstrates
+ // the benefit of using a direct SQRT instruction on systems
+ // that have one, whereas the obvious loop seems not to
+ // demonstrate such a benefit.
+ for j := 2; float64(j) <= Sqrt(float64(i)); j++ {
+ if i%j == 0 {
+ return false
+ }
+ }
+ return true
+}
+
+func BenchmarkSqrtPrime(b *testing.B) {
+ any := false
+ for i := 0; i < b.N; i++ {
+ if isPrime(100003) {
+ any = true
+ }
+ }
+ if any {
+ Global = 1
}
}