pi1541 / Pi1541

Commodore 1541 emulator for the Raspberry Pi
GNU General Public License v3.0
369 stars 80 forks source link

Performance improvements found while porting to Teensy 4.1 #223

Open dashiad opened 2 years ago

dashiad commented 2 years ago

Hello, First of all, thank you for this piece of code.I've learnt a lot about the 1541 reading it...Really, thank you. I've made a "sort of a port" of the pi1541 to the Teensy 4.1 , and had problems maintaining the required timings as soon as the motor drive was started (ie, the Update method of the Drive class enters the 16 cycle loop). In the Teensy case, it was resolved changing the type of cyclesPerBit and cyclesForBit to integers, as using floats in that loop was really hurting performance. Same goes with randomFluxReversalTime. Also, even though i've not implemented it, as that variable is random, i guess it'd be safe to test it outside the for loop (ie, setting randomFluxReversalTime to 16*-0.0625,as if the reversal time was always coupled to 1 CPU cycle boundaries). This would save a few cycles more. I dont know if floats are also slow in the Pi, or if saving cycles is still needed, but, anyway...

hugo-lyppens commented 2 years ago

I tried this on my Pi1541 build (very easy to build from WSL2!) in hopes of getting Winter Games II working again on 1.24 but it did not help. I have a Raspi 3B overclocked to 1300MHz. But I agree that these variables should be ints. Even if they are ints representing fractions. Perhaps lowest byte could be the fractional part (/256).