72 // coded with portable definitions.
73 // These are all @ForceInline in case
74 // they need to be used performantly.
75 // The various shape-specific subclasses
76 // also specialize them by wrapping
77 // them in a call like this:
78 // return (Byte128Vector)
79 // super.bOp((Byte128Vector) o);
80 // The purpose of that is to forcibly inline
81 // the generic definition from this file
82 // into a sharply type- and size-specific
83 // wrapper in the subclass file, so that
84 // the JIT can specialize the code.
85 // The code is only inlined and expanded
86 // if it gets hot. Think of it as a cheap
87 // and lazy version of C++ templates.
88
89 // Virtualized getter
90
91 /*package-private*/
92 abstract short[] getElements();
93
94 // Virtualized constructors
95
96 /**
97 * Build a vector directly using my own constructor.
98 * It is an error if the array is aliased elsewhere.
99 */
100 /*package-private*/
101 abstract ShortVector vectorFactory(short[] vec);
102
103 /**
104 * Build a mask directly using my species.
105 * It is an error if the array is aliased elsewhere.
106 */
107 /*package-private*/
108 @ForceInline
109 final
110 AbstractMask<Short> maskFactory(boolean[] bits) {
111 return vspecies().maskFactory(bits);
112 }
136 if (mbits[i]) {
137 res[i] = f.apply(i);
138 }
139 }
140 return vectorFactory(res);
141 }
142
143 // Unary operator
144
145 /*package-private*/
146 interface FUnOp {
147 short apply(int i, short a);
148 }
149
150 /*package-private*/
151 abstract
152 ShortVector uOp(FUnOp f);
153 @ForceInline
154 final
155 ShortVector uOpTemplate(FUnOp f) {
156 short[] vec = getElements();
157 short[] res = new short[length()];
158 for (int i = 0; i < res.length; i++) {
159 res[i] = f.apply(i, vec[i]);
160 }
161 return vectorFactory(res);
162 }
163
164 /*package-private*/
165 abstract
166 ShortVector uOp(VectorMask<Short> m,
167 FUnOp f);
168 @ForceInline
169 final
170 ShortVector uOpTemplate(VectorMask<Short> m,
171 FUnOp f) {
172 short[] vec = getElements();
173 short[] res = new short[length()];
174 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
175 for (int i = 0; i < res.length; i++) {
176 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
177 }
178 return vectorFactory(res);
179 }
180
181 // Binary operator
182
183 /*package-private*/
184 interface FBinOp {
185 short apply(int i, short a, short b);
186 }
187
188 /*package-private*/
189 abstract
190 ShortVector bOp(Vector<Short> o,
191 FBinOp f);
192 @ForceInline
193 final
194 ShortVector bOpTemplate(Vector<Short> o,
195 FBinOp f) {
196 short[] res = new short[length()];
197 short[] vec1 = this.getElements();
198 short[] vec2 = ((ShortVector)o).getElements();
199 for (int i = 0; i < res.length; i++) {
200 res[i] = f.apply(i, vec1[i], vec2[i]);
201 }
202 return vectorFactory(res);
203 }
204
205 /*package-private*/
206 abstract
207 ShortVector bOp(Vector<Short> o,
208 VectorMask<Short> m,
209 FBinOp f);
210 @ForceInline
211 final
212 ShortVector bOpTemplate(Vector<Short> o,
213 VectorMask<Short> m,
214 FBinOp f) {
215 short[] res = new short[length()];
216 short[] vec1 = this.getElements();
217 short[] vec2 = ((ShortVector)o).getElements();
218 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
219 for (int i = 0; i < res.length; i++) {
220 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
221 }
222 return vectorFactory(res);
223 }
224
225 // Ternary operator
226
227 /*package-private*/
228 interface FTriOp {
229 short apply(int i, short a, short b, short c);
230 }
231
232 /*package-private*/
233 abstract
234 ShortVector tOp(Vector<Short> o1,
235 Vector<Short> o2,
236 FTriOp f);
237 @ForceInline
238 final
239 ShortVector tOpTemplate(Vector<Short> o1,
240 Vector<Short> o2,
241 FTriOp f) {
242 short[] res = new short[length()];
243 short[] vec1 = this.getElements();
244 short[] vec2 = ((ShortVector)o1).getElements();
245 short[] vec3 = ((ShortVector)o2).getElements();
246 for (int i = 0; i < res.length; i++) {
247 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
248 }
249 return vectorFactory(res);
250 }
251
252 /*package-private*/
253 abstract
254 ShortVector tOp(Vector<Short> o1,
255 Vector<Short> o2,
256 VectorMask<Short> m,
257 FTriOp f);
258 @ForceInline
259 final
260 ShortVector tOpTemplate(Vector<Short> o1,
261 Vector<Short> o2,
262 VectorMask<Short> m,
263 FTriOp f) {
264 short[] res = new short[length()];
265 short[] vec1 = this.getElements();
266 short[] vec2 = ((ShortVector)o1).getElements();
267 short[] vec3 = ((ShortVector)o2).getElements();
268 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
269 for (int i = 0; i < res.length; i++) {
270 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
271 }
272 return vectorFactory(res);
273 }
274
275 // Reduction operator
276
277 /*package-private*/
278 abstract
279 short rOp(short v, FBinOp f);
280 @ForceInline
281 final
282 short rOpTemplate(short v, FBinOp f) {
283 short[] vec = getElements();
284 for (int i = 0; i < vec.length; i++) {
285 v = f.apply(i, v, vec[i]);
286 }
287 return v;
288 }
289
290 // Memory reference
291
292 /*package-private*/
293 interface FLdOp<M> {
294 short apply(M memory, int offset, int i);
295 }
296
297 /*package-private*/
298 @ForceInline
299 final
300 <M> ShortVector ldOp(M memory, int offset,
301 FLdOp<M> f) {
302 //dummy; no vec = getElements();
303 short[] res = new short[length()];
304 for (int i = 0; i < res.length; i++) {
305 res[i] = f.apply(memory, offset, i);
306 }
307 return vectorFactory(res);
308 }
309
310 /*package-private*/
311 @ForceInline
312 final
313 <M> ShortVector ldOp(M memory, int offset,
314 VectorMask<Short> m,
315 FLdOp<M> f) {
316 //short[] vec = getElements();
317 short[] res = new short[length()];
318 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
319 for (int i = 0; i < res.length; i++) {
320 if (mbits[i]) {
321 res[i] = f.apply(memory, offset, i);
322 }
323 }
324 return vectorFactory(res);
325 }
326
327 interface FStOp<M> {
328 void apply(M memory, int offset, int i, short a);
329 }
330
331 /*package-private*/
332 @ForceInline
333 final
334 <M> void stOp(M memory, int offset,
335 FStOp<M> f) {
336 short[] vec = getElements();
337 for (int i = 0; i < vec.length; i++) {
338 f.apply(memory, offset, i, vec[i]);
339 }
340 }
341
342 /*package-private*/
343 @ForceInline
344 final
345 <M> void stOp(M memory, int offset,
346 VectorMask<Short> m,
347 FStOp<M> f) {
348 short[] vec = getElements();
349 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
350 for (int i = 0; i < vec.length; i++) {
351 if (mbits[i]) {
352 f.apply(memory, offset, i, vec[i]);
353 }
354 }
355 }
356
357 // Binary test
358
359 /*package-private*/
360 interface FBinTest {
361 boolean apply(int cond, int i, short a, short b);
362 }
363
364 /*package-private*/
365 @ForceInline
366 final
367 AbstractMask<Short> bTest(int cond,
368 Vector<Short> o,
369 FBinTest f) {
370 short[] vec1 = getElements();
371 short[] vec2 = ((ShortVector)o).getElements();
372 boolean[] bits = new boolean[length()];
373 for (int i = 0; i < length(); i++){
374 bits[i] = f.apply(cond, i, vec1[i], vec2[i]);
375 }
376 return maskFactory(bits);
377 }
378
379 /*package-private*/
380 @ForceInline
381 static boolean doBinTest(int cond, short a, short b) {
382 switch (cond) {
383 case BT_eq: return a == b;
384 case BT_ne: return a != b;
385 case BT_lt: return a < b;
386 case BT_le: return a <= b;
387 case BT_gt: return a > b;
388 case BT_ge: return a >= b;
389 }
390 throw new AssertionError(Integer.toHexString(cond));
391 }
2030 */
2031 @ForceInline
2032 public final ShortVector blend(long e,
2033 VectorMask<Short> m) {
2034 return blend(broadcast(e), m);
2035 }
2036
2037 /**
2038 * {@inheritDoc} <!--workaround-->
2039 */
2040 @Override
2041 public abstract
2042 ShortVector slice(int origin, Vector<Short> v1);
2043
2044 /*package-private*/
2045 final
2046 @ForceInline
2047 ShortVector sliceTemplate(int origin, Vector<Short> v1) {
2048 ShortVector that = (ShortVector) v1;
2049 that.check(this);
2050 short[] a0 = this.getElements();
2051 short[] a1 = that.getElements();
2052 short[] res = new short[a0.length];
2053 int vlen = res.length;
2054 int firstPart = vlen - origin;
2055 System.arraycopy(a0, origin, res, 0, firstPart);
2056 System.arraycopy(a1, 0, res, firstPart, origin);
2057 return vectorFactory(res);
2058 }
2059
2060 /**
2061 * {@inheritDoc} <!--workaround-->
2062 */
2063 @Override
2064 @ForceInline
2065 public final
2066 ShortVector slice(int origin,
2067 Vector<Short> w,
2068 VectorMask<Short> m) {
2069 return broadcast(0).blend(slice(origin, w), m);
2070 }
2071
2073 * {@inheritDoc} <!--workaround-->
2074 */
2075 @Override
2076 public abstract
2077 ShortVector slice(int origin);
2078
2079 /**
2080 * {@inheritDoc} <!--workaround-->
2081 */
2082 @Override
2083 public abstract
2084 ShortVector unslice(int origin, Vector<Short> w, int part);
2085
2086 /*package-private*/
2087 final
2088 @ForceInline
2089 ShortVector
2090 unsliceTemplate(int origin, Vector<Short> w, int part) {
2091 ShortVector that = (ShortVector) w;
2092 that.check(this);
2093 short[] slice = this.getElements();
2094 short[] res = that.getElements();
2095 int vlen = res.length;
2096 int firstPart = vlen - origin;
2097 switch (part) {
2098 case 0:
2099 System.arraycopy(slice, 0, res, origin, firstPart);
2100 break;
2101 case 1:
2102 System.arraycopy(slice, firstPart, res, 0, origin);
2103 break;
2104 default:
2105 throw wrongPartForSlice(part);
2106 }
2107 return vectorFactory(res);
2108 }
2109
2110 /*package-private*/
2111 final
2112 @ForceInline
2113 <M extends VectorMask<Short>>
2114 ShortVector
|
72 // coded with portable definitions.
73 // These are all @ForceInline in case
74 // they need to be used performantly.
75 // The various shape-specific subclasses
76 // also specialize them by wrapping
77 // them in a call like this:
78 // return (Byte128Vector)
79 // super.bOp((Byte128Vector) o);
80 // The purpose of that is to forcibly inline
81 // the generic definition from this file
82 // into a sharply type- and size-specific
83 // wrapper in the subclass file, so that
84 // the JIT can specialize the code.
85 // The code is only inlined and expanded
86 // if it gets hot. Think of it as a cheap
87 // and lazy version of C++ templates.
88
89 // Virtualized getter
90
91 /*package-private*/
92 abstract short[] vec();
93
94 // Virtualized constructors
95
96 /**
97 * Build a vector directly using my own constructor.
98 * It is an error if the array is aliased elsewhere.
99 */
100 /*package-private*/
101 abstract ShortVector vectorFactory(short[] vec);
102
103 /**
104 * Build a mask directly using my species.
105 * It is an error if the array is aliased elsewhere.
106 */
107 /*package-private*/
108 @ForceInline
109 final
110 AbstractMask<Short> maskFactory(boolean[] bits) {
111 return vspecies().maskFactory(bits);
112 }
136 if (mbits[i]) {
137 res[i] = f.apply(i);
138 }
139 }
140 return vectorFactory(res);
141 }
142
143 // Unary operator
144
145 /*package-private*/
146 interface FUnOp {
147 short apply(int i, short a);
148 }
149
150 /*package-private*/
151 abstract
152 ShortVector uOp(FUnOp f);
153 @ForceInline
154 final
155 ShortVector uOpTemplate(FUnOp f) {
156 short[] vec = vec();
157 short[] res = new short[length()];
158 for (int i = 0; i < res.length; i++) {
159 res[i] = f.apply(i, vec[i]);
160 }
161 return vectorFactory(res);
162 }
163
164 /*package-private*/
165 abstract
166 ShortVector uOp(VectorMask<Short> m,
167 FUnOp f);
168 @ForceInline
169 final
170 ShortVector uOpTemplate(VectorMask<Short> m,
171 FUnOp f) {
172 short[] vec = vec();
173 short[] res = new short[length()];
174 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
175 for (int i = 0; i < res.length; i++) {
176 res[i] = mbits[i] ? f.apply(i, vec[i]) : vec[i];
177 }
178 return vectorFactory(res);
179 }
180
181 // Binary operator
182
183 /*package-private*/
184 interface FBinOp {
185 short apply(int i, short a, short b);
186 }
187
188 /*package-private*/
189 abstract
190 ShortVector bOp(Vector<Short> o,
191 FBinOp f);
192 @ForceInline
193 final
194 ShortVector bOpTemplate(Vector<Short> o,
195 FBinOp f) {
196 short[] res = new short[length()];
197 short[] vec1 = this.vec();
198 short[] vec2 = ((ShortVector)o).vec();
199 for (int i = 0; i < res.length; i++) {
200 res[i] = f.apply(i, vec1[i], vec2[i]);
201 }
202 return vectorFactory(res);
203 }
204
205 /*package-private*/
206 abstract
207 ShortVector bOp(Vector<Short> o,
208 VectorMask<Short> m,
209 FBinOp f);
210 @ForceInline
211 final
212 ShortVector bOpTemplate(Vector<Short> o,
213 VectorMask<Short> m,
214 FBinOp f) {
215 short[] res = new short[length()];
216 short[] vec1 = this.vec();
217 short[] vec2 = ((ShortVector)o).vec();
218 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
219 for (int i = 0; i < res.length; i++) {
220 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i]) : vec1[i];
221 }
222 return vectorFactory(res);
223 }
224
225 // Ternary operator
226
227 /*package-private*/
228 interface FTriOp {
229 short apply(int i, short a, short b, short c);
230 }
231
232 /*package-private*/
233 abstract
234 ShortVector tOp(Vector<Short> o1,
235 Vector<Short> o2,
236 FTriOp f);
237 @ForceInline
238 final
239 ShortVector tOpTemplate(Vector<Short> o1,
240 Vector<Short> o2,
241 FTriOp f) {
242 short[] res = new short[length()];
243 short[] vec1 = this.vec();
244 short[] vec2 = ((ShortVector)o1).vec();
245 short[] vec3 = ((ShortVector)o2).vec();
246 for (int i = 0; i < res.length; i++) {
247 res[i] = f.apply(i, vec1[i], vec2[i], vec3[i]);
248 }
249 return vectorFactory(res);
250 }
251
252 /*package-private*/
253 abstract
254 ShortVector tOp(Vector<Short> o1,
255 Vector<Short> o2,
256 VectorMask<Short> m,
257 FTriOp f);
258 @ForceInline
259 final
260 ShortVector tOpTemplate(Vector<Short> o1,
261 Vector<Short> o2,
262 VectorMask<Short> m,
263 FTriOp f) {
264 short[] res = new short[length()];
265 short[] vec1 = this.vec();
266 short[] vec2 = ((ShortVector)o1).vec();
267 short[] vec3 = ((ShortVector)o2).vec();
268 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
269 for (int i = 0; i < res.length; i++) {
270 res[i] = mbits[i] ? f.apply(i, vec1[i], vec2[i], vec3[i]) : vec1[i];
271 }
272 return vectorFactory(res);
273 }
274
275 // Reduction operator
276
277 /*package-private*/
278 abstract
279 short rOp(short v, FBinOp f);
280 @ForceInline
281 final
282 short rOpTemplate(short v, FBinOp f) {
283 short[] vec = vec();
284 for (int i = 0; i < vec.length; i++) {
285 v = f.apply(i, v, vec[i]);
286 }
287 return v;
288 }
289
290 // Memory reference
291
292 /*package-private*/
293 interface FLdOp<M> {
294 short apply(M memory, int offset, int i);
295 }
296
297 /*package-private*/
298 @ForceInline
299 final
300 <M> ShortVector ldOp(M memory, int offset,
301 FLdOp<M> f) {
302 //dummy; no vec = vec();
303 short[] res = new short[length()];
304 for (int i = 0; i < res.length; i++) {
305 res[i] = f.apply(memory, offset, i);
306 }
307 return vectorFactory(res);
308 }
309
310 /*package-private*/
311 @ForceInline
312 final
313 <M> ShortVector ldOp(M memory, int offset,
314 VectorMask<Short> m,
315 FLdOp<M> f) {
316 //short[] vec = vec();
317 short[] res = new short[length()];
318 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
319 for (int i = 0; i < res.length; i++) {
320 if (mbits[i]) {
321 res[i] = f.apply(memory, offset, i);
322 }
323 }
324 return vectorFactory(res);
325 }
326
327 interface FStOp<M> {
328 void apply(M memory, int offset, int i, short a);
329 }
330
331 /*package-private*/
332 @ForceInline
333 final
334 <M> void stOp(M memory, int offset,
335 FStOp<M> f) {
336 short[] vec = vec();
337 for (int i = 0; i < vec.length; i++) {
338 f.apply(memory, offset, i, vec[i]);
339 }
340 }
341
342 /*package-private*/
343 @ForceInline
344 final
345 <M> void stOp(M memory, int offset,
346 VectorMask<Short> m,
347 FStOp<M> f) {
348 short[] vec = vec();
349 boolean[] mbits = ((AbstractMask<Short>)m).getBits();
350 for (int i = 0; i < vec.length; i++) {
351 if (mbits[i]) {
352 f.apply(memory, offset, i, vec[i]);
353 }
354 }
355 }
356
357 // Binary test
358
359 /*package-private*/
360 interface FBinTest {
361 boolean apply(int cond, int i, short a, short b);
362 }
363
364 /*package-private*/
365 @ForceInline
366 final
367 AbstractMask<Short> bTest(int cond,
368 Vector<Short> o,
369 FBinTest f) {
370 short[] vec1 = vec();
371 short[] vec2 = ((ShortVector)o).vec();
372 boolean[] bits = new boolean[length()];
373 for (int i = 0; i < length(); i++){
374 bits[i] = f.apply(cond, i, vec1[i], vec2[i]);
375 }
376 return maskFactory(bits);
377 }
378
379 /*package-private*/
380 @ForceInline
381 static boolean doBinTest(int cond, short a, short b) {
382 switch (cond) {
383 case BT_eq: return a == b;
384 case BT_ne: return a != b;
385 case BT_lt: return a < b;
386 case BT_le: return a <= b;
387 case BT_gt: return a > b;
388 case BT_ge: return a >= b;
389 }
390 throw new AssertionError(Integer.toHexString(cond));
391 }
2030 */
2031 @ForceInline
2032 public final ShortVector blend(long e,
2033 VectorMask<Short> m) {
2034 return blend(broadcast(e), m);
2035 }
2036
2037 /**
2038 * {@inheritDoc} <!--workaround-->
2039 */
2040 @Override
2041 public abstract
2042 ShortVector slice(int origin, Vector<Short> v1);
2043
2044 /*package-private*/
2045 final
2046 @ForceInline
2047 ShortVector sliceTemplate(int origin, Vector<Short> v1) {
2048 ShortVector that = (ShortVector) v1;
2049 that.check(this);
2050 short[] a0 = this.vec();
2051 short[] a1 = that.vec();
2052 short[] res = new short[a0.length];
2053 int vlen = res.length;
2054 int firstPart = vlen - origin;
2055 System.arraycopy(a0, origin, res, 0, firstPart);
2056 System.arraycopy(a1, 0, res, firstPart, origin);
2057 return vectorFactory(res);
2058 }
2059
2060 /**
2061 * {@inheritDoc} <!--workaround-->
2062 */
2063 @Override
2064 @ForceInline
2065 public final
2066 ShortVector slice(int origin,
2067 Vector<Short> w,
2068 VectorMask<Short> m) {
2069 return broadcast(0).blend(slice(origin, w), m);
2070 }
2071
2073 * {@inheritDoc} <!--workaround-->
2074 */
2075 @Override
2076 public abstract
2077 ShortVector slice(int origin);
2078
2079 /**
2080 * {@inheritDoc} <!--workaround-->
2081 */
2082 @Override
2083 public abstract
2084 ShortVector unslice(int origin, Vector<Short> w, int part);
2085
2086 /*package-private*/
2087 final
2088 @ForceInline
2089 ShortVector
2090 unsliceTemplate(int origin, Vector<Short> w, int part) {
2091 ShortVector that = (ShortVector) w;
2092 that.check(this);
2093 short[] slice = this.vec();
2094 short[] res = that.vec().clone();
2095 int vlen = res.length;
2096 int firstPart = vlen - origin;
2097 switch (part) {
2098 case 0:
2099 System.arraycopy(slice, 0, res, origin, firstPart);
2100 break;
2101 case 1:
2102 System.arraycopy(slice, firstPart, res, 0, origin);
2103 break;
2104 default:
2105 throw wrongPartForSlice(part);
2106 }
2107 return vectorFactory(res);
2108 }
2109
2110 /*package-private*/
2111 final
2112 @ForceInline
2113 <M extends VectorMask<Short>>
2114 ShortVector
|