Created
June 4, 2023 02:55
-
-
Save EiichiroIto/7f56ba2da7e69a619f45a2541c580a30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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