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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Optimized xor of N source vectors using SSE
31 ;;; int xor_gen_sse(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 16 bytes. Length can be any value.
37 %include "reg_sizes.asm"
39 %ifidn __OUTPUT_FORMAT__, elf64
52 %define func(x) x: endbranch
56 %elifidn __OUTPUT_FORMAT__, win64
67 %define stack_size 2*16 + 8 ; must be an odd multiple of 8
68 %define func(x) proc_frame x
71 alloc_stack stack_size
72 save_xmm128 xmm6, 0*16
73 save_xmm128 xmm7, 1*16
77 movdqa xmm6, [rsp + 0*16]
78 movdqa xmm7, [rsp + 1*16]
83 %elifidn __OUTPUT_FORMAT__, elf32
91 %define func(x) x: endbranch
92 %define arg(x) [ebp+8+PS*x]
93 %define arg2 edi ; must sav/restore
107 %macro FUNC_RESTORE 0
111 mov esp, ebp ;if has frame pointer
115 %endif ; output formats
123 %ifidn PS,8 ; 64-bit code
128 ;;; Use Non-temporal load/stor
133 %define XLDR movntdqa
140 mk_global xor_check_sse, function
143 %ifidn PS,8 ;64-bit code
144 sub vec, 1 ; Keep as offset to last source
146 mov tmp, arg(0) ; Update vec length arg to last source
151 jng return_fail ;Must have at least 2 sources
154 test len, (128-1) ;Check alignment of length
158 len_aligned_128bytes:
161 mov tmp, vec ;Preset to last vector
164 mov tmp2, [arg2+tmp*PS] ;Fetch last pointer in array
165 sub tmp, 1 ;Next vect
166 XLDR xmm0, [tmp2+pos] ;Start with end of array in last vector
167 XLDR xmm1, [tmp2+pos+16] ;Keep xor parity in xmm0-7
168 XLDR xmm2, [tmp2+pos+(2*16)]
169 XLDR xmm3, [tmp2+pos+(3*16)]
170 XLDR xmm4, [tmp2+pos+(4*16)]
171 XLDR xmm5, [tmp2+pos+(5*16)]
172 XLDR xmm6, [tmp2+pos+(6*16)]
173 XLDR xmm7, [tmp2+pos+(7*16)]
176 mov ptr, [arg2+tmp*PS]
178 xorpd xmm0, [ptr+pos] ;Get next vector (source)
179 xorpd xmm1, [ptr+pos+16]
180 xorpd xmm2, [ptr+pos+(2*16)]
181 xorpd xmm3, [ptr+pos+(3*16)]
182 xorpd xmm4, [ptr+pos+(4*16)]
183 xorpd xmm5, [ptr+pos+(5*16)]
184 xorpd xmm6, [ptr+pos+(6*16)]
185 xorpd xmm7, [ptr+pos+(7*16)]
186 ;;; prefetch [ptr+pos+(8*16)]
187 jge next_vect ;Loop for each vect
189 ;; End of vects, chech that all parity regs = 0
190 mov tmp, vec ;Back to last vector
212 ;;; Do one byte at a time for no alignment case
215 mov tmp, vec ;Preset to last vector
218 mov ptr, [arg2+tmp*PS] ;Fetch last pointer in array
219 mov tmp2.b, [ptr+len-1] ;Get array n
222 mov ptr, [arg2+tmp*PS]
223 xor tmp2.b, [ptr+len-1]
227 mov tmp, vec ;Back to last vector
236 test len, (128-1) ;If not 0 and 128bit aligned
237 jz len_aligned_128bytes ; then do aligned case. len = y * 128
239 ;; else we are 8-byte aligned so fall through to recheck
242 ;; Unaligned length cases
247 and tmp3, (128-1) ;Do the unaligned bytes 4-8 at a time
248 mov tmp, vec ;Preset to last vector
250 ;; Run backwards 8 bytes (4B for 32bit) at a time for (tmp3) bytes
252 mov ptr, [arg2+tmp*PS] ;Fetch last pointer in array
253 mov tmp2, [ptr+len-PS] ;Get array n
256 mov ptr, [arg2+tmp*PS] ;Get pointer to next vector
257 xor tmp2, [ptr+len-PS]
259 jge nextvect_Nbytes ;Loop for each source
261 mov tmp, vec ;Back to last vector
268 cmp len, 128 ;Now len is aligned to 128B
269 jge len_aligned_128bytes ;We can do the rest aligned
283 ;;; func core, ver, snum
284 slversion xor_check_sse, 00, 03, 0031