Ignore:
Timestamp:
Aug 8, 2008, 2:48:10 AM (17 years ago)
Author:
[email protected]
Message:

Improve performance of arithmetic operators

Reviewed by Cameron Zwarich

Added a fast (non-virtual) mechanism to determine if a non-immediate JSValue*
is a JSNumberCell. We then use this to allow improved specialisation in many
arithmetic operators. SunSpider reports a 2.5% progression overall, with greater
than 10% progressions on a number of arithmetic heavy tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/JSNumberCell.h

    r35291 r35639  
    5959        virtual JSObject* toThisObject(ExecState*) const;
    6060        virtual JSValue* getJSNumber();
     61        int32_t fastToInt32() const;
     62        uint32_t fastToUInt32() const;
    6163
    6264        void* operator new(size_t size, ExecState* exec)
     
    147149    }
    148150
     151    inline int32_t JSNumberCell::fastToInt32() const
     152    {
     153        if (m_value >= -2147483648.0 && m_value < 2147483648.0)
     154            return static_cast<int32_t>(m_value);
     155        bool scratch;
     156        return JSValue::toInt32SlowCase(m_value, scratch);
     157    }
     158
     159    inline uint32_t JSNumberCell::fastToUInt32() const
     160    {
     161        if (m_value >= 0.0 && m_value < 4294967296.0)
     162            return static_cast<uint32_t>(m_value);
     163        bool scratch;
     164        return JSValue::toUInt32SlowCase(m_value, scratch);
     165    }
     166
    149167    ALWAYS_INLINE JSValue* JSValue::toJSNumber(ExecState* exec) const
    150168    {
Note: See TracChangeset for help on using the changeset viewer.