RFR: 8336274: MutableBigInteger.leftShift(int) optimization [v9]
fabioromano1
duke at openjdk.org
Thu Sep 12 12:30:07 UTC 2024
On Thu, 12 Sep 2024 12:01:47 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> Yes, it could, but the problem is that in this way the precondition `(resPos <= offset || resPos >= offset + intLen)` would be no longer correct, and in particular `resPos <= offset` is used by `MBI.leftShift()` if `result == value`.
>
> I mean something like
>
> private void primitiveRightShift(int n, int[] result, int resPos) {
> int[] val = value;
> int n2 = 32 - n;
> int c = 0;
> for (int i = 0; i < intLen; i++) {
> int b = val[offset + i];
> result[resPos + i] = c << n2 | b >>> n;
> c = b;
> }
> }
>
> and
>
> private void primitiveLeftShift(int n, int[] result, int resPos) {
> int[] val = value;
> int n2 = 32 - n;
> int c = 0;
> for (int i = intLen - 1; i >= 0; i--) {
> int b = val[offset + i];
> result[resPos + i] = c >>> n2 | b << n;
> c = b;
> }
>
> They are compatible with the precondition, right?
But in the second version, the precondition must be `resPos <= offset - intLen || resPos >= offset` to make sure that the result is correct whether `result == value`, and the condition `resPos <= offset - intLen` is stronger than `resPos <= offset`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20008#discussion_r1756759551
More information about the core-libs-dev
mailing list