< prev index next >

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

Print this page
rev 58165 : Fix the issue that unslice modifies the argument vector
Summary: Change the name of getElements() to vec() and clone argument value to
avoid it being modified

@@ -87,11 +87,11 @@
     // and lazy version of C++ templates.
 
     // Virtualized getter
 
     /*package-private*/
-    abstract double[] getElements();
+    abstract double[] vec();
 
     // Virtualized constructors
 
     /**
      * Build a vector directly using my own constructor.

@@ -151,11 +151,11 @@
     abstract
     DoubleVector uOp(FUnOp f);
     @ForceInline
     final
     DoubleVector uOpTemplate(FUnOp f) {
-        double[] vec = getElements();
+        double[] vec = vec();
         double[] res = new double[length()];
         for (int i = 0; i < res.length; i++) {
             res[i] = f.apply(i, vec[i]);
         }
         return vectorFactory(res);

@@ -167,11 +167,11 @@
                              FUnOp f);
     @ForceInline
     final
     DoubleVector uOpTemplate(VectorMask<Double> m,
                                      FUnOp f) {
-        double[] vec = getElements();
+        double[] vec = vec();
         double[] res = new double[length()];
         boolean[] mbits = ((AbstractMask<Double>)m).getBits();
         for (int i = 0; i < res.length; i++) {
             res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
         }

@@ -192,12 +192,12 @@
     @ForceInline
     final
     DoubleVector bOpTemplate(Vector<Double> o,
                                      FBinOp f) {
         double[] res = new double[length()];
-        double[] vec1 = this.getElements();
-        double[] vec2 = ((DoubleVector)o).getElements();
+        double[] vec1 = this.vec();
+        double[] vec2 = ((DoubleVector)o).vec();
         for (int i = 0; i < res.length; i++) {
             res[i] = f.apply(i, vec1[i], vec2[i]);
         }
         return vectorFactory(res);
     }

@@ -211,12 +211,12 @@
     final
     DoubleVector bOpTemplate(Vector<Double> o,
                                      VectorMask<Double> m,
                                      FBinOp f) {
         double[] res = new double[length()];
-        double[] vec1 = this.getElements();
-        double[] vec2 = ((DoubleVector)o).getElements();
+        double[] vec1 = this.vec();
+        double[] vec2 = ((DoubleVector)o).vec();
         boolean[] mbits = ((AbstractMask<Double>)m).getBits();
         for (int i = 0; i < res.length; i++) {
             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
         }
         return vectorFactory(res);

@@ -238,13 +238,13 @@
     final
     DoubleVector tOpTemplate(Vector<Double> o1,
                                      Vector<Double> o2,
                                      FTriOp f) {
         double[] res = new double[length()];
-        double[] vec1 = this.getElements();
-        double[] vec2 = ((DoubleVector)o1).getElements();
-        double[] vec3 = ((DoubleVector)o2).getElements();
+        double[] vec1 = this.vec();
+        double[] vec2 = ((DoubleVector)o1).vec();
+        double[] vec3 = ((DoubleVector)o2).vec();
         for (int i = 0; i < res.length; i++) {
             res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
         }
         return vectorFactory(res);
     }

@@ -260,13 +260,13 @@
     DoubleVector tOpTemplate(Vector<Double> o1,
                                      Vector<Double> o2,
                                      VectorMask<Double> m,
                                      FTriOp f) {
         double[] res = new double[length()];
-        double[] vec1 = this.getElements();
-        double[] vec2 = ((DoubleVector)o1).getElements();
-        double[] vec3 = ((DoubleVector)o2).getElements();
+        double[] vec1 = this.vec();
+        double[] vec2 = ((DoubleVector)o1).vec();
+        double[] vec3 = ((DoubleVector)o2).vec();
         boolean[] mbits = ((AbstractMask<Double>)m).getBits();
         for (int i = 0; i < res.length; i++) {
             res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
         }
         return vectorFactory(res);

@@ -278,11 +278,11 @@
     abstract
     double rOp(double v, FBinOp f);
     @ForceInline
     final
     double rOpTemplate(double v, FBinOp f) {
-        double[] vec = getElements();
+        double[] vec = vec();
         for (int i = 0; i < vec.length; i++) {
             v = f.apply(i, v, vec[i]);
         }
         return v;
     }

@@ -297,11 +297,11 @@
     /*package-private*/
     @ForceInline
     final
     <M> DoubleVector ldOp(M memory, int offset,
                                   FLdOp<M> f) {
-        //dummy; no vec = getElements();
+        //dummy; no vec = vec();
         double[] res = new double[length()];
         for (int i = 0; i < res.length; i++) {
             res[i] = f.apply(memory, offset, i);
         }
         return vectorFactory(res);

@@ -311,11 +311,11 @@
     @ForceInline
     final
     <M> DoubleVector ldOp(M memory, int offset,
                                   VectorMask<Double> m,
                                   FLdOp<M> f) {
-        //double[] vec = getElements();
+        //double[] vec = vec();
         double[] res = new double[length()];
         boolean[] mbits = ((AbstractMask<Double>)m).getBits();
         for (int i = 0; i < res.length; i++) {
             if (mbits[i]) {
                 res[i] = f.apply(memory, offset, i);

@@ -331,11 +331,11 @@
     /*package-private*/
     @ForceInline
     final
     <M> void stOp(M memory, int offset,
                   FStOp<M> f) {
-        double[] vec = getElements();
+        double[] vec = vec();
         for (int i = 0; i < vec.length; i++) {
             f.apply(memory, offset, i, vec[i]);
         }
     }
 

@@ -343,11 +343,11 @@
     @ForceInline
     final
     <M> void stOp(M memory, int offset,
                   VectorMask<Double> m,
                   FStOp<M> f) {
-        double[] vec = getElements();
+        double[] vec = vec();
         boolean[] mbits = ((AbstractMask<Double>)m).getBits();
         for (int i = 0; i < vec.length; i++) {
             if (mbits[i]) {
                 f.apply(memory, offset, i, vec[i]);
             }

@@ -365,12 +365,12 @@
     @ForceInline
     final
     AbstractMask<Double> bTest(int cond,
                                   Vector<Double> o,
                                   FBinTest f) {
-        double[] vec1 = getElements();
-        double[] vec2 = ((DoubleVector)o).getElements();
+        double[] vec1 = vec();
+        double[] vec2 = ((DoubleVector)o).vec();
         boolean[] bits = new boolean[length()];
         for (int i = 0; i < length(); i++){
             bits[i] = f.apply(cond, i, vec1[i], vec2[i]);
         }
         return maskFactory(bits);

@@ -1944,12 +1944,12 @@
     final
     @ForceInline
     DoubleVector sliceTemplate(int origin, Vector<Double> v1) {
         DoubleVector that = (DoubleVector) v1;
         that.check(this);
-        double[] a0 = this.getElements();
-        double[] a1 = that.getElements();
+        double[] a0 = this.vec();
+        double[] a1 = that.vec();
         double[] res = new double[a0.length];
         int vlen = res.length;
         int firstPart = vlen - origin;
         System.arraycopy(a0, origin, res, 0, firstPart);
         System.arraycopy(a1, 0, res, firstPart, origin);

@@ -1987,12 +1987,12 @@
     @ForceInline
     DoubleVector
     unsliceTemplate(int origin, Vector<Double> w, int part) {
         DoubleVector that = (DoubleVector) w;
         that.check(this);
-        double[] slice = this.getElements();
-        double[] res = that.getElements();
+        double[] slice = this.vec();
+        double[] res = that.vec().clone();
         int vlen = res.length;
         int firstPart = vlen - origin;
         switch (part) {
         case 0:
             System.arraycopy(slice, 0, res, origin, firstPart);
< prev index next >