gf_vect_mad_avx512_gfni.asm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_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 and loaded
  53. %define arg5 r13
  54. %define tmp r11
  55. %define stack_size 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. mov [rsp + 0*8], r12
  61. mov [rsp + 1*8], r13
  62. end_prolog
  63. mov arg4, arg(4)
  64. mov arg5, arg(5)
  65. %endmacro
  66. %macro FUNC_RESTORE 0
  67. mov r12, [rsp + 0*8]
  68. mov r13, [rsp + 1*8]
  69. add rsp, stack_size
  70. %endmacro
  71. %endif
  72. ;;; gf_vect_mad_avx512_gfni(len, vec, vec_i, mul_array, src, dest)
  73. %define len arg0
  74. %define vec arg1
  75. %define vec_i arg2
  76. %define mul_array arg3
  77. %define src arg4
  78. %define dest arg5
  79. %define pos rax
  80. %ifndef EC_ALIGNED_ADDR
  81. ;;; Use Un-aligned load/store
  82. %define XLDR vmovdqu8
  83. %define XSTR vmovdqu8
  84. %else
  85. ;;; Use Non-temporal load/stor
  86. %ifdef NO_NT_LDST
  87. %define XLDR vmovdqa64
  88. %define XSTR vmovdqa64
  89. %else
  90. %define XLDR vmovntdqa
  91. %define XSTR vmovntdq
  92. %endif
  93. %endif
  94. default rel
  95. [bits 64]
  96. section .text
  97. %define x0 zmm0
  98. %define xd zmm1
  99. %define xgft1 zmm2
  100. %define xret1 zmm3
  101. ;;
  102. ;; Encodes 64 bytes of a single source into 64 bytes (single parity disk)
  103. ;;
  104. %macro ENCODE_64B 0-1
  105. %define %%KMASK %1
  106. %if %0 == 1
  107. vmovdqu8 x0{%%KMASK}, [src + pos] ;Get next source vector
  108. vmovdqu8 xd{%%KMASK}, [dest + pos] ;Get next dest vector
  109. %else
  110. XLDR x0, [src + pos] ;Get next source vector
  111. XLDR xd, [dest + pos] ;Get next dest vector
  112. %endif
  113. GF_MUL_XOR EVEX, x0, xgft1, xret1, xd
  114. %if %0 == 1
  115. vmovdqu8 [dest + pos]{%%KMASK}, xd
  116. %else
  117. XSTR [dest + pos], xd
  118. %endif
  119. %endmacro
  120. align 16
  121. global gf_vect_mad_avx512_gfni, function
  122. func(gf_vect_mad_avx512_gfni)
  123. FUNC_SAVE
  124. xor pos, pos
  125. shl vec_i, 3 ;Multiply by 8
  126. vbroadcastf32x2 xgft1, [vec_i + mul_array]
  127. cmp len, 64
  128. jl .len_lt_64
  129. .loop64:
  130. ENCODE_64B
  131. add pos, 64 ;Loop on 64 bytes at a time
  132. sub len, 64
  133. cmp len, 64
  134. jge .loop64
  135. .len_lt_64:
  136. cmp len, 0
  137. jle .exit
  138. xor tmp, tmp
  139. bts tmp, len
  140. dec tmp
  141. kmovq k1, tmp
  142. ENCODE_64B k1
  143. .exit:
  144. vzeroupper
  145. FUNC_RESTORE
  146. ret
  147. endproc_frame
  148. %endif ; if AS_FEATURE_LEVEL >= 10