Vector.shiftER, Vector.shiftEL not working as expected.

Paul Sandoz paul.sandoz at oracle.com
Tue Oct 10 23:24:22 UTC 2017


> On 10 Oct 2017, at 14:59, Richard Startin <richard at openkappa.co.uk> wrote:
> 
> I think I may have confused similarly named instructions and want to clarify:
> 
> - As you point out, VPSLLD and VPSRLD perform bit shifts on packed integers, and these instructions correspond to shiftL and shiftR respectively on the API (and presumably, VPSRAD for aShiftR). 

Yes.


> - VPSLLDQ [1] shifts a vector word left by a whole number of bytes - which would always be a multiple of 4 for IntVector<S> - will this be the intrinsic implementation of shiftEL? 
> 

I was anticipating that shiftEL and friends might be made intrinsic using a permutation-based instruction.

I don’t see how VPSLLDQ could be used to support such element permutation since it shifts left the low and high 128-bit lanes independently:

  TEMP ← COUNT
  IF (TEMP > 15) THEN TEMP (cid:193) 16; FI
  DEST[127:0] ← SRC[127:0] << (TEMP * 8)
  DEST[255:128] ← SRC[255:128] << (TEMP * 8)


> I don't think I understand your last point. If I shift left (element wise) I expect to remove the left-most element. Is this how it will work, as in the test case, going forwards? Or the other way round?
> 

Left-most is confusing depending on the vector model in one's head :-)

My mental model of the Vector API is the sequential order of the vector elements corresponds to that they are loaded from. So when loading an int vector from an int array starting from index 0 i expect the first (left-most) element in the vector to correspond to the first (left-most) element in the array, thus shifting all elements to the left by one lane would behave as follows:

jshell> int[] x = {1, 2, 3, 4, 5, 6, 7, 8}
x ==> int[8] { 1, 2, 3, 4, 5, 6, 7, 8 }

jshell> IntVector<Shapes.S256Bit> v = (IntVector<Shapes.S256Bit>)species.fromArray(x, 0).shiftEL(1)
v ==> [2, 3, 4, 5, 6, 7, 8, 0]

jshell> // This is equivalent to

jshell> Arrays.copyOfRange(x, 1, 1 + 8)
$14 ==> int[8] { 2, 3, 4, 5, 6, 7, 8, 0 }

jshell> IntVector<Shapes.S256Bit> v = (IntVector<Shapes.S256Bit>)species.fromArray(x, 0).shiftEL(4)
v ==> [5, 6, 7, 8, 0, 0, 0, 0]

jshell> // This is equivalent to

jshell> Arrays.copyOfRange(x, 4, 4 + 8)
$16 ==> int[8] { 5, 6, 7, 8, 0, 0, 0, 0 }

That is at odds to viewing the vector as 256 bits of data where the left most significant 32 bits corresponds to the last element in the vector. I don’t believe there is a logical shift L/R operating uniformly over all 256 bits of say a YMM register, if there was then we could bit shift right appropriately to achieve the same behaviour as above.

Pail.




More information about the panama-dev mailing list