gnuradio / volk

The Vector Optimized Library of Kernels

Home Page:http://libvolk.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

64-bit integer testing is broken

argilo opened this issue · comments

The icompare function casts all inputs to int before comparing & printing them. This prevents errors in upper bits from being caught, and makes it difficult to diagnose failures.

volk/lib/qa_utils.cc

Lines 463 to 480 in e853e9b

bool icompare(t* in1, t* in2, unsigned int vlen, unsigned int tol, bool absolute_mode)
{
bool fail = false;
int print_max_errs = 10;
for (unsigned int i = 0; i < vlen; i++) {
if (((unsigned int)abs(int(((t*)(in1))[i]) - int(((t*)(in2))[i]))) > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i
<< " in1: " << static_cast<int>(t(((t*)(in1))[i]))
<< " in2: " << static_cast<int>(t(((t*)(in2))[i]));
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
return fail;
}

We could use long long int cf. Int types.

However, the fundamental int types just feel broken.
I assume we should #include <cstdint> and use fixed width integer types.

In this specific case int64_t would be correct. Though, this type is marked optional.

If we change this line:

if (((unsigned int)abs(int(((t*)(in1))[i]) - int(((t*)(in2))[i]))) > tol) {

to

if (((unsigned int)abs(int64_t(((t*)(in1))[i]) - int64_t(((t*)(in2))[i]))) > tol) { 

we should be good. Technically, a #include <cstdint> line is required as well.