Skip to content

Commit c1a7a05

Browse files
committed
finally get assembly working correctly
1 parent 1d5c02f commit c1a7a05

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tree/tree
77

88
# Test binary, build with `go test -c`
99
*.test
10+
tst
1011

1112
# save data
1213
*.gob

tree/oit_amd64.s

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
// func oneIfTrue(x, y float32) float32
66
TEXT ·oneIfTrue(SB),NOSPLIT,$0
7-
MOVQ x+0(FP), CX // put first arg in the CX register
8-
MOVQ y+4(FP), SI // put second arg in SI register
9-
CMPQ CX, SI // see if first arg equals second arg
10-
JE RONE // when equal, change the return value
11-
MOVQ $0, ret+8(FP) // default 0 as the return value
7+
MOVSS x+0(FP), X0 // put first arg in a register
8+
MOVSS y+4(FP), X1 // put second arg in a register
9+
UCOMISS X0, X1
10+
JNE NOTEQ // when not equal return 0
11+
MOVQ $0x3f800000, ret+8(FP) // when equal return 0
1212
RET
13-
RONE:
14-
MOVQ $1, ret+8(FP) // move 1 to the return value
13+
NOTEQ:
14+
MOVQ $0x00000000, ret+8(FP) // move 0 to the return value
1515
RET

tree/oit_amd64_test.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,26 @@ func TestOit(t *testing.T) {
3939
}
4040

4141
func BenchmarkOit(b *testing.B) {
42-
var count float32
43-
var a float32
44-
var v float32
45-
for i := 0; i < b.N; i++ {
46-
a = rand.Float32()
47-
v = rand.Float32()
48-
count += oneIfTrue(a, v)
49-
}
50-
}
51-
52-
func BenchmarkIf(b *testing.B) {
53-
var count float32
54-
var a float32
55-
var v float32
56-
for i := 0; i < b.N; i++ {
57-
a = rand.Float32()
58-
v = rand.Float32()
59-
if a == v {
60-
count++
42+
b.Run("oneIfTrue", func(b *testing.B) {
43+
var count float32
44+
var a float32
45+
var v float32
46+
for i := 0; i < b.N; i++ {
47+
a = rand.Float32()
48+
v = rand.Float32()
49+
count += oneIfTrue(a, v)
6150
}
62-
}
51+
})
52+
b.Run("regular conditional", func(b *testing.B) {
53+
var count float32
54+
var a float32
55+
var v float32
56+
for i := 0; i < b.N; i++ {
57+
a = rand.Float32()
58+
v = rand.Float32()
59+
if a == v {
60+
count++
61+
}
62+
}
63+
})
6364
}

0 commit comments

Comments
 (0)