2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef PredictedType_h
30 #define PredictedType_h
38 typedef uint32_t PredictedType;
39 static const PredictedType PredictNone = 0x00000000; // We don't know anything yet.
40 static const PredictedType PredictFinalObject = 0x00000001; // It's definitely a JSFinalObject.
41 static const PredictedType PredictArray = 0x00000002; // It's definitely a JSArray.
42 static const PredictedType PredictByteArray = 0x00000004; // It's definitely a JSByteArray or one of its subclasses.
43 static const PredictedType PredictFunction = 0x00000008; // It's definitely a JSFunction or one of its subclasses.
44 static const PredictedType PredictInt8Array = 0x00000010; // It's definitely an Int8Array or one of its subclasses.
45 static const PredictedType PredictInt16Array = 0x00000020; // It's definitely an Int16Array or one of its subclasses.
46 static const PredictedType PredictInt32Array = 0x00000040; // It's definitely an Int32Array or one of its subclasses.
47 static const PredictedType PredictUint8Array = 0x00000080; // It's definitely an Uint8Array or one of its subclasses.
48 static const PredictedType PredictUint16Array = 0x00000100; // It's definitely an Uint16Array or one of its subclasses.
49 static const PredictedType PredictUint32Array = 0x00000200; // It's definitely an Uint32Array or one of its subclasses.
50 static const PredictedType PredictFloat32Array = 0x00000400; // It's definitely an Uint16Array or one of its subclasses.
51 static const PredictedType PredictFloat64Array = 0x00000800; // It's definitely an Uint16Array or one of its subclasses.
52 static const PredictedType PredictObjectOther = 0x00001000; // It's definitely an object but not JSFinalObject, JSArray, JSByteArray, or JSFunction.
53 static const PredictedType PredictObjectMask = 0x00001fff; // Bitmask used for testing for any kind of object prediction.
54 static const PredictedType PredictString = 0x00002000; // It's definitely a JSString.
55 static const PredictedType PredictCellOther = 0x00004000; // It's definitely a JSCell but not a subclass of JSObject and definitely not a JSString.
56 static const PredictedType PredictCell = 0x00007fff; // It's definitely a JSCell.
57 static const PredictedType PredictInt32 = 0x00008000; // It's definitely an Int32.
58 static const PredictedType PredictDoubleReal = 0x00010000; // It's definitely a non-NaN double.
59 static const PredictedType PredictDoubleNaN = 0x00020000; // It's definitely a NaN.
60 static const PredictedType PredictDouble = 0x00030000; // It's either a non-NaN or a NaN double.
61 static const PredictedType PredictNumber = 0x00038000; // It's either an Int32 or a Double.
62 static const PredictedType PredictBoolean = 0x00040000; // It's definitely a Boolean.
63 static const PredictedType PredictOther = 0x40000000; // It's definitely none of the above.
64 static const PredictedType PredictTop = 0x7fffffff; // It can be any of the above.
65 static const PredictedType FixedIndexedStorageMask = PredictByteArray | PredictInt8Array | PredictInt16Array | PredictInt32Array | PredictUint8Array | PredictUint16Array | PredictUint32Array | PredictFloat32Array | PredictFloat64Array;
67 typedef bool (*PredictionChecker)(PredictedType);
69 inline bool isCellPrediction(PredictedType value)
71 return !!(value & PredictCell) && !(value & ~PredictCell);
74 inline bool isObjectPrediction(PredictedType value)
76 return !!(value & PredictObjectMask) && !(value & ~PredictObjectMask);
79 inline bool isFinalObjectPrediction(PredictedType value)
81 return value == PredictFinalObject;
84 inline bool isFinalObjectOrOtherPrediction(PredictedType value)
86 return !!(value & (PredictFinalObject | PredictOther)) && !(value & ~(PredictFinalObject | PredictOther));
89 inline bool isFixedIndexedStorageObjectPrediction(PredictedType value)
91 return (value & FixedIndexedStorageMask) == value;
94 inline bool isStringPrediction(PredictedType value)
96 return value == PredictString;
99 inline bool isArrayPrediction(PredictedType value)
101 return value == PredictArray;
104 inline bool isFunctionPrediction(PredictedType value)
106 return value == PredictFunction;
109 inline bool isByteArrayPrediction(PredictedType value)
111 return value == PredictByteArray;
114 inline bool isInt8ArrayPrediction(PredictedType value)
116 return value == PredictInt8Array;
119 inline bool isInt16ArrayPrediction(PredictedType value)
121 return value == PredictInt16Array;
124 inline bool isInt32ArrayPrediction(PredictedType value)
126 return value == PredictInt32Array;
129 inline bool isUint8ArrayPrediction(PredictedType value)
131 return value == PredictUint8Array;
134 inline bool isUint16ArrayPrediction(PredictedType value)
136 return value == PredictUint16Array;
139 inline bool isUint32ArrayPrediction(PredictedType value)
141 return value == PredictUint32Array;
144 inline bool isFloat32ArrayPrediction(PredictedType value)
146 return value == PredictFloat32Array;
149 inline bool isFloat64ArrayPrediction(PredictedType value)
151 return value == PredictFloat64Array;
154 inline bool isActionableMutableArrayPrediction(PredictedType value)
156 return isArrayPrediction(value)
157 || isByteArrayPrediction(value)
158 || isInt8ArrayPrediction(value)
159 || isInt16ArrayPrediction(value)
160 || isInt32ArrayPrediction(value)
161 || isUint8ArrayPrediction(value)
162 || isUint16ArrayPrediction(value)
163 || isUint32ArrayPrediction(value)
164 #if CPU(X86) || CPU(X86_64)
165 || isFloat32ArrayPrediction(value)
167 || isFloat64ArrayPrediction(value);
170 inline bool isActionableArrayPrediction(PredictedType value)
172 return isStringPrediction(value)
173 || isActionableMutableArrayPrediction(value);
176 inline bool isArrayOrOtherPrediction(PredictedType value)
178 return !!(value & (PredictArray | PredictOther)) && !(value & ~(PredictArray | PredictOther));
181 inline bool isInt32Prediction(PredictedType value)
183 return value == PredictInt32;
186 inline bool isDoubleRealPrediction(PredictedType value)
188 return value == PredictDoubleReal;
191 inline bool isDoublePrediction(PredictedType value)
193 return (value & PredictDouble) == value;
196 inline bool isNumberPrediction(PredictedType value)
198 return !!(value & PredictNumber) && !(value & ~PredictNumber);
201 inline bool isBooleanPrediction(PredictedType value)
203 return value == PredictBoolean;
206 inline bool isOtherPrediction(PredictedType value)
208 return value == PredictOther;
212 const char* predictionToString(PredictedType value);
215 // Merge two predictions. Note that currently this just does left | right. It may
216 // seem tempting to do so directly, but you would be doing so at your own peril,
217 // since the merging protocol PredictedType may change at any time (and has already
218 // changed several times in its history).
219 inline PredictedType mergePredictions(PredictedType left, PredictedType right)
225 inline bool mergePrediction(T& left, PredictedType right)
227 PredictedType newPrediction = static_cast<T>(mergePredictions(static_cast<PredictedType>(left), right));
228 bool result = newPrediction != static_cast<PredictedType>(left);
229 left = newPrediction;
233 PredictedType predictionFromClassInfo(const ClassInfo*);
234 PredictedType predictionFromStructure(Structure*);
235 PredictedType predictionFromCell(JSCell*);
236 PredictedType predictionFromValue(JSValue);
240 #endif // PredictedType_h