mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-09-08 17:15:33 -05:00
Prepare for trouble... and make it.... fixed point?
To protect the world from the soft float library... To unite all arithmetic within our binary... To denounce the evils of floating point precision... To save more kilobytes - that's our vision.... (god this is cringe) All floating point math has been eliminated, and replaced with equivalent or near-equivalent fixed-point math. sprite_data.cpp uses Q16, and get_rand_range uses a full Q32 to ensure that the exact same results are generated as before, at the cost of some inline assembly to do a umull (__aeabi_lmul is a little excessive when the lower 32 bits are discarded) This eliminates all of the expensive double precision float library, saving a few kilobytes. Additionally, the unneccessary parts of nanoprintf have been disabled. There is no need for precision specifiers, long longs, or floats.
This commit is contained in:
@@ -40,7 +40,15 @@ u16 get_rev_rand_u16(u32 input)
|
||||
return (get_rev_rand_u32(input) >> 16);
|
||||
}
|
||||
|
||||
unsigned int get_rand_range(unsigned int inc_min, unsigned int exc_max)
|
||||
// Force ARM mode. In Thumb mode this imports __aeabi_lmul.
|
||||
__attribute__((target("arm"), noinline))
|
||||
static unsigned multiply_high(unsigned x, unsigned y)
|
||||
{
|
||||
return ((double)((get_rand_u32() / (double)0x100000000) * (exc_max - inc_min)) + inc_min);
|
||||
return ((unsigned long long)x * y) >> 32; // umull
|
||||
}
|
||||
|
||||
unsigned get_rand_range(unsigned inc_min, unsigned exc_max)
|
||||
{
|
||||
// fixed point: get_rand_u32() / (float)0x100000000 * (exc_max - inc_min) + inc_min
|
||||
return multiply_high(get_rand_u32(), exc_max - inc_min) + inc_min;
|
||||
}
|
||||
Reference in New Issue
Block a user