Update stack op cost (#1402)

* Update stack op cost

* Update from review
This commit is contained in:
Robin Salen 2023-12-04 10:32:52 -05:00 committed by GitHub
parent d28ba24059
commit cb2a22a5f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -1,3 +1,4 @@
use super::opcodes::get_opcode;
use crate::cpu::kernel::assembler::BYTES_PER_OFFSET;
use crate::cpu::kernel::ast::Item;
use crate::cpu::kernel::ast::Item::*;
@ -32,6 +33,5 @@ fn cost_estimate_standard_op(_op: &str) -> u32 {
}
fn cost_estimate_push(num_bytes: usize) -> u32 {
// TODO: Once PUSH is actually implemented, check if this needs to be revised.
num_bytes as u32
}

View File

@ -286,15 +286,15 @@ impl StackOp {
panic!("Target should have been expanded already: {target:?}")
}
};
// This is just a rough estimate; we can update it after implementing PUSH.
(bytes, bytes)
// A PUSH takes one cycle, and 1 memory read per byte.
(1, bytes + 1)
}
// A POP takes one cycle, and doesn't involve memory, it just decrements a pointer.
Pop => (1, 0),
// A POP takes one cycle, and most of the time a read to update the top of the stack.
Pop => (1, 1),
// A DUP takes one cycle, and a read and a write.
StackOp::Dup(_) => (1, 2),
// A SWAP takes one cycle with four memory ops, to read both values then write to them.
StackOp::Swap(_) => (1, 4),
// A SWAP takes one cycle with three memory ops, to read both values then write to them.
StackOp::Swap(_) => (1, 3),
};
let cpu_cost = cpu_rows * NUM_CPU_COLUMNS as u32;