Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zkronos73 committed Nov 20, 2024
1 parent eba6786 commit 38bffa2
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 225 deletions.
8 changes: 4 additions & 4 deletions cli/src/commands/install_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl InstallToolchainCmd {
if let Ok(entry) = entry {
let entry_path = entry.path();
let entry_name = entry_path.file_name().unwrap();
if entry_path.is_dir()
&& entry_name != "bin"
&& entry_name != "circuits"
&& entry_name != "toolchains"
if entry_path.is_dir() &&
entry_name != "bin" &&
entry_name != "circuits" &&
entry_name != "toolchains"
{
if let Err(err) = fs::remove_dir_all(&entry_path) {
println!("Failed to remove directory {:?}: {}", entry_path, err);
Expand Down
6 changes: 3 additions & 3 deletions core/src/elf2rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub fn elf2rom(elf_file: String) -> Result<ZiskRom, Box<dyn Error>> {
add_zisk_code(&mut rom, addr, &data);
}

if (section_header.sh_flags & SHF_WRITE as u64) != 0
&& addr >= RAM_ADDR
&& addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE
if (section_header.sh_flags & SHF_WRITE as u64) != 0 &&
addr >= RAM_ADDR &&
addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE
{
add_zisk_init_data(&mut rom, addr, &data);
} else {
Expand Down
26 changes: 13 additions & 13 deletions core/src/zisk_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ impl ZiskInst {
}

pub fn get_flags(&self) -> u64 {
let flags: u64 = 1
| (((self.a_src == SRC_IMM) as u64) << 1)
| (((self.a_src == SRC_MEM) as u64) << 2)
| (((self.a_src == SRC_STEP) as u64) << 3)
| (((self.b_src == SRC_IMM) as u64) << 4)
| (((self.b_src == SRC_MEM) as u64) << 5)
| ((self.is_external_op as u64) << 6)
| ((self.store_ra as u64) << 7)
| (((self.store == STORE_MEM) as u64) << 8)
| (((self.store == STORE_IND) as u64) << 9)
| ((self.set_pc as u64) << 10)
| ((self.m32 as u64) << 11)
| (((self.b_src == SRC_IND) as u64) << 12);
let flags: u64 = 1 |
(((self.a_src == SRC_IMM) as u64) << 1) |
(((self.a_src == SRC_MEM) as u64) << 2) |
(((self.a_src == SRC_STEP) as u64) << 3) |
(((self.b_src == SRC_IMM) as u64) << 4) |
(((self.b_src == SRC_MEM) as u64) << 5) |
((self.is_external_op as u64) << 6) |
((self.store_ra as u64) << 7) |
(((self.store == STORE_MEM) as u64) << 8) |
(((self.store == STORE_IND) as u64) << 9) |
((self.set_pc as u64) << 10) |
((self.m32 as u64) << 11) |
(((self.b_src == SRC_IND) as u64) << 12);

flags
}
Expand Down
30 changes: 15 additions & 15 deletions emulator/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ impl<'a> Emu<'a> {
}

// Log emulation step, if requested
if options.print_step.is_some()
&& (options.print_step.unwrap() != 0)
&& ((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0)
if options.print_step.is_some() &&
(options.print_step.unwrap() != 0) &&
((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0)
{
println!("step={}", self.ctx.inst_ctx.step);
}
Expand Down Expand Up @@ -520,9 +520,9 @@ impl<'a> Emu<'a> {
// Increment step counter
self.ctx.inst_ctx.step += 1;

if self.ctx.inst_ctx.end
|| ((self.ctx.inst_ctx.step - self.ctx.last_callback_step)
== self.ctx.callback_steps)
if self.ctx.inst_ctx.end ||
((self.ctx.inst_ctx.step - self.ctx.last_callback_step) ==
self.ctx.callback_steps)
{
// In run() we have checked the callback consistency with ctx.do_callback
let callback = callback.as_ref().unwrap();
Expand Down Expand Up @@ -699,11 +699,11 @@ impl<'a> Emu<'a> {

let mut current_box_id = 0;
let mut current_step_idx = loop {
if current_box_id == vec_traces.len() - 1
|| vec_traces[current_box_id + 1].start_state.step >= emu_trace_start.step
if current_box_id == vec_traces.len() - 1 ||
vec_traces[current_box_id + 1].start_state.step >= emu_trace_start.step
{
break emu_trace_start.step as usize
- vec_traces[current_box_id].start_state.step as usize;
break emu_trace_start.step as usize -
vec_traces[current_box_id].start_state.step as usize;
}
current_box_id += 1;
};
Expand Down Expand Up @@ -814,8 +814,8 @@ impl<'a> Emu<'a> {
let b = [inst_ctx.b & 0xFFFFFFFF, (inst_ctx.b >> 32) & 0xFFFFFFFF];
let c = [inst_ctx.c & 0xFFFFFFFF, (inst_ctx.c >> 32) & 0xFFFFFFFF];

let addr1 = (inst.b_offset_imm0 as i64
+ if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64;
let addr1 = (inst.b_offset_imm0 as i64 +
if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64;

let jmp_offset1 = if inst.jmp_offset1 >= 0 {
F::from_canonical_u64(inst.jmp_offset1 as u64)
Expand Down Expand Up @@ -893,9 +893,9 @@ impl<'a> Emu<'a> {
m32: F::from_bool(inst.m32),
addr1: F::from_canonical_u64(addr1),
__debug_operation_bus_enabled: F::from_bool(
inst.op_type == ZiskOperationType::Arith
|| inst.op_type == ZiskOperationType::Binary
|| inst.op_type == ZiskOperationType::BinaryE,
inst.op_type == ZiskOperationType::Arith ||
inst.op_type == ZiskOperationType::Binary ||
inst.op_type == ZiskOperationType::BinaryE,
),
}
}
Expand Down
12 changes: 6 additions & 6 deletions emulator/src/emu_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ impl fmt::Display for EmuOptions {

impl EmuOptions {
pub fn is_fast(&self) -> bool {
self.trace_steps.is_none()
&& self.print_step.is_none()
&& self.trace.is_none()
&& !self.log_step
&& !self.verbose
&& !self.tracerv
self.trace_steps.is_none() &&
self.print_step.is_none() &&
self.trace.is_none() &&
!self.log_step &&
!self.verbose &&
!self.tracerv
}
}
28 changes: 14 additions & 14 deletions emulator/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ impl Stats {
output += &format!(" COST_USUAL: {:02} sec\n", COST_USUAL);
output += &format!(" COST_STEP: {:02} sec\n", COST_STEP);

let total_mem_ops = self.mops.mread_na1
+ self.mops.mread_na2
+ self.mops.mread_a
+ self.mops.mwrite_na1
+ self.mops.mwrite_na2
+ self.mops.mwrite_a;
let total_mem_align_steps = self.mops.mread_na1
+ self.mops.mread_na2 * 2
+ self.mops.mwrite_na1 * 2
+ self.mops.mwrite_na2 * 4;
let total_mem_ops = self.mops.mread_na1 +
self.mops.mread_na2 +
self.mops.mread_a +
self.mops.mwrite_na1 +
self.mops.mwrite_na2 +
self.mops.mwrite_a;
let total_mem_align_steps = self.mops.mread_na1 +
self.mops.mread_na2 * 2 +
self.mops.mwrite_na1 * 2 +
self.mops.mwrite_na2 * 4;

let cost_mem = total_mem_ops as f64 * COST_MEM;
let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1
+ self.mops.mread_na2 as f64 * COST_MEMA_R2
+ self.mops.mwrite_na1 as f64 * COST_MEMA_W1
+ self.mops.mwrite_na2 as f64 * COST_MEMA_W2;
let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1 +
self.mops.mread_na2 as f64 * COST_MEMA_R2 +
self.mops.mwrite_na1 as f64 * COST_MEMA_W1 +
self.mops.mwrite_na2 as f64 * COST_MEMA_W2;

let mut total_opcodes: u64 = 0;
let mut opcode_steps: [u64; 256] = [0; 256];
Expand Down
106 changes: 53 additions & 53 deletions state-machines/arith/src/arith_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ impl ArithOperation {
self.op = op;
self.input_a = input_a;
self.input_b = input_b;
self.div_by_zero = input_b == 0
&& (op == DIV
|| op == REM
|| op == DIV_W
|| op == REM_W
|| op == DIVU
|| op == REMU
|| op == DIVU_W
|| op == REMU_W);

self.div_overflow = ((op == DIV || op == REM)
&& input_a == 0x8000_0000_0000_0000
&& input_b == 0xFFFF_FFFF_FFFF_FFFF)
|| ((op == DIV_W || op == REM_W) && input_a == 0x8000_0000 && input_b == 0xFFFF_FFFF);
self.div_by_zero = input_b == 0 &&
(op == DIV ||
op == REM ||
op == DIV_W ||
op == REM_W ||
op == DIVU ||
op == REMU ||
op == DIVU_W ||
op == REMU_W);

self.div_overflow = ((op == DIV || op == REM) &&
input_a == 0x8000_0000_0000_0000 &&
input_b == 0xFFFF_FFFF_FFFF_FFFF) ||
((op == DIV_W || op == REM_W) && input_a == 0x8000_0000 && input_b == 0xFFFF_FFFF);

let [a, b, c, d] = Self::calculate_abcd_from_ab(op, input_a, input_b);
self.a = Self::u64_to_chunks(a);
Expand Down Expand Up @@ -564,15 +564,15 @@ impl ArithOperation {
assert!(range_c1 == 0 || range_c3 == 0, "range_c1:{} range_c3:{}", range_c1, range_c3);
assert!(range_d1 == 0 || range_d3 == 0, "range_d1:{} range_d3:{}", range_d1, range_d3);

self.range_ab = (range_a3 + range_a1) * 3
+ range_b3
+ range_b1
+ if (range_a1 + range_b1) > 0 { 8 } else { 0 };
self.range_ab = (range_a3 + range_a1) * 3 +
range_b3 +
range_b1 +
if (range_a1 + range_b1) > 0 { 8 } else { 0 };

self.range_cd = (range_c3 + range_c1) * 3
+ range_d3
+ range_d1
+ if (range_c1 + range_d1) > 0 { 8 } else { 0 };
self.range_cd = (range_c3 + range_c1) * 3 +
range_d3 +
range_d1 +
if (range_c1 + range_d1) > 0 { 8 } else { 0 };
}

pub fn calculate_chunks(&self) -> [i64; 8] {
Expand Down Expand Up @@ -600,40 +600,40 @@ impl ArithOperation {
let nb_fa = nb * (1 - 2 * na);

chunks[0] = fab * a[0] * b[0] // chunk0
- c[0]
+ 2 * np * c[0]
+ div * d[0]
- 2 * nr * d[0];
- c[0] +
2 * np * c[0] +
div * d[0] -
2 * nr * d[0];

chunks[1] = fab * a[1] * b[0] // chunk1
+ fab * a[0] * b[1]
- c[1]
+ 2 * np * c[1]
+ div * d[1]
- 2 * nr * d[1];
+ fab * a[0] * b[1] -
c[1] +
2 * np * c[1] +
div * d[1] -
2 * nr * d[1];

chunks[2] = fab * a[2] * b[0] // chunk2
+ fab * a[1] * b[1]
+ fab * a[0] * b[2]
+ a[0] * nb_fa * m32
+ b[0] * na_fb * m32
- c[2]
+ 2 * np * c[2]
+ div * d[2]
- 2 * nr * d[2]
- np * div * m32
+ nr * m32; // div == 0 ==> nr = 0
+ b[0] * na_fb * m32 -
c[2] +
2 * np * c[2] +
div * d[2] -
2 * nr * d[2] -
np * div * m32 +
nr * m32; // div == 0 ==> nr = 0

chunks[3] = fab * a[3] * b[0] // chunk3
+ fab * a[2] * b[1]
+ fab * a[1] * b[2]
+ fab * a[0] * b[3]
+ a[1] * nb_fa * m32
+ b[1] * na_fb * m32
- c[3]
+ 2 * np * c[3]
+ div * d[3]
- 2 * nr * d[3];
+ b[1] * na_fb * m32 -
c[3] +
2 * np * c[3] +
div * d[3] -
2 * nr * d[3];

chunks[4] = fab * a[3] * b[1] // chunk4
+ fab * a[2] * b[2]
Expand All @@ -657,23 +657,23 @@ impl ArithOperation {
chunks[5] = fab * a[3] * b[2] // chunk5
+ fab * a[2] * b[3]
+ a[1] * nb_fa * (1 - m32)
+ b[1] * na_fb * (1 - m32)
- d[1] * (1 - div)
+ d[1] * 2 * np * (1 - div);
+ b[1] * na_fb * (1 - m32) -
d[1] * (1 - div) +
d[1] * 2 * np * (1 - div);

chunks[6] = fab * a[3] * b[3] // chunk6
+ a[2] * nb_fa * (1 - m32)
+ b[2] * na_fb * (1 - m32)
- d[2] * (1 - div)
+ d[2] * 2 * np * (1 - div);
+ b[2] * na_fb * (1 - m32) -
d[2] * (1 - div) +
d[2] * 2 * np * (1 - div);

// 0x4000_0000_0000_0000__8000_0000_0000_0000
chunks[7] = 0x10000 * na * nb * (1 - m32) // chunk7
+ a[3] * nb_fa * (1 - m32)
+ b[3] * na_fb * (1 - m32)
- 0x10000 * np * (1 - div) * (1 - m32)
- d[3] * (1 - div)
+ d[3] * 2 * np * (1 - div);
+ b[3] * na_fb * (1 - m32) -
0x10000 * np * (1 - div) * (1 - m32) -
d[3] * (1 - div) +
d[3] * 2 * np * (1 - div);

chunks
}
Expand Down
24 changes: 12 additions & 12 deletions state-machines/arith/src/arith_operation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ impl ArithOperationTest {
println!("{:#?}", aop);

const CHUNK_SIZE: u64 = 0x10000;
let bus_a_low: u64 = aop.div as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE)
+ (1 - aop.div as u64) * (aop.a[0] + aop.a[1] * CHUNK_SIZE);
let bus_a_high: u64 = aop.div as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE)
+ (1 - aop.div as u64) * (aop.a[2] + aop.a[3] * CHUNK_SIZE);
let bus_a_low: u64 = aop.div as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) +
(1 - aop.div as u64) * (aop.a[0] + aop.a[1] * CHUNK_SIZE);
let bus_a_high: u64 = aop.div as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) +
(1 - aop.div as u64) * (aop.a[2] + aop.a[3] * CHUNK_SIZE);

let bus_b_low: u64 = aop.b[0] + CHUNK_SIZE * aop.b[1];
let bus_b_high: u64 = aop.b[2] + CHUNK_SIZE * aop.b[3];

let secondary_res: u64 = if aop.main_mul || aop.main_div { 0 } else { 1 };

let bus_res_low = secondary_res * (aop.d[0] + aop.d[1] * CHUNK_SIZE)
+ aop.main_mul as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE)
+ aop.main_div as u64 * (aop.a[0] + aop.a[1] * CHUNK_SIZE);
let bus_res_low = secondary_res * (aop.d[0] + aop.d[1] * CHUNK_SIZE) +
aop.main_mul as u64 * (aop.c[0] + aop.c[1] * CHUNK_SIZE) +
aop.main_div as u64 * (aop.a[0] + aop.a[1] * CHUNK_SIZE);

let bus_res_high_64 = secondary_res * (aop.d[2] + aop.d[3] * CHUNK_SIZE)
+ aop.main_mul as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE)
+ aop.main_div as u64 * (aop.a[2] + aop.a[3] * CHUNK_SIZE);
let bus_res_high_64 = secondary_res * (aop.d[2] + aop.d[3] * CHUNK_SIZE) +
aop.main_mul as u64 * (aop.c[2] + aop.c[3] * CHUNK_SIZE) +
aop.main_div as u64 * (aop.a[2] + aop.a[3] * CHUNK_SIZE);

let bus_res_high = if aop.sext && !aop.div_overflow { 0xFFFF_FFFF } else { 0 }
+ (1 - aop.m32 as u64) * bus_res_high_64;
let bus_res_high = if aop.sext && !aop.div_overflow { 0xFFFF_FFFF } else { 0 } +
(1 - aop.m32 as u64) * bus_res_high_64;

let expected_a_low = a & 0xFFFF_FFFF;
let expected_a_high = (a >> 32) & 0xFFFF_FFFF;
Expand Down
Loading

0 comments on commit 38bffa2

Please sign in to comment.