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 7245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7256 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 7256 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
7257 | 7257 |
7258 // If the second argument is a smi, it is much faster to call the | 7258 // If the second argument is a smi, it is much faster to call the |
7259 // custom powi() function than the generic pow(). | 7259 // custom powi() function than the generic pow(). |
7260 if (args[1]->IsSmi()) { | 7260 if (args[1]->IsSmi()) { |
7261 int y = args.smi_at(1); | 7261 int y = args.smi_at(1); |
7262 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); | 7262 return isolate->heap()->NumberFromDouble(power_double_int(x, y)); |
7263 } | 7263 } |
7264 | 7264 |
7265 CONVERT_DOUBLE_ARG_CHECKED(y, 1); | 7265 CONVERT_DOUBLE_ARG_CHECKED(y, 1); |
7266 int y_int = static_cast<int>(y); | 7266 double result = power_helper(x, y); |
7267 double result; | |
7268 if (y == y_int) { | |
7269 result = power_double_int(x, y_int); // Returns 1 if exponent is 0. | |
7270 } else if (y == 0.5) { | |
7271 result = (isinf(x)) ? V8_INFINITY | |
7272 : fast_sqrt(x + 0.0); // Convert -0 to +0. | |
7273 } else if (y == -0.5) { | |
7274 result = (isinf(x)) ? 0 | |
7275 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. | |
7276 } else { | |
7277 result = power_double_double(x, y); | |
7278 } | |
7279 if (isnan(result)) return isolate->heap()->nan_value(); | 7267 if (isnan(result)) return isolate->heap()->nan_value(); |
7280 return isolate->heap()->AllocateHeapNumber(result); | 7268 return isolate->heap()->AllocateHeapNumber(result); |
7281 } | 7269 } |
7282 | 7270 |
7283 // Fast version of Math.pow if we know that y is not an integer and y is not | 7271 // Fast version of Math.pow if we know that y is not an integer and y is not |
7284 // -0.5 or 0.5. Used as slow case from full codegen. | 7272 // -0.5 or 0.5. Used as slow case from full codegen. |
7285 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { | 7273 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_pow_cfunction) { |
7286 NoHandleAllocation ha; | 7274 NoHandleAllocation ha; |
7287 ASSERT(args.length() == 2); | 7275 ASSERT(args.length() == 2); |
7288 isolate->counters()->math_pow()->Increment(); | 7276 isolate->counters()->math_pow()->Increment(); |
(...skipping 6220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13509 // Handle last resort GC and make sure to allow future allocations | 13497 // Handle last resort GC and make sure to allow future allocations |
13510 // to grow the heap without causing GCs (if possible). | 13498 // to grow the heap without causing GCs (if possible). |
13511 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13499 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13512 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13500 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13513 "Runtime::PerformGC"); | 13501 "Runtime::PerformGC"); |
13514 } | 13502 } |
13515 } | 13503 } |
13516 | 13504 |
13517 | 13505 |
13518 } } // namespace v8::internal | 13506 } } // namespace v8::internal |
OLD | NEW |