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

Side by Side Diff: src/parser.cc

Issue 126116: Optimize constant divisions by powers of 2. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after
2640 uint32_t shift = DoubleToInt32(y_val) & 0x1f; 2640 uint32_t shift = DoubleToInt32(y_val) & 0x1f;
2641 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); 2641 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift);
2642 x = NewNumberLiteral(value); 2642 x = NewNumberLiteral(value);
2643 continue; 2643 continue;
2644 } 2644 }
2645 default: 2645 default:
2646 break; 2646 break;
2647 } 2647 }
2648 } 2648 }
2649 2649
2650 // Convert constant divisions to multiplications for speed.
2651 if (op == Token::DIV &&
2652 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) {
2653 double y_val = y->AsLiteral()->handle()->Number();
2654 int64_t y_int = static_cast<int64_t>(y_val);
2655 // There are rounding issues with this optimization, but they don't
2656 // apply if the number to be divided with has a reciprocal that can
2657 // be precisely represented as a floating point number. This is
2658 // the case if the number is an integer power of 2. You can test for
2659 // an integer power of 2 by subtracting 1 and anding.
2660 if (static_cast<double>(y_int) == y_val &&
2661 ((y_int - 1) & y_int) == 0) {
2662 y = NewNumberLiteral(1 / y_val);
2663 op = Token::MUL;
2664 }
2665 }
2666
2650 // For now we distinguish between comparisons and other binary 2667 // For now we distinguish between comparisons and other binary
2651 // operations. (We could combine the two and get rid of this 2668 // operations. (We could combine the two and get rid of this
2652 // code an AST node eventually.) 2669 // code an AST node eventually.)
2653 if (Token::IsCompareOp(op)) { 2670 if (Token::IsCompareOp(op)) {
2654 // We have a comparison. 2671 // We have a comparison.
2655 Token::Value cmp = op; 2672 Token::Value cmp = op;
2656 switch (op) { 2673 switch (op) {
2657 case Token::NE: cmp = Token::EQ; break; 2674 case Token::NE: cmp = Token::EQ; break;
2658 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2675 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2659 default: break; 2676 default: break;
(...skipping 1965 matching lines...) Expand 10 before | Expand all | Expand 10 after
4625 start_position, 4642 start_position,
4626 is_expression); 4643 is_expression);
4627 return result; 4644 return result;
4628 } 4645 }
4629 4646
4630 4647
4631 #undef NEW 4648 #undef NEW
4632 4649
4633 4650
4634 } } // namespace v8::internal 4651 } } // namespace v8::internal
OLDNEW
« 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