mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make AARCH64 harder, better, faster, stronger
- Perform some housekeeping on scalar math function code - Import ARM's Optimized Routines for SIMD string processing - Upgrade to latest Chromium zlib and enable more SIMD optimizations
This commit is contained in:
parent
550b52abf6
commit
cc1732bc42
143 changed files with 15661 additions and 1329 deletions
|
@ -61,6 +61,17 @@ TEST(memcmp, hug) {
|
|||
}
|
||||
}
|
||||
|
||||
static int coerce(int result) {
|
||||
#ifdef __aarch64__
|
||||
// arm's strcmp assembly is nuts and unpredictable, but it's legal
|
||||
if (result < 0) return -1;
|
||||
if (result > 0) return +1;
|
||||
return 0;
|
||||
#else
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(memcmp, fuzz) {
|
||||
int i, o, n, g;
|
||||
char a[256], b[256];
|
||||
|
@ -79,8 +90,18 @@ TEST(memcmp, fuzz) {
|
|||
}
|
||||
o = rand() & 31;
|
||||
n = rand() % (sizeof(a) - o);
|
||||
g = golden(a + o, b + o, n);
|
||||
ASSERT_EQ(g, memcmp(a + o, b + o, n), "n=%d o=%d", n, o);
|
||||
g = coerce(golden(a + o, b + o, n));
|
||||
#if 0
|
||||
if (memcmp(a + o, b + o, n) != g) {
|
||||
kprintf("const size_t g = %d;\n", g);
|
||||
kprintf("const size_t n = %d;\n", n);
|
||||
kprintf("const char a[] = unbingstr(%#.*hhhs); /* %p */\n", n, a + o,
|
||||
a + o);
|
||||
kprintf("const char b[] = unbingstr(%#.*hhhs); /* %p */\n", n, b + o,
|
||||
b + o);
|
||||
}
|
||||
#endif
|
||||
ASSERT_EQ(g, coerce(memcmp(a + o, b + o, n)), "n=%d o=%d", n, o);
|
||||
ASSERT_EQ(!!g, !!bcmp(a + o, b + o, n), "n=%d o=%d", n, o);
|
||||
ASSERT_EQ(!!g, !!timingsafe_bcmp(a + o, b + o, n), "n=%d o=%d", n, o);
|
||||
ASSERT_EQ(MAX(-1, MIN(1, g)), timingsafe_memcmp(a + o, b + o, n),
|
||||
|
|
|
@ -190,9 +190,11 @@ BENCH(strchr, bench2) {
|
|||
char *strlen_(const char *) asm("strlen");
|
||||
char *rawmemchr_(const char *, int) asm("rawmemchr");
|
||||
EZBENCH2("strchr z", donothing, strchr_(kHyperion, 'z'));
|
||||
EZBENCH2("rawmemchr z", donothing, rawmemchr_(kHyperion, 'z'));
|
||||
EZBENCH2("memchr z", donothing, memchr_(kHyperion, 'z', kHyperionSize));
|
||||
EZBENCH2("strchr Z", donothing, strchr_(kHyperion, 'Z'));
|
||||
EZBENCH2("memchr z", donothing, memchr_(kHyperion, 'z', kHyperionSize));
|
||||
EZBENCH2("memchr Z", donothing, memchr_(kHyperion, 'Z', kHyperionSize));
|
||||
EZBENCH2("rawmemchr z", donothing, rawmemchr_(kHyperion, 'z'));
|
||||
EZBENCH2("rawmemchr Z", donothing, rawmemchr_(kHyperion, 'z'));
|
||||
EZBENCH2("rawmemchr \\0", donothing, rawmemchr_(kHyperion, 0));
|
||||
EZBENCH2("strlen", donothing, strlen_(kHyperion));
|
||||
EZBENCH2("memchr Z", donothing, memchr_(kHyperion, 'Z', kHyperionSize));
|
|
@ -1,49 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
|
||||
TEST(crc32, testBigText) {
|
||||
size_t size;
|
||||
void *hyperion;
|
||||
size = kHyperionSize;
|
||||
hyperion = kHyperion;
|
||||
EXPECT_EQ(0xe9ded8e6, crc32(0, hyperion, size));
|
||||
EXPECT_EQ(0xe9ded8e6, crc32_z(0, hyperion, size));
|
||||
if (X86_HAVE(PCLMUL)) {
|
||||
size = ROUNDDOWN(size, 64);
|
||||
EXPECT_EQ(0xc7adc04f, crc32(0, hyperion, size));
|
||||
EXPECT_EQ(0xc7adc04f, crc32_z(0, hyperion, size));
|
||||
EXPECT_EQ(0xc7adc04f,
|
||||
0xffffffffu ^ crc32_pclmul(0 ^ 0xffffffffu, hyperion, size));
|
||||
}
|
||||
}
|
||||
|
||||
#define TESTSTR "libc/calls/typedef/sighandler_t.h"
|
||||
|
||||
BENCH(crc32c, bench) {
|
||||
EZBENCH2("crc32c", donothing,
|
||||
EXPROPRIATE(crc32c(0, VEIL("r", TESTSTR), sizeof(TESTSTR) - 1)));
|
||||
}
|
|
@ -16,17 +16,18 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
|
||||
#define FANATICS "Fanatics"
|
||||
|
||||
|
|
|
@ -17,18 +17,19 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
|
||||
#define FANATICS "Fanatics"
|
||||
|
||||
|
|
|
@ -15,15 +15,16 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/highwayhash64.h"
|
||||
#include "libc/inttypes.h"
|
||||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/highwayhash64.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/zlib/zlib.h"
|
||||
|
||||
#define kMaxSize 64
|
||||
|
||||
|
|
|
@ -472,8 +472,6 @@ TEST(wcscmp, testTwosComplementBane) {
|
|||
TEST(wcsncmp, testTwosComplementBane) {
|
||||
wchar_t *B1 = malloc(4);
|
||||
wchar_t *B2 = malloc(4);
|
||||
B1[1] = L'\0';
|
||||
B2[1] = L'\0';
|
||||
EXPECT_EQ(wcsncmp(memcpy(B1, "\x00\x00\x00\x80", 4),
|
||||
memcpy(B2, "\x00\x00\x00\x80", 4), 1),
|
||||
0);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
|
@ -51,3 +52,9 @@ TEST(asinhl, test) {
|
|||
EXPECT_STREQ("NAN", _gc(xdtoal(_asinhl(NAN))));
|
||||
EXPECT_STREQ("INFINITY", _gc(xdtoal(_asinhl(INFINITY))));
|
||||
}
|
||||
|
||||
BENCH(asinh, bench) {
|
||||
EZBENCH2("asinh", donothing, _asinh(.7)); // ~26ns
|
||||
EZBENCH2("asinhf", donothing, _asinhf(.7)); // ~17ns
|
||||
EZBENCH2("asinhl", donothing, _asinhl(.7)); // ~48ns
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
@ -60,3 +61,9 @@ TEST(sinhf, test) {
|
|||
EXPECT_STREQ("INFINITY", gc(xdtoaf(_sinhf(INFINITY))));
|
||||
EXPECT_STREQ("-INFINITY", gc(xdtoaf(_sinhf(-INFINITY))));
|
||||
}
|
||||
|
||||
BENCH(sinh, bench) {
|
||||
EZBENCH2("sinh", donothing, _sinh(.7)); // ~24ns
|
||||
EZBENCH2("sinhf", donothing, _sinhf(.7)); // ~19ns
|
||||
EZBENCH2("sinhl", donothing, _sinhl(.7)); // ~15ns
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue