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

Side by Side Diff: src/hydrogen-instructions.h

Issue 9156001: Improved range analysis for bitwise operations. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/hydrogen-instructions.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 25 matching lines...) Expand all
36 #include "small-pointer-list.h" 36 #include "small-pointer-list.h"
37 #include "string-stream.h" 37 #include "string-stream.h"
38 #include "v8conversions.h" 38 #include "v8conversions.h"
39 #include "v8utils.h" 39 #include "v8utils.h"
40 #include "zone.h" 40 #include "zone.h"
41 41
42 namespace v8 { 42 namespace v8 {
43 namespace internal { 43 namespace internal {
44 44
45 // Forward declarations. 45 // Forward declarations.
46 class BitRange;
46 class HBasicBlock; 47 class HBasicBlock;
47 class HEnvironment; 48 class HEnvironment;
48 class HInferRepresentation; 49 class HInferRepresentation;
49 class HInstruction; 50 class HInstruction;
50 class HLoopInformation; 51 class HLoopInformation;
51 class HValue; 52 class HValue;
52 class LInstruction; 53 class LInstruction;
53 class LChunkBuilder; 54 class LChunkBuilder;
54 55
55 56
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return new(zone) Range(kMinInt, upper_); 253 return new(zone) Range(kMinInt, upper_);
253 } 254 }
254 Range* CopyClearUpper(Zone* zone) const { 255 Range* CopyClearUpper(Zone* zone) const {
255 return new(zone) Range(lower_, kMaxInt); 256 return new(zone) Range(lower_, kMaxInt);
256 } 257 }
257 Range* Copy(Zone* zone) const { 258 Range* Copy(Zone* zone) const {
258 Range* result = new(zone) Range(lower_, upper_); 259 Range* result = new(zone) Range(lower_, upper_);
259 result->set_can_be_minus_zero(CanBeMinusZero()); 260 result->set_can_be_minus_zero(CanBeMinusZero());
260 return result; 261 return result;
261 } 262 }
262 int32_t Mask() const; 263 void ToBitRange(BitRange* bits) const;
263 void set_can_be_minus_zero(bool b) { can_be_minus_zero_ = b; } 264 void set_can_be_minus_zero(bool b) { can_be_minus_zero_ = b; }
264 bool CanBeMinusZero() const { return CanBeZero() && can_be_minus_zero_; } 265 bool CanBeMinusZero() const { return CanBeZero() && can_be_minus_zero_; }
265 bool CanBeZero() const { return upper_ >= 0 && lower_ <= 0; } 266 bool CanBeZero() const { return upper_ >= 0 && lower_ <= 0; }
266 bool CanBeNegative() const { return lower_ < 0; } 267 bool CanBeNegative() const { return lower_ < 0; }
267 bool CanBePositive() const { return upper_ > 0; } 268 bool CanBePositive() const { return upper_ > 0; }
268 bool Includes(int value) const { return lower_ <= value && upper_ >= value; } 269 bool Includes(int value) const { return lower_ <= value && upper_ >= value; }
269 bool IsMostGeneric() const { 270 bool IsMostGeneric() const {
270 return lower_ == kMinInt && upper_ == kMaxInt && CanBeMinusZero(); 271 return lower_ == kMinInt && upper_ == kMaxInt && CanBeMinusZero();
271 } 272 }
272 bool IsInSmiRange() const { 273 bool IsInSmiRange() const {
(...skipping 26 matching lines...) Expand all
299 bool MulAndCheckOverflow(Range* other); 300 bool MulAndCheckOverflow(Range* other);
300 301
301 private: 302 private:
302 int32_t lower_; 303 int32_t lower_;
303 int32_t upper_; 304 int32_t upper_;
304 Range* next_; 305 Range* next_;
305 bool can_be_minus_zero_; 306 bool can_be_minus_zero_;
306 }; 307 };
307 308
308 309
310 class BitRange {
311 public:
312 BitRange() : known_(0), bits_(0) { }
313 BitRange(int32_t known, int32_t bits)
314 : known_(known), bits_(bits & known) { }
315
316 static void SetFromRange(BitRange* bits, int32_t lower, int32_t upper) {
317 // Find a mask for the most significant bits that are the same for all
318 // values in the range.
319 int32_t same = ~(lower ^ upper);
320 // Flood zeros to any bits lower than the most significant zero.
321 same &= (same >> 1);
322 same &= (same >> 2);
323 same &= (same >> 4);
324 same &= (same >> 8);
325 same &= (same >> 16);
326
327 bits->known_ = same;
328 bits->bits_ = lower & same;
329 }
330
331 void ExtendRange(int32_t* lower, int32_t* upper) const {
332 int32_t limit1 = (~known_ & 0x80000000) | bits_;
333 int32_t limit2 = (~known_ & 0x7fffffff) | bits_;
334 *lower = Min(*lower, Min(limit1, limit2));
335 *upper = Max(*upper, Max(limit1, limit2));
336 }
337
338 static BitRange And(BitRange a, BitRange b) {
339 int32_t known = a.known_ & b.known_;
340 // Zeros in either operand become known.
341 known |= (a.known_ & ~a.bits_);
342 known |= (b.known_ & ~b.bits_);
343 return BitRange(known, a.bits_ & b.bits_);
344 }
345
346 static BitRange Or(BitRange a, BitRange b) {
347 int32_t known = a.known_ & b.known_;
348 // Ones in either operand become known.
349 known |= (a.known_ & a.bits_);
350 known |= (b.known_ & b.bits_);
351 return BitRange(known, a.bits_ | b.bits_);
352 }
353
354 static BitRange Xor(BitRange a, BitRange b) {
355 return BitRange(a.known_ & b.known_, a.bits_ ^ b.bits_);
356 }
357
358 private:
359 int32_t known_; // A mask of known bits.
360 int32_t bits_; // Values of known bits, zero elsewhere.
361 };
362
363
309 class UniqueValueId { 364 class UniqueValueId {
310 public: 365 public:
311 UniqueValueId() : raw_address_(NULL) { } 366 UniqueValueId() : raw_address_(NULL) { }
312 367
313 explicit UniqueValueId(Object* object) { 368 explicit UniqueValueId(Object* object) {
314 raw_address_ = reinterpret_cast<Address>(object); 369 raw_address_ = reinterpret_cast<Address>(object);
315 ASSERT(IsInitialized()); 370 ASSERT(IsInitialized());
316 } 371 }
317 372
318 explicit UniqueValueId(Handle<Object> handle) { 373 explicit UniqueValueId(Handle<Object> handle) {
(...skipping 6253 matching lines...) Expand 10 before | Expand all | Expand 10 after
6572 virtual bool IsDeletable() const { return true; } 6627 virtual bool IsDeletable() const { return true; }
6573 }; 6628 };
6574 6629
6575 6630
6576 #undef DECLARE_INSTRUCTION 6631 #undef DECLARE_INSTRUCTION
6577 #undef DECLARE_CONCRETE_INSTRUCTION 6632 #undef DECLARE_CONCRETE_INSTRUCTION
6578 6633
6579 } } // namespace v8::internal 6634 } } // namespace v8::internal
6580 6635
6581 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6636 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW
« no previous file with comments | « no previous file | src/hydrogen-instructions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698