Not a 'scientific' comparison, but handwritten 8-bit machine code compresses much less than x86/64 machine code (using gzip --best):
- a compiled C executable for x86/64 compresses to about 38% of its original size (199 KB down to 77 KB)
- a WASM blob of the same code compresses to about 32% (171 KB down to 56 KByte)
In comparison some 8-bit ROMs:
- ZX Spectrum 128 ROM (Z80): 16384 bytes compresses to 12189 (74.3%)
- C64 Kernel ROM (6502): 8192 bytes compresses to 6735 (82.2%)
So 8-bit code seems to be a lot 'denser' than today's machine code, and 6502 is denser than Z80 :)
That's interesting! Do you think this is because 64-bit code simply doesn't use a lot of its instruction set space (where more opcodes and instruction modes and variants are undefined and therefore not routinely used in executables), or because some of the people hand-writing 8-bit assembly actively use more opcodes than a typical compiler would, or some other factors?
Or are there are a lot of pointers in 64-bit code that contain a huge number of zeroes? :-)
I guess it's a combination of compiled vs handwritten code (maybe certain patterns show up more often in compiled code, while handwritten 8-bit code tries hard to remove any redundancies because of the limited available space), and bigger data types (especially 64-bit pointers).
Very interesting! Another thing to consider however is how much work each instruction can do. In that regard x86 may have a big edge.
It would be interesting to compare x86 and Z80 code density, that is, how much you can do per bit of machine code.