For x86 and x64 compilers generate similar zero/sign extend MOVSX and MOVZX. The expansion itself is not free, but allows processors to perform out-of-order magic speed up.
But on RISC-V:
Consequently, conversion between unsigned and signed 32-bit integers is a no-op, as is conversion from a signed 32-bit integer to a signed 64-bit integer.
A few new instructions (ADD[I]W/SUBW/SxxW) are required for addition and shifts to ensure reasonable performance for 32-bit values.
(C) RISC-V Spec
But at the same time, the new modern RISC-V 64-bit processors contains instructions for 32-bit signed integers. Why? To increase performance? Where then are 8 and 16-bits? I already do not understand anything.
The full quote seems clear to me:
It says that 32-bit values are stored in 64-bit registers with their MSb (Most Significant bit) repeated through bits 32-63.
This is done for both signed and unsigned integers.
This allows a few optimisations as outlined in the quote:
Compare this to the usual algorithm where you have to zero or sign extend the low 32-bit value to promote it a 64-bit value of different "sign-ness" (Ignoring overflow).
This spares a sign extension.
This is because repeating the MSb doesn't change the result of the comparison.
It's easy to see this after a couple of examples.
However addition (to name one) doesn't preserve this invariant: 0x000000007fffffff + 0x0000000000000001 = 0x0000000080000000 which violates the assumption.
Since a) working with 32-bit values happens very often and b) fixing the result would require additional work (I can think of using a
slli/sraipair) a new format of instructions has been introduced.These instructions operate on 64-bit registers but only use their lower 32-bit value and will sign-extend the 32-bit result.
This is easily done in hardware so it's worth having this new class of instruction.
As noted in the comments, 8 and 16-bit arithmetic is rare so no engineering effort has been spent on finding new room for it (both in terms of the gates required and of the opcode space used).