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

Side by Side Diff: src/runtime.cc

Issue 8831008: Tweaks on Math.pow (ia32 and x64). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 7380 matching lines...) Expand 10 before | Expand all | Expand 10 after
7391 7391
7392 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_log) { 7392 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_log) {
7393 NoHandleAllocation ha; 7393 NoHandleAllocation ha;
7394 ASSERT(args.length() == 1); 7394 ASSERT(args.length() == 1);
7395 isolate->counters()->math_log()->Increment(); 7395 isolate->counters()->math_log()->Increment();
7396 7396
7397 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7397 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7398 return isolate->transcendental_cache()->Get(TranscendentalCache::LOG, x); 7398 return isolate->transcendental_cache()->Get(TranscendentalCache::LOG, x);
7399 } 7399 }
7400 7400
7401 7401 // Slow version of Math.pow. We check for fast paths for special cases.
7402 // Used if SSE2/VFP3 is not available.
7402 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow) { 7403 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow) {
7403 NoHandleAllocation ha; 7404 NoHandleAllocation ha;
7404 ASSERT(args.length() == 2); 7405 ASSERT(args.length() == 2);
7405 isolate->counters()->math_pow()->Increment(); 7406 isolate->counters()->math_pow()->Increment();
7406 7407
7407 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7408 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7408 7409
7409 // If the second argument is a smi, it is much faster to call the 7410 // If the second argument is a smi, it is much faster to call the
7410 // custom powi() function than the generic pow(). 7411 // custom powi() function than the generic pow().
7411 if (args[1]->IsSmi()) { 7412 if (args[1]->IsSmi()) {
7412 int y = args.smi_at(1); 7413 int y = args.smi_at(1);
7413 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); 7414 return isolate->heap()->NumberFromDouble(power_double_int(x, y));
7414 } 7415 }
7415 7416
7416 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7417 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7417 // Returning a smi would not confuse crankshaft as this part of code is only 7418 int y_int = static_cast<int>(y);
7418 // run if SSE2 was not available, in which case crankshaft is disabled. 7419 double result;
7419 if (y == 0) return Smi::FromInt(1); // Returns 1 if exponent is 0. 7420 if (y == y_int) {
7420 return isolate->heap()->AllocateHeapNumber(power_double_double(x, y)); 7421 result = power_double_int(x, y_int); // Returns 1 if exponent is 0.
7422 } else if (y == 0.5) {
7423 result = (isinf(x)) ? V8_INFINITY : sqrt(x + 0.0); // Convert -0 to +0.
7424 } else if (y == -0.5) {
7425 result = (isinf(x)) ? 0 : 1.0 / sqrt(x + 0.0); // Convert -0 to +0.
7426 } else {
7427 result = power_double_double(x, y);
7428 }
7429 if (isnan(result)) return isolate->heap()->nan_value();
7430 return isolate->heap()->AllocateHeapNumber(result);
7421 } 7431 }
7422 7432
7423 // Fast version of Math.pow if we know that y is not an integer and 7433 // Fast version of Math.pow if we know that y is not an integer and y is not
7424 // y is not -0.5 or 0.5. Used as slowcase from codegen. 7434 // -0.5 or 0.5. Used as slow case from fullcodegen.
7425 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { 7435 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) {
7426 NoHandleAllocation ha; 7436 NoHandleAllocation ha;
7427 ASSERT(args.length() == 2); 7437 ASSERT(args.length() == 2);
7438 isolate->counters()->math_pow()->Increment();
7439
7428 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7440 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7429 CONVERT_DOUBLE_ARG_CHECKED(y, 1); 7441 CONVERT_DOUBLE_ARG_CHECKED(y, 1);
7430 if (y == 0) { 7442 if (y == 0) {
7431 return Smi::FromInt(1); 7443 return Smi::FromInt(1);
7432 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) { 7444 } else if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
ulan 2011/12/07 16:03:04 This code is almost the same as in power_double_do
7433 return isolate->heap()->nan_value(); 7445 return isolate->heap()->nan_value();
7434 } else { 7446 } else {
7435 return isolate->heap()->AllocateHeapNumber(pow(x, y)); 7447 return isolate->heap()->AllocateHeapNumber(pow(x, y));
7436 } 7448 }
7437 } 7449 }
7438 7450
7439 7451
7440 RUNTIME_FUNCTION(MaybeObject*, Runtime_RoundNumber) { 7452 RUNTIME_FUNCTION(MaybeObject*, Runtime_RoundNumber) {
7441 NoHandleAllocation ha; 7453 NoHandleAllocation ha;
7442 ASSERT(args.length() == 1); 7454 ASSERT(args.length() == 1);
(...skipping 6126 matching lines...) Expand 10 before | Expand all | Expand 10 after
13569 } else { 13581 } else {
13570 // Handle last resort GC and make sure to allow future allocations 13582 // Handle last resort GC and make sure to allow future allocations
13571 // to grow the heap without causing GCs (if possible). 13583 // to grow the heap without causing GCs (if possible).
13572 isolate->counters()->gc_last_resort_from_js()->Increment(); 13584 isolate->counters()->gc_last_resort_from_js()->Increment();
13573 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13585 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13574 } 13586 }
13575 } 13587 }
13576 13588
13577 13589
13578 } } // namespace v8::internal 13590 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698