OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/interpreter-intrinsics.h" | 5 #include "src/interpreter/interpreter-intrinsics.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
11 using compiler::Node; | 11 using compiler::Node; |
12 | 12 |
13 #define __ assembler_-> | 13 #define __ assembler_-> |
14 | 14 |
15 IntrinsicsHelper::IntrinsicsHelper(InterpreterAssembler* assembler) | 15 IntrinsicsHelper::IntrinsicsHelper(InterpreterAssembler* assembler) |
16 : assembler_(assembler) {} | 16 : assembler_(assembler) {} |
17 | 17 |
18 // static | |
19 bool IntrinsicsHelper::IsSupported(Runtime::FunctionId function_id) { | 18 bool IntrinsicsHelper::IsSupported(Runtime::FunctionId function_id) { |
20 switch (function_id) { | 19 switch (function_id) { |
21 #define SUPPORTED(name, lower_case, count) case Runtime::kInline##name: | 20 #define SUPPORTED(name, lower_case, count) case Runtime::kInline##name: |
22 INTRINSICS_LIST(SUPPORTED) | 21 INTRINSICS_LIST(SUPPORTED) |
23 return true; | 22 return true; |
24 #undef SUPPORTED | 23 #undef SUPPORTED |
25 default: | 24 default: |
26 return false; | 25 return false; |
27 } | 26 } |
28 } | 27 } |
29 | 28 |
30 // static | |
31 IntrinsicsHelper::IntrinsicId IntrinsicsHelper::FromRuntimeId( | |
32 Runtime::FunctionId function_id) { | |
33 switch (function_id) { | |
34 #define TO_RUNTIME_ID(name, lower_case, count) \ | |
35 case Runtime::kInline##name: \ | |
36 return IntrinsicId::k##name; | |
37 INTRINSICS_LIST(TO_RUNTIME_ID) | |
38 #undef TO_RUNTIME_ID | |
39 default: | |
40 UNREACHABLE(); | |
41 return static_cast<IntrinsicsHelper::IntrinsicId>(-1); | |
42 } | |
43 } | |
44 | |
45 // static | |
46 Runtime::FunctionId IntrinsicsHelper::ToRuntimeId( | |
47 IntrinsicsHelper::IntrinsicId intrinsic_id) { | |
48 switch (intrinsic_id) { | |
49 #define TO_INTRINSIC_ID(name, lower_case, count) \ | |
50 case IntrinsicId::k##name: \ | |
51 return Runtime::kInline##name; | |
52 INTRINSICS_LIST(TO_INTRINSIC_ID) | |
53 #undef TO_INTRINSIC_ID | |
54 default: | |
55 UNREACHABLE(); | |
56 return static_cast<Runtime::FunctionId>(-1); | |
57 } | |
58 } | |
59 | |
60 Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context, | 29 Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context, |
61 Node* first_arg_reg, Node* arg_count) { | 30 Node* first_arg_reg, Node* arg_count) { |
62 InterpreterAssembler::Label abort(assembler_), end(assembler_); | 31 InterpreterAssembler::Label abort(assembler_), end(assembler_); |
63 InterpreterAssembler::Variable result(assembler_, | 32 InterpreterAssembler::Variable result(assembler_, |
64 MachineRepresentation::kTagged); | 33 MachineRepresentation::kTagged); |
65 | 34 |
66 #define MAKE_LABEL(name, lower_case, count) \ | 35 #define MAKE_LABEL(name, lower_case, count) \ |
67 InterpreterAssembler::Label lower_case(assembler_); | 36 InterpreterAssembler::Label lower_case(assembler_); |
68 INTRINSICS_LIST(MAKE_LABEL) | 37 INTRINSICS_LIST(MAKE_LABEL) |
69 #undef MAKE_LABEL | 38 #undef MAKE_LABEL |
70 | 39 |
71 #define LABEL_POINTER(name, lower_case, count) &lower_case, | 40 #define LABEL_POINTER(name, lower_case, count) &lower_case, |
72 InterpreterAssembler::Label* labels[] = {INTRINSICS_LIST(LABEL_POINTER)}; | 41 InterpreterAssembler::Label* labels[] = {INTRINSICS_LIST(LABEL_POINTER)}; |
73 #undef LABEL_POINTER | 42 #undef LABEL_POINTER |
74 | 43 |
75 #define CASE(name, lower_case, count) \ | 44 #define CASE(name, lower_case, count) \ |
76 static_cast<int32_t>(IntrinsicId::k##name), | 45 static_cast<int32_t>(Runtime::kInline##name), |
77 int32_t cases[] = {INTRINSICS_LIST(CASE)}; | 46 int32_t cases[] = {INTRINSICS_LIST(CASE)}; |
78 #undef CASE | 47 #undef CASE |
79 | 48 |
80 __ Switch(function_id, &abort, cases, labels, arraysize(cases)); | 49 __ Switch(function_id, &abort, cases, labels, arraysize(cases)); |
81 #define HANDLE_CASE(name, lower_case, expected_arg_count) \ | 50 #define HANDLE_CASE(name, lower_case, expected_arg_count) \ |
82 __ Bind(&lower_case); \ | 51 __ Bind(&lower_case); \ |
83 if (FLAG_debug_code && expected_arg_count >= 0) { \ | 52 if (FLAG_debug_code && expected_arg_count >= 0) { \ |
84 AbortIfArgCountMismatch(expected_arg_count, arg_count); \ | 53 AbortIfArgCountMismatch(expected_arg_count, arg_count); \ |
85 } \ | 54 } \ |
86 result.Bind(name(first_arg_reg, arg_count, context)); \ | 55 result.Bind(name(first_arg_reg, arg_count, context)); \ |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 Node* comparison = __ Word32Equal(actual, __ Int32Constant(expected)); | 227 Node* comparison = __ Word32Equal(actual, __ Int32Constant(expected)); |
259 __ GotoIf(comparison, &match); | 228 __ GotoIf(comparison, &match); |
260 __ Abort(kWrongArgumentCountForInvokeIntrinsic); | 229 __ Abort(kWrongArgumentCountForInvokeIntrinsic); |
261 __ Goto(&match); | 230 __ Goto(&match); |
262 __ Bind(&match); | 231 __ Bind(&match); |
263 } | 232 } |
264 | 233 |
265 } // namespace interpreter | 234 } // namespace interpreter |
266 } // namespace internal | 235 } // namespace internal |
267 } // namespace v8 | 236 } // namespace v8 |
OLD | NEW |