Rename rand64() to _rand64()

This commit is contained in:
Justine Tunney 2022-10-10 04:12:06 -07:00
parent c424352a0a
commit 7ae556463a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
52 changed files with 141 additions and 139 deletions

View file

@ -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) {

View file

@ -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);
}

View file

@ -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);

View file

@ -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));
}
}

View file

@ -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();

View file

@ -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;

View file

@ -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);

View file

@ -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));
}

View file

@ -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));

View file

@ -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));

View file

@ -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));

View file

@ -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}, //
};

View file

@ -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));
}

View file

@ -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);

View file

@ -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));

View file

@ -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);

View file

@ -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));

View file

@ -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;

View file

@ -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); \

View file

@ -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));
}

View file

@ -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;
}