Skip to content

Replace the bl! macro with asm_sym #820

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions compiler-builtins/src/arm.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#![cfg(not(feature = "no-asm"))]
#![allow(unused_imports)]

use core::intrinsics;

// Apple symbols have a leading underscore.
#[cfg(target_vendor = "apple")]
macro_rules! bl {
($func:literal) => {
concat!("bl _", $func)
};
// Interfaces used by naked trampolines.
extern "C" {
fn __udivmodsi4(a: u32, b: u32, rem: *mut u32) -> u32;
fn __udivmoddi4(a: u64, b: u64, rem: *mut u64) -> u64;
fn __divmoddi4(a: i64, b: i64, rem: *mut i64) -> i64;
}
#[cfg(not(target_vendor = "apple"))]
macro_rules! bl {
($func:literal) => {
concat!("bl ", $func)
};

extern "aapcs" {
// AAPCS is not always the correct ABI for these intrinsics, but we only use this to
// forward another `__aeabi_` call so it doesn't matter.
fn __aeabi_idiv(a: i32, b: i32) -> i32;
}

intrinsics! {
Expand All @@ -27,10 +23,11 @@ intrinsics! {
"push {{lr}}",
"sub sp, sp, #4",
"mov r2, sp",
bl!("__udivmodsi4"),
"bl {trampoline}",
"ldr r1, [sp]",
"add sp, sp, #4",
"pop {{pc}}",
trampoline = sym crate::arm::__udivmodsi4
);
}

Expand All @@ -41,23 +38,25 @@ intrinsics! {
"sub sp, sp, #16",
"add r4, sp, #8",
"str r4, [sp]",
bl!("__udivmoddi4"),
"bl {trampoline}",
"ldr r2, [sp, #8]",
"ldr r3, [sp, #12]",
"add sp, sp, #16",
"pop {{r4, pc}}",
trampoline = sym crate::arm::__udivmoddi4
);
}

#[unsafe(naked)]
pub unsafe extern "C" fn __aeabi_idivmod() {
core::arch::naked_asm!(
"push {{r0, r1, r4, lr}}",
bl!("__aeabi_idiv"),
"bl {trampoline}",
"pop {{r1, r2}}",
"muls r2, r2, r0",
"subs r1, r1, r2",
"pop {{r4, pc}}",
trampoline = sym crate::arm::__aeabi_idiv,
);
}

Expand All @@ -68,11 +67,12 @@ intrinsics! {
"sub sp, sp, #16",
"add r4, sp, #8",
"str r4, [sp]",
bl!("__divmoddi4"),
"bl {trampoline}",
"ldr r2, [sp, #8]",
"ldr r3, [sp, #12]",
"add sp, sp, #16",
"pop {{r4, pc}}",
trampoline = sym crate::arm::__divmoddi4,
);
}

Expand Down