Improve backwards compatibility with GNU Make

This commit is contained in:
Justine Tunney 2021-05-02 07:48:59 -07:00
parent fabf7f9f02
commit 1f2288be6e
18 changed files with 412 additions and 96 deletions

View file

@ -17,16 +17,14 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/str/str.h"
noasan static const unsigned char *strchr_x64(const unsigned char *p,
uint64_t c) {
noasan static const char *strchr_x64(const char *p, uint64_t c) {
unsigned a, b;
uint64_t w, x, y;
for (c *= 0x0101010101010101;; p += 8) {
w = (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 |
(uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 |
(uint64_t)p[1] << 010 | (uint64_t)p[0] << 000;
w = READ64LE(p);
if ((x = ~(w ^ c) & ((w ^ c) - 0x0101010101010101) & 0x8080808080808080) |
(y = ~w & (w - 0x0101010101010101) & 0x8080808080808080)) {
if (x) {
@ -63,7 +61,7 @@ char *strchr(const char *s, int c) {
if ((*s & 0xff) == c) return s;
if (!*s) return NULL;
}
r = (char *)strchr_x64((const unsigned char *)s, c);
r = strchr_x64(s, c);
assert(!r || *r || !c);
return r;
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/bits/safemacros.internal.h"
#include "libc/str/str.h"
/**
@ -29,6 +30,8 @@
*/
char *strstr(const char *haystack, const char *needle) {
size_t i;
if (!*needle) return haystack;
haystack = firstnonnull(strchr(haystack, *needle), haystack);
for (;;) {
for (i = 0;;) {
if (!needle[i]) return (/*unconst*/ char *)haystack;

View file

@ -49,6 +49,9 @@ static noasan axdx_t tprecode16to8_sse2(char *dst, size_t dstsize,
/**
* Transcodes UTF-16 to UTF-8.
*
* This is a low-level function intended for the core runtime. Use
* utf16toutf8() for a much better API that uses malloc().
*
* @param dst is output buffer
* @param dstsize is bytes in dst
* @param src is NUL-terminated UTF-16 input string

View file

@ -46,6 +46,9 @@ static inline noasan axdx_t tprecode8to16_sse2(char16_t *dst, size_t dstsize,
/**
* Transcodes UTF-8 to UTF-16.
*
* This is a low-level function intended for the core runtime. Use
* utf8toutf16() for a much better API that uses malloc().
*
* @param dst is output buffer
* @param dstsize is shorts in dst
* @param src is NUL-terminated UTF-8 input string