Changeset 26912 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Oct 22, 2007, 11:44:27 PM (18 years ago)
Author:
darin
Message:

Reviewed by Maciej.

This should restore correctness and make speed better too, restoring some
of the optimization we lost in my last check-in.

  • kjs/JSImmediate.h: (KJS::JSImmediate::getTruncatedInt32): Added. Uses the range checking idiom I used in my patch yesterday. (KJS::JSImmediate::getTruncatedUInt32): Ditto.
  • kjs/internal.h: Removed getInt32 and added getTruncatedInt/UInt32.
  • kjs/internal.cpp: (KJS::NumberImp::getUInt32): Changed to always use double, since I can't find a way to write this more efficiently for float. (KJS::NumberImp::getTruncatedInt32): Added. (KJS::NumberImp::getTruncatedUInt32): Added.
  • kjs/value.h: Removed getInt32 and added getTruncatedInt/UInt32. (KJS::JSValue::getUInt32): (KJS::JSValue::getTruncatedInt32): Added. (KJS::JSValue::getTruncatedUInt32): Added. (KJS::JSValue::toInt32): Changed getInt32 call to getTruncatedInt32. (KJS::JSValue::toUInt32): Changed getUInt32 call to getTruncatedUInt32.
  • kjs/value.cpp: (KJS::JSCell::getTruncatedInt32): Added. (KJS::JSCell::getTruncatedUInt32): Added. (KJS::JSValue::toInteger): Changed getUInt32 call to getTruncatedInt32. (KJS::JSValue::toInt32SlowCase): Removed extra getInt32 call I accidentally had left in here. (KJS::JSValue::toUInt32SlowCase): Ditto. (KJS::JSValue::toUInt16): Changed getUInt32 call to getTruncatedUInt32.
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r26899 r26912  
     12007-10-22  Darin Adler  <[email protected]>
     2
     3        Reviewed by Maciej.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=15636
     6          some JavaScriptCore regression tests are failing due to numeric conversion
     7
     8        This should restore correctness and make speed better too, restoring some
     9        of the optimization we lost in my last check-in.
     10
     11        * kjs/JSImmediate.h:
     12        (KJS::JSImmediate::getTruncatedInt32): Added. Uses the range checking idiom
     13        I used in my patch yesterday.
     14        (KJS::JSImmediate::getTruncatedUInt32): Ditto.
     15
     16        * kjs/internal.h: Removed getInt32 and added getTruncatedInt/UInt32.
     17        * kjs/internal.cpp:
     18        (KJS::NumberImp::getUInt32): Changed to always use double, since I can't find
     19        a way to write this more efficiently for float.
     20        (KJS::NumberImp::getTruncatedInt32): Added.
     21        (KJS::NumberImp::getTruncatedUInt32): Added.
     22
     23        * kjs/value.h: Removed getInt32 and added getTruncatedInt/UInt32.
     24        (KJS::JSValue::getUInt32):
     25        (KJS::JSValue::getTruncatedInt32): Added.
     26        (KJS::JSValue::getTruncatedUInt32): Added.
     27        (KJS::JSValue::toInt32): Changed getInt32 call to getTruncatedInt32.
     28        (KJS::JSValue::toUInt32): Changed getUInt32 call to getTruncatedUInt32.
     29        * kjs/value.cpp:
     30        (KJS::JSCell::getTruncatedInt32): Added.
     31        (KJS::JSCell::getTruncatedUInt32): Added.
     32        (KJS::JSValue::toInteger): Changed getUInt32 call to getTruncatedInt32.
     33        (KJS::JSValue::toInt32SlowCase): Removed extra getInt32 call I accidentally
     34        had left in here.
     35        (KJS::JSValue::toUInt32SlowCase): Ditto.
     36        (KJS::JSValue::toUInt16): Changed getUInt32 call to getTruncatedUInt32.
     37
     38        * JavaScriptCore.exp: Updated.
     39
    1402007-10-22  Darin Adler  <[email protected]>
    241
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r26892 r26912  
    243243__ZNK3KJS4List2atEi
    244244__ZNK3KJS4List8copyTailEv
    245 __ZNK3KJS6JSCell8getInt32ERi
     245__ZNK3KJS6JSCell17getTruncatedInt32ERi
     246__ZNK3KJS6JSCell18getTruncatedUInt32ERj
    246247__ZNK3KJS6JSCell9getNumberERd
    247248__ZNK3KJS6JSCell9getNumberEv
  • trunk/JavaScriptCore/kjs/JSImmediate.h

    r26899 r26912  
    8888    static JSType type(const JSValue*);
    8989
    90     static bool getInt32(const JSValue*, int32_t&);
    9190    static bool getUInt32(const JSValue*, uint32_t&);
     91    static bool getTruncatedInt32(const JSValue*, int32_t&);
     92    static bool getTruncatedUInt32(const JSValue*, uint32_t&);
    9293
    9394    // It would nice just to use fromDouble() to create these values, but that would prevent them from
     
    163164    }
    164165
    165     static double toDouble(const JSValue* v)
     166    static float toFloat(const JSValue* v)
    166167    {
    167168        ASSERT(isImmediate(v));
     
    172173    }
    173174
    174     static bool getInt32(const JSValue* v, int32_t& i)
    175     {
    176         ASSERT(isImmediate(v));
    177 
    178         FloatUnion floatUnion;
    179         floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    180         float f = floatUnion.asFloat;
     175    static double toDouble(const JSValue* v)
     176    {
     177        return toFloat(v);
     178    }
     179
     180    static bool getTruncatedInt32(const JSValue* v, int32_t& i)
     181    {
     182        float f = toFloat(v);
     183        if (!(f >= -2147483648.0F && f < 2147483648.0F))
     184            return false;
    181185        i = static_cast<int32_t>(f);
    182         return isNumber(v) && i == f;
    183     }
    184 
    185     static bool getUInt32(const JSValue* v, uint32_t& i)
    186     {
    187         ASSERT(isImmediate(v));
    188 
    189         FloatUnion floatUnion;
    190         floatUnion.asBits = static_cast<uint32_t>(unTag(v));
    191         float f = floatUnion.asFloat;
     186        return isNumber(v);
     187    }
     188
     189    static bool getTruncatedUInt32(const JSValue* v, uint32_t& i)
     190    {
     191        float f = toFloat(v);
     192        if (!(f >= 0.0F && f < 4294967296.0F))
     193            return false;
    192194        i = static_cast<uint32_t>(f);
    193         return isNumber(v) && i == f;
     195        return isNumber(v);
    194196    }
    195197};
     
    221223    }
    222224
    223     static bool getInt32(const JSValue* v, int32_t& i)
     225    static bool getTruncatedInt32(const JSValue* v, int32_t& i)
    224226    {
    225227        double d = toDouble(v);
     228        if (!(d >= -2147483648.0 && d < 2147483648.0))
     229            return false;
    226230        i = static_cast<int32_t>(d);
    227         return isNumber(v) && i == d;
    228     }
    229 
    230     static bool getUInt32(const JSValue* v, uint32_t& i)
     231        return isNumber(v);
     232    }
     233
     234    static bool getTruncatedUInt32(const JSValue* v, uint32_t& i)
    231235    {
    232236        double d = toDouble(v);
     237        if (!(d >= 0.0 && d < 4294967296.0))
     238            return false;
    233239        i = static_cast<uint32_t>(d);
    234         return isNumber(v) && i == d;
     240        return isNumber(v);
    235241    }
    236242};
     
    263269}
    264270
    265 inline bool JSImmediate::getInt32(const JSValue* v, int32_t& i)
    266 {
    267     return FPBitValues<is32bit, is64bit>::getInt32(v, i);
    268 }
    269 
    270271inline bool JSImmediate::getUInt32(const JSValue* v, uint32_t& i)
    271272{
    272     return FPBitValues<is32bit, is64bit>::getUInt32(v, i);
     273    double d = toDouble(v);
     274    i = static_cast<uint32_t>(d);
     275    return isNumber(v) && i == d;
     276}
     277
     278inline bool JSImmediate::getTruncatedInt32(const JSValue* v, int32_t& i)
     279{
     280    return FPBitValues<is32bit, is64bit>::getTruncatedInt32(v, i);
     281}
     282
     283inline bool JSImmediate::getTruncatedUInt32(const JSValue* v, uint32_t& i)
     284{
     285    return FPBitValues<is32bit, is64bit>::getTruncatedUInt32(v, i);
    273286}
    274287
  • trunk/JavaScriptCore/kjs/internal.cpp

    r26899 r26912  
    112112}
    113113
    114 bool NumberImp::getInt32(int32_t& int32) const
    115 {
    116     int32 = static_cast<int32_t>(val);
    117     return int32 == val;
    118 }
    119 
    120114bool NumberImp::getUInt32(uint32_t& uint32) const
    121115{
    122116    uint32 = static_cast<uint32_t>(val);
    123117    return uint32 == val;
     118}
     119
     120bool NumberImp::getTruncatedInt32(int32_t& int32) const
     121{
     122    if (!(val >= -2147483648.0 && val < 2147483648.0))
     123        return false;
     124    int32 = static_cast<int32_t>(val);
     125    return true;
     126}
     127
     128bool NumberImp::getTruncatedUInt32(uint32_t& uint32) const
     129{
     130    if (!(val >= 0.0 && val < 4294967296.0))
     131        return false;
     132    uint32 = static_cast<uint32_t>(val);
     133    return true;
    124134}
    125135
  • trunk/JavaScriptCore/kjs/internal.h

    r26892 r26912  
    8181    NumberImp(double v) : val(v) { }
    8282
    83     virtual bool getInt32(int32_t&) const;
    8483    virtual bool getUInt32(uint32_t&) const;
     84    virtual bool getTruncatedInt32(int32_t&) const;
     85    virtual bool getTruncatedUInt32(uint32_t&) const;
    8586
    8687    double val;
  • trunk/JavaScriptCore/kjs/value.cpp

    r26892 r26912  
    4141}
    4242
    43 bool JSCell::getInt32(int32_t&) const
     43bool JSCell::getUInt32(uint32_t&) const
    4444{
    4545    return false;
    4646}
    4747
    48 bool JSCell::getUInt32(uint32_t&) const
     48bool JSCell::getTruncatedInt32(int32_t&) const
     49{
     50    return false;
     51}
     52
     53bool JSCell::getTruncatedUInt32(uint32_t&) const
    4954{
    5055    return false;
     
    5459double JSValue::toInteger(ExecState *exec) const
    5560{
    56     uint32_t i;
    57     if (getUInt32(i))
     61    int32_t i;
     62    if (getTruncatedInt32(i))
    5863        return i;
    5964    return roundValue(exec, const_cast<JSValue*>(this));
     
    6368{
    6469    ok = true;
    65 
    66     int32_t i;
    67     if (getInt32(i))
    68         return i;
    6970
    7071    double d = roundValue(exec, const_cast<JSValue*>(this));
     
    9091    ok = true;
    9192
    92     uint32_t i;
    93     if (getUInt32(i))
    94         return i;
    95 
    9693    double d = roundValue(exec, const_cast<JSValue*>(this));
    9794    if (d >= 0.0 && d < D32)
     
    113110{
    114111    uint32_t i;
    115     if (getUInt32(i))
     112    if (getTruncatedUInt32(i))
    116113        return static_cast<uint16_t>(i);
    117114
  • trunk/JavaScriptCore/kjs/value.h

    r26899 r26912  
    7777
    7878    // Extracting integer values.
    79     bool getInt32(int32_t&) const;
    8079    bool getUInt32(uint32_t&) const;
     80    bool getTruncatedInt32(int32_t&) const;
     81    bool getTruncatedUInt32(uint32_t&) const;
    8182
    8283    // Basic conversions.
     
    141142
    142143    // Extracting integer values.
    143     virtual bool getInt32(int32_t&) const;
    144144    virtual bool getUInt32(uint32_t&) const;
     145    virtual bool getTruncatedInt32(int32_t&) const;
     146    virtual bool getTruncatedUInt32(uint32_t&) const;
    145147
    146148    // Basic conversions.
     
    333335}
    334336
    335 inline bool JSValue::getInt32(int32_t& v) const
    336 {
    337     return JSImmediate::isImmediate(this) ? JSImmediate::getInt32(this, v) : asCell()->getInt32(v);
    338 }
    339 
    340337inline bool JSValue::getUInt32(uint32_t& v) const
    341338{
    342339    return JSImmediate::isImmediate(this) ? JSImmediate::getUInt32(this, v) : asCell()->getUInt32(v);
     340}
     341
     342inline bool JSValue::getTruncatedInt32(int32_t& v) const
     343{
     344    return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedInt32(this, v) : asCell()->getTruncatedInt32(v);
     345}
     346
     347inline bool JSValue::getTruncatedUInt32(uint32_t& v) const
     348{
     349    return JSImmediate::isImmediate(this) ? JSImmediate::getTruncatedUInt32(this, v) : asCell()->getTruncatedUInt32(v);
    343350}
    344351
     
    387394{
    388395    int32_t i;
    389     if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i))
     396    if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedInt32(this, i))
    390397        return i;
    391398    bool ok;
     
    396403{
    397404    uint32_t i;
    398     if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i))
     405    if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedUInt32(this, i))
    399406        return i;
    400407    bool ok;
     
    405412{
    406413    int32_t i;
    407     if (JSImmediate::isImmediate(this) && JSImmediate::getInt32(this, i)) {
     414    if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedInt32(this, i)) {
    408415        ok = true;
    409416        return i;
     
    415422{
    416423    uint32_t i;
    417     if (JSImmediate::isImmediate(this) && JSImmediate::getUInt32(this, i)) {
     424    if (JSImmediate::isImmediate(this) && JSImmediate::getTruncatedUInt32(this, i)) {
    418425        ok = true;
    419426        return i;
Note: See TracChangeset for help on using the changeset viewer.