Open
Description
In the AGM PR, I have found that ~90% of the runtime is spent computing float distances. However, at least for float
and double
, the following trivial modification drops the runtime to a negligible fraction of the total runtime:
int32_t fast_float_distance(float x, float y) {
static_assert(sizeof(float) == sizeof(int32_t), "float is incorrect size.");
int32_t xi = *reinterpret_cast<int32_t*>(&x);
int32_t yi = *reinterpret_cast<int32_t*>(&y);
return yi - xi;
}
int64_t fast_float_distance(double x, double y) {
static_assert(sizeof(double) == sizeof(int64_t), "double is incorrect size.");
int64_t xi = *reinterpret_cast<int64_t*>(&x);
int64_t yi = *reinterpret_cast<int64_t*>(&y);
return yi - xi;
}
It seems like boost::math::float_distance
is considerably more general than this, but can we dive through a happy path to extract performance in the trivial cases?
Metadata
Metadata
Assignees
Labels
No labels