1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
15
16
17
18
19
20
21
22
23
24
25
26 srcin .req x0
27 len .req x0
28
29
30 src .req x1
31 data1 .req x2
32 data2 .req x3
33 data2a .req x4
34 has_nul1 .req x5
35 has_nul2 .req x6
36 tmp1 .req x7
37 tmp2 .req x8
38 tmp3 .req x9
39 tmp4 .req x10
40 zeroones .req x11
41 pos .req x12
42
43 #define REP8_01 0x0101010101010101
44 #define REP8_7f 0x7f7f7f7f7f7f7f7f
45 #define REP8_80 0x8080808080808080
46
47 WEAK(strlen)
48 mov zeroones, #REP8_01
49 bic src, srcin, #15
50 ands tmp1, srcin, #15
51 b.ne .Lmisaligned
52
53
54
55
56
57
58
59
60
61
62
63 .Lloop:
64 ldp data1, data2, [src], #16
65 .Lrealigned:
66 sub tmp1, data1, zeroones
67 orr tmp2, data1, #REP8_7f
68 sub tmp3, data2, zeroones
69 orr tmp4, data2, #REP8_7f
70 bic has_nul1, tmp1, tmp2
71 bics has_nul2, tmp3, tmp4
72 ccmp has_nul1, #0, #0, eq
73 b.eq .Lloop
74
75 sub len, src, srcin
76 cbz has_nul1, .Lnul_in_data2
77 CPU_BE( mov data2, data1 )
78 sub len, len, #8
79 mov has_nul2, has_nul1
80 .Lnul_in_data2:
81
82
83
84
85
86
87 CPU_BE( rev data2, data2 )
88 CPU_BE( sub tmp1, data2, zeroones )
89 CPU_BE( orr tmp2, data2, #REP8_7f )
90 CPU_BE( bic has_nul2, tmp1, tmp2 )
91
92 sub len, len, #8
93 rev has_nul2, has_nul2
94 clz pos, has_nul2
95 add len, len, pos, lsr #3
96 ret
97
98 .Lmisaligned:
99 cmp tmp1, #8
100 neg tmp1, tmp1
101 ldp data1, data2, [src], #16
102 lsl tmp1, tmp1, #3
103 mov tmp2, #~0
104
105 CPU_BE( lsl tmp2, tmp2, tmp1 )
106
107 CPU_LE( lsr tmp2, tmp2, tmp1 )
108
109 orr data1, data1, tmp2
110 orr data2a, data2, tmp2
111 csinv data1, data1, xzr, le
112 csel data2, data2, data2a, le
113 b .Lrealigned
114 ENDPIPROC(strlen)
115 EXPORT_SYMBOL_NOKASAN(strlen)