MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / test_random_generator_equivalence

Function test_random_generator_equivalence

scripts/test_stringzilla.cpp:329–350  ·  view source on GitHub ↗

* @brief Tests Pseudo-Random Number Generators (PRNGs) ensuring that the same nonce * produces exactly the same output across different SIMD implementations. */

Source from the content-addressed store, hash-verified

327 * produces exactly the same output across different SIMD implementations.
328 */
329void test_random_generator_equivalence(sz_fill_random_t generate_base, sz_fill_random_t generate_simd) {
330
331 auto test_on_nonce = [&](std::size_t length, sz_u64_t nonce) {
332 std::string text_base(length, '\0');
333 std::string text_simd(length, '\0');
334 generate_base(&text_base[0], static_cast<sz_size_t>(length), nonce);
335 generate_simd(&text_simd[0], static_cast<sz_size_t>(length), nonce);
336 assert(text_base == text_simd);
337 };
338
339 // Let's try different nonces:
340 std::vector<sz_u64_t> nonces = {
341 0u,
342 42u, //
343 std::numeric_limits<sz_u32_t>::max(), //
344 std::numeric_limits<sz_u64_t>::max(), //
345 };
346 std::vector<std::size_t> lengths = {1, 11, 23, 37, 40, 51, 64, 128, 1000};
347 for (auto nonce : nonces)
348 for (auto length : lengths) //
349 test_on_nonce(length, nonce);
350}
351
352/**
353 * @brief Tests SHA256 implementations, comparing serial and SIMD variants

Callers 1

test_equivalenceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…