2020-11-09 07:24:25 -08:00
|
|
|
#![cfg(not(feature = "no-asm"))]
|
2021-05-26 12:22:52 +09:00
|
|
|
#![allow(unused_imports)]
|
2020-11-09 07:24:25 -08:00
|
|
|
|
2017-07-03 19:11:34 -07:00
|
|
|
use core::intrinsics;
|
2016-12-17 23:01:47 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
// iOS symbols have a leading underscore.
|
2018-03-27 11:33:57 +02:00
|
|
|
#[cfg(target_os = "ios")]
|
2022-02-06 09:20:43 +00:00
|
|
|
macro_rules! bl {
|
|
|
|
|
($func:literal) => {
|
|
|
|
|
concat!("bl _", $func)
|
|
|
|
|
};
|
2018-03-27 11:33:57 +02:00
|
|
|
}
|
|
|
|
|
#[cfg(not(target_os = "ios"))]
|
2022-02-06 09:20:43 +00:00
|
|
|
macro_rules! bl {
|
|
|
|
|
($func:literal) => {
|
|
|
|
|
concat!("bl ", $func)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
intrinsics! {
|
|
|
|
|
// NOTE This function and the ones below are implemented using assembly because they are using a
|
|
|
|
|
// custom calling convention which can't be implemented using a normal Rust function.
|
|
|
|
|
#[naked]
|
|
|
|
|
#[cfg(not(target_env = "msvc"))]
|
|
|
|
|
pub unsafe extern "C" fn __aeabi_uidivmod() {
|
|
|
|
|
core::arch::asm!(
|
|
|
|
|
"push {{lr}}",
|
|
|
|
|
"sub sp, sp, #4",
|
|
|
|
|
"mov r2, sp",
|
|
|
|
|
bl!("__udivmodsi4"),
|
|
|
|
|
"ldr r1, [sp]",
|
|
|
|
|
"add sp, sp, #4",
|
|
|
|
|
"pop {{pc}}",
|
|
|
|
|
options(noreturn)
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-03-27 11:33:57 +02:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[naked]
|
|
|
|
|
pub unsafe extern "C" fn __aeabi_uldivmod() {
|
|
|
|
|
core::arch::asm!(
|
|
|
|
|
"push {{r4, lr}}",
|
|
|
|
|
"sub sp, sp, #16",
|
|
|
|
|
"add r4, sp, #8",
|
|
|
|
|
"str r4, [sp]",
|
2022-02-09 20:54:39 +00:00
|
|
|
bl!("__udivmoddi4"),
|
2022-02-06 09:20:43 +00:00
|
|
|
"ldr r2, [sp, #8]",
|
|
|
|
|
"ldr r3, [sp, #12]",
|
|
|
|
|
"add sp, sp, #16",
|
|
|
|
|
"pop {{r4, pc}}",
|
|
|
|
|
options(noreturn)
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-18 17:20:24 +01:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[naked]
|
|
|
|
|
pub unsafe extern "C" fn __aeabi_idivmod() {
|
|
|
|
|
core::arch::asm!(
|
|
|
|
|
"push {{r0, r1, r4, lr}}",
|
|
|
|
|
bl!("__aeabi_idiv"),
|
|
|
|
|
"pop {{r1, r2}}",
|
|
|
|
|
"muls r2, r2, r0",
|
|
|
|
|
"subs r1, r1, r2",
|
|
|
|
|
"pop {{r4, pc}}",
|
|
|
|
|
options(noreturn)
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-03-27 11:33:57 +02:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[naked]
|
|
|
|
|
pub unsafe extern "C" fn __aeabi_ldivmod() {
|
|
|
|
|
core::arch::asm!(
|
|
|
|
|
"push {{r4, lr}}",
|
|
|
|
|
"sub sp, sp, #16",
|
|
|
|
|
"add r4, sp, #8",
|
|
|
|
|
"str r4, [sp]",
|
|
|
|
|
bl!("__divmoddi4"),
|
|
|
|
|
"ldr r2, [sp, #8]",
|
|
|
|
|
"ldr r3, [sp, #12]",
|
|
|
|
|
"add sp, sp, #16",
|
|
|
|
|
"pop {{r4, pc}}",
|
|
|
|
|
options(noreturn)
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-08-07 15:58:05 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
// FIXME: The `*4` and `*8` variants should be defined as aliases.
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) {
|
2023-07-20 17:23:56 +03:00
|
|
|
crate::mem::memcpy(dest, src, n);
|
2022-02-06 09:20:43 +00:00
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize) {
|
|
|
|
|
// We are guaranteed 4-alignment, so accessing at u32 is okay.
|
|
|
|
|
let mut dest = dest as *mut u32;
|
|
|
|
|
let mut src = src as *mut u32;
|
|
|
|
|
let mut n = n;
|
|
|
|
|
|
|
|
|
|
while n >= 4 {
|
|
|
|
|
*dest = *src;
|
|
|
|
|
dest = dest.offset(1);
|
|
|
|
|
src = src.offset(1);
|
|
|
|
|
n -= 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__aeabi_memcpy(dest as *mut u8, src as *const u8, n);
|
2017-06-29 22:40:58 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) {
|
|
|
|
|
__aeabi_memcpy4(dest, src, n);
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) {
|
2023-07-20 17:23:56 +03:00
|
|
|
crate::mem::memmove(dest, src, n);
|
2022-02-06 09:20:43 +00:00
|
|
|
}
|
2016-08-07 15:58:05 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) {
|
|
|
|
|
__aeabi_memmove(dest, src, n);
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) {
|
|
|
|
|
__aeabi_memmove(dest, src, n);
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) {
|
|
|
|
|
// Note the different argument order
|
2023-07-20 17:23:56 +03:00
|
|
|
crate::mem::memset(dest, c, n);
|
2022-02-06 09:20:43 +00:00
|
|
|
}
|
2016-08-07 15:58:05 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, n: usize, c: i32) {
|
|
|
|
|
let mut dest = dest as *mut u32;
|
|
|
|
|
let mut n = n;
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
let byte = (c as u32) & 0xff;
|
|
|
|
|
let c = (byte << 24) | (byte << 16) | (byte << 8) | byte;
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
while n >= 4 {
|
|
|
|
|
*dest = c;
|
|
|
|
|
dest = dest.offset(1);
|
|
|
|
|
n -= 4;
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
__aeabi_memset(dest as *mut u8, n, byte as i32);
|
2017-06-29 22:40:58 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) {
|
|
|
|
|
__aeabi_memset4(dest, n, c);
|
|
|
|
|
}
|
2016-08-07 15:58:05 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(target_os = "ios"))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr(dest: *mut u8, n: usize) {
|
|
|
|
|
__aeabi_memset(dest, n, 0);
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr4(dest: *mut u8, n: usize) {
|
|
|
|
|
__aeabi_memset4(dest, n, 0);
|
|
|
|
|
}
|
2017-06-29 22:40:58 -05:00
|
|
|
|
2022-02-06 09:20:43 +00:00
|
|
|
#[cfg(not(any(target_os = "ios", target_env = "msvc")))]
|
|
|
|
|
pub unsafe extern "aapcs" fn __aeabi_memclr8(dest: *mut u8, n: usize) {
|
|
|
|
|
__aeabi_memset4(dest, n, 0);
|
|
|
|
|
}
|
2016-08-08 07:20:39 +01:00
|
|
|
}
|