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_dot_prod_avx(len, vec, *g_tbls, **buffs, **dests);
34 %include "reg_sizes.asm"
36 %ifidn __OUTPUT_FORMAT__, elf64
47 %define tmp4 r12 ; must be saved and restored
64 %ifidn __OUTPUT_FORMAT__, win64
70 %define arg4 r12 ; must be saved, loaded and restored
73 %define tmp3 r13 ; must be saved and restored
74 %define tmp4 r14 ; must be saved and restored
81 %define stack_size 3*16 + 3*8 ; must be an odd multiple of 8
82 %define arg(x) [rsp + stack_size + PS + PS*x]
84 %define func(x) proc_frame x
86 alloc_stack stack_size
87 save_xmm128 xmm6, 0*16
88 save_xmm128 xmm7, 1*16
89 save_xmm128 xmm8, 2*16
90 save_reg r12, 3*16 + 0*8
91 save_reg r13, 3*16 + 1*8
92 save_reg r14, 3*16 + 2*8
98 vmovdqa xmm6, [rsp + 0*16]
99 vmovdqa xmm7, [rsp + 1*16]
100 vmovdqa xmm8, [rsp + 2*16]
101 mov r12, [rsp + 3*16 + 0*8]
102 mov r13, [rsp + 3*16 + 1*8]
103 mov r14, [rsp + 3*16 + 2*8]
108 %ifidn __OUTPUT_FORMAT__, elf32
110 ;;;================== High Address;
117 ;;;<================= esp of caller
119 ;;;<================= ebp = esp
124 ;;;<================= esp of callee
126 ;;;================== Low Address;
131 %define arg(x) [ebp + PS*2 + PS*x]
132 %define var(x) [ebp - PS - PS*x]
136 %define arg0 trans ;trans and trans2 are for the variables in stack
137 %define arg0_m arg(0)
140 %define arg2_m arg(2)
142 %define arg3_m arg(3)
144 %define arg4_m arg(4)
149 %define tmp4_m var(0)
151 %macro SLDR 2 ;; stack load/restore
159 sub esp, PS*1 ;1 local variable
166 %macro FUNC_RESTORE 0
170 add esp, PS*1 ;1 local variable
174 %endif ; output formats
178 %define mul_array arg2
187 %ifidn PS,4 ;32-bit code
190 %define dest1_m arg4_m
191 %define dest2_m tmp4_m
194 %ifndef EC_ALIGNED_ADDR
195 ;;; Use Un-aligned load/store
199 ;;; Use Non-temporal load/stor
204 %define XLDR vmovntdqa
205 %define XSTR vmovntdq
209 %ifidn PS,8 ; 64-bit code
216 %ifidn PS,8 ;64-bit code
218 %define xgft1_lo xmm7
219 %define xgft1_hi xmm6
220 %define xgft2_lo xmm5
221 %define xgft2_hi xmm4
229 %define xgft1_lo xmm7
230 %define xgft1_hi xmm6
231 %define xgft2_lo xgft1_lo
232 %define xgft2_hi xgft1_hi
241 global gf_2vect_dot_prod_avx:function
243 func(gf_2vect_dot_prod_avx)
250 vmovdqa xmask0f, [mask0f] ;Load mask of lower nibble in each byte
251 sal vec, LOG_PS ;vec *= PS. Make vec_i count by PS
253 mov dest2, [dest1+PS]
268 vmovdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
269 vmovdqu xgft1_hi, [tmp+16] ; " Ax{00}, Ax{10}, ..., Ax{f0}
270 %ifidn PS,8 ; 64-bit code
271 vmovdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
272 vmovdqu xgft2_hi, [tmp+vec*(32/PS)+16] ; " Bx{00}, Bx{10}, ..., Bx{f0}
276 XLDR x0, [ptr+pos] ;Get next source vector
278 vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
279 vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
280 vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
282 vpshufb xgft1_hi, x0 ;Lookup mul table of high nibble
283 vpshufb xgft1_lo, xtmpa ;Lookup mul table of low nibble
284 vpxor xgft1_hi, xgft1_lo ;GF add high and low partials
285 vpxor xp1, xgft1_hi ;xp1 += partial
287 %ifidn PS,4 ; 32-bit code
288 vmovdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
289 vmovdqu xgft2_hi, [tmp+vec*(32/PS)+16] ; " Bx{00}, Bx{10}, ..., Bx{f0}
293 vpshufb xgft2_hi, x0 ;Lookup mul table of high nibble
294 vpshufb xgft2_lo, xtmpa ;Lookup mul table of low nibble
295 vpxor xgft2_hi, xgft2_lo ;GF add high and low partials
296 vpxor xp2, xgft2_hi ;xp2 += partial
303 XSTR [dest1+pos], xp1
304 XSTR [dest2+pos], xp2
307 add pos, 16 ;Loop on 16 bytes at a time
316 mov pos, len ;Overlapped offset length-16
317 jmp .loop16 ;Do one more overlap pass
334 mask0f: dq 0x0f0f0f0f0f0f0f0f, 0x0f0f0f0f0f0f0f0f
336 ;;; func core, ver, snum
337 slversion gf_2vect_dot_prod_avx, 02, 05, 0191