< prev index next >

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.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.


 386     }
 387 
 388     public LongVector<S> ashiftR(Vector<Long,S> o) {
 389         return bOp(o, (i, a, b) -> (long) (a >> b));
 390     }
 391 
 392     public LongVector<S> ashiftR(Vector<Long,S> o, Mask<Long, S> m) {
 393         return bOp(o, m, (i, a, b) -> (long) (a >> b));
 394     }
 395 
 396     public LongVector<S> rotateL(int j) {
 397         return uOp((i, a) -> (long) Long.rotateLeft(a, j));
 398     }
 399 
 400     public LongVector<S> rotateR(int j) {
 401         return uOp((i, a) -> (long) Long.rotateRight(a, j));
 402     }
 403 
 404     @Override
 405     public void intoByteArray(byte[] a, int ix) {
 406         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 407         intoByteBuffer(bb);
 408     }
 409 
 410     @Override
 411     public void intoByteArray(byte[] a, int ix, Mask<Long, S> m) {
 412         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 413         intoByteBuffer(bb, m);
 414     }
 415 
 416     @Override
 417     public void intoByteBuffer(ByteBuffer bb) {
 418         LongBuffer fb = bb.asLongBuffer();
 419         forEach((i, a) -> fb.put(a));
 420     }
 421 
 422     @Override
 423     public void intoByteBuffer(ByteBuffer bb, Mask<Long, S> m) {
 424         LongBuffer fb = bb.asLongBuffer();
 425         forEach((i, a) -> {
 426             if (m.getElement(i))
 427                 fb.put(a);
 428             else
 429                 fb.position(fb.position() + 1);
 430         });
 431     }
 432 


 777          *
 778          * @param a the array
 779          * @param i the offset into the array, may be negative if relative
 780          * indexes in the index map compensate to produce a value within the
 781          * array bounds
 782          * @param indexMap the index map
 783          * @param j the offset into the index map
 784          * @return the vector loaded from an array
 785          * @throws IndexOutOfBoundsException if {@code j < 0}, or
 786          * {@code j > indexMap.length - this.length()},
 787          * or for any vector lane index {@code N} where the mask at lane
 788          * {@code N} is set the result of {@code i + indexMap[j + N]} is
 789          * {@code < 0} or {@code >= a.length}
 790          */
 791         public LongVector<S> fromArray(long[] a, int i, Mask<Long, S> m, int[] indexMap, int j) {
 792             return op(m, n -> a[i + indexMap[j + n]]);
 793         }
 794 
 795         @Override
 796         public LongVector<S> fromByteArray(byte[] a, int ix) {
 797             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 798             return fromByteBuffer(bb);
 799         }
 800 
 801         @Override
 802         public LongVector<S> fromByteArray(byte[] a, int ix, Mask<Long, S> m) {
 803             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix);
 804             return fromByteBuffer(bb, m);
 805         }
 806 
 807         @Override
 808         public LongVector<S> fromByteBuffer(ByteBuffer bb) {
 809             LongBuffer fb = bb.asLongBuffer();
 810             return op(i -> fb.get());
 811         }
 812 
 813         @Override
 814         public LongVector<S> fromByteBuffer(ByteBuffer bb, Mask<Long, S> m) {
 815             LongBuffer fb = bb.asLongBuffer();
 816             return op(i -> {
 817                 if(m.getElement(i))
 818                     return fb.get();
 819                 else {
 820                     fb.position(fb.position() + 1);
 821                     return (long) 0;
 822                 }
 823             });
 824         }
 825 
 826         @Override
 827         public LongVector<S> fromByteBuffer(ByteBuffer bb, int ix) {
 828             bb = bb.duplicate().position(ix);
 829             LongBuffer fb = bb.asLongBuffer();
 830             return op(i -> fb.get(i));
 831         }
 832 
 833         @Override
 834         public LongVector<S> fromByteBuffer(ByteBuffer bb, int ix, Mask<Long, S> m) {
 835             bb = bb.duplicate().position(ix);
 836             LongBuffer fb = bb.asLongBuffer();
 837             return op(m, i -> fb.get(i));
 838         }
 839 
 840         @Override
 841         public <F, T extends Shape> LongVector<S> reshape(Vector<F, T> o) {
 842             int blen = Math.max(o.species().bitSize(), bitSize()) / Byte.SIZE;
 843             ByteBuffer bb = ByteBuffer.allocate(blen).order(ByteOrder.nativeOrder());
 844             o.intoByteBuffer(bb, 0);
 845             return fromByteBuffer(bb, 0);
 846         }
 847 
 848         @Override
 849         @ForceInline
 850         public <F> LongVector<S> rebracket(Vector<F, S> o) {
 851             return reshape(o);
 852         }
 853 
 854         @Override
 855         @ForceInline




 386     }
 387 
 388     public LongVector<S> ashiftR(Vector<Long,S> o) {
 389         return bOp(o, (i, a, b) -> (long) (a >> b));
 390     }
 391 
 392     public LongVector<S> ashiftR(Vector<Long,S> o, Mask<Long, S> m) {
 393         return bOp(o, m, (i, a, b) -> (long) (a >> b));
 394     }
 395 
 396     public LongVector<S> rotateL(int j) {
 397         return uOp((i, a) -> (long) Long.rotateLeft(a, j));
 398     }
 399 
 400     public LongVector<S> rotateR(int j) {
 401         return uOp((i, a) -> (long) Long.rotateRight(a, j));
 402     }
 403 
 404     @Override
 405     public void intoByteArray(byte[] a, int ix) {
 406         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 407         intoByteBuffer(bb);
 408     }
 409 
 410     @Override
 411     public void intoByteArray(byte[] a, int ix, Mask<Long, S> m) {
 412         ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 413         intoByteBuffer(bb, m);
 414     }
 415 
 416     @Override
 417     public void intoByteBuffer(ByteBuffer bb) {
 418         LongBuffer fb = bb.asLongBuffer();
 419         forEach((i, a) -> fb.put(a));
 420     }
 421 
 422     @Override
 423     public void intoByteBuffer(ByteBuffer bb, Mask<Long, S> m) {
 424         LongBuffer fb = bb.asLongBuffer();
 425         forEach((i, a) -> {
 426             if (m.getElement(i))
 427                 fb.put(a);
 428             else
 429                 fb.position(fb.position() + 1);
 430         });
 431     }
 432 


 777          *
 778          * @param a the array
 779          * @param i the offset into the array, may be negative if relative
 780          * indexes in the index map compensate to produce a value within the
 781          * array bounds
 782          * @param indexMap the index map
 783          * @param j the offset into the index map
 784          * @return the vector loaded from an array
 785          * @throws IndexOutOfBoundsException if {@code j < 0}, or
 786          * {@code j > indexMap.length - this.length()},
 787          * or for any vector lane index {@code N} where the mask at lane
 788          * {@code N} is set the result of {@code i + indexMap[j + N]} is
 789          * {@code < 0} or {@code >= a.length}
 790          */
 791         public LongVector<S> fromArray(long[] a, int i, Mask<Long, S> m, int[] indexMap, int j) {
 792             return op(m, n -> a[i + indexMap[j + n]]);
 793         }
 794 
 795         @Override
 796         public LongVector<S> fromByteArray(byte[] a, int ix) {
 797             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 798             return fromByteBuffer(bb);
 799         }
 800 
 801         @Override
 802         public LongVector<S> fromByteArray(byte[] a, int ix, Mask<Long, S> m) {
 803             ByteBuffer bb = ByteBuffer.wrap(a, ix, a.length - ix).order(ByteOrder.nativeOrder());
 804             return fromByteBuffer(bb, m);
 805         }
 806 
 807         @Override
 808         public LongVector<S> fromByteBuffer(ByteBuffer bb) {
 809             LongBuffer fb = bb.asLongBuffer();
 810             return op(i -> fb.get());
 811         }
 812 
 813         @Override
 814         public LongVector<S> fromByteBuffer(ByteBuffer bb, Mask<Long, S> m) {
 815             LongBuffer fb = bb.asLongBuffer();
 816             return op(i -> {
 817                 if(m.getElement(i))
 818                     return fb.get();
 819                 else {
 820                     fb.position(fb.position() + 1);
 821                     return (long) 0;
 822                 }
 823             });
 824         }
 825 
 826         @Override
 827         public LongVector<S> fromByteBuffer(ByteBuffer bb, int ix) {
 828             bb = bb.duplicate().order(ByteOrder.nativeOrder()).position(ix);
 829             LongBuffer fb = bb.asLongBuffer();
 830             return op(i -> fb.get(i));
 831         }
 832 
 833         @Override
 834         public LongVector<S> fromByteBuffer(ByteBuffer bb, int ix, Mask<Long, S> m) {
 835             bb = bb.duplicate().order(ByteOrder.nativeOrder()).position(ix);
 836             LongBuffer fb = bb.asLongBuffer();
 837             return op(m, i -> fb.get(i));
 838         }
 839 
 840         @Override
 841         public <F, T extends Shape> LongVector<S> reshape(Vector<F, T> o) {
 842             int blen = Math.max(o.species().bitSize(), bitSize()) / Byte.SIZE;
 843             ByteBuffer bb = ByteBuffer.allocate(blen).order(ByteOrder.nativeOrder());
 844             o.intoByteBuffer(bb, 0);
 845             return fromByteBuffer(bb, 0);
 846         }
 847 
 848         @Override
 849         @ForceInline
 850         public <F> LongVector<S> rebracket(Vector<F, S> o) {
 851             return reshape(o);
 852         }
 853 
 854         @Override
 855         @ForceInline


< prev index next >