< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template

Print this page

        

@@ -1622,52 +1622,67 @@
         return new $fpvectortype$(res);
     }
 #end[intOrLong]
 
     @Override
+    @ForceInline
     public $vectortype$ rotateLanesLeft(int j) {
-        $type$[] vec = getElements();
-        $type$[] res = new $type$[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<$Boxtype$> PermMask  = VectorShuffle.shuffleIota(SPECIES, L - j);
+        return this.rearrange(PermMask);
         }
-        return new $vectortype$(res);
     }
 
     @Override
+    @ForceInline
     public $vectortype$ rotateLanesRight(int j) {
-        $type$[] vec = getElements();
-        $type$[] res = new $type$[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<$Boxtype$> PermMask = VectorShuffle.shuffleIota(SPECIES, j);
+        return this.rearrange(PermMask);
         }
-        return new $vectortype$(res);
     }
 
     @Override
+    @ForceInline
+    @SuppressWarnings("unchecked")
     public $vectortype$ shiftLanesLeft(int j) {
-        $type$[] vec = getElements();
-        $type$[] res = new $type$[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 {
+         $shuffletype$     Iota    = ($shuffletype$)(VectorShuffle.shuffleIota(SPECIES, L-j));
+         VectorMask<$Boxtype$> BlendMask = Iota.toVector().lessThan($vectortype$.broadcast(SPECIES, ($type$)(L-j)));
+         Iota    = ($shuffletype$)(VectorShuffle.shuffleIota(SPECIES, L -j));
+         return ZERO.blend(this.rearrange(Iota),BlendMask);
         }
-        return new $vectortype$(res);
     }
 
     @Override
+    @ForceInline
+    @SuppressWarnings("unchecked")
     public $vectortype$ shiftLanesRight(int j) {
-        $type$[] vec = getElements();
-        $type$[] res = new $type$[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 {
+         $shuffletype$     Iota    = ($shuffletype$)(VectorShuffle.shuffleIota(SPECIES, j));
+         VectorMask<$Boxtype$> BlendMask = Iota.toVector().greaterThanEq($vectortype$.broadcast(SPECIES, ($type$)(j)));
+         Iota    = ($shuffletype$)(VectorShuffle.shuffleIota(SPECIES, j));
+         return ZERO.blend(this.rearrange(Iota),BlendMask);
         }
-        return new $vectortype$(res);
     }
 
     @Override
     @ForceInline
     public $vectortype$ rearrange(Vector<$Boxtype$> v,

@@ -1934,21 +1949,28 @@
         @Override
         public VectorSpecies<$Boxtype$> species() {
             return SPECIES;
         }
 
-        @Override
-        public $abstractvectortype$ toVector() {
+        private $abstractvectortype$ toVector_helper() {
             $type$[] va = new $type$[SPECIES.length()];
             for (int i = 0; i < va.length; i++) {
               va[i] = ($type$) lane(i);
             }
             return $abstractvectortype$.fromArray(SPECIES, va, 0);
         }
 
         @Override
         @ForceInline
+        public $abstractvectortype$ toVector() {
+            return VectorIntrinsics.shuffleToVector($vectortype$.class, $type$.class, $shuffletype$.class, this,
+                                                    SPECIES.length(), 
+                                                    (s) -> ((($shuffletype$)(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();

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