4 ms·
Certainly if you translate x86 machine code to RISC-V code, instruction by instruction with very little context[1], you're going to see a lot of code size expan
by brucehoult 3y ago
Certainly if you translate x86 machine code to RISC-V code, instruction by instruction with very little context[1], you're going to see a lot of code size expansion.
The same is not true if you take C or other high level language code and compile it to each ISA using a modern compiler (gcc, clang) with at least -O1. RISC-V rv64gc code is significantly smaller than x86_64 code. It uses a few more instructions, but a lot fewer that you'd naively expect [2], and the smaller average instruction size more than makes up for that.
[1] thank goodness they're at least figuring out (most of the time) when the condition codes from x86 instructions are immediately overwritten, so don't need to actually be calculated, as that takes a lot more work than calculating the explicit result of instructions.
[2] mostly because of common subexpression elimination, strength reduction, induction variable optimisations, and movement of constant calculations out of loops (the latter doesn't decrease code size but increases speed)
- ptitSeb 3y agoI was a bit doubtfull of that claim about RV64 code compacity compared to x86_64, so I tried myself. I used 2 of projects https://github.com/ptitSeb/stuntcarremake https://github.com/ptitSeb/stuntcarremake and https://github.com/ptitSeb/hydracastlelabyrinth.git https://github.com/ptitSeb/hydracastlelabyrinth.git and I built them with default option, in release mode on both RV64 and x86_64 to compare the generated file size. For StuntCarRemake: RV64: 191248 x86_64: 260616 For HydraCastleLabyrinth: RV64: 652984 x86_64: 693312 And yeah, RV64 is indeed more compact than x86_64!
- brucehoult 3y agoScience!
- snvzz 3y agoJust remember to ignore file size, and check text (code) section with binutils's "size" instead.