dirkwhoffmann / vAmiga

vAmiga is a user-friendly Amiga 500, 1000, 2000 emulator for macOS
https://dirkwhoffmann.github.io/vAmiga
Other
293 stars 24 forks source link

SEC macro computes wrong cycle values #801

Closed mithrendal closed 6 months ago

mithrendal commented 6 months ago

https://github.com/dirkwhoffmann/vAmiga/blob/6d5f076e747c2d1860001d3808cc72e5ed500022/Emulator/Base/Aliases.h#L46

with the latest commit 6d5f076e747c2d1860001d3808cc72e5ed500022 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)

dirkwhoffmann commented 6 months ago

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

dirkwhoffmann commented 6 months ago

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.

dirkwhoffmann commented 6 months ago

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))