4 Copyright (C) 2010, 2014 Niels Möller
6 This file is part of GNU Nettle.
8 GNU Nettle is free software: you can redistribute it and/or
9 modify it under the terms of either:
11 * the GNU Lesser General Public License as published by the Free
12 Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
17 * the GNU General Public License as published by the Free
18 Software Foundation; either version 2 of the License, or (at your
19 option) any later version.
21 or both in parallel, as here.
23 GNU Nettle is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 General Public License for more details.
28 You should have received copies of the GNU General Public License and
29 the GNU Lesser General Public License along with this program. If
30 not, see http://www.gnu.org/licenses/.
34 define(<DST>, <%rax>) C Originally in %rdi
42 define(<S1>, <%rdi>) C Overlaps with CNT
44 define(<USE_SSE2>, <no>)
50 C memxor3(void *dst, const void *a, const void *b, size_t n)
54 PROLOGUE(nettle_memxor3)
56 C %cl needed for shift count, so move away N
60 C Get number of unaligned bytes at the end
61 C %rdi is used as CNT, %rax as DST and as return value
72 C FIXME: Instead of this loop, could try cmov with memory
73 C destination, as a sequence of one 8-bit, one 16-bit and one
74 C 32-bit operations. (Except that cmov can't do 8-bit ops, so
75 C that step has to use a conditional).
79 movb (AP, N), LREG(TMP)
80 xorb (BP, N), LREG(TMP)
81 movb LREG(TMP), (DST, N)
86 ifelse(USE_SSE2, yes, <
90 C Check for the case that AP and BP have the same alignment,
91 C but different from DST.
104 C Unrolling, with aligned values alternating in S0 and S1
152 C FIXME: Handle the case N == 16 specially,
153 C like in the non-shifted case?
167 C Next destination word is -8(DST, N)
168 C Setup for unrolling
193 ja .Lword_loop C Not zero and no carry
196 C Final operation is word aligned
206 C ENTRY might have been 3 args, too, but it doesn't matter for the exit
214 movb (AP, N), LREG(TMP)
215 xorb (BP, N), LREG(TMP)
216 movb LREG(TMP), (DST, N)
222 C ENTRY might have been 3 args, too, but it doesn't matter for the exit
226 ifelse(USE_SSE2, yes, <
240 movdqu (AP, N), %xmm0
241 movdqu (BP, N), %xmm1
243 movdqa %xmm1, (DST, N)
248 C FIXME: See if we can do a full word first, before the
249 C byte-wise final loop.
252 C Final operation is aligned
257 C ENTRY might have been 3 args, too, but it doesn't matter for the exit
263 EPILOGUE(nettle_memxor3)