|
KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Fast unsigned integer division. More...
Go to the source code of this file.
Data Structures | |
| struct | udiv_t |
| Pre-processed unsigned integer divider value. More... | |
Functions | |
| static udiv_t | udiv_set_divider (unsigned int div) |
| Create a udiv_t from an unsigned int divider. | |
| static unsigned int | udiv_divide_fast (unsigned int val, udiv_t udiv) |
| Perform a division using the udiv_t, without bound checking. | |
| static unsigned int | udiv_divide (unsigned int val, udiv_t udiv) |
| Perform a division using the udiv_t, with bound checking. | |
Fast unsigned integer division.
This file contains an API that can be used to pre-process an unsigned value into an udiv_t struct. This struct can later be used to divide another unsigned value much faster than by doing an actual division.
This API is very useful when a rarely-changing divider is used often.
|
inlinestatic |
Perform a division using the udiv_t, with bound checking.
This function will perform a division using the provided udiv_t. The pre-processed divider can correspond to any non-zero integer value.
| val | The dividend |
| udiv | The divider, as a udiv_t |
References udiv_t::m, udiv_t::p, and udiv_divide_fast().
|
inlinestatic |
Perform a division using the udiv_t, without bound checking.
This function is similar to udiv_divide(), except that it only works for values 1 < div < 0x80000001.
| val | The dividend |
| udiv | The divider, as a udiv_t |
References udiv_t::m, and udiv_t::p.
Referenced by udiv_divide().
|
inlinestatic |
Create a udiv_t from an unsigned int divider.
Use this function to create the preleminary udiv_t object, that can then be passed to udiv_divide() or udiv_divide_fast().
| div | The unsigned integer divider value |
References BITLL, and is_power_of_two().