1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Stop using struct wrappers for Neon vector types in <arm_neon.h>.

Thanks to Nate Begeman for an earlier version of this patch.

llvm-svn: 119358
This commit is contained in:
Bob Wilson 2010-11-16 18:17:03 +00:00
parent cf4418e0d6
commit c33bc803b5

View File

@ -535,10 +535,8 @@ static std::string Duplicate(unsigned nElts, StringRef typestr,
}
// Generate the definition for this intrinsic, e.g. "a + b" for OpAdd.
// If structTypes is true, the NEON types are structs of vector types rather
// than vector types, and the call becomes "a.val + b.val"
static std::string GenOpString(OpKind op, const std::string &proto,
StringRef typestr, bool structTypes = true) {
StringRef typestr) {
bool dummy, quad = false;
char type = ClassifyType(typestr, quad, dummy, dummy);
unsigned nElts = 0;
@ -557,100 +555,95 @@ static std::string GenOpString(OpKind op, const std::string &proto,
s = "union { " + ts + " r; double d; } u; u.d";
} else {
s = ts + " r; r";
if (structTypes)
s += ".val";
}
s += " = ";
std::string a, b, c;
if (proto.size() > 1)
a = (structTypes && proto[1] != 'l' && proto[1] != 's') ? "a.val" : "a";
b = structTypes ? "b.val" : "b";
c = structTypes ? "c.val" : "c";
switch(op) {
case OpAdd:
s += a + " + " + b;
s += "a + b";
break;
case OpSub:
s += a + " - " + b;
s += "a - b";
break;
case OpMulN:
b = Duplicate(nElts << (int)quad, typestr, "b");
s += "a * " + Duplicate(nElts << (int)quad, typestr, "b");
break;
case OpMul:
s += a + " * " + b;
s += "a * b";
break;
case OpMlaN:
c = Duplicate(nElts << (int)quad, typestr, "c");
s += "a + (b * " + Duplicate(nElts << (int)quad, typestr, "c") + ")";
break;
case OpMla:
s += a + " + ( " + b + " * " + c + " )";
s += "a + (b * c)";
break;
case OpMlsN:
c = Duplicate(nElts << (int)quad, typestr, "c");
s += "a - (b * " + Duplicate(nElts << (int)quad, typestr, "c") + ")";
break;
case OpMls:
s += a + " - ( " + b + " * " + c + " )";
s += "a - (b * c)";
break;
case OpEq:
s += "(__neon_" + ts + ")(" + a + " == " + b + ")";
s += "(__neon_" + ts + ")(a == b)";
break;
case OpGe:
s += "(__neon_" + ts + ")(" + a + " >= " + b + ")";
s += "(__neon_" + ts + ")(a >= b)";
break;
case OpLe:
s += "(__neon_" + ts + ")(" + a + " <= " + b + ")";
s += "(__neon_" + ts + ")(a <= b)";
break;
case OpGt:
s += "(__neon_" + ts + ")(" + a + " > " + b + ")";
s += "(__neon_" + ts + ")(a > b)";
break;
case OpLt:
s += "(__neon_" + ts + ")(" + a + " < " + b + ")";
s += "(__neon_" + ts + ")(a < b)";
break;
case OpNeg:
s += " -" + a;
s += " -a";
break;
case OpNot:
s += " ~" + a;
s += " ~a";
break;
case OpAnd:
s += a + " & " + b;
s += "a & b";
break;
case OpOr:
s += a + " | " + b;
s += "a | b";
break;
case OpXor:
s += a + " ^ " + b;
s += "a ^ b";
break;
case OpAndNot:
s += a + " & ~" + b;
s += "a & ~b";
break;
case OpOrNot:
s += a + " | ~" + b;
s += "a | ~b";
break;
case OpCast:
s += "(__neon_" + ts + ")" + a;
s += "(__neon_" + ts + ")a";
break;
case OpConcat:
s += "__builtin_shufflevector((__neon_int64x1_t)" + a;
s += ", (__neon_int64x1_t)" + b + ", 0, 1)";
s += "__builtin_shufflevector((__neon_int64x1_t)a";
s += ", (__neon_int64x1_t)b, 0, 1)";
break;
case OpHi:
s += "(((__neon_float64x2_t)" + a + ")[1])";
s += "(((__neon_float64x2_t)a)[1])";
break;
case OpLo:
s += "(((__neon_float64x2_t)" + a + ")[0])";
s += "(((__neon_float64x2_t)a)[0])";
break;
case OpDup:
s += Duplicate(nElts << (int)quad, typestr, a);
s += Duplicate(nElts << (int)quad, typestr, "a");
break;
case OpSelect:
// ((0 & 1) | (~0 & 2))
ts = TypeString(proto[1], typestr);
s += "( " + a + " & (__neon_" + ts + ")" + b + ") | ";
s += "(~" + a + " & (__neon_" + ts + ")" + c + ")";
s += "(a & (__neon_" + ts + ")b) | ";
s += "(~a & (__neon_" + ts + ")c)";
break;
case OpRev16:
s += "__builtin_shufflevector(" + a + ", " + a;
s += "__builtin_shufflevector(a, a";
for (unsigned i = 2; i <= nElts << (int)quad; i += 2)
for (unsigned j = 0; j != 2; ++j)
s += ", " + utostr(i - j - 1);
@ -658,14 +651,14 @@ static std::string GenOpString(OpKind op, const std::string &proto,
break;
case OpRev32:
nElts >>= 1;
s += "__builtin_shufflevector(" + a + ", " + a;
s += "__builtin_shufflevector(a, a";
for (unsigned i = nElts; i <= nElts << (1 + (int)quad); i += nElts)
for (unsigned j = 0; j != nElts; ++j)
s += ", " + utostr(i - j - 1);
s += ")";
break;
case OpRev64:
s += "__builtin_shufflevector(" + a + ", " + a;
s += "__builtin_shufflevector(a, a";
for (unsigned i = nElts; i <= nElts << (int)quad; i += nElts)
for (unsigned j = 0; j != nElts; ++j)
s += ", " + utostr(i - j - 1);
@ -734,11 +727,8 @@ static unsigned GetNeonEnum(const std::string &proto, StringRef typestr) {
}
// Generate the definition for this intrinsic, e.g. __builtin_neon_cls(a)
// If structTypes is true, the NEON types are structs of vector types rather
// than vector types, and the call becomes __builtin_neon_cls(a.val)
static std::string GenBuiltin(const std::string &name, const std::string &proto,
StringRef typestr, ClassKind ck,
bool structTypes = true) {
StringRef typestr, ClassKind ck) {
bool dummy, quad = false;
char type = ClassifyType(typestr, quad, dummy, dummy);
unsigned nElts = 0;
@ -777,15 +767,11 @@ static std::string GenBuiltin(const std::string &name, const std::string &proto,
if (sret)
s += "({ " + ts + " r; ";
else if (proto[0] != 's')
s += "(" + ts + "){(__neon_" + ts + ")";
s += "(" + ts + ")";
} else if (sret) {
s += ts + " r; ";
} else {
s += ts + " r; r";
if (structTypes && proto[0] != 's' && proto[0] != 'i' && proto[0] != 'l')
s += ".val";
s += " = ";
s += ts + " r; r = ";
}
}
@ -812,9 +798,9 @@ static std::string GenBuiltin(const std::string &name, const std::string &proto,
// Handle multiple-vector values specially, emitting each subvector as an
// argument to the __builtin.
if (structTypes && (proto[i] == '2' || proto[i] == '3' || proto[i] == '4')){
if (proto[i] == '2' || proto[i] == '3' || proto[i] == '4') {
for (unsigned vi = 0, ve = proto[i] - '0'; vi != ve; ++vi) {
s += args + ".val[" + utostr(vi) + "].val";
s += args + ".val[" + utostr(vi) + "]";
if ((vi + 1) < ve)
s += ", ";
}
@ -828,11 +814,6 @@ static std::string GenBuiltin(const std::string &name, const std::string &proto,
s += Duplicate(nElts, typestr, args);
else
s += args;
if (structTypes && proto[i] != 's' && proto[i] != 'i' && proto[i] != 'l' &&
proto[i] != 'p' && proto[i] != 'c' && proto[i] != 'a') {
s += ".val";
}
if ((i + 1) < e)
s += ", ";
}
@ -850,8 +831,6 @@ static std::string GenBuiltin(const std::string &name, const std::string &proto,
if (define) {
if (sret)
s += "; r; })";
else if (proto[0] != 's')
s += "}";
} else {
s += " return r;";
}
@ -942,11 +921,15 @@ void NeonEmitter::run(raw_ostream &OS) {
std::string ts = TypeString('d', TDTypeVec[i], vi == 1);
std::string vs = TypeString((vi > 1) ? '0' + vi : 'd', TDTypeVec[i]);
std::string tag = (vi > 1) ? vs : StructTag(TDTypeVec[i]);
OS << "typedef struct " << tag << " {\n";
OS << " " << ts << " val";
if (vi > 1)
if (vi > 1) {
OS << "typedef struct " << tag << " {\n";
OS << " " << ts << " val";
OS << "[" << utostr(vi) << "]";
OS << ";\n} " << vs << ";\n\n";
OS << ";\n} ";
} else {
OS << "typedef " << ts << " ";
}
OS << vs << ";\n\n";
}
}