From 7478241c8293f9be68f75de35a22abdcf12a755b Mon Sep 17 00:00:00 2001 From: "Frank J. T. Wojcik" Date: Fri, 28 Jul 2023 22:06:03 -0700 Subject: [PATCH] Tweak the types of various loop index and bounds variables (NFC) This is done to ensure comparisons are done between types of the same type, or at least signedness. --- hashes/ascon.cpp | 2 +- hashes/chaskey.cpp | 2 +- hashes/cityhash.cpp | 2 +- hashes/farsh.cpp | 6 +++--- hashes/poly_mersenne.cpp | 4 ++-- hashes/rmd.cpp | 2 +- hashes/sha3.cpp | 2 +- hashes/wyhash.cpp | 2 +- hashes/xxhash.cpp | 2 +- tests/AvalancheTest.cpp | 6 +++--- tests/BadSeedsTest.cpp | 24 ++++++++++++------------ tests/BitIndependenceTest.cpp | 12 ++++++------ tests/DifferentialTest.cpp | 6 +++--- tests/PerlinNoiseTest.cpp | 10 +++++----- tests/PermutationKeysetTest.cpp | 2 +- tests/PopcountTest.cpp | 10 +++++----- tests/SanityTest.cpp | 18 +++++++++--------- tests/SeedAvalancheTest.cpp | 6 +++--- tests/SeedBitIndependenceTest.cpp | 12 ++++++------ tests/SeedTest.cpp | 4 ++-- tests/SeedZeroesTest.cpp | 6 +++--- tests/SparseKeysetTest.cpp | 2 +- util/Analyze.cpp | 8 ++++---- util/Blobsort.cpp | 10 +++++----- util/Blobsort.h | 6 +++--- util/Stats.cpp | 4 ++-- util/VCode.cpp | 4 ++-- 27 files changed, 87 insertions(+), 87 deletions(-) diff --git a/hashes/ascon.cpp b/hashes/ascon.cpp index 08c1bc32..fdcb72c0 100644 --- a/hashes/ascon.cpp +++ b/hashes/ascon.cpp @@ -441,7 +441,7 @@ static const uint8_t KAT[KAT_NUM][2][256 / 8] = { static bool ascon_xof_selftest( void ) { uint8_t input[KAT_NUM - 1]; - for (int i = 0; i < sizeof(input); i++) { input[i] = (uint8_t)i; } + for (size_t i = 0; i < sizeof(input); i++) { input[i] = (uint8_t)i; } bool passed = true; for (int i = 0; i < KAT_NUM; i++) { diff --git a/hashes/chaskey.cpp b/hashes/chaskey.cpp index 17c50dd2..c10ac10e 100644 --- a/hashes/chaskey.cpp +++ b/hashes/chaskey.cpp @@ -84,7 +84,7 @@ static void chaskey_impl( uint8_t * tag, const uint8_t * m, const size_t mlen, c v[2] ^= lastkey[2]; v[3] ^= lastkey[3]; - for (int i = 0; i < tagwords; i++) { + for (uint32_t i = 0; i < tagwords; i++) { PUT_U32(v[i], tag, 4 * i); } } diff --git a/hashes/cityhash.cpp b/hashes/cityhash.cpp index 0bc2f54f..e062f4ea 100644 --- a/hashes/cityhash.cpp +++ b/hashes/cityhash.cpp @@ -158,7 +158,7 @@ static uint32_t Hash32Len0to4( const uint8_t * s, size_t len, uint32_t seed ) { uint32_t b = seed; uint32_t c = 9; - for (int i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { b = b * c1 + s[i]; c ^= b; } diff --git a/hashes/farsh.cpp b/hashes/farsh.cpp index d9b0812c..44d98f93 100644 --- a/hashes/farsh.cpp +++ b/hashes/farsh.cpp @@ -104,7 +104,7 @@ static uint64_t farsh_full_block( const uint8_t * data, const uint32_t * key ) { const __m256i * xdata = (const __m256i *)data; const __m256i * xkey = (const __m256i *)key; - for (int i = 0; i < STRIPE / sizeof(__m256i); i++) { + for (size_t i = 0; i < STRIPE / sizeof(__m256i); i++) { __m256i d = _mm256_loadu_si256(xdata + i); if (bswap) { d = mm256_bswap32(d); } __m256i k = _mm256_loadu_si256(xkey + i ); @@ -152,7 +152,7 @@ static uint64_t farsh_full_block( const uint8_t * data, const uint32_t * key ) { #else #define FARSH_IMPL_STR "portable" sum64 = 0; - for (int i = 0; i < STRIPE_ELEMENTS; i += 2) { + for (size_t i = 0; i < STRIPE_ELEMENTS; i += 2) { sum64 += (GET_U32(data, i * 4) + key[i]) * (uint64_t)(GET_U32(data, (i + 1) * 4) + key[i + 1]); } @@ -171,7 +171,7 @@ static uint64_t farsh_partial_block( const uint8_t * data, size_t bytes, const u memcpy(extra_data, data + 4 * elements, extra_bytes); - int i; + size_t i; for (i = 0; i < elements; i += 2) { sum += (GET_U32(data, i * 4) + key[i]) * (uint64_t)(GET_U32(data, (i + 1) * 4) + key[i + 1]); diff --git a/hashes/poly_mersenne.cpp b/hashes/poly_mersenne.cpp index 552788e9..703876a5 100644 --- a/hashes/poly_mersenne.cpp +++ b/hashes/poly_mersenne.cpp @@ -97,7 +97,7 @@ static uintptr_t poly_mersenne_seed_init( const seed_t seed ) { // a has be at most 2^60, or the lazy modular reduction won't work. poly_mersenne_data.poly_mersenne_a = rand_u128(&BSD_nextrand) % (MERSENNE_61 / 2); poly_mersenne_data.poly_mersenne_b = rand_u128(&BSD_nextrand) % MERSENNE_61; - for (int i = 0; i < POLY_MERSENNE_MAX_K + 1; i++) { + for (uint32_t i = 0; i < POLY_MERSENNE_MAX_K + 1; i++) { // The random values should be at most 2^61-2, or the lazy // modular reduction won't work. poly_mersenne_data.poly_mersenne_random[i] = rand_u128(&BSD_nextrand) % MERSENNE_61; @@ -152,7 +152,7 @@ static void Poly_Mersenne( const void * in, const size_t len, const seed_t seed, if (K != 0) { uint64_t h0 = h; h = data->poly_mersenne_random[0]; - for (int i = 1; i <= std::min(K, POLY_MERSENNE_MAX_K); i++) { + for (uint32_t i = 1; i <= std::min(K, POLY_MERSENNE_MAX_K); i++) { h = mult_combine61(h, h0, data->poly_mersenne_random[i]); } } diff --git a/hashes/rmd.cpp b/hashes/rmd.cpp index a8251479..2dbc37ac 100644 --- a/hashes/rmd.cpp +++ b/hashes/rmd.cpp @@ -473,7 +473,7 @@ static void rmd_init( rmd_ctx * ctx ) { template static void rmd_done( rmd_ctx * ctx, uint8_t * out ) { - int i; + unsigned int i; /* increase the length of the message */ ctx->length += ctx->curlen * 8; diff --git a/hashes/sha3.cpp b/hashes/sha3.cpp index 47cf416c..9090743a 100644 --- a/hashes/sha3.cpp +++ b/hashes/sha3.cpp @@ -205,7 +205,7 @@ static void sha3_Finalize( sha3_context * ctx, size_t digest_words, uint8_t * di uint32_t maxdigest_words = ctx->capacityWords / 2; if (digest_words > maxdigest_words) { digest_words = maxdigest_words; } - for (int i = 0; i < digest_words; i++) { + for (size_t i = 0; i < digest_words; i++) { PUT_U64(ctx->s[i], digest, 8 * i); } diff --git a/hashes/wyhash.cpp b/hashes/wyhash.cpp index 22f7adf2..ce743d7b 100644 --- a/hashes/wyhash.cpp +++ b/hashes/wyhash.cpp @@ -209,7 +209,7 @@ static bool wyhash64_selftest( void ) { }, }; - for (int i = 0; i < sizeof(selftests) / sizeof(selftests[0]); i++) { + for (size_t i = 0; i < sizeof(selftests) / sizeof(selftests[0]); i++) { uint64_t h; if (isLE()) { Wyhash64(selftests[i].key, strlen(selftests[i].key), i, &h); diff --git a/hashes/xxhash.cpp b/hashes/xxhash.cpp index 01484da5..dd2be2ff 100644 --- a/hashes/xxhash.cpp +++ b/hashes/xxhash.cpp @@ -699,7 +699,7 @@ static NEVER_INLINE uint64_t XXH3_len_129to240_64b( const uint8_t * RESTRICT inp #pragma clang loop vectorize(disable) #endif - for (int i = 8; i < nbRounds; i++) { + for (unsigned i = 8; i < nbRounds; i++) { /* * Prevents clang for unrolling the acc loop and interleaving with this one. */ diff --git a/tests/AvalancheTest.cpp b/tests/AvalancheTest.cpp index 8478455c..a8523b52 100644 --- a/tests/AvalancheTest.cpp +++ b/tests/AvalancheTest.cpp @@ -139,16 +139,16 @@ static bool AvalancheImpl( HashFn hash, const seed_t seed, const int keybits, } else { #if defined(HAVE_THREADS) std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { calcBiasRange, hash, seed, std::ref(bins[i]), keybytes, &keys[0], std::ref(irep), reps, drawdots }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } - for (int i = 1; i < g_NCPU; i++) { + for (unsigned i = 1; i < g_NCPU; i++) { for (int b = 0; b < arraysize; b++) { bins[0][b] += bins[i][b]; } diff --git a/tests/BadSeedsTest.cpp b/tests/BadSeedsTest.cpp index 5196ad89..b180f9cb 100644 --- a/tests/BadSeedsTest.cpp +++ b/tests/BadSeedsTest.cpp @@ -67,8 +67,8 @@ const std::set testlens = { 1, 2, 3, 6, 15, 18, 32, 52, 80 }; const std::vector testbytes = { 0, 2, 8, 32, 127, 128, 223, 247, 253, 255 }; -const unsigned numtestbytes = testbytes.size(); -const unsigned numtestlens = testlens.size(); +const size_t numtestbytes = testbytes.size(); +const size_t numtestlens = testlens.size(); #if defined(HAVE_THREADS) // For keeping track of progress printouts across threads @@ -108,7 +108,7 @@ static void TestSeedRangeThread( const HashInfo * hinfo, const uint64_t hi, cons /* Premake all the test keys */ uint8_t keys[numtestbytes][128]; - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { memset(&keys[i][0], testbytes[i], 128); } @@ -134,7 +134,7 @@ static void TestSeedRangeThread( const HashInfo * hinfo, const uint64_t hi, cons memset(&hashes[0], 0, numtestbytes * numtestlens * sizeof(hashtype)); unsigned cnt = 0; - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { for (int len: testlens) { hash(&keys[i][0], len, hseed, &hashes[cnt++]); } @@ -163,7 +163,7 @@ static void TestSeedRangeThread( const HashInfo * hinfo, const uint64_t hi, cons // Can't just print hashes vector because it's now sorted hashtype v; printf("Colliding hashes:\n"); - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { for (int len: testlens) { hash(&keys[i][0], len, hseed, &v); if (std::find(collisions.begin(), collisions.end(), v) != collisions.end()) { @@ -194,7 +194,7 @@ static void TestSeedRangeThread( const HashInfo * hinfo, const uint64_t hi, cons if (!known_seed && (fails < 32)) { // don't print too many lines hashtype v; printf("Zero hashes:\n"); - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { for (int len: testlens) { hash(&keys[i][0], len, hseed, &v); if (v == zero) { @@ -236,7 +236,7 @@ static bool TestManySeeds( const HashInfo * hinfo, const uint64_t hi, bool & new bool * newresults = new bool[g_NCPU](); printf("%d threads starting...\n", g_NCPU); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { const uint32_t start = i * len; const uint32_t end = (i < (g_NCPU - 1)) ? start + (len - 1) : 0xffffffff; t[i] = std::thread { @@ -247,13 +247,13 @@ static bool TestManySeeds( const HashInfo * hinfo, const uint64_t hi, bool & new std::this_thread::sleep_for(std::chrono::seconds(1)); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } printf("All %d threads ended\n", g_NCPU); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { result &= results[i]; newresult |= newresults[i]; } @@ -315,7 +315,7 @@ static bool TestSingleSeed( const HashInfo * hinfo, const seed_t seed ) { /* Premake all the test keys */ uint8_t keys[numtestbytes][128]; - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { memset(&keys[i][0], testbytes[i], 128); } @@ -324,7 +324,7 @@ static bool TestSingleSeed( const HashInfo * hinfo, const seed_t seed ) { memset(&hashes[0], 0, numtestbytes * numtestlens * sizeof(hashtype)); unsigned cnt = 0; - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { for (int len: testlens) { hash(&keys[i][0], len, hseed, &hashes[cnt++]); } @@ -336,7 +336,7 @@ static bool TestSingleSeed( const HashInfo * hinfo, const seed_t seed ) { #if 0 hashtype v; cnt = 0; - for (int i = 0; i < numtestbytes; i++) { + for (size_t i = 0; i < numtestbytes; i++) { for (int len: testlens) { hash(&keys[i][0], len, hseed, &v); if (std::find(collisions.begin(), collisions.end(), v) != collisions.end()) { diff --git a/tests/BitIndependenceTest.cpp b/tests/BitIndependenceTest.cpp index 20aaf0f7..13dece37 100644 --- a/tests/BitIndependenceTest.cpp +++ b/tests/BitIndependenceTest.cpp @@ -134,7 +134,7 @@ static void BicTestBatch( HashFn hash, const seed_t seed, std::vector uint8_t buf[keybytes]; hashtype h1, h2; - int irep; + size_t irep; while ((irep = irepp++) < reps) { progressdots(irep, 0, reps - 1, 12); @@ -202,20 +202,20 @@ static bool BicTestImpl( HashFn hash, const seed_t seed, const size_t keybytes, } else { #if defined(HAVE_THREADS) std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { BicTestBatch, hash, seed, std::ref(popcounts[i]), std::ref(andcounts[i]), keybytes, &keys[0], std::ref(irep), reps }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } - for (int i = 1; i < g_NCPU; i++) { - for (int b = 0; b < keybits * hashbits; b++) { + for (unsigned i = 1; i < g_NCPU; i++) { + for (size_t b = 0; b < keybits * hashbits; b++) { popcounts[0][b] += popcounts[i][b]; } - for (int b = 1; b < keybits * hashbitpairs + 1; b++) { + for (size_t b = 1; b < keybits * hashbitpairs + 1; b++) { andcounts[0][b] += andcounts[i][b]; } } diff --git a/tests/DifferentialTest.cpp b/tests/DifferentialTest.cpp index b4f0e3f6..ce902b57 100644 --- a/tests/DifferentialTest.cpp +++ b/tests/DifferentialTest.cpp @@ -210,16 +210,16 @@ static bool DiffTestImpl( HashFn hash, const seed_t seed, int diffbits, int reps } else { #if defined(HAVE_THREADS) std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { DiffTestImplThread, hash, seed, std::ref(diffcounts[i]), &keys[0], diffbits, std::ref(irep), reps }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } - for (int i = 1; i < g_NCPU; i++) { + for (unsigned i = 1; i < g_NCPU; i++) { for (std::pair dc: diffcounts[i]) { diffcounts[0][dc.first] += dc.second; } diff --git a/tests/PerlinNoiseTest.cpp b/tests/PerlinNoiseTest.cpp index 3d8ec1f1..ca3f467d 100644 --- a/tests/PerlinNoiseTest.cpp +++ b/tests/PerlinNoiseTest.cpp @@ -70,12 +70,12 @@ static bool PerlinNoise( int Xbits, int Ybits, int inputLen, int step, assert(inputLen <= INPUT_LEN_MAX); std::vector hashes; - uint8_t key[INPUT_LEN_MAX] = { 0 }; - int const xMax = (1 << Xbits); - int const yMax = (1 << Ybits); - const HashFn hash = hinfo->hashFn(g_hashEndian); + uint8_t key[INPUT_LEN_MAX] = { 0 }; + const uint64_t xMax = (UINT64_C(1) << Xbits); + const uint64_t yMax = (UINT64_C(1) << Ybits); + const HashFn hash = hinfo->hashFn(g_hashEndian); - printf("Generating coordinates from %3i-byte keys - %d keys\n", inputLen, xMax * yMax); + printf("Generating coordinates from %3i-byte keys - %ld keys\n", inputLen, xMax * yMax); addVCodeInput(yMax); // Since seeding can be expensive, loop over the seed-dependent diff --git a/tests/PermutationKeysetTest.cpp b/tests/PermutationKeysetTest.cpp index ea76da71..37277d65 100644 --- a/tests/PermutationKeysetTest.cpp +++ b/tests/PermutationKeysetTest.cpp @@ -63,7 +63,7 @@ static void CombinationKeygenRecurse( uint8_t * key, int len, int maxlen, const uint32_t blocksz, HashFn hash, const seed_t seed, std::vector & hashes ) { if (len == maxlen) { return; } // end recursion - for (int i = 0; i < blockcount; i++) { + for (size_t i = 0; i < blockcount; i++) { memcpy(&key[len * blocksz], &blocks[i * blocksz], blocksz); hashtype h; diff --git a/tests/PopcountTest.cpp b/tests/PopcountTest.cpp index 3183391f..91866df6 100644 --- a/tests/PopcountTest.cpp +++ b/tests/PopcountTest.cpp @@ -144,7 +144,7 @@ static bool PopcountResults( long double srefh, long double srefl, long double b static bool PopcountTestImpl( const HashInfo * hinfo, int inputSize, int step ) { const long double n = UINT64_C(0x100000000) / step; - const int hbits = std::min(hinfo->bits, 64U); // limited due to popcount8 + const uint64_t hbits = std::min(hinfo->bits, UINT32_C(64)); // limited due to popcount8 assert(hbits <= HASH_SIZE_MAX * 8); assert(inputSize >= 4); @@ -243,7 +243,7 @@ static bool PopcountTestImpl( const HashInfo * hinfo, int inputSize, int step ) printf("%d threads starting... ", g_NCPU); const uint64_t len = UINT64_C(0x100000000) / (step * g_NCPU); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { const uint32_t start = i * len * step; const uint32_t end = (i < (g_NCPU - 1)) ? start + (len * step - 1) : 0xffffffff; // printf("thread[%d]: %d, 0x%x - 0x%x %d\n", i, inputSize, start, end, step); @@ -254,13 +254,13 @@ static bool PopcountTestImpl( const HashInfo * hinfo, int inputSize, int step ) std::this_thread::sleep_for(std::chrono::seconds(1)); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } printf(" done\n"); - for (int i = 1; i < g_NCPU; i++) { - for (int j = 0; j <= hbits; j++) { + for (unsigned i = 1; i < g_NCPU; i++) { + for (uint64_t j = 0; j <= hbits; j++) { rawhash[0][j] += rawhash[i][j]; xorhash[0][j] += xorhash[i][j]; } diff --git a/tests/SanityTest.cpp b/tests/SanityTest.cpp index 4cfa0fb0..24e38e60 100644 --- a/tests/SanityTest.cpp +++ b/tests/SanityTest.cpp @@ -385,12 +385,12 @@ static void hashthings( const HashInfo * hinfo, seed_t seed, uint32_t reps, uint const uint32_t hashbytes = hinfo->bits / 8; // Each thread should hash the keys in a different, random order - std::vector idxs( reps ); + std::vector idxs( reps ); if (order != 0) { Rand r( 46742 + order ); - for (int i = 0; i < reps; i++) { idxs[i] = i; } - for (int i = reps - 1; i > 0; i--) { + for (uint32_t i = 0; i < reps; i++) { idxs[i] = i; } + for (uint32_t i = reps - 1; i > 0; i--) { std::swap(idxs[i], idxs[r.rand_range(i + 1)]); } } @@ -399,8 +399,8 @@ static void hashthings( const HashInfo * hinfo, seed_t seed, uint32_t reps, uint // If we're testing #2 above, then reseed per-key. // Add each key to the input VCode, but only on the main proc. // Print out progress dots on the main proc AND thread #0. - for (int i = 0; i < reps; i++) { - const int idx = (order == 0) ? i : idxs[i]; + for (uint32_t i = 0; i < reps; i++) { + const uint32_t idx = (order == 0) ? i : idxs[i]; if (reseed) { seed = hinfo->Seed(idx * UINT64_C(0xa5), true, 1); } hash(&keys[idx * reps], idx + 1, seed, &hashes[idx * hashbytes]); if (verbose && (order < 2)) { progressdots(i, 0, reps - 1, 4); } @@ -441,17 +441,17 @@ static bool ThreadingTest( const HashInfo * hinfo, bool seedthread, bool verbose // Compute all the hashes in different random orders in threads std::vector> threadhashes( g_NCPU, std::vector(reps * hashbytes)); std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { hashthings, hinfo, seed, reps, i + 1, seedthread, verbose, std::ref(keys), std::ref(threadhashes[i]) }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } // Make sure all thread results match the main process maybeprintf("."); - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { if (!memcmp(&mainhashes[0], &threadhashes[i][0], reps * hashbytes)) { continue; } @@ -459,7 +459,7 @@ static bool ThreadingTest( const HashInfo * hinfo, bool seedthread, bool verbose result = false; break; } - for (int j = 0; j < reps; j++) { + for (uint32_t j = 0; j < reps; j++) { if (memcmp(&mainhashes[j * hashbytes], &threadhashes[i][j * hashbytes], hashbytes) != 0) { maybeprintf("\nMismatch between main process and thread #%d at index %d\n", i, j); if (verbose) { ExtBlob(&mainhashes[j * hashbytes], hashbytes).printhex(" main :"); } diff --git a/tests/SeedAvalancheTest.cpp b/tests/SeedAvalancheTest.cpp index 3dfa50c8..3b3c7e30 100644 --- a/tests/SeedAvalancheTest.cpp +++ b/tests/SeedAvalancheTest.cpp @@ -139,16 +139,16 @@ static bool SeedAvalancheImpl( const HashInfo * hinfo, const int keybytes, } else { #if defined(HAVE_THREADS) std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { calcBiasRange, hinfo, std::ref(bins[i]), keybytes, &inputs[0], std::ref(irep), reps, drawdots }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } - for (int i = 1; i < g_NCPU; i++) { + for (unsigned i = 1; i < g_NCPU; i++) { for (int b = 0; b < arraysize; b++) { bins[0][b] += bins[i][b]; } diff --git a/tests/SeedBitIndependenceTest.cpp b/tests/SeedBitIndependenceTest.cpp index bb248997..de4f2df6 100644 --- a/tests/SeedBitIndependenceTest.cpp +++ b/tests/SeedBitIndependenceTest.cpp @@ -83,7 +83,7 @@ static void SeedBicTestBatch( const HashInfo * hinfo, std::vector & po const size_t hashbitpairs = hashbits / 2 * hashbits; hashtype h1, h2; - int irep; + size_t irep; uint64_t iseed = 0; while ((irep = irepp++) < reps) { @@ -157,20 +157,20 @@ static bool SeedBicTestImpl( const HashInfo * hinfo, const size_t keybytes, cons } else { #if defined(HAVE_THREADS) std::thread t[g_NCPU]; - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i] = std::thread { SeedBicTestBatch, hinfo, std::ref(popcounts[i]), std::ref(andcounts[i]), keybytes, &keys[0], seedbytes, &seeds[0], std::ref(irep), reps }; } - for (int i = 0; i < g_NCPU; i++) { + for (unsigned i = 0; i < g_NCPU; i++) { t[i].join(); } - for (int i = 1; i < g_NCPU; i++) { - for (int b = 0; b < seedbits * hashbits; b++) { + for (unsigned i = 1; i < g_NCPU; i++) { + for (size_t b = 0; b < seedbits * hashbits; b++) { popcounts[0][b] += popcounts[i][b]; } - for (int b = 1; b < seedbits * hashbitpairs + 1; b++) { + for (size_t b = 1; b < seedbits * hashbitpairs + 1; b++) { andcounts[0][b] += andcounts[i][b]; } } diff --git a/tests/SeedTest.cpp b/tests/SeedTest.cpp index a03dd577..29813398 100644 --- a/tests/SeedTest.cpp +++ b/tests/SeedTest.cpp @@ -76,7 +76,7 @@ static bool SeedTestImpl( const HashInfo * hinfo, uint32_t keylen, bool drawDiag const char text[] = "The quick brown fox jumps over the lazy dog"; const int textlen = (int)strlen(text); char key[MAXLEN] = { 0 }; - for (int i = 0; i < keylen / textlen; i++) { + for (size_t i = 0; i < keylen / textlen; i++) { memcpy(&key[i * textlen], text, textlen); } memcpy(&key[keylen / textlen * textlen], text, keylen % textlen); @@ -126,7 +126,7 @@ static bool SeedSparseTestImpl( const HashInfo * hinfo, uint32_t keylen, bool dr const char text[64] = "Sphinx of black quartz, judge my vow"; const int textlen = (int)strlen(text); char key[MAXLEN] = { 0 }; - for (int i = 0; i < keylen / textlen; i++) { + for (size_t i = 0; i < keylen / textlen; i++) { memcpy(&key[i * textlen], text, textlen); } memcpy(&key[keylen / textlen * textlen], text, keylen % textlen); diff --git a/tests/SeedZeroesTest.cpp b/tests/SeedZeroesTest.cpp index b9261f37..3a0e225d 100644 --- a/tests/SeedZeroesTest.cpp +++ b/tests/SeedZeroesTest.cpp @@ -82,18 +82,18 @@ static bool SeedZeroKeyImpl( const HashInfo * hinfo, const size_t maxbits, const size_t cnt = 0; seed_t hseed; - for (int j = 1; j <= maxbits; j++) { + for (size_t j = 1; j <= maxbits; j++) { uint64_t seed = (UINT64_C(1) << j) - 1; bool done; do { hseed = hinfo->Seed(seed, false); - for (int i = 1; i <= keycount; i++) { + for (size_t i = 1; i <= keycount; i++) { hash(nullblock, i, hseed, &hashes[cnt++]); } hseed = hinfo->Seed(~seed, false); - for (int i = 1; i <= keycount; i++) { + for (size_t i = 1; i <= keycount; i++) { hash(nullblock, i, hseed, &hashes[cnt++]); } diff --git a/tests/SparseKeysetTest.cpp b/tests/SparseKeysetTest.cpp index df572053..410e29b6 100644 --- a/tests/SparseKeysetTest.cpp +++ b/tests/SparseKeysetTest.cpp @@ -64,7 +64,7 @@ static void SparseKeygenRecurse( HashFn hash, const seed_t seed, int start, int bool inclusive, keytype & k, std::vector & hashes ) { hashtype h; - for (int i = start; i < k.bitlen; i++) { + for (size_t i = start; i < k.bitlen; i++) { k.flipbit(i); if (inclusive || (bitsleft == 1)) { diff --git a/util/Analyze.cpp b/util/Analyze.cpp index ed15e708..398e2606 100644 --- a/util/Analyze.cpp +++ b/util/Analyze.cpp @@ -558,9 +558,9 @@ static bool TestDistribution( std::vector & hashes, int * logpp, bool int tests = 0; for (int start = 0; start < hashbits; start++) { - int width = maxwidth; - int bincount = (1 << width); - bool bigbins = false; // Are we using 32-bit bins? + int width = maxwidth; + size_t bincount = (1 << width); + bool bigbins = false; // Are we using 32-bit bins? // This loop does random writes to the bins, so time is completely // dominated by cache performance. For ballpark numbers, @@ -1157,7 +1157,7 @@ bool ReportChiSqIndep( const uint32_t * popcount, const uint32_t * andcount, siz for (size_t out1 = 0; out1 < hashbits - 1; out1++) { for (size_t out2 = out1 + 1; out2 < hashbits; out2++) { printf("Output bits (%3zd,%3zd) - ", out1, out2); - for (int keybit = 0; keybit < keybits; keybit++) { + for (size_t keybit = 0; keybit < keybits; keybit++) { const uint32_t * pop_cursor = &popcount[keybit * hashbits ]; const uint32_t * and_cursor = &andcount[keybit * hashbitpairs + xyoffset]; diff --git a/util/Blobsort.cpp b/util/Blobsort.cpp index ece02dc5..927f6522 100644 --- a/util/Blobsort.cpp +++ b/util/Blobsort.cpp @@ -30,7 +30,7 @@ //----------------------------------------------------------------------------- // Blob sorting routine unit tests -static const uint32_t SORT_TESTS = 20; +static const size_t SORT_TESTS = 20; static const char * teststr[SORT_TESTS] = { "Consecutive numbers, sorted", "Consecutive numbers, almost sorted", @@ -55,7 +55,7 @@ static const char * teststr[SORT_TESTS] = { }; template -static void blobfill( std::vector & blobs, int testnum, int iternum ) { +static void blobfill( std::vector & blobs, size_t testnum, int iternum ) { if (testnum >= SORT_TESTS) { return; } Rand r( testnum + 0xb840a149 * (iternum + 1) ); @@ -233,19 +233,19 @@ bool test_blobsort_type( void ) { std::vector blobs( TEST_SIZE ); size_t timetotal = 0; size_t timesum; - std::vector testnums; + std::vector testnums; if (TEST_ITER > 1) { testnums = { 4, 6, 8, 9, 10, 15, 16, 19 }; } else { - for (int i = 0; i < SORT_TESTS; i++) { + for (size_t i = 0; i < SORT_TESTS; i++) { testnums.push_back(i); } } for (int i: testnums) { timesum = 0; - for (int j = 0; j < TEST_ITER; j++) { + for (size_t j = 0; j < TEST_ITER; j++) { blobfill(blobs, i, j); size_t timeBegin = monotonic_clock(); blobsort(blobs.begin(), blobs.end()); diff --git a/util/Blobsort.h b/util/Blobsort.h index 6570bc8a..6e88a53c 100644 --- a/util/Blobsort.h +++ b/util/Blobsort.h @@ -99,8 +99,8 @@ static const uint32_t SORT_CUTOFF = 60; // system, but there could be a better value for the general case. template static void flagsort( T * begin, T * end, int idx ) { - const uint32_t DIGITS = T::len; - const size_t count = end - begin; + const int DIGITS = T::len; + const size_t count = end - begin; assume(idx >= 0 ); assume(idx < DIGITS); @@ -160,7 +160,7 @@ static void flagsort( T * begin, T * end, int idx ) { // Sort each block by the next less-significant byte, or by // std::sort if there are only a few entries in the block. ptr = begin; - for (int i = 0; i < RADIX_SIZE; i++) { + for (size_t i = 0; i < RADIX_SIZE; i++) { if (expectp((freqs[i] > SORT_CUTOFF), 0.00390611)) { flagsort(ptr, ptr + freqs[i], idx - 1); } else if (expectp((freqs[i] > 1), 0.3847)) { diff --git a/util/Stats.cpp b/util/Stats.cpp index adc6d019..3d6645be 100644 --- a/util/Stats.cpp +++ b/util/Stats.cpp @@ -1019,9 +1019,9 @@ void ReportCollisionEstimates( void ) { " # keys : bits| True answer | A: _cur() | B: _prev() | C: _prevprev() | Error A | Error B | Error C |\n"); printf( "---------------------------------------------------------------------------------------------------------------------------------------------------\n"); - for (int i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) { + for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) { const int key = keys[i]; - for (int j = 0; j < sizeof(bits) / sizeof(bits[0]); j++) { + for (size_t j = 0; j < sizeof(bits) / sizeof(bits[0]); j++) { const int bit = bits[j]; printf(" %9d : %3d |", key, bit); printdouble(20, realcoll[i][j]); diff --git a/util/VCode.cpp b/util/VCode.cpp index a9d0ba18..d1347d30 100644 --- a/util/VCode.cpp +++ b/util/VCode.cpp @@ -287,7 +287,7 @@ static bool vcode_crc_selftest( void ) { #if !defined(HWCRC_U64) if (use_hw) { return true; } #endif - constexpr uint32_t testcnt = 6; + constexpr size_t testcnt = 6; uint8_t offsets[testcnt] = { 0x01, 0x29, 0x51, 0x79, 0xa1, 0xc9 }; uint32_t crcs[testcnt] = { 0x0e2c157f, 0xe980ebf6, 0xde74bded, @@ -295,7 +295,7 @@ static bool vcode_crc_selftest( void ) { }; uint32_t crc; - for (int i = 0; i < testcnt; i++) { + for (size_t i = 0; i < testcnt; i++) { crc = vcode_crc_selftest_40( offsets[i]); if (crc != crcs[i]) { return false; }