gf_3vect_dot_prod_avx2.asm 10.0 KB

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