Skip to content

Instantly share code, notes, and snippets.

@mengzhuo
Created May 26, 2018 15:20
Show Gist options
  • Save mengzhuo/b1a8c06947788200256ac151619b4a2c to your computer and use it in GitHub Desktop.
Save mengzhuo/b1a8c06947788200256ac151619b4a2c to your computer and use it in GitHub Desktop.
package vadd
func addGeneric(dst, src []uint8) {
for i, s := range src {
dst[i] += s
}
}
func addVector(dst, src []uint8)
TEXT ·addVector(SB),$56
MOVD dstp+0(FP), R1
MOVD srcp+24(FP), R3
VLD1 (R1), [V0.B16, V1.B16, V2.B16, V3.B16]
VLD1 (R3), [V4.B16, V5.B16, V6.B16, V7.B16]
VADD V0.B16, V4.B16, V4.B16
VADD V1.B16, V5.B16, V5.B16
VADD V2.B16, V6.B16, V6.B16
VADD V3.B16, V7.B16, V7.B16
VST1 [V4.B16, V5.B16, V6.B16, V7.B16], (R1)
RET
package vadd
import (
"testing"
)
func TestAddVector(t *testing.T) {
var src, dst []uint8
for i := uint8(0); i < 64; i++ {
src = append(src, i)
dst = append(dst, 64-i)
}
addVector(dst, src)
for i, c := range dst {
if c != 64 {
t.Error(i, c)
}
}
}
func BenchmarkAddGeneric(b *testing.B) {
src := make([]uint8, 64)
dst := make([]uint8, 64)
b.SetBytes(64)
b.ResetTimer()
for i := 0; i < b.N; i++ {
addGeneric(dst, src)
}
}
func BenchmarkAddVector(b *testing.B) {
src := make([]uint8, 64)
dst := make([]uint8, 64)
b.SetBytes(64)
b.ResetTimer()
for i := 0; i < b.N; i++ {
addVector(dst, src)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment