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_avx2(len, vec, *g_tbls, **buffs, **dests);
34 %include "reg_sizes.asm"
36 %ifidn __OUTPUT_FORMAT__, elf64
49 %define tmp4 r12 ; must be saved and restored
57 %define func(x) x: endbranch
66 %ifidn __OUTPUT_FORMAT__, win64
72 %define arg4 r12 ; must be saved, loaded and restored
77 %define tmp3 r13 ; must be saved and restored
78 %define tmp4 r14 ; must be saved and restored
85 %define stack_size 3*16 + 3*8 ; must be an odd multiple of 8
86 %define arg(x) [rsp + stack_size + PS + PS*x]
88 %define func(x) proc_frame x
90 alloc_stack stack_size
91 vmovdqa [rsp + 0*16], xmm6
92 vmovdqa [rsp + 1*16], xmm7
93 vmovdqa [rsp + 2*16], xmm8
94 save_reg r12, 3*16 + 0*8
95 save_reg r13, 3*16 + 1*8
96 save_reg r14, 3*16 + 2*8
101 %macro FUNC_RESTORE 0
102 vmovdqa xmm6, [rsp + 0*16]
103 vmovdqa xmm7, [rsp + 1*16]
104 vmovdqa xmm8, [rsp + 2*16]
105 mov r12, [rsp + 3*16 + 0*8]
106 mov r13, [rsp + 3*16 + 1*8]
107 mov r14, [rsp + 3*16 + 2*8]
112 %ifidn __OUTPUT_FORMAT__, elf32
114 ;;;================== High Address;
121 ;;;<================= esp of caller
123 ;;;<================= ebp = esp
128 ;;;<================= esp of callee
130 ;;;================== Low Address;
134 %define func(x) x: endbranch
135 %define arg(x) [ebp + PS*2 + PS*x]
136 %define var(x) [ebp - PS - PS*x]
140 %define arg0 trans ;trans and trans2 are for the variables in stack
141 %define arg0_m arg(0)
144 %define arg2_m arg(2)
146 %define arg3_m arg(3)
148 %define arg4_m arg(4)
155 %define tmp4_m var(0)
157 %macro SLDR 2 ;stack load/restore
165 sub esp, PS*1 ;1 local variable
172 %macro FUNC_RESTORE 0
176 add esp, PS*1 ;1 local variable
180 %endif ; output formats
184 %define mul_array arg2
193 %ifidn PS,4 ;32-bit code
196 %define dest1_m arg4_m
197 %define dest2_m tmp4_m
200 %ifndef EC_ALIGNED_ADDR
201 ;;; Use Un-aligned load/store
206 ;;; Use Non-temporal load/stor
211 %define XLDR vmovntdqa
212 %define XSTR vmovntdq
216 %ifidn PS,8 ;64-bit code
223 %ifidn PS,8 ;64-bit code
225 %define xmask0fx xmm8
226 %define xgft1_lo ymm7
227 %define xgft1_hi ymm6
228 %define xgft2_lo ymm5
229 %define xgft2_hi ymm4
237 %define xmask0fx xmm7
238 %define xgft1_lo ymm5
239 %define xgft1_hi ymm4
240 %define xgft2_lo xgft1_lo
241 %define xgft2_hi xgft1_hi
251 mk_global gf_2vect_dot_prod_avx2, function
253 func(gf_2vect_dot_prod_avx2)
261 vpinsrb xmask0fx, xmask0fx, tmp.w, 0
262 vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
264 sal vec, LOG_PS ;vec *= PS. Make vec_i count by PS
266 mov dest2, [dest1+PS]
281 vmovdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
282 ; " Ax{00}, Ax{10}, ..., Ax{f0}
283 vperm2i128 xgft1_hi, xgft1_lo, xgft1_lo, 0x11 ; swapped to hi | hi
284 vperm2i128 xgft1_lo, xgft1_lo, xgft1_lo, 0x00 ; swapped to lo | lo
285 %ifidn PS,8 ; 64-bit code
286 vmovdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
287 ; " Bx{00}, Bx{10}, ..., Bx{f0}
288 vperm2i128 xgft2_hi, xgft2_lo, xgft2_lo, 0x11 ; swapped to hi | hi
289 vperm2i128 xgft2_lo, xgft2_lo, xgft2_lo, 0x00 ; swapped to lo | lo
291 XLDR x0, [ptr+pos] ;Get next source vector
295 XLDR x0, [ptr+pos] ;Get next source vector
298 vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
299 vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
300 vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
302 vpshufb xgft1_hi, x0 ;Lookup mul table of high nibble
303 vpshufb xgft1_lo, xtmpa ;Lookup mul table of low nibble
304 vpxor xgft1_hi, xgft1_lo ;GF add high and low partials
305 vpxor xp1, xgft1_hi ;xp1 += partial
307 %ifidn PS,4 ; 32-bit code
308 vmovdqu xgft2_lo, [tmp+vec*(32/PS)] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
309 ; " Bx{00}, Bx{10}, ..., Bx{f0}
310 vperm2i128 xgft2_hi, xgft2_lo, xgft2_lo, 0x11 ; swapped to hi | hi
311 vperm2i128 xgft2_lo, xgft2_lo, xgft2_lo, 0x00 ; swapped to lo | lo
315 vpshufb xgft2_hi, x0 ;Lookup mul table of high nibble
316 vpshufb xgft2_lo, xtmpa ;Lookup mul table of low nibble
317 vpxor xgft2_hi, xgft2_lo ;GF add high and low partials
318 vpxor xp2, xgft2_hi ;xp2 += partial
325 XSTR [dest1+pos], xp1
326 XSTR [dest2+pos], xp2
329 add pos, 32 ;Loop on 32 bytes at a time
338 mov pos, len ;Overlapped offset length-16
339 jmp .loop32 ;Do one more overlap pass
355 ;;; func core, ver, snum
356 slversion gf_2vect_dot_prod_avx2, 04, 05, 0196