gf_3vect_mad_avx2.asm 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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_avx2(len, vec, vec_i, mul_array, src, dest);
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %define PS 8
  34. %ifidn __OUTPUT_FORMAT__, win64
  35. %define arg0 rcx
  36. %define arg0.w ecx
  37. %define arg1 rdx
  38. %define arg2 r8
  39. %define arg3 r9
  40. %define arg4 r12 ; must be saved, loaded and restored
  41. %define arg5 r15 ; must be saved and restored
  42. %define tmp r11
  43. %define tmp.w r11d
  44. %define tmp.b r11b
  45. %define return rax
  46. %define return.w eax
  47. %define stack_size 16*10 + 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. vmovdqa [rsp+16*3],xmm9
  56. vmovdqa [rsp+16*4],xmm10
  57. vmovdqa [rsp+16*5],xmm11
  58. vmovdqa [rsp+16*6],xmm12
  59. vmovdqa [rsp+16*7],xmm13
  60. vmovdqa [rsp+16*8],xmm14
  61. vmovdqa [rsp+16*9],xmm15
  62. save_reg r12, 10*16 + 0*8
  63. save_reg r15, 10*16 + 1*8
  64. end_prolog
  65. mov arg4, arg(4)
  66. mov arg5, arg(5)
  67. %endmacro
  68. %macro FUNC_RESTORE 0
  69. vmovdqa xmm6, [rsp+16*0]
  70. vmovdqa xmm7, [rsp+16*1]
  71. vmovdqa xmm8, [rsp+16*2]
  72. vmovdqa xmm9, [rsp+16*3]
  73. vmovdqa xmm10, [rsp+16*4]
  74. vmovdqa xmm11, [rsp+16*5]
  75. vmovdqa xmm12, [rsp+16*6]
  76. vmovdqa xmm13, [rsp+16*7]
  77. vmovdqa xmm14, [rsp+16*8]
  78. vmovdqa xmm15, [rsp+16*9]
  79. mov r12, [rsp + 10*16 + 0*8]
  80. mov r15, [rsp + 10*16 + 1*8]
  81. add rsp, stack_size
  82. %endmacro
  83. %elifidn __OUTPUT_FORMAT__, elf64
  84. %define arg0 rdi
  85. %define arg0.w edi
  86. %define arg1 rsi
  87. %define arg2 rdx
  88. %define arg3 rcx
  89. %define arg4 r8
  90. %define arg5 r9
  91. %define tmp r11
  92. %define tmp.w r11d
  93. %define tmp.b r11b
  94. %define return rax
  95. %define return.w eax
  96. %define func(x) x:
  97. %define FUNC_SAVE
  98. %define FUNC_RESTORE
  99. %endif
  100. ;;; gf_3vect_mad_avx2(len, vec, vec_i, mul_array, src, dest)
  101. %define len arg0
  102. %define len.w arg0.w
  103. %define vec arg1
  104. %define vec_i arg2
  105. %define mul_array arg3
  106. %define src arg4
  107. %define dest1 arg5
  108. %define pos return
  109. %define pos.w return.w
  110. %define dest2 mul_array
  111. %define dest3 vec_i
  112. %ifndef EC_ALIGNED_ADDR
  113. ;;; Use Un-aligned load/store
  114. %define XLDR vmovdqu
  115. %define XSTR vmovdqu
  116. %else
  117. ;;; Use Non-temporal load/stor
  118. %ifdef NO_NT_LDST
  119. %define XLDR vmovdqa
  120. %define XSTR vmovdqa
  121. %else
  122. %define XLDR vmovntdqa
  123. %define XSTR vmovntdq
  124. %endif
  125. %endif
  126. default rel
  127. [bits 64]
  128. section .text
  129. %define xmask0f ymm15
  130. %define xmask0fx xmm15
  131. %define xgft1_lo ymm14
  132. %define xgft1_hi ymm13
  133. %define xgft2_lo ymm12
  134. %define xgft3_lo ymm11
  135. %define x0 ymm0
  136. %define xtmpa ymm1
  137. %define xtmph1 ymm2
  138. %define xtmpl1 ymm3
  139. %define xtmph2 ymm4
  140. %define xtmpl2 ymm5
  141. %define xtmpl2x xmm5
  142. %define xtmph3 ymm6
  143. %define xtmpl3 ymm7
  144. %define xtmpl3x xmm7
  145. %define xd1 ymm8
  146. %define xd2 ymm9
  147. %define xd3 ymm10
  148. align 16
  149. global gf_3vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  150. func(gf_3vect_mad_avx2)
  151. %ifidn __OUTPUT_FORMAT__, macho64
  152. global _gf_3vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  153. func(_gf_3vect_mad_avx2)
  154. %endif
  155. FUNC_SAVE
  156. sub len, 32
  157. jl .return_fail
  158. xor pos, pos
  159. mov tmp.b, 0x0f
  160. vpinsrb xmask0fx, xmask0fx, tmp.w, 0
  161. vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
  162. sal vec_i, 5 ;Multiply by 32
  163. sal vec, 5
  164. lea tmp, [mul_array + vec_i]
  165. vmovdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
  166. ; " Ax{00}, Ax{10}, ..., Ax{f0}
  167. vperm2i128 xgft1_hi, xgft1_lo, xgft1_lo, 0x11 ; swapped to hi | hi
  168. vperm2i128 xgft1_lo, xgft1_lo, xgft1_lo, 0x00 ; swapped to lo | lo
  169. vmovdqu xgft2_lo, [tmp+vec] ;Load array Bx{00}, Bx{01}, Bx{02}, ...
  170. ; " Bx{00}, Bx{10}, Bx{20}, ... , Bx{f0}
  171. vmovdqu xgft3_lo, [tmp+2*vec] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  172. ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  173. mov dest2, [dest1+PS] ; reuse mul_array
  174. mov dest3, [dest1+2*PS] ; reuse vec_i
  175. mov dest1, [dest1]
  176. .loop32:
  177. XLDR x0, [src+pos] ;Get next source vector
  178. XLDR xd1, [dest1+pos] ;Get next dest vector
  179. XLDR xd2, [dest2+pos] ;Get next dest vector
  180. XLDR xd3, [dest3+pos] ;Get next dest vector
  181. vperm2i128 xtmph2, xgft2_lo, xgft2_lo, 0x11 ; swapped to hi | hi
  182. vperm2i128 xtmpl2, xgft2_lo, xgft2_lo, 0x00 ; swapped to lo | lo
  183. vperm2i128 xtmph3, xgft3_lo, xgft3_lo, 0x11 ; swapped to hi | hi
  184. vperm2i128 xtmpl3, xgft3_lo, xgft3_lo, 0x00 ; swapped to lo | lo
  185. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  186. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  187. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  188. ; dest1
  189. vpshufb xtmph1, xgft1_hi, x0 ;Lookup mul table of high nibble
  190. vpshufb xtmpl1, xgft1_lo, xtmpa ;Lookup mul table of low nibble
  191. vpxor xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
  192. vpxor xd1, xd1, xtmph1 ;xd1 += partial
  193. ; dest2
  194. vpshufb xtmph2, x0 ;Lookup mul table of high nibble
  195. vpshufb xtmpl2, xtmpa ;Lookup mul table of low nibble
  196. vpxor xtmph2, xtmpl2 ;GF add high and low partials
  197. vpxor xd2, xtmph2 ;xd2 += partial
  198. ; dest3
  199. vpshufb xtmph3, x0 ;Lookup mul table of high nibble
  200. vpshufb xtmpl3, xtmpa ;Lookup mul table of low nibble
  201. vpxor xtmph3, xtmpl3 ;GF add high and low partials
  202. vpxor xd3, xtmph3 ;xd3 += partial
  203. XSTR [dest1+pos], xd1
  204. XSTR [dest2+pos], xd2
  205. XSTR [dest3+pos], xd3
  206. add pos, 32 ;Loop on 32 bytes at a time
  207. cmp pos, len
  208. jle .loop32
  209. lea tmp, [len + 32]
  210. cmp pos, tmp
  211. je .return_pass
  212. .lessthan32:
  213. ;; Tail len
  214. ;; Do one more overlap pass
  215. mov tmp.b, 0x1f
  216. vpinsrb xtmpl2x, xtmpl2x, tmp.w, 0
  217. vpbroadcastb xtmpl2, xtmpl2x ;Construct mask 0x1f1f1f...
  218. mov tmp, len ;Overlapped offset length-32
  219. XLDR x0, [src+tmp] ;Get next source vector
  220. XLDR xd1, [dest1+tmp] ;Get next dest vector
  221. XLDR xd2, [dest2+tmp] ;Get next dest vector
  222. XLDR xd3, [dest3+tmp] ;Get next dest vector
  223. sub len, pos
  224. vmovdqa xtmph3, [constip32] ;Load const of i + 32
  225. vpinsrb xtmpl3x, xtmpl3x, len.w, 15
  226. vinserti128 xtmpl3, xtmpl3, xtmpl3x, 1 ;swapped to xtmpl3x | xtmpl3x
  227. vpshufb xtmpl3, xtmpl3, xtmpl2 ;Broadcast len to all bytes. xtmpl2=0x1f1f1f...
  228. vpcmpgtb xtmpl3, xtmpl3, xtmph3
  229. vperm2i128 xtmph2, xgft2_lo, xgft2_lo, 0x11 ; swapped to hi | hi
  230. vperm2i128 xgft2_lo, xgft2_lo, xgft2_lo, 0x00 ; swapped to lo | lo
  231. vperm2i128 xtmph3, xgft3_lo, xgft3_lo, 0x11 ; swapped to hi | hi
  232. vperm2i128 xgft3_lo, xgft3_lo, xgft3_lo, 0x00 ; swapped to lo | lo
  233. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  234. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  235. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  236. ; dest1
  237. vpshufb xtmph1, xgft1_hi, x0 ;Lookup mul table of high nibble
  238. vpshufb xtmpl1, xgft1_lo, xtmpa ;Lookup mul table of low nibble
  239. vpxor xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
  240. vpand xtmph1, xtmph1, xtmpl3
  241. vpxor xd1, xd1, xtmph1 ;xd1 += partial
  242. ; dest2
  243. vpshufb xtmph2, xtmph2, x0 ;Lookup mul table of high nibble
  244. vpshufb xgft2_lo, xgft2_lo, xtmpa ;Lookup mul table of low nibble
  245. vpxor xtmph2, xtmph2, xgft2_lo ;GF add high and low partials
  246. vpand xtmph2, xtmph2, xtmpl3
  247. vpxor xd2, xd2, xtmph2 ;xd2 += partial
  248. ; dest3
  249. vpshufb xtmph3, xtmph3, x0 ;Lookup mul table of high nibble
  250. vpshufb xgft3_lo, xgft3_lo, xtmpa ;Lookup mul table of low nibble
  251. vpxor xtmph3, xtmph3, xgft3_lo ;GF add high and low partials
  252. vpand xtmph3, xtmph3, xtmpl3
  253. vpxor xd3, xd3, xtmph3 ;xd3 += partial
  254. XSTR [dest1+tmp], xd1
  255. XSTR [dest2+tmp], xd2
  256. XSTR [dest3+tmp], xd3
  257. .return_pass:
  258. mov return, 0
  259. FUNC_RESTORE
  260. ret
  261. .return_fail:
  262. mov return, 1
  263. FUNC_RESTORE
  264. ret
  265. endproc_frame
  266. section .data
  267. align 32
  268. constip32:
  269. dq 0xf8f9fafbfcfdfeff, 0xf0f1f2f3f4f5f6f7
  270. dq 0xe8e9eaebecedeeef, 0xe0e1e2e3e4e5e6e7
  271. ;;; func core, ver, snum
  272. slversion gf_3vect_mad_avx2, 04, 01, 0208