From 01c1c9e3933c418ee3f974399bdeb1c9d0ac969c Mon Sep 17 00:00:00 2001 From: Max Regan Date: Sun, 1 Jul 2018 21:57:25 +0000 Subject: [PATCH] gbdb: change cycle calculation for better performance The conditions are hotpath, so pre-calcuate the end cycle count instead of doing it every loop. I didn't verify that the compiler wasn't doing this anyway, but this won't hurt. --- src/apps/gbdb.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/apps/gbdb.c b/src/apps/gbdb.c index 7b13e50..5baa02d 100644 --- a/src/apps/gbdb.c +++ b/src/apps/gbdb.c @@ -186,7 +186,7 @@ static void echo(char *arg_list) static void step(char *arg_list) { - uint64_t steps, init_steps; + uint64_t steps, end_steps; char *token; token = strtok(arg_list, " "); if (token == NULL) { @@ -198,15 +198,14 @@ static void step(char *arg_list) paused = 0; signal(SIGINT, break_execution_handler); - init_steps = cpu.metrics.retired_instrs; + end_steps = cpu.metrics.retired_instrs + steps; do { cycle(); - } while (init_steps + steps > cpu.metrics.retired_instrs && + } while (end_steps > cpu.metrics.retired_instrs && !cpu_at_breakpoint() && - !cpu.halted && !paused); - if (init_steps + steps <= cpu.metrics.retired_instrs) { + if (end_steps <= cpu.metrics.retired_instrs) { gb_log("CPU stopped after %" PRId64 " instructions\n", steps); } else if (cpu_at_breakpoint()) { breakpoint_addr_hit(cpu.pc);