1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 /*****************************************************************************/
8 /*****************************************************************************/
11 enum var_types_classification
15 VTF_UNS = 0x0002, // type is unsigned
17 VTF_GCR = 0x0008, // type is GC ref
18 VTF_BYR = 0x0010, // type is Byref
19 VTF_I = 0x0020, // is machine sized
20 VTF_S = 0x0040, // is a struct type
25 #define DEF_TP(tn, nm, jitType, verType, sz, sze, asze, st, al, tf, howUsed) TYP_##tn,
31 TYP_lastIntrins = TYP_DOUBLE
34 /*****************************************************************************
35 * C-style pointers are implemented as TYP_INT or TYP_LONG depending on the
40 #define TYP_I_IMPL TYP_LONG
41 #define TYP_U_IMPL TYP_ULONG
42 #define TYPE_REF_IIM TYPE_REF_LNG
44 #define TYP_I_IMPL TYP_INT
45 #define TYP_U_IMPL TYP_UINT
46 #define TYPE_REF_IIM TYPE_REF_INT
48 // We silence this in the 32-bit build because for portability, we like to have asserts like this:
49 // assert(op2->gtType == TYP_INT || op2->gtType == TYP_I_IMPL);
50 // This is obviously redundant for 32-bit builds, but we don't want to have ifdefs and different
51 // asserts just for 64-bit builds, so for now just silence the assert
52 #pragma warning(disable : 6287) // warning 6287: the left and right sub-expressions are identical
56 /*****************************************************************************/
58 const extern BYTE varTypeClassification[TYP_COUNT];
60 // make any class with a TypeGet member also have a function TypeGet() that does the same thing
62 inline var_types TypeGet(T* t)
67 // make a TypeGet function which is the identity function for var_types
68 // the point of this and the preceding template is now you can make template functions
69 // that work on var_types as well as any object that exposes a TypeGet method.
70 // such as all of these varTypeIs* functions
71 inline var_types TypeGet(var_types v)
78 inline bool varTypeIsSIMD(T vt)
93 // Always return false if FEATURE_SIMD is not enabled
95 inline bool varTypeIsSIMD(T vt)
99 #endif // !FEATURE_SIMD
102 inline bool varTypeIsIntegral(T vt)
104 return ((varTypeClassification[TypeGet(vt)] & (VTF_INT)) != 0);
108 inline bool varTypeIsIntegralOrI(T vt)
110 return ((varTypeClassification[TypeGet(vt)] & (VTF_INT | VTF_I)) != 0);
114 inline bool varTypeIsUnsigned(T vt)
116 return ((varTypeClassification[TypeGet(vt)] & (VTF_UNS)) != 0);
119 // If "vt" is an unsigned integral type, returns the corresponding signed integral type, otherwise
121 inline var_types varTypeUnsignedToSigned(var_types vt)
123 if (varTypeIsUnsigned(vt))
147 inline bool varTypeIsFloating(T vt)
149 return ((varTypeClassification[TypeGet(vt)] & (VTF_FLT)) != 0);
153 inline bool varTypeIsArithmetic(T vt)
155 return ((varTypeClassification[TypeGet(vt)] & (VTF_INT | VTF_FLT)) != 0);
159 inline unsigned varTypeGCtype(T vt)
161 return (unsigned)(varTypeClassification[TypeGet(vt)] & (VTF_GCR | VTF_BYR));
165 inline bool varTypeIsGC(T vt)
167 return (varTypeGCtype(vt) != 0);
171 inline bool varTypeIsI(T vt)
173 return ((varTypeClassification[TypeGet(vt)] & VTF_I) != 0);
177 inline bool varTypeCanReg(T vt)
179 return ((varTypeClassification[TypeGet(vt)] & (VTF_INT | VTF_I | VTF_FLT)) != 0);
183 inline bool varTypeIsByte(T vt)
185 return (TypeGet(vt) >= TYP_BOOL) && (TypeGet(vt) <= TYP_UBYTE);
189 inline bool varTypeIsShort(T vt)
191 return (TypeGet(vt) == TYP_SHORT) || (TypeGet(vt) == TYP_USHORT);
195 inline bool varTypeIsSmall(T vt)
197 return (TypeGet(vt) >= TYP_BOOL) && (TypeGet(vt) <= TYP_USHORT);
201 inline bool varTypeIsSmallInt(T vt)
203 return (TypeGet(vt) >= TYP_BYTE) && (TypeGet(vt) <= TYP_USHORT);
207 inline bool varTypeIsIntOrI(T vt)
209 return ((TypeGet(vt) == TYP_INT)
210 #ifdef _TARGET_64BIT_
211 || (TypeGet(vt) == TYP_I_IMPL)
212 #endif // _TARGET_64BIT_
217 inline bool genActualTypeIsIntOrI(T vt)
219 return ((TypeGet(vt) >= TYP_BOOL) && (TypeGet(vt) <= TYP_U_IMPL));
223 inline bool varTypeIsLong(T vt)
225 return (TypeGet(vt) >= TYP_LONG) && (TypeGet(vt) <= TYP_ULONG);
229 inline bool varTypeIsMultiReg(T vt)
231 #ifdef _TARGET_64BIT_
234 return (TypeGet(vt) == TYP_LONG);
239 inline bool varTypeIsSingleReg(T vt)
241 return !varTypeIsMultiReg(vt);
245 inline bool varTypeIsComposite(T vt)
247 return (!varTypeIsArithmetic(TypeGet(vt)) && TypeGet(vt) != TYP_VOID);
250 // Is this type promotable?
251 // In general only structs are promotable.
252 // However, a SIMD type, e.g. TYP_SIMD may be handled as either a struct, OR a
253 // fully-promoted register type.
254 // On 32-bit systems longs are split into an upper and lower half, and they are
255 // handled as if they are structs with two integer fields.
258 inline bool varTypeIsPromotable(T vt)
260 return (varTypeIsStruct(vt) || (TypeGet(vt) == TYP_BLK)
261 #if !defined(_TARGET_64BIT_)
263 #endif // !defined(_TARGET_64BIT_)
268 inline bool varTypeIsStruct(T vt)
270 return ((varTypeClassification[TypeGet(vt)] & VTF_S) != 0);
274 inline bool varTypeIsEnregisterableStruct(T vt)
276 return (TypeGet(vt) != TYP_STRUCT);
279 /*****************************************************************************/
280 #endif // _VARTYPE_H_
281 /*****************************************************************************/