1 ! Copyright (C) 2013 Imagination Technologies Ltd.
3 ! Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
14 !! convert c to unsigned char
22 !! length must be greater than or equal to 8 for aligned loop
28 !! increase alignment counter
32 !! exit if we have a match
35 !! exit if we have hit the end of the string
38 !! fall through if the buffer is aligned now
41 !! fall through if there is more than 8 bytes left
45 !! fill the c into 4 bytes
48 ADD D0Ar4, D0Ar4, D0Ar2
50 ADD D0Ar4, D0Ar4, D0Ar2
52 ADD D0Ar4, D0Ar4, D0Ar2
58 GETL D0Re0, D1Re0, [D0Ar6++]
59 !! decrement loop counter
62 XOR D0Re0, D0Re0, D0Ar4
63 !! test second 4 chars
65 XOR D1Re0, D0Ar2, D0Ar4
66 !! check for matches in the first 4 chars
68 ADDT D0Re0, D0Re0, #HI(0xfefefeff)
69 ADD D0Re0, D0Re0, #LO(0xfefefeff)
71 AND D0Re0, D0Re0, D0Ar2
72 ANDMT D0Re0, D0Re0, #HI(0x80808080)
73 ANDMB D0Re0, D0Re0, #LO(0x80808080)
76 !! check for matches in the second 4 chars
78 ADDT D1Re0, D1Re0, #HI(0xfefefeff)
79 ADD D1Re0, D1Re0, #LO(0xfefefeff)
81 AND D1Re0, D1Re0, D1Ar1
82 ANDMT D1Re0, D1Re0, #HI(0x80808080)
83 ANDMB D1Re0, D1Re0, #LO(0x80808080)
86 !! check if we have reached the end of the buffer
89 !! exit if there are no chars left to check
94 AND D0Ar2, D0Ar4, #0xff
100 !! exit if we have a match
103 !! fall through if we have run out of chars
112 !! move the match word into D1Re0
114 !! roll back the buffer pointer by 4 chars
117 !! roll back the buffer pointer by 4 chars
119 !! exit if lowest byte is 0
121 AND D1Ar1, D1Ar1, #0xff
124 !! advance buffer pointer to the next char
126 !! shift in the next lowest byte
128 !! exit if lowest byte is 0
130 AND D1Ar1, D1Ar1, #0xff
133 !! advance buffer pointer to the next char
135 !! shift in the next lowest byte
137 !! exit if lowest byte is 0
139 AND D1Ar1, D1Ar1, #0xff
142 !! the match must be in the last byte, exit
149 !! return the buffer pointer
154 .size _memchr,.-_memchr
156 libc_hidden_def(memchr)