gf_vect_mad_avx2_gfni.asm 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_vect_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*3 + 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. mov [rsp + 3*16 + 0*8], r12
  67. mov [rsp + 3*16 + 1*8], r13
  68. end_prolog
  69. mov arg4, arg(4)
  70. mov arg5, arg(5)
  71. %endmacro
  72. %macro FUNC_RESTORE 0
  73. vmovdqa xmm6, [rsp + 0*16]
  74. vmovdqa xmm7, [rsp + 1*16]
  75. vmovdqa xmm8, [rsp + 2*16]
  76. mov r12, [rsp + 3*16 + 0*8]
  77. mov r13, [rsp + 3*16 + 1*8]
  78. add rsp, stack_size
  79. %endmacro
  80. %endif
  81. %define len arg0
  82. %define vec arg1
  83. %define vec_i arg2
  84. %define mul_array arg3
  85. %define src arg4
  86. %define dest1 arg5
  87. %define pos rax
  88. %ifndef EC_ALIGNED_ADDR
  89. ;;; Use Un-aligned load/store
  90. %define XLDR vmovdqu
  91. %define XSTR vmovdqu
  92. %else
  93. ;;; Use Non-temporal load/stor
  94. %ifdef NO_NT_LDST
  95. %define XLDR vmovdqa
  96. %define XSTR vmovdqa
  97. %else
  98. %define XLDR vmovntdqa
  99. %define XSTR vmovntdq
  100. %endif
  101. %endif
  102. default rel
  103. [bits 64]
  104. section .text
  105. %define x0l ymm0
  106. %define x0h ymm1
  107. %define x0x ymm2
  108. %define xgft1 ymm3
  109. %define xd1l ymm4
  110. %define xd1h ymm5
  111. %define xd1x ymm6
  112. %define xret1l ymm7
  113. %define xret1h ymm8
  114. %define x0 x0l
  115. %define xd1 xd1l
  116. %define xret1 xret1l
  117. ;;
  118. ;; Encodes 96 bytes of a single source and updates a single parity disk
  119. ;;
  120. %macro ENCODE_96B 0
  121. ;; get next source vector
  122. XLDR x0l, [src + pos]
  123. XLDR x0h, [src + pos + 32]
  124. XLDR x0x, [src + pos + 64]
  125. ;; get next dest vector
  126. XLDR xd1l, [dest1 + pos]
  127. XLDR xd1h, [dest1 + pos + 32]
  128. XLDR xd1x, [dest1 + pos + 64]
  129. GF_MUL_XOR VEX, x0l, xgft1, xret1l, xd1l
  130. GF_MUL_XOR VEX, x0h, xgft1, xret1h, xd1h
  131. GF_MUL_XOR VEX, x0x, xgft1, xret1l, xd1x
  132. XSTR [dest1 + pos], xd1l
  133. XSTR [dest1 + pos + 32], xd1h
  134. XSTR [dest1 + pos + 64], xd1x
  135. %endmacro
  136. ;;
  137. ;; Encodes 64 bytes of a single source and updates a single parity disk
  138. ;;
  139. %macro ENCODE_64B 0
  140. ;; get next source vector
  141. XLDR x0l, [src + pos]
  142. XLDR x0h, [src + pos + 32]
  143. ;; get next dest vector
  144. XLDR xd1l, [dest1 + pos]
  145. XLDR xd1h, [dest1 + pos + 32]
  146. GF_MUL_XOR VEX, x0l, xgft1, xret1l, xd1l
  147. GF_MUL_XOR VEX, x0h, xgft1, xret1h, xd1h
  148. XSTR [dest1 + pos], xd1l
  149. XSTR [dest1 + pos + 32], xd1h
  150. %endmacro
  151. ;;
  152. ;; Encodes 32 bytes of a single source and updates single parity disk
  153. ;;
  154. %macro ENCODE_32B 0
  155. ;; get next source vector
  156. XLDR x0, [src + pos]
  157. ;; get next dest vector
  158. XLDR xd1, [dest1 + pos]
  159. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1
  160. XSTR [dest1 + pos], xd1
  161. %endmacro
  162. ;;
  163. ;; Encodes less than 32 bytes of a single source and updates parity disk
  164. ;;
  165. %macro ENCODE_LT_32B 1
  166. %define %%LEN %1
  167. ;; get next source vector
  168. simd_load_avx2 x0, src + pos, %%LEN, tmp, tmp2
  169. ;; get next dest vector
  170. simd_load_avx2 xd1, dest1 + pos, %%LEN, tmp, tmp2
  171. GF_MUL_XOR VEX, x0, xgft1, xret1, xd1
  172. lea dest1, [dest1 + pos]
  173. simd_store_avx2 dest1, xd1, %%LEN, tmp, tmp2
  174. %endmacro
  175. align 16
  176. global gf_vect_mad_avx2_gfni, function
  177. func(gf_vect_mad_avx2_gfni)
  178. FUNC_SAVE
  179. xor pos, pos
  180. shl vec_i, 3 ;Multiply by 8
  181. shl vec, 3 ;Multiply by 8
  182. lea tmp, [mul_array + vec_i]
  183. vbroadcastsd xgft1, [tmp]
  184. cmp len, 96
  185. jl .len_lt_96
  186. .loop96:
  187. ENCODE_96B ;; loop on 96 bytes at a time
  188. add pos, 96
  189. sub len, 96
  190. cmp len, 96
  191. jge .loop96
  192. .len_lt_96:
  193. cmp len, 64
  194. jl .len_lt_64
  195. ENCODE_64B ;; encode next 64 bytes
  196. add pos, 64
  197. sub len, 64
  198. .len_lt_64:
  199. cmp len, 32
  200. jl .len_lt_32
  201. ENCODE_32B ;; encode next 32 bytes
  202. add pos, 32
  203. sub len, 32
  204. .len_lt_32:
  205. cmp len, 0
  206. jle .exit
  207. ENCODE_LT_32B len ;; encode final bytes
  208. .exit:
  209. vzeroupper
  210. FUNC_RESTORE
  211. ret
  212. endproc_frame
  213. %endif ; if AS_FEATURE_LEVEL >= 10