-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlibc_overrides.cc
63 lines (49 loc) · 1.28 KB
/
libc_overrides.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//---------------------------------------------------------------------------
//
// Definitions to improve the performance of standard C functions.
//
//---------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
//---------------------------------------------------------------------------
extern "C" [[gnu::naked]] size_t strlen(const char *p) {
// spell-checker: disable
asm volatile(R"(
push {r0, r4}
lsl r1, r0, #30
beq 2f // p is aligned
1:
ldrb r3, [r0]
cmp r3, #0
beq 5f // terminating '\0' found
add r0, #1
lsl r1, r0, #30
bne 1b // Loop until aligned
2: // p is aligned
ldr r2, =#0x01010101
lsl r3, r2, #7
3: // Process 4 bytes
ldmia r0!, {r1}
sub r4, r1, r2
bic r4, r1
and r4, r3
beq 3b
4: // Trailer of loop.
sub r0, #4
lsr r4, #8
bcs 5f
add r0, #1
lsr r4, #8
bcs 5f
add r0, #1
lsr r4, #8
bcs 5f
add r0, #1
5:
pop {r1, r4}
sub r0, r1
bx lr
)");
// spell-checker: enable
}
//---------------------------------------------------------------------------