< prev index next >

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

Print this page
rev 49878 : ByteBuffers need to use native order

All ByteBuffers need to use native order since intrinsification leads
to use of vector operations with native order. Additionally, using
native order means there is no preferential treatment to ordering
that would create unnecessary overheads.


 471         return tOp(o1, o2, m, (i, a, b, c) -> Math.fma(a, b, c));
 472     }
 473 
 474     public abstract FloatVector<S> fma(float o1, float o2, Mask<Float,S> m);
 475 
 476     public FloatVector<S> hypot(Vector<Float,S> o) {
 477         return bOp(o, (i, a, b) -> (float) Math.hypot((double) a, (double) b));
 478     }
 479 
 480     public abstract FloatVector<S> hypot(float o);
 481 
 482     public FloatVector<S> hypot(Vector<Float,S> o, Mask<Float,S> m) {
 483         return bOp(o, m, (i, a, b) -> (float) Math.hypot((double) a, (double) b));
 484     }
 485 
 486     public abstract FloatVector<S> hypot(float o, Mask<Float,S> m);
 487 
 488 
 489     @Override
 490     public void intoByteArray(byte[] a, int ix) {
 491         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 492         intoByteBuffer(bb);
 493     }
 494 
 495     @Override
 496     public void intoByteArray(byte[] a, int ix, Mask<Float, S> m) {
 497         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 498         intoByteBuffer(bb, m);
 499     }
 500 
 501     @Override
 502     public void intoByteBuffer(ByteBuffer bb) {
 503         FloatBuffer fb = bb.asFloatBuffer();
 504         forEach((i, a) -> fb.put(a));
 505     }
 506 
 507     @Override
 508     public void intoByteBuffer(ByteBuffer bb, Mask<Float, S> m) {
 509         FloatBuffer fb = bb.asFloatBuffer();
 510         forEach((i, a) -> {
 511             if (m.getElement(i))
 512                 fb.put(a);
 513             else
 514                 fb.position(fb.position() + 1);
 515         });
 516     }
 517 


 842          *
 843          * @param a the array
 844          * @param i the offset into the array, may be negative if relative
 845          * indexes in the index map compensate to produce a value within the
 846          * array bounds
 847          * @param indexMap the index map
 848          * @param j the offset into the index map
 849          * @return the vector loaded from an array
 850          * @throws IndexOutOfBoundsException if {@code j < 0}, or
 851          * {@code j > indexMap.length - this.length()},
 852          * or for any vector lane index {@code N} where the mask at lane
 853          * {@code N} is set the result of {@code i + indexMap[j + N]} is
 854          * {@code < 0} or {@code >= a.length}
 855          */
 856         public FloatVector<S> fromArray(float[] a, int i, Mask<Float, S> m, int[] indexMap, int j) {
 857             return op(m, n -> a[i + indexMap[j + n]]);
 858         }
 859 
 860         @Override
 861         public FloatVector<S> fromByteArray(byte[] a, int ix) {
 862             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 863             return fromByteBuffer(bb);
 864         }
 865 
 866         @Override
 867         public FloatVector<S> fromByteArray(byte[] a, int ix, Mask<Float, S> m) {
 868             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 869             return fromByteBuffer(bb, m);
 870         }
 871 
 872         @Override
 873         public FloatVector<S> fromByteBuffer(ByteBuffer bb) {
 874             FloatBuffer fb = bb.asFloatBuffer();
 875             return op(i -> fb.get());
 876         }
 877 
 878         @Override
 879         public FloatVector<S> fromByteBuffer(ByteBuffer bb, Mask<Float, S> m) {
 880             FloatBuffer fb = bb.asFloatBuffer();
 881             return op(i -> {
 882                 if(m.getElement(i))
 883                     return fb.get();
 884                 else {
 885                     fb.position(fb.position() + 1);
 886                     return (float) 0;
 887                 }
 888             });
 889         }
 890 
 891         @Override
 892         public FloatVector<S> fromByteBuffer(ByteBuffer bb, int ix) {
 893             bb = bb.duplicate().position(ix);
 894             FloatBuffer fb = bb.asFloatBuffer();
 895             return op(i -> fb.get(i));
 896         }
 897 
 898         @Override
 899         public FloatVector<S> fromByteBuffer(ByteBuffer bb, int ix, Mask<Float, S> m) {
 900             bb = bb.duplicate().position(ix);
 901             FloatBuffer fb = bb.asFloatBuffer();
 902             return op(m, i -> fb.get(i));
 903         }
 904 
 905         @Override
 906         public <F, T extends Shape> FloatVector<S> reshape(Vector<F, T> o) {
 907             int blen = Math.max(o.species().bitSize(), bitSize()) / Byte.SIZE;
 908             ByteBuffer bb = ByteBuffer.allocate(blen).order(ByteOrder.nativeOrder());
 909             o.intoByteBuffer(bb, 0);
 910             return fromByteBuffer(bb, 0);
 911         }
 912 
 913         @Override
 914         @ForceInline
 915         public <F> FloatVector<S> rebracket(Vector<F, S> o) {
 916             return reshape(o);
 917         }
 918 
 919         @Override
 920         @ForceInline




 471         return tOp(o1, o2, m, (i, a, b, c) -> Math.fma(a, b, c));
 472     }
 473 
 474     public abstract FloatVector<S> fma(float o1, float o2, Mask<Float,S> m);
 475 
 476     public FloatVector<S> hypot(Vector<Float,S> o) {
 477         return bOp(o, (i, a, b) -> (float) Math.hypot((double) a, (double) b));
 478     }
 479 
 480     public abstract FloatVector<S> hypot(float o);
 481 
 482     public FloatVector<S> hypot(Vector<Float,S> o, Mask<Float,S> m) {
 483         return bOp(o, m, (i, a, b) -> (float) Math.hypot((double) a, (double) b));
 484     }
 485 
 486     public abstract FloatVector<S> hypot(float o, Mask<Float,S> m);
 487 
 488 
 489     @Override
 490     public void intoByteArray(byte[] a, int ix) {
 491         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 492         intoByteBuffer(bb);
 493     }
 494 
 495     @Override
 496     public void intoByteArray(byte[] a, int ix, Mask<Float, S> m) {
 497         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 498         intoByteBuffer(bb, m);
 499     }
 500 
 501     @Override
 502     public void intoByteBuffer(ByteBuffer bb) {
 503         FloatBuffer fb = bb.asFloatBuffer();
 504         forEach((i, a) -> fb.put(a));
 505     }
 506 
 507     @Override
 508     public void intoByteBuffer(ByteBuffer bb, Mask<Float, S> m) {
 509         FloatBuffer fb = bb.asFloatBuffer();
 510         forEach((i, a) -> {
 511             if (m.getElement(i))
 512                 fb.put(a);
 513             else
 514                 fb.position(fb.position() + 1);
 515         });
 516     }
 517 


 842          *
 843          * @param a the array
 844          * @param i the offset into the array, may be negative if relative
 845          * indexes in the index map compensate to produce a value within the
 846          * array bounds
 847          * @param indexMap the index map
 848          * @param j the offset into the index map
 849          * @return the vector loaded from an array
 850          * @throws IndexOutOfBoundsException if {@code j < 0}, or
 851          * {@code j > indexMap.length - this.length()},
 852          * or for any vector lane index {@code N} where the mask at lane
 853          * {@code N} is set the result of {@code i + indexMap[j + N]} is
 854          * {@code < 0} or {@code >= a.length}
 855          */
 856         public FloatVector<S> fromArray(float[] a, int i, Mask<Float, S> m, int[] indexMap, int j) {
 857             return op(m, n -> a[i + indexMap[j + n]]);
 858         }
 859 
 860         @Override
 861         public FloatVector<S> fromByteArray(byte[] a, int ix) {
 862             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 863             return fromByteBuffer(bb);
 864         }
 865 
 866         @Override
 867         public FloatVector<S> fromByteArray(byte[] a, int ix, Mask<Float, S> m) {
 868             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 869             return fromByteBuffer(bb, m);
 870         }
 871 
 872         @Override
 873         public FloatVector<S> fromByteBuffer(ByteBuffer bb) {
 874             FloatBuffer fb = bb.asFloatBuffer();
 875             return op(i -> fb.get());
 876         }
 877 
 878         @Override
 879         public FloatVector<S> fromByteBuffer(ByteBuffer bb, Mask<Float, S> m) {
 880             FloatBuffer fb = bb.asFloatBuffer();
 881             return op(i -> {
 882                 if(m.getElement(i))
 883                     return fb.get();
 884                 else {
 885                     fb.position(fb.position() + 1);
 886                     return (float) 0;
 887                 }
 888             });
 889         }
 890 
 891         @Override
 892         public FloatVector<S> fromByteBuffer(ByteBuffer bb, int ix) {
 893             bb = bb.duplicate().order(ByteOrder.nativeOrder()).position(ix);
 894             FloatBuffer fb = bb.asFloatBuffer();
 895             return op(i -> fb.get(i));
 896         }
 897 
 898         @Override
 899         public FloatVector<S> fromByteBuffer(ByteBuffer bb, int ix, Mask<Float, S> m) {
 900             bb = bb.duplicate().order(ByteOrder.nativeOrder()).position(ix);
 901             FloatBuffer fb = bb.asFloatBuffer();
 902             return op(m, i -> fb.get(i));
 903         }
 904 
 905         @Override
 906         public <F, T extends Shape> FloatVector<S> reshape(Vector<F, T> o) {
 907             int blen = Math.max(o.species().bitSize(), bitSize()) / Byte.SIZE;
 908             ByteBuffer bb = ByteBuffer.allocate(blen).order(ByteOrder.nativeOrder());
 909             o.intoByteBuffer(bb, 0);
 910             return fromByteBuffer(bb, 0);
 911         }
 912 
 913         @Override
 914         @ForceInline
 915         public <F> FloatVector<S> rebracket(Vector<F, S> o) {
 916             return reshape(o);
 917         }
 918 
 919         @Override
 920         @ForceInline


< prev index next >