gf_vect_dot_prod_avx2.asm 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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_vect_dot_prod_avx2(len, vec, *g_tbls, **buffs, *dest);
  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 return rax
  46. %macro SLDR 2
  47. %endmacro
  48. %define SSTR SLDR
  49. %define PS 8
  50. %define func(x) x:
  51. %define FUNC_SAVE
  52. %define FUNC_RESTORE
  53. %endif
  54. %ifidn __OUTPUT_FORMAT__, win64
  55. %define arg0 rcx
  56. %define arg1 rdx
  57. %define arg2 r8
  58. %define arg3 r9
  59. %define arg4 r12 ; must be saved and loaded
  60. %define tmp r11
  61. %define tmp.w r11d
  62. %define tmp.b r11b
  63. %define tmp2 r10
  64. %define tmp3 rdi ; must be saved and loaded
  65. %define return rax
  66. %macro SLDR 2
  67. %endmacro
  68. %define SSTR SLDR
  69. %define PS 8
  70. %define frame_size 2*8
  71. %define arg(x) [rsp + frame_size + PS + PS*x]
  72. %define func(x) proc_frame x
  73. %macro FUNC_SAVE 0
  74. rex_push_reg r12
  75. push_reg rdi
  76. end_prolog
  77. mov arg4, arg(4)
  78. %endmacro
  79. %macro FUNC_RESTORE 0
  80. pop rdi
  81. pop r12
  82. %endmacro
  83. %endif
  84. %ifidn __OUTPUT_FORMAT__, elf32
  85. ;;;================== High Address;
  86. ;;; arg4
  87. ;;; arg3
  88. ;;; arg2
  89. ;;; arg1
  90. ;;; arg0
  91. ;;; return
  92. ;;;<================= esp of caller
  93. ;;; ebp
  94. ;;;<================= ebp = esp
  95. ;;; esi
  96. ;;; edi
  97. ;;; ebx
  98. ;;;<================= esp of callee
  99. ;;;
  100. ;;;================== Low Address;
  101. %define PS 4
  102. %define LOG_PS 2
  103. %define func(x) x:
  104. %define arg(x) [ebp + PS*2 + PS*x]
  105. %define trans ecx ;trans is for the variables in stack
  106. %define arg0 trans
  107. %define arg0_m arg(0)
  108. %define arg1 trans
  109. %define arg1_m arg(1)
  110. %define arg2 arg2_m
  111. %define arg2_m arg(2)
  112. %define arg3 ebx
  113. %define arg4 trans
  114. %define arg4_m arg(4)
  115. %define tmp edx
  116. %define tmp.w edx
  117. %define tmp.b dl
  118. %define tmp2 edi
  119. %define tmp3 esi
  120. %define return eax
  121. %macro SLDR 2 ;stack load/restore
  122. mov %1, %2
  123. %endmacro
  124. %define SSTR SLDR
  125. %macro FUNC_SAVE 0
  126. push ebp
  127. mov ebp, esp
  128. push esi
  129. push edi
  130. push ebx
  131. mov arg3, arg(3)
  132. %endmacro
  133. %macro FUNC_RESTORE 0
  134. pop ebx
  135. pop edi
  136. pop esi
  137. mov esp, ebp
  138. pop ebp
  139. %endmacro
  140. %endif ; output formats
  141. %define len arg0
  142. %define vec arg1
  143. %define mul_array arg2
  144. %define src arg3
  145. %define dest arg4
  146. %define vec_i tmp2
  147. %define ptr tmp3
  148. %define pos return
  149. %ifidn PS,4 ;32-bit code
  150. %define vec_m arg1_m
  151. %define len_m arg0_m
  152. %define dest_m arg4_m
  153. %endif
  154. %ifndef EC_ALIGNED_ADDR
  155. ;;; Use Un-aligned load/store
  156. %define XLDR vmovdqu
  157. %define XSTR vmovdqu
  158. %else
  159. ;;; Use Non-temporal load/stor
  160. %ifdef NO_NT_LDST
  161. %define XLDR vmovdqa
  162. %define XSTR vmovdqa
  163. %else
  164. %define XLDR vmovntdqa
  165. %define XSTR vmovntdq
  166. %endif
  167. %endif
  168. %ifidn PS,8 ;64-bit code
  169. default rel
  170. [bits 64]
  171. %endif
  172. section .text
  173. %define xmask0f ymm3
  174. %define xmask0fx xmm3
  175. %define xgft_lo ymm4
  176. %define xgft_hi ymm5
  177. %define x0 ymm0
  178. %define xtmpa ymm1
  179. %define xp ymm2
  180. align 16
  181. global gf_vect_dot_prod_avx2:ISAL_SYM_TYPE_FUNCTION
  182. func(gf_vect_dot_prod_avx2)
  183. %ifidn __OUTPUT_FORMAT__, macho64
  184. global _gf_vect_dot_prod_avx2:ISAL_SYM_TYPE_FUNCTION
  185. func(_gf_vect_dot_prod_avx2)
  186. %endif
  187. FUNC_SAVE
  188. SLDR len, len_m
  189. sub len, 32
  190. SSTR len_m, len
  191. jl .return_fail
  192. xor pos, pos
  193. mov tmp.b, 0x0f
  194. vpinsrb xmask0fx, xmask0fx, tmp.w, 0
  195. vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
  196. .loop32:
  197. vpxor xp, xp
  198. mov tmp, mul_array
  199. xor vec_i, vec_i
  200. .next_vect:
  201. mov ptr, [src+vec_i*PS]
  202. vmovdqu xgft_lo, [tmp] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  203. ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  204. vperm2i128 xgft_hi, xgft_lo, xgft_lo, 0x11 ; swapped to hi | hi
  205. vperm2i128 xgft_lo, xgft_lo, xgft_lo, 0x00 ; swapped to lo | lo
  206. XLDR x0, [ptr+pos] ;Get next source vector
  207. add tmp, 32
  208. add vec_i, 1
  209. vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
  210. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  211. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  212. vpshufb xgft_hi, xgft_hi, x0 ;Lookup mul table of high nibble
  213. vpshufb xgft_lo, xgft_lo, xtmpa ;Lookup mul table of low nibble
  214. vpxor xgft_hi, xgft_hi, xgft_lo ;GF add high and low partials
  215. vpxor xp, xp, xgft_hi ;xp += partial
  216. SLDR vec, vec_m
  217. cmp vec_i, vec
  218. jl .next_vect
  219. SLDR dest, dest_m
  220. XSTR [dest+pos], xp
  221. add pos, 32 ;Loop on 32 bytes at a time
  222. SLDR len, len_m
  223. cmp pos, len
  224. jle .loop32
  225. lea tmp, [len + 32]
  226. cmp pos, tmp
  227. je .return_pass
  228. ;; Tail len
  229. mov pos, len ;Overlapped offset length-32
  230. jmp .loop32 ;Do one more overlap pass
  231. .return_pass:
  232. mov return, 0
  233. FUNC_RESTORE
  234. ret
  235. .return_fail:
  236. mov return, 1
  237. FUNC_RESTORE
  238. ret
  239. endproc_frame
  240. section .data
  241. ;;; func core, ver, snum
  242. slversion gf_vect_dot_prod_avx2, 04, 05, 0190