2000-11-30 09:57:27 +08:00
|
|
|
#if defined __thumb__
|
|
|
|
|
|
|
|
#include "../../string/memset.c"
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "xscale.h"
|
2018-08-28 02:32:31 +08:00
|
|
|
#include "../../string/local.h"
|
2000-11-30 09:57:27 +08:00
|
|
|
|
|
|
|
void *
|
2018-08-28 02:32:31 +08:00
|
|
|
__inhibit_loop_to_libcall
|
2000-11-30 09:57:27 +08:00
|
|
|
memset (void *dst, int c, size_t len)
|
|
|
|
{
|
|
|
|
int dummy;
|
2002-01-18 01:02:08 +08:00
|
|
|
|
2000-11-30 09:57:27 +08:00
|
|
|
asm volatile ("tst %0, #0x3"
|
|
|
|
#ifndef __OPTIMIZE_SIZE__
|
2002-04-20 08:29:51 +08:00
|
|
|
"\n\
|
|
|
|
beq 1f\n\
|
|
|
|
b 2f\n\
|
|
|
|
0:\n\
|
|
|
|
strb %1, [%0], #1\n\
|
|
|
|
tst %0, #0x3\n\
|
|
|
|
beq 1f\n\
|
|
|
|
2:\n\
|
|
|
|
movs r3, %2\n\
|
|
|
|
sub %2, %2, #1\n\
|
|
|
|
bne 0b\n\
|
|
|
|
# At this point we know that %2 == len == -1 (since the SUB has already taken\n\
|
|
|
|
# place). If we fall through to the 1: label (as the code used to do), the\n\
|
|
|
|
# CMP will detect this negative value and branch to the 2: label. This will\n\
|
|
|
|
# test %2 again, but this time against 0. The test will fail and the loop\n\
|
|
|
|
# at 2: will go on for (almost) ever. Hence the explicit branch to the end\n\
|
|
|
|
# of the hand written assembly code.\n\
|
|
|
|
b 4f\n\
|
|
|
|
1:\n\
|
|
|
|
cmp %2, #0x3\n\
|
|
|
|
bls 2f\n\
|
|
|
|
and %1, %1, #0xff\n\
|
|
|
|
orr lr, %1, %1, asl #8\n\
|
|
|
|
cmp %2, #0xf\n\
|
|
|
|
orr lr, lr, lr, asl #16\n\
|
|
|
|
bls 1f\n\
|
|
|
|
mov r3, lr\n\
|
|
|
|
mov r4, lr\n\
|
|
|
|
mov r5, lr\n\
|
|
|
|
0:\n\
|
|
|
|
sub %2, %2, #16\n\
|
|
|
|
stmia %0!, { r3, r4, r5, lr }\n\
|
|
|
|
cmp %2, #0xf\n\
|
|
|
|
bhi 0b\n\
|
|
|
|
1:\n\
|
|
|
|
cmp %2, #0x7\n\
|
|
|
|
bls 1f\n\
|
|
|
|
mov r3, lr\n\
|
|
|
|
0:\n\
|
|
|
|
sub %2, %2, #8\n\
|
|
|
|
stmia %0!, { r3, lr }\n\
|
|
|
|
cmp %2, #0x7\n\
|
|
|
|
bhi 0b\n\
|
|
|
|
1:\n\
|
|
|
|
cmp %2, #0x3\n\
|
|
|
|
bls 2f\n\
|
|
|
|
0:\n\
|
|
|
|
sub %2, %2, #4\n\
|
|
|
|
str lr, [%0], #4\n\
|
|
|
|
cmp %2, #0x3\n\
|
|
|
|
bhi 0b\n\
|
2000-11-30 09:57:27 +08:00
|
|
|
"
|
|
|
|
#endif /* !__OPTIMIZE_SIZE__ */
|
2002-04-20 08:29:51 +08:00
|
|
|
"\n\
|
|
|
|
2:\n\
|
|
|
|
movs r3, %2\n\
|
|
|
|
sub %2, %2, #1\n\
|
|
|
|
beq 4f\n\
|
|
|
|
0:\n\
|
|
|
|
movs r3, %2\n\
|
|
|
|
sub %2, %2, #1\n\
|
|
|
|
strb %1, [%0], #1\n\
|
|
|
|
bne 0b\n\
|
2002-01-18 01:02:08 +08:00
|
|
|
4:"
|
2000-11-30 09:57:27 +08:00
|
|
|
|
|
|
|
: "=&r" (dummy), "=&r" (c), "=&r" (len)
|
|
|
|
: "0" (dst), "1" (c), "2" (len)
|
|
|
|
: "memory", "r3", "r4", "r5", "lr");
|
2002-01-18 01:02:08 +08:00
|
|
|
|
2000-11-30 09:57:27 +08:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|