gf_3vect_mad_avx512.asm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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_3vect_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, loaded and restored
  53. %define arg5 r15 ; must be saved and restored
  54. %define tmp r11
  55. %define return rax
  56. %define return.w eax
  57. %define stack_size 16*10 + 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. vmovdqa [rsp+16*3],xmm9
  66. vmovdqa [rsp+16*4],xmm10
  67. vmovdqa [rsp+16*5],xmm11
  68. vmovdqa [rsp+16*6],xmm12
  69. vmovdqa [rsp+16*7],xmm13
  70. vmovdqa [rsp+16*8],xmm14
  71. vmovdqa [rsp+16*9],xmm15
  72. save_reg r12, 10*16 + 0*8
  73. save_reg r15, 10*16 + 1*8
  74. end_prolog
  75. mov arg4, arg(4)
  76. mov arg5, arg(5)
  77. %endmacro
  78. %macro FUNC_RESTORE 0
  79. vmovdqa xmm6, [rsp+16*0]
  80. vmovdqa xmm7, [rsp+16*1]
  81. vmovdqa xmm8, [rsp+16*2]
  82. vmovdqa xmm9, [rsp+16*3]
  83. vmovdqa xmm10, [rsp+16*4]
  84. vmovdqa xmm11, [rsp+16*5]
  85. vmovdqa xmm12, [rsp+16*6]
  86. vmovdqa xmm13, [rsp+16*7]
  87. vmovdqa xmm14, [rsp+16*8]
  88. vmovdqa xmm15, [rsp+16*9]
  89. mov r12, [rsp + 10*16 + 0*8]
  90. mov r15, [rsp + 10*16 + 1*8]
  91. add rsp, stack_size
  92. %endmacro
  93. %endif
  94. %define PS 8
  95. %define len arg0
  96. %define vec arg1
  97. %define vec_i arg2
  98. %define mul_array arg3
  99. %define src arg4
  100. %define dest1 arg5
  101. %define pos return
  102. %define dest2 mul_array
  103. %define dest3 vec_i
  104. %ifndef EC_ALIGNED_ADDR
  105. ;;; Use Un-aligned load/store
  106. %define XLDR vmovdqu8
  107. %define XSTR vmovdqu8
  108. %else
  109. ;;; Use Non-temporal load/stor
  110. %ifdef NO_NT_LDST
  111. %define XLDR vmovdqa
  112. %define XSTR vmovdqa
  113. %else
  114. %define XLDR vmovntdqa
  115. %define XSTR vmovntdq
  116. %endif
  117. %endif
  118. default rel
  119. [bits 64]
  120. section .text
  121. %define x0 zmm0
  122. %define xtmpa zmm1
  123. %define xtmph1 zmm2
  124. %define xtmpl1 zmm3
  125. %define xtmph2 zmm4
  126. %define xtmpl2 zmm5
  127. %define xtmph3 zmm6
  128. %define xtmpl3 zmm7
  129. %define xgft1_hi zmm8
  130. %define xgft1_lo zmm9
  131. %define xgft1_loy ymm9
  132. %define xgft2_hi zmm10
  133. %define xgft2_lo zmm11
  134. %define xgft2_loy ymm11
  135. %define xgft3_hi zmm12
  136. %define xgft3_lo zmm13
  137. %define xgft3_loy ymm13
  138. %define xd1 zmm14
  139. %define xd2 zmm15
  140. %define xd3 zmm16
  141. %define xmask0f zmm17
  142. align 16
  143. global gf_3vect_mad_avx512:ISAL_SYM_TYPE_FUNCTION
  144. func(gf_3vect_mad_avx512)
  145. %ifidn __OUTPUT_FORMAT__, macho64
  146. global _gf_3vect_mad_avx512:ISAL_SYM_TYPE_FUNCTION
  147. func(_gf_3vect_mad_avx512)
  148. %endif
  149. FUNC_SAVE
  150. sub len, 64
  151. jl .return_fail
  152. xor pos, pos
  153. mov tmp, 0x0f
  154. vpbroadcastb xmask0f, tmp ;Construct mask 0x0f0f0f...
  155. sal vec_i, 5 ;Multiply by 32
  156. sal vec, 5
  157. lea tmp, [mul_array + vec_i]
  158. vmovdqu xgft1_loy, [tmp] ;Load array Ax{00}..{0f}, Ax{00}..{f0}
  159. vmovdqu xgft2_loy, [tmp+vec] ;Load array Bx{00}..{0f}, Bx{00}..{f0}
  160. vmovdqu xgft3_loy, [tmp+2*vec] ;Load array Cx{00}..{0f}, Cx{00}..{f0}
  161. vshufi64x2 xgft1_hi, xgft1_lo, xgft1_lo, 0x55
  162. vshufi64x2 xgft1_lo, xgft1_lo, xgft1_lo, 0x00
  163. vshufi64x2 xgft2_hi, xgft2_lo, xgft2_lo, 0x55
  164. vshufi64x2 xgft2_lo, xgft2_lo, xgft2_lo, 0x00
  165. vshufi64x2 xgft3_hi, xgft3_lo, xgft3_lo, 0x55
  166. vshufi64x2 xgft3_lo, xgft3_lo, xgft3_lo, 0x00
  167. mov dest2, [dest1+PS] ; reuse mul_array
  168. mov dest3, [dest1+2*PS] ; reuse vec_i
  169. mov dest1, [dest1]
  170. mov tmp, -1
  171. kmovq k1, tmp
  172. .loop64:
  173. XLDR x0, [src+pos] ;Get next source vector
  174. XLDR xd1, [dest1+pos] ;Get next dest vector
  175. XLDR xd2, [dest2+pos] ;Get next dest vector
  176. XLDR xd3, [dest3+pos] ;Get next dest vector
  177. vpandq xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  178. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  179. vpandq x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  180. ; dest1
  181. vpshufb xtmph1 {k1}{z}, xgft1_hi, x0 ;Lookup mul table of high nibble
  182. vpshufb xtmpl1 {k1}{z}, xgft1_lo, xtmpa ;Lookup mul table of low nibble
  183. vpxorq xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
  184. vpxorq xd1, xd1, xtmph1 ;xd1 += partial
  185. ; dest2
  186. vpshufb xtmph2 {k1}{z}, xgft2_hi, x0 ;Lookup mul table of high nibble
  187. vpshufb xtmpl2 {k1}{z}, xgft2_lo, xtmpa ;Lookup mul table of low nibble
  188. vpxorq xtmph2, xtmph2, xtmpl2 ;GF add high and low partials
  189. vpxorq xd2, xd2, xtmph2 ;xd2 += partial
  190. ; dest3
  191. vpshufb xtmph3 {k1}{z}, xgft3_hi, x0 ;Lookup mul table of high nibble
  192. vpshufb xtmpl3 {k1}{z}, xgft3_lo, xtmpa ;Lookup mul table of low nibble
  193. vpxorq xtmph3, xtmph3, xtmpl3 ;GF add high and low partials
  194. vpxorq xd3, xd3, xtmph3 ;xd2 += partial
  195. XSTR [dest1+pos], xd1
  196. XSTR [dest2+pos], xd2
  197. XSTR [dest3+pos], xd3
  198. add pos, 64 ;Loop on 64 bytes at a time
  199. cmp pos, len
  200. jle .loop64
  201. lea tmp, [len + 64]
  202. cmp pos, tmp
  203. je .return_pass
  204. ;; Tail len
  205. mov pos, (1 << 63)
  206. lea tmp, [len + 64 - 1]
  207. and tmp, 63
  208. sarx pos, pos, tmp
  209. kmovq k1, pos
  210. mov pos, len ;Overlapped offset length-64
  211. jmp .loop64 ;Do one more overlap pass
  212. .return_pass:
  213. mov return, 0
  214. FUNC_RESTORE
  215. ret
  216. .return_fail:
  217. mov return, 1
  218. FUNC_RESTORE
  219. ret
  220. endproc_frame
  221. %else
  222. %ifidn __OUTPUT_FORMAT__, win64
  223. global no_gf_3vect_mad_avx512
  224. no_gf_3vect_mad_avx512:
  225. %endif
  226. %endif ; ifdef HAVE_AS_KNOWS_AVX512