Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/types.h

Issue 759013003: Avoid number range holes in bitset types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Another rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/typer.cc ('k') | src/types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_TYPES_H_ 5 #ifndef V8_TYPES_H_
6 #define V8_TYPES_H_ 6 #define V8_TYPES_H_
7 7
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/handles.h" 10 #include "src/handles.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // ----------------------------------------------------------------------------- 153 // -----------------------------------------------------------------------------
154 // Values for bitset types 154 // Values for bitset types
155 155
156 #define MASK_BITSET_TYPE_LIST(V) \ 156 #define MASK_BITSET_TYPE_LIST(V) \
157 V(Representation, 0xff800000u) \ 157 V(Representation, 0xff800000u) \
158 V(Semantic, 0x007ffffeu) 158 V(Semantic, 0x007ffffeu)
159 159
160 #define REPRESENTATION(k) ((k) & BitsetType::kRepresentation) 160 #define REPRESENTATION(k) ((k) & BitsetType::kRepresentation)
161 #define SEMANTIC(k) ((k) & BitsetType::kSemantic) 161 #define SEMANTIC(k) ((k) & BitsetType::kSemantic)
162 162
163 #define REPRESENTATION_BITSET_TYPE_LIST(V) \ 163 #define REPRESENTATION_BITSET_TYPE_LIST(V) \
164 V(None, 0) \ 164 V(None, 0) \
165 V(UntaggedInt1, 1u << 23 | kSemantic) \ 165 V(UntaggedInt1, 1u << 23 | kSemantic) \
166 V(UntaggedInt8, 1u << 24 | kSemantic) \ 166 V(UntaggedInt8, 1u << 24 | kSemantic) \
167 V(UntaggedInt16, 1u << 25 | kSemantic) \ 167 V(UntaggedInt16, 1u << 25 | kSemantic) \
168 V(UntaggedInt32, 1u << 26 | kSemantic) \ 168 V(UntaggedInt32, 1u << 26 | kSemantic) \
169 V(UntaggedFloat32, 1u << 27 | kSemantic) \ 169 V(UntaggedFloat32, 1u << 27 | kSemantic) \
170 V(UntaggedFloat64, 1u << 28 | kSemantic) \ 170 V(UntaggedFloat64, 1u << 28 | kSemantic) \
171 V(UntaggedPtr, 1u << 29 | kSemantic) \ 171 V(UntaggedPtr, 1u << 29 | kSemantic) \
172 V(TaggedInt, 1u << 30 | kSemantic) \ 172 V(TaggedInt, 1u << 30 | kSemantic) \
173 V(TaggedPtr, 1u << 31 | kSemantic) \ 173 V(TaggedPtr, 1u << 31 | kSemantic) \
174 \ 174 \
175 V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \ 175 V(UntaggedInt, kUntaggedInt1 | kUntaggedInt8 | \
176 kUntaggedInt16 | kUntaggedInt32) \ 176 kUntaggedInt16 | kUntaggedInt32) \
177 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \ 177 V(UntaggedFloat, kUntaggedFloat32 | kUntaggedFloat64) \
178 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \ 178 V(UntaggedNumber, kUntaggedInt | kUntaggedFloat) \
179 V(Untagged, kUntaggedNumber | kUntaggedPtr) \ 179 V(Untagged, kUntaggedNumber | kUntaggedPtr) \
180 V(Tagged, kTaggedInt | kTaggedPtr) 180 V(Tagged, kTaggedInt | kTaggedPtr)
181 181
182 #define SEMANTIC_BITSET_TYPE_LIST(V) \ 182 #define INTERNAL_BITSET_TYPE_LIST(V) \
183 V(Null, 1u << 1 | REPRESENTATION(kTaggedPtr)) \ 183 V(OtherUnsigned31, 1u << 1 | REPRESENTATION(kTagged | kUntaggedNumber)) \
184 V(Undefined, 1u << 2 | REPRESENTATION(kTaggedPtr)) \ 184 V(OtherUnsigned32, 1u << 2 | REPRESENTATION(kTagged | kUntaggedNumber)) \
185 V(Boolean, 1u << 3 | REPRESENTATION(kTaggedPtr)) \ 185 V(OtherSigned32, 1u << 3 | REPRESENTATION(kTagged | kUntaggedNumber)) \
186 V(UnsignedSmall, 1u << 4 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 186 V(OtherNumber, 1u << 4 | REPRESENTATION(kTagged | kUntaggedNumber))
187 V(OtherSignedSmall, 1u << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 187
188 V(OtherUnsigned31, 1u << 6 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 188 #define SEMANTIC_BITSET_TYPE_LIST(V) \
189 V(OtherUnsigned32, 1u << 7 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 189 V(NegativeSignedSmall, 1u << 5 | REPRESENTATION(kTagged | kUntaggedNumber)) \
190 V(OtherSigned32, 1u << 8 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 190 V(Null, 1u << 6 | REPRESENTATION(kTaggedPtr)) \
191 V(MinusZero, 1u << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 191 V(Undefined, 1u << 7 | REPRESENTATION(kTaggedPtr)) \
192 V(NaN, 1u << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 192 V(Boolean, 1u << 8 | REPRESENTATION(kTaggedPtr)) \
193 V(OtherNumber, 1u << 11 | REPRESENTATION(kTagged | kUntaggedNumber)) \ 193 V(UnsignedSmall, 1u << 9 | REPRESENTATION(kTagged | kUntaggedNumber)) \
194 V(Symbol, 1u << 12 | REPRESENTATION(kTaggedPtr)) \ 194 V(MinusZero, 1u << 10 | REPRESENTATION(kTagged | kUntaggedNumber)) \
195 V(InternalizedString, 1u << 13 | REPRESENTATION(kTaggedPtr)) \ 195 V(NaN, 1u << 11 | REPRESENTATION(kTagged | kUntaggedNumber)) \
196 V(OtherString, 1u << 14 | REPRESENTATION(kTaggedPtr)) \ 196 V(Symbol, 1u << 12 | REPRESENTATION(kTaggedPtr)) \
197 V(Undetectable, 1u << 15 | REPRESENTATION(kTaggedPtr)) \ 197 V(InternalizedString, 1u << 13 | REPRESENTATION(kTaggedPtr)) \
198 V(Array, 1u << 16 | REPRESENTATION(kTaggedPtr)) \ 198 V(OtherString, 1u << 14 | REPRESENTATION(kTaggedPtr)) \
199 V(Buffer, 1u << 17 | REPRESENTATION(kTaggedPtr)) \ 199 V(Undetectable, 1u << 15 | REPRESENTATION(kTaggedPtr)) \
200 V(Function, 1u << 18 | REPRESENTATION(kTaggedPtr)) \ 200 V(Array, 1u << 16 | REPRESENTATION(kTaggedPtr)) \
201 V(RegExp, 1u << 19 | REPRESENTATION(kTaggedPtr)) \ 201 V(Buffer, 1u << 17 | REPRESENTATION(kTaggedPtr)) \
202 V(OtherObject, 1u << 20 | REPRESENTATION(kTaggedPtr)) \ 202 V(Function, 1u << 18 | REPRESENTATION(kTaggedPtr)) \
203 V(Proxy, 1u << 21 | REPRESENTATION(kTaggedPtr)) \ 203 V(RegExp, 1u << 19 | REPRESENTATION(kTaggedPtr)) \
204 V(Internal, 1u << 22 | REPRESENTATION(kTagged | kUntagged)) \ 204 V(OtherObject, 1u << 20 | REPRESENTATION(kTaggedPtr)) \
205 \ 205 V(Proxy, 1u << 21 | REPRESENTATION(kTaggedPtr)) \
206 V(SignedSmall, kUnsignedSmall | kOtherSignedSmall) \ 206 V(Internal, 1u << 22 | REPRESENTATION(kTagged | kUntagged)) \
207 V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \ 207 \
208 V(Unsigned32, kUnsignedSmall | kOtherUnsigned31 | kOtherUnsigned32) \ 208 V(SignedSmall, kUnsignedSmall | kNegativeSignedSmall) \
209 V(Integral32, kSigned32 | kUnsigned32) \ 209 V(Signed32, kSignedSmall | kOtherUnsigned31 | kOtherSigned32) \
210 V(OrderedNumber, kIntegral32 | kMinusZero | kOtherNumber) \ 210 V(NegativeSigned32, kNegativeSignedSmall | kOtherSigned32) \
211 V(Number, kOrderedNumber | kNaN) \ 211 V(NonNegativeSigned32, kUnsignedSmall | kOtherUnsigned31) \
212 V(String, kInternalizedString | kOtherString) \ 212 V(Unsigned32, kNonNegativeSigned32 | kOtherUnsigned32) \
213 V(UniqueName, kSymbol | kInternalizedString) \ 213 V(Integral32, kSigned32 | kUnsigned32) \
214 V(Name, kSymbol | kString) \ 214 V(PlainNumber, kIntegral32 | kOtherNumber) \
215 V(NumberOrString, kNumber | kString) \ 215 V(OrderedNumber, kPlainNumber | kMinusZero) \
216 V(PlainPrimitive, kNumberOrString | kBoolean | kNull | kUndefined) \ 216 V(Number, kOrderedNumber | kNaN) \
217 V(Primitive, kSymbol | kPlainPrimitive) \ 217 V(String, kInternalizedString | kOtherString) \
218 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \ 218 V(UniqueName, kSymbol | kInternalizedString) \
219 V(DetectableReceiver, kDetectableObject | kProxy) \ 219 V(Name, kSymbol | kString) \
220 V(Detectable, kDetectableReceiver | kNumber | kName) \ 220 V(NumberOrString, kNumber | kString) \
221 V(Object, kDetectableObject | kUndetectable) \ 221 V(PlainPrimitive, kNumberOrString | kBoolean | kNull | kUndefined) \
222 V(Receiver, kObject | kProxy) \ 222 V(Primitive, kSymbol | kPlainPrimitive) \
223 V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \ 223 V(DetectableObject, kArray | kFunction | kRegExp | kOtherObject) \
224 kReceiver) \ 224 V(DetectableReceiver, kDetectableObject | kProxy) \
225 V(NonNumber, kUnique | kString | kInternal) \ 225 V(Detectable, kDetectableReceiver | kNumber | kName) \
226 V(Any, 0xfffffffeu) 226 V(Object, kDetectableObject | kUndetectable) \
227 V(Receiver, kObject | kProxy) \
228 V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \
229 kReceiver) \
230 V(NonNumber, kUnique | kString | kInternal) \
231 V(Any, 0xfffffffeu)
227 232
228 /* 233 /*
229 * The following diagrams show how integers (in the mathematical sense) are 234 * The following diagrams show how integers (in the mathematical sense) are
230 * divided among the different atomic numerical types. 235 * divided among the different atomic numerical types.
231 * 236 *
232 * If SmiValuesAre31Bits(): 237 * If SmiValuesAre31Bits():
233 * 238 *
234 * ON OS32 OSS US OU31 OU32 ON 239 * ON OS32 OSS US OU31 OU32 ON
235 * ______[_______[_______[_______[_______[_______[_______ 240 * ______[_______[_______[_______[_______[_______[_______
236 * -2^31 -2^30 0 2^30 2^31 2^32 241 * -2^31 -2^30 0 2^30 2^31 2^32
237 * 242 *
238 * Otherwise: 243 * Otherwise:
239 * 244 *
240 * ON OSS US OU32 ON 245 * ON OSS US OU32 ON
241 * ______[_______________[_______________[_______[_______ 246 * ______[_______________[_______________[_______[_______
242 * -2^31 0 2^31 2^32 247 * -2^31 0 2^31 2^32
243 * 248 *
244 * 249 *
245 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1. 250 * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1.
246 * 251 *
247 * NOTE: OtherSigned32 (OS32) and OU31 (OtherUnsigned31) are empty if Smis are 252 * NOTE: OtherSigned32 (OS32) and OU31 (OtherUnsigned31) are empty if Smis are
248 * 32-bit wide. They should thus never be used directly, only indirectly 253 * 32-bit wide. They should thus never be used directly, only indirectly
249 * via e.g. Number. 254 * via e.g. Number.
250 */ 255 */
251 256
252 #define PROPER_BITSET_TYPE_LIST(V) \ 257 #define PROPER_BITSET_TYPE_LIST(V) \
253 REPRESENTATION_BITSET_TYPE_LIST(V) \ 258 REPRESENTATION_BITSET_TYPE_LIST(V) \
254 SEMANTIC_BITSET_TYPE_LIST(V) 259 SEMANTIC_BITSET_TYPE_LIST(V)
255 260
256 #define BITSET_TYPE_LIST(V) \ 261 #define BITSET_TYPE_LIST(V) \
257 MASK_BITSET_TYPE_LIST(V) \ 262 MASK_BITSET_TYPE_LIST(V) \
258 PROPER_BITSET_TYPE_LIST(V) 263 REPRESENTATION_BITSET_TYPE_LIST(V) \
264 INTERNAL_BITSET_TYPE_LIST(V) \
265 SEMANTIC_BITSET_TYPE_LIST(V)
259 266
260 267
261 // ----------------------------------------------------------------------------- 268 // -----------------------------------------------------------------------------
262 // The abstract Type class, parameterized over the low-level representation. 269 // The abstract Type class, parameterized over the low-level representation.
263 270
264 // struct Config { 271 // struct Config {
265 // typedef TypeImpl<Config> Type; 272 // typedef TypeImpl<Config> Type;
266 // typedef Base; 273 // typedef Base;
267 // typedef Struct; 274 // typedef Struct;
268 // typedef Region; 275 // typedef Region;
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 #define DECLARE_TYPE(type, value) k##type = (value), 592 #define DECLARE_TYPE(type, value) k##type = (value),
586 BITSET_TYPE_LIST(DECLARE_TYPE) 593 BITSET_TYPE_LIST(DECLARE_TYPE)
587 #undef DECLARE_TYPE 594 #undef DECLARE_TYPE
588 kUnusedEOL = 0 595 kUnusedEOL = 0
589 }; 596 };
590 597
591 bitset Bitset() { return Config::as_bitset(this); } 598 bitset Bitset() { return Config::as_bitset(this); }
592 599
593 static TypeImpl* New(bitset bits) { 600 static TypeImpl* New(bitset bits) {
594 DCHECK(bits == kNone || IsInhabited(bits)); 601 DCHECK(bits == kNone || IsInhabited(bits));
602
603 if (FLAG_enable_slow_asserts) {
604 // Check that the bitset does not contain any holes in number ranges.
605 bitset mask = kSemantic;
606 if (!i::SmiValuesAre31Bits()) {
607 mask &= ~(kOtherUnsigned31 | kOtherSigned32);
608 }
609 bitset number_bits = bits & kPlainNumber & mask;
610 if (number_bits != 0) {
611 bitset lub = Lub(Min(number_bits), Max(number_bits)) & mask;
612 CHECK(lub == number_bits);
613 }
614 }
615
595 return Config::from_bitset(bits); 616 return Config::from_bitset(bits);
596 } 617 }
597 static TypeHandle New(bitset bits, Region* region) { 618 static TypeHandle New(bitset bits, Region* region) {
598 DCHECK(bits == kNone || IsInhabited(bits)); 619 DCHECK(bits == kNone || IsInhabited(bits));
599 return Config::from_bitset(bits, region); 620 return Config::from_bitset(bits, region);
600 } 621 }
601 // TODO(neis): Eventually allow again for types with empty semantics 622 // TODO(neis): Eventually allow again for types with empty semantics
602 // part and modify intersection and possibly subtyping accordingly. 623 // part and modify intersection and possibly subtyping accordingly.
603 624
604 static bool IsInhabited(bitset bits) { 625 static bool IsInhabited(bitset bits) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 bool Narrows(BoundsImpl that) { 1085 bool Narrows(BoundsImpl that) {
1065 return that.lower->Is(this->lower) && this->upper->Is(that.upper); 1086 return that.lower->Is(this->lower) && this->upper->Is(that.upper);
1066 } 1087 }
1067 }; 1088 };
1068 1089
1069 typedef BoundsImpl<ZoneTypeConfig> Bounds; 1090 typedef BoundsImpl<ZoneTypeConfig> Bounds;
1070 1091
1071 } } // namespace v8::internal 1092 } } // namespace v8::internal
1072 1093
1073 #endif // V8_TYPES_H_ 1094 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « src/compiler/typer.cc ('k') | src/types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698