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

Side by Side Diff: src/runtime.cc

Issue 9690010: Ensure consistency of Math.sqrt on Intel platforms. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed suggestions. Created 8 years, 9 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 7423 matching lines...) Expand 10 before | Expand all | Expand 10 after
7434 int y = args.smi_at(1); 7434 int y = args.smi_at(1);
7435 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); 7435 return isolate->heap()->NumberFromDouble(power_double_int(x, y));
7436 } 7436 }
7437 7437
7438 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7438 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7439 int y_int = static_cast<int>(y); 7439 int y_int = static_cast<int>(y);
7440 double result; 7440 double result;
7441 if (y == y_int) { 7441 if (y == y_int) {
7442 result = power_double_int(x, y_int); // Returns 1 if exponent is 0. 7442 result = power_double_int(x, y_int); // Returns 1 if exponent is 0.
7443 } else if (y == 0.5) { 7443 } else if (y == 0.5) {
7444 result = (isinf(x)) ? V8_INFINITY : sqrt(x + 0.0); // Convert -0 to +0. 7444 result = (isinf(x)) ? V8_INFINITY
7445 : fast_sqrt(x + 0.0); // Convert -0 to +0.
7445 } else if (y == -0.5) { 7446 } else if (y == -0.5) {
7446 result = (isinf(x)) ? 0 : 1.0 / sqrt(x + 0.0); // Convert -0 to +0. 7447 result = (isinf(x)) ? 0
7448 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0.
7447 } else { 7449 } else {
7448 result = power_double_double(x, y); 7450 result = power_double_double(x, y);
7449 } 7451 }
7450 if (isnan(result)) return isolate->heap()->nan_value(); 7452 if (isnan(result)) return isolate->heap()->nan_value();
7451 return isolate->heap()->AllocateHeapNumber(result); 7453 return isolate->heap()->AllocateHeapNumber(result);
7452 } 7454 }
7453 7455
7454 // Fast version of Math.pow if we know that y is not an integer and y is not 7456 // Fast version of Math.pow if we know that y is not an integer and y is not
7455 // -0.5 or 0.5. Used as slow case from full codegen. 7457 // -0.5 or 0.5. Used as slow case from full codegen.
7456 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { 7458 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7522 return isolate->transcendental_cache()->Get(TranscendentalCache::SIN, x); 7524 return isolate->transcendental_cache()->Get(TranscendentalCache::SIN, x);
7523 } 7525 }
7524 7526
7525 7527
7526 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_sqrt) { 7528 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_sqrt) {
7527 NoHandleAllocation ha; 7529 NoHandleAllocation ha;
7528 ASSERT(args.length() == 1); 7530 ASSERT(args.length() == 1);
7529 isolate->counters()->math_sqrt()->Increment(); 7531 isolate->counters()->math_sqrt()->Increment();
7530 7532
7531 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7533 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7532 return isolate->heap()->AllocateHeapNumber(sqrt(x)); 7534 return isolate->heap()->AllocateHeapNumber(fast_sqrt(x));
7533 } 7535 }
7534 7536
7535 7537
7536 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { 7538 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) {
7537 NoHandleAllocation ha; 7539 NoHandleAllocation ha;
7538 ASSERT(args.length() == 1); 7540 ASSERT(args.length() == 1);
7539 isolate->counters()->math_tan()->Increment(); 7541 isolate->counters()->math_tan()->Increment();
7540 7542
7541 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7543 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7542 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x); 7544 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
(...skipping 5778 matching lines...) Expand 10 before | Expand all | Expand 10 after
13321 // Handle last resort GC and make sure to allow future allocations 13323 // Handle last resort GC and make sure to allow future allocations
13322 // to grow the heap without causing GCs (if possible). 13324 // to grow the heap without causing GCs (if possible).
13323 isolate->counters()->gc_last_resort_from_js()->Increment(); 13325 isolate->counters()->gc_last_resort_from_js()->Increment();
13324 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13326 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13325 "Runtime::PerformGC"); 13327 "Runtime::PerformGC");
13326 } 13328 }
13327 } 13329 }
13328 13330
13329 13331
13330 } } // namespace v8::internal 13332 } } // namespace v8::internal
OLDNEW
« src/ia32/codegen-ia32.cc ('K') | « src/platform-win32.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698