floooh / yakc

Yet another KC emulator
MIT License
108 stars 9 forks source link

New 'algorithmic' Z80 instruction decoder #18

Closed floooh closed 8 years ago

floooh commented 8 years ago

This implements a new Z80 instruction decoder which which actually decodes the opcodes instead of branching over a huge nested switch-case. It's much less code, but also about 20% slower with only very moderate size reduction. The brute force switch-case decoding is probably better (but less elegant). The decoders can be toggled with the cmake option YAKC_Z80_DECODER.

anotherlin commented 8 years ago

With z80emu, I also use a decoder type emulator instead of the usual switch/cases. Regarding code size, the z80emu.o needed to run zextests, is around 14k (stripped). Whereas yaze's simz80.o (switch/cases type) is around 44k (stripped). Both compiled with gcc -O3 on Linux 64-bit. So I'm a bit surprised that you only got "moderate" size reduction. As for execution speed, it's of course slower, but not that much. When I developped z80emu (2006), I've done quite a bit of comparisons using the zextests as a benchmark. Yaze's was the fastest by a long way (and fully zexall ok). MZ80 which generates a switch-case in 32-bit assembly, making careful use of x86 flags and 8-bit/16-bit registers (after all, x86 descend from 8080), was actually slower than any C emulator. The Athlon XP I used was already optimized for full 32-bit execution. I remember beating Marat Fayzullin's Z80 which is switch/cases (and not zexall ok). I tested one or two other emulators. Unfortunatelly, I lost the actual numbers, but zextests can be executed in around 1m30s if I remember correctly.

floooh commented 8 years ago

Thanks for the interesting info :) I was looking at the size reduction in the emscripten-compiled and gzipped version of the emulator, since I was interested how much the download size could be reduced. In that case the size reduction was only around 6 KByte (IFIR) from about 400 KByte overall. I guess in that case asm.js compressed size behaves very different than native x86 code.