mailing list of musl libc
 help / color / mirror / code / Atom feed
0b3d3d8064a289c0ee0ca14c7be3f65c846c7854 blob 749 bytes (raw)

 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
 
#include <string.h>
#include <stdint.h>

#define aliases __attribute__((__may_alias__))
#define byte_repeat(x) ((size_t)~0 / 0xff * (x))
#define word_has_zero(x) (((x) - byte_repeat(0x01)) & ~(x) & byte_repeat(0x80))

void *memchr(const void *_s, int i, size_t n)
{
	i = (unsigned char)i;
	const unsigned char *s = _s;
	const size_t aliases *ws, wi = byte_repeat(i);

	if (n < sizeof(size_t) * 3) goto bytewise;

	for (; (uintptr_t)s & sizeof(size_t) - 1 && *s != i; s++, n--);
	if ((uintptr_t)s & sizeof(size_t) - 1) return (void *)s;

	ws = (const void *)s;
	for (; n >= sizeof(size_t) && !word_has_zero(*ws ^ wi)
	     ; ws++, n -= sizeof(size_t));
	s = (const void *)ws;

bytewise:
	for (; n && *s != i; s++, n--);

	return n ? (void *)s : 0;
}
debug log:

solving 0b3d3d80 ...
found 0b3d3d80 in https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
found 4daff7bb in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 4daff7bbc4634c6162b0158fc3bc893c9b697d53	src/string/memchr.c

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-3-nwmcsween@gmail.com/
diff --git a/src/string/memchr.c b/src/string/memchr.c
index 4daff7bb..0b3d3d80 100644

Checking patch src/string/memchr.c...
Applied patch src/string/memchr.c cleanly.

index at:
100644 0b3d3d8064a289c0ee0ca14c7be3f65c846c7854	src/string/memchr.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).