aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/opto/vectornode.cpp
blob: 4d72b73a0d7d049b49c49ea718c7fc291c0d0bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/*
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "opto/connode.hpp"
#include "opto/vectornode.hpp"

//------------------------------VectorNode--------------------------------------

// Return vector type for an element type and vector length.
const Type* VectorNode::vect_type(BasicType elt_bt, uint len) {
  assert(len <= VectorNode::max_vlen(elt_bt), "len in range");
  switch(elt_bt) {
  case T_BOOLEAN:
  case T_BYTE:
    switch(len) {
    case 2:  return TypeInt::CHAR;
    case 4:  return TypeInt::INT;
    case 8:  return TypeLong::LONG;
    }
    break;
  case T_CHAR:
  case T_SHORT:
    switch(len) {
    case 2:  return TypeInt::INT;
    case 4:  return TypeLong::LONG;
    }
    break;
  case T_INT:
    switch(len) {
    case 2:  return TypeLong::LONG;
    }
    break;
  case T_LONG:
    break;
  case T_FLOAT:
    switch(len) {
    case 2:  return Type::DOUBLE;
    }
    break;
  case T_DOUBLE:
    break;
  }
  ShouldNotReachHere();
  return NULL;
}

// Scalar promotion
VectorNode* VectorNode::scalar2vector(Compile* C, Node* s, uint vlen, const Type* opd_t) {
  BasicType bt = opd_t->array_element_basic_type();
  assert(vlen <= VectorNode::max_vlen(bt), "vlen in range");
  switch (bt) {
  case T_BOOLEAN:
  case T_BYTE:
    if (vlen == 16) return new (C, 2) Replicate16BNode(s);
    if (vlen ==  8) return new (C, 2) Replicate8BNode(s);
    if (vlen ==  4) return new (C, 2) Replicate4BNode(s);
    break;
  case T_CHAR:
    if (vlen == 8) return new (C, 2) Replicate8CNode(s);
    if (vlen == 4) return new (C, 2) Replicate4CNode(s);
    if (vlen == 2) return new (C, 2) Replicate2CNode(s);
    break;
  case T_SHORT:
    if (vlen == 8) return new (C, 2) Replicate8SNode(s);
    if (vlen == 4) return new (C, 2) Replicate4SNode(s);
    if (vlen == 2) return new (C, 2) Replicate2SNode(s);
    break;
  case T_INT:
    if (vlen == 4) return new (C, 2) Replicate4INode(s);
    if (vlen == 2) return new (C, 2) Replicate2INode(s);
    break;
  case T_LONG:
    if (vlen == 2) return new (C, 2) Replicate2LNode(s);
    break;
  case T_FLOAT:
    if (vlen == 4) return new (C, 2) Replicate4FNode(s);
    if (vlen == 2) return new (C, 2) Replicate2FNode(s);
    break;
  case T_DOUBLE:
    if (vlen == 2) return new (C, 2) Replicate2DNode(s);
    break;
  }
  ShouldNotReachHere();
  return NULL;
}

// Return initial Pack node. Additional operands added with add_opd() calls.
PackNode* PackNode::make(Compile* C, Node* s, const Type* opd_t) {
  BasicType bt = opd_t->array_element_basic_type();
  switch (bt) {
  case T_BOOLEAN:
  case T_BYTE:
    return new (C, 2) PackBNode(s);
  case T_CHAR:
    return new (C, 2) PackCNode(s);
  case T_SHORT:
    return new (C, 2) PackSNode(s);
  case T_INT:
    return new (C, 2) PackINode(s);
  case T_LONG:
    return new (C, 2) PackLNode(s);
  case T_FLOAT:
    return new (C, 2) PackFNode(s);
  case T_DOUBLE:
    return new (C, 2) PackDNode(s);
  }
  ShouldNotReachHere();
  return NULL;
}

// Create a binary tree form for Packs. [lo, hi) (half-open) range
Node* PackNode::binaryTreePack(Compile* C, int lo, int hi) {
  int ct = hi - lo;
  assert(is_power_of_2(ct), "power of 2");
  int mid = lo + ct/2;
  Node* n1 = ct == 2 ? in(lo)   : binaryTreePack(C, lo,  mid);
  Node* n2 = ct == 2 ? in(lo+1) : binaryTreePack(C, mid, hi );
  int rslt_bsize = ct * type2aelembytes(elt_basic_type());
  if (bottom_type()->is_floatingpoint()) {
    switch (rslt_bsize) {
    case  8: return new (C, 3) PackFNode(n1, n2);
    case 16: return new (C, 3) PackDNode(n1, n2);
    }
  } else {
    assert(bottom_type()->isa_int() || bottom_type()->isa_long(), "int or long");
    switch (rslt_bsize) {
    case  2: return new (C, 3) Pack2x1BNode(n1, n2);
    case  4: return new (C, 3) Pack2x2BNode(n1, n2);
    case  8: return new (C, 3) PackINode(n1, n2);
    case 16: return new (C, 3) PackLNode(n1, n2);
    }
  }
  ShouldNotReachHere();
  return NULL;
}

// Return the vector operator for the specified scalar operation
// and vector length.  One use is to check if the code generator
// supports the vector operation.
int VectorNode::opcode(int sopc, uint vlen, const Type* opd_t) {
  BasicType bt = opd_t->array_element_basic_type();
  if (!(is_power_of_2(vlen) && vlen <= max_vlen(bt)))
    return 0; // unimplemented
  switch (sopc) {
  case Op_AddI:
    switch (bt) {
    case T_BOOLEAN:
    case T_BYTE:      return Op_AddVB;
    case T_CHAR:      return Op_AddVC;
    case T_SHORT:     return Op_AddVS;
    case T_INT:       return Op_AddVI;
    }
    ShouldNotReachHere();
  case Op_AddL:
    assert(bt == T_LONG, "must be");
    return Op_AddVL;
  case Op_AddF:
    assert(bt == T_FLOAT, "must be");
    return Op_AddVF;
  case Op_AddD:
    assert(bt == T_DOUBLE, "must be");
    return Op_AddVD;
  case Op_SubI:
    switch (bt) {
    case T_BOOLEAN:
    case T_BYTE:   return Op_SubVB;
    case T_CHAR:   return Op_SubVC;
    case T_SHORT:  return Op_SubVS;
    case T_INT:    return Op_SubVI;
    }
    ShouldNotReachHere();
  case Op_SubL:
    assert(bt == T_LONG, "must be");
    return Op_SubVL;
  case Op_SubF:
    assert(bt == T_FLOAT, "must be");
    return Op_SubVF;
  case Op_SubD:
    assert(bt == T_DOUBLE, "must be");
    return Op_SubVD;
  case Op_MulF:
    assert(bt == T_FLOAT, "must be");
    return Op_MulVF;
  case Op_MulD:
    assert(bt == T_DOUBLE, "must be");
    return Op_MulVD;
  case Op_DivF:
    assert(bt == T_FLOAT, "must be");
    return Op_DivVF;
  case Op_DivD:
    assert(bt == T_DOUBLE, "must be");
    return Op_DivVD;
  case Op_LShiftI:
    switch (bt) {
    case T_BOOLEAN:
    case T_BYTE:   return Op_LShiftVB;
    case T_CHAR:   return Op_LShiftVC;
    case T_SHORT:  return Op_LShiftVS;
    case T_INT:    return Op_LShiftVI;
    }
    ShouldNotReachHere();
  case Op_URShiftI:
    switch (bt) {
    case T_BOOLEAN:
    case T_BYTE:   return Op_URShiftVB;
    case T_CHAR:   return Op_URShiftVC;
    case T_SHORT:  return Op_URShiftVS;
    case T_INT:    return Op_URShiftVI;
    }
    ShouldNotReachHere();
  case Op_AndI:
  case Op_AndL:
    return Op_AndV;
  case Op_OrI:
  case Op_OrL:
    return Op_OrV;
  case Op_XorI:
  case Op_XorL:
    return Op_XorV;

  case Op_LoadB:
  case Op_LoadUS:
  case Op_LoadS:
  case Op_LoadI:
  case Op_LoadL:
  case Op_LoadF:
  case Op_LoadD:
    return VectorLoadNode::opcode(sopc, vlen);

  case Op_StoreB:
  case Op_StoreC:
  case Op_StoreI:
  case Op_StoreL:
  case Op_StoreF:
  case Op_StoreD:
    return VectorStoreNode::opcode(sopc, vlen);
  }
  return 0; // Unimplemented
}

// Helper for above.
int VectorLoadNode::opcode(int sopc, uint vlen) {
  switch (sopc) {
  case Op_LoadB:
    switch (vlen) {
    case  2:       return 0; // Unimplemented
    case  4:       return Op_Load4B;
    case  8:       return Op_Load8B;
    case 16:       return Op_Load16B;
    }
    break;
  case Op_LoadUS:
    switch (vlen) {
    case  2:       return Op_Load2C;
    case  4:       return Op_Load4C;
    case  8:       return Op_Load8C;
    }
    break;
  case Op_LoadS:
    switch (vlen) {
    case  2:       return Op_Load2S;
    case  4:       return Op_Load4S;
    case  8:       return Op_Load8S;
    }
    break;
  case Op_LoadI:
    switch (vlen) {
    case  2:       return Op_Load2I;
    case  4:       return Op_Load4I;
    }
    break;
  case Op_LoadL:
    if (vlen == 2) return Op_Load2L;
    break;
  case Op_LoadF:
    switch (vlen) {
    case  2:       return Op_Load2F;
    case  4:       return Op_Load4F;
    }
    break;
  case Op_LoadD:
    if (vlen == 2) return Op_Load2D;
    break;
  }
  return 0; // Unimplemented
}

// Helper for above
int VectorStoreNode::opcode(int sopc, uint vlen) {
  switch (sopc) {
  case Op_StoreB:
    switch (vlen) {
    case  2:       return 0; // Unimplemented
    case  4:       return Op_Store4B;
    case  8:       return Op_Store8B;
    case 16:       return Op_Store16B;
    }
    break;
  case Op_StoreC:
    switch (vlen) {
    case  2:       return Op_Store2C;
    case  4:       return Op_Store4C;
    case  8:       return Op_Store8C;
    }
    break;
  case Op_StoreI:
    switch (vlen) {
    case  2:       return Op_Store2I;
    case  4:       return Op_Store4I;
    }
    break;
  case Op_StoreL:
    if (vlen == 2) return Op_Store2L;
    break;
  case Op_StoreF:
    switch (vlen) {
    case  2:       return Op_Store2F;
    case  4:       return Op_Store4F;
    }
    break;
  case Op_StoreD:
    if (vlen == 2) return Op_Store2D;
    break;
  }
  return 0; // Unimplemented
}

// Return the vector version of a scalar operation node.
VectorNode* VectorNode::make(Compile* C, int sopc, Node* n1, Node* n2, uint vlen, const Type* opd_t) {
  int vopc = opcode(sopc, vlen, opd_t);

  switch (vopc) {
  case Op_AddVB: return new (C, 3) AddVBNode(n1, n2, vlen);
  case Op_AddVC: return new (C, 3) AddVCNode(n1, n2, vlen);
  case Op_AddVS: return new (C, 3) AddVSNode(n1, n2, vlen);
  case Op_AddVI: return new (C, 3) AddVINode(n1, n2, vlen);
  case Op_AddVL: return new (C, 3) AddVLNode(n1, n2, vlen);
  case Op_AddVF: return new (C, 3) AddVFNode(n1, n2, vlen);
  case Op_AddVD: return new (C, 3) AddVDNode(n1, n2, vlen);

  case Op_SubVB: return new (C, 3) SubVBNode(n1, n2, vlen);
  case Op_SubVC: return new (C, 3) SubVCNode(n1, n2, vlen);
  case Op_SubVS: return new (C, 3) SubVSNode(n1, n2, vlen);
  case Op_SubVI: return new (C, 3) SubVINode(n1, n2, vlen);
  case Op_SubVL: return new (C, 3) SubVLNode(n1, n2, vlen);
  case Op_SubVF: return new (C, 3) SubVFNode(n1, n2, vlen);
  case Op_SubVD: return new (C, 3) SubVDNode(n1, n2, vlen);

  case Op_MulVF: return new (C, 3) MulVFNode(n1, n2, vlen);
  case Op_MulVD: return new (C, 3) MulVDNode(n1, n2, vlen);

  case Op_DivVF: return new (C, 3) DivVFNode(n1, n2, vlen);
  case Op_DivVD: return new (C, 3) DivVDNode(n1, n2, vlen);

  case Op_LShiftVB: return new (C, 3) LShiftVBNode(n1, n2, vlen);
  case Op_LShiftVC: return new (C, 3) LShiftVCNode(n1, n2, vlen);
  case Op_LShiftVS: return new (C, 3) LShiftVSNode(n1, n2, vlen);
  case Op_LShiftVI: return new (C, 3) LShiftVINode(n1, n2, vlen);

  case Op_URShiftVB: return new (C, 3) URShiftVBNode(n1, n2, vlen);
  case Op_URShiftVC: return new (C, 3) URShiftVCNode(n1, n2, vlen);
  case Op_URShiftVS: return new (C, 3) URShiftVSNode(n1, n2, vlen);
  case Op_URShiftVI: return new (C, 3) URShiftVINode(n1, n2, vlen);

  case Op_AndV: return new (C, 3) AndVNode(n1, n2, vlen, opd_t->array_element_basic_type());
  case Op_OrV:  return new (C, 3) OrVNode (n1, n2, vlen, opd_t->array_element_basic_type());
  case Op_XorV: return new (C, 3) XorVNode(n1, n2, vlen, opd_t->array_element_basic_type());
  }
  ShouldNotReachHere();
  return NULL;
}

// Return the vector version of a scalar load node.
VectorLoadNode* VectorLoadNode::make(Compile* C, int opc, Node* ctl, Node* mem,
                                     Node* adr, const TypePtr* atyp, uint vlen) {
  int vopc = opcode(opc, vlen);

  switch(vopc) {
  case Op_Load16B: return new (C, 3) Load16BNode(ctl, mem, adr, atyp);
  case Op_Load8B:  return new (C, 3) Load8BNode(ctl, mem, adr, atyp);
  case Op_Load4B:  return new (C, 3) Load4BNode(ctl, mem, adr, atyp);

  case Op_Load8C:  return new (C, 3) Load8CNode(ctl, mem, adr, atyp);
  case Op_Load4C:  return new (C, 3) Load4CNode(ctl, mem, adr, atyp);
  case Op_Load2C:  return new (C, 3) Load2CNode(ctl, mem, adr, atyp);

  case Op_Load8S:  return new (C, 3) Load8SNode(ctl, mem, adr, atyp);
  case Op_Load4S:  return new (C, 3) Load4SNode(ctl, mem, adr, atyp);
  case Op_Load2S:  return new (C, 3) Load2SNode(ctl, mem, adr, atyp);

  case Op_Load4I:  return new (C, 3) Load4INode(ctl, mem, adr, atyp);
  case Op_Load2I:  return new (C, 3) Load2INode(ctl, mem, adr, atyp);

  case Op_Load2L:  return new (C, 3) Load2LNode(ctl, mem, adr, atyp);

  case Op_Load4F:  return new (C, 3) Load4FNode(ctl, mem, adr, atyp);
  case Op_Load2F:  return new (C, 3) Load2FNode(ctl, mem, adr, atyp);

  case Op_Load2D:  return new (C, 3) Load2DNode(ctl, mem, adr, atyp);
  }
  ShouldNotReachHere();
  return NULL;
}

// Return the vector version of a scalar store node.
VectorStoreNode* VectorStoreNode::make(Compile* C, int opc, Node* ctl, Node* mem,
                                       Node* adr, const TypePtr* atyp, VectorNode* val,
                                       uint vlen) {
  int vopc = opcode(opc, vlen);

  switch(vopc) {
  case Op_Store16B: return new (C, 4) Store16BNode(ctl, mem, adr, atyp, val);
  case Op_Store8B: return new (C, 4) Store8BNode(ctl, mem, adr, atyp, val);
  case Op_Store4B: return new (C, 4) Store4BNode(ctl, mem, adr, atyp, val);

  case Op_Store8C: return new (C, 4) Store8CNode(ctl, mem, adr, atyp, val);
  case Op_Store4C: return new (C, 4) Store4CNode(ctl, mem, adr, atyp, val);
  case Op_Store2C: return new (C, 4) Store2CNode(ctl, mem, adr, atyp, val);

  case Op_Store4I: return new (C, 4) Store4INode(ctl, mem, adr, atyp, val);
  case Op_Store2I: return new (C, 4) Store2INode(ctl, mem, adr, atyp, val);

  case Op_Store2L: return new (C, 4) Store2LNode(ctl, mem, adr, atyp, val);

  case Op_Store4F: return new (C, 4) Store4FNode(ctl, mem, adr, atyp, val);
  case Op_Store2F: return new (C, 4) Store2FNode(ctl, mem, adr, atyp, val);

  case Op_Store2D: return new (C, 4) Store2DNode(ctl, mem, adr, atyp, val);
  }
  ShouldNotReachHere();
  return NULL;
}

// Extract a scalar element of vector.
Node* ExtractNode::make(Compile* C, Node* v, uint position, const Type* opd_t) {
  BasicType bt = opd_t->array_element_basic_type();
  assert(position < VectorNode::max_vlen(bt), "pos in range");
  ConINode* pos = ConINode::make(C, (int)position);
  switch (bt) {
  case T_BOOLEAN:
  case T_BYTE:
    return new (C, 3) ExtractBNode(v, pos);
  case T_CHAR:
    return new (C, 3) ExtractCNode(v, pos);
  case T_SHORT:
    return new (C, 3) ExtractSNode(v, pos);
  case T_INT:
    return new (C, 3) ExtractINode(v, pos);
  case T_LONG:
    return new (C, 3) ExtractLNode(v, pos);
  case T_FLOAT:
    return new (C, 3) ExtractFNode(v, pos);
  case T_DOUBLE:
    return new (C, 3) ExtractDNode(v, pos);
  }
  ShouldNotReachHere();
  return NULL;
}