Merge pull request #8 from Amanieu/arm_mem_builttins

Rewrite the arm mem* builtins without asm and naked functions
This commit is contained in:
Jorge Aparicio 2016-08-08 01:42:03 -05:00 committed by GitHub
commit b7a9d45cf0

View File

@ -1,67 +1,74 @@
use core::intrinsics; extern "C" {
fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32;
macro_rules! defer { fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
($($symbol:ident),+ -> $routine:ident) => { fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
$( fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8;
#[naked]
#[no_mangle]
pub extern "C" fn $symbol() {
unsafe {
asm!(concat!("b ", stringify!($routine)));
intrinsics::unreachable();
}
}
)+
}
} }
// FIXME only `__aeabi_memcmp` should be defined like this. The `*4` and `*8` variants should be // FIXME: The `*4` and `*8` variants should be defined as aliases.
// defined as aliases of `__aeabi_memcmp`
defer!(__aeabi_memcmp, __aeabi_memcmp4, __aeabi_memcmp8 -> memcmp);
// FIXME same issue as `__aeabi_memcmp*` #[no_mangle]
defer!(__aeabi_memcpy, __aeabi_memcpy4, __aeabi_memcpy8 -> memcpy); pub unsafe extern "aapcs" fn __aeabi_memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
memcmp(s1, s2, n)
// FIXME same issue as `__aeabi_memcmp*` }
defer!(__aeabi_memmove, __aeabi_memmove4, __aeabi_memmove8 -> memmove); #[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memcmp4(s1: *const u8, s2: *const u8, n: usize) -> i32 {
macro_rules! memset { memcmp(s1, s2, n)
($($symbol:ident),+) => { }
$( #[no_mangle]
#[naked] pub unsafe extern "aapcs" fn __aeabi_memcmp8(s1: *const u8, s2: *const u8, n: usize) -> i32 {
#[no_mangle] memcmp(s1, s2, n)
pub extern "C" fn $symbol() {
unsafe {
asm!("mov r3, r1
mov r1, r2
mov r2, r3
b memset");
intrinsics::unreachable();
}
}
)+
}
} }
// FIXME same issue as `__aeabi_memcmp*` #[no_mangle]
memset!(__aeabi_memset, __aeabi_memset4, __aeabi_memset8); pub unsafe extern "aapcs" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize) {
memcpy(dest, src, n);
macro_rules! memclr { }
($($symbol:ident),+) => { #[no_mangle]
$( pub unsafe extern "aapcs" fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize) {
#[naked] memcpy(dest, src, n);
#[no_mangle] }
pub extern "C" fn $symbol() { #[no_mangle]
unsafe { pub unsafe extern "aapcs" fn __aeabi_memcpy8(dest: *mut u8, src: *const u8, n: usize) {
asm!("mov r2, r1 memcpy(dest, src, n);
mov r1, #0
b memset");
intrinsics::unreachable();
}
}
)+
}
} }
// FIXME same issue as `__aeabi_memcmp*` #[no_mangle]
memclr!(__aeabi_memclr, __aeabi_memclr4, __aeabi_memclr8); pub unsafe extern "aapcs" fn __aeabi_memmove(dest: *mut u8, src: *const u8, n: usize) {
memmove(dest, src, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memmove4(dest: *mut u8, src: *const u8, n: usize) {
memmove(dest, src, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memmove8(dest: *mut u8, src: *const u8, n: usize) {
memmove(dest, src, n);
}
// Note the different argument order
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memset(dest: *mut u8, n: usize, c: i32) {
memset(dest, c, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memset4(dest: *mut u8, n: usize, c: i32) {
memset(dest, c, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memset8(dest: *mut u8, n: usize, c: i32) {
memset(dest, c, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memclr(dest: *mut u8, n: usize) {
memset(dest, 0, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memclr4(dest: *mut u8, n: usize) {
memset(dest, 0, n);
}
#[no_mangle]
pub unsafe extern "aapcs" fn __aeabi_memclr8(dest: *mut u8, n: usize) {
memset(dest, 0, n);
}