dirkwhoffmann / vAmiga

vAmiga is a user-friendly Amiga 500, 1000, 2000 emulator for macOS

Home Page:https://dirkwhoffmann.github.io/vAmiga

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SEC macro computes wrong cycle values

mithrendal opened this issue · comments

#define SEC(delay) (Cycle(delay) * 28000000)

with the latest commit 6d5f076 the SEC(number_in_seconds) macro above cuts the fractional part of the number. It therefore translates to

SEC(0.5) == SEC(0)

and

SEC(1.8) == SEC(1)

when agnus schedules tasks for example every SEC(0.5) then it runs these tasks now in every slot ... which leads to higher host cpu load.

solution

use MSEC(500) instead of SEC(0.5)
use MSEC(1800) instead of SEC(1.8)

The best way to solve it cleanly is probably to replace the macros with inline functions overloaded for different types.

The best way to solve it cleanly is probably to replace the macros with inline functions overloaded for different types.

Despite being the clearest solution, it is apparently not the best. The compiler does not optimize away the function call in debug builds, even for trivial functions:

Bildschirmfoto 2023-12-29 um 17 33 47

Using (overloaded) functions would thus slow down the emulator in debug mode, which I don't want to happen.

I went for this solution for now:

#define USEC(delay)           (Cycle((i64)delay * 28))
#define MSEC(delay)           (Cycle((i64)delay * 28000))
#define SEC(delay)            (Cycle((double)delay * 28000000))