[webkit-changes] cvs commit: JavaScriptCore/kjs simple_number.h
Geoffrey
ggaren at opensource.apple.com
Thu Sep 22 13:09:49 PDT 2005
ggaren 05/09/22 13:09:49
Modified: . ChangeLog
kjs simple_number.h
Log:
- Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=5053
Need to restore int/long changes to simple_number.h
Reviewed by darin and mjs.
* kjs/simple_number.h: changed enums to indenpendent constants to clarify types
(KJS::isNegativeZero): changed to static function - no reason to export
(KJS::SimpleNumber::rightShiftSignExtended): new function for clarity
(KJS::SimpleNumber::make): specified cast as reinterpret_cast
(KJS::SimpleNumber::is): changed to use uintptr_t for portability
(KJS::SimpleNumber::value): changed to use uintptr_t and rightShiftSignExtended
(KJS::SimpleNumber::fits): inverted tests - probably only a performance win for double
(KJS::SimpleNumber::integerFits): ditto
Revision Changes Path
1.835 +16 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.834
retrieving revision 1.835
diff -u -r1.834 -r1.835
--- ChangeLog 21 Sep 2005 05:53:04 -0000 1.834
+++ ChangeLog 22 Sep 2005 20:09:48 -0000 1.835
@@ -1,3 +1,19 @@
+2005-09-22 Geoffrey Garen <ggaren at apple.com>
+
+ - Fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=5053
+ Need to restore int/long changes to simple_number.h
+
+ Reviewed by darin and mjs.
+
+ * kjs/simple_number.h: changed enums to indenpendent constants to clarify types
+ (KJS::isNegativeZero): changed to static function - no reason to export
+ (KJS::SimpleNumber::rightShiftSignExtended): new function for clarity
+ (KJS::SimpleNumber::make): specified cast as reinterpret_cast
+ (KJS::SimpleNumber::is): changed to use uintptr_t for portability
+ (KJS::SimpleNumber::value): changed to use uintptr_t and rightShiftSignExtended
+ (KJS::SimpleNumber::fits): inverted tests - probably only a performance win for double
+ (KJS::SimpleNumber::integerFits): ditto
+
2005-09-20 Maciej Stachowiak <mjs at apple.com>
Reviewed by Geoff and partly by Darin.
1.17 +31 -15 JavaScriptCore/kjs/simple_number.h
Index: simple_number.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/simple_number.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- simple_number.h 19 Sep 2005 21:53:22 -0000 1.16
+++ simple_number.h 22 Sep 2005 20:09:49 -0000 1.17
@@ -36,11 +36,13 @@
using std::signbit;
#endif
+#define KJS_MIN_MACRO(a, b) ((a) < (b) ? (a) : (b))
+
namespace KJS {
class ValueImp;
- inline bool isNegativeZero(double num)
+ static inline bool isNegativeZero(double num)
{
#if WIN32
return _fpclass(num) == _FPCLASS_NZ;
@@ -51,20 +53,34 @@
class SimpleNumber {
public:
- enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1L << (sizeof(long) * 8 - 1 ), max = (1L << ((sizeof(long) * 8 - 1) - shift)) - 1, min = -max - 1, imax = (1L << ((sizeof(int) * 8 - 1) - shift)) - 1, imin = -imax - 1 };
-
- static inline bool is(const ValueImp *imp) { return ((long)imp & mask) == tag; }
- static inline long value(const ValueImp *imp) { return ((long)imp >> shift) | (((long)imp & sign) ? ~max : 0); }
-
- static inline bool fits(int i) { return i <= imax && i >= imin; }
- static inline bool fits(unsigned i) { return i <= (unsigned)max; }
- static inline bool fits(long i) { return i <= max && i >= min; }
- static inline bool fits(unsigned long i) { return i <= (unsigned)max; }
- static inline bool fits(long long i) { return i <= max && i >= min; }
- static inline bool fits(unsigned long long i) { return i <= (unsigned)max; }
- static inline bool integerFits(double d) { return !(d < min || d > max); }
- static inline bool fits(double d) { return d >= min && d <= max && d == (double)(long)d && !isNegativeZero(d); }
- static inline ValueImp *make(long i) { return (ValueImp *)((i << shift) | tag); }
+ static const int tagBits = 2; // Pointer alignment guarantees that we have the low two bits to play with for type tagging
+ static const unsigned long tag = 1UL; // 01 is the full tag
+ static const unsigned long tagMask = (1UL << tagBits) - 1;
+ static const int valueBits = KJS_MIN_MACRO(sizeof(ValueImp *) * 8 - tagBits, sizeof(long) * 8);
+ static const unsigned long signMask = 1UL << sizeof(long) * 8 - 1;
+ static const long maxValue = (signMask >> tagBits) - 1;
+ static const unsigned long umaxValue = maxValue;
+ static const long minValue = -(maxValue + 1);
+
+ static unsigned long rightShiftSignExtended(uintptr_t l, int n)
+ {
+ return (l >> n) | ((l & signMask) ? (~0UL << valueBits) : 0);
+ }
+
+ static ValueImp *make(long i) { return reinterpret_cast<ValueImp *>((i << tagBits) | tag); }
+ static bool is(const ValueImp *imp) { return (reinterpret_cast<uintptr_t>(imp) & tagMask) == tag; }
+ static long value(const ValueImp *imp) { return rightShiftSignExtended(reinterpret_cast<uintptr_t>(imp), tagBits); }
+
+ static bool fits(int i) { return !(i > maxValue || i < minValue); }
+ static bool fits(long i) { return !(i > maxValue || i < minValue); }
+ static bool fits(long long i) { return !(i > maxValue || i < minValue); }
+ static bool integerFits(double i) { return !(i > maxValue || i < minValue); }
+
+ static bool fits(double d) { return !(d > maxValue || d < minValue) && d == (double)(long)d && !isNegativeZero(d); }
+
+ static bool fits(unsigned i) { return !(i > umaxValue); }
+ static bool fits(unsigned long i) { return !(i > umaxValue); }
+ static bool fits(unsigned long long i) { return !(i > umaxValue); }
};
}
More information about the webkit-changes
mailing list