On Wed, 25 Nov 2026 21:42:08 GMT, Shawn Emery <[email protected]> wrote:

>> This set of changes implements multiplication and squaring field operations 
>> on the P-384 curve using AArch64 intrinsics.  The performance gains from 
>> this enhancement yields:
>> 
>> Key pair generation - P-384: +38%
>> Key agreement - P-384: +37%
>> KEM decapsulation - secP384r1: +36%
>> KEM encapsulation - secP384r1: +36%
>> 
>> Key pair generation - secP384r1MLKEM1024: +35%
>> KEM decapsulation - secP384r1MLKEM1024: +35%
>> KEM encapsulation - secP384r1MLKEM1024: +36%
>> 
>> ---------
>> - [X] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Shawn Emery has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update based on comment from @adinn

Spotted one more detail that needs fixing.

src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp line 9173:

> 9171:       for (int j = i + 1; j < LIMBS_P384; j++) {
> 9172:         __ ldr(a, Address(aLimbs, j * 8));
> 9173:         __ smulh(high, a, aArg);

Hmm. I was expecting this generation sequence also to be encapsulated in a call 
to `mulhl_P384`. However, I overlooked the small detail that in this case the 
accumulation into `(c[i], c[i+1])` requires a left shift by 1.

It would be clearer to any maintainer if you emphasised the continuity of this 
case with the others. You can achieve that by tweaking `mulhl_P384` to accept 
an extra, optional shift argument, allowing you to call it to cater for this 
case as well as the previous ones.

i.e. modify the implementation of mulhl_P384 to:


  // output a * b as 2*55 bit products in (high, low) and
  // accumulate (high << shift, low << shift) into (c[i], c[i+1])
  void mulhl_P384(Register a, Register b, Register high, Register low, Register 
c[], int i, int shift = 0) {
    __ smulh(high, a, b);
    __ mul(low, a, b);
    __ extr(high, high, low, BPL_P384);
    __ andr(low, low,  MASK_P384);
    __ add(c[i], c[i], low, Assembler::LSL, shift);
    __ add(c[i + 1], c[i + 1], high, Assembler::LSL, shift);
  }


and then at this point replace the generation sequence with


        mulhl_P384(a, aArg, high, low, c, i+j, 1);


Note that `shift` defaults to `0` so the existing calls to `mulhl_P384` will 
still generate the desired result.

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

PR Review: https://git.openjdk.org/jdk/pull/33618#pullrequestreview-6072165051
PR Review Comment: https://git.openjdk.org/jdk/pull/33618#discussion_r4706755102

Reply via email to