edescourtis wrote on 2024-07-24, 13:10:
I understand that Real Mode is quite slow on modern CPUs
I never believed in this claim, and trying to verify or refute it has been sitting in the back of my head for quite some time, and because I still cannot think of a single piece of software that does not have graphics interaction and can be used to test real mode performance, and because I stumbled across a neat SHA256 implementation, I thought I could build a small 16-bit DOS program using Open Watcom utilizing this code, so this is exactly what I did. Additionally, and this was actually the most time-consuming work, I disassembled the inner loop and adapted it to run in 32-bit protected mode, still using the exact same 16bit registers, under Linux. The assembly listing is almost exactly the same apart from some pointer-reload operations that required slight adjustments, but the machine code is not, because almost every instruction acquired an operand size override prefix. If you are interested in the code or the binaries, let me know, but I will need a little time for preparing them.
My findings:
- There is absolutely no difference in performance between actual real mode, v86 mode, VME, virtualization and any combination thereof.
- The equivalent protected mode code runs at almost exactly the same speed as well, actually slightly faster, which might be attributed to the outer code being compiled in a more efficient environment.
- Compiling the same code for 32 bits (Open Watcom, DOS4GW) makes it an order of magnitude faster (10x), mostly because shifting/rotating 32 bit values is just a lot more efficient in 32 bit registers.
- Compiling the same code using a modern compiler for modern x86 (both 32 and 64 bit) doubles the performance again. And it is not even utilizing the special SHA instruction set.
I don't know if you consider my CPU "modern", as it is an i3-8100 from 2018, but it is at least not ancient and reasonably fast.
Conclusion: There is no such thing as "real mode performance". There is just CPU performance.