gf_3vect_dot_prod_sse.asm 9.2 KB

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