gf_2vect_dot_prod_avx2.asm 8.6 KB

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