Changeset 51334 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Nov 23, 2009, 6:30:04 PM (16 years ago)
Author:
[email protected]
Message:

Streamlined some Math functions where we expect or know the result not
to be representable as an int.

Reviewed by Oliver Hunt.

SunSpider says 0.6% faster.

  • runtime/JSNumberCell.h:

(JSC::JSValue::JSValue):

  • runtime/JSValue.h:

(JSC::JSValue::):
(JSC::jsDoubleNumber):
(JSC::JSValue::JSValue): Added a function for making a numeric JSValue
and skipping the "can I encode this as an int?" check, avoiding the
overhead of int <-> double roundtripping and double <-> double comparison
and branching.

  • runtime/MathObject.cpp:

(JSC::mathProtoFuncACos):
(JSC::mathProtoFuncASin):
(JSC::mathProtoFuncATan):
(JSC::mathProtoFuncATan2):
(JSC::mathProtoFuncCos):
(JSC::mathProtoFuncExp):
(JSC::mathProtoFuncLog):
(JSC::mathProtoFuncRandom):
(JSC::mathProtoFuncSin):
(JSC::mathProtoFuncSqrt):
(JSC::mathProtoFuncTan): For these functions, which we expect or know
to produce results not representable as ints, call jsDoubleNumber instead
of jsNumber.

Location:
trunk/JavaScriptCore/runtime
Files:
3 edited

Legend:

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

    r49649 r51334  
    110110    }
    111111
     112    ALWAYS_INLINE JSValue::JSValue(EncodeAsDoubleTag, ExecState* exec, double d)
     113    {
     114        *this = jsNumberCell(exec, d);
     115    }
     116
    112117    inline JSValue::JSValue(ExecState* exec, double d)
    113118    {
     
    194199
    195200#if USE(JSVALUE64)
     201    ALWAYS_INLINE JSValue::JSValue(EncodeAsDoubleTag, ExecState*, double d)
     202    {
     203        *this = JSImmediate::fromNumberOutsideIntegerRange(d);
     204    }
     205
    196206    inline JSValue::JSValue(ExecState*, double d)
    197207    {
  • trunk/JavaScriptCore/runtime/JSValue.h

    r49734 r51334  
    8181        enum JSTrueTag { JSTrue };
    8282        enum JSFalseTag { JSFalse };
     83        enum EncodeAsDoubleTag { EncodeAsDouble };
    8384
    8485        JSValue();
     
    9192
    9293        // Numbers
     94        JSValue(EncodeAsDoubleTag, ExecState*, double);
    9395        JSValue(ExecState*, double);
    9496        JSValue(ExecState*, char);
     
    280282    }
    281283
     284    ALWAYS_INLINE JSValue jsDoubleNumber(ExecState* exec, double d)
     285    {
     286        return JSValue(JSValue::EncodeAsDouble, exec, d);
     287    }
     288
    282289    ALWAYS_INLINE JSValue jsNumber(ExecState* exec, double d)
    283290    {
     
    584591    }
    585592
     593    ALWAYS_INLINE JSValue::JSValue(EncodeAsDoubleTag, ExecState*, double d)
     594    {
     595        u.asDouble = d;
     596    }
     597
    586598    inline JSValue::JSValue(ExecState* exec, double d)
    587599    {
  • trunk/JavaScriptCore/runtime/MathObject.cpp

    r50789 r51334  
    120120JSValue JSC_HOST_CALL mathProtoFuncACos(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    121121{
    122     return jsNumber(exec, acos(args.at(0).toNumber(exec)));
     122    return jsDoubleNumber(exec, acos(args.at(0).toNumber(exec)));
    123123}
    124124
    125125JSValue JSC_HOST_CALL mathProtoFuncASin(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    126126{
    127     return jsNumber(exec, asin(args.at(0).toNumber(exec)));
     127    return jsDoubleNumber(exec, asin(args.at(0).toNumber(exec)));
    128128}
    129129
    130130JSValue JSC_HOST_CALL mathProtoFuncATan(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    131131{
    132     return jsNumber(exec, atan(args.at(0).toNumber(exec)));
     132    return jsDoubleNumber(exec, atan(args.at(0).toNumber(exec)));
    133133}
    134134
    135135JSValue JSC_HOST_CALL mathProtoFuncATan2(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    136136{
    137     return jsNumber(exec, atan2(args.at(0).toNumber(exec), args.at(1).toNumber(exec)));
     137    return jsDoubleNumber(exec, atan2(args.at(0).toNumber(exec), args.at(1).toNumber(exec)));
    138138}
    139139
     
    145145JSValue JSC_HOST_CALL mathProtoFuncCos(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    146146{
    147     return jsNumber(exec, cos(args.at(0).toNumber(exec)));
     147    return jsDoubleNumber(exec, cos(args.at(0).toNumber(exec)));
    148148}
    149149
    150150JSValue JSC_HOST_CALL mathProtoFuncExp(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    151151{
    152     return jsNumber(exec, exp(args.at(0).toNumber(exec)));
     152    return jsDoubleNumber(exec, exp(args.at(0).toNumber(exec)));
    153153}
    154154
     
    160160JSValue JSC_HOST_CALL mathProtoFuncLog(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    161161{
    162     return jsNumber(exec, log(args.at(0).toNumber(exec)));
     162    return jsDoubleNumber(exec, log(args.at(0).toNumber(exec)));
    163163}
    164164
     
    211211JSValue JSC_HOST_CALL mathProtoFuncRandom(ExecState* exec, JSObject*, JSValue, const ArgList&)
    212212{
    213     return jsNumber(exec, exec->globalData().weakRandom.get());
     213    return jsDoubleNumber(exec, exec->globalData().weakRandom.get());
    214214}
    215215
     
    224224JSValue JSC_HOST_CALL mathProtoFuncSin(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    225225{
    226     return jsNumber(exec, sin(args.at(0).toNumber(exec)));
     226    return jsDoubleNumber(exec, sin(args.at(0).toNumber(exec)));
    227227}
    228228
    229229JSValue JSC_HOST_CALL mathProtoFuncSqrt(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    230230{
    231     return jsNumber(exec, sqrt(args.at(0).toNumber(exec)));
     231    return jsDoubleNumber(exec, sqrt(args.at(0).toNumber(exec)));
    232232}
    233233
    234234JSValue JSC_HOST_CALL mathProtoFuncTan(ExecState* exec, JSObject*, JSValue, const ArgList& args)
    235235{
    236     return jsNumber(exec, tan(args.at(0).toNumber(exec)));
     236    return jsDoubleNumber(exec, tan(args.at(0).toNumber(exec)));
    237237}
    238238
Note: See TracChangeset for help on using the changeset viewer.