1 //===- NeonEmitter.cpp - Generate arm_neon.h for use with clang -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend is responsible for emitting arm_neon.h, which includes
11 // a declaration and definition of each function specified by the ARM NEON
12 // compiler interface. See ARM document DUI0348B.
14 // Each NEON instruction is implemented in terms of 1 or more functions which
15 // are suffixed with the element type of the input vectors. Functions may be
16 // implemented in terms of generic vector operations such as +, *, -, etc. or
17 // by calling a __builtin_-prefixed function which will be handled by clang's
20 // Additional validation code can be generated by this file when runHeader() is
21 // called, rather than the normal run() entry point.
23 //===----------------------------------------------------------------------===//
25 #include "NeonEmitter.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringExtras.h"
33 /// ParseTypes - break down a string such as "fQf" into a vector of StringRefs,
34 /// which each StringRef representing a single type declared in the string.
35 /// for "fQf" we would end up with 2 StringRefs, "f", and "Qf", representing
36 /// 2xfloat and 4xfloat respectively.
37 static void ParseTypes(Record *r, std::string &s,
38 SmallVectorImpl<StringRef> &TV) {
39 const char *data = s.data();
42 for (unsigned i = 0, e = s.size(); i != e; ++i, ++len) {
43 if (data[len] == 'P' || data[len] == 'Q' || data[len] == 'U')
55 throw TGError(r->getLoc(),
56 "Unexpected letter: " + std::string(data + len, 1));
59 TV.push_back(StringRef(data, len + 1));
65 /// Widen - Convert a type code into the next wider type. char -> short,
66 /// short -> int, etc.
67 static char Widen(const char t) {
75 default: throw "unhandled type in widen!";
80 /// Narrow - Convert a type code into the next smaller type. short -> char,
81 /// float -> half float, etc.
82 static char Narrow(const char t) {
92 default: throw "unhandled type in widen!";
97 /// For a particular StringRef, return the base type code, and whether it has
98 /// the quad-vector, polynomial, or unsigned modifiers set.
99 static char ClassifyType(StringRef ty, bool &quad, bool &poly, bool &usgn) {
103 if (ty[off] == 'Q') {
109 if (ty[off] == 'P') {
114 // remember unsigned.
115 if (ty[off] == 'U') {
120 // base type to get the type string for.
124 /// ModType - Transform a type code and its modifiers based on a mod code. The
125 /// mod code definitions may be found at the top of arm_neon.td.
126 static char ModType(const char mod, char type, bool &quad, bool &poly,
127 bool &usgn, bool &scal, bool &cnst, bool &pntr) {
188 /// TypeString - for a modifier and type, generate the name of the typedef for
189 /// that type. If generic is true, emit the generic vector type rather than
190 /// the public NEON type. QUc -> uint8x8t_t / __neon_uint8x8_t.
191 static std::string TypeString(const char mod, StringRef typestr,
192 bool generic = false) {
205 // base type to get the type string for.
206 char type = ClassifyType(typestr, quad, poly, usgn);
208 // Based on the modifying character, change the type and width if necessary.
209 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
221 s += poly ? "poly8" : "int8";
224 s += quad ? "x16" : "x8";
227 s += poly ? "poly16" : "int16";
230 s += quad ? "x8" : "x4";
236 s += quad ? "x4" : "x2";
242 s += quad ? "x2" : "x1";
248 s += quad ? "x8" : "x4";
254 s += quad ? "x4" : "x2";
257 throw "unhandled type!";
268 // Append _t, finishing the type string typedef type.
280 /// TypeString - for a modifier and type, generate the clang BuiltinsARM.def
281 /// prototype code for the function. See the top of clang's Builtins.def for
282 /// a description of the type strings.
283 static std::string BuiltinTypeString(const char mod, StringRef typestr,
284 ClassKind ck, bool ret) {
297 // base type to get the type string for.
298 char type = ClassifyType(typestr, quad, poly, usgn);
300 // Based on the modifying character, change the type and width if necessary.
301 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
312 usgn = usgn | poly | ((ck == ClassI || ck == ClassW) && scal && type != 'f');
332 // Since the return value must be one type, return a vector type of the
333 // appropriate width which we will bitcast. An exception is made for
334 // returning structs of 2, 3, or 4 vectors which are returned in a sret-like
335 // fashion, storing them to a pointer arg.
337 if (mod == '2' || mod == '3' || mod == '4')
339 if (mod == 'f' || (ck != ClassB && type == 'f'))
340 return quad ? "V4f" : "V2f";
341 if (ck != ClassB && type == 's')
342 return quad ? "V8s" : "V4s";
343 if (ck != ClassB && type == 'i')
344 return quad ? "V4i" : "V2i";
345 if (ck != ClassB && type == 'l')
346 return quad ? "V2LLi" : "V1LLi";
348 return quad ? "V16c" : "V8c";
351 // Non-return array types are passed as individual vectors.
353 return quad ? "V16cV16c" : "V8cV8c";
355 return quad ? "V16cV16cV16c" : "V8cV8cV8c";
357 return quad ? "V16cV16cV16cV16c" : "V8cV8cV8cV8c";
359 if (mod == 'f' || (ck != ClassB && type == 'f'))
360 return quad ? "V4f" : "V2f";
361 if (ck != ClassB && type == 's')
362 return quad ? "V8s" : "V4s";
363 if (ck != ClassB && type == 'i')
364 return quad ? "V4i" : "V2i";
365 if (ck != ClassB && type == 'l')
366 return quad ? "V2LLi" : "V1LLi";
368 return quad ? "V16c" : "V8c";
371 /// MangleName - Append a type or width suffix to a base neon function name,
372 /// and insert a 'q' in the appropriate location if the operation works on
373 /// 128b rather than 64b. E.g. turn "vst2_lane" into "vst2q_lane_f32", etc.
374 static std::string MangleName(const std::string &name, StringRef typestr,
376 if (name == "vcvt_f32_f16")
382 char type = ClassifyType(typestr, quad, poly, usgn);
384 std::string s = name;
389 case ClassS: s += poly ? "_p8" : usgn ? "_u8" : "_s8"; break;
390 case ClassI: s += "_i8"; break;
391 case ClassW: s += "_8"; break;
397 case ClassS: s += poly ? "_p16" : usgn ? "_u16" : "_s16"; break;
398 case ClassI: s += "_i16"; break;
399 case ClassW: s += "_16"; break;
405 case ClassS: s += usgn ? "_u32" : "_s32"; break;
406 case ClassI: s += "_i32"; break;
407 case ClassW: s += "_32"; break;
413 case ClassS: s += usgn ? "_u64" : "_s64"; break;
414 case ClassI: s += "_i64"; break;
415 case ClassW: s += "_64"; break;
422 case ClassI: s += "_f16"; break;
423 case ClassW: s += "_16"; break;
430 case ClassI: s += "_f32"; break;
431 case ClassW: s += "_32"; break;
436 throw "unhandled type!";
442 // Insert a 'q' before the first '_' character so that it ends up before
443 // _lane or _n on vector-scalar operations.
445 size_t pos = s.find('_');
446 s = s.insert(pos, "q");
451 // Generate the string "(argtype a, argtype b, ...)"
452 static std::string GenArgs(const std::string &proto, StringRef typestr) {
453 bool define = proto.find('i') != std::string::npos;
459 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
461 s += TypeString(proto[i], typestr);
473 static std::string Duplicate(unsigned nElts, StringRef typestr,
474 const std::string &a) {
477 s = "(__neon_" + TypeString('d', typestr) + "){ ";
478 for (unsigned i = 0; i != nElts; ++i) {
488 // Generate the definition for this intrinsic, e.g. "a + b" for OpAdd.
489 // If structTypes is true, the NEON types are structs of vector types rather
490 // than vector types, and the call becomes "a.val + b.val"
491 static std::string GenOpString(OpKind op, const std::string &proto,
492 StringRef typestr, bool structTypes = true) {
493 bool dummy, quad = false;
494 char type = ClassifyType(typestr, quad, dummy, dummy);
497 case 'c': nElts = 8; break;
498 case 's': nElts = 4; break;
499 case 'i': nElts = 2; break;
500 case 'l': nElts = 1; break;
501 case 'h': nElts = 4; break;
502 case 'f': nElts = 2; break;
505 std::string ts = TypeString(proto[0], typestr);
506 std::string s = ts + " r; r";
514 if (proto.size() > 1)
515 a = (structTypes && proto[1] != 'l' && proto[1] != 's') ? "a.val" : "a";
516 b = structTypes ? "b.val" : "b";
517 c = structTypes ? "c.val" : "c";
527 b = Duplicate(nElts << (int)quad, typestr, "b");
532 c = Duplicate(nElts << (int)quad, typestr, "c");
534 s += a + " + ( " + b + " * " + c + " )";
537 c = Duplicate(nElts << (int)quad, typestr, "c");
539 s += a + " - ( " + b + " * " + c + " )";
542 s += "(__neon_" + ts + ")(" + a + " == " + b + ")";
545 s += "(__neon_" + ts + ")(" + a + " >= " + b + ")";
548 s += "(__neon_" + ts + ")(" + a + " <= " + b + ")";
551 s += "(__neon_" + ts + ")(" + a + " > " + b + ")";
554 s += "(__neon_" + ts + ")(" + a + " < " + b + ")";
578 s += "(__neon_" + ts + ")" + a;
581 s += "__builtin_shufflevector((__neon_int64x1_t)" + a;
582 s += ", (__neon_int64x1_t)" + b + ", 0, 1)";
585 s += "(__neon_int64x1_t)(((__neon_int64x2_t)" + a + ")[1])";
588 s += "(__neon_int64x1_t)(((__neon_int64x2_t)" + a + ")[0])";
591 s += Duplicate(nElts << (int)quad, typestr, a);
594 // ((0 & 1) | (~0 & 2))
595 ts = TypeString(proto[1], typestr);
596 s += "( " + a + " & (__neon_" + ts + ")" + b + ") | ";
597 s += "(~" + a + " & (__neon_" + ts + ")" + c + ")";
600 s += "__builtin_shufflevector(" + a + ", " + a;
601 for (unsigned i = 2; i <= nElts << (int)quad; i += 2)
602 for (unsigned j = 0; j != 2; ++j)
603 s += ", " + utostr(i - j - 1);
608 s += "__builtin_shufflevector(" + a + ", " + a;
609 for (unsigned i = nElts; i <= nElts << (1 + (int)quad); i += nElts)
610 for (unsigned j = 0; j != nElts; ++j)
611 s += ", " + utostr(i - j - 1);
615 s += "__builtin_shufflevector(" + a + ", " + a;
616 for (unsigned i = nElts; i <= nElts << (int)quad; i += nElts)
617 for (unsigned j = 0; j != nElts; ++j)
618 s += ", " + utostr(i - j - 1);
622 throw "unknown OpKind!";
629 static unsigned GetNeonEnum(const std::string &proto, StringRef typestr) {
630 unsigned mod = proto[0];
633 if (mod == 'v' || mod == 'f')
643 // base type to get the type string for.
644 char type = ClassifyType(typestr, quad, poly, usgn);
646 // Based on the modifying character, change the type and width if necessary.
647 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
674 throw "unhandled type!";
680 // Generate the definition for this intrinsic, e.g. __builtin_neon_cls(a)
681 // If structTypes is true, the NEON types are structs of vector types rather
682 // than vector types, and the call becomes __builtin_neon_cls(a.val)
683 static std::string GenBuiltin(const std::string &name, const std::string &proto,
684 StringRef typestr, ClassKind ck,
685 bool structTypes = true) {
686 bool dummy, quad = false;
687 char type = ClassifyType(typestr, quad, dummy, dummy);
690 case 'c': nElts = 8; break;
691 case 's': nElts = 4; break;
692 case 'i': nElts = 2; break;
693 case 'l': nElts = 1; break;
694 case 'h': nElts = 4; break;
695 case 'f': nElts = 2; break;
697 if (quad) nElts <<= 1;
702 // If this builtin returns a struct 2, 3, or 4 vectors, pass it as an implicit
703 // sret-like argument.
704 bool sret = (proto[0] == '2' || proto[0] == '3' || proto[0] == '4');
706 // If this builtin takes an immediate argument, we need to #define it rather
707 // than use a standard declaration, so that SemaChecking can range check
708 // the immediate passed by the user.
709 bool define = proto.find('i') != std::string::npos;
711 // If all types are the same size, bitcasting the args will take care
712 // of arg checking. The actual signedness etc. will be taken care of with
714 if (proto.find('s') == std::string::npos)
717 if (proto[0] != 'v') {
718 std::string ts = TypeString(proto[0], typestr);
722 s += "({ " + ts + " r; ";
723 else if (proto[0] != 's')
724 s += "(" + ts + "){(__neon_" + ts + ")";
729 if (structTypes && proto[0] != 's' && proto[0] != 'i' && proto[0] != 'l')
736 bool splat = proto.find('a') != std::string::npos;
738 s += "__builtin_neon_";
740 std::string vname(name, 0, name.size()-2);
741 s += MangleName(vname, typestr, ck);
743 s += MangleName(name, typestr, ck);
747 // Pass the address of the return variable as the first argument to sret-like
752 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
753 std::string args = std::string(&arg, 1);
755 args = "(" + args + ")";
757 // Handle multiple-vector values specially, emitting each subvector as an
758 // argument to the __builtin.
759 if (structTypes && (proto[i] == '2' || proto[i] == '3' || proto[i] == '4')){
760 for (unsigned vi = 0, ve = proto[i] - '0'; vi != ve; ++vi) {
761 s += args + ".val[" + utostr(vi) + "]";
771 if (splat && (i + 1) == e)
772 s += Duplicate(nElts, typestr, args);
776 if (structTypes && proto[i] != 's' && proto[i] != 'i' && proto[i] != 'l' &&
777 proto[i] != 'p' && proto[i] != 'c' && proto[i] != 'a') {
784 // Extra constant integer to hold type class enum for this function, e.g. s8
786 s += ", " + utostr(GetNeonEnum(proto, typestr));
793 if (proto[0] != 'v') {
797 else if (proto[0] != 's')
806 static std::string GenBuiltinDef(const std::string &name,
807 const std::string &proto,
808 StringRef typestr, ClassKind ck) {
809 std::string s("BUILTIN(__builtin_neon_");
811 // If all types are the same size, bitcasting the args will take care
812 // of arg checking. The actual signedness etc. will be taken care of with
814 if (proto.find('s') == std::string::npos)
817 s += MangleName(name, typestr, ck);
820 for (unsigned i = 0, e = proto.size(); i != e; ++i)
821 s += BuiltinTypeString(proto[i], typestr, ck, i == 0);
823 // Extra constant integer to hold type class enum for this function, e.g. s8
831 /// run - Read the records in arm_neon.td and output arm_neon.h. arm_neon.h
832 /// is comprised of type definitions and function declarations.
833 void NeonEmitter::run(raw_ostream &OS) {
834 EmitSourceFileHeader("ARM NEON Header", OS);
836 // FIXME: emit license into file?
838 OS << "#ifndef __ARM_NEON_H\n";
839 OS << "#define __ARM_NEON_H\n\n";
841 OS << "#ifndef __ARM_NEON__\n";
842 OS << "#error \"NEON support not enabled\"\n";
845 OS << "#include <stdint.h>\n\n";
847 // Emit NEON-specific scalar typedefs.
848 OS << "typedef float float32_t;\n";
849 OS << "typedef uint8_t poly8_t;\n";
850 OS << "typedef uint16_t poly16_t;\n";
851 OS << "typedef uint16_t float16_t;\n";
853 // Emit Neon vector typedefs.
854 std::string TypedefTypes("cQcsQsiQilQlUcQUcUsQUsUiQUiUlQUlhQhfQfPcQPcPsQPs");
855 SmallVector<StringRef, 24> TDTypeVec;
856 ParseTypes(0, TypedefTypes, TDTypeVec);
858 // Emit vector typedefs.
859 for (unsigned v = 1; v != 5; ++v) {
860 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
861 bool dummy, quad = false;
862 (void) ClassifyType(TDTypeVec[i], quad, dummy, dummy);
863 OS << "typedef __attribute__(( __vector_size__(";
865 OS << utostr(8*v*(quad ? 2 : 1)) << ") )) ";
869 OS << TypeString('s', TDTypeVec[i]);
872 char t = (v == 1) ? 'd' : '0' + v;
873 OS << TypeString(t, TDTypeVec[i]) << ";\n";
878 // Emit struct typedefs.
879 for (unsigned vi = 1; vi != 5; ++vi) {
880 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
881 std::string ts = TypeString('d', TDTypeVec[i]);
882 std::string vs = (vi > 1) ? TypeString('0' + vi, TDTypeVec[i]) : ts;
883 OS << "typedef struct __" << vs << " {\n";
884 OS << " __neon_" << ts << " val";
886 OS << "[" << utostr(vi) << "]";
887 OS << ";\n} " << vs << ";\n\n";
891 OS << "#define __ai static __attribute__((__always_inline__))\n\n";
893 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
895 // Unique the return+pattern types, and assign them.
896 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
898 std::string name = LowercaseString(R->getName());
899 std::string Proto = R->getValueAsString("Prototype");
900 std::string Types = R->getValueAsString("Types");
902 SmallVector<StringRef, 16> TypeVec;
903 ParseTypes(R, Types, TypeVec);
905 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
907 bool define = Proto.find('i') != std::string::npos;
909 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
910 assert(!Proto.empty() && "");
912 // static always inline + return type
916 OS << "__ai " << TypeString(Proto[0], TypeVec[ti]);
918 // Function name with type suffix
919 OS << " " << MangleName(name, TypeVec[ti], ClassS);
921 // Function arguments
922 OS << GenArgs(Proto, TypeVec[ti]);
931 OS << GenOpString(k, Proto, TypeVec[ti]);
933 if (R->getSuperClasses().size() < 2)
934 throw TGError(R->getLoc(), "Builtin has no class kind");
936 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
939 throw TGError(R->getLoc(), "Builtin has no class kind");
940 OS << GenBuiltin(name, Proto, TypeVec[ti], ck);
948 OS << "#undef __ai\n\n";
949 OS << "#endif /* __ARM_NEON_H */\n";
952 static unsigned RangeFromType(StringRef typestr) {
953 // base type to get the type string for.
954 bool quad = false, dummy = false;
955 char type = ClassifyType(typestr, quad, dummy, dummy);
959 return (8 << (int)quad) - 1;
962 return (4 << (int)quad) - 1;
965 return (2 << (int)quad) - 1;
967 return (1 << (int)quad) - 1;
969 throw "unhandled type!";
974 /// runHeader - Emit a file with sections defining:
975 /// 1. the NEON section of BuiltinsARM.def.
976 /// 2. the SemaChecking code for the type overload checking.
977 /// 3. the SemaChecking code for validation of intrinsic immedate arguments.
978 void NeonEmitter::runHeader(raw_ostream &OS) {
979 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
981 StringMap<OpKind> EmittedMap;
983 // Generate BuiltinsARM.def for NEON
984 OS << "#ifdef GET_NEON_BUILTINS\n";
985 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
987 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
991 std::string Proto = R->getValueAsString("Prototype");
993 // Functions with 'a' (the splat code) in the type prototype should not get
994 // their own builtin as they use the non-splat variant.
995 if (Proto.find('a') != std::string::npos)
998 std::string Types = R->getValueAsString("Types");
999 SmallVector<StringRef, 16> TypeVec;
1000 ParseTypes(R, Types, TypeVec);
1002 if (R->getSuperClasses().size() < 2)
1003 throw TGError(R->getLoc(), "Builtin has no class kind");
1005 std::string name = LowercaseString(R->getName());
1006 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1008 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1009 // Generate the BuiltinsARM.def declaration for this builtin, ensuring
1010 // that each unique BUILTIN() macro appears only once in the output
1012 std::string bd = GenBuiltinDef(name, Proto, TypeVec[ti], ck);
1013 if (EmittedMap.count(bd))
1016 EmittedMap[bd] = OpNone;
1022 // Generate the overloaded type checking code for SemaChecking.cpp
1023 OS << "#ifdef GET_NEON_OVERLOAD_CHECK\n";
1024 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1026 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1030 std::string Proto = R->getValueAsString("Prototype");
1031 std::string Types = R->getValueAsString("Types");
1032 std::string name = LowercaseString(R->getName());
1034 // Functions with 'a' (the splat code) in the type prototype should not get
1035 // their own builtin as they use the non-splat variant.
1036 if (Proto.find('a') != std::string::npos)
1039 // Functions which have a scalar argument cannot be overloaded, no need to
1040 // check them if we are emitting the type checking code.
1041 if (Proto.find('s') != std::string::npos)
1044 SmallVector<StringRef, 16> TypeVec;
1045 ParseTypes(R, Types, TypeVec);
1047 if (R->getSuperClasses().size() < 2)
1048 throw TGError(R->getLoc(), "Builtin has no class kind");
1050 int si = -1, qi = -1;
1051 unsigned mask = 0, qmask = 0;
1052 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1053 // Generate the switch case(s) for this builtin for the type validation.
1054 bool quad = false, poly = false, usgn = false;
1055 (void) ClassifyType(TypeVec[ti], quad, poly, usgn);
1059 qmask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1062 mask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1066 OS << "case ARM::BI__builtin_neon_"
1067 << MangleName(name, TypeVec[si], ClassB)
1068 << ": mask = " << "0x" << utohexstr(mask) << "; break;\n";
1070 OS << "case ARM::BI__builtin_neon_"
1071 << MangleName(name, TypeVec[qi], ClassB)
1072 << ": mask = " << "0x" << utohexstr(qmask) << "; break;\n";
1076 // Generate the intrinsic range checking code for shift/lane immediates.
1077 OS << "#ifdef GET_NEON_IMMEDIATE_CHECK\n";
1078 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1081 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1085 std::string name = LowercaseString(R->getName());
1086 std::string Proto = R->getValueAsString("Prototype");
1087 std::string Types = R->getValueAsString("Types");
1089 // Functions with 'a' (the splat code) in the type prototype should not get
1090 // their own builtin as they use the non-splat variant.
1091 if (Proto.find('a') != std::string::npos)
1094 // Functions which do not have an immediate do not need to have range
1095 // checking code emitted.
1096 if (Proto.find('i') == std::string::npos)
1099 SmallVector<StringRef, 16> TypeVec;
1100 ParseTypes(R, Types, TypeVec);
1102 if (R->getSuperClasses().size() < 2)
1103 throw TGError(R->getLoc(), "Builtin has no class kind");
1105 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1107 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1108 std::string namestr, shiftstr, rangestr;
1110 // Builtins which are overloaded by type will need to have their upper
1111 // bound computed at Sema time based on the type constant.
1112 if (Proto.find('s') == std::string::npos) {
1114 if (R->getValueAsBit("isShift")) {
1115 shiftstr = ", true";
1117 // Right shifts have an 'r' in the name, left shifts do not.
1118 if (name.find('r') != std::string::npos)
1119 rangestr = "l = 1; ";
1121 rangestr += "u = RFT(TV" + shiftstr + ")";
1123 rangestr = "u = " + utostr(RangeFromType(TypeVec[ti]));
1125 // Make sure cases appear only once by uniquing them in a string map.
1126 namestr = MangleName(name, TypeVec[ti], ck);
1127 if (EmittedMap.count(namestr))
1129 EmittedMap[namestr] = OpNone;
1131 // Calculate the index of the immediate that should be range checked.
1132 unsigned immidx = 0;
1134 // Builtins that return a struct of multiple vectors have an extra
1135 // leading arg for the struct return.
1136 if (Proto[0] == '2' || Proto[0] == '3' || Proto[0] == '4')
1139 // Add one to the index for each argument until we reach the immediate
1140 // to be checked. Structs of vectors are passed as multiple arguments.
1141 for (unsigned ii = 1, ie = Proto.size(); ii != ie; ++ii) {
1142 switch (Proto[ii]) {
1143 default: immidx += 1; break;
1144 case '2': immidx += 2; break;
1145 case '3': immidx += 3; break;
1146 case '4': immidx += 4; break;
1147 case 'i': ie = ii + 1; break;
1150 OS << "case ARM::BI__builtin_neon_" << MangleName(name, TypeVec[ti], ck)
1151 << ": i = " << immidx << "; " << rangestr << "; break;\n";