diff --git a/Makefile b/Makefile index e759e31f0..f73541285 100644 --- a/Makefile +++ b/Makefile @@ -402,6 +402,15 @@ $(SRCS): \ libc/integral/lp64arg.inc \ libc/integral/lp64.inc +.PHONY: toolchain +toolchain: o/cosmopolitan.h \ + o/$(MODE)/ape/public/ape.lds \ + o/$(MODE)/libc/crt/crt.o \ + o/$(MODE)/ape/ape.o \ + o/$(MODE)/ape/ape-copy-self.o \ + o/$(MODE)/ape/ape-no-modify-self.o \ + o/$(MODE)/cosmopolitan.a + # UNSPECIFIED PREREQUISITES TUTORIAL # # A build rule must exist for all files that make needs to consider in diff --git a/examples/forkrand.c b/examples/forkrand.c index 18aad3392..9a02e2a5b 100644 --- a/examples/forkrand.c +++ b/examples/forkrand.c @@ -9,19 +9,12 @@ #endif #include "libc/calls/calls.h" #include "libc/log/check.h" -#include "libc/log/log.h" -#include "libc/nt/nt/process.h" -#include "libc/mem/gc.h" -#include "libc/runtime/memtrack.internal.h" -#include "libc/runtime/runtime.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" -#include "libc/time/time.h" -#include "libc/x/x.h" dontinline void dostuff(const char *s) { int i, us; - srand(rand64()); /* seeds rand() w/ intel rdrnd, auxv, etc. */ + srand(_rand64()); /* seeds rand() w/ intel rdrnd, auxv, etc. */ for (i = 0; i < 5; ++i) { us = rand() % 500000; usleep(us); diff --git a/examples/getrandom.c b/examples/getrandom.c index e60a1b174..baf8df0ce 100644 --- a/examples/getrandom.c +++ b/examples/getrandom.c @@ -102,7 +102,7 @@ uint64_t rngset64(void) { static unsigned i; static uint64_t s; if (!i) { - s = rand64(); + s = _rand64(); i = (s + 1) & (511); } return MarsagliaXorshift64(&s); @@ -215,7 +215,7 @@ const struct Function { {"moby", moby}, // {"mt19937", _mt19937}, // {"python", pythonx2}, // - {"rand64", rand64}, // + {"rand64", _rand64}, // {"rdrand", rdrand}, // {"rdrnd", rdrand}, // {"rdseed", rdseed}, // diff --git a/libc/calls/tmpfd.c b/libc/calls/tmpfd.c index 26ae7f7ea..083595b47 100644 --- a/libc/calls/tmpfd.c +++ b/libc/calls/tmpfd.c @@ -86,7 +86,7 @@ int tmpfd(void) { *p++ = '.'; } for (i = 0; i < 10; ++i) { - x = rand64(); + x = _rand64(); for (j = 0; j < 6; ++j) { p[j] = "0123456789abcdefghijklmnopqrstuvwxyz"[x % 36]; x /= 36; diff --git a/libc/dns/resolvedns.c b/libc/dns/resolvedns.c index 4606ecb16..bf83c3669 100644 --- a/libc/dns/resolvedns.c +++ b/libc/dns/resolvedns.c @@ -63,7 +63,7 @@ int ResolveDns(const struct ResolvConf *resolvconf, int af, const char *name, if (!resolvconf->nameservers.i) return 0; bzero(&h, sizeof(h)); rc = ebadmsg(); - h.id = rand64(); + h.id = _rand64(); h.bf1 = 1; /* recursion desired */ h.qdcount = 1; q.qname = name; diff --git a/libc/dns/resolvednsreverse.c b/libc/dns/resolvednsreverse.c index 4f8b08f8c..5709d1a5e 100644 --- a/libc/dns/resolvednsreverse.c +++ b/libc/dns/resolvednsreverse.c @@ -24,17 +24,17 @@ │ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │ │ OTHER DEALINGS IN THE SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/calls/calls.h" #include "libc/dns/consts.h" #include "libc/dns/dns.h" #include "libc/dns/dnsheader.h" #include "libc/dns/dnsquestion.h" #include "libc/dns/resolvconf.h" +#include "libc/intrin/bits.h" #include "libc/mem/mem.h" -#include "libc/stdio/rand.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" +#include "libc/stdio/rand.h" #include "libc/str/str.h" #include "libc/sysv/consts/af.h" #include "libc/sysv/consts/ipproto.h" @@ -65,7 +65,7 @@ int ResolveDnsReverse(const struct ResolvConf *resolvconf, int af, if (!resolvconf->nameservers.i) return 0; bzero(&h, sizeof(h)); rc = ebadmsg(); - h.id = rand64(); + h.id = _rand64(); h.bf1 = 1; /* recursion desired */ h.qdcount = 1; q.qname = name; diff --git a/libc/intrin/getpid.c b/libc/intrin/getpid.c index badabd355..94b0fb4f1 100644 --- a/libc/intrin/getpid.c +++ b/libc/intrin/getpid.c @@ -29,7 +29,7 @@ * tracked by a global variable which is updated at fork(). The only * exception is when the process is vfork()'d in which case a system * call shall be issued. This optimization helps make functions like - * rand64() fork-safe, however it could lead to race conditions in + * _rand64() fork-safe, however it could lead to race conditions in * programs that mix fork() with threads. In that case, apps should * consider using `sys_getpid().ax` instead to force a system call. * diff --git a/libc/intrin/rand64.c b/libc/intrin/rand64.c index 24aa0e691..97ef4e875 100644 --- a/libc/intrin/rand64.c +++ b/libc/intrin/rand64.c @@ -46,7 +46,7 @@ static struct { * @threadsafe * @vforksafe */ -uint64_t rand64(void) { +uint64_t _rand64(void) { void *p; uint128_t s; if (__threaded) pthread_spin_lock(&g_rand64.lock); diff --git a/libc/stdio/lemur64.c b/libc/stdio/lemur64.c index a28536475..a3a77c5ee 100644 --- a/libc/stdio/lemur64.c +++ b/libc/stdio/lemur64.c @@ -29,7 +29,7 @@ * double x = _real1(lemur64()); // make float on [0,1]-interval * * If you want a fast pseudorandom number generator that seeds itself - * automatically on startup and fork() then consider rand64(). If you + * automatically on startup and fork(), then consider _rand64. If you * want true random data then consider rdseed, rdrand, and getrandom. * * @return 64 bits of pseudorandom data @@ -37,7 +37,7 @@ * @note this function takes at minimum 1 cycle * @note this function passes bigcrush and practrand * @note this function is not intended for cryptography - * @see rand64(), rngset(), _real1(), _real2(), _real3() + * @see _rand64(), rngset(), _real1(), _real2(), _real3() */ uint64_t lemur64(void) { static uint128_t s = 2131259787901769494; diff --git a/libc/stdio/mkdtemp.c b/libc/stdio/mkdtemp.c index 1a62f15e6..b8fcf1b0d 100644 --- a/libc/stdio/mkdtemp.c +++ b/libc/stdio/mkdtemp.c @@ -42,7 +42,7 @@ char *mkdtemp(char *template) { int i, j, n; if ((n = strlen(template)) >= 6 && !memcmp(template + n - 6, "XXXXXX", 6)) { for (i = 0; i < 10; ++i) { - x = rand64(); + x = _rand64(); for (j = 0; j < 6; ++j) { template[n - 6 + j] = "0123456789abcdefghijklmnopqrstuvwxyz"[x % 36]; x /= 36; diff --git a/libc/stdio/mkostempsm.c b/libc/stdio/mkostempsm.c index 8b74f47a2..61c58f437 100644 --- a/libc/stdio/mkostempsm.c +++ b/libc/stdio/mkostempsm.c @@ -77,7 +77,7 @@ static uint64_t g_mkostemps_reseed; dontdiscard int mkostempsm(char *template, int suffixlen, unsigned flags, int mode) { int fd; - if (g_mkostemps_reseed++ % RESEED == 0) g_mkostemps_rand = rand64(); + if (g_mkostemps_reseed++ % RESEED == 0) g_mkostemps_rand = _rand64(); fd = mkostempsmi(template, suffixlen, flags, &g_mkostemps_rand, mode, open); STRACE("mkostempsm([%#s], %'d, %#x, %#o) → %d% m", template, suffixlen, flags, mode, fd); diff --git a/libc/stdio/rand.c b/libc/stdio/rand.c index edbad3b26..fb4800833 100644 --- a/libc/stdio/rand.c +++ b/libc/stdio/rand.c @@ -35,7 +35,7 @@ * * @note this function does well on bigcrush and practrand * @note this function is not intended for cryptography - * @see lemur64(), rand64(), rdrand() + * @see lemur64(), _rand64(), rdrand() */ int rand(void) { return KnuthLinearCongruentialGenerator(&g_rando) >> 33; diff --git a/libc/stdio/rand.h b/libc/stdio/rand.h index 48cf0824c..8e0ebffbf 100644 --- a/libc/stdio/rand.h +++ b/libc/stdio/rand.h @@ -23,7 +23,7 @@ long random(void); void srandom(unsigned); uint64_t lemur64(void); -uint64_t rand64(void); +uint64_t _rand64(void); uint64_t vigna(void); uint64_t vigna_r(uint64_t[hasatleast 1]); void svigna(uint64_t); diff --git a/libc/stdio/rdrand.c b/libc/stdio/rdrand.c index 7b588cd74..d55fa10fb 100644 --- a/libc/stdio/rdrand.c +++ b/libc/stdio/rdrand.c @@ -16,8 +16,8 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/asmflag.h" #include "libc/errno.h" +#include "libc/intrin/asmflag.h" #include "libc/nexgen32e/x86feature.h" #include "libc/stdio/rand.h" #include "libc/sysv/consts/grnd.h" @@ -38,7 +38,7 @@ static dontinline uint64_t rdrand_failover(void) { r = 0; f = 0; } else { - return rand64(); + return _rand64(); } } } @@ -59,7 +59,7 @@ static dontinline uint64_t rdrand_failover(void) { * @note this function could block a nontrivial time on old computers * @note this function is indeed intended for cryptography * @note this function takes around 300 cycles - * @see rngset(), rdseed(), rand64() + * @see rngset(), rdseed(), _rand64() * @asyncsignalsafe * @vforksafe */ diff --git a/libc/stdio/rdseed.c b/libc/stdio/rdseed.c index 3ffe033ec..e68612ce1 100644 --- a/libc/stdio/rdseed.c +++ b/libc/stdio/rdseed.c @@ -34,7 +34,7 @@ * @note this function could block a nontrivial time on old computers * @note this function is indeed intended for cryptography * @note this function takes around 800 cycles - * @see rngset(), rdrand(), rand64() + * @see rngset(), rdrand(), _rand64() * @asyncsignalsafe * @vforksafe */ diff --git a/libc/stdio/vigna.c b/libc/stdio/vigna.c index 5aeb30253..92c26e178 100644 --- a/libc/stdio/vigna.c +++ b/libc/stdio/vigna.c @@ -46,7 +46,7 @@ static uint64_t g_vigna; * rngset(buf, sizeof(buf), vigna, 0); * * If you want a fast pseudorandom number generator that seeds itself - * automatically on startup and fork() then consider rand64(). If you + * automatically on startup and fork(), then consider _rand64. If you * want true random data then consider rdseed, rdrand, and getrandom. * * @return 64 bits of pseudorandom data diff --git a/test/dsp/core/scalevolume_test.c b/test/dsp/core/scalevolume_test.c index 11a646480..d4172fe03 100644 --- a/test/dsp/core/scalevolume_test.c +++ b/test/dsp/core/scalevolume_test.c @@ -22,8 +22,8 @@ #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/stdio/rand.h" #include "libc/runtime/buffer.internal.h" +#include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -146,7 +146,7 @@ TEST(scalevolume, testSmallestScale_justSaturates) { // - ~200ns w/ -O3 -march=skylake MODE=rel void randomizeaudio(void) { - rngset(pcm, sizeof(pcm), rand64, -1); + rngset(pcm, sizeof(pcm), _rand64, -1); } void scalevolume_pure(int amt) { diff --git a/test/dsp/tty/ttymove_test.c b/test/dsp/tty/ttymove_test.c index a52b435b3..47369a746 100644 --- a/test/dsp/tty/ttymove_test.c +++ b/test/dsp/tty/ttymove_test.c @@ -27,7 +27,7 @@ char p[16]; struct TtyCursor c; void SetUp(void) { - rngset(p, sizeof(p), rand64, -1); + rngset(p, sizeof(p), _rand64, -1); } TEST(ttymove, sameCoord_doesNothing) { diff --git a/test/libc/calls/reservefd_test.c b/test/libc/calls/reservefd_test.c index 0d958625f..3383fc776 100644 --- a/test/libc/calls/reservefd_test.c +++ b/test/libc/calls/reservefd_test.c @@ -95,7 +95,7 @@ int Worker(void *p, int tid) { int i, rc, fd; for (i = 0; i < 64; ++i) { ASSERT_NE(-1, (fd = open("/zip/libc/testlib/hyperion.txt", O_RDONLY))); - usleep(rand64() % 100); + usleep(_rand64() % 100); for (;;) { rc = read(fd, buf, 64); if (rc != -1) { diff --git a/test/libc/calls/setrlimit_test.c b/test/libc/calls/setrlimit_test.c index 5f8786256..bc4b0d6bf 100644 --- a/test/libc/calls/setrlimit_test.c +++ b/test/libc/calls/setrlimit_test.c @@ -101,7 +101,7 @@ TEST(setrlimit, testFileSizeLimit) { firstnonnull(getenv("TMPDIR"), "/tmp"), firstnonnull(program_invocation_short_name, "unknown"), getpid()); ASSERT_NE(-1, (fd = open(tmpname, O_RDWR | O_CREAT | O_TRUNC, 0644))); - rngset(junkdata, 512, rand64, -1); + rngset(junkdata, 512, _rand64, -1); for (i = 0; i < 5 * 1024 * 1024 / 512; ++i) { ASSERT_EQ(512, write(fd, junkdata, 512)); } @@ -143,7 +143,7 @@ TEST(setrlimit, testMemoryLimit) { ASSERT_EQ(ENOMEM, errno); _exit(0); } - rngset(p, PAGESIZE, rand64, -1); + rngset(p, PAGESIZE, _rand64, -1); } _exit(1); } @@ -171,7 +171,7 @@ TEST(setrlimit, testVirtualMemoryLimit) { ASSERT_EQ(ENOMEM, errno); _exit(0); } - rngset(p, PAGESIZE, rand64, -1); + rngset(p, PAGESIZE, _rand64, -1); } _exit(1); } @@ -201,7 +201,7 @@ TEST(setrlimit, testDataMemoryLimit) { ASSERT_EQ(ENOMEM, errno); _exit(0); } - rngset(p, PAGESIZE, rand64, -1); + rngset(p, PAGESIZE, _rand64, -1); } _exit(1); } diff --git a/test/libc/dns/dnsheader_test.c b/test/libc/dns/dnsheader_test.c index 712c1031e..782484e34 100644 --- a/test/libc/dns/dnsheader_test.c +++ b/test/libc/dns/dnsheader_test.c @@ -18,9 +18,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/dns/dns.h" #include "libc/dns/dnsheader.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" @@ -39,8 +39,8 @@ TEST(SerializeDnsHeader, test) { TEST(SerializeDnsHeader, fuzzSymmetry) { uint8_t buf[12]; struct DnsHeader in, out; - rngset(&in, sizeof(in), rand64, -1); - rngset(&out, sizeof(out), rand64, -1); + rngset(&in, sizeof(in), _rand64, -1); + rngset(&out, sizeof(out), _rand64, -1); SerializeDnsHeader(buf, &in); DeserializeDnsHeader(&out, buf); ASSERT_EQ(0, memcmp(&in, &out, 12), "%#.*s\n\t%#.*s", 12, in, 12, buf); diff --git a/test/libc/intrin/intrin_test.c b/test/libc/intrin/intrin_test.c index 98d088f58..7a205ba4b 100644 --- a/test/libc/intrin/intrin_test.c +++ b/test/libc/intrin/intrin_test.c @@ -101,10 +101,10 @@ #include "libc/intrin/pxor.h" #include "libc/limits.h" #include "libc/log/check.h" +#include "libc/mem/gc.internal.h" #include "libc/nexgen32e/kcpuids.h" #include "libc/stdio/lcg.internal.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" @@ -2105,8 +2105,8 @@ TEST(pdep, fuzz) { int i; uint64_t x, y; for (i = 0; i < 1000; ++i) { - x = rand64(); - y = rand64(); + x = _rand64(); + y = _rand64(); ASSERT_EQ(pdep(x, y), (pdep)(x, y)); } } @@ -2115,8 +2115,8 @@ TEST(pext, fuzz) { int i; uint64_t x, y; for (i = 0; i < 1000; ++i) { - x = rand64(); - y = rand64(); + x = _rand64(); + y = _rand64(); ASSERT_EQ(pext(x, y), (pext)(x, y)); } } diff --git a/test/libc/intrin/memcmp_test.c b/test/libc/intrin/memcmp_test.c index 44404786c..230e6be30 100644 --- a/test/libc/intrin/memcmp_test.c +++ b/test/libc/intrin/memcmp_test.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" @@ -65,7 +65,7 @@ TEST(memcmp, fuzz) { int i, o, n, g; char a[256], b[256]; for (i = 0; i < 100000; ++i) { - rngset(a, sizeof(a), rand64, -1); + rngset(a, sizeof(a), _rand64, -1); memcpy(b, a, sizeof(a)); if (rand() & 1) { a[rand() % sizeof(a)] += rand(); diff --git a/test/libc/intrin/rand64_test.c b/test/libc/intrin/rand64_test.c index 45ada3724..ed0ca88cf 100644 --- a/test/libc/intrin/rand64_test.c +++ b/test/libc/intrin/rand64_test.c @@ -44,7 +44,7 @@ void OnChld(int sig) { } dontinline void Generate(int i) { - A[i] = rand64(); + A[i] = _rand64(); } int Thrasher(void *arg, int tid) { @@ -56,11 +56,11 @@ int Thrasher(void *arg, int tid) { return 0; } -TEST(rand64, testLcg_doesntProduceIdenticalValues) { +TEST(_rand64, testLcg_doesntProduceIdenticalValues) { int i, j; bzero(A, sizeof(A)); for (i = 0; i < ARRAYLEN(A); ++i) { - A[i] = rand64(); + A[i] = _rand64(); } for (i = 0; i < ARRAYLEN(A); ++i) { EXPECT_NE(0, A[i], "i=%d", i); @@ -71,7 +71,7 @@ TEST(rand64, testLcg_doesntProduceIdenticalValues) { } } -TEST(rand64, testThreadSafety_doesntProduceIdenticalValues) { +TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) { int i, j, rc, ws; sigset_t ss, oldss; struct sigaction oldsa; diff --git a/test/libc/intrin/strlen_test.c b/test/libc/intrin/strlen_test.c index 374ebc647..5a5452d19 100644 --- a/test/libc/intrin/strlen_test.c +++ b/test/libc/intrin/strlen_test.c @@ -114,7 +114,7 @@ TEST(strlen, fuzz) { char *b; size_t n, n1, n2; for (n = 2; n < 1026; ++n) { - b = rngset(calloc(1, n), n - 1, rand64, -1); + b = rngset(calloc(1, n), n - 1, _rand64, -1); n1 = strlen(b); n2 = strlen_pure(b); ASSERT_EQ(n1, n2, "%#.*s", n, b); diff --git a/test/libc/mem/djbsort_test.c b/test/libc/mem/djbsort_test.c index e419a09fb..cc5995273 100644 --- a/test/libc/mem/djbsort_test.c +++ b/test/libc/mem/djbsort_test.c @@ -101,10 +101,10 @@ static int CompareInt(const void *a, const void *b) { BENCH(djbsort, bench) { n = 256; a = _gc(memalign(32, n * 4)); - EZBENCH2("insertionsort[255]", rngset(a, n * 4, rand64, -1), + EZBENCH2("insertionsort[255]", rngset(a, n * 4, _rand64, -1), insertionsort(a, n)); - EZBENCH2("djbsort[255]", rngset(a, n * 4, rand64, -1), djbsort(a, n)); - EZBENCH2("_intsort[255]", rngset(a, n * 4, rand64, -1), _intsort(a, n)); - EZBENCH2("qsort[255]", rngset(a, n * 4, rand64, -1), + EZBENCH2("djbsort[255]", rngset(a, n * 4, _rand64, -1), djbsort(a, n)); + EZBENCH2("_intsort[255]", rngset(a, n * 4, _rand64, -1), _intsort(a, n)); + EZBENCH2("qsort[255]", rngset(a, n * 4, _rand64, -1), qsort(a, n, sizeof(int), CompareInt)); } diff --git a/test/libc/nexgen32e/memmove_test.c b/test/libc/nexgen32e/memmove_test.c index 9fdb0434a..b348e0f9a 100644 --- a/test/libc/nexgen32e/memmove_test.c +++ b/test/libc/nexgen32e/memmove_test.c @@ -42,7 +42,7 @@ TEST(MemMove, overlapping) { for (i = 0; i < N; i += S) { for (j = 0; j < N; j += S) { for (n = MIN(N - i, N - j) + 1; n--;) { - b0 = rngset(malloc(N), N, rand64, -1); + b0 = rngset(malloc(N), N, _rand64, -1); b1 = memcpy(malloc(N), b0, N); b2 = memcpy(malloc(N), b0, N); ASSERT_EQ(b1 + j, memmove(b1 + j, b1 + i, n)); @@ -66,7 +66,7 @@ TEST(MemCpy, overlapping) { for (j = 0; j < N; j += S) { for (n = MIN(N - i, N - j) + 1; n--;) { if (j <= i) { - b0 = rngset(malloc(N), N, rand64, -1); + b0 = rngset(malloc(N), N, _rand64, -1); b1 = memcpy(malloc(N), b0, N); b2 = memcpy(malloc(N), b0, N); ASSERT_EQ(b1 + j, memcpy(b1 + j, b1 + i, n)); @@ -90,7 +90,7 @@ TEST(MemMove, overlappingDirect) { for (i = 0; i < N; i += S) { for (j = 0; j < N; j += S) { for (n = MIN(N - i, N - j) + 1; n--;) { - b0 = rngset(malloc(N), N, rand64, -1); + b0 = rngset(malloc(N), N, _rand64, -1); b1 = memcpy(malloc(N), b0, N); b2 = memcpy(malloc(N), b0, N); ASSERT_EQ(b1 + j, (memmove)(b1 + j, b1 + i, n)); diff --git a/test/libc/nexgen32e/strcaseconv_test.c b/test/libc/nexgen32e/strcaseconv_test.c index cfa827af2..bbd280426 100644 --- a/test/libc/nexgen32e/strcaseconv_test.c +++ b/test/libc/nexgen32e/strcaseconv_test.c @@ -16,10 +16,10 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" @@ -56,7 +56,7 @@ BENCH(strtolower, bench) { EZBENCH2( "strtolower", { - rngset(data, size, rand64, -1); + rngset(data, size, _rand64, -1); data[size - 1] = 0; }, strtolower(data)); diff --git a/test/libc/stdio/fwrite_test.c b/test/libc/stdio/fwrite_test.c index beeed09f0..e8dc45548 100644 --- a/test/libc/stdio/fwrite_test.c +++ b/test/libc/stdio/fwrite_test.c @@ -144,7 +144,7 @@ void MeatyReadWriteTest(void) { char *mem, *buf; n = 8 * 1024 * 1024; buf = gc(malloc(n)); - mem = rngset(gc(malloc(n)), n, rand64, -1); + mem = rngset(gc(malloc(n)), n, _rand64, -1); ASSERT_NE(NULL, (f = fopen(PATH, "wb"))); setbuffer(f, gc(malloc(4 * 1000 * 1000)), 4 * 1000 * 1000); EXPECT_EQ(n, fwrite(mem, 1, n, f)); diff --git a/test/libc/stdio/getrandom_test.c b/test/libc/stdio/getrandom_test.c index d274997b8..963831d73 100644 --- a/test/libc/stdio/getrandom_test.c +++ b/test/libc/stdio/getrandom_test.c @@ -180,7 +180,7 @@ uint64_t Rand64LowByte(void) { uint64_t x; for (x = i = 0; i < 8; ++i) { x <<= 8; - x |= rand64() & 255; + x |= _rand64() & 255; } return x; } @@ -203,7 +203,7 @@ static const struct RandomFunction { {"SixthEditionLowByte", SixthEditionLowByte, false}, // {"SeventhEditionLowByte", SeventhEditionLowByte, false}, // {"KnuthLcg", KnuthLcg, false}, // - {"rand64", rand64, true}, // + {"rand64", _rand64, true}, // {"Rand64LowByte", Rand64LowByte, true}, // {"GetRandom", GetRandom, true}, // }; diff --git a/test/libc/stdio/mt19937_test.c b/test/libc/stdio/mt19937_test.c index b20ef21a4..c0df389ce 100644 --- a/test/libc/stdio/mt19937_test.c +++ b/test/libc/stdio/mt19937_test.c @@ -16,14 +16,14 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/errno.h" +#include "libc/intrin/bits.h" #include "libc/log/check.h" #include "libc/macros.internal.h" -#include "libc/mem/mem.h" -#include "libc/stdio/rand.h" #include "libc/mem/gc.internal.h" +#include "libc/mem/mem.h" #include "libc/runtime/runtime.h" +#include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/grnd.h" #include "libc/testlib/ezbench.h" @@ -157,14 +157,14 @@ TEST(mt19937, test) { BENCH(mt19937, bench8) { volatile uint64_t x; EZBENCH2("lemur64", donothing, x = lemur64()); - EZBENCH2("rand64", donothing, x = rand64()); + EZBENCH2("_rand64", donothing, x = _rand64()); EZBENCH2("vigna", donothing, x = vigna()); EZBENCH2("vigna_r", donothing, vigna_r(&x)); EZBENCH2("xorshift", donothing, x = xorshift()); EZBENCH2("knuth", donothing, x = knuth()); EZBENCH2("random", donothing, x = urandom()); EZBENCH2("mt19937", donothing, x = _mt19937()); - EZBENCH2("rand64char", donothing, x = rand64()); + EZBENCH2("rand64char", donothing, x = _rand64()); size_t i = 0; volatile uint8_t *p = gc(malloc(3 * 2048 * 2 * 8)); EZBENCH3("rdrand", 2048, donothing, p[i++] = rdrand()); @@ -174,7 +174,7 @@ BENCH(mt19937, bench8) { BENCH(mt19937, bench32k) { volatile char *p = gc(malloc(32768)); - EZBENCH_N("rngset(rand64,-1)", 32768, rngset(p, 32768, rand64, -1)); + EZBENCH_N("rngset(_rand64,-1)", 32768, rngset(p, 32768, _rand64, -1)); EZBENCH_N("rngset(rdseed,512)", 32768, rngset(p, 32768, rdseed, 512)); EZBENCH_N("ctrdrbg+rdseed [blk]", 32768, ctrdrbg1(p, 32768)); EZBENCH_N("getrandom [block]", 32768, GetRandom(p, 32768)); @@ -183,7 +183,7 @@ BENCH(mt19937, bench32k) { EZBENCH_N("knuth [word]", 32768, knutha(p, 32768)); EZBENCH_N("random [word]", 32768, rngset(p, 32768, urandom, 0)); EZBENCH_N("mt19937 [word]", 32768, rngset(p, 32768, _mt19937, 0)); - EZBENCH_N("rand64 [word]", 32768, rngset(p, 32768, rand64, 0)); + EZBENCH_N("_rand64 [word]", 32768, rngset(p, 32768, _rand64, 0)); EZBENCH_N("rdrand [word]", 32768, rngset(p, 32768, rdrand, 0)); EZBENCH_N("rdseed [word]", 32768, rngset(p, 32768, rdseed, 0)); } diff --git a/test/libc/stdio/rand_test.c b/test/libc/stdio/rand_test.c index 9af0ac52a..e8188a5c0 100644 --- a/test/libc/stdio/rand_test.c +++ b/test/libc/stdio/rand_test.c @@ -39,16 +39,16 @@ TEST(rand003, srandSmokeTest) { } TEST(rand005, rand64SmokeTest) { - ASSERT_TRUE(rand64() != rand64() || rand64() != rand64()); + ASSERT_TRUE(_rand64() != _rand64() || _rand64() != _rand64()); } -TEST(rand64, test) { +TEST(_rand64, test) { char *p; size_t i; uint64_t x; p = memcpy(malloc(kHyperionSize), kHyperion, kHyperionSize); for (i = 0; i < kHyperionSize / 8; ++i) { - x = rand64(); + x = _rand64(); WRITE64LE(p + i * 8, x); } free(p); diff --git a/test/libc/str/blake2_test.c b/test/libc/str/blake2_test.c index bc669e6e8..2f55e9495 100644 --- a/test/libc/str/blake2_test.c +++ b/test/libc/str/blake2_test.c @@ -68,7 +68,7 @@ TEST(BLAKE2B256Test, ABC) { BENCH(blake2, bench) { char fun[256]; - rngset(fun, 256, rand64, -1); + rngset(fun, 256, _rand64, -1); EZBENCH_N("blake2b256", 0, EZBLAKE2B256(0, 0)); EZBENCH_N("blake2b256", 8, EZBLAKE2B256("helloooo", 8)); EZBENCH_N("blake2b256", 31, EZBLAKE2B256(fun, 31)); diff --git a/test/libc/str/bzero_test.c b/test/libc/str/bzero_test.c index 7cefb35c7..6aeb6faac 100644 --- a/test/libc/str/bzero_test.c +++ b/test/libc/str/bzero_test.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" @@ -30,7 +30,7 @@ TEST(bzero, test) { a = gc(malloc(128)); b = gc(malloc(128)); for (n = 0; n < 128; ++n) { - rngset(a, 128, rand64, -1); + rngset(a, 128, _rand64, -1); memcpy(b, a, 128); bzero(a, n); memset(b, 0, n); diff --git a/test/libc/str/highwayhash64_test.c b/test/libc/str/highwayhash64_test.c index 681d4d853..0284c8d72 100644 --- a/test/libc/str/highwayhash64_test.c +++ b/test/libc/str/highwayhash64_test.c @@ -96,7 +96,7 @@ TEST(highwayhash64, test) { BENCH(highwayhash64, newbench) { char fun[256]; - rngset(fun, 256, rand64, -1); + rngset(fun, 256, _rand64, -1); EZBENCH_N("highwayhash64", 0, HighwayHash64(0, 0, kTestKey1)); EZBENCH_N("highwayhash64", 8, HighwayHash64("helloooo", 8, kTestKey1)); EZBENCH_N("highwayhash64", 31, HighwayHash64(fun, 31, kTestKey1)); diff --git a/test/libc/str/memccpy_test.c b/test/libc/str/memccpy_test.c index 76bb68493..5eba5612f 100644 --- a/test/libc/str/memccpy_test.c +++ b/test/libc/str/memccpy_test.c @@ -56,7 +56,7 @@ TEST(memccpy, memcpy) { b1 = calloc(1, n); b2 = calloc(1, n); b3 = calloc(1, n); - rngset(b1, n, rand64, -1); + rngset(b1, n, _rand64, -1); e1 = memccpy_pure(b2, b1, 31337, n); e2 = memccpy(b3, b1, 31337, n); n1 = e1 ? e1 - b2 : n; diff --git a/test/libc/str/memcpy_test.c b/test/libc/str/memcpy_test.c index aae1f1301..25eee7ec6 100644 --- a/test/libc/str/memcpy_test.c +++ b/test/libc/str/memcpy_test.c @@ -30,8 +30,8 @@ TEST(memcpy, test) { for (unsigned n = 0; n < 1026; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1, memcpy(b1, b2, n), "%ld\n\t%#.*s\n\t%#.*s", n, n, b1, n, b2); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -40,8 +40,8 @@ TEST(memcpy, test) { for (unsigned n = kHalfCache3 - 1; n < kHalfCache3 + 2; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1, memcpy(b1, b2, n), "%ld\n\t%#.*s\n\t%#.*s", n, n, b1, n, b2); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -54,8 +54,8 @@ TEST(mempcpy, test) { for (unsigned n = 0; n < 1026; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1 + n, mempcpy(b1, b2, n)); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -64,8 +64,8 @@ TEST(mempcpy, test) { for (unsigned n = kHalfCache3 - 1; n < kHalfCache3 + 2; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1 + n, mempcpy(b1, b2, n)); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -78,8 +78,8 @@ TEST(memcpy, direct) { for (unsigned n = 0; n < 1026; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1, (memcpy)(b1, b2, n), "%ld\n\t%#.*s\n\t%#.*s", n, n, b1, n, b2); ASSERT_EQ(0, memcmp(b1, b2, n)); @@ -89,8 +89,8 @@ TEST(memcpy, direct) { for (unsigned n = kHalfCache3 - 1; n < kHalfCache3 + 2; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1, (memcpy)(b1, b2, n), "%ld\n\t%#.*s\n\t%#.*s", n, n, b1, n, b2); ASSERT_EQ(0, memcmp(b1, b2, n)); @@ -104,8 +104,8 @@ TEST(mempcpy, direct) { for (unsigned n = 0; n < 1026; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1 + n, (mempcpy)(b1, b2, n)); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -114,8 +114,8 @@ TEST(mempcpy, direct) { for (unsigned n = kHalfCache3 - 1; n < kHalfCache3 + 2; ++n) { b1 = malloc(n); b2 = malloc(n); - rngset(b1, n, rand64, -1); - rngset(b2, n, rand64, -1); + rngset(b1, n, _rand64, -1); + rngset(b2, n, _rand64, -1); ASSERT_EQ(b1 + n, (mempcpy)(b1, b2, n)); ASSERT_EQ(0, memcmp(b1, b2, n)); free(b2); @@ -162,8 +162,8 @@ TEST(memcpy, testBackwardsOverlap3) { #define B(F, N) \ do { \ - char *d = rngset(malloc(N), N, rand64, -1); \ - char *s = rngset(malloc(N), N, rand64, -1); \ + char *d = rngset(malloc(N), N, _rand64, -1); \ + char *s = rngset(malloc(N), N, _rand64, -1); \ EZBENCH2(#F " " #N, donothing, \ EXPROPRIATE(F(VEIL("r", d), VEIL("r", s), N))); \ free(d); \ diff --git a/test/libc/str/strchr_test.c b/test/libc/str/strchr_test.c index a3ae1586d..fec5a6cae 100644 --- a/test/libc/str/strchr_test.c +++ b/test/libc/str/strchr_test.c @@ -118,7 +118,7 @@ TEST(memchr, fuzz) { p = malloc(64); for (i = -2; i < 257; ++i) { for (j = 0; j < 17; ++j) { - rngset(p, 64, rand64, -1); + rngset(p, 64, _rand64, -1); ASSERT_EQ(memchr(p + j, i, 64 - j), memchr_pure(p + j, i, 64 - j)); } } @@ -139,7 +139,7 @@ TEST(strchrnul, fuzz) { p = calloc(1, 64); for (i = -2; i < 257; ++i) { for (j = 0; j < 17; ++j) { - rngset(p, 63, rand64, -1); + rngset(p, 63, _rand64, -1); ASSERT_EQ(strchrnul(p + j, i), strchrnul_pure(p + j, i)); } } @@ -159,7 +159,7 @@ TEST(rawmemchr, fuzz) { p = malloc(64); for (i = -2; i < 257; ++i) { for (j = 0; j < 17; ++j) { - rngset(p, 63, rand64, -1); + rngset(p, 63, _rand64, -1); p[63] = i; ASSERT_EQ(rawmemchr(p + j, i), rawmemchr_pure(p + j, i)); } diff --git a/test/libc/str/strcmp_test.c b/test/libc/str/strcmp_test.c index 2a10c0fab..f7ceb4ff1 100644 --- a/test/libc/str/strcmp_test.c +++ b/test/libc/str/strcmp_test.c @@ -20,10 +20,10 @@ #include "libc/dce.h" #include "libc/intrin/bits.h" #include "libc/macros.internal.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/cachesize.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/mem/gc.internal.h" #include "libc/stdio/rand.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" @@ -506,7 +506,7 @@ dontinline int strcasecmp_pure(const char *a, const char *b) { } char *randomize_buf2str(size_t size, char data[size]) { - rngset(data, size, rand64, -1); + rngset(data, size, _rand64, -1); data[size - 1] = '\0'; return data; } diff --git a/test/net/http/encodebase64_test.c b/test/net/http/encodebase64_test.c index 0d187ac65..f957ead37 100644 --- a/test/net/http/encodebase64_test.c +++ b/test/net/http/encodebase64_test.c @@ -16,9 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" #include "libc/str/str.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" @@ -75,7 +75,7 @@ TEST(EncodeBase64, testOom_returnsNullAndSetsSizeToZero) { TEST(Base64, RoundTrip) { for (i = 0; i < 1000; ++i) { n = rand() % 32; - rngset(b, n, rand64, -1); + rngset(b, n, _rand64, -1); p = EncodeBase64(b, n, &m); q = DecodeBase64(p, m, &m); ASSERT_EQ(n, m); @@ -88,7 +88,7 @@ TEST(Base64, RoundTrip) { TEST(Base64, Fuzz) { for (i = 0; i < 1000; ++i) { n = rand() % 32; - rngset(b, n, rand64, -1); + rngset(b, n, _rand64, -1); free(DecodeBase64(p, m, 0)); } } diff --git a/test/net/https/mbedtls_test.c b/test/net/https/mbedtls_test.c index a29c3265f..72ff3437f 100644 --- a/test/net/https/mbedtls_test.c +++ b/test/net/https/mbedtls_test.c @@ -65,12 +65,12 @@ uint64_t rng[12]; mbedtls_ecp_group grp; int GetEntropy(void *c, unsigned char *p, size_t n) { - rngset(p, n, rand64, -1); + rngset(p, n, _rand64, -1); return 0; } void SetUp(void) { - rngset(rng, sizeof(rng), rand64, -1); + rngset(rng, sizeof(rng), _rand64, -1); } #ifdef MBEDTLS_SELF_TEST @@ -169,7 +169,7 @@ BENCH(p256, bench) { mbedtls_ecp_group_init(&grp); mbedtls_ecp_group_load(&grp, MBEDTLS_ECP_DP_SECP256R1); mbedtls_mpi x = {1, 8, _gc(calloc(8, 8))}; - rngset(x.p, 8 * 8, rand64, -1); + rngset(x.p, 8 * 8, _rand64, -1); EZBENCH2("P-256 modulus MbedTLS MPI lib", donothing, P256_MPI(&x)); EZBENCH2("P-256 modulus Justine rewrite", donothing, P256_JUSTINE(&x)); mbedtls_ecp_group_free(&grp); @@ -704,7 +704,7 @@ TEST(ShiftRightAvx, test1) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[1] = {rand64()}; + uint64_t mem[1] = {_rand64()}; uint64_t want[1]; uint64_t got[1]; memcpy(want, mem, sizeof(mem)); @@ -719,7 +719,7 @@ TEST(ShiftRightAvx, test2) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[2] = {rand64(), rand64()}; + uint64_t mem[2] = {_rand64(), _rand64()}; uint64_t want[2]; uint64_t got[2]; memcpy(want, mem, sizeof(mem)); @@ -735,7 +735,7 @@ TEST(ShiftRightAvx, test3) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[3] = {rand64(), rand64(), rand64()}; + uint64_t mem[3] = {_rand64(), _rand64(), _rand64()}; uint64_t want[3]; uint64_t got[3]; memcpy(want, mem, sizeof(mem)); @@ -752,7 +752,7 @@ TEST(ShiftRightAvx, test4) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[4] = {rand64(), rand64(), rand64(), rand64()}; + uint64_t mem[4] = {_rand64(), _rand64(), _rand64(), _rand64()}; uint64_t want[4]; uint64_t got[4]; memcpy(want, mem, sizeof(mem)); @@ -770,8 +770,8 @@ TEST(ShiftRightAvx, test8) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[8] = {rand64(), rand64(), rand64(), rand64(), - rand64(), rand64(), rand64(), rand64()}; + uint64_t mem[8] = {_rand64(), _rand64(), _rand64(), _rand64(), + _rand64(), _rand64(), _rand64(), _rand64()}; uint64_t want[8]; uint64_t got[8]; memcpy(want, mem, sizeof(mem)); @@ -793,8 +793,8 @@ TEST(ShiftRightAvx, test9) { if (!X86_HAVE(AVX)) return; int i; for (i = 0; i < 10; ++i) { - uint64_t mem[9] = {rand64(), rand64(), rand64(), rand64(), rand64(), - rand64(), rand64(), rand64(), rand64()}; + uint64_t mem[9] = {_rand64(), _rand64(), _rand64(), _rand64(), _rand64(), + _rand64(), _rand64(), _rand64(), _rand64()}; uint64_t want[9]; uint64_t got[9]; memcpy(want, mem, sizeof(mem)); @@ -811,7 +811,7 @@ TEST(ShiftRightAvx, test9) { BENCH(ShiftRight, bench) { if (!X86_HAVE(AVX)) return; uint64_t x[64]; - rngset(x, sizeof(x), rand64, -1); + rngset(x, sizeof(x), _rand64, -1); EZBENCH2("ShiftRight", donothing, ShiftRight(x, 64, 1)); EZBENCH2("ShiftRightAvx", donothing, ShiftRightAvx(x, 64, 1)); EZBENCH2("ShiftRightPure", donothing, ShiftRightPure(x, 64, 1)); @@ -819,7 +819,7 @@ BENCH(ShiftRight, bench) { BENCH(Zeroize, bench) { uint64_t x[64]; - rngset(x, sizeof(x), rand64, -1); + rngset(x, sizeof(x), _rand64, -1); EZBENCH2("memset (64)", donothing, memset(x, 0, sizeof(x))); EZBENCH2("Zeroize (64)", donothing, mbedtls_platform_zeroize(x, 64)); } diff --git a/test/tool/net/sqlite_test.c b/test/tool/net/sqlite_test.c index 39c2381d0..70c5f7255 100644 --- a/test/tool/net/sqlite_test.c +++ b/test/tool/net/sqlite_test.c @@ -92,9 +92,9 @@ void *Worker(void *arg) { for (int j = 0; j < 50; ++j) { ASSERT_EQ(SQLITE_OK, DbExec(db, "BEGIN TRANSACTION")); for (int i = 0; i < 4; ++i) { - ASSERT_EQ(SQLITE_OK, sqlite3_bind_int64(stmt[0], 1, rand64())); + ASSERT_EQ(SQLITE_OK, sqlite3_bind_int64(stmt[0], 1, _rand64())); ASSERT_EQ(SQLITE_OK, sqlite3_bind_text( - stmt[0], 2, kNames[rand64() % ARRAYLEN(kNames)], + stmt[0], 2, kNames[_rand64() % ARRAYLEN(kNames)], -1, SQLITE_TRANSIENT)); ASSERT_EQ(SQLITE_DONE, DbStep(stmt[0])); ASSERT_EQ(SQLITE_OK, sqlite3_reset(stmt[0])); diff --git a/third_party/dlmalloc/init.inc b/third_party/dlmalloc/init.inc index 0309f7feb..51f774542 100644 --- a/third_party/dlmalloc/init.inc +++ b/third_party/dlmalloc/init.inc @@ -83,7 +83,7 @@ static int init_mparams(void) { } else #endif /* USE_DEV_RANDOM */ - magic = (size_t)(rand64() ^ (size_t)0x55555555U); + magic = (size_t)(_rand64() ^ (size_t)0x55555555U); magic |= (size_t)8U; /* ensure nonzero */ magic &= ~(size_t)7U; /* improve chances of fault for bad values */ /* Until memory modes commonly available, use volatile-write */ diff --git a/third_party/mbedtls/test/everest_test.c b/third_party/mbedtls/test/everest_test.c index 79d5c486b..7492d42da 100644 --- a/third_party/mbedtls/test/everest_test.c +++ b/third_party/mbedtls/test/everest_test.c @@ -47,8 +47,8 @@ TEST(everest, tinierVersionBehavesTheSame) { size_t i; uint8_t secret[32], bpoint[32], public[2][32]; for (i = 0; i < 500; ++i) { - rngset(secret, sizeof(secret), rand64, -1); - rngset(bpoint, sizeof(bpoint), rand64, -1); + rngset(secret, sizeof(secret), _rand64, -1); + rngset(bpoint, sizeof(bpoint), _rand64, -1); Hacl_Curve25519_crypto_scalarmult(public[0], secret, bpoint); curve25519(public[1], secret, bpoint); ASSERT_EQ(0, memcmp(public[0], public[1], sizeof(public[0]))); @@ -70,8 +70,8 @@ TEST(everest, tinierVersionBehavesTheSame) { BENCH(everest, bench) { uint8_t secret[32], bpoint[32], public[32]; - rngset(secret, sizeof(secret), rand64, -1); - rngset(bpoint, sizeof(bpoint), rand64, -1); + rngset(secret, sizeof(secret), _rand64, -1); + rngset(bpoint, sizeof(bpoint), _rand64, -1); EZBENCH2("everest", donothing, Hacl_Curve25519_crypto_scalarmult(public, secret, bpoint)); EZBENCH2("mariana", donothing, curve25519(public, secret, bpoint)); diff --git a/third_party/mbedtls/test/secp384r1_test.c b/third_party/mbedtls/test/secp384r1_test.c index 2c78465ba..6981959e4 100644 --- a/third_party/mbedtls/test/secp384r1_test.c +++ b/third_party/mbedtls/test/secp384r1_test.c @@ -32,7 +32,7 @@ int ecp_mod_p384_old(mbedtls_mpi *); int GetEntropy(void *c, unsigned char *p, size_t n) { - rngset(p, n, rand64, -1); + rngset(p, n, _rand64, -1); return 0; } diff --git a/third_party/mbedtls/test/test_suite_ssl.c b/third_party/mbedtls/test/test_suite_ssl.c index 3d6f5e721..ffafcab1f 100644 --- a/third_party/mbedtls/test/test_suite_ssl.c +++ b/third_party/mbedtls/test/test_suite_ssl.c @@ -3709,7 +3709,7 @@ void test_ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac, * hundreds of milliseconds of latency, which we can't have in our pure * testing infrastructure. */ - for( i = block_size; i < buflen; i += max( 1, rand64() & 31 ) ) + for( i = block_size; i < buflen; i += max( 1, _rand64() & 31 ) ) { mbedtls_test_set_step( i ); /* Restore correct pre-encryption record */ @@ -3747,7 +3747,7 @@ void test_ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac, * hundreds of milliseconds of latency, which we can't have in our pure * testing infrastructure. */ - for( i = padlen; i <= pad_max_len; i += max( 1, rand64() & 31 ) ) + for( i = padlen; i <= pad_max_len; i += max( 1, _rand64() & 31 ) ) { mbedtls_test_set_step( i ); /* Restore correct pre-encryption record */ diff --git a/tool/build/calculator.inc b/tool/build/calculator.inc index 3e58c03b6..2a92fb9d8 100644 --- a/tool/build/calculator.inc +++ b/tool/build/calculator.inc @@ -98,4 +98,4 @@ M(1, f, "fpclassify", Fpclassify, fpclassify(x), "nan=0,inf=1,zero=2,subnorm=3,normal=4") M(0, i, "rand", Rand, rand(), "deterministic random number") -M(0, i, "rand64", Rand64, rand64(), "64-bit random number") +M(0, i, "rand64", _Rand64, _rand64(), "64-bit random number") diff --git a/tool/net/echo.c b/tool/net/echo.c index 1b341fba7..2437e5c2e 100644 --- a/tool/net/echo.c +++ b/tool/net/echo.c @@ -70,7 +70,7 @@ void UdpClient(void) { CHECK_NE(-1, (sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))); CHECK_NE(-1, connect(sock, &addr, addrsize)); for (;;) { - rngset(buf, sizeof(buf), rand64, -1); + rngset(buf, sizeof(buf), _rand64, -1); CHECK_NE(-1, write(sock, &addr, addrsize)); } } @@ -106,7 +106,7 @@ void TcpClient(void) { CHECK_NE(-1, (sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))); CHECK_NE(-1, connect(sock, &addr, addrsize)); for (;;) { - rngset(buf, sizeof(buf), rand64, -1); + rngset(buf, sizeof(buf), _rand64, -1); CHECK_NE(-1, write(sock, buf, sizeof(buf))); CHECK_NE(-1, read(sock, buf, sizeof(buf))); } diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index 25961845f..a4f3b6e0d 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -150,7 +150,7 @@ int LuaLemur64(lua_State *L) { } int LuaRand64(lua_State *L) { - return LuaRand(L, rand64); + return LuaRand(L, _rand64); } int LuaRdrand(lua_State *L) { diff --git a/tool/net/redbean.c b/tool/net/redbean.c index e5a7a545f..e7670ef56 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -2611,7 +2611,7 @@ static char *ServeAssetCompressed(struct Asset *a) { dg.i = 0; dg.c = 0; if (usingssl) { - dg.z = 512 + (rand64() & 1023); + dg.z = 512 + (_rand64() & 1023); } else { dg.z = 65536; } diff --git a/tool/viz/generatematrix.c b/tool/viz/generatematrix.c index 744665a9f..c54578129 100644 --- a/tool/viz/generatematrix.c +++ b/tool/viz/generatematrix.c @@ -16,19 +16,19 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/limits.h" #include "libc/log/check.h" #include "libc/log/log.h" #include "libc/macros.internal.h" #include "libc/math.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" +#include "libc/runtime/runtime.h" #include "libc/stdio/lcg.internal.h" #include "libc/stdio/rand.h" -#include "libc/mem/gc.internal.h" -#include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/sysv/consts/ex.h" @@ -184,7 +184,7 @@ void GetOpts(int argc, char *argv[]) { want_double = true; break; case 'g': - rand_ = rand64; + rand_ = _rand64; break; case 'N': name_ = optarg; diff --git a/tool/viz/life.c b/tool/viz/life.c index a3cb922c4..c9e848c1c 100644 --- a/tool/viz/life.c +++ b/tool/viz/life.c @@ -414,8 +414,8 @@ static void OnMouseLeftDrag(long y, long x) { save_x = x; y = top + (y << (zoom + !!zoom)); x = left + (x << zoom); - y += rand64() & ((1ul << (zoom + !!zoom)) - 1); - x += rand64() & ((1ul << zoom) - 1); + y += _rand64() & ((1ul << (zoom + !!zoom)) - 1); + x += _rand64() & ((1ul << zoom) - 1); if (y < 0 || y >= byn) return; if (x < 0 || x >= bxn) return; if (erase) { @@ -819,7 +819,7 @@ static void Rando1(void) { long i, n; n = (byn * bxn) >> 6; for (i = 0; i < n; ++i) { - board[i] = rand64(); + board[i] = _rand64(); } }