gf_5vect_dot_prod_sse.asm 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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_dot_prod_sse(len, vec, *g_tbls, **buffs, **dests);
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %ifidn __OUTPUT_FORMAT__, elf64
  34. %define arg0 rdi
  35. %define arg1 rsi
  36. %define arg2 rdx
  37. %define arg3 rcx
  38. %define arg4 r8
  39. %define arg5 r9
  40. %define tmp r11
  41. %define tmp2 r10
  42. %define tmp3 r13 ; must be saved and restored
  43. %define tmp4 r12 ; must be saved and restored
  44. %define tmp5 r14 ; must be saved and restored
  45. %define tmp6 r15 ; must be saved and restored
  46. %define return rax
  47. %define PS 8
  48. %define LOG_PS 3
  49. %define func(x) x:
  50. %macro FUNC_SAVE 0
  51. push r12
  52. push r13
  53. push r14
  54. push r15
  55. %endmacro
  56. %macro FUNC_RESTORE 0
  57. pop r15
  58. pop r14
  59. pop r13
  60. pop r12
  61. %endmacro
  62. %endif
  63. %ifidn __OUTPUT_FORMAT__, win64
  64. %define arg0 rcx
  65. %define arg1 rdx
  66. %define arg2 r8
  67. %define arg3 r9
  68. %define arg4 r12 ; must be saved, loaded and restored
  69. %define arg5 r15 ; must be saved and restored
  70. %define tmp r11
  71. %define tmp2 r10
  72. %define tmp3 r13 ; must be saved and restored
  73. %define tmp4 r14 ; must be saved and restored
  74. %define tmp5 rdi ; must be saved and restored
  75. %define tmp6 rsi ; must be saved and restored
  76. %define return rax
  77. %define PS 8
  78. %define LOG_PS 3
  79. %define stack_size 10*16 + 7*8 ; must be an odd multiple of 8
  80. %define arg(x) [rsp + stack_size + PS + PS*x]
  81. %define func(x) proc_frame x
  82. %macro FUNC_SAVE 0
  83. alloc_stack stack_size
  84. save_xmm128 xmm6, 0*16
  85. save_xmm128 xmm7, 1*16
  86. save_xmm128 xmm8, 2*16
  87. save_xmm128 xmm9, 3*16
  88. save_xmm128 xmm10, 4*16
  89. save_xmm128 xmm11, 5*16
  90. save_xmm128 xmm12, 6*16
  91. save_xmm128 xmm13, 7*16
  92. save_xmm128 xmm14, 8*16
  93. save_xmm128 xmm15, 9*16
  94. save_reg r12, 10*16 + 0*8
  95. save_reg r13, 10*16 + 1*8
  96. save_reg r14, 10*16 + 2*8
  97. save_reg r15, 10*16 + 3*8
  98. save_reg rdi, 10*16 + 4*8
  99. save_reg rsi, 10*16 + 5*8
  100. end_prolog
  101. mov arg4, arg(4)
  102. %endmacro
  103. %macro FUNC_RESTORE 0
  104. movdqa xmm6, [rsp + 0*16]
  105. movdqa xmm7, [rsp + 1*16]
  106. movdqa xmm8, [rsp + 2*16]
  107. movdqa xmm9, [rsp + 3*16]
  108. movdqa xmm10, [rsp + 4*16]
  109. movdqa xmm11, [rsp + 5*16]
  110. movdqa xmm12, [rsp + 6*16]
  111. movdqa xmm13, [rsp + 7*16]
  112. movdqa xmm14, [rsp + 8*16]
  113. movdqa xmm15, [rsp + 9*16]
  114. mov r12, [rsp + 10*16 + 0*8]
  115. mov r13, [rsp + 10*16 + 1*8]
  116. mov r14, [rsp + 10*16 + 2*8]
  117. mov r15, [rsp + 10*16 + 3*8]
  118. mov rdi, [rsp + 10*16 + 4*8]
  119. mov rsi, [rsp + 10*16 + 5*8]
  120. add rsp, stack_size
  121. %endmacro
  122. %endif
  123. %define len arg0
  124. %define vec arg1
  125. %define mul_array arg2
  126. %define src arg3
  127. %define dest arg4
  128. %define ptr arg5
  129. %define vec_i tmp2
  130. %define dest1 tmp3
  131. %define dest2 tmp4
  132. %define vskip1 tmp5
  133. %define vskip3 tmp6
  134. %define pos return
  135. %ifndef EC_ALIGNED_ADDR
  136. ;;; Use Un-aligned load/store
  137. %define XLDR movdqu
  138. %define XSTR movdqu
  139. %else
  140. ;;; Use Non-temporal load/stor
  141. %ifdef NO_NT_LDST
  142. %define XLDR movdqa
  143. %define XSTR movdqa
  144. %else
  145. %define XLDR movntdqa
  146. %define XSTR movntdq
  147. %endif
  148. %endif
  149. default rel
  150. [bits 64]
  151. section .text
  152. %define xmask0f xmm15
  153. %define xgft1_lo xmm2
  154. %define xgft1_hi xmm3
  155. %define xgft2_lo xmm4
  156. %define xgft2_hi xmm5
  157. %define xgft3_lo xmm10
  158. %define xgft3_hi xmm6
  159. %define xgft4_lo xmm8
  160. %define xgft4_hi xmm7
  161. %define x0 xmm0
  162. %define xtmpa xmm1
  163. %define xp1 xmm9
  164. %define xp2 xmm11
  165. %define xp3 xmm12
  166. %define xp4 xmm13
  167. %define xp5 xmm14
  168. align 16
  169. global gf_5vect_dot_prod_sse:ISAL_SYM_TYPE_FUNCTION
  170. func(gf_5vect_dot_prod_sse)
  171. %ifidn __OUTPUT_FORMAT__, macho64
  172. global _gf_5vect_dot_prod_sse:ISAL_SYM_TYPE_FUNCTION
  173. func(_gf_5vect_dot_prod_sse)
  174. %endif
  175. FUNC_SAVE
  176. sub len, 16
  177. jl .return_fail
  178. xor pos, pos
  179. movdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  180. mov vskip1, vec
  181. imul vskip1, 32
  182. mov vskip3, vec
  183. imul vskip3, 96
  184. sal vec, LOG_PS ;vec *= PS. Make vec_i count by PS
  185. mov dest1, [dest]
  186. mov dest2, [dest+PS]
  187. .loop16:
  188. mov tmp, mul_array
  189. xor vec_i, vec_i
  190. pxor xp1, xp1
  191. pxor xp2, xp2
  192. pxor xp3, xp3
  193. pxor xp4, xp4
  194. pxor xp5, xp5
  195. .next_vect:
  196. mov ptr, [src+vec_i]
  197. add vec_i, PS
  198. XLDR x0, [ptr+pos] ;Get next source vector
  199. movdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
  200. movdqu xgft1_hi, [tmp+16] ; " Ax{00}, Ax{10}, ..., Ax{f0}
  201. movdqu xgft2_lo, [tmp+vskip1*1] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
  202. movdqu xgft2_hi, [tmp+vskip1*1+16] ; " Bx{00}, Bx{10}, ..., Bx{f0}
  203. movdqu xgft3_lo, [tmp+vskip1*2] ;Load array Cx{00}, Cx{01}, ..., Cx{0f}
  204. movdqu xgft3_hi, [tmp+vskip1*2+16] ; " Cx{00}, Cx{10}, ..., Cx{f0}
  205. movdqu xgft4_lo, [tmp+vskip3] ;Load array Dx{00}, Dx{01}, ..., Dx{0f}
  206. movdqu xgft4_hi, [tmp+vskip3+16] ; " Dx{00}, Dx{10}, ..., Dx{f0}
  207. movdqa xtmpa, x0 ;Keep unshifted copy of src
  208. psraw x0, 4 ;Shift to put high nibble into bits 4-0
  209. pand x0, xmask0f ;Mask high src nibble in bits 4-0
  210. pand xtmpa, xmask0f ;Mask low src nibble in bits 4-0
  211. pshufb xgft1_hi, x0 ;Lookup mul table of high nibble
  212. pshufb xgft1_lo, xtmpa ;Lookup mul table of low nibble
  213. pxor xgft1_hi, xgft1_lo ;GF add high and low partials
  214. pxor xp1, xgft1_hi ;xp1 += partial
  215. pshufb xgft2_hi, x0 ;Lookup mul table of high nibble
  216. pshufb xgft2_lo, xtmpa ;Lookup mul table of low nibble
  217. pxor xgft2_hi, xgft2_lo ;GF add high and low partials
  218. pxor xp2, xgft2_hi ;xp2 += partial
  219. movdqu xgft1_lo, [tmp+vskip1*4] ;Load array Ex{00}, Ex{01}, ..., Ex{0f}
  220. movdqu xgft1_hi, [tmp+vskip1*4+16] ; " Ex{00}, Ex{10}, ..., Ex{f0}
  221. add tmp, 32
  222. pshufb xgft3_hi, x0 ;Lookup mul table of high nibble
  223. pshufb xgft3_lo, xtmpa ;Lookup mul table of low nibble
  224. pxor xgft3_hi, xgft3_lo ;GF add high and low partials
  225. pxor xp3, xgft3_hi ;xp3 += partial
  226. pshufb xgft4_hi, x0 ;Lookup mul table of high nibble
  227. pshufb xgft4_lo, xtmpa ;Lookup mul table of low nibble
  228. pxor xgft4_hi, xgft4_lo ;GF add high and low partials
  229. pxor xp4, xgft4_hi ;xp4 += partial
  230. pshufb xgft1_hi, x0 ;Lookup mul table of high nibble
  231. pshufb xgft1_lo, xtmpa ;Lookup mul table of low nibble
  232. pxor xgft1_hi, xgft1_lo ;GF add high and low partials
  233. pxor xp5, xgft1_hi ;xp5 += partial
  234. cmp vec_i, vec
  235. jl .next_vect
  236. mov tmp, [dest+2*PS]
  237. mov ptr, [dest+3*PS]
  238. mov vec_i, [dest+4*PS]
  239. XSTR [dest1+pos], xp1
  240. XSTR [dest2+pos], xp2
  241. XSTR [tmp+pos], xp3
  242. XSTR [ptr+pos], xp4
  243. XSTR [vec_i+pos], xp5
  244. add pos, 16 ;Loop on 16 bytes at a time
  245. cmp pos, len
  246. jle .loop16
  247. lea tmp, [len + 16]
  248. cmp pos, tmp
  249. je .return_pass
  250. ;; Tail len
  251. mov pos, len ;Overlapped offset length-16
  252. jmp .loop16 ;Do one more overlap pass
  253. .return_pass:
  254. FUNC_RESTORE
  255. mov return, 0
  256. ret
  257. .return_fail:
  258. FUNC_RESTORE
  259. mov return, 1
  260. ret
  261. endproc_frame
  262. section .data
  263. align 16
  264. mask0f: dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
  265. ;;; func core, ver, snum
  266. slversion gf_5vect_dot_prod_sse, 00, 05, 0065