38
by Michael Hope
Added the XScale specific routines from Newlib 1.19.0 |
1 |
#include <string.h> |
2 |
#include "xscale.h" |
|
3 |
||
4 |
void * |
|
5 |
memset (void *dst, int c, size_t len) |
|
6 |
{
|
|
7 |
int dummy; |
|
8 |
||
9 |
asm volatile ("tst %0, #0x3" |
|
10 |
#ifndef __OPTIMIZE_SIZE__
|
|
11 |
"\n\ |
|
12 |
beq 1f\n\ |
|
13 |
b 2f\n\ |
|
14 |
0:\n\ |
|
15 |
strb %1, [%0], #1\n\ |
|
16 |
tst %0, #0x3\n\ |
|
17 |
beq 1f\n\ |
|
18 |
2:\n\ |
|
19 |
movs r3, %2\n\ |
|
20 |
sub %2, %2, #1\n\ |
|
21 |
bne 0b\n\ |
|
22 |
# At this point we know that %2 == len == -1 (since the SUB has already taken\n\ |
|
23 |
# place). If we fall through to the 1: label (as the code used to do), the\n\ |
|
24 |
# CMP will detect this negative value and branch to the 2: label. This will\n\ |
|
25 |
# test %2 again, but this time against 0. The test will fail and the loop\n\ |
|
26 |
# at 2: will go on for (almost) ever. Hence the explicit branch to the end\n\ |
|
27 |
# of the hand written assembly code.\n\ |
|
28 |
b 4f\n\ |
|
29 |
1:\n\ |
|
30 |
cmp %2, #0x3\n\ |
|
31 |
bls 2f\n\ |
|
32 |
and %1, %1, #0xff\n\ |
|
33 |
orr lr, %1, %1, asl #8\n\ |
|
34 |
cmp %2, #0xf\n\ |
|
35 |
orr lr, lr, lr, asl #16\n\ |
|
36 |
bls 1f\n\ |
|
37 |
mov r3, lr\n\ |
|
38 |
mov r4, lr\n\ |
|
39 |
mov r5, lr\n\ |
|
40 |
0:\n\ |
|
41 |
sub %2, %2, #16\n\ |
|
42 |
stmia %0!, { r3, r4, r5, lr }\n\ |
|
43 |
cmp %2, #0xf\n\ |
|
44 |
bhi 0b\n\ |
|
45 |
1:\n\ |
|
46 |
cmp %2, #0x7\n\ |
|
47 |
bls 1f\n\ |
|
48 |
mov r3, lr\n\ |
|
49 |
0:\n\ |
|
50 |
sub %2, %2, #8\n\ |
|
51 |
stmia %0!, { r3, lr }\n\ |
|
52 |
cmp %2, #0x7\n\ |
|
53 |
bhi 0b\n\ |
|
54 |
1:\n\ |
|
55 |
cmp %2, #0x3\n\ |
|
56 |
bls 2f\n\ |
|
57 |
0:\n\ |
|
58 |
sub %2, %2, #4\n\ |
|
59 |
str lr, [%0], #4\n\ |
|
60 |
cmp %2, #0x3\n\ |
|
61 |
bhi 0b\n\ |
|
62 |
"
|
|
63 |
#endif /* !__OPTIMIZE_SIZE__ */ |
|
64 |
"\n\ |
|
65 |
2:\n\ |
|
66 |
movs r3, %2\n\ |
|
67 |
sub %2, %2, #1\n\ |
|
68 |
beq 4f\n\ |
|
69 |
0:\n\ |
|
70 |
movs r3, %2\n\ |
|
71 |
sub %2, %2, #1\n\ |
|
72 |
strb %1, [%0], #1\n\ |
|
73 |
bne 0b\n\ |
|
74 |
4:"
|
|
75 |
||
76 |
: "=&r" (dummy), "=&r" (c), "=&r" (len) |
|
77 |
: "0" (dst), "1" (c), "2" (len) |
|
78 |
: "memory", "r3", "r4", "r5", "lr"); |
|
79 |
||
80 |
return dst; |
|
81 |
}
|