Commit 678e6b8c authored by oliver's avatar oliver

Add a fast path for bitwise-and of two immediate numbers for a 0.7%...

Add a fast path for bitwise-and of two immediate numbers for a 0.7% improvement in SunSpider (4% bitop improvement).

Reviewed by Sam.

This only improves bitwise-and performance, as the additional logic required
for similar code paths on or, xor, and shifting requires additional operations
and branches that negate (and in certain cases, regress) any advantage we might
otherwise receive.

This improves performance on all bitop tests, the cryptography tests, as well as
the string-base64 and string-unpack-code tests.  No significant degradation on
any other tests.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@27615 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9fb42da2
2007-11-08 Oliver Hunt <oliver@apple.com>
Reviewed by Sam.
Add a fast path for bitwise-and of two immediate numbers for a 0.7% improvement in SunSpider (4% bitop improvement).
This only improves bitwise-and performance, as the additional logic required
for similar code paths on or, xor, and shifting requires additional operations
and branches that negate (and in certain cases, regress) any advantage we might
otherwise receive.
This improves performance on all bitop tests, the cryptography tests, as well as
the string-base64 and string-unpack-code tests. No significant degradation on
any other tests.
* kjs/JSImmediate.h:
(KJS::JSImmediate::areBothImmediateNumbers):
(KJS::JSImmediate::andImmediateNumbers):
* kjs/nodes.cpp:
(KJS::BitAndNode::evaluate):
* kjs/value.h:
(KJS::jsNumberFromAnd):
2007-11-08 Adam Roben <aroben@apple.com>
Stop using KJS inside of MathExtras.h
......
......@@ -82,6 +82,17 @@ public:
return (getTag(v) == UndefinedType);
}
static ALWAYS_INLINE bool areBothImmediateNumbers(const JSValue* v1, const JSValue* v2)
{
return (reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2) & TagMask) == NumberType;
}
static ALWAYS_INLINE JSValue* andImmediateNumbers(const JSValue* v1, const JSValue* v2)
{
ASSERT(areBothImmediateNumbers(v1, v2));
return reinterpret_cast<JSValue*>(reinterpret_cast<uintptr_t>(v1) & reinterpret_cast<uintptr_t>(v2));
}
static JSValue* fromDouble(double d);
static double toDouble(const JSValue*);
static bool toBoolean(const JSValue*);
......
......@@ -2185,13 +2185,13 @@ void BitAndNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::No
// ECMA 11.10
JSValue *BitAndNode::evaluate(ExecState *exec)
{
{
JSValue *v1 = expr1->evaluate(exec);
KJS_CHECKEXCEPTIONVALUE
JSValue *v2 = expr2->evaluate(exec);
KJS_CHECKEXCEPTIONVALUE
return jsNumber(v1->toInt32(exec) & v2->toInt32(exec));
return jsNumberFromAnd(exec, v1, v2);
}
void BitXOrNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
......
......@@ -204,6 +204,13 @@ ALWAYS_INLINE JSValue* jsNumber(double d)
return v ? v : jsNumberCell(d);
}
ALWAYS_INLINE JSValue* jsNumberFromAnd(ExecState *exec, JSValue* v1, JSValue* v2)
{
if (JSImmediate::areBothImmediateNumbers(v1, v2))
return JSImmediate::andImmediateNumbers(v1, v2);
return jsNumber(v1->toInt32(exec) & v2->toInt32(exec));
}
inline JSValue::JSValue()
{
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment