2017-03-07 12:44:16 +00:00
|
|
|
//+build !noasm
|
|
|
|
//+build !appengine
|
|
|
|
|
|
|
|
// Copyright 2015, Klaus Post, see LICENSE for details.
|
|
|
|
|
|
|
|
package reedsolomon
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func galMulSSSE3(low, high, in, out []byte)
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func galMulSSSE3Xor(low, high, in, out []byte)
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func galMulAVX2Xor(low, high, in, out []byte)
|
|
|
|
|
|
|
|
//go:noescape
|
|
|
|
func galMulAVX2(low, high, in, out []byte)
|
|
|
|
|
|
|
|
// This is what the assembler rountes does in blocks of 16 bytes:
|
|
|
|
/*
|
|
|
|
func galMulSSSE3(low, high, in, out []byte) {
|
|
|
|
for n, input := range in {
|
|
|
|
l := input & 0xf
|
|
|
|
h := input >> 4
|
|
|
|
out[n] = low[l] ^ high[h]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func galMulSSSE3Xor(low, high, in, out []byte) {
|
|
|
|
for n, input := range in {
|
|
|
|
l := input & 0xf
|
|
|
|
h := input >> 4
|
|
|
|
out[n] ^= low[l] ^ high[h]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-03-07 13:28:09 +00:00
|
|
|
func galMulSlice(c byte, in, out []byte, ssse3, avx2 bool) {
|
2017-03-07 12:44:16 +00:00
|
|
|
var done int
|
2017-03-07 13:28:09 +00:00
|
|
|
if avx2 {
|
2017-03-07 12:44:16 +00:00
|
|
|
galMulAVX2(mulTableLow[c][:], mulTableHigh[c][:], in, out)
|
|
|
|
done = (len(in) >> 5) << 5
|
2017-03-07 13:28:09 +00:00
|
|
|
} else if ssse3 {
|
2017-03-07 12:44:16 +00:00
|
|
|
galMulSSSE3(mulTableLow[c][:], mulTableHigh[c][:], in, out)
|
|
|
|
done = (len(in) >> 4) << 4
|
|
|
|
}
|
|
|
|
remain := len(in) - done
|
|
|
|
if remain > 0 {
|
|
|
|
mt := mulTable[c]
|
|
|
|
for i := done; i < len(in); i++ {
|
|
|
|
out[i] = mt[in[i]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 13:28:09 +00:00
|
|
|
func galMulSliceXor(c byte, in, out []byte, ssse3, avx2 bool) {
|
2017-03-07 12:44:16 +00:00
|
|
|
var done int
|
2017-03-07 13:28:09 +00:00
|
|
|
if avx2 {
|
2017-03-07 12:44:16 +00:00
|
|
|
galMulAVX2Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out)
|
|
|
|
done = (len(in) >> 5) << 5
|
2017-03-07 13:28:09 +00:00
|
|
|
} else if ssse3 {
|
2017-03-07 12:44:16 +00:00
|
|
|
galMulSSSE3Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out)
|
|
|
|
done = (len(in) >> 4) << 4
|
|
|
|
}
|
|
|
|
remain := len(in) - done
|
|
|
|
if remain > 0 {
|
|
|
|
mt := mulTable[c]
|
|
|
|
for i := done; i < len(in); i++ {
|
|
|
|
out[i] ^= mt[in[i]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|