< prev index next >

src/java.base/share/classes/jdk/internal/vm/vector/VectorSupport.java

Print this page

 52 
 53     public static final int VECTOR_OP_AND  = 10;
 54     public static final int VECTOR_OP_OR   = 11;
 55     public static final int VECTOR_OP_XOR  = 12;
 56 
 57     // Ternary
 58     public static final int VECTOR_OP_FMA  = 13;
 59 
 60     // Broadcast int
 61     public static final int VECTOR_OP_LSHIFT  = 14;
 62     public static final int VECTOR_OP_RSHIFT  = 15;
 63     public static final int VECTOR_OP_URSHIFT = 16;
 64 
 65     public static final int VECTOR_OP_CAST        = 17;
 66     public static final int VECTOR_OP_REINTERPRET = 18;
 67 
 68     // Mask manipulation operations
 69     public static final int VECTOR_OP_MASK_TRUECOUNT = 19;
 70     public static final int VECTOR_OP_MASK_FIRSTTRUE = 20;
 71     public static final int VECTOR_OP_MASK_LASTTRUE  = 21;

 72 
 73     // Rotate operations
 74     public static final int VECTOR_OP_LROTATE = 22;
 75     public static final int VECTOR_OP_RROTATE = 23;
 76 
 77     // Math routines
 78     public static final int VECTOR_OP_TAN = 101;
 79     public static final int VECTOR_OP_TANH = 102;
 80     public static final int VECTOR_OP_SIN = 103;
 81     public static final int VECTOR_OP_SINH = 104;
 82     public static final int VECTOR_OP_COS = 105;
 83     public static final int VECTOR_OP_COSH = 106;
 84     public static final int VECTOR_OP_ASIN = 107;
 85     public static final int VECTOR_OP_ACOS = 108;
 86     public static final int VECTOR_OP_ATAN = 109;
 87     public static final int VECTOR_OP_ATAN2 = 110;
 88     public static final int VECTOR_OP_CBRT = 111;
 89     public static final int VECTOR_OP_LOG = 112;
 90     public static final int VECTOR_OP_LOG10 = 113;
 91     public static final int VECTOR_OP_LOG1P = 114;
 92     public static final int VECTOR_OP_POW = 115;
 93     public static final int VECTOR_OP_EXP = 116;
 94     public static final int VECTOR_OP_EXPM1 = 117;
 95     public static final int VECTOR_OP_HYPOT = 118;

139     }
140 
141     public static class Vector<E> extends VectorPayload {
142         public Vector(Object payload) {
143             super(payload);
144         }
145     }
146 
147     public static class VectorShuffle<E> extends VectorPayload {
148         public VectorShuffle(Object payload) {
149             super(payload);
150         }
151     }
152     public static class VectorMask<E> extends VectorPayload {
153         public VectorMask(Object payload) {
154             super(payload);
155         }
156     }
157 
158     /* ============================================================================ */
159     public interface BroadcastOperation<VM, E, S extends VectorSpecies<E>> {

160         VM broadcast(long l, S s);
161     }
162 
163     @IntrinsicCandidate
164     public static
165     <VM, E, S extends VectorSpecies<E>>
166     VM broadcastCoerced(Class<? extends VM> vmClass, Class<E> E, int length,
167                                   long bits, S s,
168                                   BroadcastOperation<VM, E, S> defaultImpl) {



169         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
170         return defaultImpl.broadcast(bits, s);
171     }
172 
173     /* ============================================================================ */
174     public interface ShuffleIotaOperation<E, S extends VectorSpecies<E>> {
175         VectorShuffle<E> apply(int length, int start, int step, S s);

176     }
177 
178     @IntrinsicCandidate
179     public static
180     <E, S extends VectorSpecies<E>>
181     VectorShuffle<E> shuffleIota(Class<?> E, Class<?> ShuffleClass, S s, int length,
182                      int start, int step, int wrap, ShuffleIotaOperation<E, S> defaultImpl) {




183        assert isNonCapturingLambda(defaultImpl) : defaultImpl;
184        return defaultImpl.apply(length, start, step, s);
185     }
186 
187     public interface ShuffleToVectorOperation<VM, Sh, E> {
188        VM apply(Sh s);

189     }
190 
191     @IntrinsicCandidate
192     public static
193     <VM ,Sh extends VectorShuffle<E>, E>
194     VM shuffleToVector(Class<?> VM, Class<?>E , Class<?> ShuffleClass, Sh s, int length,
195                        ShuffleToVectorOperation<VM,Sh,E> defaultImpl) {



196       assert isNonCapturingLambda(defaultImpl) : defaultImpl;
197       return defaultImpl.apply(s);
198     }
199 
200     /* ============================================================================ */
201     public interface IndexOperation<V extends Vector<E>, E, S extends VectorSpecies<E>> {

202         V index(V v, int step, S s);
203     }
204 
205     //FIXME @IntrinsicCandidate
206     public static
207     <V extends Vector<E>, E, S extends VectorSpecies<E>>
208     V indexVector(Class<? extends V> vClass, Class<E> E, int length,



209                   V v, int step, S s,
210                   IndexOperation<V, E, S> defaultImpl) {
211         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
212         return defaultImpl.index(v, step, s);
213     }
214 
215     /* ============================================================================ */
216 





217     @IntrinsicCandidate
218     public static
219     <V extends Vector<?>>
220     long reductionCoerced(int oprId, Class<?> vectorClass, Class<?> elementType, int length,
221                           V v,
222                           Function<V,Long> defaultImpl) {




223         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
224         return defaultImpl.apply(v);
225     }
226 

227     /* ============================================================================ */
228 
229     public interface VecExtractOp<V> {
230         long apply(V v1, int idx);
231     }
232 
233     @IntrinsicCandidate
234     public static
235     <V extends Vector<?>>
236     long extract(Class<?> vectorClass, Class<?> elementType, int vlen,
237                  V vec, int ix,


238                  VecExtractOp<V> defaultImpl) {
239         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
240         return defaultImpl.apply(vec, ix);
241     }
242 
243     /* ============================================================================ */
244 
245     public interface VecInsertOp<V> {
246         V apply(V v1, int idx, long val);
247     }
248 
249     @IntrinsicCandidate
250     public static
251     <V extends Vector<?>>
252     V insert(Class<? extends V> vectorClass, Class<?> elementType, int vlen,
253              V vec, int ix, long val,


254              VecInsertOp<V> defaultImpl) {
255         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
256         return defaultImpl.apply(vec, ix, val);
257     }
258 
259     /* ============================================================================ */
260 





261     @IntrinsicCandidate
262     public static
263     <VM>
264     VM unaryOp(int oprId, Class<? extends VM> vmClass, Class<?> elementType, int length,
265                VM vm,
266                Function<VM, VM> defaultImpl) {




267         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
268         return defaultImpl.apply(vm);
269     }
270 
271     /* ============================================================================ */
272 





273     @IntrinsicCandidate
274     public static
275     <VM>
276     VM binaryOp(int oprId, Class<? extends VM> vmClass, Class<?> elementType, int length,
277                 VM vm1, VM vm2,
278                 BiFunction<VM, VM, VM> defaultImpl) {




279         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
280         return defaultImpl.apply(vm1, vm2);
281     }
282 
283     /* ============================================================================ */
284 
285     public interface TernaryOperation<V> {
286         V apply(V v1, V v2, V v3);

287     }
288 
289     @IntrinsicCandidate
290     public static
291     <VM>
292     VM ternaryOp(int oprId, Class<? extends VM> vmClass, Class<?> elementType, int length,
293                  VM vm1, VM vm2, VM vm3,
294                  TernaryOperation<VM> defaultImpl) {




295         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
296         return defaultImpl.apply(vm1, vm2, vm3);
297     }
298 
299     /* ============================================================================ */
300 
301     // Memory operations
302 
303     public interface LoadOperation<C, V, E, S extends VectorSpecies<E>> {
304         V load(C container, int index, S s);


305     }
306 
307     @IntrinsicCandidate
308     public static
309     <C, VM, E, S extends VectorSpecies<E>>
310     VM load(Class<? extends VM> vmClass, Class<E> E, int length,
311            Object base, long offset,    // Unsafe addressing
312            C container, int index, S s,     // Arguments for default implementation
313            LoadOperation<C, VM, E, S> defaultImpl) {




314         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
315         return defaultImpl.load(container, index, s);
316     }
317 
318     /* ============================================================================ */
319 
320     public interface LoadVectorOperationWithMap<C, V extends Vector<?>, E, S extends VectorSpecies<E>> {
321         V loadWithMap(C container, int index, int[] indexMap, int indexM, S s);



322     }
323 
324     @IntrinsicCandidate
325     public static
326     <C, V extends Vector<?>, W extends Vector<Integer>, E, S extends VectorSpecies<E>>
327     V loadWithMap(Class<?> vectorClass, Class<E> E, int length, Class<?> vectorIndexClass,
328                   Object base, long offset, // Unsafe addressing
































329                   W index_vector,
330                   C container, int index, int[] indexMap, int indexM, S s, // Arguments for default implementation
331                   LoadVectorOperationWithMap<C, V, E, S> defaultImpl) {
332         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
333         return defaultImpl.loadWithMap(container, index, indexMap, indexM, s);
334     }
335 
336     /* ============================================================================ */
337 
338     public interface StoreVectorOperation<C, V extends Vector<?>> {

339         void store(C container, int index, V v);
340     }
341 
342     @IntrinsicCandidate
343     public static
344     <C, V extends Vector<?>>
345     void store(Class<?> vectorClass, Class<?> elementType, int length,
346                Object base, long offset,    // Unsafe addressing
347                V v,
348                C container, int index,      // Arguments for default implementation

349                StoreVectorOperation<C, V> defaultImpl) {
350         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
351         defaultImpl.store(container, index, v);
352     }
353 





















354     /* ============================================================================ */
355 
356     public interface StoreVectorOperationWithMap<C, V extends Vector<?>> {
357         void storeWithMap(C container, int index, V v, int[] indexMap, int indexM);


358     }
359 
360     @IntrinsicCandidate
361     public static
362     <C, V extends Vector<?>, W extends Vector<Integer>>
363     void storeWithMap(Class<?> vectorClass, Class<?> elementType, int length, Class<?> vectorIndexClass,
364                       Object base, long offset,    // Unsafe addressing
365                       W index_vector, V v,
366                       C container, int index, int[] indexMap, int indexM, // Arguments for default implementation
367                       StoreVectorOperationWithMap<C, V> defaultImpl) {






368         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
369         defaultImpl.storeWithMap(container, index, v, indexMap, indexM);
370     }
371 
372     /* ============================================================================ */
373 
374     @IntrinsicCandidate
375     public static
376     <VM>
377     boolean test(int cond, Class<?> vmClass, Class<?> elementType, int length,
378                  VM vm1, VM vm2,
379                  BiFunction<VM, VM, Boolean> defaultImpl) {



380         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
381         return defaultImpl.apply(vm1, vm2);
382     }
383 
384     /* ============================================================================ */
385 
386     public interface VectorCompareOp<V,M> {
387         M apply(int cond, V v1, V v2);

388     }
389 
390     @IntrinsicCandidate
391     public static <V extends Vector<E>,
392                    M extends VectorMask<E>,
393                    E>
394     M compare(int cond, Class<? extends V> vectorClass, Class<M> maskClass, Class<?> elementType, int length,
395               V v1, V v2,
396               VectorCompareOp<V,M> defaultImpl) {



397         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
398         return defaultImpl.apply(cond, v1, v2);
399     }
400 
401     /* ============================================================================ */
402 
403     public interface VectorRearrangeOp<V extends Vector<E>,
404             Sh extends VectorShuffle<E>,
405             E> {
406         V apply(V v1, Sh shuffle);
407     }
408 
409     @IntrinsicCandidate
410     public static
411     <V extends Vector<E>,
412             Sh extends VectorShuffle<E>,
413             E>
414     V rearrangeOp(Class<? extends V> vectorClass, Class<Sh> shuffleClass, Class<?> elementType, int vlen,
415                   V v1, Sh sh,
416                   VectorRearrangeOp<V,Sh, E> defaultImpl) {


417         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
418         return defaultImpl.apply(v1, sh);
419     }
420 
421     /* ============================================================================ */
422 
423     public interface VectorBlendOp<V extends Vector<E>,
424             M extends VectorMask<E>,
425             E> {
426         V apply(V v1, V v2, M mask);
427     }
428 
429     @IntrinsicCandidate
430     public static
431     <V extends Vector<E>,
432      M extends VectorMask<E>,
433      E>
434     V blend(Class<? extends V> vectorClass, Class<M> maskClass, Class<?> elementType, int length,

435             V v1, V v2, M m,
436             VectorBlendOp<V,M, E> defaultImpl) {
437         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
438         return defaultImpl.apply(v1, v2, m);
439     }
440 
441     /* ============================================================================ */
442 
443     public interface VectorBroadcastIntOp<V extends Vector<?>> {
444         V apply(V v, int n);

445     }
446 
447     @IntrinsicCandidate
448     public static
449     <V extends Vector<?>>
450     V broadcastInt(int opr, Class<? extends V> vectorClass, Class<?> elementType, int length,
451                    V v, int n,
452                    VectorBroadcastIntOp<V> defaultImpl) {




453         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
454         return defaultImpl.apply(v, n);
455     }
456 
457     /* ============================================================================ */
458 
459     public interface VectorConvertOp<VOUT, VIN, S> {
460         VOUT apply(VIN v, S species);


461     }
462 
463     // Users of this intrinsic assume that it respects
464     // REGISTER_ENDIAN, which is currently ByteOrder.LITTLE_ENDIAN.
465     // See javadoc for REGISTER_ENDIAN.
466 
467     @IntrinsicCandidate
468     public static <VOUT extends VectorPayload,
469                     VIN extends VectorPayload,
470                       S extends VectorSpecies<?>>
471     VOUT convert(int oprId,
472               Class<?> fromVectorClass, Class<?> fromElementType, int fromVLen,
473               Class<?>   toVectorClass, Class<?>   toElementType, int   toVLen,
474               VIN v, S s,
475               VectorConvertOp<VOUT, VIN, S> defaultImpl) {
476         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
477         return defaultImpl.apply(v, s);
478     }
479 
480     /* ============================================================================ */
481 
482     @IntrinsicCandidate
483     public static <V> V maybeRebox(V v) {


484         // The fence is added here to avoid memory aliasing problems in C2 between scalar & vector accesses.
485         // TODO: move the fence generation into C2. Generate only when reboxing is taking place.
486         U.loadFence();
487         return v;
488     }
489 
490     /* ============================================================================ */
491     public interface VectorMaskOp<M> {
492         int apply(M m);
493     }
494 
495     @IntrinsicCandidate
496     public static
497     <E, M>
498     int maskReductionCoerced(int oper, Class<? extends M> maskClass, Class<?> elemClass, int length, M m,
499                VectorMaskOp<M> defaultImpl) {




500        assert isNonCapturingLambda(defaultImpl) : defaultImpl;
501        return defaultImpl.apply(m);
502     }
503 
504     /* ============================================================================ */
505 
506     // query the JVM's supported vector sizes and types
507     public static native int getMaxLaneCount(Class<?> etype);
508 
509     /* ============================================================================ */
510 
511     public static boolean isNonCapturingLambda(Object o) {
512         return o.getClass().getDeclaredFields().length == 0;
513     }
514 
515     /* ============================================================================ */
516 
517     private static native int registerNatives();
518 }

 52 
 53     public static final int VECTOR_OP_AND  = 10;
 54     public static final int VECTOR_OP_OR   = 11;
 55     public static final int VECTOR_OP_XOR  = 12;
 56 
 57     // Ternary
 58     public static final int VECTOR_OP_FMA  = 13;
 59 
 60     // Broadcast int
 61     public static final int VECTOR_OP_LSHIFT  = 14;
 62     public static final int VECTOR_OP_RSHIFT  = 15;
 63     public static final int VECTOR_OP_URSHIFT = 16;
 64 
 65     public static final int VECTOR_OP_CAST        = 17;
 66     public static final int VECTOR_OP_REINTERPRET = 18;
 67 
 68     // Mask manipulation operations
 69     public static final int VECTOR_OP_MASK_TRUECOUNT = 19;
 70     public static final int VECTOR_OP_MASK_FIRSTTRUE = 20;
 71     public static final int VECTOR_OP_MASK_LASTTRUE  = 21;
 72     public static final int VECTOR_OP_MASK_TOLONG    = 22;
 73 
 74     // Rotate operations
 75     public static final int VECTOR_OP_LROTATE = 23;
 76     public static final int VECTOR_OP_RROTATE = 24;
 77 
 78     // Math routines
 79     public static final int VECTOR_OP_TAN = 101;
 80     public static final int VECTOR_OP_TANH = 102;
 81     public static final int VECTOR_OP_SIN = 103;
 82     public static final int VECTOR_OP_SINH = 104;
 83     public static final int VECTOR_OP_COS = 105;
 84     public static final int VECTOR_OP_COSH = 106;
 85     public static final int VECTOR_OP_ASIN = 107;
 86     public static final int VECTOR_OP_ACOS = 108;
 87     public static final int VECTOR_OP_ATAN = 109;
 88     public static final int VECTOR_OP_ATAN2 = 110;
 89     public static final int VECTOR_OP_CBRT = 111;
 90     public static final int VECTOR_OP_LOG = 112;
 91     public static final int VECTOR_OP_LOG10 = 113;
 92     public static final int VECTOR_OP_LOG1P = 114;
 93     public static final int VECTOR_OP_POW = 115;
 94     public static final int VECTOR_OP_EXP = 116;
 95     public static final int VECTOR_OP_EXPM1 = 117;
 96     public static final int VECTOR_OP_HYPOT = 118;

140     }
141 
142     public static class Vector<E> extends VectorPayload {
143         public Vector(Object payload) {
144             super(payload);
145         }
146     }
147 
148     public static class VectorShuffle<E> extends VectorPayload {
149         public VectorShuffle(Object payload) {
150             super(payload);
151         }
152     }
153     public static class VectorMask<E> extends VectorPayload {
154         public VectorMask(Object payload) {
155             super(payload);
156         }
157     }
158 
159     /* ============================================================================ */
160     public interface BroadcastOperation<VM extends VectorPayload,
161                                         S extends VectorSpecies<?>> {
162         VM broadcast(long l, S s);
163     }
164 
165     @IntrinsicCandidate
166     public static
167     <VM extends VectorPayload,
168      S extends VectorSpecies<E>,
169      E>
170     VM broadcastCoerced(Class<? extends VM> vmClass, Class<E> eClass,
171                         int length,
172                         long bits, S s,
173                         BroadcastOperation<VM, S> defaultImpl) {
174         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
175         return defaultImpl.broadcast(bits, s);
176     }
177 
178     /* ============================================================================ */
179     public interface ShuffleIotaOperation<S extends VectorSpecies<?>,
180                                           SH extends VectorShuffle<?>> {
181         SH apply(int length, int start, int step, S s);
182     }
183 
184     @IntrinsicCandidate
185     public static
186     <E,
187      S extends VectorSpecies<E>,
188      SH extends VectorShuffle<E>>
189     SH shuffleIota(Class<E> eClass, Class<? extends SH> shClass, S s,
190                    int length,
191                    int start, int step, int wrap,
192                    ShuffleIotaOperation<S, SH> defaultImpl) {
193        assert isNonCapturingLambda(defaultImpl) : defaultImpl;
194        return defaultImpl.apply(length, start, step, s);
195     }
196 
197     public interface ShuffleToVectorOperation<V extends Vector<?>,
198                                               SH extends VectorShuffle<?>> {
199        V apply(SH sh);
200     }
201 
202     @IntrinsicCandidate
203     public static
204     <V extends Vector<E>,
205      SH extends VectorShuffle<E>,
206      E>
207     V shuffleToVector(Class<? extends Vector<E>> vClass, Class<E> eClass, Class<? extends SH> shClass, SH sh,
208                       int length,
209                       ShuffleToVectorOperation<V, SH> defaultImpl) {
210       assert isNonCapturingLambda(defaultImpl) : defaultImpl;
211       return defaultImpl.apply(sh);
212     }
213 
214     /* ============================================================================ */
215     public interface IndexOperation<V extends Vector<?>,
216                                     S extends VectorSpecies<?>> {
217         V index(V v, int step, S s);
218     }
219 
220     //FIXME @IntrinsicCandidate
221     public static
222     <V extends Vector<E>,
223      E,
224      S extends VectorSpecies<E>>
225     V indexVector(Class<? extends V> vClass, Class<E> eClass,
226                   int length,
227                   V v, int step, S s,
228                   IndexOperation<V, S> defaultImpl) {
229         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
230         return defaultImpl.index(v, step, s);
231     }
232 
233     /* ============================================================================ */
234 
235     public interface ReductionOperation<V extends Vector<?>,
236                                         M extends VectorMask<?>> {
237         long apply(V v, M m);
238     }
239 
240     @IntrinsicCandidate
241     public static
242     <V extends Vector<E>,
243      M extends VectorMask<E>,
244      E>
245     long reductionCoerced(int oprId,
246                           Class<? extends V> vClass, Class<? extends M> mClass, Class<E> eClass,
247                           int length,
248                           V v, M m,
249                           ReductionOperation<V, M> defaultImpl) {
250         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
251         return defaultImpl.apply(v, m);
252     }
253 
254 
255     /* ============================================================================ */
256 
257     public interface VecExtractOp<V extends Vector<?>> {
258         long apply(V v, int i);
259     }
260 
261     @IntrinsicCandidate
262     public static
263     <V extends Vector<E>,
264      E>
265     long extract(Class<? extends V> vClass, Class<E> eClass,
266                  int length,
267                  V v, int i,
268                  VecExtractOp<V> defaultImpl) {
269         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
270         return defaultImpl.apply(v, i);
271     }
272 
273     /* ============================================================================ */
274 
275     public interface VecInsertOp<V extends Vector<?>> {
276         V apply(V v, int i, long val);
277     }
278 
279     @IntrinsicCandidate
280     public static
281     <V extends Vector<E>,
282      E>
283     V insert(Class<? extends V> vClass, Class<E> eClass,
284              int length,
285              V v, int i, long val,
286              VecInsertOp<V> defaultImpl) {
287         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
288         return defaultImpl.apply(v, i, val);
289     }
290 
291     /* ============================================================================ */
292 
293     public interface UnaryOperation<V extends Vector<?>,
294                                     M extends VectorMask<?>> {
295         V apply(V v, M m);
296     }
297 
298     @IntrinsicCandidate
299     public static
300     <V extends Vector<E>,
301      M extends VectorMask<E>,
302      E>
303     V unaryOp(int oprId,
304               Class<? extends V> vClass, Class<? extends M> mClass, Class<E> eClass,
305               int length,
306               V v, M m,
307               UnaryOperation<V, M> defaultImpl) {
308         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
309         return defaultImpl.apply(v, m);
310     }
311 
312     /* ============================================================================ */
313 
314     public interface BinaryOperation<VM extends VectorPayload,
315                                      M extends VectorMask<?>> {
316         VM apply(VM v1, VM v2, M m);
317     }
318 
319     @IntrinsicCandidate
320     public static
321     <VM extends VectorPayload,
322      M extends VectorMask<E>,
323      E>
324     VM binaryOp(int oprId,
325                 Class<? extends VM> vmClass, Class<? extends M> mClass, Class<E> eClass,
326                 int length,
327                 VM v1, VM v2, M m,
328                 BinaryOperation<VM, M> defaultImpl) {
329         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
330         return defaultImpl.apply(v1, v2, m);
331     }
332 
333     /* ============================================================================ */
334 
335     public interface TernaryOperation<V extends Vector<?>,
336                                       M extends VectorMask<?>> {
337         V apply(V v1, V v2, V v3, M m);
338     }
339 
340     @IntrinsicCandidate
341     public static
342     <V extends Vector<E>,
343      M extends VectorMask<E>,
344      E>
345     V ternaryOp(int oprId,
346                 Class<? extends V> vClass, Class<? extends M> mClass, Class<E> eClass,
347                 int length,
348                 V v1, V v2, V v3, M m,
349                 TernaryOperation<V, M> defaultImpl) {
350         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
351         return defaultImpl.apply(v1, v2, v3, m);
352     }
353 
354     /* ============================================================================ */
355 
356     // Memory operations
357 
358     public interface LoadOperation<C,
359                                    VM extends VectorPayload,
360                                    S extends VectorSpecies<?>> {
361         VM load(C container, int index, S s);
362     }
363 
364     @IntrinsicCandidate
365     public static
366     <C,
367      VM extends VectorPayload,
368      E,
369      S extends VectorSpecies<E>>
370     VM load(Class<? extends VM> vmClass, Class<E> eClass,
371             int length,
372             Object base, long offset,
373             C container, int index, S s,
374             LoadOperation<C, VM, S> defaultImpl) {
375         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
376         return defaultImpl.load(container, index, s);
377     }
378 
379     /* ============================================================================ */
380 
381     public interface LoadVectorMaskedOperation<C,
382                                                V extends Vector<?>,
383                                                S extends VectorSpecies<?>,
384                                                M extends VectorMask<?>> {
385         V load(C container, int index, S s, M m);
386     }
387 
388     @IntrinsicCandidate
389     public static
390     <C,
391      V extends Vector<?>,
392      E,
393      S extends VectorSpecies<E>,
394      M extends VectorMask<E>>
395     V loadMasked(Class<? extends V> vClass, Class<M> mClass, Class<E> eClass,
396                  int length,
397                  Object base, long offset,
398                  M m, C container, int index, S s,
399                  LoadVectorMaskedOperation<C, V, S, M> defaultImpl) {
400         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
401         return defaultImpl.load(container, index, s, m);
402     }
403 
404     /* ============================================================================ */
405 
406     public interface LoadVectorOperationWithMap<C,
407                                                 V extends Vector<?>,
408                                                 S extends VectorSpecies<?>,
409                                                 M extends VectorMask<?>> {
410         V loadWithMap(C container, int index, int[] indexMap, int indexM, S s, M m);
411     }
412 
413     @IntrinsicCandidate
414     public static
415     <C,
416      V extends Vector<?>,
417      W extends Vector<Integer>,
418      S extends VectorSpecies<E>,
419      M extends VectorMask<E>,
420      E>
421     V loadWithMap(Class<? extends V> vClass, Class<M> mClass, Class<E> eClass,
422                   int length,
423                   Class<? extends Vector<Integer>> vectorIndexClass,
424                   Object base, long offset,
425                   W index_vector,
426                   M m, C container, int index, int[] indexMap, int indexM, S s,
427                   LoadVectorOperationWithMap<C, V, S, M> defaultImpl) {
428         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
429         return defaultImpl.loadWithMap(container, index, indexMap, indexM, s, m);
430     }
431 
432     /* ============================================================================ */
433 
434     public interface StoreVectorOperation<C,
435                                           V extends Vector<?>> {
436         void store(C container, int index, V v);
437     }
438 
439     @IntrinsicCandidate
440     public static
441     <C,
442      V extends Vector<?>>
443     void store(Class<?> vClass, Class<?> eClass,
444                int length,
445                Object base, long offset,
446                V v, C container, int index,
447                StoreVectorOperation<C, V> defaultImpl) {
448         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
449         defaultImpl.store(container, index, v);
450     }
451 
452     public interface StoreVectorMaskedOperation<C,
453                                                 V extends Vector<?>,
454                                                 M extends VectorMask<?>> {
455         void store(C container, int index, V v, M m);
456     }
457 
458     @IntrinsicCandidate
459     public static
460     <C,
461      V extends Vector<E>,
462      M extends VectorMask<E>,
463      E>
464     void storeMasked(Class<? extends V> vClass, Class<M> mClass, Class<E> eClass,
465                      int length,
466                      Object base, long offset,
467                      V v, M m, C container, int index,
468                      StoreVectorMaskedOperation<C, V, M> defaultImpl) {
469         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
470         defaultImpl.store(container, index, v, m);
471     }
472 
473     /* ============================================================================ */
474 
475     public interface StoreVectorOperationWithMap<C,
476                                                  V extends Vector<?>,
477                                                  M extends VectorMask<?>> {
478         void storeWithMap(C container, int index, V v, int[] indexMap, int indexM, M m);
479     }
480 
481     @IntrinsicCandidate
482     public static
483     <C,
484      V extends Vector<E>,
485      W extends Vector<Integer>,
486      M extends VectorMask<E>,
487      E>
488     void storeWithMap(Class<? extends V> vClass, Class<M> mClass, Class<E> eClass,
489                       int length,
490                       Class<? extends Vector<Integer>> vectorIndexClass,
491                       Object base, long offset,
492                       W index_vector,
493                       V v, M m, C container, int index, int[] indexMap, int indexM,
494                       StoreVectorOperationWithMap<C, V, M> defaultImpl) {
495         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
496         defaultImpl.storeWithMap(container, index, v, indexMap, indexM, m);
497     }
498 
499     /* ============================================================================ */
500 
501     @IntrinsicCandidate
502     public static
503     <M extends VectorMask<E>,
504      E>
505     boolean test(int cond,
506                  Class<?> mClass, Class<?> eClass,
507                  int length,
508                  M m1, M m2,
509                  BiFunction<M, M, Boolean> defaultImpl) {
510         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
511         return defaultImpl.apply(m1, m2);
512     }
513 
514     /* ============================================================================ */
515 
516     public interface VectorCompareOp<V extends Vector<?>,
517                                      M extends VectorMask<?>> {
518         M apply(int cond, V v1, V v2, M m);
519     }
520 
521     @IntrinsicCandidate
522     public static
523     <V extends Vector<E>,
524      M extends VectorMask<E>,
525      E>
526     M compare(int cond,
527               Class<? extends V> vectorClass, Class<M> mClass, Class<E> eClass,
528               int length,
529               V v1, V v2, M m,
530               VectorCompareOp<V, M> defaultImpl) {
531         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
532         return defaultImpl.apply(cond, v1, v2, m);
533     }
534 
535     /* ============================================================================ */
536     public interface VectorRearrangeOp<V extends Vector<?>,
537                                        SH extends VectorShuffle<?>,
538                                        M extends VectorMask<?>> {
539         V apply(V v, SH sh, M m);

540     }
541 
542     @IntrinsicCandidate
543     public static
544     <V extends Vector<E>,
545      SH extends VectorShuffle<E>,
546      M  extends VectorMask<E>,
547      E>
548     V rearrangeOp(Class<? extends V> vClass, Class<SH> shClass, Class<M> mClass, Class<E> eClass,
549                   int length,
550                   V v, SH sh, M m,
551                   VectorRearrangeOp<V, SH, M> defaultImpl) {
552         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
553         return defaultImpl.apply(v, sh, m);
554     }
555 
556     /* ============================================================================ */
557 
558     public interface VectorBlendOp<V extends Vector<?>,
559                                    M extends VectorMask<?>> {
560         V apply(V v1, V v2, M m);

561     }
562 
563     @IntrinsicCandidate
564     public static
565     <V extends Vector<E>,
566      M extends VectorMask<E>,
567      E>
568     V blend(Class<? extends V> vClass, Class<M> mClass, Class<E> eClass,
569             int length,
570             V v1, V v2, M m,
571             VectorBlendOp<V, M> defaultImpl) {
572         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
573         return defaultImpl.apply(v1, v2, m);
574     }
575 
576     /* ============================================================================ */
577 
578     public interface VectorBroadcastIntOp<V extends Vector<?>,
579                                           M extends VectorMask<?>> {
580         V apply(V v, int n, M m);
581     }
582 
583     @IntrinsicCandidate
584     public static
585     <V extends Vector<E>,
586      M extends VectorMask<E>,
587      E>
588     V broadcastInt(int opr,
589                    Class<? extends V> vClass, Class<? extends M> mClass, Class<E> eClass,
590                    int length,
591                    V v, int n, M m,
592                    VectorBroadcastIntOp<V, M> defaultImpl) {
593         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
594         return defaultImpl.apply(v, n, m);
595     }
596 
597     /* ============================================================================ */
598 
599     public interface VectorConvertOp<VOUT extends VectorPayload,
600                                      VIN extends VectorPayload,
601                                      S extends VectorSpecies<?>> {
602         VOUT apply(VIN v, S s);
603     }
604 
605     // Users of this intrinsic assume that it respects
606     // REGISTER_ENDIAN, which is currently ByteOrder.LITTLE_ENDIAN.
607     // See javadoc for REGISTER_ENDIAN.
608 
609     @IntrinsicCandidate
610     public static <VOUT extends VectorPayload,
611                     VIN extends VectorPayload,
612                       S extends VectorSpecies<?>>
613     VOUT convert(int oprId,
614               Class<?> fromVectorClass, Class<?> fromeClass, int fromVLen,
615               Class<?>   toVectorClass, Class<?>   toeClass, int   toVLen,
616               VIN v, S s,
617               VectorConvertOp<VOUT, VIN, S> defaultImpl) {
618         assert isNonCapturingLambda(defaultImpl) : defaultImpl;
619         return defaultImpl.apply(v, s);
620     }
621 
622     /* ============================================================================ */
623 
624     @IntrinsicCandidate
625     public static
626     <VP extends VectorPayload>
627     VP maybeRebox(VP v) {
628         // The fence is added here to avoid memory aliasing problems in C2 between scalar & vector accesses.
629         // TODO: move the fence generation into C2. Generate only when reboxing is taking place.
630         U.loadFence();
631         return v;
632     }
633 
634     /* ============================================================================ */
635     public interface VectorMaskOp<M extends VectorMask<?>> {
636         long apply(M m);
637     }
638 
639     @IntrinsicCandidate
640     public static
641     <M extends VectorMask<E>,
642      E>
643     long maskReductionCoerced(int oper,
644                               Class<? extends M> mClass, Class<?> eClass,
645                               int length,
646                               M m,
647                               VectorMaskOp<M> defaultImpl) {
648        assert isNonCapturingLambda(defaultImpl) : defaultImpl;
649        return defaultImpl.apply(m);
650     }
651 
652     /* ============================================================================ */
653 
654     // query the JVM's supported vector sizes and types
655     public static native int getMaxLaneCount(Class<?> etype);
656 
657     /* ============================================================================ */
658 
659     public static boolean isNonCapturingLambda(Object o) {
660         return o.getClass().getDeclaredFields().length == 0;
661     }
662 
663     /* ============================================================================ */
664 
665     private static native int registerNatives();
666 }
< prev index next >