Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1173)

Unified Diff: src/runtime.js

Issue 125118: Optimize the slow case implementations of bit operations by... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.js
===================================================================
--- src/runtime.js (revision 2158)
+++ src/runtime.js (working copy)
@@ -97,12 +97,12 @@
if (IS_STRING(this)) {
if (!IS_STRING(x)) return 1; // not equal
return %StringEquals(this, x);
- }
+ }
if (IS_NUMBER(this)) {
if (!IS_NUMBER(x)) return 1; // not equal
return %NumberEquals(this, x);
- }
+ }
// If anything else gets here, we just do simple identity check.
// Objects (including functions), null, undefined and booleans were
@@ -148,7 +148,7 @@
// Default implementation.
var a = %ToPrimitive(this, NO_HINT);
var b = %ToPrimitive(x, NO_HINT);
-
+
if (IS_STRING(a)) {
return %StringAdd(a, %ToString(b));
} else if (IS_STRING(b)) {
@@ -160,40 +160,48 @@
// Left operand (this) is already a string.
-function STRING_ADD_LEFT(x) {
- x = %ToString(%ToPrimitive(x, NO_HINT));
- return %StringAdd(this, x);
+function STRING_ADD_LEFT(y) {
+ if (!IS_STRING(y)) y = %ToString(%ToPrimitive(y, NO_HINT));
+ return %StringAdd(this, y);
}
-// Right operand (x) is already a string.
-function STRING_ADD_RIGHT(x) {
- var a = %ToString(%ToPrimitive(this, NO_HINT));
- return %StringAdd(a, x);
+// Right operand (y) is already a string.
+function STRING_ADD_RIGHT(y) {
+ var x = IS_STRING(this) ? this : %ToString(%ToPrimitive(this, NO_HINT));
+ return %StringAdd(x, y);
}
// ECMA-262, section 11.6.2, page 50.
-function SUB(x) {
- return %NumberSub(%ToNumber(this), %ToNumber(x));
+function SUB(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberSub(x, y);
}
// ECMA-262, section 11.5.1, page 48.
-function MUL(x) {
- return %NumberMul(%ToNumber(this), %ToNumber(x));
+function MUL(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberMul(x, y);
}
// ECMA-262, section 11.5.2, page 49.
-function DIV(x) {
- return %NumberDiv(%ToNumber(this), %ToNumber(x));
+function DIV(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberDiv(x, y);
}
// ECMA-262, section 11.5.3, page 49.
-function MOD(x) {
- return %NumberMod(%ToNumber(this), %ToNumber(x));
+function MOD(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberMod(x, y);
}
@@ -204,50 +212,82 @@
*/
// ECMA-262, section 11.10, page 57.
-function BIT_OR(x) {
- return %NumberOr(%ToNumber(this), %ToNumber(x));
+function BIT_OR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberOr(x, y);
}
// ECMA-262, section 11.10, page 57.
-function BIT_AND(x) {
- return %NumberAnd(%ToNumber(this), %ToNumber(x));
+function BIT_AND(y) {
+ var x;
+ if (IS_NUMBER(this)) {
+ x = this;
+ } else {
+ x = %ToNumber(this);
+ // Optimize for the case where we end up AND'ing a value
+ // that doesn't convert to a number. This is common in
+ // certain benchmarks.
+ if (NUMBER_IS_NAN(x)) return 0;
+ }
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberAnd(x, y);
}
// ECMA-262, section 11.10, page 57.
-function BIT_XOR(x) {
- return %NumberXor(%ToNumber(this), %ToNumber(x));
+function BIT_XOR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberXor(x, y);
}
// ECMA-262, section 11.4.7, page 47.
function UNARY_MINUS() {
- return %NumberUnaryMinus(%ToNumber(this));
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ return %NumberUnaryMinus(x);
}
// ECMA-262, section 11.4.8, page 48.
function BIT_NOT() {
- return %NumberNot(%ToNumber(this));
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ return %NumberNot(x);
}
// ECMA-262, section 11.7.1, page 51.
-function SHL(x) {
- return %NumberShl(%ToNumber(this), %ToNumber(x));
+function SHL(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberShl(x, y);
}
// ECMA-262, section 11.7.2, page 51.
-function SAR(x) {
- return %NumberSar(%ToNumber(this), %ToNumber(x));
+function SAR(y) {
+ var x;
+ if (IS_NUMBER(this)) {
+ x = this;
+ } else {
+ x = %ToNumber(this);
+ // Optimize for the case where we end up shifting a value
+ // that doesn't convert to a number. This is common in
+ // certain benchmarks.
+ if (NUMBER_IS_NAN(x)) return 0;
+ }
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberSar(x, y);
}
// ECMA-262, section 11.7.3, page 52.
-function SHR(x) {
- return %NumberShr(%ToNumber(this), %ToNumber(x));
+function SHR(y) {
+ var x = IS_NUMBER(this) ? this : %ToNumber(this);
+ if (!IS_NUMBER(y)) y = %ToNumber(y);
+ return %NumberShr(x, y);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698