mailing list of musl libc
 help / color / mirror / code / Atom feed
165c422bf174f40b9ba3d3047e701bec47391f48 blob 829 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
29
 
#include <string.h>
#include <stdint.h>

#define byte_repeat(x) ((size_t)~0 / 0xff * (x))
#define word_has_zero(x) (((x) - byte_repeat(0x01)) & ~(x) & byte_repeat(0x80))
#define weak_alias(o, n) extern __typeof__(o) n __attribute__((weak, alias(#o)))

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

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

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

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

bytewise:
	for (; n && s[n - 1] != i; n--);

	return n ? (void *)(s + n - 1) : 0;
}

weak_alias(__memrchr, memrchr);
debug log:

solving 165c422b ...
found 165c422b in https://inbox.vuxu.org/musl/20170715195541.3136-2-nwmcsween@gmail.com/
found a78e9d6c in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 a78e9d6cafa0c700cdeb00c856ac250d932e5ab5	src/string/memrchr.c

applying [1/1] https://inbox.vuxu.org/musl/20170715195541.3136-2-nwmcsween@gmail.com/
diff --git a/src/string/memrchr.c b/src/string/memrchr.c
index a78e9d6c..165c422b 100644

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

index at:
100644 165c422bf174f40b9ba3d3047e701bec47391f48	src/string/memrchr.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).