Comment by sylware

2 days ago

I am coding RISC-V assembly (which I run on x86_64 with a mini-interpreter) but I am careful to avoid the usage of the pseudo-instructions and the registers aliases (no compressed instruction ofc). I have a little tool to generate constant loading code, one-liner (semi-colon separated instructions).

And as a pre-processor I use a simple C preprocessor (I don't want to tie the code to the pre-processor of a specific assembler): I did that for x86_64 assembly, and I could assemble with gas, nasm and fasmng(fasm2) transparently.

What's wrong with compressed instructions?

  • I don't feel comfy using duplicate instructions for a 'R'educed instruction set.

    That said, I know in some cases it could increase performance since the code would use less memory (and certainly more things which I don't know because I am not into modern advanced hardware CPU micro-architecture design).

    • It's just an alternative encoding for exactly the same instructions, it does not make the ISA more complex.

      If you are writing assembly you probably are using compressed instructions already since your assembler can do the substitions transparently, e.g.

        addi a0,a0,10 -> c.addi a0,10
      

      Example: https://godbolt.org/z/MG3v3jx7P (the disassembly shows addi but the instruction is only two bytes).

      They offer a nice reduction in code size with basically no downsides :)

      1 reply →