gf_3vect_mad_avx2_gfni.asm 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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_3vect_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 func(x) x: endbranch
  46. %define FUNC_SAVE
  47. %define FUNC_RESTORE
  48. %endif
  49. %ifidn __OUTPUT_FORMAT__, win64
  50. %define arg0 rcx
  51. %define arg1 rdx
  52. %define arg2 r8
  53. %define arg3 r9
  54. %define arg4 r12 ; must be saved, loaded and restored
  55. %define arg5 r13 ; must be saved and restored
  56. %define tmp r11
  57. %define tmp2 r10
  58. %define stack_size 16*10 + 3*8
  59. %define arg(x) [rsp + stack_size + 8 + 8*x]
  60. %define func(x) proc_frame x
  61. %macro FUNC_SAVE 0
  62. sub rsp, stack_size
  63. vmovdqa [rsp + 0*16], xmm6
  64. vmovdqa [rsp + 1*16], xmm7
  65. vmovdqa [rsp + 2*16], xmm8
  66. vmovdqa [rsp + 3*16], xmm9
  67. vmovdqa [rsp + 4*16], xmm10
  68. vmovdqa [rsp + 5*16], xmm11
  69. vmovdqa [rsp + 6*16], xmm12
  70. vmovdqa [rsp + 7*16], xmm13
  71. vmovdqa [rsp + 8*16], xmm14
  72. vmovdqa [rsp + 9*16], xmm15
  73. mov [rsp + 10*16 + 0*8], r12
  74. mov [rsp + 10*16 + 1*8], r13
  75. end_prolog
  76. mov arg4, arg(4)
  77. mov arg5, arg(5)
  78. %endmacro
  79. %macro FUNC_RESTORE 0
  80. vmovdqa xmm6, [rsp + 0*16]
  81. vmovdqa xmm7, [rsp + 1*16]
  82. vmovdqa xmm8, [rsp + 2*16]
  83. vmovdqa xmm9, [rsp + 3*16]
  84. vmovdqa xmm10, [rsp + 4*16]
  85. vmovdqa xmm11, [rsp + 5*16]
  86. vmovdqa xmm12, [rsp + 6*16]
  87. vmovdqa xmm13, [rsp + 7*16]
  88. vmovdqa xmm14, [rsp + 8*16]
  89. vmovdqa xmm15, [rsp + 9*16]
  90. mov r12, [rsp + 10*16 + 0*8]
  91. mov r13, [rsp + 10*16 + 1*8]
  92. add rsp, stack_size
  93. %endmacro
  94. %endif
  95. %define len arg0
  96. %define vec arg1
  97. %define vec_i arg2
  98. %define mul_array arg3
  99. %define src arg4
  100. %define dest1 arg5
  101. %define pos rax
  102. %define dest2 mul_array
  103. %define dest3 vec_i
  104. %ifndef EC_ALIGNED_ADDR
  105. ;;; Use Un-aligned load/store
  106. %define XLDR vmovdqu
  107. %define XSTR vmovdqu
  108. %else
  109. ;;; Use Non-temporal load/stor
  110. %ifdef NO_NT_LDST
  111. %define XLDR vmovdqa
  112. %define XSTR vmovdqa
  113. %else
  114. %define XLDR vmovntdqa
  115. %define XSTR vmovntdq
  116. %endif
  117. %endif
  118. default rel
  119. [bits 64]
  120. section .text
  121. %define x0l ymm0
  122. %define x0h ymm0 ; reuse ymm0
  123. %define xgft1 ymm1
  124. %define xgft2 ymm2
  125. %define xgft3 ymm3
  126. %define xd1l ymm4
  127. %define xd1h ymm5
  128. %define xd2l ymm6
  129. %define xd2h ymm7
  130. %define xd3l ymm8
  131. %define xd3h ymm9
  132. %define xret1l ymm10
  133. %define xret1h ymm11
  134. %define xret2l ymm12
  135. %define xret2h ymm13
  136. %define xret3l ymm14
  137. %define xret3h ymm15
  138. %define x0 x0l
  139. %define xd1 xd1l
  140. %define xd2 xd2l
  141. %define xd3 xd3l
  142. %define xret1 xret1l
  143. %define xret2 xret2l
  144. %define xret3 xret3l
  145. ;;
  146. ;; Encodes 64 bytes of a single source into 3x 64 bytes (parity disks)
  147. ;;
  148. %macro ENCODE_64B_3 0
  149. ; get next source vector
  150. XLDR x0l, [src + pos] ;; read low 32 bytes
  151. ; get next dest vectors
  152. XLDR xd1l, [dest1 + pos]
  153. XLDR xd1h, [dest1 + pos + 32]
  154. XLDR xd2l, [dest2 + pos]
  155. XLDR xd2h, [dest2 + pos + 32]
  156. XLDR xd3l, [dest3 + pos]
  157. XLDR xd3h, [dest3 + pos + 32]
  158. GF_MUL_XOR VEX, x0l, xgft1, xret1l, xd1l, xgft2, xret2l, xd2l, xgft3, xret3l, xd3l
  159. XLDR x0h, [src + pos + 32] ;; read high 32 bytes
  160. GF_MUL_XOR VEX, x0h, xgft1, xret1h, xd1h, xgft2, xret2h, xd2h, xgft3, xret3h, xd3h
  161. XSTR [dest1 + pos], xd1l
  162. XSTR [dest1 + pos + 32], xd1h
  163. XSTR [dest2 + pos], xd2l
  164. XSTR [dest2 + pos + 32], xd2h
  165. XSTR [dest3 + pos], xd3l
  166. XSTR [dest3 + pos + 32], xd3h
  167. %endmacro
  168. ;;
  169. ;; Encodes 32 bytes of a single source into 3x 32 bytes (parity disks)
  170. ;;
  171. %macro ENCODE_32B_3 0
  172. ; get next source vector
  173. XLDR x0, [src + pos]
  174. ; get next dest vectors
  175. XLDR xd1, [dest1 + pos]
  176. XLDR xd2, [dest2 + pos]
  177. XLDR xd3, [dest3 + pos]
  178. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1, xgft2, xret2, xd2, xgft3, xret3, xd3
  179. XSTR [dest1 + pos], xd1
  180. XSTR [dest2 + pos], xd2
  181. XSTR [dest3 + pos], xd3
  182. %endmacro
  183. ;;
  184. ;; Encodes less than 32 bytes of a single source into 3x parity disks
  185. ;;
  186. %macro ENCODE_LT_32B_3 1
  187. %define %%LEN %1
  188. ; get next source vector
  189. simd_load_avx2 x0, src + pos, %%LEN, tmp, tmp2
  190. ; get next dest vectors
  191. simd_load_avx2 xd1, dest1 + pos, %%LEN, tmp, tmp2
  192. simd_load_avx2 xd2, dest2 + pos, %%LEN, tmp, tmp2
  193. simd_load_avx2 xd3, dest3 + pos, %%LEN, tmp, tmp2
  194. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1, xgft2, xret2, xd2, xgft3, xret3, xd3
  195. lea dest1, [dest1 + pos]
  196. simd_store_avx2 dest1, xd1, %%LEN, tmp, tmp2
  197. lea dest2, [dest2 + pos]
  198. simd_store_avx2 dest2, xd2, %%LEN, tmp, tmp2
  199. lea dest3, [dest3 + pos]
  200. simd_store_avx2 dest3, xd3, %%LEN, tmp, tmp2
  201. %endmacro
  202. align 16
  203. global gf_3vect_mad_avx2_gfni, function
  204. func(gf_3vect_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. vbroadcastsd xgft1, [tmp]
  211. vbroadcastsd xgft2, [tmp + vec]
  212. vbroadcastsd xgft3, [tmp + vec*2]
  213. mov dest2, [dest1 + 8] ; reuse mul_array
  214. mov dest3, [dest1 + 2*8] ; reuse vec_i
  215. mov dest1, [dest1]
  216. cmp len, 64
  217. jl .len_lt_64
  218. .loop64:
  219. ENCODE_64B_3 ;; loop on 64 bytes at a time
  220. add pos, 64
  221. sub len, 64
  222. cmp len, 64
  223. jge .loop64
  224. .len_lt_64:
  225. cmp len, 32
  226. jl .len_lt_32
  227. ENCODE_32B_3 ;; encode next 32 bytes
  228. add pos, 32
  229. sub len, 32
  230. .len_lt_32:
  231. cmp len, 0
  232. jle .exit
  233. ENCODE_LT_32B_3 len ;; encode final bytes
  234. .exit:
  235. vzeroupper
  236. FUNC_RESTORE
  237. ret
  238. endproc_frame
  239. %endif ; if AS_FEATURE_LEVEL >= 10