mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 16:58:30 +00:00
Make fixes, improvements, and chibicc python bindings
- python now mixes audio 10x faster - python octal notation is restored - chibicc now builds code 3x faster - chibicc now has help documentation - chibicc can now generate basic python bindings - linenoise now supports some paredit-like features See #141
This commit is contained in:
parent
28997f3acb
commit
7061c79c22
121 changed files with 5272 additions and 1928 deletions
|
@ -24,25 +24,6 @@
|
|||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
const signed char kHexToInt[256] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 0x30
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x40
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x50
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x60
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x70
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xa0
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xb0
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xc0
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xd0
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xe0
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xf0
|
||||
};
|
||||
|
||||
uint8_t *EZBLAKE2B256(const char *s, size_t n) {
|
||||
static uint8_t digest[BLAKE2B256_DIGEST_LENGTH];
|
||||
BLAKE2B256(s, n, digest);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/nexgen32e/crc32.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
|
@ -49,7 +50,38 @@ TEST(crc32c, test) {
|
|||
EXPECT_EQ(0xecc9871d, crc32c(0, kHyperion, kHyperionSize));
|
||||
}
|
||||
|
||||
BENCH(crc32c, bench) {
|
||||
EZBENCH2("crc32c", donothing, crc32c(0, kHyperion, kHyperionSize));
|
||||
EZBENCH2("crc32_z", donothing, crc32_z(0, kHyperion, kHyperionSize));
|
||||
noinline uint64_t fnv_hash(char *s, int len) {
|
||||
uint64_t hash = 0xcbf29ce484222325;
|
||||
for (int i = 0; i < len; i++) {
|
||||
hash *= 0x100000001b3;
|
||||
hash ^= (unsigned char)s[i];
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static unsigned KMH(const void *p, unsigned long n) {
|
||||
unsigned h, i;
|
||||
for (h = i = 0; i < n; i++) {
|
||||
h += ((unsigned char *)p)[i];
|
||||
h *= 0x9e3779b1;
|
||||
}
|
||||
return MAX(1, h);
|
||||
}
|
||||
|
||||
BENCH(crc32c, bench) {
|
||||
for (int i = 1; i < 256; i *= 2) {
|
||||
EZBENCH_N("crc32c", i, crc32c(0, kHyperion, i));
|
||||
EZBENCH_N("crc32_z", i, crc32_z(0, kHyperion, i));
|
||||
EZBENCH_N("fnv_hash", i,
|
||||
EXPROPRIATE(fnv_hash(VEIL("r", kHyperion), VEIL("r", i))));
|
||||
EZBENCH_N("KMH", i, EXPROPRIATE(KMH(VEIL("r", kHyperion), VEIL("r", i))));
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
EZBENCH_N("crc32c", kHyperionSize, crc32c(0, kHyperion, kHyperionSize));
|
||||
EZBENCH_N("crc32_z", kHyperionSize, crc32_z(0, kHyperion, kHyperionSize));
|
||||
EZBENCH_N(
|
||||
"fnv_hash", kHyperionSize,
|
||||
EXPROPRIATE(fnv_hash(VEIL("r", kHyperion), VEIL("r", kHyperionSize))));
|
||||
EZBENCH_N("KMH", kHyperionSize,
|
||||
EXPROPRIATE(KMH(VEIL("r", kHyperion), VEIL("r", kHyperionSize))));
|
||||
}
|
||||
|
|
51
test/libc/str/longsort_test.c
Normal file
51
test/libc/str/longsort_test.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*-*- 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 2021 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/alg/alg.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int CompareLong(const void *a, const void *b) {
|
||||
const long *x = a;
|
||||
const long *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(longsort, test) {
|
||||
size_t n = 5000;
|
||||
long *a = gc(calloc(n, sizeof(long)));
|
||||
long *b = gc(calloc(n, sizeof(long)));
|
||||
rngset(a, n * sizeof(long), 0, 0);
|
||||
memcpy(b, a, n * sizeof(long));
|
||||
qsort(a, n, sizeof(long), CompareLong);
|
||||
longsort(b, n);
|
||||
ASSERT_EQ(0, memcmp(b, a, n * sizeof(long)));
|
||||
}
|
||||
|
||||
BENCH(longsort, bench) {
|
||||
size_t n = 1000;
|
||||
long *p1 = gc(malloc(n * sizeof(long)));
|
||||
long *p2 = gc(malloc(n * sizeof(long)));
|
||||
rngset(p1, n * sizeof(long), 0, 0);
|
||||
EZBENCH2("longsort", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n));
|
||||
}
|
60
test/libc/str/qsort_test.c
Normal file
60
test/libc/str/qsort_test.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*-*- 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/alg/alg.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int CompareLong(const void *a, const void *b) {
|
||||
const long *x = a;
|
||||
const long *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(qsort, test) {
|
||||
const int32_t A[][2] = {{4, 'a'}, {65, 'b'}, {2, 'c'}, {-31, 'd'},
|
||||
{0, 'e'}, {99, 'f'}, {2, 'g'}, {83, 'h'},
|
||||
{782, 'i'}, {1, 'j'}};
|
||||
const int32_t B[][2] = {{-31, 'd'}, {0, 'e'}, {1, 'j'}, {2, 'c'},
|
||||
{2, 'g'}, {4, 'a'}, {65, 'b'}, {83, 'h'},
|
||||
{99, 'f'}, {782, 'i'}};
|
||||
int32_t(*M)[2] = malloc(sizeof(A));
|
||||
memcpy(M, B, sizeof(A));
|
||||
qsort(M, ARRAYLEN(A), sizeof(*M), cmpsl);
|
||||
EXPECT_EQ(0, memcmp(M, B, sizeof(B)));
|
||||
free(M);
|
||||
}
|
||||
|
||||
BENCH(qsort, bench) {
|
||||
size_t n = 1000;
|
||||
long *p1 = gc(malloc(n * sizeof(long)));
|
||||
long *p2 = gc(malloc(n * sizeof(long)));
|
||||
rngset(p1, n * sizeof(long), 0, 0);
|
||||
EZBENCH2("qsort", memcpy(p2, p1, n * sizeof(long)),
|
||||
qsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("longsort", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n));
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
#include "libc/rand/rand.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strchr, blank) {
|
||||
|
@ -84,8 +85,8 @@ TEST(strchr, fuzz) {
|
|||
p = calloc(1, 64);
|
||||
for (i = -2; i < 257; ++i) {
|
||||
for (j = 0; j < 17; ++j) {
|
||||
rngset(p, 63, rand64, -1);
|
||||
ASSERT_EQ(strchr(p + j, i), strchr_pure(p + j, i));
|
||||
rngset(p, 63, rdseed, -1);
|
||||
ASSERT_EQ(strchr_pure(p + j, i), strchr(p + j, i));
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
|
@ -165,3 +166,20 @@ TEST(rawmemchr, fuzz) {
|
|||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
BENCH(strchr, bench2) {
|
||||
char *strchr_(const char *, int) asm("strchr");
|
||||
char *strchrnul_(const char *, int) asm("strchrnul");
|
||||
char *memchr_(const char *, int, size_t) asm("memchr");
|
||||
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("rawmemchr \\0", donothing, rawmemchr_(kHyperion, 0));
|
||||
EZBENCH2("strlen", donothing, strlen_(kHyperion));
|
||||
EZBENCH2("memchr Z", donothing, memchr_(kHyperion, 'Z', kHyperionSize));
|
||||
EZBENCH2("strchrnul z", donothing, strchrnul_(kHyperion, 'z'));
|
||||
EZBENCH2("strchrnul Z", donothing, strchrnul_(kHyperion, 'Z'));
|
||||
}
|
||||
|
|
36
test/libc/str/strpbrk_test.c
Normal file
36
test/libc/str/strpbrk_test.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*-*- 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 2021 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/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(strpbrk, test) {
|
||||
EXPECT_STREQ("o", strpbrk("hello", "abco"));
|
||||
EXPECT_EQ(NULL, strpbrk("hello", "ABCO"));
|
||||
}
|
||||
|
||||
BENCH(strpbrk, bench) {
|
||||
char *strchr_(const char *, int) asm("strchr");
|
||||
char *strpbrk_(const char *, const char *) asm("strpbrk");
|
||||
EZBENCH2("strchr", donothing, strchr_(kHyperion, 'z'));
|
||||
EZBENCH2("strpbrk 1", donothing, strpbrk_(kHyperion, "z"));
|
||||
EZBENCH2("strpbrk 2", donothing, strpbrk_(kHyperion, "Zz"));
|
||||
EZBENCH2("strpbrk 10", donothing, strpbrk_(kHyperion, ">@#\6\3\2\5\6Zz"));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue