gf_vect_mul_avx.asm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Copyright(c) 2011-2015 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_mul_avx(len, mul_array, src, dest)
  31. ;;;
  32. %include "reg_sizes.asm"
  33. %ifidn __OUTPUT_FORMAT__, elf64
  34. %define arg0 rdi
  35. %define arg1 rsi
  36. %define arg2 rdx
  37. %define arg3 rcx
  38. %define arg4 r8
  39. %define arg5 r9
  40. %define tmp r11
  41. %define return rax
  42. %define func(x) x:
  43. %define FUNC_SAVE
  44. %define FUNC_RESTORE
  45. %elifidn __OUTPUT_FORMAT__, win64
  46. %define arg0 rcx
  47. %define arg1 rdx
  48. %define arg2 r8
  49. %define arg3 r9
  50. %define return rax
  51. %define stack_size 5*16 + 8 ; must be an odd multiple of 8
  52. %define func(x) proc_frame x
  53. %macro FUNC_SAVE 0
  54. alloc_stack stack_size
  55. save_xmm128 xmm6, 0*16
  56. save_xmm128 xmm7, 1*16
  57. save_xmm128 xmm13, 2*16
  58. save_xmm128 xmm14, 3*16
  59. save_xmm128 xmm15, 4*16
  60. end_prolog
  61. %endmacro
  62. %macro FUNC_RESTORE 0
  63. vmovdqa xmm6, [rsp + 0*16]
  64. vmovdqa xmm7, [rsp + 1*16]
  65. vmovdqa xmm13, [rsp + 2*16]
  66. vmovdqa xmm14, [rsp + 3*16]
  67. vmovdqa xmm15, [rsp + 4*16]
  68. add rsp, stack_size
  69. %endmacro
  70. %endif
  71. %define len arg0
  72. %define mul_array arg1
  73. %define src arg2
  74. %define dest arg3
  75. %define pos return
  76. ;;; Use Non-temporal load/stor
  77. %ifdef NO_NT_LDST
  78. %define XLDR vmovdqa
  79. %define XSTR vmovdqa
  80. %else
  81. %define XLDR vmovntdqa
  82. %define XSTR vmovntdq
  83. %endif
  84. default rel
  85. [bits 64]
  86. section .text
  87. %define xmask0f xmm15
  88. %define xgft_lo xmm14
  89. %define xgft_hi xmm13
  90. %define x0 xmm0
  91. %define xtmp1a xmm1
  92. %define xtmp1b xmm2
  93. %define xtmp1c xmm3
  94. %define x1 xmm4
  95. %define xtmp2a xmm5
  96. %define xtmp2b xmm6
  97. %define xtmp2c xmm7
  98. align 16
  99. global gf_vect_mul_avx:ISAL_SYM_TYPE_FUNCTION
  100. func(gf_vect_mul_avx)
  101. %ifidn __OUTPUT_FORMAT__, macho64
  102. global _gf_vect_mul_avx:ISAL_SYM_TYPE_FUNCTION
  103. func(_gf_vect_mul_avx)
  104. %endif
  105. FUNC_SAVE
  106. mov pos, 0
  107. vmovdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  108. vmovdqu xgft_lo, [mul_array] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  109. vmovdqu xgft_hi, [mul_array+16] ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  110. loop32:
  111. XLDR x0, [src+pos] ;Get next source vector
  112. XLDR x1, [src+pos+16] ;Get next source vector + 16B ahead
  113. add pos, 32 ;Loop on 16 bytes at a time
  114. cmp pos, len
  115. vpand xtmp1a, x0, xmask0f ;Mask low src nibble in bits 4-0
  116. vpand xtmp2a, x1, xmask0f
  117. vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
  118. vpsraw x1, x1, 4
  119. vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
  120. vpand x1, x1, xmask0f
  121. vpshufb xtmp1b, xgft_hi, x0 ;Lookup mul table of high nibble
  122. vpshufb xtmp1c, xgft_lo, xtmp1a ;Lookup mul table of low nibble
  123. vpshufb xtmp2b, xgft_hi, x1 ;Lookup mul table of high nibble
  124. vpshufb xtmp2c, xgft_lo, xtmp2a ;Lookup mul table of low nibble
  125. vpxor xtmp1b, xtmp1b, xtmp1c ;GF add high and low partials
  126. vpxor xtmp2b, xtmp2b, xtmp2c
  127. XSTR [dest+pos-32], xtmp1b ;Store result
  128. XSTR [dest+pos-16], xtmp2b ;Store +16B result
  129. jl loop32
  130. return_pass:
  131. FUNC_RESTORE
  132. sub pos, len
  133. ret
  134. return_fail:
  135. FUNC_RESTORE
  136. mov return, 1
  137. ret
  138. endproc_frame
  139. section .data
  140. align 16
  141. mask0f:
  142. dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
  143. ;;; func core, ver, snum
  144. slversion gf_vect_mul_avx, 01, 03, 0036