gf_5vect_mad_avx.asm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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_5vect_mad_avx(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 tmp2 r10
  44. %define tmp3 r13
  45. %define tmp4 r14
  46. %define return rax
  47. %define return.w eax
  48. %define stack_size 16*10 + 5*8
  49. %define arg(x) [rsp + stack_size + PS + PS*x]
  50. %define func(x) proc_frame x
  51. %macro FUNC_SAVE 0
  52. sub rsp, stack_size
  53. movdqa [rsp+16*0],xmm6
  54. movdqa [rsp+16*1],xmm7
  55. movdqa [rsp+16*2],xmm8
  56. movdqa [rsp+16*3],xmm9
  57. movdqa [rsp+16*4],xmm10
  58. movdqa [rsp+16*5],xmm11
  59. movdqa [rsp+16*6],xmm12
  60. movdqa [rsp+16*7],xmm13
  61. movdqa [rsp+16*8],xmm14
  62. movdqa [rsp+16*9],xmm15
  63. save_reg r12, 10*16 + 0*8
  64. save_reg r13, 10*16 + 1*8
  65. save_reg r14, 10*16 + 2*8
  66. save_reg r15, 10*16 + 3*8
  67. end_prolog
  68. mov arg4, arg(4)
  69. mov arg5, arg(5)
  70. %endmacro
  71. %macro FUNC_RESTORE 0
  72. movdqa xmm6, [rsp+16*0]
  73. movdqa xmm7, [rsp+16*1]
  74. movdqa xmm8, [rsp+16*2]
  75. movdqa xmm9, [rsp+16*3]
  76. movdqa xmm10, [rsp+16*4]
  77. movdqa xmm11, [rsp+16*5]
  78. movdqa xmm12, [rsp+16*6]
  79. movdqa xmm13, [rsp+16*7]
  80. movdqa xmm14, [rsp+16*8]
  81. movdqa xmm15, [rsp+16*9]
  82. mov r12, [rsp + 10*16 + 0*8]
  83. mov r13, [rsp + 10*16 + 1*8]
  84. mov r14, [rsp + 10*16 + 2*8]
  85. mov r15, [rsp + 10*16 + 3*8]
  86. add rsp, stack_size
  87. %endmacro
  88. %elifidn __OUTPUT_FORMAT__, elf64
  89. %define arg0 rdi
  90. %define arg0.w edi
  91. %define arg1 rsi
  92. %define arg2 rdx
  93. %define arg3 rcx
  94. %define arg4 r8
  95. %define arg5 r9
  96. %define tmp r11
  97. %define tmp2 r10
  98. %define tmp3 r12
  99. %define tmp4 r13
  100. %define return rax
  101. %define return.w eax
  102. %define func(x) x: endbranch
  103. %macro FUNC_SAVE 0
  104. push r12
  105. push r13
  106. %endmacro
  107. %macro FUNC_RESTORE 0
  108. pop r13
  109. pop r12
  110. %endmacro
  111. %endif
  112. ;;; gf_5vect_mad_avx(len, vec, vec_i, mul_array, src, dest)
  113. %define len arg0
  114. %define len.w arg0.w
  115. %define vec arg1
  116. %define vec_i arg2
  117. %define mul_array arg3
  118. %define src arg4
  119. %define dest1 arg5
  120. %define pos return
  121. %define pos.w return.w
  122. %define dest2 tmp4
  123. %define dest3 mul_array
  124. %define dest4 tmp2
  125. %define dest5 vec_i
  126. %ifndef EC_ALIGNED_ADDR
  127. ;;; Use Un-aligned load/store
  128. %define XLDR vmovdqu
  129. %define XSTR vmovdqu
  130. %else
  131. ;;; Use Non-temporal load/stor
  132. %ifdef NO_NT_LDST
  133. %define XLDR vmovdqa
  134. %define XSTR vmovdqa
  135. %else
  136. %define XLDR vmovntdqa
  137. %define XSTR vmovntdq
  138. %endif
  139. %endif
  140. default rel
  141. [bits 64]
  142. section .text
  143. %define xmask0f xmm15
  144. %define xgft5_hi xmm14
  145. %define xgft4_lo xmm13
  146. %define xgft4_hi xmm12
  147. %define x0 xmm0
  148. %define xtmpa xmm1
  149. %define xtmph1 xmm2
  150. %define xtmpl1 xmm3
  151. %define xtmph2 xmm4
  152. %define xtmpl2 xmm5
  153. %define xtmph3 xmm6
  154. %define xtmpl3 xmm7
  155. %define xtmph5 xmm8
  156. %define xtmpl5 xmm9
  157. %define xd1 xmm10
  158. %define xd2 xmm11
  159. %define xd3 xtmpl1
  160. %define xd4 xtmph1
  161. %define xd5 xtmpl2
  162. align 16
  163. global gf_5vect_mad_avx, function
  164. func(gf_5vect_mad_avx)
  165. FUNC_SAVE
  166. sub len, 16
  167. jl .return_fail
  168. xor pos, pos
  169. vmovdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  170. mov tmp, vec
  171. sal vec_i, 5 ;Multiply by 32
  172. lea tmp3, [mul_array + vec_i]
  173. sal tmp, 6 ;Multiply by 64
  174. vmovdqu xgft5_hi, [tmp3+2*tmp+16] ; " Ex{00}, Ex{10}, ..., Ex{f0}
  175. sal vec, 5 ;Multiply by 32
  176. add tmp, vec
  177. vmovdqu xgft4_hi, [tmp3+tmp+16] ; " Dx{00}, Dx{10}, Dx{20}, ... , Dx{f0}
  178. vmovdqu xgft4_lo, [tmp3+tmp] ;Load array Dx{00}, Dx{01}, Dx{02}, ...
  179. mov dest3, [dest1+2*PS] ; reuse mul_array
  180. mov dest4, [dest1+3*PS]
  181. mov dest5, [dest1+4*PS] ; reuse vec_i
  182. mov dest2, [dest1+PS]
  183. mov dest1, [dest1]
  184. .loop16:
  185. XLDR x0, [src+pos] ;Get next source vector
  186. vmovdqu xtmph1, [tmp3+16] ; " Ax{00}, Ax{10}, Ax{20}, ... , Ax{f0}
  187. vmovdqu xtmpl1, [tmp3] ;Load array Ax{00}, Ax{01}, Ax{02}, ...
  188. vmovdqu xtmph2, [tmp3+vec+16] ; " Bx{00}, Bx{10}, Bx{20}, ... , Bx{f0}
  189. vmovdqu xtmpl2, [tmp3+vec] ;Load array Bx{00}, Bx{01}, Bx{02}, ...
  190. vmovdqu xtmph3, [tmp3+2*vec+16] ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  191. vmovdqu xtmpl3, [tmp3+2*vec] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  192. vmovdqu xtmpl5, [tmp3+4*vec] ;Load array Ex{00}, Ex{01}, ..., Ex{0f}
  193. XLDR xd1, [dest1+pos] ;Get next dest vector
  194. XLDR xd2, [dest2+pos] ;Get next dest vector
  195. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  196. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  197. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  198. ; dest1
  199. vpshufb xtmph1, xtmph1, x0 ;Lookup mul table of high nibble
  200. vpshufb xtmpl1, xtmpl1, xtmpa ;Lookup mul table of low nibble
  201. vpxor xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
  202. vpxor xd1, xd1, xtmph1
  203. XLDR xd3, [dest3+pos] ;Reuse xtmpl1, Get next dest vector
  204. XLDR xd4, [dest4+pos] ;Reuse xtmph1, Get next dest vector
  205. ; dest2
  206. vpshufb xtmph2, xtmph2, x0 ;Lookup mul table of high nibble
  207. vpshufb xtmpl2, xtmpl2, xtmpa ;Lookup mul table of low nibble
  208. vpxor xtmph2, xtmph2, xtmpl2 ;GF add high and low partials
  209. vpxor xd2, xd2, xtmph2
  210. XLDR xd5, [dest5+pos] ;Reuse xtmpl2. Get next dest vector
  211. ; dest3
  212. vpshufb xtmph3, xtmph3, x0 ;Lookup mul table of high nibble
  213. vpshufb xtmpl3, xtmpl3, xtmpa ;Lookup mul table of low nibble
  214. vpxor xtmph3, xtmph3, xtmpl3 ;GF add high and low partials
  215. vpxor xd3, xd3, xtmph3
  216. ; dest4
  217. vpshufb xtmph2, xgft4_hi, x0 ;Lookup mul table of high nibble
  218. vpshufb xtmpl3, xgft4_lo, xtmpa ;Lookup mul table of low nibble
  219. vpxor xtmph2, xtmph2, xtmpl3 ;GF add high and low partials
  220. vpxor xd4, xd4, xtmph2
  221. ; dest5
  222. vpshufb xtmph5, xgft5_hi, x0 ;Lookup mul table of high nibble
  223. vpshufb xtmpl5, xtmpl5, xtmpa ;Lookup mul table of low nibble
  224. vpxor xtmph5, xtmph5, xtmpl5 ;GF add high and low partials
  225. vpxor xd5, xd5, xtmph5
  226. XSTR [dest1+pos], xd1 ;Store result into dest1
  227. XSTR [dest2+pos], xd2 ;Store result into dest2
  228. XSTR [dest3+pos], xd3 ;Store result into dest3
  229. XSTR [dest4+pos], xd4 ;Store result into dest4
  230. XSTR [dest5+pos], xd5 ;Store result into dest5
  231. add pos, 16 ;Loop on 16 bytes at a time
  232. cmp pos, len
  233. jle .loop16
  234. lea tmp, [len + 16]
  235. cmp pos, tmp
  236. je .return_pass
  237. .lessthan16:
  238. ;; Tail len
  239. ;; Do one more overlap pass
  240. mov tmp, len ;Overlapped offset length-16
  241. XLDR x0, [src+tmp] ;Get next source vector
  242. sub len, pos
  243. vmovdqa xtmph1, [constip16] ;Load const of i + 16
  244. vpinsrb xtmph5, len.w, 15
  245. vpshufb xtmph5, xmask0f ;Broadcast len to all bytes
  246. vpcmpgtb xtmph5, xtmph5, xtmph1
  247. vmovdqu xtmph1, [tmp3+16] ; " Ax{00}, Ax{10}, Ax{20}, ... , Ax{f0}
  248. vmovdqu xtmpl1, [tmp3] ;Load array Ax{00}, Ax{01}, Ax{02}, ...
  249. vmovdqu xtmph2, [tmp3+vec+16] ; " Bx{00}, Bx{10}, Bx{20}, ... , Bx{f0}
  250. vmovdqu xtmpl2, [tmp3+vec] ;Load array Bx{00}, Bx{01}, Bx{02}, ...
  251. vmovdqu xtmph3, [tmp3+2*vec+16] ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  252. vmovdqu xtmpl3, [tmp3+2*vec] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  253. vmovdqu xtmpl5, [tmp3+4*vec] ;Load array Ex{00}, Ex{01}, ..., Ex{0f}
  254. XLDR xd1, [dest1+tmp] ;Get next dest vector
  255. XLDR xd2, [dest2+tmp] ;Get next dest vector
  256. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  257. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  258. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  259. ; dest1
  260. vpshufb xtmph1, xtmph1, x0 ;Lookup mul table of high nibble
  261. vpshufb xtmpl1, xtmpl1, xtmpa ;Lookup mul table of low nibble
  262. vpxor xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
  263. vpand xtmph1, xtmph1, xtmph5
  264. vpxor xd1, xd1, xtmph1
  265. XLDR xd3, [dest3+tmp] ;Reuse xtmpl1, Get next dest vector
  266. XLDR xd4, [dest4+tmp] ;Reuse xtmph1, Get next dest vector
  267. ; dest2
  268. vpshufb xtmph2, xtmph2, x0 ;Lookup mul table of high nibble
  269. vpshufb xtmpl2, xtmpl2, xtmpa ;Lookup mul table of low nibble
  270. vpxor xtmph2, xtmph2, xtmpl2 ;GF add high and low partials
  271. vpand xtmph2, xtmph2, xtmph5
  272. vpxor xd2, xd2, xtmph2
  273. XLDR xd5, [dest5+tmp] ;Reuse xtmpl2. Get next dest vector
  274. ; dest3
  275. vpshufb xtmph3, xtmph3, x0 ;Lookup mul table of high nibble
  276. vpshufb xtmpl3, xtmpl3, xtmpa ;Lookup mul table of low nibble
  277. vpxor xtmph3, xtmph3, xtmpl3 ;GF add high and low partials
  278. vpand xtmph3, xtmph3, xtmph5
  279. vpxor xd3, xd3, xtmph3
  280. ; dest4
  281. vpshufb xgft4_hi, xgft4_hi, x0 ;Lookup mul table of high nibble
  282. vpshufb xgft4_lo, xgft4_lo, xtmpa ;Lookup mul table of low nibble
  283. vpxor xgft4_hi, xgft4_hi, xgft4_lo ;GF add high and low partials
  284. vpand xgft4_hi, xgft4_hi, xtmph5
  285. vpxor xd4, xd4, xgft4_hi
  286. ; dest5
  287. vpshufb xgft5_hi, xgft5_hi, x0 ;Lookup mul table of high nibble
  288. vpshufb xtmpl5, xtmpl5, xtmpa ;Lookup mul table of low nibble
  289. vpxor xgft5_hi, xgft5_hi, xtmpl5 ;GF add high and low partials
  290. vpand xgft5_hi, xgft5_hi, xtmph5
  291. vpxor xd5, xd5, xgft5_hi
  292. XSTR [dest1+tmp], xd1 ;Store result into dest1
  293. XSTR [dest2+tmp], xd2 ;Store result into dest2
  294. XSTR [dest3+tmp], xd3 ;Store result into dest3
  295. XSTR [dest4+tmp], xd4 ;Store result into dest4
  296. XSTR [dest5+tmp], xd5 ;Store result into dest5
  297. .return_pass:
  298. FUNC_RESTORE
  299. mov return, 0
  300. ret
  301. .return_fail:
  302. FUNC_RESTORE
  303. mov return, 1
  304. ret
  305. endproc_frame
  306. section .data
  307. align 16
  308. mask0f: dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
  309. constip16:
  310. dq 0xf8f9fafbfcfdfeff, 0xf0f1f2f3f4f5f6f7