gf_5vect_mad_avx2_gfni.asm 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Copyright(c) 2023 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_5vect_mad_avx2_gfni(len, vec, vec_i, mul_array, src, dest);
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %include "gf_vect_gfni.inc"
  34. %include "memcpy.asm"
  35. %if AS_FEATURE_LEVEL >= 10
  36. %ifidn __OUTPUT_FORMAT__, elf64
  37. %define arg0 rdi
  38. %define arg1 rsi
  39. %define arg2 rdx
  40. %define arg3 rcx
  41. %define arg4 r8
  42. %define arg5 r9
  43. %define tmp r11
  44. %define tmp2 r10
  45. %define tmp3 r12
  46. %define tmp4 r13
  47. %define func(x) x: endbranch
  48. %define stack_size 2*8
  49. %macro FUNC_SAVE 0
  50. sub rsp, stack_size
  51. mov [rsp + 0*8], r12
  52. mov [rsp + 1*8], r13
  53. %endmacro
  54. %macro FUNC_RESTORE 0
  55. mov r12, [rsp + 0*8]
  56. mov r13, [rsp + 1*8]
  57. add rsp, stack_size
  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 r13 ; must be saved and restored
  67. %define tmp r11
  68. %define tmp2 r10
  69. %define tmp3 r14
  70. %define tmp4 r15
  71. %define stack_size 16*10 + 5*8
  72. %define arg(x) [rsp + stack_size + 8 + 8*x]
  73. %define func(x) proc_frame x
  74. %macro FUNC_SAVE 0
  75. sub rsp, stack_size
  76. vmovdqa [rsp + 0*16], xmm6
  77. vmovdqa [rsp + 1*16], xmm7
  78. vmovdqa [rsp + 2*16], xmm8
  79. vmovdqa [rsp + 3*16], xmm9
  80. vmovdqa [rsp + 4*16], xmm10
  81. vmovdqa [rsp + 5*16], xmm11
  82. vmovdqa [rsp + 6*16], xmm12
  83. vmovdqa [rsp + 7*16], xmm13
  84. vmovdqa [rsp + 8*16], xmm14
  85. vmovdqa [rsp + 9*16], xmm15
  86. mov [rsp + 10*16 + 0*8], r12
  87. mov [rsp + 10*16 + 1*8], r13
  88. mov [rsp + 10*16 + 2*8], r14
  89. mov [rsp + 10*16 + 3*8], r15
  90. end_prolog
  91. mov arg4, arg(4)
  92. mov arg5, arg(5)
  93. %endmacro
  94. %macro FUNC_RESTORE 0
  95. vmovdqa xmm6, [rsp + 0*16]
  96. vmovdqa xmm7, [rsp + 1*16]
  97. vmovdqa xmm8, [rsp + 2*16]
  98. vmovdqa xmm9, [rsp + 3*16]
  99. vmovdqa xmm10, [rsp + 4*16]
  100. vmovdqa xmm11, [rsp + 5*16]
  101. vmovdqa xmm12, [rsp + 6*16]
  102. vmovdqa xmm13, [rsp + 7*16]
  103. vmovdqa xmm14, [rsp + 8*16]
  104. vmovdqa xmm15, [rsp + 9*16]
  105. mov r12, [rsp + 10*16 + 0*8]
  106. mov r13, [rsp + 10*16 + 1*8]
  107. mov r14, [rsp + 10*16 + 2*8]
  108. mov r15, [rsp + 10*16 + 3*8]
  109. add rsp, stack_size
  110. %endmacro
  111. %endif
  112. %define len arg0
  113. %define vec arg1
  114. %define vec_i arg2
  115. %define mul_array arg3
  116. %define src arg4
  117. %define dest1 arg5
  118. %define pos rax
  119. %define dest2 mul_array
  120. %define dest3 vec_i
  121. %define dest4 tmp3
  122. %define dest5 tmp4
  123. %ifndef EC_ALIGNED_ADDR
  124. ;;; Use Un-aligned load/store
  125. %define XLDR vmovdqu
  126. %define XSTR vmovdqu
  127. %else
  128. ;;; Use Non-temporal load/stor
  129. %ifdef NO_NT_LDST
  130. %define XLDR vmovdqa
  131. %define XSTR vmovdqa
  132. %else
  133. %define XLDR vmovntdqa
  134. %define XSTR vmovntdq
  135. %endif
  136. %endif
  137. default rel
  138. [bits 64]
  139. section .text
  140. %define x0 ymm0
  141. %define xd1 ymm1
  142. %define xd2 ymm2
  143. %define xd3 ymm3
  144. %define xd4 ymm4
  145. %define xd5 ymm5
  146. %define xgft1 ymm6
  147. %define xgft2 ymm7
  148. %define xgft3 ymm8
  149. %define xgft4 ymm9
  150. %define xgft5 ymm10
  151. %define xret1 ymm11
  152. %define xret2 ymm12
  153. %define xret3 ymm13
  154. %define xret4 ymm14
  155. %define xret5 ymm15
  156. ;;
  157. ;; Encodes 32 bytes of a single source into 5x 32 bytes (parity disks)
  158. ;;
  159. %macro ENCODE_32B_5 0
  160. ;; get next source vector
  161. XLDR x0, [src + pos]
  162. ;; get next dest vectors
  163. XLDR xd1, [dest1 + pos]
  164. XLDR xd2, [dest2 + pos]
  165. XLDR xd3, [dest3 + pos]
  166. XLDR xd4, [dest4 + pos]
  167. XLDR xd5, [dest5 + pos]
  168. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1, xgft2, xret2, xd2, \
  169. xgft3, xret3, xd3, xgft4, xret4, xd4, xgft5, xret5, xd5
  170. XSTR [dest1 + pos], xd1
  171. XSTR [dest2 + pos], xd2
  172. XSTR [dest3 + pos], xd3
  173. XSTR [dest4 + pos], xd4
  174. XSTR [dest5 + pos], xd5
  175. %endmacro
  176. ;;
  177. ;; Encodes less than 32 bytes of a single source into 5x parity disks
  178. ;;
  179. %macro ENCODE_LT_32B_5 1
  180. %define %%LEN %1
  181. ;; get next source vector
  182. simd_load_avx2 x0, src + pos, %%LEN, tmp, tmp2
  183. ;; get next dest vectors
  184. simd_load_avx2 xd1, dest1 + pos, %%LEN, tmp, tmp2
  185. simd_load_avx2 xd2, dest2 + pos, %%LEN, tmp, tmp2
  186. simd_load_avx2 xd3, dest3 + pos, %%LEN, tmp, tmp2
  187. simd_load_avx2 xd4, dest4 + pos, %%LEN, tmp, tmp2
  188. simd_load_avx2 xd5, dest5 + pos, %%LEN, tmp, tmp2
  189. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1, xgft2, xret2, xd2, \
  190. xgft3, xret3, xd3, xgft4, xret4, xd4, xgft5, xret5, xd5
  191. lea dest1, [dest1 + pos]
  192. simd_store_avx2 dest1, xd1, %%LEN, tmp, tmp2
  193. lea dest2, [dest2 + pos]
  194. simd_store_avx2 dest2, xd2, %%LEN, tmp, tmp2
  195. lea dest3, [dest3 + pos]
  196. simd_store_avx2 dest3, xd3, %%LEN, tmp, tmp2
  197. lea dest4, [dest4 + pos]
  198. simd_store_avx2 dest4, xd4, %%LEN, tmp, tmp2
  199. lea dest5, [dest5 + pos]
  200. simd_store_avx2 dest5, xd5, %%LEN, tmp, tmp2
  201. %endmacro
  202. align 16
  203. global gf_5vect_mad_avx2_gfni, function
  204. func(gf_5vect_mad_avx2_gfni)
  205. FUNC_SAVE
  206. xor pos, pos
  207. shl vec_i, 3 ;Multiply by 8
  208. shl vec, 3 ;Multiply by 8
  209. lea tmp, [mul_array + vec_i]
  210. lea tmp2, [vec*3]
  211. vbroadcastsd xgft1, [tmp]
  212. vbroadcastsd xgft2, [tmp + vec]
  213. vbroadcastsd xgft3, [tmp + vec*2]
  214. vbroadcastsd xgft4, [tmp + tmp2]
  215. vbroadcastsd xgft5, [tmp + vec*4]
  216. mov dest2, [dest1 + 1*8] ; reuse mul_array
  217. mov dest3, [dest1 + 2*8] ; reuse vec_i
  218. mov dest4, [dest1 + 3*8]
  219. mov dest5, [dest1 + 4*8]
  220. mov dest1, [dest1]
  221. cmp len, 32
  222. jl .len_lt_32
  223. .loop32:
  224. ENCODE_32B_5 ;; loop on 32 bytes at a time
  225. add pos, 32
  226. sub len, 32
  227. cmp len, 32
  228. jge .loop32
  229. .len_lt_32:
  230. cmp len, 0
  231. jle .exit
  232. ENCODE_LT_32B_5 len ;; encode final bytes
  233. .exit:
  234. vzeroupper
  235. FUNC_RESTORE
  236. ret
  237. endproc_frame
  238. %endif ; if AS_FEATURE_LEVEL >= 10