-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement LLVM intrinsics for Div and Mod so that /
and %
work "normally" on the GBA
#8
Comments
Upon further chats on the discord, I'm convinced that it'll be fine to make normal division work via special intrinsic magic, so we'll mark this as Enhancement |
So, due to reasons that no one can seem to figure out, LLVM just doesn't wanna play nice with the intrinsics here. It inserts calls to count zeroes and even if we try to implement that then it says it can't find it and no one was sure what was up. So we'll put in the GBA BIOS call for /// BIOS Call: Div (GBA SWI 0x06).
///
/// Gives both the DIV and MOD output of `numerator / denominator`.
///
/// # Panics
///
/// If `denominator` is 0.
#[inline]
pub fn div_modulus(numerator: i32, denominator: i32) -> (i32, i32) {
assert!(denominator != 0);
let div_out: i32;
let mod_out: i32;
unsafe {
asm!(/* assembly template */ "swi 0x06"
:/* output operands */ "={r0}"(div_out), "={r1}"(mod_out)
:/* input operands */ "{r0}"(numerator), "{r1}"(denominator)
:/* clobbers */ "r3"
:/* options */
);
}
(div_out, mod_out)
} And we'll have to get back to mapping that (and anything else) into LLVM intrinsic stuff later. |
/
and %
work "normally" on the GBA
Commented on the rustc issue for this rust-lang/compiler-builtins#260 Hopefully we can get this done easily enough |
Put in the start of a PR: rust-lang/compiler-builtins#267 |
Also we now have software versions for |
Oh yeah, the PR was merged and also the update made its way all the way to rustc now that we can count leading zeroes, we still need division |
I think we did this forever ago. |
So, if we implement the correct special function, then we can make code like
Will suddenly magically work on the GBA.
Question
Do we want division to magically work like that?
Personally, I think that division is so damn costly on the GBA that I want it to be called as a special function or even as a macro (which makes it look a little weird) just so that people remember that they're doing a weird and costly operation.
The text was updated successfully, but these errors were encountered: