On Tue, 28 Nov 2023 11:46:10 GMT, fabioromano1 <d...@openjdk.org> wrote:
>> Indeed it looks as if that is correct. > > As specified in > https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.19: > "If the promoted type of the left-hand operand is int, then only the five > lowest-order bits of the right-hand operand are used as the shift distance. > It is as if the right-hand operand were subjected to a bitwise logical AND > operator & > ([ยง15.22.1](https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.22.1)) > with the mask value 0x1f (0b11111). The shift distance actually used is > therefore always in the range 0 to 31, inclusive. > The value of n >>> s is n right-shifted s bit positions with zero-extension, > where If n is negative and the type of the left-hand operand is int, then the > result is equal to that of the expression (n >> s) + (2 << ~s). The added > term (2 << ~s) cancels out the propagated sign bit." > Since (excessBits == 32 * numInts - numBits), then (excessBits == (32 - > (numBits & 0x1f)) & 0x1f), because (n & 0x1f == n mod 32). Since the five > lowest-order bits of 32 are 0, then the five lowest-order bits of (32 - > (numBits & 0x1f)) are the same of (-numBits), and so (excessBits == > (-numBits) & 0x1f), therefore (-1 >>> excessBits == -1 >>> -numBits). Thanks for the proof. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/16817#discussion_r1408164544