1 /* Copyright (c) 2017 SiFive Inc. All rights reserved.
3 This copyrighted material is made available to anyone wishing to use,
4 modify, copy, or redistribute it subject to the terms and conditions
5 of the FreeBSD License. This program is distributed in the hope that
6 it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7 including the implied warranties of MERCHANTABILITY or FITNESS FOR
8 A PARTICULAR PURPOSE. A copy of this license is available at
9 http://www.opensource.org/licenses.
12 #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
13 //memcpy defined in memcpy-asm.S
18 #include "../../string/local.h"
20 #define unlikely(X) __builtin_expect (!!(X), 0)
23 __inhibit_loop_to_libcall
24 memcpy(void *__restrict aa
, const void *__restrict bb
, size_t n
)
26 #define BODY(a, b, t) { \
33 const char *b
= (const char *)bb
;
35 uintptr_t msk
= sizeof (long) - 1;
36 if (unlikely ((((uintptr_t)a
& msk
) != ((uintptr_t)b
& msk
))
37 || n
< sizeof (long)))
40 if (__builtin_expect (a
< end
, 1))
46 if (unlikely (((uintptr_t)a
& msk
) != 0))
47 while ((uintptr_t)a
& msk
)
51 const long *lb
= (const long *)b
;
52 long *lend
= (long *)((uintptr_t)end
& ~msk
);
54 if (unlikely (lend
- la
> 8))
84 if (unlikely (a
< end
))