From 63b8b79dd7e096b8c5bc7a051c50c2f927c56d48 Mon Sep 17 00:00:00 2001 From: Logan McNaughton <848146+loganmc10@users.noreply.github.com> Date: Sat, 11 Jan 2025 14:48:57 +0100 Subject: [PATCH] More RSP cleanup --- src/device/rsp_su_instructions.rs | 31 +++++++++---------------------- src/device/rsp_vu_instructions.rs | 22 ++++++---------------- 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/device/rsp_su_instructions.rs b/src/device/rsp_su_instructions.rs index 5671db8..12eaf2a 100644 --- a/src/device/rsp_su_instructions.rs +++ b/src/device/rsp_su_instructions.rs @@ -508,7 +508,7 @@ pub fn cfc2(device: &mut device::Device, opcode: u32) { lo = &mut device.rsp.cpu.vce; } _ => { - panic!("unknown ctc2") + panic!("unknown cfc2") } } @@ -687,8 +687,7 @@ pub fn lpv(device: &mut device::Device, opcode: u32) { let index = ((address & 7) as u8).wrapping_sub(velement(opcode)); address &= !7; - let mut offset: u8 = 0; - while offset < 8 { + for offset in 0..8 { modify_vpr_element( &mut device.rsp.cpu.vpr[rt(opcode) as usize], offset, @@ -696,7 +695,6 @@ pub fn lpv(device: &mut device::Device, opcode: u32) { & 0xFFF) as usize] as u16) << 8, ); - offset += 1; } } @@ -706,8 +704,7 @@ pub fn luv(device: &mut device::Device, opcode: u32) { let index = ((address & 7) as u8).wrapping_sub(velement(opcode)); address &= !7; - let mut offset: u8 = 0; - while offset < 8 { + for offset in 0..8 { modify_vpr_element( &mut device.rsp.cpu.vpr[rt(opcode) as usize], offset, @@ -715,7 +712,6 @@ pub fn luv(device: &mut device::Device, opcode: u32) { & 0xFFF) as usize] as u16) << 7, ); - offset += 1; } } @@ -725,8 +721,7 @@ pub fn lhv(device: &mut device::Device, opcode: u32) { let index = ((address & 7) as u8).wrapping_sub(velement(opcode)); address &= !7; - let mut offset: u8 = 0; - while offset < 8 { + for offset in 0..8 { modify_vpr_element( &mut device.rsp.cpu.vpr[rt(opcode) as usize], offset, @@ -734,7 +729,6 @@ pub fn lhv(device: &mut device::Device, opcode: u32) { & 0xFFF) as usize] as u16) << 7, ); - offset += 1; } } @@ -784,8 +778,7 @@ pub fn ltv(device: &mut device::Device, opcode: u32) { address = begin + (((velement(opcode)) as u32 + (address & 8)) & 15); let vtbase = rt(opcode) & !7; let mut vtoff = (velement(opcode)) as u32 >> 1; - let mut i = 0; - while i < 8 { + for i in 0..8 { modify_vpr_byte( &mut device.rsp.cpu.vpr[(vtbase + vtoff) as usize], i * 2, @@ -805,7 +798,6 @@ pub fn ltv(device: &mut device::Device, opcode: u32) { address = begin } vtoff = (vtoff + 1) & 7; - i += 1; } } @@ -934,13 +926,11 @@ pub fn shv(device: &mut device::Device, opcode: u32) { let element = velement(opcode); let index = (address & 7) as u8; address &= !7; - let mut offset = 0; - while offset < 8 { + for offset in 0..8 { let byte_val = element + offset * 2; let value = (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val) << 1) | (get_vpr_byte(device.rsp.cpu.vpr[rt(opcode) as usize], byte_val + 1) >> 7); device.rsp.mem[((address + ((index + offset * 2) & 15) as u32) & 0xFFF) as usize] = value; - offset += 1; } } @@ -949,8 +939,7 @@ pub fn sfv(device: &mut device::Device, opcode: u32) { .wrapping_add(sign_extend_7bit_offset(voffset(opcode), 4)); let base = address & 7; address &= !7; - let element = velement(opcode); - let elements = match element { + let elements = match velement(opcode) { 0 | 15 => [0, 1, 2, 3], 1 => [6, 7, 4, 5], 4 => [1, 2, 3, 0], @@ -967,12 +956,10 @@ pub fn sfv(device: &mut device::Device, opcode: u32) { } }; let mut offset = 0; - let mut i = 0; - while i < 4 { + for element in elements { device.rsp.mem[((address + ((base + offset) & 15)) & 0xFFF) as usize] = - (get_vpr_element(device.rsp.cpu.vpr[rt(opcode) as usize], elements[i]) >> 7) as u8; + (get_vpr_element(device.rsp.cpu.vpr[rt(opcode) as usize], element) >> 7) as u8; offset += 4; - i += 1; } } diff --git a/src/device/rsp_vu_instructions.rs b/src/device/rsp_vu_instructions.rs index 948a797..3d64a43 100644 --- a/src/device/rsp_vu_instructions.rs +++ b/src/device/rsp_vu_instructions.rs @@ -23,11 +23,11 @@ pub fn de(opcode: u32) -> u32 { } pub fn clamp_signed_32(value: i32) -> i16 { - return value.clamp(-32768, 32767) as i16; + value.clamp(-32768, 32767) as i16 } pub fn clamp_signed_64(value: i64) -> i16 { - return value.clamp(-32768, 32767) as i16; + value.clamp(-32768, 32767) as i16 } pub fn s_clip(x: i64, bits: u32) -> i64 { @@ -144,8 +144,7 @@ pub fn vrndp(device: &mut device::Device, opcode: u32) { let accm: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accm) }; let accl: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accl) }; - let mut n = 0; - while n < 8 { + for n in 0..8 { let mut product = get_vpr_element(vte, n) as i16 as i32; if vs(opcode) & 1 != 0 { product <<= 16 @@ -169,8 +168,6 @@ pub fn vrndp(device: &mut device::Device, opcode: u32) { n, clamp_signed_64(acc >> 16) as u16, ); - - n += 1; } } @@ -186,8 +183,7 @@ pub fn vmulq(device: &mut device::Device, opcode: u32) { let accm: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accm) }; let accl: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accl) }; - let mut n = 0; - while n < 8 { + for n in 0..8 { let mut product = (get_vpr_element(device.rsp.cpu.vpr[vs(opcode) as usize], n) as i16 as i32) .wrapping_mul(get_vpr_element(vte, n) as i16 as i32); @@ -202,7 +198,6 @@ pub fn vmulq(device: &mut device::Device, opcode: u32) { n, (clamp_signed_32(product >> 1) & !15) as u16, ); - n += 1; } } @@ -407,8 +402,7 @@ pub fn vrndn(device: &mut device::Device, opcode: u32) { let accm: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accm) }; let accl: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accl) }; - let mut n = 0; - while n < 8 { + for n in 0..8 { let mut product = get_vpr_element(vte, n) as i16 as i32; if vs(opcode) & 1 != 0 { product <<= 16 @@ -432,8 +426,6 @@ pub fn vrndn(device: &mut device::Device, opcode: u32) { n, clamp_signed_64(acc >> 16) as u16, ); - - n += 1; } } @@ -441,8 +433,7 @@ pub fn vmacq(device: &mut device::Device, opcode: u32) { let acch: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.acch) }; let accm: &mut u128 = unsafe { std::mem::transmute(&mut device.rsp.cpu.accm) }; - let mut n = 0; - while n < 8 { + for n in 0..8 { let mut product = ((get_vpr_element(*acch, n) as i32) << 16) | (get_vpr_element(*accm, n) as i32); if product < 0 && (product & (1 << 5)) == 0 { @@ -457,7 +448,6 @@ pub fn vmacq(device: &mut device::Device, opcode: u32) { n, (clamp_signed_32(product >> 1) & !15) as u16, ); - n += 1; } }