galois_amd64.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //+build !noasm
  2. //+build !appengine
  3. // Copyright 2015, Klaus Post, see LICENSE for details.
  4. package reedsolomon
  5. //go:noescape
  6. func galMulSSSE3(low, high, in, out []byte)
  7. //go:noescape
  8. func galMulSSSE3Xor(low, high, in, out []byte)
  9. //go:noescape
  10. func galMulAVX2Xor(low, high, in, out []byte)
  11. //go:noescape
  12. func galMulAVX2(low, high, in, out []byte)
  13. // This is what the assembler rountes does in blocks of 16 bytes:
  14. /*
  15. func galMulSSSE3(low, high, in, out []byte) {
  16. for n, input := range in {
  17. l := input & 0xf
  18. h := input >> 4
  19. out[n] = low[l] ^ high[h]
  20. }
  21. }
  22. func galMulSSSE3Xor(low, high, in, out []byte) {
  23. for n, input := range in {
  24. l := input & 0xf
  25. h := input >> 4
  26. out[n] ^= low[l] ^ high[h]
  27. }
  28. }
  29. */
  30. func galMulSlice(c byte, in, out []byte, ssse3, avx2 bool) {
  31. var done int
  32. if avx2 {
  33. galMulAVX2(mulTableLow[c][:], mulTableHigh[c][:], in, out)
  34. done = (len(in) >> 5) << 5
  35. } else if ssse3 {
  36. galMulSSSE3(mulTableLow[c][:], mulTableHigh[c][:], in, out)
  37. done = (len(in) >> 4) << 4
  38. }
  39. remain := len(in) - done
  40. if remain > 0 {
  41. mt := mulTable[c]
  42. for i := done; i < len(in); i++ {
  43. out[i] = mt[in[i]]
  44. }
  45. }
  46. }
  47. func galMulSliceXor(c byte, in, out []byte, ssse3, avx2 bool) {
  48. var done int
  49. if avx2 {
  50. galMulAVX2Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out)
  51. done = (len(in) >> 5) << 5
  52. } else if ssse3 {
  53. galMulSSSE3Xor(mulTableLow[c][:], mulTableHigh[c][:], in, out)
  54. done = (len(in) >> 4) << 4
  55. }
  56. remain := len(in) - done
  57. if remain > 0 {
  58. mt := mulTable[c]
  59. for i := done; i < len(in); i++ {
  60. out[i] ^= mt[in[i]]
  61. }
  62. }
  63. }