Skip to content
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

use naked_asm! macro for recent nightly #205

Merged
merged 1 commit into from
Jan 10, 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: 12 additions & 24 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#[cfg_attr(feature = "on_gba", instruction_set(arm::a32))]
#[cfg_attr(feature = "on_gba", link_section = ".iwram.copy_u8_unchecked")]
pub unsafe extern "C" fn copy_u8_unchecked(
dest: *mut u8, src: *const u8, byte_count: usize,

Check warning on line 15 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `dest`

Check warning on line 15 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `src`

Check warning on line 15 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `byte_count`
) {
on_gba_or_unimplemented!(unsafe {
// Note(Lokathor): This loop setup assumes that the `byte_count` is usually
Expand Down Expand Up @@ -55,7 +55,7 @@
#[cfg_attr(feature = "on_gba", instruction_set(arm::a32))]
#[cfg_attr(feature = "on_gba", link_section = ".iwram.copy_u32x8_unchecked")]
pub unsafe extern "C" fn copy_u32x8_unchecked(
dest: *mut [u32; 8], src: *const [u32; 8], count: usize,

Check warning on line 58 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `dest`

Check warning on line 58 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `src`

Check warning on line 58 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `count`
) {
on_gba_or_unimplemented!(unsafe {
// Note(Lokathor): Same loop logic as `copy_u8_unchecked`, we're just
Expand Down Expand Up @@ -97,7 +97,7 @@
#[cfg_attr(feature = "on_gba", instruction_set(arm::a32))]
#[cfg_attr(feature = "on_gba", link_section = ".iwram.set_u32x80_unchecked")]
pub unsafe extern "C" fn set_u32x80_unchecked(
dest: *mut [u32; 80], word: u32, count: usize,

Check warning on line 100 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `dest`

Check warning on line 100 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `word`

Check warning on line 100 in src/mem.rs

View workflow job for this annotation

GitHub Actions / build (nightly)

unused variable: `count`
) {
on_gba_or_unimplemented!(unsafe {
core::arch::asm!(
Expand Down Expand Up @@ -238,7 +238,7 @@
pub unsafe extern "C" fn __aeabi_memcpy4(
dest: *mut u32, src: *const u32, byte_count: usize,
) {
core::arch::asm! {
core::arch::naked_asm! {
bracer::when!(("r2" >=u "#32") [2] {
"push {{r4-r9}}",
"1:",
Expand Down Expand Up @@ -275,7 +275,6 @@
"ldrbmi r3, [r1], #1",
"strbmi r3, [r0], #1",
"bx lr",
options(noreturn),
}
}

Expand Down Expand Up @@ -309,7 +308,7 @@
pub unsafe extern "C" fn __aeabi_memcpy(
dest: *mut u8, src: *const u8, byte_count: usize,
) {
core::arch::asm! {
core::arch::naked_asm! {
"cmp r2, #7", // if count <= (fix+word): just byte copy
"ble {__aeabi_memcpy1}",

Expand Down Expand Up @@ -341,7 +340,6 @@
__aeabi_memcpy4 = sym __aeabi_memcpy4,
__aeabi_memcpy2 = sym __aeabi_memcpy2,
__aeabi_memcpy1 = sym __aeabi_memcpy1,
options(noreturn)
}
}

Expand All @@ -361,13 +359,12 @@
) -> *mut u8 {
// I've seen a standard call to `__aeabi_memcpy` give weird codegen,
// so we (currently) do the call manually.
core::arch::asm! {
core::arch::naked_asm! {
"push {{r0, lr}}",
"bl {__aeabi_memcpy}",
"pop {{r0, lr}}",
"bx lr",
__aeabi_memcpy = sym __aeabi_memcpy,
options(noreturn)
}
}

Expand Down Expand Up @@ -427,7 +424,7 @@
unsafe extern "C" fn reverse_copy_u32(
dest: *mut u32, src: *const u32, byte_count: usize,
) {
core::arch::asm! {
core::arch::naked_asm! {
bracer::when!(("r2" >=u "#32") [2] {
"push {{r4-r9}}",
"1:",
Expand Down Expand Up @@ -463,7 +460,6 @@
"ldrbmi r3, [r1, #-1]!",
"strbmi r3, [r0, #-1]!",
"bx lr",
options(noreturn),
}
}

Expand Down Expand Up @@ -508,7 +504,7 @@
pub unsafe extern "C" fn __aeabi_memmove(
dest: *mut u8, src: *const u8, byte_count: usize,
) {
core::arch::asm! {
core::arch::naked_asm! {
// when d > s we need to copy back-to-front
bracer::when!(("r0" >=u "r1") [1] {
"add r0, r0, r2",
Expand Down Expand Up @@ -542,7 +538,6 @@
reverse_copy_u8 = sym reverse_copy_u8,
reverse_copy_u16 = sym reverse_copy_u16,
reverse_copy_u32 = sym reverse_copy_u32,
options(noreturn),
}
}

Expand All @@ -561,13 +556,12 @@
pub unsafe extern "C" fn memmove(
dest: *mut u8, src: *const u8, byte_count: usize,
) -> *mut u8 {
core::arch::asm! {
core::arch::naked_asm! {
"push {{r0, lr}}",
"bl {__aeabi_memmove}",
"pop {{r0, lr}}",
"bx lr",
__aeabi_memmove = sym __aeabi_memmove,
options(noreturn)
}
}

Expand Down Expand Up @@ -612,7 +606,7 @@
pub unsafe extern "C" fn __aeabi_memset(
dest: *mut u8, byte_count: usize, byte: i32,
) {
core::arch::asm! {
core::arch::naked_asm! {
bracer::when!(("r1" >=u "#8") [7] {
// duplicate the byte across all of r2 and r3
"and r2, r2, #0xFF",
Expand Down Expand Up @@ -666,7 +660,6 @@
"strbcs r2, [r0], #1",
"bgt 9b",
"bx lr",
options(noreturn)
}
}

Expand All @@ -686,7 +679,7 @@
pub unsafe extern "C" fn memset(
dest: *mut u8, byte: i32, byte_count: usize,
) -> *mut u8 {
core::arch::asm! {
core::arch::naked_asm! {
"push {{r0, lr}}",
"mov r3, r2",
"mov r2, r1",
Expand All @@ -695,7 +688,6 @@
"pop {{r0, lr}}",
"bx lr",
__aeabi_memset = sym __aeabi_memset,
options(noreturn)
}
}

Expand Down Expand Up @@ -747,7 +739,7 @@
#[instruction_set(arm::a32)]
#[link_section = ".iwram.aeabi.uread4"]
unsafe extern "C" fn __aeabi_uread4(address: *const c_void) -> u32 {
core::arch::asm!(
core::arch::naked_asm!(
"ldrb r2, [r0]",
"ldrb r3, [r0, #1]",
"orr r2, r2, r3, lsl #8",
Expand All @@ -757,7 +749,6 @@
"orr r2, r2, r3, lsl #24",
"mov r0, r2",
"bx lr",
options(noreturn),
)
}

Expand All @@ -771,7 +762,7 @@
#[instruction_set(arm::a32)]
#[link_section = ".iwram.aeabi.uwrite4"]
unsafe extern "C" fn __aeabi_uwrite4(value: u32, address: *mut c_void) {
core::arch::asm!(
core::arch::naked_asm!(
"strb r0, [r1]",
"lsr r2, r0, #8",
"strb r2, [r1, #1]",
Expand All @@ -780,7 +771,6 @@
"lsr r2, r2, #8",
"strb r2, [r1, #3]",
"bx lr",
options(noreturn),
)
}

Expand All @@ -794,7 +784,7 @@
#[instruction_set(arm::a32)]
#[link_section = ".iwram.aeabi.uread8"]
unsafe extern "C" fn __aeabi_uread8(address: *const c_void) -> u64 {
core::arch::asm!(
core::arch::naked_asm!(
"ldrb r1, [r0, #4]",
"ldrb r2, [r0, #5]",
"orr r1, r1, r2, lsl #8",
Expand All @@ -804,7 +794,6 @@
"orr r1, r1, r2, lsl #24",
"b {__aeabi_uread4}",
__aeabi_uread4 = sym __aeabi_uread4,
options(noreturn),
)
}

Expand All @@ -818,7 +807,7 @@
#[instruction_set(arm::a32)]
#[link_section = ".iwram.aeabi.uwrite8"]
unsafe extern "C" fn __aeabi_uwrite8(value: u64, address: *mut c_void) {
core::arch::asm!(
core::arch::naked_asm!(
"strb r0, [r2]",
"lsr r3, r0, #8",
"strb r3, [r2, #1]",
Expand All @@ -834,7 +823,6 @@
"lsr r3, r3, #8",
"strb r3, [r2, #7]",
"bx lr",
options(noreturn),
)
}
}
Loading