OLD | NEW |
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 7241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7252 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7252 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
7253 | 7253 |
7254 // If the second argument is a smi, it is much faster to call the | 7254 // If the second argument is a smi, it is much faster to call the |
7255 // custom powi() function than the generic pow(). | 7255 // custom powi() function than the generic pow(). |
7256 if (args[1]->IsSmi()) { | 7256 if (args[1]->IsSmi()) { |
7257 int y = args.smi_at(1); | 7257 int y = args.smi_at(1); |
7258 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); | 7258 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); |
7259 } | 7259 } |
7260 | 7260 |
7261 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7261 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
7262 int y_int = static_cast<int>(y); | 7262 double result = power_helper(x, y); |
7263 double result; | |
7264 if (y == y_int) { | |
7265 result = power_double_int(x, y_int); // Returns 1 if exponent is 0. | |
7266 } else if (y == 0.5) { | |
7267 result = (isinf(x)) ? V8_INFINITY | |
7268 : fast_sqrt(x + 0.0); // Convert -0 to +0. | |
7269 } else if (y == -0.5) { | |
7270 result = (isinf(x)) ? 0 | |
7271 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. | |
7272 } else { | |
7273 result = power_double_double(x, y); | |
7274 } | |
7275 if (isnan(result)) return isolate->heap()->nan_value(); | 7263 if (isnan(result)) return isolate->heap()->nan_value(); |
7276 return isolate->heap()->AllocateHeapNumber(result); | 7264 return isolate->heap()->AllocateHeapNumber(result); |
7277 } | 7265 } |
7278 | 7266 |
7279 // Fast version of Math.pow if we know that y is not an integer and y is not | 7267 // Fast version of Math.pow if we know that y is not an integer and y is not |
7280 // -0.5 or 0.5. Used as slow case from full codegen. | 7268 // -0.5 or 0.5. Used as slow case from full codegen. |
7281 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { | 7269 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { |
7282 NoHandleAllocation ha; | 7270 NoHandleAllocation ha; |
7283 ASSERT(args.length() == 2); | 7271 ASSERT(args.length() == 2); |
7284 isolate->counters()->math_pow()->Increment(); | 7272 isolate->counters()->math_pow()->Increment(); |
(...skipping 6248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13533 // Handle last resort GC and make sure to allow future allocations | 13521 // Handle last resort GC and make sure to allow future allocations |
13534 // to grow the heap without causing GCs (if possible). | 13522 // to grow the heap without causing GCs (if possible). |
13535 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13523 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13536 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13524 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13537 "Runtime::PerformGC"); | 13525 "Runtime::PerformGC"); |
13538 } | 13526 } |
13539 } | 13527 } |
13540 | 13528 |
13541 | 13529 |
13542 } } // namespace v8::internal | 13530 } } // namespace v8::internal |
OLD | NEW |