diff --git a/lib/qa_utils.cc b/lib/qa_utils.cc index 251bbfd0..4be7b8ad 100644 --- a/lib/qa_utils.cc +++ b/lib/qa_utils.cc @@ -51,44 +51,69 @@ void load_random_data(void* data, volk_type_t type, unsigned int n) random_floats(data, n, rnd_engine); } } else { - float int_max = float(uint64_t(2) << (type.size * 8)); - if (type.is_signed) - int_max /= 2.0; - std::uniform_real_distribution uniform_dist(-int_max, int_max); - for (unsigned int i = 0; i < n; i++) { - float scaled_rand = uniform_dist(rnd_engine); - // man i really don't know how to do this in a more clever way, you have to - // cast down at some point - switch (type.size) { - case 8: - if (type.is_signed) - ((int64_t*)data)[i] = (int64_t)scaled_rand; - else - ((uint64_t*)data)[i] = (uint64_t)scaled_rand; - break; - case 4: - if (type.is_signed) - ((int32_t*)data)[i] = (int32_t)scaled_rand; - else - ((uint32_t*)data)[i] = (uint32_t)scaled_rand; - break; - case 2: - if (type.is_signed) - ((int16_t*)data)[i] = (int16_t)((int16_t)scaled_rand % 8); - else - ((uint16_t*)data)[i] = (uint16_t)((int16_t)scaled_rand % 8); - break; - case 1: - if (type.is_signed) - ((int8_t*)data)[i] = (int8_t)scaled_rand; - else - ((uint8_t*)data)[i] = (uint8_t)scaled_rand; - break; - default: - throw "load_random_data: no support for data size > 8 or < 1"; // no - // shenanigans - // here + switch (type.size) { + case 8: + if (type.is_signed) { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((int64_t*)data)[i] = uniform_dist(rnd_engine); + } else { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((uint64_t*)data)[i] = uniform_dist(rnd_engine); } + break; + case 4: + if (type.is_signed) { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((int32_t*)data)[i] = uniform_dist(rnd_engine); + } else { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((uint32_t*)data)[i] = uniform_dist(rnd_engine); + } + break; + case 2: + if (type.is_signed) { + std::uniform_int_distribution uniform_dist(-7, 7); + for (unsigned int i = 0; i < n; i++) + ((int16_t*)data)[i] = uniform_dist(rnd_engine); + } else { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((uint16_t*)data)[i] = uniform_dist(rnd_engine); + } + break; + case 1: + if (type.is_signed) { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((int8_t*)data)[i] = uniform_dist(rnd_engine); + } else { + std::uniform_int_distribution uniform_dist( + std::numeric_limits::min(), + std::numeric_limits::max()); + for (unsigned int i = 0; i < n; i++) + ((uint8_t*)data)[i] = uniform_dist(rnd_engine); + } + break; + default: + throw "load_random_data: no support for data size > 8 or < 1"; // no + // shenanigans + // here } } } @@ -460,7 +485,7 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode) } template -bool icompare(t* in1, t* in2, unsigned int vlen, unsigned int tol, bool absolute_mode) +bool icompare(t* in1, t* in2, unsigned int vlen, unsigned int tol) { bool fail = false; int print_max_errs = 10; @@ -548,7 +573,7 @@ bool run_volk_tests(volk_func_desc_t desc, vlen = vlen + vlen_twiddle; const float tol_f = tol; - const unsigned int tol_i = static_cast(tol); + const unsigned int tol_i = static_cast(tol); // first let's get a list of available architectures for the test std::vector arch_list = get_arch_list(desc); @@ -774,14 +799,12 @@ bool run_volk_tests(volk_func_desc_t desc, fail = icompare((int64_t*)test_data[generic_offset][j], (int64_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } else { fail = icompare((uint64_t*)test_data[generic_offset][j], (uint64_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } break; case 4: @@ -790,28 +813,24 @@ bool run_volk_tests(volk_func_desc_t desc, fail = icompare((int16_t*)test_data[generic_offset][j], (int16_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } else { fail = icompare((uint16_t*)test_data[generic_offset][j], (uint16_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } } else { if (both_sigs[j].is_signed) { fail = icompare((int32_t*)test_data[generic_offset][j], (int32_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } else { fail = icompare((uint32_t*)test_data[generic_offset][j], (uint32_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } } break; @@ -820,14 +839,12 @@ bool run_volk_tests(volk_func_desc_t desc, fail = icompare((int16_t*)test_data[generic_offset][j], (int16_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } else { fail = icompare((uint16_t*)test_data[generic_offset][j], (uint16_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } break; case 1: @@ -835,14 +852,12 @@ bool run_volk_tests(volk_func_desc_t desc, fail = icompare((int8_t*)test_data[generic_offset][j], (int8_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } else { fail = icompare((uint8_t*)test_data[generic_offset][j], (uint8_t*)test_data[i][j], vlen * (both_sigs[j].is_complex ? 2 : 1), - tol_i, - absolute_mode); + tol_i); } break; default: