vectornode.cpp revision 1879
0N/A/*
0N/A * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "memory/allocation.inline.hpp"
0N/A#include "opto/connode.hpp"
0N/A#include "opto/vectornode.hpp"
0N/A
0N/A//------------------------------VectorNode--------------------------------------
0N/A
0N/A// Return vector type for an element type and vector length.
0N/Aconst Type* VectorNode::vect_type(BasicType elt_bt, uint len) {
0N/A assert(len <= VectorNode::max_vlen(elt_bt), "len in range");
0N/A switch(elt_bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE:
0N/A switch(len) {
0N/A case 2: return TypeInt::CHAR;
0N/A case 4: return TypeInt::INT;
0N/A case 8: return TypeLong::LONG;
0N/A }
0N/A break;
0N/A case T_CHAR:
0N/A case T_SHORT:
0N/A switch(len) {
0N/A case 2: return TypeInt::INT;
0N/A case 4: return TypeLong::LONG;
0N/A }
0N/A break;
0N/A case T_INT:
0N/A switch(len) {
0N/A case 2: return TypeLong::LONG;
0N/A }
0N/A break;
0N/A case T_LONG:
0N/A break;
0N/A case T_FLOAT:
0N/A switch(len) {
0N/A case 2: return Type::DOUBLE;
0N/A }
0N/A break;
0N/A case T_DOUBLE:
0N/A break;
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A// Scalar promotion
0N/AVectorNode* VectorNode::scalar2vector(Compile* C, Node* s, uint vlen, const Type* opd_t) {
0N/A BasicType bt = opd_t->array_element_basic_type();
0N/A assert(vlen <= VectorNode::max_vlen(bt), "vlen in range");
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE:
0N/A if (vlen == 16) return new (C, 2) Replicate16BNode(s);
0N/A if (vlen == 8) return new (C, 2) Replicate8BNode(s);
0N/A if (vlen == 4) return new (C, 2) Replicate4BNode(s);
0N/A break;
0N/A case T_CHAR:
0N/A if (vlen == 8) return new (C, 2) Replicate8CNode(s);
0N/A if (vlen == 4) return new (C, 2) Replicate4CNode(s);
0N/A if (vlen == 2) return new (C, 2) Replicate2CNode(s);
0N/A break;
0N/A case T_SHORT:
0N/A if (vlen == 8) return new (C, 2) Replicate8SNode(s);
0N/A if (vlen == 4) return new (C, 2) Replicate4SNode(s);
0N/A if (vlen == 2) return new (C, 2) Replicate2SNode(s);
0N/A break;
0N/A case T_INT:
0N/A if (vlen == 4) return new (C, 2) Replicate4INode(s);
0N/A if (vlen == 2) return new (C, 2) Replicate2INode(s);
0N/A break;
0N/A case T_LONG:
0N/A if (vlen == 2) return new (C, 2) Replicate2LNode(s);
0N/A break;
0N/A case T_FLOAT:
0N/A if (vlen == 4) return new (C, 2) Replicate4FNode(s);
0N/A if (vlen == 2) return new (C, 2) Replicate2FNode(s);
0N/A break;
0N/A case T_DOUBLE:
0N/A if (vlen == 2) return new (C, 2) Replicate2DNode(s);
0N/A break;
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A// Return initial Pack node. Additional operands added with add_opd() calls.
0N/APackNode* PackNode::make(Compile* C, Node* s, const Type* opd_t) {
0N/A BasicType bt = opd_t->array_element_basic_type();
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE:
0N/A return new (C, 2) PackBNode(s);
0N/A case T_CHAR:
0N/A return new (C, 2) PackCNode(s);
0N/A case T_SHORT:
0N/A return new (C, 2) PackSNode(s);
0N/A case T_INT:
0N/A return new (C, 2) PackINode(s);
0N/A case T_LONG:
0N/A return new (C, 2) PackLNode(s);
0N/A case T_FLOAT:
0N/A return new (C, 2) PackFNode(s);
0N/A case T_DOUBLE:
0N/A return new (C, 2) PackDNode(s);
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A// Create a binary tree form for Packs. [lo, hi) (half-open) range
0N/ANode* PackNode::binaryTreePack(Compile* C, int lo, int hi) {
0N/A int ct = hi - lo;
0N/A assert(is_power_of_2(ct), "power of 2");
0N/A int mid = lo + ct/2;
0N/A Node* n1 = ct == 2 ? in(lo) : binaryTreePack(C, lo, mid);
0N/A Node* n2 = ct == 2 ? in(lo+1) : binaryTreePack(C, mid, hi );
0N/A int rslt_bsize = ct * type2aelembytes(elt_basic_type());
0N/A if (bottom_type()->is_floatingpoint()) {
0N/A switch (rslt_bsize) {
0N/A case 8: return new (C, 3) PackFNode(n1, n2);
0N/A case 16: return new (C, 3) PackDNode(n1, n2);
0N/A }
0N/A } else {
0N/A assert(bottom_type()->isa_int() || bottom_type()->isa_long(), "int or long");
0N/A switch (rslt_bsize) {
0N/A case 2: return new (C, 3) Pack2x1BNode(n1, n2);
0N/A case 4: return new (C, 3) Pack2x2BNode(n1, n2);
0N/A case 8: return new (C, 3) PackINode(n1, n2);
0N/A case 16: return new (C, 3) PackLNode(n1, n2);
0N/A }
0N/A }
0N/A ShouldNotReachHere();
0N/A return NULL;
0N/A}
0N/A
0N/A// Return the vector operator for the specified scalar operation
0N/A// and vector length. One use is to check if the code generator
0N/A// supports the vector operation.
0N/Aint VectorNode::opcode(int sopc, uint vlen, const Type* opd_t) {
0N/A BasicType bt = opd_t->array_element_basic_type();
0N/A if (!(is_power_of_2(vlen) && vlen <= max_vlen(bt)))
0N/A return 0; // unimplemented
0N/A switch (sopc) {
0N/A case Op_AddI:
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE: return Op_AddVB;
0N/A case T_CHAR: return Op_AddVC;
0N/A case T_SHORT: return Op_AddVS;
0N/A case T_INT: return Op_AddVI;
0N/A }
0N/A ShouldNotReachHere();
0N/A case Op_AddL:
0N/A assert(bt == T_LONG, "must be");
0N/A return Op_AddVL;
0N/A case Op_AddF:
0N/A assert(bt == T_FLOAT, "must be");
0N/A return Op_AddVF;
0N/A case Op_AddD:
0N/A assert(bt == T_DOUBLE, "must be");
0N/A return Op_AddVD;
0N/A case Op_SubI:
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE: return Op_SubVB;
0N/A case T_CHAR: return Op_SubVC;
0N/A case T_SHORT: return Op_SubVS;
0N/A case T_INT: return Op_SubVI;
0N/A }
0N/A ShouldNotReachHere();
0N/A case Op_SubL:
0N/A assert(bt == T_LONG, "must be");
0N/A return Op_SubVL;
0N/A case Op_SubF:
0N/A assert(bt == T_FLOAT, "must be");
0N/A return Op_SubVF;
0N/A case Op_SubD:
0N/A assert(bt == T_DOUBLE, "must be");
0N/A return Op_SubVD;
0N/A case Op_MulF:
0N/A assert(bt == T_FLOAT, "must be");
0N/A return Op_MulVF;
0N/A case Op_MulD:
0N/A assert(bt == T_DOUBLE, "must be");
0N/A return Op_MulVD;
0N/A case Op_DivF:
0N/A assert(bt == T_FLOAT, "must be");
0N/A return Op_DivVF;
0N/A case Op_DivD:
0N/A assert(bt == T_DOUBLE, "must be");
0N/A return Op_DivVD;
0N/A case Op_LShiftI:
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE: return Op_LShiftVB;
0N/A case T_CHAR: return Op_LShiftVC;
0N/A case T_SHORT: return Op_LShiftVS;
0N/A case T_INT: return Op_LShiftVI;
0N/A }
0N/A ShouldNotReachHere();
0N/A case Op_URShiftI:
0N/A switch (bt) {
0N/A case T_BOOLEAN:
0N/A case T_BYTE: return Op_URShiftVB;
0N/A case T_CHAR: return Op_URShiftVC;
0N/A case T_SHORT: return Op_URShiftVS;
0N/A case T_INT: return Op_URShiftVI;
0N/A }
0N/A ShouldNotReachHere();
0N/A case Op_AndI:
0N/A case Op_AndL:
0N/A return Op_AndV;
0N/A case Op_OrI:
0N/A case Op_OrL:
0N/A return Op_OrV;
0N/A case Op_XorI:
0N/A case Op_XorL:
0N/A return Op_XorV;
0N/A
0N/A case Op_LoadB:
0N/A case Op_LoadUS:
0N/A case Op_LoadS:
0N/A case Op_LoadI:
0N/A case Op_LoadL:
0N/A case Op_LoadF:
0N/A case Op_LoadD:
0N/A return VectorLoadNode::opcode(sopc, vlen);
0N/A
0N/A case Op_StoreB:
0N/A case Op_StoreC:
0N/A case Op_StoreI:
0N/A case Op_StoreL:
0N/A case Op_StoreF:
0N/A case Op_StoreD:
0N/A return VectorStoreNode::opcode(sopc, vlen);
0N/A }
0N/A return 0; // Unimplemented
0N/A}
0N/A
0N/A// Helper for above.
0N/Aint VectorLoadNode::opcode(int sopc, uint vlen) {
0N/A switch (sopc) {
0N/A case Op_LoadB:
0N/A switch (vlen) {
0N/A case 2: return 0; // Unimplemented
0N/A case 4: return Op_Load4B;
0N/A case 8: return Op_Load8B;
0N/A case 16: return Op_Load16B;
0N/A }
0N/A break;
0N/A case Op_LoadUS:
0N/A switch (vlen) {
0N/A case 2: return Op_Load2C;
0N/A case 4: return Op_Load4C;
0N/A case 8: return Op_Load8C;
0N/A }
0N/A break;
0N/A case Op_LoadS:
0N/A switch (vlen) {
0N/A case 2: return Op_Load2S;
0N/A case 4: return Op_Load4S;
0N/A case 8: return Op_Load8S;
0N/A }
0N/A break;
0N/A case Op_LoadI:
0N/A switch (vlen) {
0N/A case 2: return Op_Load2I;
0N/A case 4: return Op_Load4I;
0N/A }
0N/A break;
0N/A case Op_LoadL:
0N/A if (vlen == 2) return Op_Load2L;
0N/A break;
0N/A case Op_LoadF:
0N/A switch (vlen) {
0N/A case 2: return Op_Load2F;
0N/A case 4: return Op_Load4F;
0N/A }
0N/A break;
0N/A case Op_LoadD:
0N/A if (vlen == 2) return Op_Load2D;
0N/A break;
0N/A }
0N/A return 0; // Unimplemented
0N/A}
0N/A
0N/A// Helper for above
0N/Aint VectorStoreNode::opcode(int sopc, uint vlen) {
0N/A switch (sopc) {
0N/A case Op_StoreB:
0N/A switch (vlen) {
0N/A case 2: return 0; // Unimplemented
0N/A case 4: return Op_Store4B;
0N/A case 8: return Op_Store8B;
0N/A case 16: return Op_Store16B;
0N/A }
0N/A break;
0N/A case Op_StoreC:
0N/A switch (vlen) {
0N/A case 2: return Op_Store2C;
0N/A case 4: return Op_Store4C;
0N/A case 8: return Op_Store8C;
0N/A }
0N/A break;
0N/A case Op_StoreI:
0N/A switch (vlen) {
0N/A case 2: return Op_Store2I;
0N/A case 4: return Op_Store4I;
0N/A }
0N/A break;
0N/A case Op_StoreL:
0N/A if (vlen == 2) return Op_Store2L;
0N/A break;
0N/A case Op_StoreF:
0N/A switch (vlen) {
0N/A case 2: return Op_Store2F;
0N/A case 4: return Op_Store4F;
0N/A }
0N/A break;
0N/A case Op_StoreD:
0N/A if (vlen == 2) return Op_Store2D;
0N/A break;
0N/A }
0N/A return 0; // Unimplemented
0N/A}
0N/A
0N/A// Return the vector version of a scalar operation node.
0N/AVectorNode* VectorNode::make(Compile* C, int sopc, Node* n1, Node* n2, uint vlen, const Type* opd_t) {
0N/A int vopc = opcode(sopc, vlen, opd_t);
0N/A
0N/A switch (vopc) {
0N/A case Op_AddVB: return new (C, 3) AddVBNode(n1, n2, vlen);
0N/A case Op_AddVC: return new (C, 3) AddVCNode(n1, n2, vlen);
0N/A case Op_AddVS: return new (C, 3) AddVSNode(n1, n2, vlen);
0N/A case Op_AddVI: return new (C, 3) AddVINode(n1, n2, vlen);
0N/A case Op_AddVL: return new (C, 3) AddVLNode(n1, n2, vlen);
0N/A case Op_AddVF: return new (C, 3) AddVFNode(n1, n2, vlen);
0N/A case Op_AddVD: return new (C, 3) AddVDNode(n1, n2, vlen);
0N/A
0N/A 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;
}