gf_vect_mad_avx512.asm 5.2 KB

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