mirror of
https://github.com/open-goal/jak-project
synced 2026-08-21 14:54:53 -04:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user