1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2017 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Optimized xor of N source vectors using AVX512
31 ;;; int xor_gen_avx512(int vects, int len, void **array)
33 ;;; Generates xor parity vector from N (vects-1) sources in array of pointers
34 ;;; (**array). Last pointer is the dest.
35 ;;; Vectors must be aligned to 32 bytes. Length can be any value.
37 %include "reg_sizes.asm"
39 %ifdef HAVE_AS_KNOWS_AVX512
41 %ifidn __OUTPUT_FORMAT__, elf64
55 %elifidn __OUTPUT_FORMAT__, win64
62 %define func(x) proc_frame x
64 %define stack_size 2*16 + 8 ;must be an odd multiple of 8
67 alloc_stack stack_size
68 vmovdqu [rsp + 0*16], xmm6
69 vmovdqu [rsp + 1*16], xmm7
73 vmovdqu xmm6, [rsp + 0*16]
74 vmovdqu xmm7, [rsp + 1*316]
78 %endif ;output formats
90 ;;; Use Non-temporal load/stor
95 %define XLDR vmovntdqa
106 global xor_gen_avx512:function
109 sub vec, 2 ;Keep as offset to last source
110 jng return_fail ;Must have at least 2 sources
113 test len, (128-1) ;Check alignment of length
116 len_aligned_128bytes:
121 mov tmp, vec ;Back to last vector
122 mov tmp2, [arg2+vec*PS] ;Fetch last pointer in array
123 sub tmp, 1 ;Next vect
124 XLDR zmm0, [tmp2+pos] ;Start with end of array in last vector
125 XLDR zmm1, [tmp2+pos+64] ;Keep xor parity in xmm0-7
128 mov ptr, [arg2+tmp*PS]
130 XLDR zmm4, [ptr+pos] ;Get next vector (source)
131 XLDR zmm5, [ptr+pos+64]
132 vpxorq zmm0, zmm0, zmm4 ;Add to xor parity
133 vpxorq zmm1, zmm1, zmm5
134 jge next_vect ;Loop for each source
136 mov ptr, [arg2+PS+vec*PS] ;Address of parity vector
137 XSTR [ptr+pos], zmm0 ;Write parity xor vector
138 XSTR [ptr+pos+64], zmm1
149 ;;; Do one byte at a time for no alignment case
151 mov tmp, vec ;Back to last vector
152 mov ptr, [arg2+vec*PS] ;Fetch last pointer in array
153 mov tmp2.b, [ptr+len-1] ;Get array n
156 mov ptr, [arg2+tmp*PS]
157 xor tmp2.b, [ptr+len-1]
162 add tmp, 1 ;Add back to point to last vec
163 mov ptr, [arg2+tmp*PS]
164 mov [ptr+len-1], tmp2.b ;Write parity
171 test len, (128-1) ;If not 0 and 128bit aligned
172 jz len_aligned_128bytes ; then do aligned case. len = y * 128
174 ;; else we are 8-byte aligned so fall through to recheck
177 ;; Unaligned length cases
182 and tmp3, (128-1) ;Do the unaligned bytes 8 at a time
184 ;; Run backwards 8 bytes at a time for (tmp3) bytes
186 mov tmp, vec ;Back to last vector
187 mov ptr, [arg2+vec*PS] ;Fetch last pointer in array
188 mov tmp2, [ptr+len-PS] ;Get array n
191 mov ptr, [arg2+tmp*PS] ;Get pointer to next vector
192 xor tmp2, [ptr+len-PS]
194 jge nextvect_8bytes ;Loop for each source
197 add tmp, 1 ;Add back to point to last vec
198 mov ptr, [arg2+tmp*PS]
199 mov [ptr+len-PS], tmp2 ;Write parity
204 cmp len, 128 ;Now len is aligned to 128B
205 jge len_aligned_128bytes ;We can do the rest aligned
217 %endif ; ifdef HAVE_AS_KNOWS_AVX512