-
Notifications
You must be signed in to change notification settings - Fork 251
/
galois_arm64.go
151 lines (128 loc) · 3.35 KB
/
galois_arm64.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
147
148
149
150
151
//go:build !noasm && !appengine && !gccgo && !nopshufb
// Copyright 2015, Klaus Post, see LICENSE for details.
// Copyright 2017, Minio, Inc.
package reedsolomon
const pshufb = true
//go:noescape
func galMulNEON(low, high, in, out []byte)
//go:noescape
func galMulXorNEON(low, high, in, out []byte)
func getVectorLength() (vl, pl uint64)
func init() {
if defaultOptions.useSVE {
if vl, _ := getVectorLength(); vl <= 256 {
// set vector length in bytes
defaultOptions.vectorLength = int(vl) >> 3
} else {
// disable SVE for hardware implementatons over 256 bits (only know to be Fujitsu A64FX atm)
defaultOptions.useSVE = false
}
}
}
func galMulSlice(c byte, in, out []byte, o *options) {
if c == 1 {
copy(out, in)
return
}
var done int
done = (len(in) >> 5) << 5
if raceEnabled {
raceReadSlice(in[:done])
raceWriteSlice(out[:done])
}
galMulNEON(mulTableLow[c][:], mulTableHigh[c][:], in, out)
remain := len(in) - done
if remain > 0 {
mt := mulTable[c][:256]
for i := done; i < len(in); i++ {
out[i] = mt[in[i]]
}
}
}
func galMulSliceXor(c byte, in, out []byte, o *options) {
if c == 1 {
sliceXor(in, out, o)
return
}
done := (len(in) >> 5) << 5
if raceEnabled {
raceReadSlice(in[:done])
raceWriteSlice(out[:done])
}
galMulXorNEON(mulTableLow[c][:], mulTableHigh[c][:], in, out)
remain := len(in) - done
if remain > 0 {
mt := mulTable[c][:256]
for i := done; i < len(in); i++ {
out[i] ^= mt[in[i]]
}
}
}
// 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)
// 64 byte aligned, always full.
xorSliceNEON(x, y)
}
// 2-way butterfly forward
func fftDIT28(x, y []byte, log_m ffe8, o *options) {
// Reference version:
mulAdd8(x, y, log_m, o)
sliceXor(x, y, o)
}
// 2-way butterfly
func ifftDIT2(x, y []byte, log_m ffe, o *options) {
// 64 byte aligned, always full.
xorSliceNEON(x, y)
// Reference version:
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)
mulAdd8(x, y, log_m, o)
}
func mulgf16(x, y []byte, log_m ffe, o *options) {
refMul(x, y, log_m)
}
func mulAdd8(out, in []byte, log_m ffe8, o *options) {
t := &multiply256LUT8[log_m]
galMulXorNEON(t[:16], t[16:32], in, out)
done := (len(in) >> 5) << 5
in = in[done:]
if len(in) > 0 {
out = out[done:]
refMulAdd8(in, out, log_m)
}
}
func mulgf8(out, in []byte, log_m ffe8, o *options) {
var done int
t := &multiply256LUT8[log_m]
galMulNEON(t[:16], t[16:32], in, out)
done = (len(in) >> 5) << 5
remain := len(in) - done
if remain > 0 {
mt := mul8LUTs[log_m].Value[:]
for i := done; i < len(in); i++ {
out[i] ^= byte(mt[in[i]])
}
}
}