gf_vect_mul_avx.asm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Copyright(c) 2011-2015 Intel Corporation All rights reserved.
  3. ;
  4. ; Redistribution and use in source and binary forms, with or without
  5. ; modification, are permitted provided that the following conditions
  6. ; are met:
  7. ; * Redistributions of source code must retain the above copyright
  8. ; notice, this list of conditions and the following disclaimer.
  9. ; * Redistributions in binary form must reproduce the above copyright
  10. ; notice, this list of conditions and the following disclaimer in
  11. ; the documentation and/or other materials provided with the
  12. ; distribution.
  13. ; * Neither the name of Intel Corporation nor the names of its
  14. ; contributors may be used to endorse or promote products derived
  15. ; from this software without specific prior written permission.
  16. ;
  17. ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;;;
  30. ;;; gf_vect_mul_avx(len, mul_array, src, dest)
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %ifidn __OUTPUT_FORMAT__, elf64
  34. %define arg0 rdi
  35. %define arg1 rsi
  36. %define arg2 rdx
  37. %define arg3 rcx
  38. %define return rax
  39. %define func(x) x: endbranch
  40. %define FUNC_SAVE
  41. %define FUNC_RESTORE
  42. %elifidn __OUTPUT_FORMAT__, win64
  43. %define arg0 rcx
  44. %define arg1 rdx
  45. %define arg2 r8
  46. %define arg3 r9
  47. %define return rax
  48. %define stack_size 5*16 + 8 ; must be an odd multiple of 8
  49. %define func(x) proc_frame x
  50. %macro FUNC_SAVE 0
  51. alloc_stack stack_size
  52. vmovdqa [rsp + 0*16], xmm6
  53. vmovdqa [rsp + 1*16], xmm7
  54. vmovdqa [rsp + 2*16], xmm13
  55. vmovdqa [rsp + 3*16], xmm14
  56. vmovdqa [rsp + 4*16], xmm15
  57. end_prolog
  58. %endmacro
  59. %macro FUNC_RESTORE 0
  60. vmovdqa xmm6, [rsp + 0*16]
  61. vmovdqa xmm7, [rsp + 1*16]
  62. vmovdqa xmm13, [rsp + 2*16]
  63. vmovdqa xmm14, [rsp + 3*16]
  64. vmovdqa xmm15, [rsp + 4*16]
  65. add rsp, stack_size
  66. %endmacro
  67. %endif
  68. %define len arg0
  69. %define mul_array arg1
  70. %define src arg2
  71. %define dest arg3
  72. %define pos return
  73. %define tmp r11
  74. ;;; Use Non-temporal load/stor
  75. %ifdef NO_NT_LDST
  76. %define XLDR vmovdqa
  77. %define XSTR vmovdqa
  78. %else
  79. %define XLDR vmovntdqa
  80. %define XSTR vmovntdq
  81. %endif
  82. default rel
  83. [bits 64]
  84. section .text
  85. %define xmask0f xmm15
  86. %define xgft_lo xmm14
  87. %define xgft_hi xmm13
  88. %define x0 xmm0
  89. %define xtmp1a xmm1
  90. %define xtmp1b xmm2
  91. %define xtmp1c xmm3
  92. %define x1 xmm4
  93. %define xtmp2a xmm5
  94. %define xtmp2b xmm6
  95. %define xtmp2c xmm7
  96. align 16
  97. global gf_vect_mul_avx, function
  98. func(gf_vect_mul_avx)
  99. ; Check if length is multiple of 32 bytes
  100. mov tmp, len
  101. and tmp, 0x1f
  102. jnz return_fail
  103. FUNC_SAVE
  104. mov pos, 0
  105. vmovdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  106. vmovdqu xgft_lo, [mul_array] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  107. vmovdqu xgft_hi, [mul_array+16] ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  108. loop32:
  109. XLDR x0, [src+pos] ;Get next source vector
  110. XLDR x1, [src+pos+16] ;Get next source vector + 16B ahead
  111. add pos, 32 ;Loop on 16 bytes at a time
  112. cmp pos, len
  113. vpand xtmp1a, x0, xmask0f ;Mask low src nibble in bits 4-0
  114. vpand xtmp2a, x1, xmask0f
  115. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  116. vpsraw x1, x1, 4
  117. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  118. vpand x1, x1, xmask0f
  119. vpshufb xtmp1b, xgft_hi, x0 ;Lookup mul table of high nibble
  120. vpshufb xtmp1c, xgft_lo, xtmp1a ;Lookup mul table of low nibble
  121. vpshufb xtmp2b, xgft_hi, x1 ;Lookup mul table of high nibble
  122. vpshufb xtmp2c, xgft_lo, xtmp2a ;Lookup mul table of low nibble
  123. vpxor xtmp1b, xtmp1b, xtmp1c ;GF add high and low partials
  124. vpxor xtmp2b, xtmp2b, xtmp2c
  125. XSTR [dest+pos-32], xtmp1b ;Store result
  126. XSTR [dest+pos-16], xtmp2b ;Store +16B result
  127. jl loop32
  128. FUNC_RESTORE
  129. return_pass:
  130. xor return, return
  131. ret
  132. return_fail:
  133. mov return, 1
  134. ret
  135. endproc_frame
  136. section .data
  137. align 16
  138. mask0f:
  139. dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f