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

Side by Side Diff: src/parser.cc

Issue 125258: Don't strength reduce divisions by 1 or 2 as they can often be... (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 2635 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 break; 2646 break;
2647 } 2647 }
2648 } 2648 }
2649 2649
2650 // Convert constant divisions to multiplications for speed. 2650 // Convert constant divisions to multiplications for speed.
2651 if (op == Token::DIV && 2651 if (op == Token::DIV &&
2652 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) { 2652 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) {
2653 double y_val = y->AsLiteral()->handle()->Number(); 2653 double y_val = y->AsLiteral()->handle()->Number();
2654 int64_t y_int = static_cast<int64_t>(y_val); 2654 int64_t y_int = static_cast<int64_t>(y_val);
2655 // There are rounding issues with this optimization, but they don't 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 2656 // apply if the number to be divided with has a reciprocal that can be
2657 // be precisely represented as a floating point number. This is 2657 // precisely represented as a floating point number. This is the case
2658 // the case if the number is an integer power of 2. 2658 // if the number is an integer power of 2. Negative integer powers of
2659 if (static_cast<double>(y_int) == y_val && IsPowerOf2(y_int)) { 2659 // 2 work too, but for -2, -1, 1 and 2 we don't do the strength
2660 // reduction because the inlined optimistic idiv has a reasonable
2661 // chance of succeeding by producing a Smi answer with no remainder.
2662 if (static_cast<double>(y_int) == y_val &&
2663 (IsPowerOf2(y_int) || IsPowerOf2(-y_int)) &&
2664 (y_int > 2 || y_int < -2)) {
2660 y = NewNumberLiteral(1 / y_val); 2665 y = NewNumberLiteral(1 / y_val);
2661 op = Token::MUL; 2666 op = Token::MUL;
2662 } 2667 }
2663 } 2668 }
2664 2669
2665 // For now we distinguish between comparisons and other binary 2670 // For now we distinguish between comparisons and other binary
2666 // operations. (We could combine the two and get rid of this 2671 // operations. (We could combine the two and get rid of this
2667 // code an AST node eventually.) 2672 // code an AST node eventually.)
2668 if (Token::IsCompareOp(op)) { 2673 if (Token::IsCompareOp(op)) {
2669 // We have a comparison. 2674 // We have a comparison.
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after
4640 start_position, 4645 start_position,
4641 is_expression); 4646 is_expression);
4642 return result; 4647 return result;
4643 } 4648 }
4644 4649
4645 4650
4646 #undef NEW 4651 #undef NEW
4647 4652
4648 4653
4649 } } // namespace v8::internal 4654 } } // 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