Use the syscall to do the memset because the default implementation is really slow

This commit is contained in:
Gwilym Kuiper 2022-06-11 17:22:29 +01:00
parent 4633fe7e3c
commit e6f5494242
2 changed files with 31 additions and 3 deletions

View file

@ -5,6 +5,7 @@ use bare_metal::{CriticalSection, Mutex};
use super::hw; use super::hw;
use super::hw::LeftOrRight; use super::hw::LeftOrRight;
use super::{SoundChannel, SoundPriority}; use super::{SoundChannel, SoundPriority};
use crate::syscall::cpu_fast_fill_i8;
use crate::{ use crate::{
fixnum::Num, fixnum::Num,
interrupt::free, interrupt::free,
@ -284,7 +285,8 @@ impl MixerBuffer {
let write_buffer_index = free(|cs| self.state.borrow(*cs).borrow_mut().active_advanced()); let write_buffer_index = free(|cs| self.state.borrow(*cs).borrow_mut().active_advanced());
let write_buffer = &mut self.buffers[write_buffer_index].0; let write_buffer = &mut self.buffers[write_buffer_index].0;
write_buffer.fill(0); cpu_fast_fill_i8(write_buffer, 0);
unsafe { unsafe {
agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr()); agb_rs__mixer_collapse(write_buffer.as_mut_ptr(), buffer.as_ptr());
} }

View file

@ -2,7 +2,6 @@ use core::arch::asm;
// use crate::display::object::AffineMatrixAttributes; // use crate::display::object::AffineMatrixAttributes;
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn halt() { pub fn halt() {
@ -94,6 +93,9 @@ pub fn arc_tan(n: i16) -> i16 {
"swi 0x09", "swi 0x09",
in("r0") n, in("r0") n,
lateout("r0") result, lateout("r0") result,
lateout("r1") _,
lateout("r2") _,
lateout("r3") _
); );
} }
result result
@ -107,12 +109,36 @@ pub fn arc_tan2(x: i16, y: i32) -> i16 {
in("r0") x, in("r0") x,
in("r1") y, in("r1") y,
lateout("r0") result, lateout("r0") result,
lateout("r2") _,
lateout("r3") _
); );
} }
result result
} }
pub(crate) fn cpu_fast_fill_i8(input: &mut [i8], new_content: i32) {
assert_eq!(
input.len() % (4 * 8),
0,
"Input length must be divisible by 32"
);
let input_ptr = [new_content].as_ptr();
let output_ptr = input.as_mut_ptr();
let length_mode = (1 << 24) | // copy
(input.len() / 4);
unsafe {
asm!(
"swi 0x0c",
in("r0") input_ptr,
in("r1") output_ptr,
in("r2") length_mode,
lateout("r3") _,
);
}
}
// pub fn affine_matrix( // pub fn affine_matrix(
// x_scale: Num<i16, 8>, // x_scale: Num<i16, 8>,
// y_scale: Num<i16, 8>, // y_scale: Num<i16, 8>,