gf_4vect_mad_avx2.asm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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_4vect_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
  41. %define arg5 r15
  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. movdqa [rsp+16*0],xmm6
  53. movdqa [rsp+16*1],xmm7
  54. movdqa [rsp+16*2],xmm8
  55. movdqa [rsp+16*3],xmm9
  56. movdqa [rsp+16*4],xmm10
  57. movdqa [rsp+16*5],xmm11
  58. movdqa [rsp+16*6],xmm12
  59. movdqa [rsp+16*7],xmm13
  60. movdqa [rsp+16*8],xmm14
  61. movdqa [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. movdqa xmm6, [rsp+16*0]
  70. movdqa xmm7, [rsp+16*1]
  71. movdqa xmm8, [rsp+16*2]
  72. movdqa xmm9, [rsp+16*3]
  73. movdqa xmm10, [rsp+16*4]
  74. movdqa xmm11, [rsp+16*5]
  75. movdqa xmm12, [rsp+16*6]
  76. movdqa xmm13, [rsp+16*7]
  77. movdqa xmm14, [rsp+16*8]
  78. movdqa 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_4vect_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
  112. %define dest4 vec_i
  113. %ifndef EC_ALIGNED_ADDR
  114. ;;; Use Un-aligned load/store
  115. %define XLDR vmovdqu
  116. %define XSTR vmovdqu
  117. %else
  118. ;;; Use Non-temporal load/stor
  119. %ifdef NO_NT_LDST
  120. %define XLDR vmovdqa
  121. %define XSTR vmovdqa
  122. %else
  123. %define XLDR vmovntdqa
  124. %define XSTR vmovntdq
  125. %endif
  126. %endif
  127. default rel
  128. [bits 64]
  129. section .text
  130. %define xmask0f ymm15
  131. %define xmask0fx xmm15
  132. %define xgft1_lo ymm14
  133. %define xgft2_lo ymm13
  134. %define xgft3_lo ymm12
  135. %define xgft4_lo ymm11
  136. %define x0 ymm0
  137. %define xtmpa ymm1
  138. %define xtmpl ymm2
  139. %define xtmplx xmm2
  140. %define xtmph1 ymm3
  141. %define xtmph1x xmm3
  142. %define xtmph2 ymm4
  143. %define xtmph3 ymm5
  144. %define xtmph4 ymm6
  145. %define xd1 ymm7
  146. %define xd2 ymm8
  147. %define xd3 ymm9
  148. %define xd4 ymm10
  149. align 16
  150. global gf_4vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  151. func(gf_4vect_mad_avx2)
  152. %ifidn __OUTPUT_FORMAT__, macho64
  153. global _gf_4vect_mad_avx2:ISAL_SYM_TYPE_FUNCTION
  154. func(_gf_4vect_mad_avx2)
  155. %endif
  156. FUNC_SAVE
  157. sub len, 32
  158. jl .return_fail
  159. xor pos, pos
  160. mov tmp.b, 0x0f
  161. vpinsrb xmask0fx, xmask0fx, tmp.w, 0
  162. vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
  163. sal vec_i, 5 ;Multiply by 32
  164. sal vec, 5 ;Multiply by 32
  165. lea tmp, [mul_array + vec_i]
  166. vmovdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, Ax{02}, ...
  167. ; " Ax{00}, Ax{10}, Ax{20}, ... , Ax{f0}
  168. vmovdqu xgft2_lo, [tmp+vec] ;Load array Bx{00}, Bx{01}, Bx{02}, ...
  169. ; " Bx{00}, Bx{10}, Bx{20}, ... , Bx{f0}
  170. vmovdqu xgft3_lo, [tmp+2*vec] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  171. ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  172. add tmp, vec
  173. vmovdqu xgft4_lo, [tmp+2*vec] ;Load array Dx{00}, Dx{01}, Dx{02}, ...
  174. ; " Dx{00}, Dx{10}, Dx{20}, ... , Dx{f0}
  175. mov dest2, [dest1+PS] ; reuse mul_array
  176. mov dest3, [dest1+2*PS] ; reuse vec
  177. mov dest4, [dest1+3*PS] ; reuse vec_i
  178. mov dest1, [dest1]
  179. .loop32:
  180. XLDR x0, [src+pos] ;Get next source vector
  181. XLDR xd1, [dest1+pos] ;Get next dest vector
  182. XLDR xd2, [dest2+pos] ;Get next dest vector
  183. XLDR xd3, [dest3+pos] ;Get next dest vector
  184. XLDR xd4, [dest4+pos] ;reuse xtmpl1. Get next dest vector
  185. vpand xtmpl, 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. vperm2i128 xtmpa, xtmpl, x0, 0x30 ;swap xtmpa from 1lo|2lo to 1lo|2hi
  189. vperm2i128 x0, xtmpl, x0, 0x12 ;swap x0 from 1hi|2hi to 1hi|2lo
  190. vperm2i128 xtmph1, xgft1_lo, xgft1_lo, 0x01 ; swapped to hi | lo
  191. vperm2i128 xtmph2, xgft2_lo, xgft2_lo, 0x01 ; swapped to hi | lo
  192. vperm2i128 xtmph3, xgft3_lo, xgft3_lo, 0x01 ; swapped to hi | lo
  193. vperm2i128 xtmph4, xgft4_lo, xgft4_lo, 0x01 ; swapped to hi | lo
  194. ; dest1
  195. vpshufb xtmph1, xtmph1, x0 ;Lookup mul table of high nibble
  196. vpshufb xtmpl, xgft1_lo, xtmpa ;Lookup mul table of low nibble
  197. vpxor xtmph1, xtmph1, xtmpl ;GF add high and low partials
  198. vpxor xd1, xd1, xtmph1 ;xd1 += partial
  199. ; dest2
  200. vpshufb xtmph2, xtmph2, x0 ;Lookup mul table of high nibble
  201. vpshufb xtmpl, xgft2_lo, xtmpa ;Lookup mul table of low nibble
  202. vpxor xtmph2, xtmph2, xtmpl ;GF add high and low partials
  203. vpxor xd2, xd2, xtmph2 ;xd2 += partial
  204. ; dest3
  205. vpshufb xtmph3, xtmph3, x0 ;Lookup mul table of high nibble
  206. vpshufb xtmpl, xgft3_lo, xtmpa ;Lookup mul table of low nibble
  207. vpxor xtmph3, xtmph3, xtmpl ;GF add high and low partials
  208. vpxor xd3, xd3, xtmph3 ;xd3 += partial
  209. ; dest4
  210. vpshufb xtmph4, xtmph4, x0 ;Lookup mul table of high nibble
  211. vpshufb xtmpl, xgft4_lo, xtmpa ;Lookup mul table of low nibble
  212. vpxor xtmph4, xtmph4, xtmpl ;GF add high and low partials
  213. vpxor xd4, xd4, xtmph4 ;xd4 += partial
  214. XSTR [dest1+pos], xd1
  215. XSTR [dest2+pos], xd2
  216. XSTR [dest3+pos], xd3
  217. XSTR [dest4+pos], xd4
  218. add pos, 32 ;Loop on 32 bytes at a time
  219. cmp pos, len
  220. jle .loop32
  221. lea tmp, [len + 32]
  222. cmp pos, tmp
  223. je .return_pass
  224. .lessthan32:
  225. ;; Tail len
  226. ;; Do one more overlap pass
  227. mov tmp.b, 0x1f
  228. vpinsrb xtmph1x, xtmph1x, tmp.w, 0
  229. vpbroadcastb xtmph1, xtmph1x ;Construct mask 0x1f1f1f...
  230. mov tmp, len ;Overlapped offset length-32
  231. XLDR x0, [src+tmp] ;Get next source vector
  232. XLDR xd1, [dest1+tmp] ;Get next dest vector
  233. XLDR xd2, [dest2+tmp] ;Get next dest vector
  234. XLDR xd3, [dest3+tmp] ;Get next dest vector
  235. XLDR xd4, [dest4+tmp] ;Get next dest vector
  236. sub len, pos
  237. vmovdqa xtmph2, [constip32] ;Load const of i + 32
  238. vpinsrb xtmplx, xtmplx, len.w, 15
  239. vinserti128 xtmpl, xtmpl, xtmplx, 1 ;swapped to xtmplx | xtmplx
  240. vpshufb xtmpl, xtmpl, xtmph1 ;Broadcast len to all bytes. xtmph1=0x1f1f1f...
  241. vpcmpgtb xtmpl, xtmpl, xtmph2
  242. vpand xtmph1, x0, xmask0f ;Mask low src nibble in bits 4-0
  243. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  244. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  245. vperm2i128 xtmpa, xtmph1, x0, 0x30 ;swap xtmpa from 1lo|2lo to 1lo|2hi
  246. vperm2i128 x0, xtmph1, x0, 0x12 ;swap x0 from 1hi|2hi to 1hi|2lo
  247. vperm2i128 xtmph1, xgft1_lo, xgft1_lo, 0x01 ; swapped to hi | lo
  248. vperm2i128 xtmph2, xgft2_lo, xgft2_lo, 0x01 ; swapped to hi | lo
  249. vperm2i128 xtmph3, xgft3_lo, xgft3_lo, 0x01 ; swapped to hi | lo
  250. vperm2i128 xtmph4, xgft4_lo, xgft4_lo, 0x01 ; swapped to hi | lo
  251. ; dest1
  252. vpshufb xtmph1, xtmph1, x0 ;Lookup mul table of high nibble
  253. vpshufb xgft1_lo, xgft1_lo, xtmpa ;Lookup mul table of low nibble
  254. vpxor xtmph1, xtmph1, xgft1_lo ;GF add high and low partials
  255. vpand xtmph1, xtmph1, xtmpl
  256. vpxor xd1, xd1, xtmph1 ;xd1 += partial
  257. ; dest2
  258. vpshufb xtmph2, xtmph2, x0 ;Lookup mul table of high nibble
  259. vpshufb xgft2_lo, xgft2_lo, xtmpa ;Lookup mul table of low nibble
  260. vpxor xtmph2, xtmph2, xgft2_lo ;GF add high and low partials
  261. vpand xtmph2, xtmph2, xtmpl
  262. vpxor xd2, xd2, xtmph2 ;xd2 += partial
  263. ; dest3
  264. vpshufb xtmph3, xtmph3, x0 ;Lookup mul table of high nibble
  265. vpshufb xgft3_lo, xgft3_lo, xtmpa ;Lookup mul table of low nibble
  266. vpxor xtmph3, xtmph3, xgft3_lo ;GF add high and low partials
  267. vpand xtmph3, xtmph3, xtmpl
  268. vpxor xd3, xd3, xtmph3 ;xd3 += partial
  269. ; dest4
  270. vpshufb xtmph4, xtmph4, x0 ;Lookup mul table of high nibble
  271. vpshufb xgft4_lo, xgft4_lo, xtmpa ;Lookup mul table of low nibble
  272. vpxor xtmph4, xtmph4, xgft4_lo ;GF add high and low partials
  273. vpand xtmph4, xtmph4, xtmpl
  274. vpxor xd4, xd4, xtmph4 ;xd4 += partial
  275. XSTR [dest1+tmp], xd1
  276. XSTR [dest2+tmp], xd2
  277. XSTR [dest3+tmp], xd3
  278. XSTR [dest4+tmp], xd4
  279. .return_pass:
  280. mov return, 0
  281. FUNC_RESTORE
  282. ret
  283. .return_fail:
  284. mov return, 1
  285. FUNC_RESTORE
  286. ret
  287. endproc_frame
  288. section .data
  289. align 32
  290. constip32:
  291. dq 0xf8f9fafbfcfdfeff, 0xf0f1f2f3f4f5f6f7
  292. dq 0xe8e9eaebecedeeef, 0xe0e1e2e3e4e5e6e7
  293. ;;; func core, ver, snum
  294. slversion gf_4vect_mad_avx2, 04, 01, 020b