| 1 |
//go:build !noasm && !appengine && !gccgo && !nopshufb |
| 2 |
|
| 3 |
// Copyright 2015, Klaus Post, see LICENSE for details. |
| 4 |
|
| 5 |
package reedsolomon |
| 6 |
|
| 7 |
const pshufb = true |
| 8 |
|
| 9 |
//go:noescape |
| 10 |
func galMulSSSE3(low, high, in, out []byte) |
| 11 |
|
| 12 |
//go:noescape |
| 13 |
func galMulSSSE3Xor(low, high, in, out []byte) |
| 14 |
|
| 15 |
//go:noescape |
| 16 |
func galMulAVX2Xor(low, high, in, out []byte) |
| 17 |
|
| 18 |
//go:noescape |
| 19 |
func galMulAVX2(low, high, in, out []byte) |
| 20 |
|
| 21 |
//go:noescape |
| 22 |
func galMulAVX2Xor_64(low, high, in, out []byte) |
| 23 |
|
| 24 |
//go:noescape |
| 25 |
func galMulAVX2_64(low, high, in, out []byte) |
| 26 |
|
| 27 |
// This is what the assembler routines do in blocks of 16 bytes: |
| 28 |
/* |
| 29 |
func galMulSSSE3(low, high, in, out []byte) { |
| 30 |
for n, input := range in { |
| 31 |
l := input & 0xf |
| 32 |
h := input >> 4 |
| 33 |
out[n] = low[l] ^ high[h] |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func galMulSSSE3Xor(low, high, in, out []byte) { |
| 38 |
for n, input := range in { |
| 39 |
l := input & 0xf |
| 40 |
h := input >> 4 |
| 41 |
out[n] ^= low[l] ^ high[h] |
| 42 |
} |
| 43 |
} |
| 44 |
*/ |
| 45 |
|
| 46 |
// bigSwitchover is the size where 64 bytes are processed per loop. |
| 47 |
const bigSwitchover = 128 |
| 48 |
|
| 49 |
func galMulSlice(c byte, in, out []byte, o *options) { |
| 50 |
if c == 1 { |
| 51 |
copy(out, in) |
| 52 |
return |
| 53 |
} |
| 54 |
if o.useAVX2 { |
| 55 |
if len(in) >= bigSwitchover { |
| 56 |
done := (len(in) >> 6) << 6 |
| 57 |
if raceEnabled { |
| 58 |
raceReadSlice(in[:done]) |
| 59 |
raceWriteSlice(out[:done]) |
| 60 |
} |
| 61 |
galMulAVX2_64(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 62 |
in = in[done:] |
| 63 |
out = out[done:] |
| 64 |
} |
| 65 |
if len(in) > 32 { |
| 66 |
done := (len(in) >> 5) << 5 |
| 67 |
if raceEnabled { |
| 68 |
raceReadSlice(in[:done]) |
| 69 |
raceWriteSlice(out[:done]) |
| 70 |
} |
| 71 |
galMulAVX2(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 72 |
in = in[done:] |
| 73 |
out = out[done:] |
| 74 |
} |
| 75 |
} else if o.useSSSE3 { |
| 76 |
done := (len(in) >> 4) << 4 |
| 77 |
if raceEnabled { |
| 78 |
raceReadSlice(in[:done]) |
| 79 |
raceWriteSlice(out[:done]) |
| 80 |
} |
| 81 |
galMulSSSE3(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 82 |
in = in[done:] |
| 83 |
out = out[done:] |
| 84 |
} else if !o.skip2B { |
| 85 |
mt16 := getMulTable16(c) |
| 86 |
for len(in) >= 8 { |
| 87 |
store16(out, mt16[load16(in, 0)], 0) |
| 88 |
store16(out, mt16[load16(in, 2)], 2) |
| 89 |
store16(out, mt16[load16(in, 4)], 4) |
| 90 |
store16(out, mt16[load16(in, 6)], 6) |
| 91 |
|
| 92 |
in = in[8:] |
| 93 |
out = out[8:] |
| 94 |
} |
| 95 |
} |
| 96 |
out = out[:len(in)] |
| 97 |
mt := mulTable[c][:256] |
| 98 |
for i := range in { |
| 99 |
out[i] = mt[in[i]] |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
func galMulSliceXor(c byte, in, out []byte, o *options) { |
| 104 |
if c == 1 { |
| 105 |
sliceXor(in, out, o) |
| 106 |
return |
| 107 |
} |
| 108 |
|
| 109 |
if o.useAVX2 { |
| 110 |
if len(in) >= bigSwitchover { |
| 111 |
done := (len(in) >> 6) << 6 |
| 112 |
if raceEnabled { |
| 113 |
raceReadSlice(in[:done]) |
| 114 |
raceWriteSlice(out[:done]) |
| 115 |
} |
| 116 |
galMulAVX2Xor_64(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 117 |
in = in[done:] |
| 118 |
out = out[done:] |
| 119 |
} |
| 120 |
if len(in) >= 32 { |
| 121 |
done := (len(in) >> 5) << 5 |
| 122 |
if raceEnabled { |
| 123 |
raceReadSlice(in[:done]) |
| 124 |
raceWriteSlice(out[:done]) |
| 125 |
} |
| 126 |
galMulAVX2Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 127 |
in = in[done:] |
| 128 |
out = out[done:] |
| 129 |
} |
| 130 |
} else if o.useSSSE3 { |
| 131 |
done := (len(in) >> 4) << 4 |
| 132 |
if raceEnabled { |
| 133 |
raceReadSlice(in[:done]) |
| 134 |
raceWriteSlice(out[:done]) |
| 135 |
} |
| 136 |
galMulSSSE3Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out) |
| 137 |
in = in[done:] |
| 138 |
out = out[done:] |
| 139 |
} else if !o.skip2B { |
| 140 |
mt16 := getMulTable16(c) |
| 141 |
for len(in) >= 8 { |
| 142 |
store16(out, load16(out, 0)^mt16[load16(in, 0)], 0) |
| 143 |
store16(out, load16(out, 2)^mt16[load16(in, 2)], 2) |
| 144 |
store16(out, load16(out, 4)^mt16[load16(in, 4)], 4) |
| 145 |
store16(out, load16(out, 6)^mt16[load16(in, 6)], 6) |
| 146 |
|
| 147 |
in = in[8:] |
| 148 |
out = out[8:] |
| 149 |
} |
| 150 |
} |
| 151 |
if len(in) == 0 { |
| 152 |
return |
| 153 |
} |
| 154 |
out = out[:len(in)] |
| 155 |
mt := mulTable[c][:256] |
| 156 |
for i := range in { |
| 157 |
out[i] ^= mt[in[i]] |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
// simple slice xor |
| 162 |
func sliceXor(in, out []byte, o *options) { |
| 163 |
if o.useSSE2 { |
| 164 |
if len(in) >= bigSwitchover { |
| 165 |
if o.useAVX2 { |
| 166 |
done := (len(in) >> 6) << 6 |
| 167 |
if raceEnabled { |
| 168 |
raceReadSlice(in[:done]) |
| 169 |
raceWriteSlice(out[:done]) |
| 170 |
} |
| 171 |
avx2XorSlice_64(in, out) |
| 172 |
in = in[done:] |
| 173 |
out = out[done:] |
| 174 |
} else { |
| 175 |
done := (len(in) >> 6) << 6 |
| 176 |
if raceEnabled { |
| 177 |
raceReadSlice(in[:done]) |
| 178 |
raceWriteSlice(out[:done]) |
| 179 |
} |
| 180 |
sSE2XorSlice_64(in, out) |
| 181 |
in = in[done:] |
| 182 |
out = out[done:] |
| 183 |
} |
| 184 |
} |
| 185 |
if len(in) >= 16 { |
| 186 |
done := (len(in) >> 4) << 4 |
| 187 |
if raceEnabled { |
| 188 |
raceReadSlice(in[:done]) |
| 189 |
raceWriteSlice(out[:done]) |
| 190 |
} |
| 191 |
sSE2XorSlice(in, out) |
| 192 |
in = in[done:] |
| 193 |
out = out[done:] |
| 194 |
} |
| 195 |
} else { |
| 196 |
sliceXorGo(in, out, o) |
| 197 |
return |
| 198 |
} |
| 199 |
out = out[:len(in)] |
| 200 |
for i := range in { |
| 201 |
out[i] ^= in[i] |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
// 4-way butterfly |
| 206 |
func ifftDIT4(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe, o *options) { |
| 207 |
if len(work[0]) == 0 { |
| 208 |
return |
| 209 |
} |
| 210 |
|
| 211 |
t01 := &multiply256LUT[log_m01] |
| 212 |
t23 := &multiply256LUT[log_m23] |
| 213 |
t02 := &multiply256LUT[log_m02] |
| 214 |
if o.useAvx512GFNI && o.useAVX512 && gf2p811dMulMatrices16 != nil { |
| 215 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 216 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 217 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 218 |
if log_m01 == modulus { |
| 219 |
if log_m23 == modulus { |
| 220 |
if log_m02 == modulus { |
| 221 |
ifftDIT4_gfni_avx512_7(work, dist*24, g01, g23, g02) |
| 222 |
} else { |
| 223 |
ifftDIT4_gfni_avx512_3(work, dist*24, g01, g23, g02) |
| 224 |
} |
| 225 |
} else { |
| 226 |
if log_m02 == modulus { |
| 227 |
ifftDIT4_gfni_avx512_5(work, dist*24, g01, g23, g02) |
| 228 |
} else { |
| 229 |
ifftDIT4_gfni_avx512_1(work, dist*24, g01, g23, g02) |
| 230 |
} |
| 231 |
} |
| 232 |
} else { |
| 233 |
if log_m23 == modulus { |
| 234 |
if log_m02 == modulus { |
| 235 |
ifftDIT4_gfni_avx512_6(work, dist*24, g01, g23, g02) |
| 236 |
} else { |
| 237 |
ifftDIT4_gfni_avx512_2(work, dist*24, g01, g23, g02) |
| 238 |
} |
| 239 |
} else { |
| 240 |
if log_m02 == modulus { |
| 241 |
ifftDIT4_gfni_avx512_4(work, dist*24, g01, g23, g02) |
| 242 |
} else { |
| 243 |
ifftDIT4_gfni_avx512_0(work, dist*24, g01, g23, g02) |
| 244 |
} |
| 245 |
} |
| 246 |
} |
| 247 |
return |
| 248 |
} |
| 249 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 250 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 251 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 252 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 253 |
if log_m01 == modulus { |
| 254 |
if log_m23 == modulus { |
| 255 |
if log_m02 == modulus { |
| 256 |
ifftDIT4_gfni_7(work, dist*24, g01, g23, g02) |
| 257 |
} else { |
| 258 |
ifftDIT4_gfni_3(work, dist*24, g01, g23, g02) |
| 259 |
} |
| 260 |
} else { |
| 261 |
if log_m02 == modulus { |
| 262 |
ifftDIT4_gfni_5(work, dist*24, g01, g23, g02) |
| 263 |
} else { |
| 264 |
ifftDIT4_gfni_1(work, dist*24, g01, g23, g02) |
| 265 |
} |
| 266 |
} |
| 267 |
} else { |
| 268 |
if log_m23 == modulus { |
| 269 |
if log_m02 == modulus { |
| 270 |
ifftDIT4_gfni_6(work, dist*24, g01, g23, g02) |
| 271 |
} else { |
| 272 |
ifftDIT4_gfni_2(work, dist*24, g01, g23, g02) |
| 273 |
} |
| 274 |
} else { |
| 275 |
if log_m02 == modulus { |
| 276 |
ifftDIT4_gfni_4(work, dist*24, g01, g23, g02) |
| 277 |
} else { |
| 278 |
ifftDIT4_gfni_0(work, dist*24, g01, g23, g02) |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
return |
| 283 |
} |
| 284 |
if o.useAVX512 { |
| 285 |
if log_m01 == modulus { |
| 286 |
if log_m23 == modulus { |
| 287 |
if log_m02 == modulus { |
| 288 |
ifftDIT4_avx512_7(work, dist*24, t01, t23, t02) |
| 289 |
} else { |
| 290 |
ifftDIT4_avx512_3(work, dist*24, t01, t23, t02) |
| 291 |
} |
| 292 |
} else { |
| 293 |
if log_m02 == modulus { |
| 294 |
ifftDIT4_avx512_5(work, dist*24, t01, t23, t02) |
| 295 |
} else { |
| 296 |
ifftDIT4_avx512_1(work, dist*24, t01, t23, t02) |
| 297 |
} |
| 298 |
} |
| 299 |
} else { |
| 300 |
if log_m23 == modulus { |
| 301 |
if log_m02 == modulus { |
| 302 |
ifftDIT4_avx512_6(work, dist*24, t01, t23, t02) |
| 303 |
} else { |
| 304 |
ifftDIT4_avx512_2(work, dist*24, t01, t23, t02) |
| 305 |
} |
| 306 |
} else { |
| 307 |
if log_m02 == modulus { |
| 308 |
ifftDIT4_avx512_4(work, dist*24, t01, t23, t02) |
| 309 |
} else { |
| 310 |
ifftDIT4_avx512_0(work, dist*24, t01, t23, t02) |
| 311 |
} |
| 312 |
} |
| 313 |
} |
| 314 |
return |
| 315 |
} else if o.useAVX2 { |
| 316 |
if log_m01 == modulus { |
| 317 |
if log_m23 == modulus { |
| 318 |
if log_m02 == modulus { |
| 319 |
ifftDIT4_avx2_7(work, dist*24, t01, t23, t02) |
| 320 |
} else { |
| 321 |
ifftDIT4_avx2_3(work, dist*24, t01, t23, t02) |
| 322 |
} |
| 323 |
} else { |
| 324 |
if log_m02 == modulus { |
| 325 |
ifftDIT4_avx2_5(work, dist*24, t01, t23, t02) |
| 326 |
} else { |
| 327 |
ifftDIT4_avx2_1(work, dist*24, t01, t23, t02) |
| 328 |
} |
| 329 |
} |
| 330 |
} else { |
| 331 |
if log_m23 == modulus { |
| 332 |
if log_m02 == modulus { |
| 333 |
ifftDIT4_avx2_6(work, dist*24, t01, t23, t02) |
| 334 |
} else { |
| 335 |
ifftDIT4_avx2_2(work, dist*24, t01, t23, t02) |
| 336 |
} |
| 337 |
} else { |
| 338 |
if log_m02 == modulus { |
| 339 |
ifftDIT4_avx2_4(work, dist*24, t01, t23, t02) |
| 340 |
} else { |
| 341 |
ifftDIT4_avx2_0(work, dist*24, t01, t23, t02) |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
return |
| 346 |
} |
| 347 |
ifftDIT4Ref(work, dist, log_m01, log_m23, log_m02, o) |
| 348 |
} |
| 349 |
|
| 350 |
// 4-way butterfly with separate destination |
| 351 |
func ifftDIT4Dst(dst, work [][]byte, dist int, log_m01, log_m23, log_m02 ffe, o *options) { |
| 352 |
if len(work[0]) == 0 { |
| 353 |
return |
| 354 |
} |
| 355 |
|
| 356 |
t01 := &multiply256LUT[log_m01] |
| 357 |
t23 := &multiply256LUT[log_m23] |
| 358 |
t02 := &multiply256LUT[log_m02] |
| 359 |
if o.useAvx512GFNI && o.useAVX512 && gf2p811dMulMatrices16 != nil { |
| 360 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 361 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 362 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 363 |
if log_m01 == modulus { |
| 364 |
if log_m23 == modulus { |
| 365 |
if log_m02 == modulus { |
| 366 |
ifftDIT4_gfni_avx512_dst_7(dst, work, dist*24, g01, g23, g02) |
| 367 |
} else { |
| 368 |
ifftDIT4_gfni_avx512_dst_3(dst, work, dist*24, g01, g23, g02) |
| 369 |
} |
| 370 |
} else { |
| 371 |
if log_m02 == modulus { |
| 372 |
ifftDIT4_gfni_avx512_dst_5(dst, work, dist*24, g01, g23, g02) |
| 373 |
} else { |
| 374 |
ifftDIT4_gfni_avx512_dst_1(dst, work, dist*24, g01, g23, g02) |
| 375 |
} |
| 376 |
} |
| 377 |
} else { |
| 378 |
if log_m23 == modulus { |
| 379 |
if log_m02 == modulus { |
| 380 |
ifftDIT4_gfni_avx512_dst_6(dst, work, dist*24, g01, g23, g02) |
| 381 |
} else { |
| 382 |
ifftDIT4_gfni_avx512_dst_2(dst, work, dist*24, g01, g23, g02) |
| 383 |
} |
| 384 |
} else { |
| 385 |
if log_m02 == modulus { |
| 386 |
ifftDIT4_gfni_avx512_dst_4(dst, work, dist*24, g01, g23, g02) |
| 387 |
} else { |
| 388 |
ifftDIT4_gfni_avx512_dst_0(dst, work, dist*24, g01, g23, g02) |
| 389 |
} |
| 390 |
} |
| 391 |
} |
| 392 |
return |
| 393 |
} |
| 394 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 395 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 396 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 397 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 398 |
if log_m01 == modulus { |
| 399 |
if log_m23 == modulus { |
| 400 |
if log_m02 == modulus { |
| 401 |
ifftDIT4_gfni_dst_7(dst, work, dist*24, g01, g23, g02) |
| 402 |
} else { |
| 403 |
ifftDIT4_gfni_dst_3(dst, work, dist*24, g01, g23, g02) |
| 404 |
} |
| 405 |
} else { |
| 406 |
if log_m02 == modulus { |
| 407 |
ifftDIT4_gfni_dst_5(dst, work, dist*24, g01, g23, g02) |
| 408 |
} else { |
| 409 |
ifftDIT4_gfni_dst_1(dst, work, dist*24, g01, g23, g02) |
| 410 |
} |
| 411 |
} |
| 412 |
} else { |
| 413 |
if log_m23 == modulus { |
| 414 |
if log_m02 == modulus { |
| 415 |
ifftDIT4_gfni_dst_6(dst, work, dist*24, g01, g23, g02) |
| 416 |
} else { |
| 417 |
ifftDIT4_gfni_dst_2(dst, work, dist*24, g01, g23, g02) |
| 418 |
} |
| 419 |
} else { |
| 420 |
if log_m02 == modulus { |
| 421 |
ifftDIT4_gfni_dst_4(dst, work, dist*24, g01, g23, g02) |
| 422 |
} else { |
| 423 |
ifftDIT4_gfni_dst_0(dst, work, dist*24, g01, g23, g02) |
| 424 |
} |
| 425 |
} |
| 426 |
} |
| 427 |
return |
| 428 |
} |
| 429 |
if o.useAVX512 { |
| 430 |
if log_m01 == modulus { |
| 431 |
if log_m23 == modulus { |
| 432 |
if log_m02 == modulus { |
| 433 |
ifftDIT4_avx512_dst_7(dst, work, dist*24, t01, t23, t02) |
| 434 |
} else { |
| 435 |
ifftDIT4_avx512_dst_3(dst, work, dist*24, t01, t23, t02) |
| 436 |
} |
| 437 |
} else { |
| 438 |
if log_m02 == modulus { |
| 439 |
ifftDIT4_avx512_dst_5(dst, work, dist*24, t01, t23, t02) |
| 440 |
} else { |
| 441 |
ifftDIT4_avx512_dst_1(dst, work, dist*24, t01, t23, t02) |
| 442 |
} |
| 443 |
} |
| 444 |
} else { |
| 445 |
if log_m23 == modulus { |
| 446 |
if log_m02 == modulus { |
| 447 |
ifftDIT4_avx512_dst_6(dst, work, dist*24, t01, t23, t02) |
| 448 |
} else { |
| 449 |
ifftDIT4_avx512_dst_2(dst, work, dist*24, t01, t23, t02) |
| 450 |
} |
| 451 |
} else { |
| 452 |
if log_m02 == modulus { |
| 453 |
ifftDIT4_avx512_dst_4(dst, work, dist*24, t01, t23, t02) |
| 454 |
} else { |
| 455 |
ifftDIT4_avx512_dst_0(dst, work, dist*24, t01, t23, t02) |
| 456 |
} |
| 457 |
} |
| 458 |
} |
| 459 |
return |
| 460 |
} else if o.useAVX2 { |
| 461 |
if log_m01 == modulus { |
| 462 |
if log_m23 == modulus { |
| 463 |
if log_m02 == modulus { |
| 464 |
ifftDIT4_avx2_dst_7(dst, work, dist*24, t01, t23, t02) |
| 465 |
} else { |
| 466 |
ifftDIT4_avx2_dst_3(dst, work, dist*24, t01, t23, t02) |
| 467 |
} |
| 468 |
} else { |
| 469 |
if log_m02 == modulus { |
| 470 |
ifftDIT4_avx2_dst_5(dst, work, dist*24, t01, t23, t02) |
| 471 |
} else { |
| 472 |
ifftDIT4_avx2_dst_1(dst, work, dist*24, t01, t23, t02) |
| 473 |
} |
| 474 |
} |
| 475 |
} else { |
| 476 |
if log_m23 == modulus { |
| 477 |
if log_m02 == modulus { |
| 478 |
ifftDIT4_avx2_dst_6(dst, work, dist*24, t01, t23, t02) |
| 479 |
} else { |
| 480 |
ifftDIT4_avx2_dst_2(dst, work, dist*24, t01, t23, t02) |
| 481 |
} |
| 482 |
} else { |
| 483 |
if log_m02 == modulus { |
| 484 |
ifftDIT4_avx2_dst_4(dst, work, dist*24, t01, t23, t02) |
| 485 |
} else { |
| 486 |
ifftDIT4_avx2_dst_0(dst, work, dist*24, t01, t23, t02) |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
return |
| 491 |
} |
| 492 |
ifftDIT4DstRef(dst, work, dist, log_m01, log_m23, log_m02, o) |
| 493 |
} |
| 494 |
|
| 495 |
// 4-way butterfly |
| 496 |
func ifftDIT48(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe8, o *options) { |
| 497 |
if len(work[0]) == 0 { |
| 498 |
return |
| 499 |
} |
| 500 |
|
| 501 |
if o.useAvx512GFNI { |
| 502 |
// Note that these currently require that length is multiple of 64. |
| 503 |
t01 := gf2p811dMulMatricesLeo8[log_m01] |
| 504 |
t23 := gf2p811dMulMatricesLeo8[log_m23] |
| 505 |
t02 := gf2p811dMulMatricesLeo8[log_m02] |
| 506 |
if log_m01 == modulus8 { |
| 507 |
if log_m23 == modulus8 { |
| 508 |
if log_m02 == modulus8 { |
| 509 |
ifftDIT48_gfni_7(work, dist*24, t01, t23, t02) |
| 510 |
} else { |
| 511 |
ifftDIT48_gfni_3(work, dist*24, t01, t23, t02) |
| 512 |
} |
| 513 |
} else { |
| 514 |
if log_m02 == modulus8 { |
| 515 |
ifftDIT48_gfni_5(work, dist*24, t01, t23, t02) |
| 516 |
} else { |
| 517 |
ifftDIT48_gfni_1(work, dist*24, t01, t23, t02) |
| 518 |
} |
| 519 |
} |
| 520 |
} else { |
| 521 |
if log_m23 == modulus8 { |
| 522 |
if log_m02 == modulus8 { |
| 523 |
ifftDIT48_gfni_6(work, dist*24, t01, t23, t02) |
| 524 |
} else { |
| 525 |
ifftDIT48_gfni_2(work, dist*24, t01, t23, t02) |
| 526 |
} |
| 527 |
} else { |
| 528 |
if log_m02 == modulus8 { |
| 529 |
ifftDIT48_gfni_4(work, dist*24, t01, t23, t02) |
| 530 |
} else { |
| 531 |
ifftDIT48_gfni_0(work, dist*24, t01, t23, t02) |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
return |
| 536 |
} |
| 537 |
if o.useAVX2 { |
| 538 |
// Note that these currently require that length is multiple of 64. |
| 539 |
t01 := &multiply256LUT8[log_m01] |
| 540 |
t23 := &multiply256LUT8[log_m23] |
| 541 |
t02 := &multiply256LUT8[log_m02] |
| 542 |
if log_m01 == modulus8 { |
| 543 |
if log_m23 == modulus8 { |
| 544 |
if log_m02 == modulus8 { |
| 545 |
ifftDIT48_avx2_7(work, dist*24, t01, t23, t02) |
| 546 |
} else { |
| 547 |
ifftDIT48_avx2_3(work, dist*24, t01, t23, t02) |
| 548 |
} |
| 549 |
} else { |
| 550 |
if log_m02 == modulus8 { |
| 551 |
ifftDIT48_avx2_5(work, dist*24, t01, t23, t02) |
| 552 |
} else { |
| 553 |
ifftDIT48_avx2_1(work, dist*24, t01, t23, t02) |
| 554 |
} |
| 555 |
} |
| 556 |
} else { |
| 557 |
if log_m23 == modulus8 { |
| 558 |
if log_m02 == modulus8 { |
| 559 |
ifftDIT48_avx2_6(work, dist*24, t01, t23, t02) |
| 560 |
} else { |
| 561 |
ifftDIT48_avx2_2(work, dist*24, t01, t23, t02) |
| 562 |
} |
| 563 |
} else { |
| 564 |
if log_m02 == modulus8 { |
| 565 |
ifftDIT48_avx2_4(work, dist*24, t01, t23, t02) |
| 566 |
} else { |
| 567 |
ifftDIT48_avx2_0(work, dist*24, t01, t23, t02) |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
return |
| 572 |
} |
| 573 |
ifftDIT4Ref8(work, dist, log_m01, log_m23, log_m02, o) |
| 574 |
} |
| 575 |
|
| 576 |
// 4-way butterfly |
| 577 |
func ifftDIT48Dst(dst, work [][]byte, dist int, log_m01, log_m23, log_m02 ffe8, o *options) { |
| 578 |
if len(work[0]) == 0 { |
| 579 |
return |
| 580 |
} |
| 581 |
|
| 582 |
if o.useAvx512GFNI { |
| 583 |
// Note that these currently require that length is multiple of 64. |
| 584 |
t01 := gf2p811dMulMatricesLeo8[log_m01] |
| 585 |
t23 := gf2p811dMulMatricesLeo8[log_m23] |
| 586 |
t02 := gf2p811dMulMatricesLeo8[log_m02] |
| 587 |
if log_m01 == modulus8 { |
| 588 |
if log_m23 == modulus8 { |
| 589 |
if log_m02 == modulus8 { |
| 590 |
ifftDIT48_gfni_dst_7(dst, work, dist*24, t01, t23, t02) |
| 591 |
} else { |
| 592 |
ifftDIT48_gfni_dst_3(dst, work, dist*24, t01, t23, t02) |
| 593 |
} |
| 594 |
} else { |
| 595 |
if log_m02 == modulus8 { |
| 596 |
ifftDIT48_gfni_dst_5(dst, work, dist*24, t01, t23, t02) |
| 597 |
} else { |
| 598 |
ifftDIT48_gfni_dst_1(dst, work, dist*24, t01, t23, t02) |
| 599 |
} |
| 600 |
} |
| 601 |
} else { |
| 602 |
if log_m23 == modulus8 { |
| 603 |
if log_m02 == modulus8 { |
| 604 |
ifftDIT48_gfni_dst_6(dst, work, dist*24, t01, t23, t02) |
| 605 |
} else { |
| 606 |
ifftDIT48_gfni_dst_2(dst, work, dist*24, t01, t23, t02) |
| 607 |
} |
| 608 |
} else { |
| 609 |
if log_m02 == modulus8 { |
| 610 |
ifftDIT48_gfni_dst_4(dst, work, dist*24, t01, t23, t02) |
| 611 |
} else { |
| 612 |
ifftDIT48_gfni_dst_0(dst, work, dist*24, t01, t23, t02) |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
return |
| 617 |
} |
| 618 |
if o.useAVX2 { |
| 619 |
// Note that these currently require that length is multiple of 64. |
| 620 |
t01 := &multiply256LUT8[log_m01] |
| 621 |
t23 := &multiply256LUT8[log_m23] |
| 622 |
t02 := &multiply256LUT8[log_m02] |
| 623 |
if log_m01 == modulus8 { |
| 624 |
if log_m23 == modulus8 { |
| 625 |
if log_m02 == modulus8 { |
| 626 |
ifftDIT48_avx2_dst_7(dst, work, dist*24, t01, t23, t02) |
| 627 |
} else { |
| 628 |
ifftDIT48_avx2_dst_3(dst, work, dist*24, t01, t23, t02) |
| 629 |
} |
| 630 |
} else { |
| 631 |
if log_m02 == modulus8 { |
| 632 |
ifftDIT48_avx2_dst_5(dst, work, dist*24, t01, t23, t02) |
| 633 |
} else { |
| 634 |
ifftDIT48_avx2_dst_1(dst, work, dist*24, t01, t23, t02) |
| 635 |
} |
| 636 |
} |
| 637 |
} else { |
| 638 |
if log_m23 == modulus8 { |
| 639 |
if log_m02 == modulus8 { |
| 640 |
ifftDIT48_avx2_dst_6(dst, work, dist*24, t01, t23, t02) |
| 641 |
} else { |
| 642 |
ifftDIT48_avx2_dst_2(dst, work, dist*24, t01, t23, t02) |
| 643 |
} |
| 644 |
} else { |
| 645 |
if log_m02 == modulus8 { |
| 646 |
ifftDIT48_avx2_dst_4(dst, work, dist*24, t01, t23, t02) |
| 647 |
} else { |
| 648 |
ifftDIT48_avx2_dst_0(dst, work, dist*24, t01, t23, t02) |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
return |
| 653 |
} |
| 654 |
ifftDIT4DstRef8(dst, work, dist, log_m01, log_m23, log_m02, o) |
| 655 |
} |
| 656 |
|
| 657 |
func fftDIT4(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe, o *options) { |
| 658 |
if len(work[0]) == 0 { |
| 659 |
return |
| 660 |
} |
| 661 |
|
| 662 |
t01 := &multiply256LUT[log_m01] |
| 663 |
t23 := &multiply256LUT[log_m23] |
| 664 |
t02 := &multiply256LUT[log_m02] |
| 665 |
if o.useAvx512GFNI && o.useAVX512 && gf2p811dMulMatrices16 != nil { |
| 666 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 667 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 668 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 669 |
if log_m02 == modulus { |
| 670 |
if log_m01 == modulus { |
| 671 |
if log_m23 == modulus { |
| 672 |
fftDIT4_gfni_avx512_7(work, dist*24, g01, g23, g02) |
| 673 |
} else { |
| 674 |
fftDIT4_gfni_avx512_3(work, dist*24, g01, g23, g02) |
| 675 |
} |
| 676 |
} else { |
| 677 |
if log_m23 == modulus { |
| 678 |
fftDIT4_gfni_avx512_5(work, dist*24, g01, g23, g02) |
| 679 |
} else { |
| 680 |
fftDIT4_gfni_avx512_1(work, dist*24, g01, g23, g02) |
| 681 |
} |
| 682 |
} |
| 683 |
} else { |
| 684 |
if log_m01 == modulus { |
| 685 |
if log_m23 == modulus { |
| 686 |
fftDIT4_gfni_avx512_6(work, dist*24, g01, g23, g02) |
| 687 |
} else { |
| 688 |
fftDIT4_gfni_avx512_2(work, dist*24, g01, g23, g02) |
| 689 |
} |
| 690 |
} else { |
| 691 |
if log_m23 == modulus { |
| 692 |
fftDIT4_gfni_avx512_4(work, dist*24, g01, g23, g02) |
| 693 |
} else { |
| 694 |
fftDIT4_gfni_avx512_0(work, dist*24, g01, g23, g02) |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
return |
| 699 |
} |
| 700 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 701 |
g01 := &gf2p811dMulMatrices16[log_m01] |
| 702 |
g23 := &gf2p811dMulMatrices16[log_m23] |
| 703 |
g02 := &gf2p811dMulMatrices16[log_m02] |
| 704 |
if log_m02 == modulus { |
| 705 |
if log_m01 == modulus { |
| 706 |
if log_m23 == modulus { |
| 707 |
fftDIT4_gfni_7(work, dist*24, g01, g23, g02) |
| 708 |
} else { |
| 709 |
fftDIT4_gfni_3(work, dist*24, g01, g23, g02) |
| 710 |
} |
| 711 |
} else { |
| 712 |
if log_m23 == modulus { |
| 713 |
fftDIT4_gfni_5(work, dist*24, g01, g23, g02) |
| 714 |
} else { |
| 715 |
fftDIT4_gfni_1(work, dist*24, g01, g23, g02) |
| 716 |
} |
| 717 |
} |
| 718 |
} else { |
| 719 |
if log_m01 == modulus { |
| 720 |
if log_m23 == modulus { |
| 721 |
fftDIT4_gfni_6(work, dist*24, g01, g23, g02) |
| 722 |
} else { |
| 723 |
fftDIT4_gfni_2(work, dist*24, g01, g23, g02) |
| 724 |
} |
| 725 |
} else { |
| 726 |
if log_m23 == modulus { |
| 727 |
fftDIT4_gfni_4(work, dist*24, g01, g23, g02) |
| 728 |
} else { |
| 729 |
fftDIT4_gfni_0(work, dist*24, g01, g23, g02) |
| 730 |
} |
| 731 |
} |
| 732 |
} |
| 733 |
return |
| 734 |
} |
| 735 |
if o.useAVX512 { |
| 736 |
if log_m02 == modulus { |
| 737 |
if log_m01 == modulus { |
| 738 |
if log_m23 == modulus { |
| 739 |
fftDIT4_avx512_7(work, dist*24, t01, t23, t02) |
| 740 |
} else { |
| 741 |
fftDIT4_avx512_3(work, dist*24, t01, t23, t02) |
| 742 |
} |
| 743 |
} else { |
| 744 |
if log_m23 == modulus { |
| 745 |
fftDIT4_avx512_5(work, dist*24, t01, t23, t02) |
| 746 |
} else { |
| 747 |
fftDIT4_avx512_1(work, dist*24, t01, t23, t02) |
| 748 |
} |
| 749 |
} |
| 750 |
} else { |
| 751 |
if log_m01 == modulus { |
| 752 |
if log_m23 == modulus { |
| 753 |
fftDIT4_avx512_6(work, dist*24, t01, t23, t02) |
| 754 |
} else { |
| 755 |
fftDIT4_avx512_2(work, dist*24, t01, t23, t02) |
| 756 |
} |
| 757 |
} else { |
| 758 |
if log_m23 == modulus { |
| 759 |
fftDIT4_avx512_4(work, dist*24, t01, t23, t02) |
| 760 |
} else { |
| 761 |
fftDIT4_avx512_0(work, dist*24, t01, t23, t02) |
| 762 |
} |
| 763 |
} |
| 764 |
} |
| 765 |
return |
| 766 |
} else if o.useAVX2 { |
| 767 |
if log_m02 == modulus { |
| 768 |
if log_m01 == modulus { |
| 769 |
if log_m23 == modulus { |
| 770 |
fftDIT4_avx2_7(work, dist*24, t01, t23, t02) |
| 771 |
} else { |
| 772 |
fftDIT4_avx2_3(work, dist*24, t01, t23, t02) |
| 773 |
} |
| 774 |
} else { |
| 775 |
if log_m23 == modulus { |
| 776 |
fftDIT4_avx2_5(work, dist*24, t01, t23, t02) |
| 777 |
} else { |
| 778 |
fftDIT4_avx2_1(work, dist*24, t01, t23, t02) |
| 779 |
} |
| 780 |
} |
| 781 |
} else { |
| 782 |
if log_m01 == modulus { |
| 783 |
if log_m23 == modulus { |
| 784 |
fftDIT4_avx2_6(work, dist*24, t01, t23, t02) |
| 785 |
} else { |
| 786 |
fftDIT4_avx2_2(work, dist*24, t01, t23, t02) |
| 787 |
} |
| 788 |
} else { |
| 789 |
if log_m23 == modulus { |
| 790 |
fftDIT4_avx2_4(work, dist*24, t01, t23, t02) |
| 791 |
} else { |
| 792 |
fftDIT4_avx2_0(work, dist*24, t01, t23, t02) |
| 793 |
} |
| 794 |
} |
| 795 |
} |
| 796 |
return |
| 797 |
} |
| 798 |
fftDIT4Ref(work, dist, log_m01, log_m23, log_m02, o) |
| 799 |
} |
| 800 |
|
| 801 |
// 4-way butterfly |
| 802 |
func fftDIT48(work [][]byte, dist int, log_m01, log_m23, log_m02 ffe8, o *options) { |
| 803 |
if len(work[0]) == 0 { |
| 804 |
return |
| 805 |
} |
| 806 |
|
| 807 |
if o.useAvx512GFNI { |
| 808 |
t01 := gf2p811dMulMatricesLeo8[log_m01] |
| 809 |
t23 := gf2p811dMulMatricesLeo8[log_m23] |
| 810 |
t02 := gf2p811dMulMatricesLeo8[log_m02] |
| 811 |
// Note that these currently require that length is multiple of 64. |
| 812 |
if log_m02 == modulus8 { |
| 813 |
if log_m01 == modulus8 { |
| 814 |
if log_m23 == modulus8 { |
| 815 |
fftDIT48_gfni_7(work, dist*24, t01, t23, t02) |
| 816 |
} else { |
| 817 |
fftDIT48_gfni_3(work, dist*24, t01, t23, t02) |
| 818 |
} |
| 819 |
} else { |
| 820 |
if log_m23 == modulus8 { |
| 821 |
fftDIT48_gfni_5(work, dist*24, t01, t23, t02) |
| 822 |
} else { |
| 823 |
fftDIT48_gfni_1(work, dist*24, t01, t23, t02) |
| 824 |
} |
| 825 |
} |
| 826 |
} else { |
| 827 |
if log_m01 == modulus8 { |
| 828 |
if log_m23 == modulus8 { |
| 829 |
fftDIT48_gfni_6(work, dist*24, t01, t23, t02) |
| 830 |
} else { |
| 831 |
fftDIT48_gfni_2(work, dist*24, t01, t23, t02) |
| 832 |
} |
| 833 |
} else { |
| 834 |
if log_m23 == modulus8 { |
| 835 |
fftDIT48_gfni_4(work, dist*24, t01, t23, t02) |
| 836 |
} else { |
| 837 |
fftDIT48_gfni_0(work, dist*24, t01, t23, t02) |
| 838 |
} |
| 839 |
} |
| 840 |
} |
| 841 |
return |
| 842 |
} |
| 843 |
if o.useAVX2 { |
| 844 |
t01 := &multiply256LUT8[log_m01] |
| 845 |
t23 := &multiply256LUT8[log_m23] |
| 846 |
t02 := &multiply256LUT8[log_m02] |
| 847 |
// Note that these currently require that length is multiple of 64. |
| 848 |
if log_m02 == modulus8 { |
| 849 |
if log_m01 == modulus8 { |
| 850 |
if log_m23 == modulus8 { |
| 851 |
fftDIT48_avx2_7(work, dist*24, t01, t23, t02) |
| 852 |
} else { |
| 853 |
fftDIT48_avx2_3(work, dist*24, t01, t23, t02) |
| 854 |
} |
| 855 |
} else { |
| 856 |
if log_m23 == modulus8 { |
| 857 |
fftDIT48_avx2_5(work, dist*24, t01, t23, t02) |
| 858 |
} else { |
| 859 |
fftDIT48_avx2_1(work, dist*24, t01, t23, t02) |
| 860 |
} |
| 861 |
} |
| 862 |
} else { |
| 863 |
if log_m01 == modulus8 { |
| 864 |
if log_m23 == modulus8 { |
| 865 |
fftDIT48_avx2_6(work, dist*24, t01, t23, t02) |
| 866 |
} else { |
| 867 |
fftDIT48_avx2_2(work, dist*24, t01, t23, t02) |
| 868 |
} |
| 869 |
} else { |
| 870 |
if log_m23 == modulus8 { |
| 871 |
fftDIT48_avx2_4(work, dist*24, t01, t23, t02) |
| 872 |
} else { |
| 873 |
fftDIT48_avx2_0(work, dist*24, t01, t23, t02) |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
return |
| 878 |
} |
| 879 |
fftDIT4Ref8(work, dist, log_m01, log_m23, log_m02, o) |
| 880 |
} |
| 881 |
|
| 882 |
// 2-way butterfly forward |
| 883 |
func fftDIT2(x, y []byte, log_m ffe, o *options) { |
| 884 |
if len(x) == 0 { |
| 885 |
return |
| 886 |
} |
| 887 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 888 |
tmp := &gf2p811dMulMatrices16[log_m] |
| 889 |
if raceEnabled { |
| 890 |
raceReadSlice(y) |
| 891 |
raceWriteSlice(x) |
| 892 |
} |
| 893 |
fftDIT2_gfni(x, y, tmp) |
| 894 |
} else if o.useAVX2 { |
| 895 |
tmp := &multiply256LUT[log_m] |
| 896 |
if raceEnabled { |
| 897 |
raceReadSlice(y) |
| 898 |
raceWriteSlice(x) |
| 899 |
} |
| 900 |
fftDIT2_avx2(x, y, tmp) |
| 901 |
} else if o.useSSSE3 { |
| 902 |
tmp := &multiply256LUT[log_m] |
| 903 |
if raceEnabled { |
| 904 |
raceReadSlice(y) |
| 905 |
raceWriteSlice(x) |
| 906 |
} |
| 907 |
fftDIT2_ssse3(x, y, tmp) |
| 908 |
} else { |
| 909 |
// Reference version: |
| 910 |
refMulAdd(x, y, log_m) |
| 911 |
sliceXor(x, y, o) |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
// 2-way butterfly forward |
| 916 |
func fftDIT28(x, y []byte, log_m ffe8, o *options) { |
| 917 |
if len(x) == 0 { |
| 918 |
return |
| 919 |
} |
| 920 |
|
| 921 |
if o.useAVX2 { |
| 922 |
done := (len(y) >> 6) << 6 |
| 923 |
if raceEnabled { |
| 924 |
raceReadSlice(y[:done]) |
| 925 |
raceWriteSlice(x[:done]) |
| 926 |
} |
| 927 |
fftDIT28_avx2(x, y, &multiply256LUT8[log_m]) |
| 928 |
if len(x)&63 == 0 { |
| 929 |
return |
| 930 |
} |
| 931 |
y = y[done:] |
| 932 |
x = x[done:] |
| 933 |
} |
| 934 |
mulAdd8(x, y, log_m, o) |
| 935 |
sliceXor(x, y, o) |
| 936 |
} |
| 937 |
|
| 938 |
// 2-way butterfly inverse |
| 939 |
func ifftDIT28(x, y []byte, log_m ffe8, o *options) { |
| 940 |
if len(x) == 0 { |
| 941 |
return |
| 942 |
} |
| 943 |
|
| 944 |
if o.useAVX2 { |
| 945 |
done := (len(y) >> 6) << 6 |
| 946 |
if raceEnabled { |
| 947 |
raceReadSlice(y[:done]) |
| 948 |
raceWriteSlice(x[:done]) |
| 949 |
} |
| 950 |
ifftDIT28_avx2(x, y, &multiply256LUT8[log_m]) |
| 951 |
if len(x)&63 == 0 { |
| 952 |
return |
| 953 |
} |
| 954 |
y = y[done:] |
| 955 |
x = x[done:] |
| 956 |
} |
| 957 |
sliceXor(x, y, o) |
| 958 |
mulAdd8(x, y, log_m, o) |
| 959 |
} |
| 960 |
|
| 961 |
func mulAdd8(x, y []byte, log_m ffe8, o *options) { |
| 962 |
if o.useAVX2 { |
| 963 |
t := &multiply256LUT8[log_m] |
| 964 |
done := (len(y) >> 6) << 6 |
| 965 |
if raceEnabled { |
| 966 |
raceReadSlice(y[:done]) |
| 967 |
raceWriteSlice(x[:done]) |
| 968 |
} |
| 969 |
galMulAVX2Xor_64(t[:16], t[16:32], y, x) |
| 970 |
y = y[done:] |
| 971 |
x = x[done:] |
| 972 |
} else if o.useSSSE3 { |
| 973 |
t := &multiply256LUT8[log_m] |
| 974 |
done := (len(y) >> 4) << 4 |
| 975 |
if raceEnabled { |
| 976 |
raceReadSlice(y[:done]) |
| 977 |
raceWriteSlice(x[:done]) |
| 978 |
} |
| 979 |
galMulSSSE3Xor(t[:16], t[16:32], y, x) |
| 980 |
y = y[done:] |
| 981 |
x = x[done:] |
| 982 |
} |
| 983 |
refMulAdd8(x, y, log_m) |
| 984 |
} |
| 985 |
|
| 986 |
// 2-way butterfly |
| 987 |
func ifftDIT2(x, y []byte, log_m ffe, o *options) { |
| 988 |
if len(x) == 0 { |
| 989 |
return |
| 990 |
} |
| 991 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 992 |
tmp := &gf2p811dMulMatrices16[log_m] |
| 993 |
if raceEnabled { |
| 994 |
raceReadSlice(y) |
| 995 |
raceWriteSlice(x) |
| 996 |
} |
| 997 |
ifftDIT2_gfni(x, y, tmp) |
| 998 |
} else if o.useAVX2 { |
| 999 |
tmp := &multiply256LUT[log_m] |
| 1000 |
if raceEnabled { |
| 1001 |
raceReadSlice(y) |
| 1002 |
raceWriteSlice(x) |
| 1003 |
} |
| 1004 |
|
| 1005 |
ifftDIT2_avx2(x, y, tmp) |
| 1006 |
} else if o.useSSSE3 { |
| 1007 |
tmp := &multiply256LUT[log_m] |
| 1008 |
if raceEnabled { |
| 1009 |
raceReadSlice(y) |
| 1010 |
raceWriteSlice(x) |
| 1011 |
} |
| 1012 |
|
| 1013 |
ifftDIT2_ssse3(x, y, tmp) |
| 1014 |
} else { |
| 1015 |
// Reference version: |
| 1016 |
sliceXor(x, y, o) |
| 1017 |
refMulAdd(x, y, log_m) |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
func mulgf16(x, y []byte, log_m ffe, o *options) { |
| 1022 |
if len(x) == 0 { |
| 1023 |
return |
| 1024 |
} |
| 1025 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 1026 |
tmp := &gf2p811dMulMatrices16[log_m] |
| 1027 |
if raceEnabled { |
| 1028 |
raceReadSlice(y) |
| 1029 |
raceWriteSlice(x) |
| 1030 |
} |
| 1031 |
mulgf16_gfni(x, y, tmp) |
| 1032 |
} else if o.useAVX2 { |
| 1033 |
tmp := &multiply256LUT[log_m] |
| 1034 |
if raceEnabled { |
| 1035 |
raceReadSlice(y) |
| 1036 |
raceWriteSlice(x) |
| 1037 |
} |
| 1038 |
mulgf16_avx2(x, y, tmp) |
| 1039 |
} else if o.useSSSE3 { |
| 1040 |
tmp := &multiply256LUT[log_m] |
| 1041 |
if raceEnabled { |
| 1042 |
raceReadSlice(y) |
| 1043 |
raceWriteSlice(x) |
| 1044 |
} |
| 1045 |
mulgf16_ssse3(x, y, tmp) |
| 1046 |
} else { |
| 1047 |
refMul(x, y, log_m) |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
func mulgf16Xor8(scalars *[8]uint16, in []byte, outs *[8][]byte, o *options) { |
| 1052 |
if len(in) == 0 { |
| 1053 |
return |
| 1054 |
} |
| 1055 |
if o.useAvx512GFNI && gf2p811dMulMatrices16 != nil { |
| 1056 |
var tables [8][4]uint64 |
| 1057 |
for k, c := range scalars { |
| 1058 |
if c != 0 { |
| 1059 |
tables[k] = gf2p811dMulMatrices16[logLUT[ffe(c)]] |
| 1060 |
} |
| 1061 |
} |
| 1062 |
if raceEnabled { |
| 1063 |
raceReadSlice(in) |
| 1064 |
for k := range outs { |
| 1065 |
raceWriteSlice(outs[k]) |
| 1066 |
} |
| 1067 |
} |
| 1068 |
mulgf16Xor8_avx512gfni(in, outs, &tables) |
| 1069 |
return |
| 1070 |
} |
| 1071 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 1072 |
var tables [8][4]uint64 |
| 1073 |
for k, c := range scalars { |
| 1074 |
if c != 0 { |
| 1075 |
tables[k] = gf2p811dMulMatrices16[logLUT[ffe(c)]] |
| 1076 |
} |
| 1077 |
} |
| 1078 |
if raceEnabled { |
| 1079 |
raceReadSlice(in) |
| 1080 |
for k := range outs { |
| 1081 |
raceWriteSlice(outs[k]) |
| 1082 |
} |
| 1083 |
} |
| 1084 |
mulgf16Xor8_gfni(in, outs, &tables) |
| 1085 |
return |
| 1086 |
} |
| 1087 |
if o.useAVX2 { |
| 1088 |
var tables [8][8 * 16]byte |
| 1089 |
for k, c := range scalars { |
| 1090 |
if c != 0 { |
| 1091 |
tables[k] = multiply256LUT[logLUT[ffe(c)]] |
| 1092 |
} |
| 1093 |
} |
| 1094 |
if raceEnabled { |
| 1095 |
raceReadSlice(in) |
| 1096 |
for k := range outs { |
| 1097 |
raceWriteSlice(outs[k]) |
| 1098 |
} |
| 1099 |
} |
| 1100 |
mulgf16Xor8_avx2(in, outs, &tables) |
| 1101 |
return |
| 1102 |
} |
| 1103 |
refMulAdd8x(scalars, in, outs) |
| 1104 |
} |
| 1105 |
|
| 1106 |
func mulgf16Xor(x, y []byte, log_m ffe, o *options) { |
| 1107 |
if len(x) == 0 { |
| 1108 |
return |
| 1109 |
} |
| 1110 |
if o.useAvxGNFI && gf2p811dMulMatrices16 != nil { |
| 1111 |
tmp := &gf2p811dMulMatrices16[log_m] |
| 1112 |
if raceEnabled { |
| 1113 |
raceReadSlice(y) |
| 1114 |
raceWriteSlice(x) |
| 1115 |
} |
| 1116 |
mulgf16Xor_gfni(x, y, tmp) |
| 1117 |
} else if o.useAVX2 { |
| 1118 |
tmp := &multiply256LUT[log_m] |
| 1119 |
if raceEnabled { |
| 1120 |
raceReadSlice(y) |
| 1121 |
raceWriteSlice(x) |
| 1122 |
} |
| 1123 |
mulgf16Xor_avx2(x, y, tmp) |
| 1124 |
} else if o.useSSSE3 { |
| 1125 |
tmp := &multiply256LUT[log_m] |
| 1126 |
if raceEnabled { |
| 1127 |
raceReadSlice(y) |
| 1128 |
raceWriteSlice(x) |
| 1129 |
} |
| 1130 |
mulgf16Xor_ssse3(x, y, tmp) |
| 1131 |
} else { |
| 1132 |
refMulAdd(x, y, log_m) |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
func mulgf8(out, in []byte, log_m ffe8, o *options) { |
| 1137 |
if o.useAVX2 { |
| 1138 |
t := &multiply256LUT8[log_m] |
| 1139 |
done := (len(in) >> 6) << 6 |
| 1140 |
if raceEnabled { |
| 1141 |
raceReadSlice(in[:done]) |
| 1142 |
raceWriteSlice(out[:done]) |
| 1143 |
} |
| 1144 |
|
| 1145 |
galMulAVX2_64(t[:16], t[16:32], in, out) |
| 1146 |
in = in[done:] |
| 1147 |
out = out[done:] |
| 1148 |
} else if o.useSSSE3 { |
| 1149 |
t := &multiply256LUT8[log_m] |
| 1150 |
done := (len(in) >> 4) << 4 |
| 1151 |
if raceEnabled { |
| 1152 |
raceReadSlice(in[:done]) |
| 1153 |
raceWriteSlice(out[:done]) |
| 1154 |
} |
| 1155 |
galMulSSSE3(t[:16], t[16:32], in, out) |
| 1156 |
in = in[done:] |
| 1157 |
out = out[done:] |
| 1158 |
} |
| 1159 |
out = out[:len(in)] |
| 1160 |
mt := mul8LUTs[log_m].Value[:] |
| 1161 |
for i := range in { |
| 1162 |
out[i] = byte(mt[in[i]]) |
| 1163 |
} |
| 1164 |
} |