Skip to content

Instantly share code, notes, and snippets.

@EiichiroIto
Created June 4, 2023 02:55
Show Gist options
  • Save EiichiroIto/7f56ba2da7e69a619f45a2541c580a30 to your computer and use it in GitHub Desktop.
Save EiichiroIto/7f56ba2da7e69a619f45a2541c580a30 to your computer and use it in GitHub Desktop.
typedef uint32_t UINT;
UINT __aeabi_uidiv(UINT lhs, UINT rhs)
{
UINT quotient = 0;
UINT remainder = 0;
for (int i = 31; i >= 0; i --) {
quotient <<= 1;
remainder <<= 1;
remainder |= (lhs >> 31) & 1;
lhs <<= 1;
if (rhs <= remainder) {
remainder -= rhs;
quotient |= 1;
}
}
return quotient;
}
UINT __aeabi_uldivmod(UINT lhs, UINT rhs)
{
UINT remainder = 0;
for (int i = 31; i >= 0; --i) {
remainder <<= 1;
remainder |= (lhs >> 31) & 1;
lhs <<= 1;
if (rhs <= remainder) {
remainder -= rhs;
}
}
return remainder;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment