< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java

Print this page

        

@@ -1054,52 +1054,67 @@
     }
 
 
 
     @Override
+    @ForceInline
     public ShortMaxVector rotateLanesLeft(int j) {
-        short[] vec = getElements();
-        short[] res = new short[length()];
-        for (int i = 0; i < length(); i++){
-            res[(j + i) % length()] = vec[i];
+      int L = length();
+      if (j < 0) {
+         throw new IllegalArgumentException("Index " + j + " must be zero or positive");
+      } else {
+        j = j & (L-1);
+        VectorShuffle<Short> PermMask  = VectorShuffle.shuffleIota(SPECIES, L - j);
+        return this.rearrange(PermMask);
         }
-        return new ShortMaxVector(res);
     }
 
     @Override
+    @ForceInline
     public ShortMaxVector rotateLanesRight(int j) {
-        short[] vec = getElements();
-        short[] res = new short[length()];
-        for (int i = 0; i < length(); i++){
-            int z = i - j;
-            if(j < 0) {
-                res[length() + z] = vec[i];
+      int L = length();
+      if (j < 0) {
+         throw new IllegalArgumentException("Index " + j + " must be zero or positive");
             } else {
-                res[z] = vec[i];
-            }
+        j = j & (L-1);
+        VectorShuffle<Short> PermMask = VectorShuffle.shuffleIota(SPECIES, j);
+        return this.rearrange(PermMask);
         }
-        return new ShortMaxVector(res);
     }
 
     @Override
+    @ForceInline
+    @SuppressWarnings("unchecked")
     public ShortMaxVector shiftLanesLeft(int j) {
-        short[] vec = getElements();
-        short[] res = new short[length()];
-        for (int i = 0; i < length() - j; i++) {
-            res[i] = vec[i + j];
+       int L = length();
+       if (j < 0) {
+         throw new IllegalArgumentException("Index " + j + " must be zero or positive");
+       } else if ( j >= L ) {
+         return ZERO;
+       } else {
+         ShortMaxShuffle     Iota    = (ShortMaxShuffle)(VectorShuffle.shuffleIota(SPECIES, L-j));
+         VectorMask<Short> BlendMask = Iota.toVector().lessThan(ShortMaxVector.broadcast(SPECIES, (short)(L-j)));
+         Iota    = (ShortMaxShuffle)(VectorShuffle.shuffleIota(SPECIES, L -j));
+         return ZERO.blend(this.rearrange(Iota),BlendMask);
         }
-        return new ShortMaxVector(res);
     }
 
     @Override
+    @ForceInline
+    @SuppressWarnings("unchecked")
     public ShortMaxVector shiftLanesRight(int j) {
-        short[] vec = getElements();
-        short[] res = new short[length()];
-        for (int i = 0; i < length() - j; i++){
-            res[i + j] = vec[i];
+       int L = length();
+       if (j < 0) {
+         throw new IllegalArgumentException("Index " + j + " must be zero or positive");
+       } else if ( j >= L ) {
+         return ZERO;
+       } else {
+         ShortMaxShuffle     Iota    = (ShortMaxShuffle)(VectorShuffle.shuffleIota(SPECIES, j));
+         VectorMask<Short> BlendMask = Iota.toVector().greaterThanEq(ShortMaxVector.broadcast(SPECIES, (short)(j)));
+         Iota    = (ShortMaxShuffle)(VectorShuffle.shuffleIota(SPECIES, j));
+         return ZERO.blend(this.rearrange(Iota),BlendMask);
         }
-        return new ShortMaxVector(res);
     }
 
     @Override
     @ForceInline
     public ShortMaxVector rearrange(Vector<Short> v,

@@ -1334,21 +1349,28 @@
         @Override
         public VectorSpecies<Short> species() {
             return SPECIES;
         }
 
-        @Override
-        public ShortVector toVector() {
+        private ShortVector toVector_helper() {
             short[] va = new short[SPECIES.length()];
             for (int i = 0; i < va.length; i++) {
               va[i] = (short) lane(i);
             }
             return ShortVector.fromArray(SPECIES, va, 0);
         }
 
         @Override
         @ForceInline
+        public ShortVector toVector() {
+            return VectorIntrinsics.shuffleToVector(ShortMaxVector.class, short.class, ShortMaxShuffle.class, this,
+                                                    SPECIES.length(), 
+                                                    (s) -> (((ShortMaxShuffle)(s)).toVector_helper()));
+        }
+
+        @Override
+        @ForceInline
         @SuppressWarnings("unchecked")
         public <F> VectorShuffle<F> cast(VectorSpecies<F> species) {
             if (length() != species.length())
                 throw new IllegalArgumentException("Shuffle length and species length differ");
             Class<?> stype = species.elementType();

@@ -1368,10 +1390,11 @@
             } else {
                 throw new UnsupportedOperationException("Bad lane type for casting.");
             }
         }
 
+
         @Override
         public ShortMaxShuffle rearrange(VectorShuffle<Short> o) {
             ShortMaxShuffle s = (ShortMaxShuffle) o;
             byte[] r = new byte[reorder.length];
             for (int i = 0; i < reorder.length; i++) {
< prev index next >