-
Notifications
You must be signed in to change notification settings - Fork 249
/
galois_nopshufb_amd64.go
146 lines (128 loc) · 2.95 KB
/
galois_nopshufb_amd64.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2015, Klaus Post, see LICENSE for details
//go:build nopshufb && !noasm
package reedsolomon
// bigSwitchover is the size where 64 bytes are processed per loop.
const bigSwitchover = 128
const pshufb = false
// simple slice xor
func sliceXor(in, out []byte, o *options) {
if o.useSSE2 {
if len(in) >= bigSwitchover {
if o.useAVX2 {
avx2XorSlice_64(in, out)
done := (len(in) >> 6) << 6
in = in[done:]
out = out[done:]
} else {
sSE2XorSlice_64(in, out)
done := (len(in) >> 6) << 6
in = in[done:]
out = out[done:]
}
}
if len(in) >= 16 {
sSE2XorSlice(in, out)
done := (len(in) >> 4) << 4
in = in[done:]
out = out[done:]
}
} else {
sliceXorGo(in, out, o)
return
}
out = out[:len(in)]
for i := range in {
out[i] ^= in[i]
}
}
func galMulSlice(c byte, in, out []byte, o *options) {
out = out[:len(in)]
if c == 1 {
copy(out, in)
return
}
mt := mulTable[c][:256]
for len(in) >= 4 {
ii := (*[4]byte)(in)
oo := (*[4]byte)(out)
oo[0] = mt[ii[0]]
oo[1] = mt[ii[1]]
oo[2] = mt[ii[2]]
oo[3] = mt[ii[3]]
in = in[4:]
out = out[4:]
}
for n, input := range in {
out[n] = mt[input]
}
}
func galMulSliceXor(c byte, in, out []byte, o *options) {
out = out[:len(in)]
if c == 1 {
sliceXor(in, out, o)
return
}
mt := mulTable[c][:256]
for len(in) >= 4 {
ii := (*[4]byte)(in)
oo := (*[4]byte)(out)
oo[0] ^= mt[ii[0]]
oo[1] ^= mt[ii[1]]
oo[2] ^= mt[ii[2]]
oo[3] ^= mt[ii[3]]
in = in[4:]
out = out[4:]
}
for n, input := range in {
out[n] ^= mt[input]
}
}
func init() {
defaultOptions.useAVX512 = false
}
// 4-way butterfly
func ifftDIT4(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe, o *options) {
ifftDIT4Ref(work, dist, log_m01, log_m23, log_m02, o)
}
// 4-way butterfly
func ifftDIT48(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe8, o *options) {
ifftDIT4Ref8(work, dist, log_m01, log_m23, log_m02, o)
}
// 4-way butterfly
func fftDIT4(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe, o *options) {
fftDIT4Ref(work, dist, log_m01, log_m23, log_m02, o)
}
// 4-way butterfly
func fftDIT48(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe8, o *options) {
fftDIT4Ref8(work, dist, log_m01, log_m23, log_m02, o)
}
// 2-way butterfly forward
func fftDIT2(x, y []byte, log_m ffe, o *options) {
// Reference version:
refMulAdd(x, y, log_m)
sliceXor(x, y, o)
}
// 2-way butterfly forward
func fftDIT28(x, y []byte, log_m ffe8, o *options) {
// Reference version:
refMulAdd8(x, y, log_m)
sliceXor(x, y, o)
}
// 2-way butterfly inverse
func ifftDIT2(x, y []byte, log_m ffe, o *options) {
// Reference version:
sliceXor(x, y, o)
refMulAdd(x, y, log_m)
}
// 2-way butterfly inverse
func ifftDIT28(x, y []byte, log_m ffe8, o *options) {
// Reference version:
sliceXor(x, y, o)
refMulAdd8(x, y, log_m)
}
func mulgf16(x, y []byte, log_m ffe, o *options) {
refMul(x, y, log_m)
}
func mulgf8(x, y []byte, log_m ffe8, o *options) {
refMul8(x, y, log_m)
}