Skip to content

Commit 7b17e30

Browse files
committed
Add release debug profile
1 parent 888afe8 commit 7b17e30

File tree

10 files changed

+99
-64
lines changed

10 files changed

+99
-64
lines changed

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ vitasdk-sys = { version = "0.3.2", features = [
5353
# "SceRazorCapture_stub",
5454
] }
5555

56+
[profile.release-debug]
57+
inherits = "dev"
58+
opt-level = 3
59+
overflow-checks = true
60+
debug-assertions = true
61+
debug = true
62+
panic = "abort"
63+
64+
[profile.release.package."*"]
65+
opt-level = 3
66+
5667
[profile.release]
5768
panic = "abort"
5869
lto = "fat"

build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
use bindgen::Formatter;
2+
use std::fs::File;
3+
use std::io::Write;
24
use std::path::PathBuf;
35
use std::process::Command;
46
use std::{env, fs};
57

68
fn main() {
9+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
10+
11+
let build_profile_name = out_path.to_str().unwrap().split(std::path::MAIN_SEPARATOR).nth_back(3).unwrap();
12+
let build_profile_name_file = out_path.join("build_profile_name");
13+
File::create(build_profile_name_file).unwrap().write_all(build_profile_name.as_bytes()).unwrap();
14+
715
let target = env::var("TARGET").unwrap();
816
if target != "armv7-sony-vita-newlibeabihf" {
917
// Running IDE on anything other than linux will fail, so ignore compile error
@@ -17,7 +25,6 @@ fn main() {
1725
let vitasdk_include_path = vitasdk_path.join("arm-vita-eabi").join("include");
1826
let vitasdk_lib_path = vitasdk_path.join("arm-vita-eabi").join("lib");
1927

20-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
2128
let bindings_file = out_path.join("imgui_bindings.rs");
2229

2330
const IMGUI_HEADERS: [&str; 3] = ["imgui.h", "imgui_internal.h", "imgui_impl_vitagl.h"];

src/core/cpu_regs.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ struct InterruptFlags(u32);
4848

4949
impl Debug for InterruptFlags {
5050
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51-
let mut flags = f.debug_set();
51+
let mut debug_set = f.debug_set();
5252
for i in 0..=InterruptFlag::Wifi as u8 {
5353
if self.0 & (1 << i) != 0 {
54-
flags.entry(&InterruptFlag::from(i));
54+
let flag = InterruptFlag::from(i);
55+
debug_set.entry(&flag);
5556
}
5657
}
57-
flags.finish()
58+
debug_set.finish()
5859
}
5960
}
6061

@@ -112,7 +113,7 @@ impl CpuRegs {
112113
}
113114

114115
pub fn set_irf(&mut self, mask: u32, value: u32) {
115-
debug_println!("{:?} set irf {:?}", self.cpu_type, InterruptFlags(value & mask));
116+
// debug_println!("{:?} set irf {:?}", self.cpu_type, InterruptFlags(value & mask));
116117
self.irf &= !(value & mask);
117118
}
118119

src/core/rtc.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::logging::debug_println;
2+
use crate::IS_DEBUG;
23
use bilge::prelude::*;
34
use chrono::{Datelike, Timelike};
45

@@ -133,27 +134,23 @@ impl Rtc {
133134
}
134135

135136
fn update_date_time(&mut self) {
136-
let local_now = chrono::Local::now();
137-
138-
// let year = local_now.year() as u32 % 100;
139-
// let month = local_now.month() as u8;
140-
// let day = local_now.day() as u8;
141-
// let (hour, is_pm) = {
142-
// let hour = local_now.hour();
143-
// ((if self.cnt & 0x2 == 0 { hour % 12 } else { hour }) as u8, hour >= 12)
144-
// };
145-
// let min = local_now.minute() as u8;
146-
// let sec = local_now.second() as u8;
147-
148-
let year = 2000 as u32 % 100;
149-
let month = 1 as u8;
150-
let day = 1 as u8;
151-
let (hour, is_pm) = {
152-
let hour = 11;
153-
((if self.cnt & 0x2 == 0 { hour % 12 } else { hour }) as u8, hour >= 12)
137+
let (year, month, day, hour, is_pm, min, sec) = if IS_DEBUG {
138+
(2000, 1, 1, 11, false, 0, 0)
139+
} else {
140+
let local_now = chrono::Local::now();
141+
142+
let year = local_now.year() as u32 % 100;
143+
let month = local_now.month() as u8;
144+
let day = local_now.day() as u8;
145+
let (hour, is_pm) = {
146+
let hour = local_now.hour();
147+
((if self.cnt & 0x2 == 0 { hour % 12 } else { hour }) as u8, hour >= 12)
148+
};
149+
let min = local_now.minute() as u8;
150+
let sec = local_now.second() as u8;
151+
152+
(year, month, day, hour, is_pm, min, sec)
154153
};
155-
let min = 0 as u8;
156-
let sec = 0 as u8;
157154

158155
self.date_time[0] = (((year / 10) << 4) | (year % 10)) as u8;
159156
self.date_time[1] = ((month / 10) << 4) | (month % 10);

src/jit/emitter/emit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::jit::jit_asm::{JitAsm, JitRuntimeData};
88
use crate::jit::op::Op;
99
use crate::jit::reg::Reg;
1010
use crate::jit::Cond;
11-
use crate::DEBUG_LOG_BRANCH_OUT;
11+
use crate::IS_DEBUG;
1212
use CpuType::ARM9;
1313

1414
impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
@@ -29,7 +29,7 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
2929
Op::MrsRc | Op::MrsRs => self.emit_mrs(block_asm),
3030
Op::Swi => self.emit_swi::<false>(block_asm),
3131
Op::Swpb | Op::Swp => self.emit_swp(block_asm),
32-
Op::UnkArm => todo!(),
32+
Op::UnkArm => unreachable!(),
3333
op if op.is_single_mem_transfer() => {
3434
if op.mem_is_write() {
3535
self.emit_single_write(block_asm)
@@ -103,7 +103,7 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
103103
let runtime_data_addr_reg = block_asm.new_reg();
104104
block_asm.mov(runtime_data_addr_reg, self.runtime_data.get_addr() as u32);
105105

106-
if DEBUG_LOG_BRANCH_OUT {
106+
if IS_DEBUG {
107107
let pc_reg = block_asm.new_reg();
108108
block_asm.mov(pc_reg, self.jit_buf.current_pc);
109109
block_asm.store_u32(pc_reg, runtime_data_addr_reg, JitRuntimeData::get_out_pc_offset() as u32);

src/jit/emitter/thumb/emit_thumb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, const CPU: CpuType> JitAsm<'a, CPU> {
5656
Op::BlxRegT => self.emit_blx_thumb(block_asm),
5757

5858
Op::SwiT => self.emit_swi::<true>(block_asm),
59-
Op::UnkThumb => {}
59+
Op::UnkThumb => unreachable!(),
6060
op if op.is_single_mem_transfer() => {
6161
if op.mem_is_write() {
6262
self.emit_str_thumb(block_asm)

src/jit/inst_mem_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod handler {
153153
macro_rules! imm_breakout {
154154
($asm:expr, $pc:expr, $thumb:expr, $total_cycles:expr) => {{
155155
crate::logging::debug_println!("immediate breakout");
156-
if crate::DEBUG_LOG_BRANCH_OUT {
156+
if crate::IS_DEBUG {
157157
$asm.runtime_data.branch_out_pc = $pc;
158158
}
159159
$asm.runtime_data.accumulated_cycles += $total_cycles - $asm.runtime_data.pre_cycle_count_sum;

src/jit/jit_asm.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use crate::jit::op::Op;
1111
use crate::jit::reg::Reg;
1212
use crate::jit::reg::{reg_reserve, RegReserve};
1313
use crate::logging::debug_println;
14-
use crate::{get_jit_asm_ptr, DEBUG_LOG, DEBUG_LOG_BRANCH_OUT};
14+
use crate::{get_jit_asm_ptr, DEBUG_LOG, IS_DEBUG};
1515
use std::arch::asm;
1616
use std::cell::UnsafeCell;
17+
use std::hint::unreachable_unchecked;
1718
use std::intrinsics::unlikely;
1819
use std::{mem, ptr};
1920

@@ -111,22 +112,22 @@ impl JitRuntimeData {
111112

112113
pub extern "C" fn hle_bios_uninterrupt<const CPU: CpuType>(store_host_sp: bool) {
113114
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
114-
bios::uninterrupt::<CPU>(asm.emu);
115+
if IS_DEBUG {
116+
asm.runtime_data.branch_out_pc = get_regs!(asm.emu, CPU).pc;
117+
}
115118
asm.runtime_data.return_stack_ptr = 0;
116119
asm.runtime_data.accumulated_cycles += 3;
120+
bios::uninterrupt::<CPU>(asm.emu);
117121
if unlikely(get_cpu_regs!(asm.emu, CPU).is_halted()) {
118-
if DEBUG_LOG_BRANCH_OUT {
119-
asm.runtime_data.branch_out_pc = get_regs!(asm.emu, CPU).pc;
120-
}
121122
if !store_host_sp {
122123
// r4-r12,pc since we need an even amount of registers for 8 byte alignment, in case the compiler decides to use neon instructions
123124
unsafe {
124125
asm!(
125-
"mov sp, {}",
126-
"pop {{r4-r12,pc}}",
127-
in(reg) asm.runtime_data.host_sp
126+
"mov sp, {}",
127+
"pop {{r4-r12,pc}}",
128+
in(reg) asm.runtime_data.host_sp
128129
);
129-
std::hint::unreachable_unchecked();
130+
unreachable_unchecked();
130131
}
131132
}
132133
} else {
@@ -154,36 +155,37 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
154155
let asm = unsafe { get_jit_asm_ptr::<CPU>().as_mut().unwrap_unchecked() };
155156

156157
{
157-
let mut index = 0;
158+
let mut pc_offset = 0;
158159
loop {
159160
let inst_info = if THUMB {
160-
let opcode = asm.emu.mem_read::<CPU, u16>(guest_pc + index);
161+
let opcode = asm.emu.mem_read::<CPU, u16>(guest_pc + pc_offset);
161162
let (op, func) = lookup_thumb_opcode(opcode);
162163
InstInfo::from(func(opcode, *op))
163164
} else {
164-
let opcode = asm.emu.mem_read::<CPU, u32>(guest_pc + index);
165+
let opcode = asm.emu.mem_read::<CPU, u32>(guest_pc + pc_offset);
165166
let (op, func) = lookup_opcode(opcode);
166167
func(opcode, *op)
167168
};
168169

170+
if inst_info.op == Op::UnkArm || inst_info.op == Op::UnkThumb {
171+
break;
172+
}
173+
169174
if let Some(last) = asm.jit_buf.insts_cycle_counts.last() {
170-
assert!(u16::MAX - last >= inst_info.cycle as u16, "{CPU:?} {guest_pc:x} {inst_info:?}");
175+
debug_assert!(u16::MAX - last >= inst_info.cycle as u16, "{CPU:?} {guest_pc:x} {inst_info:?}");
171176
asm.jit_buf.insts_cycle_counts.push(last + inst_info.cycle as u16);
172177
} else {
173178
asm.jit_buf.insts_cycle_counts.push(inst_info.cycle as u16);
174-
assert!(asm.jit_buf.insts_cycle_counts.len() <= u16::MAX as usize, "{CPU:?} {guest_pc:x} {inst_info:?}")
179+
debug_assert!(asm.jit_buf.insts_cycle_counts.len() <= u16::MAX as usize, "{CPU:?} {guest_pc:x} {inst_info:?}")
175180
}
176181

177182
let is_unreturnable_branch = !inst_info.out_regs.is_reserved(Reg::LR) && inst_info.is_uncond_branch();
178-
// let is_uncond_branch = inst_info.is_uncond_branch();
179-
let is_unknown = inst_info.op == Op::UnkArm || inst_info.op == Op::UnkThumb;
180-
181183
asm.jit_buf.insts.push(inst_info);
182184

183-
index += if THUMB { 2 } else { 4 };
184-
if is_unreturnable_branch || is_unknown {
185+
if is_unreturnable_branch {
185186
break;
186187
}
188+
pc_offset += if THUMB { 2 } else { 4 };
187189
}
188190
}
189191

@@ -198,7 +200,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
198200
block_asm.restore_reg(Reg::CPSR);
199201
}
200202

201-
// if guest_pc == 0x20b2688 {
203+
// if guest_pc == 0x2001b5e {
202204
// block_asm.bkpt(2);
203205
// }
204206

@@ -207,7 +209,7 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
207209
asm.jit_buf.current_pc = guest_pc + (i << if THUMB { 1 } else { 2 }) as u32;
208210
debug_println!("{CPU:?} emitting {:?} at pc: {:x}", asm.jit_buf.current_inst(), asm.jit_buf.current_pc);
209211

210-
// if asm.jit_buf.current_pc == 0x20216e2 {
212+
// if asm.jit_buf.current_pc == 0x2001b5c {
211213
// block_asm.bkpt(1);
212214
// }
213215

@@ -217,11 +219,11 @@ fn emit_code_block_internal<const CPU: CpuType, const THUMB: bool>(store_host_sp
217219
asm.emit(&mut block_asm);
218220
}
219221

220-
// if DEBUG_LOG {
221-
// block_asm.save_context();
222-
// block_asm.call2(debug_after_exec_op::<CPU> as *const (), asm.jit_buf.current_pc, asm.jit_buf.current_inst().opcode);
223-
// block_asm.restore_reg(Reg::CPSR);
224-
// }
222+
if DEBUG_LOG {
223+
block_asm.save_context();
224+
block_asm.call2(debug_after_exec_op::<CPU> as *const (), asm.jit_buf.current_pc, asm.jit_buf.current_inst().opcode);
225+
block_asm.restore_reg(Reg::CPSR);
226+
}
225227
}
226228

227229
let opcodes = block_asm.finalize(guest_pc, THUMB);
@@ -263,7 +265,7 @@ fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
263265

264266
debug_println!("{CPU:?} Enter jit addr {:x}", jit_entry as usize);
265267

266-
if DEBUG_LOG {
268+
if IS_DEBUG {
267269
asm.runtime_data.branch_out_pc = u32::MAX;
268270
}
269271
asm.runtime_data.pre_cycle_count_sum = 0;
@@ -274,11 +276,9 @@ fn execute_internal<const CPU: CpuType>(guest_pc: u32) -> u16 {
274276

275277
jit_entry(true);
276278

277-
if DEBUG_LOG {
278-
assert_ne!(asm.runtime_data.branch_out_pc, u32::MAX);
279-
}
279+
debug_assert_ne!(asm.runtime_data.branch_out_pc, u32::MAX);
280280

281-
if DEBUG_LOG && DEBUG_LOG_BRANCH_OUT {
281+
if DEBUG_LOG {
282282
println!(
283283
"{:?} reading opcode of breakout at {:x} executed cycles {}",
284284
CPU, asm.runtime_data.branch_out_pc, asm.runtime_data.accumulated_cycles

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::jit::jit_asm::JitAsm;
2323
use crate::logging::debug_println;
2424
use crate::presenter::{PresentEvent, Presenter, PRESENTER_AUDIO_BUF_SIZE};
2525
use crate::settings::Settings;
26-
use crate::utils::{set_thread_prio_affinity, HeapMemU32, ThreadAffinity, ThreadPriority};
26+
use crate::utils::{const_str_equal, set_thread_prio_affinity, HeapMemU32, ThreadAffinity, ThreadPriority};
2727
use std::cell::UnsafeCell;
2828
use std::cmp::min;
2929
use std::intrinsics::{likely, unlikely};
@@ -46,8 +46,9 @@ mod presenter;
4646
mod settings;
4747
mod utils;
4848

49-
pub const DEBUG_LOG: bool = cfg!(debug_assertions);
50-
pub const DEBUG_LOG_BRANCH_OUT: bool = DEBUG_LOG;
49+
const BUILD_PROFILE_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/build_profile_name"));
50+
pub const DEBUG_LOG: bool = const_str_equal(BUILD_PROFILE_NAME, "debug");
51+
pub const IS_DEBUG: bool = !const_str_equal(BUILD_PROFILE_NAME, "release");
5152

5253
fn run_cpu(
5354
cartridge_io: CartridgeIo,

src/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,21 @@ pub fn rgb6_to_float8(color: u32) -> (f32, f32, f32) {
260260
let b = ((color >> 12) & 0x3F) as f32;
261261
(r / 63f32, g / 63f32, b / 63f32)
262262
}
263+
264+
pub const fn const_bytes_equal(lhs: &[u8], rhs: &[u8]) -> bool {
265+
if lhs.len() != rhs.len() {
266+
return false;
267+
}
268+
let mut i = 0;
269+
while i < lhs.len() {
270+
if lhs[i] != rhs[i] {
271+
return false;
272+
}
273+
i += 1;
274+
}
275+
true
276+
}
277+
278+
pub const fn const_str_equal(lhs: &str, rhs: &str) -> bool {
279+
const_bytes_equal(lhs.as_bytes(), rhs.as_bytes())
280+
}

0 commit comments

Comments
 (0)