source: trunk/libs/newlib/src/newlib/libc/machine/xscale/memset.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.6 KB
Line 
1#if defined __thumb__
2
3#include "../../string/memset.c"
4
5#else
6
7#include <string.h>
8#include "xscale.h"
9
10void *
11memset (void *dst, int c, size_t len)
12{
13  int dummy;
14
15  asm volatile ("tst    %0, #0x3"
16#ifndef __OPTIMIZE_SIZE__
17"\n\
18        beq     1f\n\
19        b       2f\n\
200:\n\
21        strb    %1, [%0], #1\n\
22        tst     %0, #0x3\n\
23        beq     1f\n\
242:\n\
25        movs    r3, %2\n\
26        sub     %2, %2, #1\n\
27        bne     0b\n\
28# At this point we know that %2 == len == -1 (since the SUB has already taken\n\
29# place).  If we fall through to the 1: label (as the code used to do), the\n\
30# CMP will detect this negative value and branch to the 2: label.  This will\n\
31# test %2 again, but this time against 0.  The test will fail and the loop\n\
32# at 2: will go on for (almost) ever.  Hence the explicit branch to the end\n\
33# of the hand written assembly code.\n\
34        b       4f\n\
351:\n\
36        cmp     %2, #0x3\n\
37        bls     2f\n\
38        and     %1, %1, #0xff\n\
39        orr     lr, %1, %1, asl #8\n\
40        cmp     %2, #0xf\n\
41        orr     lr, lr, lr, asl #16\n\
42        bls     1f\n\
43        mov     r3, lr\n\
44        mov     r4, lr\n\
45        mov     r5, lr\n\
460:\n\
47        sub     %2, %2, #16\n\
48        stmia   %0!, { r3, r4, r5, lr }\n\
49        cmp     %2, #0xf\n\
50        bhi     0b\n\
511:\n\
52        cmp     %2, #0x7\n\
53        bls     1f\n\
54        mov     r3, lr\n\
550:\n\
56        sub     %2, %2, #8\n\
57        stmia   %0!, { r3, lr }\n\
58        cmp     %2, #0x7\n\
59        bhi     0b\n\
601:\n\
61        cmp     %2, #0x3\n\
62        bls     2f\n\
630:\n\
64        sub     %2, %2, #4\n\
65        str     lr, [%0], #4\n\
66        cmp     %2, #0x3\n\
67        bhi     0b\n\
68"
69#endif /* !__OPTIMIZE_SIZE__ */
70"\n\
712:\n\
72        movs    r3, %2\n\
73        sub     %2, %2, #1\n\
74        beq     4f\n\
750:\n\
76        movs    r3, %2\n\
77        sub     %2, %2, #1\n\
78        strb    %1, [%0], #1\n\
79        bne     0b\n\
804:"
81
82       : "=&r" (dummy), "=&r" (c), "=&r" (len)
83       : "0" (dst), "1" (c), "2" (len)
84       : "memory", "r3", "r4", "r5", "lr");
85
86  return dst;
87}
88 
89#endif
Note: See TracBrowser for help on using the repository browser.