OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 Handle<Object> x = args.at<Object>(1); | 2026 Handle<Object> x = args.at<Object>(1); |
2027 Handle<Object> y = args.at<Object>(2); | 2027 Handle<Object> y = args.at<Object>(2); |
2028 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); | 2028 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); |
2029 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y)); | 2029 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y)); |
2030 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y)); | 2030 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y)); |
2031 return *isolate->factory()->NewNumberFromInt(product); | 2031 return *isolate->factory()->NewNumberFromInt(product); |
2032 } | 2032 } |
2033 | 2033 |
2034 // ES6 section 20.2.2.32 Math.sqrt ( x ) | 2034 // ES6 section 20.2.2.32 Math.sqrt ( x ) |
2035 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) { | 2035 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) { |
2036 typedef compiler::CodeStubAssembler::Label Label; | 2036 using compiler::Node; |
2037 typedef compiler::Node Node; | |
2038 typedef compiler::CodeStubAssembler::Variable Variable; | |
2039 | 2037 |
| 2038 Node* x = assembler->Parameter(1); |
2040 Node* context = assembler->Parameter(4); | 2039 Node* context = assembler->Parameter(4); |
2041 | 2040 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); |
2042 // Shared entry for the floating point sqrt. | 2041 Node* value = assembler->Float64Sqrt(x_value); |
2043 Label do_fsqrt(assembler); | 2042 Node* result = assembler->AllocateHeapNumberWithValue(value); |
2044 Variable var_fsqrt_x(assembler, MachineRepresentation::kFloat64); | 2043 assembler->Return(result); |
2045 | |
2046 // We might need to loop once due to the ToNumber conversion. | |
2047 Variable var_x(assembler, MachineRepresentation::kTagged); | |
2048 Label loop(assembler, &var_x); | |
2049 var_x.Bind(assembler->Parameter(1)); | |
2050 assembler->Goto(&loop); | |
2051 assembler->Bind(&loop); | |
2052 { | |
2053 // Load the current {x} value. | |
2054 Node* x = var_x.value(); | |
2055 | |
2056 // Check if {x} is a Smi or a HeapObject. | |
2057 Label if_xissmi(assembler), if_xisnotsmi(assembler); | |
2058 assembler->Branch(assembler->WordIsSmi(x), &if_xissmi, &if_xisnotsmi); | |
2059 | |
2060 assembler->Bind(&if_xissmi); | |
2061 { | |
2062 // Perform the floating point sqrt. | |
2063 var_fsqrt_x.Bind(assembler->SmiToFloat64(x)); | |
2064 assembler->Goto(&do_fsqrt); | |
2065 } | |
2066 | |
2067 assembler->Bind(&if_xisnotsmi); | |
2068 { | |
2069 // Load the map of {x}. | |
2070 Node* x_map = assembler->LoadMap(x); | |
2071 | |
2072 // Check if {x} is a HeapNumber. | |
2073 Label if_xisnumber(assembler), | |
2074 if_xisnotnumber(assembler, Label::kDeferred); | |
2075 assembler->Branch( | |
2076 assembler->WordEqual(x_map, assembler->HeapNumberMapConstant()), | |
2077 &if_xisnumber, &if_xisnotnumber); | |
2078 | |
2079 assembler->Bind(&if_xisnumber); | |
2080 { | |
2081 // Perform the floating point sqrt. | |
2082 var_fsqrt_x.Bind(assembler->LoadHeapNumberValue(x)); | |
2083 assembler->Goto(&do_fsqrt); | |
2084 } | |
2085 | |
2086 assembler->Bind(&if_xisnotnumber); | |
2087 { | |
2088 // Convert {x} to a Number first. | |
2089 Callable callable = | |
2090 CodeFactory::NonNumberToNumber(assembler->isolate()); | |
2091 var_x.Bind(assembler->CallStub(callable, context, x)); | |
2092 assembler->Goto(&loop); | |
2093 } | |
2094 } | |
2095 } | |
2096 | |
2097 assembler->Bind(&do_fsqrt); | |
2098 { | |
2099 Node* x = var_fsqrt_x.value(); | |
2100 Node* value = assembler->Float64Sqrt(x); | |
2101 Node* result = assembler->AllocateHeapNumberWithValue(value); | |
2102 assembler->Return(result); | |
2103 } | |
2104 } | 2044 } |
2105 | 2045 |
2106 // ----------------------------------------------------------------------------- | 2046 // ----------------------------------------------------------------------------- |
2107 // ES6 section 26.1 The Reflect Object | 2047 // ES6 section 26.1 The Reflect Object |
2108 | 2048 |
2109 | 2049 |
2110 // ES6 section 26.1.3 Reflect.defineProperty | 2050 // ES6 section 26.1.3 Reflect.defineProperty |
2111 BUILTIN(ReflectDefineProperty) { | 2051 BUILTIN(ReflectDefineProperty) { |
2112 HandleScope scope(isolate); | 2052 HandleScope scope(isolate); |
2113 DCHECK_EQ(4, args.length()); | 2053 DCHECK_EQ(4, args.length()); |
(...skipping 2506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4620 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 4560 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
4621 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4561 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4622 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4562 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4623 #undef DEFINE_BUILTIN_ACCESSOR_C | 4563 #undef DEFINE_BUILTIN_ACCESSOR_C |
4624 #undef DEFINE_BUILTIN_ACCESSOR_A | 4564 #undef DEFINE_BUILTIN_ACCESSOR_A |
4625 #undef DEFINE_BUILTIN_ACCESSOR_T | 4565 #undef DEFINE_BUILTIN_ACCESSOR_T |
4626 #undef DEFINE_BUILTIN_ACCESSOR_H | 4566 #undef DEFINE_BUILTIN_ACCESSOR_H |
4627 | 4567 |
4628 } // namespace internal | 4568 } // namespace internal |
4629 } // namespace v8 | 4569 } // namespace v8 |
OLD | NEW |