mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Use hand written fast fill to save a few more cycles
This commit is contained in:
parent
e051a17836
commit
4969672c73
|
@ -136,12 +136,34 @@ agb_arm_func agb_rs__mixer_add_stereo
|
||||||
|
|
||||||
agb_arm_end agb_rs__mixer_add_stereo
|
agb_arm_end agb_rs__mixer_add_stereo
|
||||||
|
|
||||||
|
.section .iwram
|
||||||
|
.balign 4
|
||||||
|
constant_zero:
|
||||||
|
.rept 4
|
||||||
|
.word 0
|
||||||
|
.endr
|
||||||
|
|
||||||
agb_arm_func agb_rs__mixer_collapse
|
agb_arm_func agb_rs__mixer_collapse
|
||||||
@ Arguments:
|
@ Arguments:
|
||||||
@ r0 = target buffer (i8)
|
@ r0 = target buffer (i8)
|
||||||
@ r1 = input buffer (i16) of fixnums with 4 bits of precision (read in sets of i16 in an i32)
|
@ r1 = input buffer (i16) of fixnums with 4 bits of precision (read in sets of i16 in an i32)
|
||||||
push {r4-r11}
|
push {r4-r11}
|
||||||
|
|
||||||
|
@ zero registers r4-r7 (4 of them)
|
||||||
|
mov r8, #constant_zero
|
||||||
|
ldm r8, {r4-r7}
|
||||||
|
|
||||||
|
@ get the size of the buffer
|
||||||
|
ldr r9, agb_rs__buffer_size
|
||||||
|
@ make a copy of the output buffer pointer
|
||||||
|
mov r10, r0
|
||||||
|
1:
|
||||||
|
@ zero 4 words worth of the output buffer
|
||||||
|
stmia r10, {r4-r7}
|
||||||
|
subs r9, r9, #16
|
||||||
|
@ loop if we haven't zeroed everything
|
||||||
|
bne 1b
|
||||||
|
|
||||||
CONST_0 .req r7
|
CONST_0 .req r7
|
||||||
CONST_FF .req r8
|
CONST_FF .req r8
|
||||||
CONST_127 .req r9
|
CONST_127 .req r9
|
||||||
|
|
|
@ -5,7 +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,
|
||||||
|
@ -245,9 +245,6 @@ impl MixerBuffer {
|
||||||
channel.playback_speed
|
channel.playback_speed
|
||||||
};
|
};
|
||||||
|
|
||||||
let right_amount = ((channel.panning + 1) / 2) * channel.volume;
|
|
||||||
let left_amount = ((-channel.panning + 1) / 2) * channel.volume;
|
|
||||||
|
|
||||||
if (channel.pos + playback_speed * constants::SOUND_BUFFER_SIZE).floor()
|
if (channel.pos + playback_speed * constants::SOUND_BUFFER_SIZE).floor()
|
||||||
>= channel.data.len()
|
>= channel.data.len()
|
||||||
{
|
{
|
||||||
|
@ -268,6 +265,9 @@ impl MixerBuffer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
let right_amount = ((channel.panning + 1) / 2) * channel.volume;
|
||||||
|
let left_amount = ((-channel.panning + 1) / 2) * channel.volume;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
agb_rs__mixer_add(
|
agb_rs__mixer_add(
|
||||||
channel.data.as_ptr().add(channel.pos.floor()),
|
channel.data.as_ptr().add(channel.pos.floor()),
|
||||||
|
@ -285,7 +285,6 @@ 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;
|
||||||
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());
|
||||||
|
|
|
@ -120,29 +120,6 @@ pub fn arc_tan2(x: i16, y: i32) -> i16 {
|
||||||
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>,
|
||||||
|
|
Loading…
Reference in a new issue