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

Unified Diff: src/ast.cc

Issue 1233003: Speed up conversion of untagged int32 result if we know it must be a smi. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 9 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 | « src/ast.h ('k') | src/ia32/codegen-ia32.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.cc
===================================================================
--- src/ast.cc (revision 4271)
+++ src/ast.cc (working copy)
@@ -172,6 +172,72 @@
}
+bool Expression::GuaranteedSmiResult() {
+ BinaryOperation* node = AsBinaryOperation();
+ if (node == NULL) return false;
+ Token::Value op = node->op();
+ switch (op) {
+ case Token::COMMA:
+ case Token::OR:
+ case Token::AND:
+ case Token::ADD:
+ case Token::SUB:
+ case Token::MUL:
+ case Token::DIV:
+ case Token::MOD:
+ case Token::BIT_XOR:
+ case Token::SHL:
+ return false;
+ break;
+ case Token::BIT_OR:
+ case Token::BIT_AND: {
+ Literal* left = node->left()->AsLiteral();
+ Literal* right = node->right()->AsLiteral();
+ if (left != NULL && left->handle()->IsSmi()) {
+ int value = Smi::cast(*left->handle())->value();
+ if (op == Token::BIT_OR && ((value & 0xc0000000) == 0xc0000000)) {
+ // Result of bitwise or is always a negative Smi.
+ return true;
+ }
+ if (op == Token::BIT_AND && ((value & 0xc0000000) == 0)) {
+ // Result of bitwise and is always a positive Smi.
+ return true;
+ }
+ }
+ if (right != NULL && right->handle()->IsSmi()) {
+ int value = Smi::cast(*right->handle())->value();
+ if (op == Token::BIT_OR && ((value & 0xc0000000) == 0xc0000000)) {
+ // Result of bitwise or is always a negative Smi.
+ return true;
+ }
+ if (op == Token::BIT_AND && ((value & 0xc0000000) == 0)) {
+ // Result of bitwise and is always a positive Smi.
+ return true;
+ }
+ }
+ return false;
+ break;
+ }
+ case Token::SAR:
+ case Token::SHR: {
+ Literal* right = node->right()->AsLiteral();
+ if (right != NULL && right->handle()->IsSmi()) {
+ int value = Smi::cast(*right->handle())->value();
+ if ((value & 0x1F) > 1 ||
+ (op == Token::SAR && (value & 0x1F) == 1)) {
+ return true;
+ }
+ }
+ return false;
+ break;
+ }
+ default:
+ UNREACHABLE();
+ break;
+ }
+ return false;
+}
+
// ----------------------------------------------------------------------------
// Implementation of AstVisitor
« no previous file with comments | « src/ast.h ('k') | src/ia32/codegen-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698