[444] | 1 | #if defined __thumb__ |
---|
| 2 | |
---|
| 3 | #include "../../string/memset.c" |
---|
| 4 | |
---|
| 5 | #else |
---|
| 6 | |
---|
| 7 | #include <string.h> |
---|
| 8 | #include "xscale.h" |
---|
| 9 | |
---|
| 10 | void * |
---|
| 11 | memset (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\ |
---|
| 20 | 0:\n\ |
---|
| 21 | strb %1, [%0], #1\n\ |
---|
| 22 | tst %0, #0x3\n\ |
---|
| 23 | beq 1f\n\ |
---|
| 24 | 2:\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\ |
---|
| 35 | 1:\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\ |
---|
| 46 | 0:\n\ |
---|
| 47 | sub %2, %2, #16\n\ |
---|
| 48 | stmia %0!, { r3, r4, r5, lr }\n\ |
---|
| 49 | cmp %2, #0xf\n\ |
---|
| 50 | bhi 0b\n\ |
---|
| 51 | 1:\n\ |
---|
| 52 | cmp %2, #0x7\n\ |
---|
| 53 | bls 1f\n\ |
---|
| 54 | mov r3, lr\n\ |
---|
| 55 | 0:\n\ |
---|
| 56 | sub %2, %2, #8\n\ |
---|
| 57 | stmia %0!, { r3, lr }\n\ |
---|
| 58 | cmp %2, #0x7\n\ |
---|
| 59 | bhi 0b\n\ |
---|
| 60 | 1:\n\ |
---|
| 61 | cmp %2, #0x3\n\ |
---|
| 62 | bls 2f\n\ |
---|
| 63 | 0:\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\ |
---|
| 71 | 2:\n\ |
---|
| 72 | movs r3, %2\n\ |
---|
| 73 | sub %2, %2, #1\n\ |
---|
| 74 | beq 4f\n\ |
---|
| 75 | 0:\n\ |
---|
| 76 | movs r3, %2\n\ |
---|
| 77 | sub %2, %2, #1\n\ |
---|
| 78 | strb %1, [%0], #1\n\ |
---|
| 79 | bne 0b\n\ |
---|
| 80 | 4:" |
---|
| 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 |
---|