gf_vect_mul_sse.asm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 return rax
  39. %define func(x) x: endbranch
  40. %define FUNC_SAVE
  41. %define FUNC_RESTORE
  42. %elifidn __OUTPUT_FORMAT__, win64
  43. %define arg0 rcx
  44. %define arg1 rdx
  45. %define arg2 r8
  46. %define arg3 r9
  47. %define return rax
  48. %define stack_size 5*16 + 8 ; must be an odd multiple of 8
  49. %define func(x) proc_frame x
  50. %macro FUNC_SAVE 0
  51. alloc_stack stack_size
  52. save_xmm128 xmm6, 0*16
  53. save_xmm128 xmm7, 1*16
  54. save_xmm128 xmm13, 2*16
  55. save_xmm128 xmm14, 3*16
  56. save_xmm128 xmm15, 4*16
  57. end_prolog
  58. %endmacro
  59. %macro FUNC_RESTORE 0
  60. movdqa xmm6, [rsp + 0*16]
  61. movdqa xmm7, [rsp + 1*16]
  62. movdqa xmm13, [rsp + 2*16]
  63. movdqa xmm14, [rsp + 3*16]
  64. movdqa xmm15, [rsp + 4*16]
  65. add rsp, stack_size
  66. %endmacro
  67. %endif
  68. %define len arg0
  69. %define mul_array arg1
  70. %define src arg2
  71. %define dest arg3
  72. %define pos return
  73. %define tmp r11
  74. ;;; Use Non-temporal load/stor
  75. %ifdef NO_NT_LDST
  76. %define XLDR movdqa
  77. %define XSTR movdqa
  78. %else
  79. %define XLDR movntdqa
  80. %define XSTR movntdq
  81. %endif
  82. default rel
  83. [bits 64]
  84. section .text
  85. %define xmask0f xmm15
  86. %define xgft_lo xmm14
  87. %define xgft_hi xmm13
  88. %define x0 xmm0
  89. %define xtmp1a xmm1
  90. %define xtmp1b xmm2
  91. %define xtmp1c xmm3
  92. %define x1 xmm4
  93. %define xtmp2a xmm5
  94. %define xtmp2b xmm6
  95. %define xtmp2c xmm7
  96. align 16
  97. global gf_vect_mul_sse, function
  98. func(gf_vect_mul_sse)
  99. ; Check if length is multiple of 32 bytes
  100. mov tmp, len
  101. and tmp, 0x1f
  102. jnz return_fail
  103. FUNC_SAVE
  104. mov pos, 0
  105. movdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
  106. movdqu xgft_lo, [mul_array] ;Load array Cx{00}, Cx{01}, Cx{02}, ...
  107. movdqu xgft_hi, [mul_array+16] ; " Cx{00}, Cx{10}, Cx{20}, ... , Cx{f0}
  108. loop32:
  109. XLDR x0, [src+pos] ;Get next source vector
  110. XLDR x1, [src+pos+16] ;Get next source vector + 16B ahead
  111. movdqa xtmp1b, xgft_hi ;Reload const array registers
  112. movdqa xtmp1c, xgft_lo
  113. movdqa xtmp2b, xgft_hi
  114. movdqa xtmp2c, xgft_lo
  115. movdqa xtmp1a, x0 ;Keep unshifted copy of src
  116. movdqa xtmp2a, x1
  117. psraw x0, 4 ;Shift to put high nibble into bits 4-0
  118. psraw x1, 4
  119. pand xtmp1a, xmask0f ;Mask low src nibble in bits 4-0
  120. pand xtmp2a, xmask0f
  121. pand x0, xmask0f ;Mask high src nibble in bits 4-0
  122. pand x1, xmask0f
  123. pshufb xtmp1b, x0 ;Lookup mul table of high nibble
  124. pshufb xtmp1c, xtmp1a ;Lookup mul table of low nibble
  125. pshufb xtmp2b, x1
  126. pshufb xtmp2c, xtmp2a
  127. pxor xtmp1b, xtmp1c ;GF add high and low partials
  128. pxor xtmp2b, xtmp2c
  129. XSTR [dest+pos], xtmp1b ;Store result
  130. XSTR [dest+pos+16], xtmp2b ;Store +16B result
  131. add pos, 32 ;Loop on 32 bytes at at time
  132. cmp pos, len
  133. jl loop32
  134. FUNC_RESTORE
  135. return_pass:
  136. xor return, return
  137. ret
  138. return_fail:
  139. mov return, 1
  140. ret
  141. endproc_frame
  142. section .data
  143. align 16
  144. mask0f:
  145. dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f