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

Side by Side Diff: src/x64/codegen-x64.cc

Issue 545134: Fix V8 issue 580: Arithmetic on some integer constants gives wrong anwers. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 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 | test/mjsunit/regress/regress-580.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 6187 matching lines...) Expand 10 before | Expand all | Expand 10 after
6198 __ bind(&true_result); 6198 __ bind(&true_result);
6199 __ movq(rax, Immediate(1)); 6199 __ movq(rax, Immediate(1));
6200 __ ret(1 * kPointerSize); 6200 __ ret(1 * kPointerSize);
6201 __ bind(&false_result); 6201 __ bind(&false_result);
6202 __ xor_(rax, rax); 6202 __ xor_(rax, rax);
6203 __ ret(1 * kPointerSize); 6203 __ ret(1 * kPointerSize);
6204 } 6204 }
6205 6205
6206 6206
6207 bool CodeGenerator::FoldConstantSmis(Token::Value op, int left, int right) { 6207 bool CodeGenerator::FoldConstantSmis(Token::Value op, int left, int right) {
6208 // TODO(X64): This method is identical to the ia32 version.
6209 // Either find a reason to change it, or move it somewhere where it can be
6210 // shared. (Notice: It assumes that a Smi can fit in an int).
6211
6212 Object* answer_object = Heap::undefined_value(); 6208 Object* answer_object = Heap::undefined_value();
6213 switch (op) { 6209 switch (op) {
6214 case Token::ADD: 6210 case Token::ADD:
6215 if (Smi::IsValid(left + right)) { 6211 // Use intptr_t to detect overflow of 32-bit int.
6212 if (Smi::IsValid(static_cast<intptr_t>(left) + right)) {
6216 answer_object = Smi::FromInt(left + right); 6213 answer_object = Smi::FromInt(left + right);
6217 } 6214 }
6218 break; 6215 break;
6219 case Token::SUB: 6216 case Token::SUB:
6220 if (Smi::IsValid(left - right)) { 6217 // Use intptr_t to detect overflow of 32-bit int.
6218 if (Smi::IsValid(static_cast<intptr_t>(left) - right)) {
6221 answer_object = Smi::FromInt(left - right); 6219 answer_object = Smi::FromInt(left - right);
6222 } 6220 }
6223 break; 6221 break;
6224 case Token::MUL: { 6222 case Token::MUL: {
6225 double answer = static_cast<double>(left) * right; 6223 double answer = static_cast<double>(left) * right;
6226 if (answer >= Smi::kMinValue && answer <= Smi::kMaxValue) { 6224 if (answer >= Smi::kMinValue && answer <= Smi::kMaxValue) {
6227 // If the product is zero and the non-zero factor is negative, 6225 // If the product is zero and the non-zero factor is negative,
6228 // the spec requires us to return floating point negative zero. 6226 // the spec requires us to return floating point negative zero.
6229 if (answer != 0 || (left + right) >= 0) { 6227 if (answer != 0 || (left + right) >= 0) {
6230 answer_object = Smi::FromInt(static_cast<int>(answer)); 6228 answer_object = Smi::FromInt(static_cast<int>(answer));
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after
8377 // Call the function from C++. 8375 // Call the function from C++.
8378 return FUNCTION_CAST<ModuloFunction>(buffer); 8376 return FUNCTION_CAST<ModuloFunction>(buffer);
8379 } 8377 }
8380 8378
8381 #endif 8379 #endif
8382 8380
8383 8381
8384 #undef __ 8382 #undef __
8385 8383
8386 } } // namespace v8::internal 8384 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-580.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698