1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2015 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
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
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.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 ;;; gf_2vect_mad_sse(len, vec, vec_i, mul_array, src, dest);
34 %include "reg_sizes.asm"
38 %ifidn __OUTPUT_FORMAT__, win64
50 %define stack_size 16*9 + 3*8
51 %define arg(x) [rsp + stack_size + PS + PS*x]
52 %define func(x) proc_frame x
56 movdqa [rsp+16*0],xmm6
57 movdqa [rsp+16*1],xmm7
58 movdqa [rsp+16*2],xmm8
59 movdqa [rsp+16*3],xmm9
60 movdqa [rsp+16*4],xmm10
61 movdqa [rsp+16*5],xmm11
62 movdqa [rsp+16*6],xmm12
63 movdqa [rsp+16*7],xmm13
64 movdqa [rsp+16*8],xmm14
65 save_reg r12, 9*16 + 0*8
66 save_reg r15, 9*16 + 1*8
73 movdqa xmm6, [rsp+16*0]
74 movdqa xmm7, [rsp+16*1]
75 movdqa xmm8, [rsp+16*2]
76 movdqa xmm9, [rsp+16*3]
77 movdqa xmm10, [rsp+16*4]
78 movdqa xmm11, [rsp+16*5]
79 movdqa xmm12, [rsp+16*6]
80 movdqa xmm13, [rsp+16*7]
81 movdqa xmm14, [rsp+16*8]
82 mov r12, [rsp + 9*16 + 0*8]
83 mov r15, [rsp + 9*16 + 1*8]
87 %elifidn __OUTPUT_FORMAT__, elf64
105 ;;; gf_2vect_mad_sse(len, vec, vec_i, mul_array, src, dest)
110 %define mul_array arg3
114 %define pos.w return.w
118 %ifndef EC_ALIGNED_ADDR
119 ;;; Use Un-aligned load/store
123 ;;; Use Non-temporal load/stor
128 %define XLDR movntdqa
138 %define xmask0f xmm14
139 %define xgft1_lo xmm13
140 %define xgft1_hi xmm12
141 %define xgft2_lo xmm11
142 %define xgft2_hi xmm10
157 global gf_2vect_mad_sse:function
158 func(gf_2vect_mad_sse)
164 movdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
165 sal vec_i, 5 ;Multiply by 32
167 lea tmp, [mul_array + vec_i]
168 movdqu xgft1_lo,[tmp] ;Load array Ax{00}, Ax{01}, Ax{02}, ...
169 movdqu xgft1_hi, [tmp+16] ; " Ax{00}, Ax{10}, Ax{20}, ... , Ax{f0}
170 movdqu xgft2_lo, [tmp+vec] ;Load array Bx{00}, Bx{01}, Bx{02}, ...
171 movdqu xgft2_hi, [tmp+vec+16] ; " Bx{00}, Bx{10}, Bx{20}, ... , Bx{f0}
172 mov dest2, [dest1+PS]
175 XLDR xtmpd1, [dest1+len] ;backup the last 16 bytes in dest
176 XLDR xtmpd2, [dest2+len] ;backup the last 16 bytes in dest
179 XLDR xd1, [dest1+pos] ;Get next dest vector
180 XLDR xd2, [dest2+pos] ;Get next dest vector
182 XLDR x0, [src+pos] ;Get next source vector
183 movdqa xtmph1, xgft1_hi ;Reload const array registers
184 movdqa xtmpl1, xgft1_lo
185 movdqa xtmph2, xgft2_hi ;Reload const array registers
186 movdqa xtmpl2, xgft2_lo
187 movdqa xtmpa, x0 ;Keep unshifted copy of src
188 psraw x0, 4 ;Shift to put high nibble into bits 4-0
189 pand x0, xmask0f ;Mask high src nibble in bits 4-0
190 pand xtmpa, xmask0f ;Mask low src nibble in bits 4-0
192 pshufb xtmph1, x0 ;Lookup mul table of high nibble
193 pshufb xtmpl1, xtmpa ;Lookup mul table of low nibble
194 pxor xtmph1, xtmpl1 ;GF add high and low partials
197 pshufb xtmph2, x0 ;Lookup mul table of high nibble
198 pshufb xtmpl2, xtmpa ;Lookup mul table of low nibble
199 pxor xtmph2, xtmpl2 ;GF add high and low partials
202 XSTR [dest1+pos], xd1 ;Store result
203 XSTR [dest2+pos], xd2 ;Store result
205 add pos, 16 ;Loop on 16 bytes at a time
214 mov pos, len ;Overlapped offset length-16
215 movdqa xd1, xtmpd1 ;Restore xd1
216 movdqa xd2, xtmpd2 ;Restore xd2
217 jmp .loop16_overlap ;Do one more overlap pass
236 ddq 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f
238 ;;; func core, ver, snum
239 slversion gf_2vect_mad_sse, 00, 01, 0203