gf_3vect_mad_avx512_gfni.asm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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_avx512_gfni(len, vec, vec_i, mul_array, src, dest);
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %include "gf_vect_gfni.inc"
  34. %if AS_FEATURE_LEVEL >= 10
  35. %ifidn __OUTPUT_FORMAT__, elf64
  36. %define arg0 rdi
  37. %define arg1 rsi
  38. %define arg2 rdx
  39. %define arg3 rcx
  40. %define arg4 r8
  41. %define arg5 r9
  42. %define tmp r11
  43. %define func(x) x: endbranch
  44. %define FUNC_SAVE
  45. %define FUNC_RESTORE
  46. %endif
  47. %ifidn __OUTPUT_FORMAT__, win64
  48. %define arg0 rcx
  49. %define arg1 rdx
  50. %define arg2 r8
  51. %define arg3 r9
  52. %define arg4 r12 ; must be saved, loaded and restored
  53. %define arg5 r13 ; must be saved and restored
  54. %define tmp r11
  55. %define stack_size 16*4 + 3*8
  56. %define arg(x) [rsp + stack_size + 8 + 8*x]
  57. %define func(x) proc_frame x
  58. %macro FUNC_SAVE 0
  59. sub rsp, stack_size
  60. vmovdqa [rsp + 16*0], xmm6
  61. vmovdqa [rsp + 16*1], xmm7
  62. vmovdqa [rsp + 16*2], xmm8
  63. vmovdqa [rsp + 16*3], xmm9
  64. mov [rsp + 4*16 + 0*8], r12
  65. mov [rsp + 4*16 + 1*8], r13
  66. end_prolog
  67. mov arg4, arg(4)
  68. mov arg5, arg(5)
  69. %endmacro
  70. %macro FUNC_RESTORE 0
  71. vmovdqa xmm6, [rsp + 16*0]
  72. vmovdqa xmm7, [rsp + 16*1]
  73. vmovdqa xmm8, [rsp + 16*2]
  74. vmovdqa xmm9, [rsp + 16*3]
  75. mov r12, [rsp + 4*16 + 0*8]
  76. mov r13, [rsp + 4*16 + 1*8]
  77. add rsp, stack_size
  78. %endmacro
  79. %endif
  80. %define len arg0
  81. %define vec arg1
  82. %define vec_i arg2
  83. %define mul_array arg3
  84. %define src arg4
  85. %define dest1 arg5
  86. %define pos rax
  87. %define dest2 mul_array
  88. %define dest3 vec_i
  89. %ifndef EC_ALIGNED_ADDR
  90. ;;; Use Un-aligned load/store
  91. %define XLDR vmovdqu8
  92. %define XSTR vmovdqu8
  93. %else
  94. ;;; Use Non-temporal load/stor
  95. %ifdef NO_NT_LDST
  96. %define XLDR vmovdqa64
  97. %define XSTR vmovdqa64
  98. %else
  99. %define XLDR vmovntdqa
  100. %define XSTR vmovntdq
  101. %endif
  102. %endif
  103. default rel
  104. [bits 64]
  105. section .text
  106. %define x0 zmm0
  107. %define xgft1 zmm1
  108. %define xgft2 zmm2
  109. %define xgft3 zmm3
  110. %define xd1 zmm4
  111. %define xd2 zmm5
  112. %define xd3 zmm6
  113. %define xret1 zmm7
  114. %define xret2 zmm8
  115. %define xret3 zmm9
  116. ;;
  117. ;; Encodes 64 bytes of a single source into 3x 64 bytes (parity disks)
  118. ;;
  119. %macro ENCODE_64B_3 0-1
  120. %define %%KMASK %1
  121. %if %0 == 1
  122. vmovdqu8 x0{%%KMASK}, [src + pos] ;Get next source vector
  123. vmovdqu8 xd1{%%KMASK}, [dest1 + pos] ;Get next dest vector
  124. vmovdqu8 xd2{%%KMASK}, [dest2 + pos] ;Get next dest vector
  125. vmovdqu8 xd3{%%KMASK}, [dest3 + pos] ;Get next dest vector
  126. %else
  127. XLDR x0, [src + pos] ;Get next source vector
  128. XLDR xd1, [dest1 + pos] ;Get next dest vector
  129. XLDR xd2, [dest2 + pos] ;Get next dest vector
  130. XLDR xd3, [dest3 + pos] ;Get next dest vector
  131. %endif
  132. GF_MUL_XOR EVEX, x0, xgft1, xret1, xd1, xgft2, xret2, xd2, xgft3, xret3, xd3
  133. %if %0 == 1
  134. vmovdqu8 [dest1 + pos]{%%KMASK}, xd1
  135. vmovdqu8 [dest2 + pos]{%%KMASK}, xd2
  136. vmovdqu8 [dest3 + pos]{%%KMASK}, xd3
  137. %else
  138. XSTR [dest1 + pos], xd1
  139. XSTR [dest2 + pos], xd2
  140. XSTR [dest3 + pos], xd3
  141. %endif
  142. %endmacro
  143. align 16
  144. global gf_3vect_mad_avx512_gfni, function
  145. func(gf_3vect_mad_avx512_gfni)
  146. FUNC_SAVE
  147. xor pos, pos
  148. shl vec_i, 3 ;Multiply by 8
  149. shl vec, 3 ;Multiply by 8
  150. lea tmp, [mul_array + vec_i]
  151. vbroadcastf32x2 xgft1, [tmp]
  152. vbroadcastf32x2 xgft2, [tmp + vec]
  153. vbroadcastf32x2 xgft3, [tmp + vec*2]
  154. mov dest2, [dest1 + 8] ; reuse mul_array
  155. mov dest3, [dest1 + 2*8] ; reuse vec
  156. mov dest1, [dest1]
  157. cmp len, 64
  158. jl .len_lt_64
  159. .loop64:
  160. ENCODE_64B_3
  161. add pos, 64 ;Loop on 64 bytes at a time
  162. sub len, 64
  163. cmp len, 64
  164. jge .loop64
  165. .len_lt_64:
  166. cmp len, 0
  167. jle .exit
  168. xor tmp, tmp
  169. bts tmp, len
  170. dec tmp
  171. kmovq k1, tmp
  172. ENCODE_64B_3 k1
  173. .exit:
  174. vzeroupper
  175. FUNC_RESTORE
  176. ret
  177. endproc_frame
  178. %endif ; if AS_FEATURE_LEVEL >= 10