Simple modulo optimization

As we are using a base 2 for our RHS modulo operator, we changed that for a bitwise and operator, which is faster.

In other words, if the RHS of the modulo operator (i.e. LHS % RHS) is a base 2, we can write "LHS & (RHS -1)", which will yield the same results but with a faster processing time.
This commit is contained in:
Marcus Vinicius de Carvalho 2021-08-01 12:49:28 +08:00
parent 25d228c440
commit ab5914b269
1 changed files with 2 additions and 2 deletions

View File

@ -345,8 +345,8 @@ fn op_cxnn(cpu: &mut CPU) {
fn op_dxyn(cpu: &mut CPU) {
let mut vf: bool = false;
let value = cpu.op.n as usize;
let ori_x = cpu.regs.get(cpu.op.x) as usize % WIDTH;
let ori_y = cpu.regs.get(cpu.op.y) as usize % HEIGHT;
let ori_x = cpu.regs.get(cpu.op.x) as usize & (WIDTH - 1); //% WIDTH;
let ori_y = cpu.regs.get(cpu.op.y) as usize & (HEIGHT -1); //% HEIGHT;
for row in 0..value {
let y = ori_y + row;