Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
static unsigned Bsr(unsigned x) {
static unsigned _Bsr(unsigned x) {
static const char kDebruijn[32] = {
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31,
@ -35,6 +35,8 @@ static unsigned Bsr(unsigned x) {
return kDebruijn[x];
}
TEST(bsr, test) {
ASSERT_EQ(bsr(0xffffffff), Bsr(0xffffffff));
TEST(_bsr, test) {
for (int i = 1; i < 1000; ++i) {
ASSERT_EQ(_bsr(i), _Bsr(i));
}
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -21,7 +21,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -23,7 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -17,10 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -33,23 +33,23 @@ int CompareLong(const void *a, const void *b) {
return 0;
}
TEST(longsort, test) {
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);
_longsort(b, n);
ASSERT_EQ(0, memcmp(b, a, n * sizeof(long)));
}
BENCH(longsort, bench) {
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));
EZBENCH2("_longsort", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n));
EZBENCH2("qsort", memcpy(p2, p1, n * sizeof(long)),
qsort(p2, n, sizeof(long), CompareLong));
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -23,7 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/cachesize.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -20,7 +20,7 @@
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "libc/intrin/tpenc.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -28,34 +28,34 @@ STATIC_YOINK("strwidth");
volatile uint64_t v;
TEST(tpenc, test) {
EXPECT_EQ(0, tpenc(0));
EXPECT_EQ(1, tpenc(1));
EXPECT_EQ(' ', tpenc(' '));
EXPECT_EQ(0x7f, tpenc(0x7f));
EXPECT_EQ(0x008496E2, tpenc(L''));
EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN));
TEST(_tpenc, test) {
EXPECT_EQ(0, _tpenc(0));
EXPECT_EQ(1, _tpenc(1));
EXPECT_EQ(' ', _tpenc(' '));
EXPECT_EQ(0x7f, _tpenc(0x7f));
EXPECT_EQ(0x008496E2, _tpenc(L''));
EXPECT_EQ(0x8080808080FEul, _tpenc(INT_MIN));
}
TEST(tpenc, theimp) {
ASSERT_EQ(0x88989FF0, tpenc(L'😈'));
TEST(_tpenc, theimp) {
ASSERT_EQ(0x88989FF0, _tpenc(L'😈'));
}
TEST(tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1));
TEST(_tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, _tpenc(-1));
}
uint64_t Tpenc(int x) {
return (v = EXPROPRIATE(tpenc(VEIL("r", x))));
uint64_t _Tpenc(int x) {
return (v = EXPROPRIATE(_tpenc(VEIL("r", x))));
}
BENCH(tpenc, bench) {
EZBENCH(donothing, Tpenc(0));
EZBENCH(donothing, Tpenc(1));
EZBENCH(donothing, Tpenc(' '));
EZBENCH(donothing, Tpenc(0x7f));
EZBENCH(donothing, Tpenc(L''));
EZBENCH(donothing, Tpenc(-1));
EZBENCH(donothing, Tpenc(INT_MIN));
BENCH(_tpenc, bench) {
EZBENCH(donothing, _Tpenc(0));
EZBENCH(donothing, _Tpenc(1));
EZBENCH(donothing, _Tpenc(' '));
EZBENCH(donothing, _Tpenc(0x7f));
EZBENCH(donothing, _Tpenc(L''));
EZBENCH(donothing, _Tpenc(-1));
EZBENCH(donothing, _Tpenc(INT_MIN));
fprintf(stderr, "\n");
}

View file

@ -1,168 +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/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/undeflate.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/s.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/zip.h"
#include "libc/zipos/zipos.internal.h"
#include "third_party/zlib/puff.h"
#include "third_party/zlib/zlib.h"
STATIC_YOINK("zip_uri_support");
STATIC_YOINK("libc/testlib/hyperion.txt");
TEST(undeflate, testEmbeddedPlaintextConstant) {
EXPECT_STARTSWITH("The fall of Hyperion - a Dream", kHyperion);
}
TEST(undeflate, testStatCentralDirectory_notFound_noSysCalls) {
uint64_t c;
struct stat st;
stat("/zip/doge.txt", &st); /* warmup */
c = __syscount;
ASSERT_EQ(-1, stat("/zip/doge.txt", &st));
ASSERT_EQ(0, __syscount - c);
ASSERT_EQ(ENOENT, errno);
}
TEST(undeflate, testStatCentralDirectory_isFound_noSysCalls) {
uint64_t c;
struct stat st = {0};
c = __syscount;
ASSERT_NE(-1, stat("/zip/libc/testlib/hyperion.txt", &st));
ASSERT_TRUE(S_ISREG(st.st_mode));
ASSERT_EQ(kHyperionSize, st.st_size);
ASSERT_EQ(0, __syscount - c);
}
TEST(undeflate, testOpenReadCloseEmbeddedZip) {
int fd;
char *data;
ASSERT_NE(-1, (fd = open("/zip/libc/testlib/hyperion.txt", O_RDONLY)));
ASSERT_NE(NULL, (data = gc(malloc(kHyperionSize))));
ASSERT_EQ(kHyperionSize, read(fd, data, kHyperionSize));
EXPECT_EQ(0, memcmp(kHyperion, data, kHyperionSize));
EXPECT_NE(-1, close(fd));
}
TEST(undeflate, testEmbeddedCompressedZipFile_theHardWay) {
int fd;
size_t i;
bool found;
struct stat st;
struct DeflateState ds;
uint8_t *map, *cd, *cf, *lf, *data;
found = false;
ASSERT_NE(-1, (fd = open(FindComBinary(), O_RDONLY)));
ASSERT_NE(-1, fstat(fd, &st));
ASSERT_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
ASSERT_NE(NULL, (cd = GetZipCdir(map, st.st_size)));
ASSERT_GE(ZIP_CDIR_RECORDS(cd), 1);
for (i = 0, cf = map + ZIP_CDIR_OFFSET(cd); i < ZIP_CDIR_RECORDS(cd);
++i, cf += ZIP_CFILE_HDRSIZE(cf)) {
if (strncmp("libc/testlib/hyperion.txt", ZIP_CFILE_NAME(cf),
ZIP_CFILE_NAMESIZE(cf)) == 0) {
lf = map + ZIP_CFILE_OFFSET(cf);
ASSERT_EQ(kZipCompressionDeflate, ZIP_LFILE_COMPRESSIONMETHOD(lf));
ASSERT_EQ(kHyperionSize, ZIP_LFILE_UNCOMPRESSEDSIZE(lf));
undeflate((data = gc(xmalloc(ZIP_LFILE_UNCOMPRESSEDSIZE(lf) * 24))),
ZIP_LFILE_UNCOMPRESSEDSIZE(lf), ZIP_LFILE_CONTENT(lf),
ZIP_LFILE_COMPRESSEDSIZE(lf), &ds);
ASSERT_EQ(ZIP_LFILE_CRC32(lf),
crc32_z(0, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf)));
ASSERT_EQ(0, memcmp(kHyperion, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf)));
found = true;
break;
}
}
ASSERT_NE(-1, munmap(map, st.st_size));
ASSERT_NE(-1, close(fd));
ASSERT_TRUE(found);
}
uint8_t *buf_;
size_t bufsize_;
uint8_t *data_;
size_t compressedsize_;
size_t uncompressedsize_;
struct DeflateState ds_;
void Inflate(void) {
z_stream stream;
stream.next_in = data_;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.avail_in = compressedsize_;
stream.total_in = compressedsize_;
stream.next_out = buf_;
stream.avail_out = bufsize_;
stream.total_out = bufsize_;
CHECK_EQ(Z_OK, inflateInit2(&stream, -MAX_WBITS));
CHECK_EQ(Z_STREAM_END, inflate(&stream, Z_FINISH));
CHECK_EQ(Z_OK, inflateEnd(&stream));
}
void Undeflate(void) {
undeflate(buf_, uncompressedsize_, data_, compressedsize_, &ds_);
}
void Puff(void) {
size_t insize = compressedsize_;
size_t outsize = uncompressedsize_;
CHECK_EQ(0, puff(buf_, &outsize, data_, &insize));
}
BENCH(undeflate, bench) {
size_t cf, lf;
struct Zipos *zipos;
struct ZiposUri path;
zipos = __zipos_get();
path.path = "libc/testlib/hyperion.txt";
path.len = strlen(path.path);
cf = __zipos_find(zipos, &path);
lf = GetZipCfileOffset(zipos->map + cf);
data_ = ZIP_LFILE_CONTENT(zipos->map + lf);
compressedsize_ = ZIP_LFILE_COMPRESSEDSIZE(zipos->map + lf);
uncompressedsize_ = ZIP_LFILE_UNCOMPRESSEDSIZE(zipos->map + lf);
bufsize_ = ROUNDUP(uncompressedsize_, FRAMESIZE / 2);
buf_ = gc(malloc(bufsize_));
EZBENCH(donothing, Puff());
EZBENCH(donothing, Inflate());
EZBENCH(donothing, Undeflate());
}