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 6044010: Do not transform a/b into a * (1/b) in the parser for integer constants.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 11 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 2305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 uint32_t shift = DoubleToInt32(y_val) & 0x1f; 2316 uint32_t shift = DoubleToInt32(y_val) & 0x1f;
2317 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); 2317 int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift);
2318 x = NewNumberLiteral(value); 2318 x = NewNumberLiteral(value);
2319 continue; 2319 continue;
2320 } 2320 }
2321 default: 2321 default:
2322 break; 2322 break;
2323 } 2323 }
2324 } 2324 }
2325 2325
2326 // Convert constant divisions to multiplications for speed.
2327 if (op == Token::DIV &&
2328 y && y->AsLiteral() && y->AsLiteral()->handle()->IsNumber()) {
2329 double y_val = y->AsLiteral()->handle()->Number();
2330 int64_t y_int = static_cast<int64_t>(y_val);
2331 // There are rounding issues with this optimization, but they don't
2332 // apply if the number to be divided with has a reciprocal that can be
2333 // precisely represented as a floating point number. This is the case
2334 // if the number is an integer power of 2. Negative integer powers of
2335 // 2 work too, but for -2, -1, 1 and 2 we don't do the strength
2336 // reduction because the inlined optimistic idiv has a reasonable
2337 // chance of succeeding by producing a Smi answer with no remainder.
2338 if (static_cast<double>(y_int) == y_val &&
2339 (IsPowerOf2(y_int) || IsPowerOf2(-y_int)) &&
2340 (y_int > 2 || y_int < -2)) {
2341 y = NewNumberLiteral(1 / y_val);
2342 op = Token::MUL;
2343 }
2344 }
2345
2346 // For now we distinguish between comparisons and other binary 2326 // For now we distinguish between comparisons and other binary
2347 // operations. (We could combine the two and get rid of this 2327 // operations. (We could combine the two and get rid of this
2348 // code and AST node eventually.) 2328 // code and AST node eventually.)
2349 if (Token::IsCompareOp(op)) { 2329 if (Token::IsCompareOp(op)) {
2350 // We have a comparison. 2330 // We have a comparison.
2351 Token::Value cmp = op; 2331 Token::Value cmp = op;
2352 switch (op) { 2332 switch (op) {
2353 case Token::NE: cmp = Token::EQ; break; 2333 case Token::NE: cmp = Token::EQ; break;
2354 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; 2334 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
2355 default: break; 2335 default: break;
(...skipping 2352 matching lines...) Expand 10 before | Expand all | Expand 10 after
4708 Handle<String> source = Handle<String>(String::cast(script->source())); 4688 Handle<String> source = Handle<String>(String::cast(script->source()));
4709 result = parser.ParseProgram(source, info->is_global()); 4689 result = parser.ParseProgram(source, info->is_global());
4710 } 4690 }
4711 } 4691 }
4712 4692
4713 info->SetFunction(result); 4693 info->SetFunction(result);
4714 return (result != NULL); 4694 return (result != NULL);
4715 } 4695 }
4716 4696
4717 } } // namespace v8::internal 4697 } } // 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