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

Side by Side Diff: src/runtime.cc

Issue 1694004: Simplify double to number convertion. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 7 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 | « src/heap.cc ('k') | 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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 5394 matching lines...) Expand 10 before | Expand all | Expand 10 after
5405 return Heap::AllocateHeapNumber(-x); 5405 return Heap::AllocateHeapNumber(-x);
5406 } 5406 }
5407 5407
5408 5408
5409 static Object* Runtime_NumberDiv(Arguments args) { 5409 static Object* Runtime_NumberDiv(Arguments args) {
5410 NoHandleAllocation ha; 5410 NoHandleAllocation ha;
5411 ASSERT(args.length() == 2); 5411 ASSERT(args.length() == 2);
5412 5412
5413 CONVERT_DOUBLE_CHECKED(x, args[0]); 5413 CONVERT_DOUBLE_CHECKED(x, args[0]);
5414 CONVERT_DOUBLE_CHECKED(y, args[1]); 5414 CONVERT_DOUBLE_CHECKED(y, args[1]);
5415 return Heap::NewNumberFromDouble(x / y); 5415 return Heap::NumberFromDouble(x / y);
5416 } 5416 }
5417 5417
5418 5418
5419 static Object* Runtime_NumberMod(Arguments args) { 5419 static Object* Runtime_NumberMod(Arguments args) {
5420 NoHandleAllocation ha; 5420 NoHandleAllocation ha;
5421 ASSERT(args.length() == 2); 5421 ASSERT(args.length() == 2);
5422 5422
5423 CONVERT_DOUBLE_CHECKED(x, args[0]); 5423 CONVERT_DOUBLE_CHECKED(x, args[0]);
5424 CONVERT_DOUBLE_CHECKED(y, args[1]); 5424 CONVERT_DOUBLE_CHECKED(y, args[1]);
5425 5425
5426 x = modulo(x, y); 5426 x = modulo(x, y);
5427 // NewNumberFromDouble may return a Smi instead of a Number object 5427 // NumberFromDouble may return a Smi instead of a Number object
5428 return Heap::NewNumberFromDouble(x); 5428 return Heap::NumberFromDouble(x);
5429 } 5429 }
5430 5430
5431 5431
5432 static Object* Runtime_StringAdd(Arguments args) { 5432 static Object* Runtime_StringAdd(Arguments args) {
5433 NoHandleAllocation ha; 5433 NoHandleAllocation ha;
5434 ASSERT(args.length() == 2); 5434 ASSERT(args.length() == 2);
5435 CONVERT_CHECKED(String, str1, args[0]); 5435 CONVERT_CHECKED(String, str1, args[0]);
5436 CONVERT_CHECKED(String, str2, args[1]); 5436 CONVERT_CHECKED(String, str2, args[1]);
5437 Counters::string_add_runtime.Increment(); 5437 Counters::string_add_runtime.Increment();
5438 return Heap::AllocateConsString(str1, str2); 5438 return Heap::AllocateConsString(str1, str2);
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
6072 } 6072 }
6073 6073
6074 // If the magnitude is big enough, there's no place for fraction part. If we 6074 // If the magnitude is big enough, there's no place for fraction part. If we
6075 // try to add 0.5 to this number, 1.0 will be added instead. 6075 // try to add 0.5 to this number, 1.0 will be added instead.
6076 if (exponent >= 52) { 6076 if (exponent >= 52) {
6077 return number; 6077 return number;
6078 } 6078 }
6079 6079
6080 if (sign && value >= -0.5) return Heap::minus_zero_value(); 6080 if (sign && value >= -0.5) return Heap::minus_zero_value();
6081 6081
6082 return Heap::NumberFromDouble(floor(value + 0.5)); 6082 // Do not call NumberFromDouble() to avoid extra checks.
6083 return Heap::AllocateHeapNumber(floor(value + 0.5));
6083 } 6084 }
6084 6085
6085 6086
6086 static Object* Runtime_Math_sin(Arguments args) { 6087 static Object* Runtime_Math_sin(Arguments args) {
6087 NoHandleAllocation ha; 6088 NoHandleAllocation ha;
6088 ASSERT(args.length() == 1); 6089 ASSERT(args.length() == 1);
6089 Counters::math_sin.Increment(); 6090 Counters::math_sin.Increment();
6090 6091
6091 CONVERT_DOUBLE_CHECKED(x, args[0]); 6092 CONVERT_DOUBLE_CHECKED(x, args[0]);
6092 return TranscendentalCache::Get(TranscendentalCache::SIN, x); 6093 return TranscendentalCache::Get(TranscendentalCache::SIN, x);
(...skipping 4149 matching lines...) Expand 10 before | Expand all | Expand 10 after
10242 } else { 10243 } else {
10243 // Handle last resort GC and make sure to allow future allocations 10244 // Handle last resort GC and make sure to allow future allocations
10244 // to grow the heap without causing GCs (if possible). 10245 // to grow the heap without causing GCs (if possible).
10245 Counters::gc_last_resort_from_js.Increment(); 10246 Counters::gc_last_resort_from_js.Increment();
10246 Heap::CollectAllGarbage(false); 10247 Heap::CollectAllGarbage(false);
10247 } 10248 }
10248 } 10249 }
10249 10250
10250 10251
10251 } } // namespace v8::internal 10252 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698