gf_vect_mad_avx2.asm 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_mad_avx2(len, vec, vec_i, mul_array, src, dest);
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %ifidn __OUTPUT_FORMAT__, win64
  34. %define arg0 rcx
  35. %define arg0.w ecx
  36. %define arg1 rdx
  37. %define arg2 r8
  38. %define arg3 r9
  39. %define arg4 r12 ; must be saved and loaded
  40. %define arg5 r15
  41. %define tmp r11
  42. %define tmp.w r11d
  43. %define tmp.b r11b
  44. %define return rax
  45. %define return.w eax
  46. %define PS 8
  47. %define stack_size 16*3 + 3*8
  48. %define arg(x) [rsp + stack_size + PS + PS*x]
  49. %define func(x) proc_frame x
  50. %macro FUNC_SAVE 0
  51. sub rsp, stack_size
  52. vmovdqa [rsp+16*0],xmm6
  53. vmovdqa [rsp+16*1],xmm7
  54. vmovdqa [rsp+16*2],xmm8
  55. save_reg r12, 3*16 + 0*8
  56. save_reg r15, 3*16 + 1*8
  57. end_prolog
  58. mov arg4, arg(4)
  59. mov arg5, arg(5)
  60. %endmacro
  61. %macro FUNC_RESTORE 0
  62. vmovdqa xmm6, [rsp+16*0]
  63. vmovdqa xmm7, [rsp+16*1]
  64. vmovdqa xmm8, [rsp+16*2]
  65. mov r12, [rsp + 3*16 + 0*8]
  66. mov r15, [rsp + 3*16 + 1*8]
  67. add rsp, stack_size
  68. %endmacro
  69. %elifidn __OUTPUT_FORMAT__, elf64
  70. %define arg0 rdi
  71. %define arg0.w edi
  72. %define arg1 rsi
  73. %define arg2 rdx
  74. %define arg3 rcx
  75. %define arg4 r8
  76. %define arg5 r9
  77. %define tmp r11
  78. %define tmp.w r11d
  79. %define tmp.b r11b
  80. %define return rax
  81. %define return.w eax
  82. %define func(x) x:
  83. %define FUNC_SAVE
  84. %define FUNC_RESTORE
  85. %endif
  86. ;;; gf_vect_mad_avx2(len, vec, vec_i, mul_array, src, dest)
  87. %define len arg0
  88. %define len.w arg0.w
  89. %define vec arg1
  90. %define vec_i arg2
  91. %define mul_array arg3
  92. %define src arg4
  93. %define dest arg5
  94. %define pos return
  95. %define pos.w return.w
  96. %ifndef EC_ALIGNED_ADDR
  97. ;;; Use Un-aligned load/store
  98. %define XLDR vmovdqu
  99. %define XSTR vmovdqu
  100. %else
  101. ;;; Use Non-temporal load/stor
  102. %ifdef NO_NT_LDST
  103. %define XLDR vmovdqa
  104. %define XSTR vmovdqa
  105. %else
  106. %define XLDR vmovntdqa
  107. %define XSTR vmovntdq
  108. %endif
  109. %endif
  110. default rel
  111. [bits 64]
  112. section .text
  113. %define xmask0f ymm8
  114. %define xmask0fx xmm8
  115. %define xgft_lo ymm7
  116. %define xgft_hi ymm6
  117. %define x0 ymm0
  118. %define xtmpa ymm1
  119. %define xtmph ymm2
  120. %define xtmpl ymm3
  121. %define xd ymm4
  122. %define xtmpd ymm5
  123. align 16
  124. global gf_vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  125. func(gf_vect_mad_avx2)
  126. %ifidn __OUTPUT_FORMAT__, macho64
  127. global _gf_vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  128. func(_gf_vect_mad_avx2)
  129. %endif
  130. FUNC_SAVE
  131. sub len, 32
  132. jl .return_fail
  133. xor pos, pos
  134. mov tmp.b, 0x0f
  135. vpinsrb xmask0fx, xmask0fx, tmp.w, 0
  136. vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
  137. sal vec_i, 5 ;Multiply by 32
  138. vmovdqu xgft_lo, [vec_i+mul_array] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  139. ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  140. vperm2i128 xgft_hi, xgft_lo, xgft_lo, 0x11 ; swapped to hi | hi
  141. vperm2i128 xgft_lo, xgft_lo, xgft_lo, 0x00 ; swapped to lo | lo
  142. XLDR xtmpd, [dest+len] ;backup the last 32 bytes in dest
  143. .loop32:
  144. XLDR xd, [dest+pos] ;Get next dest vector
  145. .loop32_overlap:
  146. XLDR x0, [src+pos] ;Get next source vector
  147. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  148. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  149. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  150. vpshufb xtmph, xgft_hi, x0 ;Lookup mul table of high nibble
  151. vpshufb xtmpl, xgft_lo, xtmpa ;Lookup mul table of low nibble
  152. vpxor xtmph, xtmph, xtmpl ;GF add high and low partials
  153. vpxor xd, xd, xtmph ;xd += partial
  154. XSTR [dest+pos], xd
  155. add pos, 32 ;Loop on 32 bytes at a time
  156. cmp pos, len
  157. jle .loop32
  158. lea tmp, [len + 32]
  159. cmp pos, tmp
  160. je .return_pass
  161. ;; Tail len
  162. mov pos, len ;Overlapped offset length-32
  163. vmovdqa xd, xtmpd ;Restore xd
  164. jmp .loop32_overlap ;Do one more overlap pass
  165. .return_pass:
  166. mov return, 0
  167. FUNC_RESTORE
  168. ret
  169. .return_fail:
  170. mov return, 1
  171. FUNC_RESTORE
  172. ret
  173. endproc_frame
  174. section .data
  175. ;;; func core, ver, snum
  176. slversion gf_vect_mad_avx2, 04, 01, 0202