gf_2vect_dot_prod_sse.asm 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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_2vect_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 r9
  43. %define tmp4 r12 ; must be saved and restored
  44. %define return rax
  45. %macro SLDR 2
  46. %endmacro
  47. %define SSTR SLDR
  48. %define PS 8
  49. %define LOG_PS 3
  50. %define func(x) x:
  51. %macro FUNC_SAVE 0
  52. push r12
  53. %endmacro
  54. %macro FUNC_RESTORE 0
  55. pop r12
  56. %endmacro
  57. %endif
  58. %ifidn __OUTPUT_FORMAT__, win64
  59. %define arg0 rcx
  60. %define arg1 rdx
  61. %define arg2 r8
  62. %define arg3 r9
  63. %define arg4 r12 ; must be saved, loaded and restored
  64. %define tmp r11
  65. %define tmp2 r10
  66. %define tmp3 r13 ; must be saved and restored
  67. %define tmp4 r14 ; must be saved and restored
  68. %define return rax
  69. %macro SLDR 2
  70. %endmacro
  71. %define SSTR SLDR
  72. %define PS 8
  73. %define LOG_PS 3
  74. %define stack_size 3*16 + 3*8 ; must be an odd multiple of 8
  75. %define arg(x) [rsp + stack_size + PS + PS*x]
  76. %define func(x) proc_frame x
  77. %macro FUNC_SAVE 0
  78. alloc_stack stack_size
  79. save_xmm128 xmm6, 0*16
  80. save_xmm128 xmm7, 1*16
  81. save_xmm128 xmm8, 2*16
  82. save_reg r12, 3*16 + 0*8
  83. save_reg r13, 3*16 + 1*8
  84. save_reg r14, 3*16 + 2*8
  85. end_prolog
  86. mov arg4, arg(4)
  87. %endmacro
  88. %macro FUNC_RESTORE 0
  89. movdqa xmm6, [rsp + 0*16]
  90. movdqa xmm7, [rsp + 1*16]
  91. movdqa xmm8, [rsp + 2*16]
  92. mov r12, [rsp + 3*16 + 0*8]
  93. mov r13, [rsp + 3*16 + 1*8]
  94. mov r14, [rsp + 3*16 + 2*8]
  95. add rsp, stack_size
  96. %endmacro
  97. %endif
  98. %ifidn __OUTPUT_FORMAT__, elf32
  99. ;;;================== High Address;
  100. ;;; arg4
  101. ;;; arg3
  102. ;;; arg2
  103. ;;; arg1
  104. ;;; arg0
  105. ;;; return
  106. ;;;<================= esp of caller
  107. ;;; ebp
  108. ;;;<================= ebp = esp
  109. ;;; var0
  110. ;;; esi
  111. ;;; edi
  112. ;;; ebx
  113. ;;;<================= esp of callee
  114. ;;;
  115. ;;;================== Low Address;
  116. %define PS 4
  117. %define LOG_PS 2
  118. %define func(x) x:
  119. %define arg(x) [ebp + PS*2 + PS*x]
  120. %define var(x) [ebp - PS - PS*x]
  121. %define trans ecx
  122. %define trans2 esi
  123. %define arg0 trans ;trans and trans2 are for the variables in stack
  124. %define arg0_m arg(0)
  125. %define arg1 ebx
  126. %define arg2 arg2_m
  127. %define arg2_m arg(2)
  128. %define arg3 trans
  129. %define arg3_m arg(3)
  130. %define arg4 trans
  131. %define arg4_m arg(4)
  132. %define tmp edx
  133. %define tmp2 edi
  134. %define tmp3 trans2
  135. %define tmp4 trans2
  136. %define tmp4_m var(0)
  137. %define return eax
  138. %macro SLDR 2 ;; stack load/restore
  139. mov %1, %2
  140. %endmacro
  141. %define SSTR SLDR
  142. %macro FUNC_SAVE 0
  143. push ebp
  144. mov ebp, esp
  145. sub esp, PS*1 ;1 local variable
  146. push esi
  147. push edi
  148. push ebx
  149. mov arg1, arg(1)
  150. %endmacro
  151. %macro FUNC_RESTORE 0
  152. pop ebx
  153. pop edi
  154. pop esi
  155. add esp, PS*1 ;1 local variable
  156. pop ebp
  157. %endmacro
  158. %endif ; output formats
  159. %define len arg0
  160. %define vec arg1
  161. %define mul_array arg2
  162. %define src arg3
  163. %define dest1 arg4
  164. %define vec_i tmp2
  165. %define ptr tmp3
  166. %define dest2 tmp4
  167. %define pos return
  168. %ifidn PS,4 ;32-bit code
  169. %define len_m arg0_m
  170. %define src_m arg3_m
  171. %define dest1_m arg4_m
  172. %define dest2_m tmp4_m
  173. %endif
  174. %ifndef EC_ALIGNED_ADDR
  175. ;;; Use Un-aligned load/store
  176. %define XLDR movdqu
  177. %define XSTR movdqu
  178. %else
  179. ;;; Use Non-temporal load/stor
  180. %ifdef NO_NT_LDST
  181. %define XLDR movdqa
  182. %define XSTR movdqa
  183. %else
  184. %define XLDR movntdqa
  185. %define XSTR movntdq
  186. %endif
  187. %endif
  188. %ifidn PS,8 ;64-bit code
  189. default rel
  190. [bits 64]
  191. %endif
  192. section .text
  193. %ifidn PS,8 ;64-bit code
  194. %define xmask0f xmm8
  195. %define xgft1_lo xmm7
  196. %define xgft1_hi xmm6
  197. %define xgft2_lo xmm5
  198. %define xgft2_hi xmm4
  199. %define x0 xmm0
  200. %define xtmpa xmm1
  201. %define xp1 xmm2
  202. %define xp2 xmm3
  203. %else ;32-bit code
  204. %define xmask0f xmm4
  205. %define xgft1_lo xmm7
  206. %define xgft1_hi xmm6
  207. %define xgft2_lo xgft1_lo
  208. %define xgft2_hi xgft1_hi
  209. %define x0 xmm0
  210. %define xtmpa xmm1
  211. %define xp1 xmm2
  212. %define xp2 xmm3
  213. %endif
  214. align 16
  215. global gf_2vect_dot_prod_sse:ISAL_SYM_TYPE_FUNCTION
  216. func(gf_2vect_dot_prod_sse)
  217. %ifidn __OUTPUT_FORMAT__, macho64
  218. global _gf_2vect_dot_prod_sse:ISAL_SYM_TYPE_FUNCTION
  219. func(_gf_2vect_dot_prod_sse)
  220. %endif
  221. FUNC_SAVE
  222. SLDR len, len_m
  223. sub len, 16
  224. SSTR len_m, len
  225. jl .return_fail
  226. xor pos, pos
  227. movdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  228. sal vec, LOG_PS ;vec *= PS. Make vec_i count by PS
  229. SLDR dest1, dest1_m
  230. mov dest2, [dest1+PS]
  231. SSTR dest2_m, dest2
  232. mov dest1, [dest1]
  233. SSTR dest1_m, dest1
  234. .loop16:
  235. pxor xp1, xp1
  236. pxor xp2, xp2
  237. mov tmp, mul_array
  238. xor vec_i, vec_i
  239. .next_vect:
  240. SLDR src, src_m
  241. mov ptr, [src+vec_i]
  242. movdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
  243. movdqu xgft1_hi, [tmp+16] ; " Ax{00}, Ax{10}, ..., Ax{f0}
  244. %ifidn PS,8 ;64-bit code
  245. movdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
  246. movdqu xgft2_hi, [tmp+vec*(32/PS)+16] ; " Bx{00}, Bx{10}, ..., Bx{f0}
  247. add tmp, 32
  248. add vec_i, PS
  249. %endif
  250. XLDR x0, [ptr+pos] ;Get next source vector
  251. movdqa xtmpa, x0 ;Keep unshifted copy of src
  252. psraw x0, 4 ;Shift to put high nibble into bits 4-0
  253. pand x0, xmask0f ;Mask high src nibble in bits 4-0
  254. pand xtmpa, xmask0f ;Mask low src nibble in bits 4-0
  255. pshufb xgft1_hi, x0 ;Lookup mul table of high nibble
  256. pshufb xgft1_lo, xtmpa ;Lookup mul table of low nibble
  257. pxor xgft1_hi, xgft1_lo ;GF add high and low partials
  258. pxor xp1, xgft1_hi ;xp1 += partial
  259. %ifidn PS,4 ;32-bit code
  260. movdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
  261. movdqu xgft2_hi, [tmp+vec*(32/PS)+16] ; " Bx{00}, Bx{10}, ..., Bx{f0}
  262. add tmp, 32
  263. add vec_i, PS
  264. %endif
  265. pshufb xgft2_hi, x0 ;Lookup mul table of high nibble
  266. pshufb xgft2_lo, xtmpa ;Lookup mul table of low nibble
  267. pxor xgft2_hi, xgft2_lo ;GF add high and low partials
  268. pxor xp2, xgft2_hi ;xp2 += partial
  269. cmp vec_i, vec
  270. jl .next_vect
  271. SLDR dest1, dest1_m
  272. SLDR dest2, dest2_m
  273. XSTR [dest1+pos], xp1
  274. XSTR [dest2+pos], xp2
  275. SLDR len, len_m
  276. add pos, 16 ;Loop on 16 bytes at a time
  277. cmp pos, len
  278. jle .loop16
  279. lea tmp, [len + 16]
  280. cmp pos, tmp
  281. je .return_pass
  282. ;; Tail len
  283. mov pos, len ;Overlapped offset length-16
  284. jmp .loop16 ;Do one more overlap pass
  285. .return_pass:
  286. mov return, 0
  287. FUNC_RESTORE
  288. ret
  289. .return_fail:
  290. mov return, 1
  291. FUNC_RESTORE
  292. ret
  293. endproc_frame
  294. section .data
  295. align 16
  296. mask0f: dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
  297. ;;; func core, ver, snum
  298. slversion gf_2vect_dot_prod_sse, 00, 04, 0062