RFR: 8346478: RISC-V: Refactor add/sub assembler routines [v3]

Fei Yang fyang at openjdk.org
Fri Dec 20 13:27:38 UTC 2024


On Thu, 19 Dec 2024 15:50:22 GMT, Fei Yang <fyang at openjdk.org> wrote:

>> Hi, please consider this cleanup change.
>> 
>> Currently, we have mixed use of `addi` and `add(int64_t)`/`sub(int64_t)`. The former adds a 12-bit immediate while the latter
>> does not have a constraint on the immediate range. We should use `addi` when possible, which would help save one runtime check about the immediate range and avoid the use of one tmp register by the latter as well.
>> 
>> In order to make the code more readable, this also introduces helper routines `subi`/`subiw` and adapts callsites of `addi`/`addiw` with negative immediates.
>> 
>> 
>> 
>>  <Design of the RISC-V Instruction Set Architecture>:
>> 
>>  There is no SUBI instruction, because ADDI with a negative immediate is almost equivalent. The one
>>  exception arises from the asymmetry of the twos complement representation: SUBI with an immediate of
>>  211 would add 211 to a register, which ADDI is incapable of.
>> 
>> 
>> Testing on Premier-P550 SBC running Ubuntu-24.04:
>> - [x] : tier1-3 and gtest:all (release)
>> - [x] : hotspot:tier1 (fastdebug)
>
> Fei Yang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Revert unnecessary changes

Let's take `add` for example, new proposal about the naming is:

Assembler::addr    ====> add two registers
Assembler::addi    ====> add one register and sign-extended 12-bit immediate

and 

MacroAssembler::add(int64_t increment)    ====> add one register and any 64-bit immediate


Similar for rotate-right:

Assembler::rorr    ====> rotate right variable amount (Zbb)
Assembler::rori    ====> rotate right constant amount (sign-extended 12-bit immediate) (Zbb)

and 

MacroAssembler::ror(Register amount)    ====> Use Zbb rorr if available and basic instructions otherwise
MacroAssembler::ror(uint32_t amount)    ====> Use Zbb rori if available and basic instructions otherwise


Let me know what you think. Thanks.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/22804#issuecomment-2557005905


More information about the hotspot-dev mailing list