< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.incubator.vector;
 26 

 27 import jdk.internal.vm.annotation.ForceInline;
 28 import jdk.internal.vm.annotation.Stable;
 29 import java.nio.ByteOrder;
 30 import java.lang.reflect.Array;

 31 import java.util.Arrays;
 32 import java.util.function.Function;
 33 import java.util.function.IntUnaryOperator;
 34 
 35 abstract class AbstractSpecies<E> extends jdk.internal.vm.vector.VectorSupport.VectorSpecies<E>
 36                                   implements VectorSpecies<E> {
 37     @Stable
 38     final VectorShape vectorShape;
 39     @Stable
 40     final LaneType laneType;
 41     @Stable
 42     final int laneCount;
 43     @Stable
 44     final int laneCountLog2P1;
 45     @Stable
 46     final Class<? extends AbstractVector<E>> vectorType;
 47     @Stable
 48     final Class<? extends AbstractMask<E>> maskType;
 49     @Stable
 50     final Function<Object, ? extends AbstractVector<E>> vectorFactory;

186     }
187 
188     @Override
189     @ForceInline
190     public final int vectorBitSize() {
191         return vectorBitSize;
192     }
193 
194     @Override
195     @ForceInline
196     public final int vectorByteSize() {
197         return vectorByteSize;
198     }
199 
200     @Override
201     @ForceInline
202     public final int loopBound(int length) {
203         return VectorIntrinsics.roundDown(length, laneCount);
204     }
205 






206     @Override
207     @ForceInline
208     public final VectorMask<E> indexInRange(int offset, int limit) {
209         return maskAll(true).indexInRange(offset, limit);
210     }
211 






212     @Override
213     @ForceInline
214     public final <F> VectorSpecies<F> withLanes(Class<F> newType) {
215         return withLanes(LaneType.of(newType)).check(newType);
216     }
217 
218     @ForceInline
219     /*package-private*/
220     final
221     AbstractSpecies<?> withLanes(LaneType newType) {
222         if (newType == laneType)  return this;
223         return findSpecies(newType, vectorShape);
224     }
225 
226     @ForceInline
227     /*package-private*/
228     AbstractSpecies<?> asIntegral() {
229         return withLanes(laneType.asIntegral());
230     }
231 

332     public final
333     @Override
334     @ForceInline
335     VectorShuffle<E> shuffleFromOp(IntUnaryOperator fn) {
336         return dummyVector().shuffleFromOp(fn);
337     }
338 
339     public final
340     @Override
341     @ForceInline
342     VectorShuffle<E> iotaShuffle(int start, int step, boolean wrap) {
343         AbstractShuffle<E> res;
344         if (start == 0 && step == 1)
345             return dummyVector().iotaShuffle();
346         else
347             return dummyVector().iotaShuffle(start, step, wrap);
348     }
349 
350     @ForceInline
351     @Override
352     public final Vector<E> fromByteArray(byte[] a, int offset, ByteOrder bo) {
353         return dummyVector()
354             .fromByteArray0(a, offset)
355             .maybeSwap(bo);
356     }
357 
358     @Override
359     public VectorMask<E> loadMask(boolean[] bits, int offset) {
360         return VectorMask.fromArray(this, bits, offset);
361     }
362 
363     // Define zero and iota when we know the ETYPE and VSHAPE.
364     public abstract AbstractVector<E> zero();
365     /*package-private*/ abstract AbstractVector<E> iota();
366 
367     // Constructing vectors from raw bits.
368 
369     /*package-private*/
370     abstract long longToElementBits(long e);
371 
372     /*package-private*/
373     abstract AbstractVector<E> broadcastBits(long bits);
374 

  1 /*
  2  * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 package jdk.incubator.vector;
 26 
 27 import jdk.incubator.foreign.MemorySegment;
 28 import jdk.internal.vm.annotation.ForceInline;
 29 import jdk.internal.vm.annotation.Stable;

 30 import java.lang.reflect.Array;
 31 import java.nio.ByteOrder;
 32 import java.util.Arrays;
 33 import java.util.function.Function;
 34 import java.util.function.IntUnaryOperator;
 35 
 36 abstract class AbstractSpecies<E> extends jdk.internal.vm.vector.VectorSupport.VectorSpecies<E>
 37                                   implements VectorSpecies<E> {
 38     @Stable
 39     final VectorShape vectorShape;
 40     @Stable
 41     final LaneType laneType;
 42     @Stable
 43     final int laneCount;
 44     @Stable
 45     final int laneCountLog2P1;
 46     @Stable
 47     final Class<? extends AbstractVector<E>> vectorType;
 48     @Stable
 49     final Class<? extends AbstractMask<E>> maskType;
 50     @Stable
 51     final Function<Object, ? extends AbstractVector<E>> vectorFactory;

187     }
188 
189     @Override
190     @ForceInline
191     public final int vectorBitSize() {
192         return vectorBitSize;
193     }
194 
195     @Override
196     @ForceInline
197     public final int vectorByteSize() {
198         return vectorByteSize;
199     }
200 
201     @Override
202     @ForceInline
203     public final int loopBound(int length) {
204         return VectorIntrinsics.roundDown(length, laneCount);
205     }
206 
207     @Override
208     @ForceInline
209     public final long loopBound(long length) {
210         return VectorIntrinsics.roundDown(length, laneCount);
211     }
212 
213     @Override
214     @ForceInline
215     public final VectorMask<E> indexInRange(int offset, int limit) {
216         return maskAll(true).indexInRange(offset, limit);
217     }
218 
219     @Override
220     @ForceInline
221     public final VectorMask<E> indexInRange(long offset, long limit) {
222         return maskAll(true).indexInRange(offset, limit);
223     }
224 
225     @Override
226     @ForceInline
227     public final <F> VectorSpecies<F> withLanes(Class<F> newType) {
228         return withLanes(LaneType.of(newType)).check(newType);
229     }
230 
231     @ForceInline
232     /*package-private*/
233     final
234     AbstractSpecies<?> withLanes(LaneType newType) {
235         if (newType == laneType)  return this;
236         return findSpecies(newType, vectorShape);
237     }
238 
239     @ForceInline
240     /*package-private*/
241     AbstractSpecies<?> asIntegral() {
242         return withLanes(laneType.asIntegral());
243     }
244 

345     public final
346     @Override
347     @ForceInline
348     VectorShuffle<E> shuffleFromOp(IntUnaryOperator fn) {
349         return dummyVector().shuffleFromOp(fn);
350     }
351 
352     public final
353     @Override
354     @ForceInline
355     VectorShuffle<E> iotaShuffle(int start, int step, boolean wrap) {
356         AbstractShuffle<E> res;
357         if (start == 0 && step == 1)
358             return dummyVector().iotaShuffle();
359         else
360             return dummyVector().iotaShuffle(start, step, wrap);
361     }
362 
363     @ForceInline
364     @Override
365     public final Vector<E> fromMemorySegment(MemorySegment ms, long offset, ByteOrder bo) {
366         return dummyVector()
367             .fromMemorySegment0(ms, offset)
368             .maybeSwap(bo);
369     }
370 
371     @Override
372     public VectorMask<E> loadMask(boolean[] bits, int offset) {
373         return VectorMask.fromArray(this, bits, offset);
374     }
375 
376     // Define zero and iota when we know the ETYPE and VSHAPE.
377     public abstract AbstractVector<E> zero();
378     /*package-private*/ abstract AbstractVector<E> iota();
379 
380     // Constructing vectors from raw bits.
381 
382     /*package-private*/
383     abstract long longToElementBits(long e);
384 
385     /*package-private*/
386     abstract AbstractVector<E> broadcastBits(long bits);
387 
< prev index next >