How can I perform a bitwise shift operation (<< or >>) directly on an IntVector
using the Java Vector API?
I haven't been able to find anything obvious in the API to do this; the closest I've found is myIntVec.lanewise(VectorOperators.ASHR, shiftAmt)
but this performs an additional AND
operation on the shift amount.
The behavior is correct: pure <<
for int
s also performs an &
operation on the shift amount. The &
correctly does the appropriate &
operation for the values being operated on.
ASHR is correctly equivalent to >>
. LSHR is equivalent to >>>
. LSHL is equivalent to <<
. These all do the same thing as the normal operators do.
See JLS 15.19 for details.