less branches for division + fix divide by zeros (#2585)

Slight change to float divide operations (again). Now it only turns into
inverse multiplication if the float is a power of 2 (positive or
negative). Non-zero immediate divisors will be compiled as regular float
divisions but will forgo the extra branches and checks for divide by
zero.

Also fixes #2584
This commit is contained in:
ManDude
2023-04-29 21:10:51 +01:00
committed by GitHub
parent 0d3e272876
commit 2feb231105
4 changed files with 31 additions and 10 deletions
+14
View File
@@ -41,6 +41,7 @@
#include "Object.h"
#include <cinttypes>
#include <cstring>
#include "common/util/FileUtil.h"
#include "common/util/print_float.h"
@@ -207,6 +208,19 @@ Object build_list(std::vector<Object>&& objects) {
return result;
}
/*!
* Is this a float object that's a power of two?
* NOTE: assumes 64-bit float.
*/
bool Object::is_power_of_2_float() const {
FloatType val = as_float();
u64 val_i = -1;
memcpy(&val_i, &val, sizeof(val));
u64 mantissa = val_i & ((1LL << 52) - 1);
u64 exponent = (val_i >> 52) & ((1LL << 11) - 1);
return mantissa == 0 && exponent != 0 && exponent != ((1LL << 11) - 1);
}
/*!
* Compare two objects for equality.
* Does "expensive" checking.