< prev index next >

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

Print this page

 37             throw requireLengthFailed(haveLength, length);
 38         }
 39     }
 40     static IllegalArgumentException requireLengthFailed(int haveLength, int length) {
 41         String msg = String.format("Length check failed: "+
 42                                    "length %d should have been %s",
 43                                    haveLength, length);
 44         return new IllegalArgumentException(msg);
 45     }
 46 
 47     @ForceInline
 48     static int checkFromIndexSize(int ix, int vlen, int length) {
 49         switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
 50             case 0: return ix; // no range check
 51             case 1: return Objects.checkFromIndexSize(ix, vlen, length);
 52             case 2: return Objects.checkIndex(ix, length - (vlen - 1));
 53             default: throw new InternalError();
 54         }
 55     }
 56 










 57     @ForceInline
 58     static IntVector checkIndex(IntVector vix, int length) {
 59         switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
 60             case 0: return vix; // no range check
 61             case 1: // fall-through
 62             case 2:
 63                 if (vix.compare(VectorOperators.LT, 0)
 64                     .or(vix.compare(VectorOperators.GE, length))
 65                     .anyTrue()) {
 66                     throw checkIndexFailed(vix, length);
 67                 }
 68                 return vix;
 69             default: throw new InternalError();
 70         }
 71     }
 72 
 73     private static
 74     IndexOutOfBoundsException checkIndexFailed(IntVector vix, int length) {
 75         String msg = String.format("Range check failed: vector %s out of bounds for length %d", vix, length);
 76         return new IndexOutOfBoundsException(msg);
 77     }
 78 
 79     // If the index is not already a multiple of size,
 80     // round it down to the next smaller multiple of size.
 81     // It is an error if size is less than zero.
 82     @ForceInline
 83     static int roundDown(int index, int size) {
 84         if ((size & (size - 1)) == 0) {
 85             // Size is zero or a power of two, so we got this.
 86             return index & ~(size - 1);
 87         } else {
 88             return roundDownNPOT(index, size);
 89         }
 90     }
 91     private static int roundDownNPOT(int index, int size) {
 92         if (index >= 0) {
 93             return index - (index % size);
 94         } else {
 95             return index - Math.floorMod(index, Math.abs(size));
 96         }
 97     }





















 98     @ForceInline
 99     static int wrapToRange(int index, int size) {
100         if ((size & (size - 1)) == 0) {
101             // Size is zero or a power of two, so we got this.
102             return index & (size - 1);
103         } else {
104             return wrapToRangeNPOT(index, size);
105         }
106     }
107     private static int wrapToRangeNPOT(int index, int size) {
108         if (index >= 0) {
109             return (index % size);
110         } else {
111             return Math.floorMod(index, Math.abs(size));
112         }
113     }
114 }

 37             throw requireLengthFailed(haveLength, length);
 38         }
 39     }
 40     static IllegalArgumentException requireLengthFailed(int haveLength, int length) {
 41         String msg = String.format("Length check failed: "+
 42                                    "length %d should have been %s",
 43                                    haveLength, length);
 44         return new IllegalArgumentException(msg);
 45     }
 46 
 47     @ForceInline
 48     static int checkFromIndexSize(int ix, int vlen, int length) {
 49         switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
 50             case 0: return ix; // no range check
 51             case 1: return Objects.checkFromIndexSize(ix, vlen, length);
 52             case 2: return Objects.checkIndex(ix, length - (vlen - 1));
 53             default: throw new InternalError();
 54         }
 55     }
 56 
 57     @ForceInline
 58     static long checkFromIndexSize(long ix, long vlen, long length) {
 59         switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
 60             case 0: return ix; // no range check
 61             case 1: return Objects.checkFromIndexSize(ix, vlen, length);
 62             case 2: return Objects.checkIndex(ix, length - (vlen - 1));
 63             default: throw new InternalError();
 64         }
 65     }
 66 
 67     @ForceInline
 68     static IntVector checkIndex(IntVector vix, int length) {
 69         switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
 70             case 0: return vix; // no range check
 71             case 1: // fall-through
 72             case 2:
 73                 if (vix.compare(VectorOperators.LT, 0)
 74                     .or(vix.compare(VectorOperators.GE, length))
 75                     .anyTrue()) {
 76                     throw checkIndexFailed(vix, length);
 77                 }
 78                 return vix;
 79             default: throw new InternalError();
 80         }
 81     }
 82 
 83     private static
 84     IndexOutOfBoundsException checkIndexFailed(IntVector vix, int length) {
 85         String msg = String.format("Range check failed: vector %s out of bounds for length %d", vix, length);
 86         return new IndexOutOfBoundsException(msg);
 87     }
 88 
 89     // If the index is not already a multiple of size,
 90     // round it down to the next smaller multiple of size.
 91     // It is an error if size is less than zero.
 92     @ForceInline
 93     static int roundDown(int index, int size) {
 94         if ((size & (size - 1)) == 0) {
 95             // Size is zero or a power of two, so we got this.
 96             return index & ~(size - 1);
 97         } else {
 98             return roundDownNPOT(index, size);
 99         }
100     }
101     private static int roundDownNPOT(int index, int size) {
102         if (index >= 0) {
103             return index - (index % size);
104         } else {
105             return index - Math.floorMod(index, size);
106         }
107     }
108 
109     // If the index is not already a multiple of size,
110     // round it down to the next smaller multiple of size.
111     // It is an error if size is less than zero.
112     @ForceInline
113     static long roundDown(long index, int size) {
114         if ((size & (size - 1)) == 0) {
115             // Size is zero or a power of two, so we got this.
116             return index & ~(size - 1);
117         } else {
118             return roundDownNPOT(index, size);
119         }
120     }
121     private static long roundDownNPOT(long index, int size) {
122         if (index >= 0) {
123             return index - (index % size);
124         } else {
125             return index - Math.floorMod(index, size);
126         }
127     }
128 
129     @ForceInline
130     static int wrapToRange(int index, int size) {
131         if ((size & (size - 1)) == 0) {
132             // Size is zero or a power of two, so we got this.
133             return index & (size - 1);
134         } else {
135             return wrapToRangeNPOT(index, size);
136         }
137     }
138     private static int wrapToRangeNPOT(int index, int size) {
139         if (index >= 0) {
140             return (index % size);
141         } else {
142             return Math.floorMod(index, Math.abs(size));
143         }
144     }
145 }
< prev index next >