Skip to content

Commit

Permalink
Fix random numbers used in integer tests.
Browse files Browse the repository at this point in the history
The range of random numbers for integer tests is not correct.  For
uint64_t it was overflowing and only producing 0's and 1's.

Signed-off-by: John Sallay <[email protected]>
  • Loading branch information
jsallay committed Oct 28, 2023
1 parent e853e9b commit 5b653fa
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions lib/qa_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,48 @@ void load_random_data(void* data, volk_type_t type, unsigned int n)
random_floats<float>(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<float> uniform_dist(-int_max, int_max);
float int_max, int_min;
switch(type.size) {
case 8:
if (type.is_signed) {
int_max = static_cast<float>(std::numeric_limits<int64_t>::max());
int_min = static_cast<float>(std::numeric_limits<int64_t>::min());
} else {
int_max = static_cast<float>(std::numeric_limits<uint64_t>::max());
int_min = static_cast<float>(std::numeric_limits<uint64_t>::min());
}
break;
case 4:
if (type.is_signed) {
int_max = static_cast<float>(std::numeric_limits<int32_t>::max());
int_min = static_cast<float>(std::numeric_limits<int32_t>::min());
} else {
int_max = static_cast<float>(std::numeric_limits<uint32_t>::max());
int_min = static_cast<float>(std::numeric_limits<uint32_t>::min());
}
break;
case 2:
if (type.is_signed) {
int_max = static_cast<float>(std::numeric_limits<int16_t>::max());
int_min = static_cast<float>(std::numeric_limits<int16_t>::min());
} else {
int_max = static_cast<float>(std::numeric_limits<uint16_t>::max());
int_min = static_cast<float>(std::numeric_limits<uint16_t>::min());
}
break;
case 1:
if (type.is_signed) {
int_max = static_cast<float>(std::numeric_limits<int8_t>::max());
int_min = static_cast<float>(std::numeric_limits<int8_t>::min());
} else {
int_max = static_cast<float>(std::numeric_limits<uint8_t>::max());
int_min = static_cast<float>(std::numeric_limits<uint8_t>::min());
}
break;
default:
throw "load_random_data: no support for data size > 8 or < 1"; // no
}
std::uniform_real_distribution<float> uniform_dist(int_min, 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
Expand Down

0 comments on commit 5b653fa

Please sign in to comment.