Skip to content

Commit 3df4437

Browse files
committed
WIP
1 parent b1304de commit 3df4437

File tree

13 files changed

+182
-226
lines changed

13 files changed

+182
-226
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ debug = true
6363

6464
[profile.release.package."*"]
6565
opt-level = 3
66+
debug = true
6667

6768
[profile.release]
6869
panic = "abort"
6970
lto = "fat"
71+
debug = true

src/bitset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ impl<const SIZE: usize> Bitset<SIZE> {
1212
let bit = bit.into();
1313
let array_index = bit >> 5;
1414
let pos_index = bit & 31;
15-
self.0[array_index] |= 1 << pos_index;
15+
unsafe { *self.0.get_unchecked_mut(array_index) |= 1 << pos_index };
1616
}
1717

1818
fn _sub(&mut self, bit: impl Into<usize>) {
1919
let bit = bit.into();
2020
let array_index = bit >> 5;
2121
let pos_index = bit & 31;
22-
self.0[array_index] &= !(1 << pos_index);
22+
unsafe { *self.0.get_unchecked_mut(array_index) &= !(1 << pos_index) };
2323
}
2424

2525
pub fn contains(&self, bit: impl Into<usize>) -> bool {
2626
let bit = bit.into();
2727
let array_index = bit >> 5;
2828
let pos_index = bit & 31;
29-
self.0[array_index] & (1 << pos_index) != 0
29+
unsafe { *self.0.get_unchecked(array_index) & (1 << pos_index) != 0 }
3030
}
3131

3232
pub const fn len(&self) -> usize {

src/core/graphics/gpu_3d/registers_3d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,13 +1387,13 @@ impl Gpu3DRegisters {
13871387
self.queue_entry(Entry::new(self.gx_fifo as u8, value & mask), emu);
13881388
self.cmd_fifo_param_count += 1;
13891389

1390-
if self.cmd_fifo_param_count == FIFO_PARAM_COUNTS[(self.gx_fifo & 0xFF) as usize] as u32 {
1390+
if self.cmd_fifo_param_count == unsafe { *FIFO_PARAM_COUNTS.get_unchecked((self.gx_fifo & 0xFF) as usize) } as u32 {
13911391
self.gx_fifo >>= 8;
13921392
self.cmd_fifo_param_count = 0;
13931393
}
13941394
}
13951395

1396-
while self.gx_fifo != 0 && FIFO_PARAM_COUNTS[(self.gx_fifo & 0xFF) as usize] == 0 {
1396+
while self.gx_fifo != 0 && unsafe { *FIFO_PARAM_COUNTS.get_unchecked((self.gx_fifo & 0xFF) as usize) } == 0 {
13971397
self.queue_entry(Entry::new(self.gx_fifo as u8, value & mask), emu);
13981398
self.gx_fifo >>= 8;
13991399
}

src/core/hle/sound_nitro.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl SoundNitro {
217217

218218
let mut main_cnt = MainSoundCnt::from(0);
219219
main_cnt.set_master_volume(u7::new(0x7F));
220-
main_cnt.set_master_enable(u1::new(1));
220+
main_cnt.set_master_enable(true);
221221
get_spu_mut!(emu).set_main_sound_cnt(!0, u16::from(main_cnt), emu);
222222

223223
get_cm_mut!(emu).schedule(174592, EventType::SoundCmdHle);
@@ -247,9 +247,9 @@ impl SoundNitro {
247247
fn stop_channel(chan_id: usize, hold: bool, emu: &mut Emu) {
248248
let spu = get_spu_mut!(emu);
249249
let mut cnt = SoundCnt::from(spu.get_cnt(chan_id));
250-
cnt.set_start_status(u1::new(0));
250+
cnt.set_start_status(false);
251251
if hold {
252-
cnt.set_hold(u1::new(1));
252+
cnt.set_hold(true);
253253
}
254254
spu.set_cnt(chan_id, !0, u32::from(cnt), emu);
255255
}
@@ -488,7 +488,7 @@ impl SoundNitro {
488488
if channel.status_flags & (1 << 3) != 0 {
489489
let spu = get_spu_mut!(emu);
490490
let mut cnt = SoundCnt::from(spu.get_cnt(i));
491-
cnt.set_start_status(u1::new(1));
491+
cnt.set_start_status(true);
492492
spu.set_cnt(i, !0, u32::from(cnt), emu);
493493
}
494494

@@ -803,21 +803,21 @@ impl SoundNitro {
803803

804804
let spu = get_spu_mut!(emu);
805805
let mut cnt = SoundCnt::from(spu.get_cnt(i));
806-
cnt.set_start_status(u1::new(1));
806+
cnt.set_start_status(true);
807807
spu.set_cnt(i, !0, u32::from(cnt), emu);
808808
}
809809

810810
if mask_cap & 0x1 != 0 {
811811
let spu = get_spu_mut!(emu);
812812
let mut cap_cnt = SoundCapCnt::from(spu.get_snd_cap_cnt(0));
813-
cap_cnt.set_cap_start_status(u1::new(1));
813+
cap_cnt.set_cap_start_status(true);
814814
spu.set_snd_cap_cnt(0, u8::from(cap_cnt));
815815
}
816816

817817
if mask_cap & 0x2 != 0 {
818818
let spu = get_spu_mut!(emu);
819819
let mut cap_cnt = SoundCapCnt::from(spu.get_snd_cap_cnt(1));
820-
cap_cnt.set_cap_start_status(u1::new(1));
820+
cap_cnt.set_cap_start_status(true);
821821
spu.set_snd_cap_cnt(1, u8::from(cap_cnt));
822822
}
823823

@@ -1008,11 +1008,11 @@ impl SoundNitro {
10081008

10091009
let spu = get_spu_mut!(emu);
10101010
let mut cnt = MainSoundCnt::from(spu.get_main_sound_cnt());
1011-
cnt.set_master_enable(u1::new(1));
1011+
cnt.set_master_enable(true);
10121012
cnt.set_left_output_from(u2::new((output_l & 0x3) as u8));
10131013
cnt.set_right_output_from(u2::new((output_r & 0x3) as u8));
1014-
cnt.set_output_ch1_to_mixer(u1::new((mixch1 & 0x1) as u8));
1015-
cnt.set_output_ch3_to_mixer(u1::new((mixch3 & 0x1) as u8));
1014+
cnt.set_output_ch1_to_mixer((mixch1 & 0x1) != 0);
1015+
cnt.set_output_ch3_to_mixer((mixch3 & 0x1) != 0);
10161016
spu.set_main_sound_cnt(!0, u16::from(cnt), emu);
10171017
}
10181018
0x1A => {}

src/core/spu.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ pub struct SoundCnt {
7979
not_used: u1,
8080
pub volume_div: u2,
8181
not_used1: u5,
82-
pub hold: u1,
82+
pub hold: bool,
8383
pub panning: u7,
8484
not_used2: u1,
8585
pub wave_duty: u3,
8686
pub repeat_mode: u2,
8787
pub format: u2,
88-
pub start_status: u1,
88+
pub start_status: bool,
8989
}
9090

9191
impl SoundCnt {
@@ -123,10 +123,10 @@ pub struct MainSoundCnt {
123123
not_used: u1,
124124
pub left_output_from: u2,
125125
pub right_output_from: u2,
126-
pub output_ch1_to_mixer: u1,
127-
pub output_ch3_to_mixer: u1,
126+
pub output_ch1_to_mixer: bool,
127+
pub output_ch3_to_mixer: bool,
128128
not_used2: u1,
129-
pub master_enable: u1,
129+
pub master_enable: bool,
130130
}
131131

132132
#[derive(Copy, Clone, Default)]
@@ -159,12 +159,12 @@ struct AdpcmHeader {
159159
#[bitsize(8)]
160160
#[derive(FromBits)]
161161
pub struct SoundCapCnt {
162-
pub cnt_associated_channels: u1,
163-
pub cap_src_select: u1,
164-
pub cap_repeat: u1,
165-
pub cap_format: u1,
162+
pub cnt_associated_channels: bool,
163+
pub cap_src_select: bool,
164+
pub cap_repeat: bool,
165+
pub cap_format: bool,
166166
not_used: u3,
167-
pub cap_start_status: u1,
167+
pub cap_start_status: bool,
168168
}
169169

170170
pub struct Spu {
@@ -211,7 +211,7 @@ impl Spu {
211211
}
212212

213213
pub fn set_cnt(&mut self, channel: usize, mut mask: u32, value: u32, emu: &mut Emu) {
214-
let was_disabled = !bool::from(self.channels[channel].cnt.start_status());
214+
let was_disabled = !self.channels[channel].cnt.start_status();
215215

216216
mask &= 0xFF7F837F;
217217
self.channels[channel].cnt = ((u32::from(self.channels[channel].cnt) & !mask) | (value & mask)).into();
@@ -222,12 +222,12 @@ impl Spu {
222222
self.channels[channel].volume = volume;
223223

224224
if was_disabled
225-
&& bool::from(self.channels[channel].cnt.start_status())
226-
&& bool::from(self.main_sound_cnt.master_enable())
225+
&& self.channels[channel].cnt.start_status()
226+
&& self.main_sound_cnt.master_enable()
227227
&& (self.channels[channel].sad != 0 || self.channels[channel].cnt.get_format() == SoundChannelFormat::PsgNoise)
228228
{
229229
self.start_channel(channel, emu);
230-
} else if !bool::from(self.channels[channel].cnt.start_status()) {
230+
} else if !self.channels[channel].cnt.start_status() {
231231
self.channels[channel].active = false;
232232
}
233233
}
@@ -237,7 +237,7 @@ impl Spu {
237237
self.channels[channel].sad = (self.channels[channel].sad & !mask) | (value & mask);
238238

239239
if self.channels[channel].cnt.get_format() != SoundChannelFormat::PsgNoise {
240-
if self.channels[channel].sad != 0 && (bool::from(self.main_sound_cnt.master_enable()) && bool::from(self.channels[channel].cnt.start_status())) {
240+
if self.channels[channel].sad != 0 && (self.main_sound_cnt.master_enable() && self.channels[channel].cnt.start_status()) {
241241
self.start_channel(channel, emu);
242242
} else {
243243
self.channels[channel].active = false;
@@ -259,7 +259,7 @@ impl Spu {
259259
}
260260

261261
pub fn set_main_sound_cnt(&mut self, mut mask: u16, value: u16, emu: &mut Emu) {
262-
let was_disabled = !bool::from(self.main_sound_cnt.master_enable());
262+
let was_disabled = !self.main_sound_cnt.master_enable();
263263

264264
mask &= 0xBF7F;
265265
self.main_sound_cnt = ((u16::from(self.main_sound_cnt) & !mask) | (value & mask)).into();
@@ -269,13 +269,13 @@ impl Spu {
269269
}
270270
self.master_volume = volume;
271271

272-
if was_disabled && bool::from(self.main_sound_cnt.master_enable()) {
272+
if was_disabled && self.main_sound_cnt.master_enable() {
273273
for i in 0..CHANNEL_COUNT {
274-
if bool::from(self.channels[i].cnt.start_status()) && (self.channels[i].sad != 0 || self.channels[i].cnt.get_format() == SoundChannelFormat::PsgNoise) {
274+
if self.channels[i].cnt.start_status() && (self.channels[i].sad != 0 || self.channels[i].cnt.get_format() == SoundChannelFormat::PsgNoise) {
275275
self.start_channel(i, emu);
276276
}
277277
}
278-
} else if !bool::from(self.main_sound_cnt.master_enable()) {
278+
} else if !self.main_sound_cnt.master_enable() {
279279
for channel in &mut self.channels {
280280
channel.active = false;
281281
}
@@ -401,7 +401,7 @@ impl Spu {
401401

402402
if unlikely(!get_spu!(emu).audio_enabled) {
403403
for i in 0..CHANNEL_COUNT {
404-
get_channel_mut!(emu, i).cnt.set_start_status(u1::new(0));
404+
get_channel_mut!(emu, i).cnt.set_start_status(false);
405405
}
406406
let spu = get_spu_mut!(emu);
407407
spu.samples_buffer.push(0);
@@ -466,7 +466,7 @@ impl Spu {
466466
channel.adpcm_toggle = false;
467467
}
468468
} else {
469-
channel.cnt.set_start_status(u1::new(0));
469+
channel.cnt.set_start_status(false);
470470
channel.active = false;
471471
break;
472472
}
@@ -492,13 +492,13 @@ impl Spu {
492492
if i == 1 {
493493
channels_left[0] = data_left;
494494
channels_right[0] = data_right;
495-
if bool::from(get_spu!(emu).main_sound_cnt.output_ch1_to_mixer()) {
495+
if get_spu!(emu).main_sound_cnt.output_ch1_to_mixer() {
496496
continue;
497497
}
498498
} else if i == 3 {
499499
channels_left[1] = data_left;
500500
channels_right[1] = data_right;
501-
if bool::from(get_spu!(emu).main_sound_cnt.output_ch3_to_mixer()) {
501+
if get_spu!(emu).main_sound_cnt.output_ch3_to_mixer() {
502502
continue;
503503
}
504504
}

src/core/thread_regs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl ThreadRegs {
129129
}
130130
}
131131

132+
#[inline]
132133
pub fn set_cpsr_with_flags(&mut self, value: u32, flags: u8, emu: &mut Emu) {
133134
if flags & 1 == 1 {
134135
let mask = if u8::from(Cpsr::from(self.cpsr).mode()) == 0x10 { 0xE0 } else { 0xFF };
@@ -143,6 +144,7 @@ impl ThreadRegs {
143144
}
144145
}
145146

147+
#[inline]
146148
pub fn set_spsr_with_flags(&mut self, value: u32, flags: u8) {
147149
if DEBUG_LOG {
148150
let mode = u8::from(Cpsr::from(self.cpsr).mode());
@@ -158,6 +160,7 @@ impl ThreadRegs {
158160
}
159161
}
160162

163+
#[inline]
161164
pub fn restore_spsr(&mut self, emu: &mut Emu) {
162165
if !self.is_user {
163166
self.set_cpsr::<false>(self.spsr, emu);

src/jit/assembler/block_asm.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::jit::assembler::block_inst::{BlockAluOp, BlockAluSetCond, BlockInst,
55
use crate::jit::assembler::block_inst_list::BlockInstList;
66
use crate::jit::assembler::block_reg_allocator::ALLOCATION_REGS;
77
use crate::jit::assembler::block_reg_set::BlockRegSet;
8-
use crate::jit::assembler::{BlockAsmBuf, BlockInstKind, BlockLabel, BlockOperand, BlockOperandShift, BlockReg, BlockShift, ANY_REG_LIMIT};
8+
use crate::jit::assembler::{block_inst_list, BlockAsmBuf, BlockInstKind, BlockLabel, BlockOperand, BlockOperandShift, BlockReg, BlockShift, ANY_REG_LIMIT};
99
use crate::jit::inst_info::InstInfo;
1010
use crate::jit::reg::{Reg, RegReserve};
1111
use crate::jit::{Cond, MemoryAmount, ShiftType};
@@ -43,7 +43,7 @@ macro_rules! alu2_op0 {
4343
pub struct BlockAsm<'a> {
4444
pub buf: &'a mut BlockAsmBuf,
4545

46-
pub insts_link: BlockInstList,
46+
insts_link: BlockInstList,
4747

4848
any_reg_count: u16,
4949
freed_any_regs: NoHashSet<u16>,
@@ -801,6 +801,7 @@ impl<'a> BlockAsm<'a> {
801801
}
802802

803803
fn assemble_basic_blocks(&mut self, block_start_pc: u32, thumb: bool) -> (Vec<BasicBlock>, NoHashSet<usize>) {
804+
unsafe { block_inst_list::reset_inst_list_entries() };
804805
for i in 0..self.buf.insts.len() {
805806
self.insts_link.insert_end(i);
806807
}
@@ -941,7 +942,7 @@ impl<'a> BlockAsm<'a> {
941942
}
942943

943944
basic_block.remove_dead_code(self);
944-
// basic_block.consolidate_reg_io(self);
945+
basic_block.consolidate_reg_io(self);
945946
}
946947

947948
(basic_blocks, reachable_blocks)
@@ -972,7 +973,7 @@ impl<'a> BlockAsm<'a> {
972973
}
973974

974975
self.buf.reg_allocator.dirty_regs.clear();
975-
self.buf.reg_allocator.global_mapping.clear();
976+
self.buf.reg_allocator.global_mapping.fill(Reg::None);
976977
let mut input_regs = BlockRegSet::new();
977978
for (i, basic_block) in basic_blocks.iter().enumerate() {
978979
if !reachable_blocks.contains(&i) {
@@ -983,15 +984,15 @@ impl<'a> BlockAsm<'a> {
983984
}
984985
let gp_guest_regs = input_regs.get_guests().get_gp_regs();
985986
for guest_reg in gp_guest_regs {
986-
self.buf.reg_allocator.global_mapping.insert(guest_reg as u16, guest_reg);
987+
self.buf.reg_allocator.global_mapping[guest_reg as usize] = guest_reg;
987988
}
988989

989990
let mut non_input_guest_regs = input_regs;
990991
non_input_guest_regs.remove_guests(gp_guest_regs);
991992
let mut free_input_regs = (!input_regs.get_guests()).get_gp_regs();
992993
for reg in non_input_guest_regs.iter_any() {
993994
let free_input_reg = free_input_regs.pop().unwrap_or(Reg::None);
994-
self.buf.reg_allocator.global_mapping.insert(reg, free_input_reg);
995+
self.buf.reg_allocator.global_mapping[reg as usize] = free_input_reg;
995996
}
996997

997998
if IS_DEBUG && unsafe { BLOCK_LOG } {

0 commit comments

Comments
 (0)