Index: src/interpreter/interpreter-intrinsics.cc |
diff --git a/src/interpreter/interpreter-intrinsics.cc b/src/interpreter/interpreter-intrinsics.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4454188a0031774fdd1c3082f1bb10078c5f4477 |
--- /dev/null |
+++ b/src/interpreter/interpreter-intrinsics.cc |
@@ -0,0 +1,153 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/interpreter/interpreter-intrinsics.h" |
+ |
+namespace v8 { |
+namespace internal { |
+namespace interpreter { |
+ |
+using compiler::Node; |
+ |
+#define __ assembler_-> |
+ |
+IntrinsicsHelper::IntrinsicsHelper(InterpreterAssembler* assembler) |
+ : assembler_(assembler) {} |
+ |
+bool IntrinsicsHelper::IsSupported(Runtime::FunctionId function_id) { |
+ switch (function_id) { |
+#define SUPPORTED(name, lower_case, count) case Runtime::kInline##name: |
+ INTRINSICS_LIST(SUPPORTED) |
+ return true; |
rmcilroy
2016/03/08 11:19:30
nit - indent
epertoso
2016/03/08 14:11:09
That's what clang-format does. I can change it man
rmcilroy
2016/03/08 16:09:43
Ok.
|
+#undef SUPPORTED |
+ default: |
+ return false; |
+ } |
+} |
+ |
+Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context, |
+ Node* first_arg_reg, Node* arg_count) { |
+ InterpreterAssembler::Label abort(assembler_), end(assembler_); |
+ InterpreterAssembler::Variable result(assembler_, |
+ MachineRepresentation::kTagged); |
+ |
+#define MAKE_LABEL(name, lower_case, count) \ |
+ InterpreterAssembler::Label lower_case(assembler_); |
+ INTRINSICS_LIST(MAKE_LABEL) |
+#undef MAKE_LABEL |
+ |
+#define LABEL_POINTER(name, lower_case, count) &lower_case, |
+ InterpreterAssembler::Label* labels[] = {INTRINSICS_LIST(LABEL_POINTER)}; |
+#undef LABEL_POINTER |
+ |
+#define CASE(name, lower_case, count) \ |
+ static_cast<int32_t>(Runtime::kInline##name), |
+ int32_t cases[] = {INTRINSICS_LIST(CASE)}; |
+#undef CASE |
+ |
+ __ Switch(function_id, &abort, cases, labels, arraysize(cases)); |
+#define HANDLE_CASE(name, lower_case, expected_arg_count) \ |
+ __ Bind(&lower_case); \ |
+ if (FLAG_debug_code) { \ |
+ InterpreterAssembler::Label match(assembler_), mismatch(assembler_); \ |
rmcilroy
2016/03/08 11:19:30
nit - could you pull this out into a seperate func
epertoso
2016/03/08 14:11:09
Sure.
|
+ Node* argument_count_check = \ |
+ __ Word32Equal(arg_count, __ Int32Constant(expected_arg_count)); \ |
+ __ Branch(argument_count_check, &match, &mismatch); \ |
+ __ Bind(&mismatch); \ |
+ __ Abort(kWrongArgumentCountForInvokeIntrinsic); \ |
+ __ Bind(&match); \ |
+ } \ |
+ result.Bind(name(first_arg_reg)); \ |
+ __ Goto(&end); |
+ INTRINSICS_LIST(HANDLE_CASE) |
+#undef HANDLE_CASE |
+ |
+ __ Bind(&abort); |
+ __ Abort(BailoutReason::kUnexpectedFunctionIDForInvokeIntrinsic); |
+ |
+ __ Bind(&end); |
+ return result.value(); |
+} |
+ |
+Node* IntrinsicsHelper::CompareInstanceType(Node* map, int type, |
+ InstanceTypeCompareMode mode) { |
+ InterpreterAssembler::Variable return_value(assembler_, |
+ MachineRepresentation::kTagged); |
+ Node* instance_type = |
+ __ Load(MachineType::Uint8(), map, |
+ __ IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag)); |
+ |
+ InterpreterAssembler::Label if_true(assembler_), if_false(assembler_), |
+ end(assembler_); |
+ switch (mode) { |
+ case kInstanceTypeEqual: |
+ __ Branch(__ Word32Equal(instance_type, __ Int32Constant(type)), &if_true, |
rmcilroy
2016/03/08 11:19:30
just build the condition (i.e., Word32Equal or Int
epertoso
2016/03/08 14:11:09
Done.
|
+ &if_false); |
+ break; |
+ case kInstanceTypeGreaterThanOrEqual: |
+ __ Branch( |
+ __ Int32GreaterThanOrEqual(instance_type, __ Int32Constant(type)), |
+ &if_true, &if_false); |
+ break; |
+ } |
+ __ Bind(&if_true); |
+ return_value.Bind(__ BooleanConstant(true)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&if_false); |
+ return_value.Bind(__ BooleanConstant(false)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&end); |
+ return return_value.value(); |
+} |
+ |
+Node* IntrinsicsHelper::IsJSReceiver(Node* input) { |
rmcilroy
2016/03/08 11:19:30
These intrinsics are simple enough that it's proba
epertoso
2016/03/08 14:11:09
Actually, this is a good point. I'm not sure about
rmcilroy
2016/03/08 16:09:43
I'd create a separate file cctest/interpreter/inte
|
+ InterpreterAssembler::Variable return_value(assembler_, |
+ MachineRepresentation::kTagged); |
+ |
+ InterpreterAssembler::Label if_smi(assembler_), if_not_smi(assembler_), |
+ end(assembler_); |
+ Node* arg = __ LoadRegister(input); |
+ |
+ __ Branch(__ WordIsSmi(arg), &if_smi, &if_not_smi); |
+ __ Bind(&if_smi); |
+ return_value.Bind(__ BooleanConstant(false)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&if_not_smi); |
+ STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
+ Node* map = __ LoadObjectField(arg, HeapObject::kMapOffset); |
+ return_value.Bind(CompareInstanceType(map, FIRST_JS_RECEIVER_TYPE, |
+ kInstanceTypeGreaterThanOrEqual)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&end); |
+ return return_value.value(); |
+} |
+ |
+Node* IntrinsicsHelper::IsArray(Node* input) { |
+ InterpreterAssembler::Label if_smi(assembler_), if_not_smi(assembler_), |
+ end(assembler_); |
+ Node* arg = __ LoadRegister(input); |
+ __ Branch(__ WordIsSmi(arg), &if_smi, &if_not_smi); |
+ InterpreterAssembler::Variable return_value(assembler_, |
+ MachineRepresentation::kTagged); |
+ __ Bind(&if_smi); |
+ return_value.Bind(__ BooleanConstant(false)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&if_not_smi); |
+ Node* map = __ LoadObjectField(arg, HeapObject::kMapOffset); |
+ return_value.Bind( |
+ CompareInstanceType(map, JS_ARRAY_TYPE, kInstanceTypeEqual)); |
+ __ Goto(&end); |
+ |
+ __ Bind(&end); |
+ return return_value.value(); |
+} |
+ |
+} // namespace interpreter |
+} // namespace internal |
+} // namespace v8 |