-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathgmu_test.go
66 lines (52 loc) · 1.29 KB
/
gmu_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2017 Temple3x ([email protected])
//
// Use of this source code is governed by the MIT License
// that can be found in the LICENSE file.
package reedsolomon
import (
"bytes"
"math/rand"
"testing"
"time"
)
func TestGMU(t *testing.T) {
max := testSize
switch getCPUFeature() {
case featAVX2:
testGMU(t, max, featAVX2, featNoSIMD)
}
}
func testGMU(t *testing.T, maxSize, feat, cmpFeat int) {
rand.Seed(time.Now().UnixNano())
fs := featToStr(feat)
start, n := 1, 1
if feat != featNoSIMD {
start, n = 16, 16 // The min size for SIMD instructions.
}
g := new(gmu)
g.initFunc(feat)
cg := new(gmu)
cg.initFunc(cmpFeat)
for size := start; size <= maxSize; size += n {
for c := 0; c <= 255; c++ {
input := make([]byte, size)
act := make([]byte, size)
fillRandom(input)
g.mulVect(byte(c), input, act)
exp := make([]byte, size)
cg.mulVect(byte(c), input, exp)
if !bytes.Equal(act, exp) {
t.Fatalf("%s mismatched with %s, size: %d",
fs, featToStr(cmpFeat), size)
}
g.mulVectXOR(byte(c), input, act)
cg.mulVectXOR(byte(c), input, exp)
if !bytes.Equal(act, exp) {
t.Fatalf("%s mismatched with %s, size: %d",
fs, featToStr(cmpFeat), size)
}
}
}
t.Logf("%s passed, size: [%d, %d), size = i * %d",
fs, start, maxSize+1, n)
}