KJS::SimpleNumber on 64 bit machines
Maciej Stachowiak
mjs at apple.com
Wed Oct 1 14:21:44 CEST 2003
On Oct 1, 2003, at 12:28 PM, Harri Porten wrote:
> On Wed, 1 Oct 2003, Harri Porten wrote:
>
>> the SimpleNumber::fits() trickery causes problems on 64 bit machines.
>> At
>> least on Alphas. I can reproduce a SIGFPE that happens when NaN is
>> passed. gcc is suspicous about the comparisons:
>
> As I've just found out the SIGFPE can be avoided by specifying the
> -mieee
> switch on Alpha. Still, the issue of the warnings remain because of the
> non-portable casts.
I think this patch will fix it, but I don't have a 64-bit platform to
test on. Could you try it? It shuts up the warnings and also uses all
64 bits (which is not really required but seems nice).
Even better than using long would be to include stdint.h and use
intptr_t. I don't know if that's portable enough for KDE's target
platforms. Let me know if you prefer the intptr_t approach, and if so
I'll land it that way in our tree.
Index: kjs/simple_number.h
===================================================================
RCS file: /local/home/cvs/Labyrinth/JavaScriptCore/kjs/simple_number.h,v
retrieving revision 1.7
diff -u -p -r1.7 kjs/simple_number.h
--- kjs/simple_number.h 2003/01/22 00:11:44 1.7
+++ kjs/simple_number.h 2003/10/01 20:17:59
@@ -31,17 +31,17 @@ namespace KJS {
class SimpleNumber {
public:
- enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1 << 31,
max = (1 << (31 - shift)) - 1, min = -max - 1 };
+ enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1 <<
(sizeof(long) * 8 - 1), max = (1 << ((sizeof(long) * 8 - 1) - shift)) -
1, min = -max - 1 };
- static inline bool is(const ValueImp *imp) { return ((int)imp & mask)
== tag; }
- static inline int value(const ValueImp *imp) { return ((int)imp >>
shift) | (((int)imp & sign) ? ~max : 0); }
+ static inline bool is(const ValueImp *imp) { return ((long)imp &
mask) == tag; }
+ static inline int value(const ValueImp *imp) { return ((long)imp >>
shift) | (((long)imp & sign) ? ~max : 0); }
static inline bool fits(int i) { return i <= max && i >= min; }
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(double d) { return d <= max && d >= min && d
== (double)(int)d; }
- static inline ValueImp *make(int i) { return (ValueImp *)((i <<
shift) | tag); }
+ static inline ValueImp *make(long i) { return (ValueImp *)((i <<
shift) | tag); }
};
}
More information about the Khtml-devel
mailing list