diff mbox series

[RFC,PATCH-for-6.1,v2,4/6] target/mips/cp0_timer: Add ns_substract_to_count() helper

Message ID 20210409093623.2402750-5-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series target/mips/cp0_timer: Use new clock_ns_to_ticks() | expand

Commit Message

Philippe Mathieu-Daudé April 9, 2021, 9:36 a.m. UTC
Factor ns_substract_to_count() out to simplify a bit.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/mips/cp0_timer.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Richard Henderson April 9, 2021, 4:27 p.m. UTC | #1
On 4/9/21 2:36 AM, Philippe Mathieu-Daudé wrote:
> Factor ns_substract_to_count() out to simplify a bit.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   target/mips/cp0_timer.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)

s/substract/subtract/g
Also, one usually subtracts "from".

That said, I'm not sure I see this as clearer...


r~
diff mbox series

Patch

diff --git a/target/mips/cp0_timer.c b/target/mips/cp0_timer.c
index 73355b44b15..85f2f85838d 100644
--- a/target/mips/cp0_timer.c
+++ b/target/mips/cp0_timer.c
@@ -32,6 +32,12 @@  static uint32_t ns_to_count(CPUMIPSState *env, uint64_t ns)
     return ns / env->cp0_count_ns;
 }
 
+static uint32_t ns_substract_to_count(CPUMIPSState *env,
+                                      uint32_t count, uint64_t ns)
+{
+    return count - ns_to_count(env, ns);
+}
+
 /* MIPS R4K timer */
 static void cpu_mips_timer_update(CPUMIPSState *env)
 {
@@ -39,7 +45,7 @@  static void cpu_mips_timer_update(CPUMIPSState *env)
     uint32_t wait;
 
     now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
-    wait = env->CP0_Compare - env->CP0_Count - ns_to_count(env, now_ns);
+    wait = ns_substract_to_count(env, env->CP0_Compare - env->CP0_Count, now_ns);
     next_ns = now_ns + (uint64_t)wait * env->cp0_count_ns;
     timer_mod(env->timer, next_ns);
 }
@@ -83,8 +89,8 @@  void cpu_mips_store_count(CPUMIPSState *env, uint32_t count)
         env->CP0_Count = count;
     } else {
         /* Store new count register */
-        env->CP0_Count = count - ns_to_count(env,
-                                             qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+        env->CP0_Count = ns_substract_to_count(env, count,
+                                               qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
         /* Update timer timer */
         cpu_mips_timer_update(env);
     }