Changeset 46598 in webkit for trunk/JavaScriptCore/runtime/JSImmediate.h
- Timestamp:
- Jul 30, 2009, 1:57:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/JSImmediate.h
r43153 r46598 23 23 #define JSImmediate_h 24 24 25 #include <wtf/Platform.h> 26 27 #if !USE(JSVALUE32_64) 28 25 29 #include <wtf/Assertions.h> 26 30 #include <wtf/AlwaysInline.h> … … 43 47 class UString; 44 48 45 #if USE( ALTERNATE_JSIMMEDIATE)49 #if USE(JSVALUE64) 46 50 inline intptr_t reinterpretDoubleToIntptr(double value) 47 51 { … … 99 103 /* 100 104 * On 64-bit platforms, we support an alternative encoding form for immediates, if 101 * USE( ALTERNATE_JSIMMEDIATE) is defined. When this format is used, double precision105 * USE(JSVALUE64) is defined. When this format is used, double precision 102 106 * floating point values may also be encoded as JSImmediates. 103 107 * … … 156 160 friend JSValue jsNumber(JSGlobalData* globalData, unsigned long long i); 157 161 158 #if USE( ALTERNATE_JSIMMEDIATE)162 #if USE(JSVALUE64) 159 163 // If all bits in the mask are set, this indicates an integer number, 160 164 // if any but not all are set this value is a double precision number. … … 178 182 static const intptr_t FullTagTypeNull = TagBitTypeOther; 179 183 180 #if USE( ALTERNATE_JSIMMEDIATE)184 #if USE(JSVALUE64) 181 185 static const int32_t IntegerPayloadShift = 0; 182 186 #else … … 201 205 static ALWAYS_INLINE bool isIntegerNumber(JSValue v) 202 206 { 203 #if USE( ALTERNATE_JSIMMEDIATE)207 #if USE(JSVALUE64) 204 208 return (rawValue(v) & TagTypeNumber) == TagTypeNumber; 205 209 #else … … 208 212 } 209 213 210 #if USE( ALTERNATE_JSIMMEDIATE)211 static ALWAYS_INLINE bool isDouble Number(JSValue v)214 #if USE(JSVALUE64) 215 static ALWAYS_INLINE bool isDouble(JSValue v) 212 216 { 213 217 return isNumber(v) && !isIntegerNumber(v); … … 257 261 static ALWAYS_INLINE bool areBothImmediateIntegerNumbers(JSValue v1, JSValue v2) 258 262 { 259 #if USE( ALTERNATE_JSIMMEDIATE)263 #if USE(JSVALUE64) 260 264 return (rawValue(v1) & rawValue(v2) & TagTypeNumber) == TagTypeNumber; 261 265 #else … … 268 272 static JSObject* toObject(JSValue, ExecState*); 269 273 static JSObject* toThisObject(JSValue, ExecState*); 270 static UString toString(JSValue);271 274 272 275 static bool getUInt32(JSValue, uint32_t&); … … 287 290 288 291 private: 289 #if USE( ALTERNATE_JSIMMEDIATE)292 #if USE(JSVALUE64) 290 293 static const int minImmediateInt = ((-INT_MAX) - 1); 291 294 static const int maxImmediateInt = INT_MAX; … … 301 304 } 302 305 303 // With USE( ALTERNATE_JSIMMEDIATE) we want the argument to be zero extended, so the306 // With USE(JSVALUE64) we want the argument to be zero extended, so the 304 307 // integer doesn't interfere with the tag bits in the upper word. In the default encoding, 305 308 // if intptr_t id larger then int32_t we sign extend the value through the upper word. 306 #if USE( ALTERNATE_JSIMMEDIATE)309 #if USE(JSVALUE64) 307 310 static ALWAYS_INLINE JSValue makeInt(uint32_t value) 308 311 #else … … 313 316 } 314 317 315 #if USE( ALTERNATE_JSIMMEDIATE)318 #if USE(JSVALUE64) 316 319 static ALWAYS_INLINE JSValue makeDouble(double value) 317 320 { … … 338 341 static JSValue fromNumberOutsideIntegerRange(T); 339 342 340 #if USE( ALTERNATE_JSIMMEDIATE)343 #if USE(JSVALUE64) 341 344 static ALWAYS_INLINE double doubleValue(JSValue v) 342 345 { … … 364 367 return v.immediateValue(); 365 368 } 366 367 static double nonInlineNaN();368 369 }; 369 370 … … 375 376 ALWAYS_INLINE JSValue JSImmediate::oneImmediate() { return makeInt(1); } 376 377 377 #if USE( ALTERNATE_JSIMMEDIATE)378 #if USE(JSVALUE64) 378 379 inline bool doubleToBoolean(double value) 379 380 { … … 402 403 } 403 404 404 #if USE( ALTERNATE_JSIMMEDIATE)405 #if USE(JSVALUE64) 405 406 template<typename T> 406 407 inline JSValue JSImmediate::fromNumberOutsideIntegerRange(T value) … … 443 444 ALWAYS_INLINE JSValue JSImmediate::from(int i) 444 445 { 445 #if !USE( ALTERNATE_JSIMMEDIATE)446 #if !USE(JSVALUE64) 446 447 if ((i < minImmediateInt) | (i > maxImmediateInt)) 447 448 return fromNumberOutsideIntegerRange(i); … … 509 510 return intValue(v); 510 511 511 #if USE( ALTERNATE_JSIMMEDIATE)512 #if USE(JSVALUE64) 512 513 if (isNumber(v)) { 513 ASSERT(isDouble Number(v));514 ASSERT(isDouble(v)); 514 515 return doubleValue(v); 515 516 } … … 542 543 } 543 544 544 // These are identical logic to the JSValue functions above, and faster than jsNumber(number).toInt32().545 int32_t toInt32(double);546 uint32_t toUInt32(double);547 int32_t toInt32SlowCase(double, bool& ok);548 uint32_t toUInt32SlowCase(double, bool& ok);549 550 545 inline JSValue::JSValue(JSNullTag) 551 546 { … … 576 571 { 577 572 return JSImmediate::isBoolean(asValue()); 573 } 574 575 inline bool JSValue::isTrue() const 576 { 577 return asValue() == JSImmediate::trueImmediate(); 578 } 579 580 inline bool JSValue::isFalse() const 581 { 582 return asValue() == JSImmediate::falseImmediate(); 578 583 } 579 584 … … 593 598 } 594 599 595 ALWAYS_INLINE int32_t JSValue::toInt32(ExecState* exec) const596 {597 int32_t i;598 if (getTruncatedInt32(i))599 return i;600 bool ignored;601 return toInt32SlowCase(toNumber(exec), ignored);602 }603 604 inline uint32_t JSValue::toUInt32(ExecState* exec) const605 {606 uint32_t i;607 if (getTruncatedUInt32(i))608 return i;609 bool ignored;610 return toUInt32SlowCase(toNumber(exec), ignored);611 }612 613 inline int32_t toInt32(double val)614 {615 if (!(val >= -2147483648.0 && val < 2147483648.0)) {616 bool ignored;617 return toInt32SlowCase(val, ignored);618 }619 return static_cast<int32_t>(val);620 }621 622 inline uint32_t toUInt32(double val)623 {624 if (!(val >= 0.0 && val < 4294967296.0)) {625 bool ignored;626 return toUInt32SlowCase(val, ignored);627 }628 return static_cast<uint32_t>(val);629 }630 631 inline int32_t JSValue::toInt32(ExecState* exec, bool& ok) const632 {633 int32_t i;634 if (getTruncatedInt32(i)) {635 ok = true;636 return i;637 }638 return toInt32SlowCase(toNumber(exec), ok);639 }640 641 inline uint32_t JSValue::toUInt32(ExecState* exec, bool& ok) const642 {643 uint32_t i;644 if (getTruncatedUInt32(i)) {645 ok = true;646 return i;647 }648 return toUInt32SlowCase(toNumber(exec), ok);649 }650 651 600 inline bool JSValue::isCell() const 652 601 { … … 654 603 } 655 604 656 inline bool JSValue::isInt32 Fast() const605 inline bool JSValue::isInt32() const 657 606 { 658 607 return JSImmediate::isIntegerNumber(asValue()); 659 608 } 660 609 661 inline int32_t JSValue:: getInt32Fast() const662 { 663 ASSERT(isInt32 Fast());610 inline int32_t JSValue::asInt32() const 611 { 612 ASSERT(isInt32()); 664 613 return JSImmediate::getTruncatedInt32(asValue()); 665 614 } 666 615 667 inline bool JSValue::isUInt32 Fast() const616 inline bool JSValue::isUInt32() const 668 617 { 669 618 return JSImmediate::isPositiveIntegerNumber(asValue()); 670 619 } 671 620 672 inline uint32_t JSValue:: getUInt32Fast() const673 { 674 ASSERT(isUInt32 Fast());621 inline uint32_t JSValue::asUInt32() const 622 { 623 ASSERT(isUInt32()); 675 624 return JSImmediate::getTruncatedUInt32(asValue()); 676 }677 678 inline JSValue JSValue::makeInt32Fast(int32_t i)679 {680 return JSImmediate::from(i);681 }682 683 inline bool JSValue::areBothInt32Fast(JSValue v1, JSValue v2)684 {685 return JSImmediate::areBothImmediateIntegerNumbers(v1, v2);686 625 } 687 626 … … 736 675 { 737 676 ASSERT(canDoFastRshift(val, shift) || canDoFastUrshift(val, shift)); 738 #if USE( ALTERNATE_JSIMMEDIATE)677 #if USE(JSVALUE64) 739 678 return JSImmediate::makeValue(static_cast<intptr_t>(static_cast<uint32_t>(static_cast<int32_t>(JSImmediate::rawValue(val)) >> ((JSImmediate::rawValue(shift) >> JSImmediate::IntegerPayloadShift) & 0x1f))) | JSImmediate::TagTypeNumber); 740 679 #else … … 784 723 } // namespace JSC 785 724 725 #endif // !USE(JSVALUE32_64) 726 786 727 #endif // JSImmediate_h
Note:
See TracChangeset
for help on using the changeset viewer.