| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/base/utils/random-number-generator.h" | 9 #include "src/base/utils/random-number-generator.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| 11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
| 12 #include "src/third_party/fdlibm/fdlibm.h" | |
| 13 | 12 |
| 14 namespace v8 { | 13 namespace v8 { |
| 15 namespace internal { | 14 namespace internal { |
| 16 | 15 |
| 17 RUNTIME_FUNCTION(Runtime_DoubleHi) { | 16 RUNTIME_FUNCTION(Runtime_DoubleHi) { |
| 18 HandleScope scope(isolate); | 17 HandleScope scope(isolate); |
| 19 DCHECK(args.length() == 1); | 18 DCHECK(args.length() == 1); |
| 20 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 19 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 21 uint64_t unsigned64 = double_to_uint64(x); | 20 uint64_t unsigned64 = double_to_uint64(x); |
| 22 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64 >> 32); | 21 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64 >> 32); |
| 23 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); | 22 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); |
| 24 return *isolate->factory()->NewNumber(signed32); | 23 return *isolate->factory()->NewNumber(signed32); |
| 25 } | 24 } |
| 26 | 25 |
| 27 | 26 |
| 28 RUNTIME_FUNCTION(Runtime_DoubleLo) { | 27 RUNTIME_FUNCTION(Runtime_DoubleLo) { |
| 29 HandleScope scope(isolate); | 28 HandleScope scope(isolate); |
| 30 DCHECK(args.length() == 1); | 29 DCHECK(args.length() == 1); |
| 31 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 30 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 32 uint64_t unsigned64 = double_to_uint64(x); | 31 uint64_t unsigned64 = double_to_uint64(x); |
| 33 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64); | 32 uint32_t unsigned32 = static_cast<uint32_t>(unsigned64); |
| 34 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); | 33 int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32); |
| 35 return *isolate->factory()->NewNumber(signed32); | 34 return *isolate->factory()->NewNumber(signed32); |
| 36 } | 35 } |
| 37 | 36 |
| 38 | 37 |
| 39 RUNTIME_FUNCTION(Runtime_ConstructDouble) { | |
| 40 HandleScope scope(isolate); | |
| 41 DCHECK(args.length() == 2); | |
| 42 CONVERT_NUMBER_CHECKED(uint32_t, hi, Uint32, args[0]); | |
| 43 CONVERT_NUMBER_CHECKED(uint32_t, lo, Uint32, args[1]); | |
| 44 uint64_t result = (static_cast<uint64_t>(hi) << 32) | lo; | |
| 45 return *isolate->factory()->NewNumber(uint64_to_double(result)); | |
| 46 } | |
| 47 | |
| 48 | |
| 49 RUNTIME_FUNCTION(Runtime_RemPiO2) { | |
| 50 SealHandleScope shs(isolate); | |
| 51 DisallowHeapAllocation no_gc; | |
| 52 DCHECK(args.length() == 2); | |
| 53 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | |
| 54 CONVERT_ARG_CHECKED(JSTypedArray, result, 1); | |
| 55 CHECK(result->byte_length() == Smi::FromInt(2 * sizeof(double))); | |
| 56 FixedFloat64Array* array = FixedFloat64Array::cast(result->elements()); | |
| 57 double* y = static_cast<double*>(array->DataPtr()); | |
| 58 return Smi::FromInt(fdlibm::rempio2(x, y)); | |
| 59 } | |
| 60 | |
| 61 | |
| 62 // Slow version of Math.pow. We check for fast paths for special cases. | 38 // Slow version of Math.pow. We check for fast paths for special cases. |
| 63 // Used if VFP3 is not available. | 39 // Used if VFP3 is not available. |
| 64 RUNTIME_FUNCTION(Runtime_MathPow) { | 40 RUNTIME_FUNCTION(Runtime_MathPow) { |
| 65 HandleScope scope(isolate); | 41 HandleScope scope(isolate); |
| 66 DCHECK(args.length() == 2); | 42 DCHECK(args.length() == 2); |
| 67 isolate->counters()->math_pow_runtime()->Increment(); | 43 isolate->counters()->math_pow_runtime()->Increment(); |
| 68 | 44 |
| 69 CONVERT_DOUBLE_ARG_CHECKED(x, 0); | 45 CONVERT_DOUBLE_ARG_CHECKED(x, 0); |
| 70 | 46 |
| 71 // If the second argument is a smi, it is much faster to call the | 47 // If the second argument is a smi, it is much faster to call the |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 base::RandomNumberGenerator::XorShift128(&state0, &state1); | 127 base::RandomNumberGenerator::XorShift128(&state0, &state1); |
| 152 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); | 128 array[i] = base::RandomNumberGenerator::ToDouble(state0, state1); |
| 153 } | 129 } |
| 154 // Persist current state. | 130 // Persist current state. |
| 155 array[kState0Offset] = uint64_to_double(state0); | 131 array[kState0Offset] = uint64_to_double(state0); |
| 156 array[kState1Offset] = uint64_to_double(state1); | 132 array[kState1Offset] = uint64_to_double(state1); |
| 157 return *typed_array; | 133 return *typed_array; |
| 158 } | 134 } |
| 159 } // namespace internal | 135 } // namespace internal |
| 160 } // namespace v8 | 136 } // namespace v8 |
| OLD | NEW |