gf_vect_mul_sse.asm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_sse(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. movdqa xmm6, [rsp + 0*16]
  64. movdqa xmm7, [rsp + 1*16]
  65. movdqa xmm13, [rsp + 2*16]
  66. movdqa xmm14, [rsp + 3*16]
  67. movdqa 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 movdqa
  79. %define XSTR movdqa
  80. %else
  81. %define XLDR movntdqa
  82. %define XSTR movntdq
  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_sse:ISAL_SYM_TYPE_FUNCTION
  100. func(gf_vect_mul_sse)
  101. %ifidn __OUTPUT_FORMAT__, macho64
  102. global _gf_vect_mul_sse:ISAL_SYM_TYPE_FUNCTION
  103. func(_gf_vect_mul_sse)
  104. %endif
  105. FUNC_SAVE
  106. mov pos, 0
  107. movdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  108. movdqu xgft_lo, [mul_array] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  109. movdqu 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. movdqa xtmp1b, xgft_hi ;Reload const array registers
  114. movdqa xtmp1c, xgft_lo
  115. movdqa xtmp2b, xgft_hi
  116. movdqa xtmp2c, xgft_lo
  117. movdqa xtmp1a, x0 ;Keep unshifted copy of src
  118. movdqa xtmp2a, x1
  119. psraw x0, 4 ;Shift to put high nibble into bits 4-0
  120. psraw x1, 4
  121. pand xtmp1a, xmask0f ;Mask low src nibble in bits 4-0
  122. pand xtmp2a, xmask0f
  123. pand x0, xmask0f ;Mask high src nibble in bits 4-0
  124. pand x1, xmask0f
  125. pshufb xtmp1b, x0 ;Lookup mul table of high nibble
  126. pshufb xtmp1c, xtmp1a ;Lookup mul table of low nibble
  127. pshufb xtmp2b, x1
  128. pshufb xtmp2c, xtmp2a
  129. pxor xtmp1b, xtmp1c ;GF add high and low partials
  130. pxor xtmp2b, xtmp2c
  131. XSTR [dest+pos], xtmp1b ;Store result
  132. XSTR [dest+pos+16], xtmp2b ;Store +16B result
  133. add pos, 32 ;Loop on 32 bytes at at time
  134. cmp pos, len
  135. jl loop32
  136. return_pass:
  137. sub pos, len
  138. FUNC_RESTORE
  139. ret
  140. return_fail:
  141. mov return, 1
  142. FUNC_RESTORE
  143. ret
  144. endproc_frame
  145. section .data
  146. align 16
  147. mask0f:
  148. dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
  149. ;;; func core, ver, snum
  150. slversion gf_vect_mul_sse, 00, 03, 0034