Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: test/unittests/interpreter/bytecodes-unittest.cc

Issue 1783483002: [interpreter] Add support for scalable operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix tests. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/interpreter/bytecodes.h" 9 #include "src/interpreter/bytecodes.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 for (int i = 0; i < parameter_count; i += 1) { 77 for (int i = 0; i < parameter_count; i += 1) {
78 Register r = Register::FromParameterIndex(i, parameter_count); 78 Register r = Register::FromParameterIndex(i, parameter_count);
79 uint32_t operand = r.ToWideOperand(); 79 uint32_t operand = r.ToWideOperand();
80 CHECK_LT(operand, operand_count.size()); 80 CHECK_LT(operand, operand_count.size());
81 operand_count[operand] += 1; 81 operand_count[operand] += 1;
82 CHECK_EQ(operand_count[operand], 1); 82 CHECK_EQ(operand_count[operand], 1);
83 } 83 }
84 } 84 }
85 85
86 TEST(OperandScaling, ScalableAndNonScalable) {
87 for (int scale = 1; scale < 8; scale *= 2) {
88 CHECK_EQ(Bytecodes::Size(Bytecode::kCallRuntime, scale), 1 + 2 + 2 * scale);
89 CHECK_EQ(Bytecodes::Size(Bytecode::kCreateObjectLiteral, scale),
90 1 + 2 * scale + 1);
91 CHECK_EQ(Bytecodes::Size(Bytecode::kTestIn, scale), 1 + scale);
92 }
93 }
94
86 TEST(Bytecodes, HasAnyRegisterOperands) { 95 TEST(Bytecodes, HasAnyRegisterOperands) {
87 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kAdd), 1); 96 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kAdd), 1);
88 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCall), 2); 97 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCall), 2);
89 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntime), 1); 98 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntime), 1);
90 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeWide), 1);
91 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPair), 99 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPair),
92 2); 100 2);
93 CHECK_EQ(
94 Bytecodes::NumberOfRegisterOperands(Bytecode::kCallRuntimeForPairWide),
95 2);
96 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kDeletePropertyStrict), 101 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kDeletePropertyStrict),
97 1); 102 1);
98 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepare), 1); 103 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepare), 1);
99 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kForInPrepareWide), 1);
100 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kInc), 0); 104 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kInc), 0);
101 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kJumpIfTrue), 0); 105 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kJumpIfTrue), 0);
102 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kNew), 2); 106 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kNew), 2);
103 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kToName), 0); 107 CHECK_EQ(Bytecodes::NumberOfRegisterOperands(Bytecode::kToName), 0);
104 } 108 }
105 109
106 TEST(Bytecodes, RegisterOperandBitmaps) { 110 TEST(Bytecodes, RegisterOperandBitmaps) {
107 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kAdd), 1); 111 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kAdd), 1);
108 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kCallRuntimeForPair), 112 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kCallRuntimeForPair),
109 10); 113 10);
110 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kStar), 1); 114 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kStar), 1);
111 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kMov), 3); 115 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kMov), 3);
112 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kTestIn), 1); 116 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kTestIn), 1);
113 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInPrepare), 1); 117 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInPrepare), 1);
114 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInDone), 3); 118 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInDone), 3);
115 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInNext), 7); 119 CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInNext), 7);
116 } 120 }
117 121
118 TEST(Bytecodes, RegisterOperands) { 122 TEST(Bytecodes, RegisterOperands) {
119 CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg8)); 123 CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg));
120 CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg8)); 124 CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg));
121 CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg8)); 125 CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg));
122 CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut8)); 126 CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut));
123 CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut8)); 127 CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut));
124 128
125 #define IS_REGISTER_OPERAND_TYPE(Name, _) \ 129 #define IS_REGISTER_OPERAND_TYPE(Name, _, __) \
126 CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name)); 130 CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name));
127 REGISTER_OPERAND_TYPE_LIST(IS_REGISTER_OPERAND_TYPE) 131 REGISTER_OPERAND_TYPE_LIST(IS_REGISTER_OPERAND_TYPE)
128 #undef IS_REGISTER_OPERAND_TYPE 132 #undef IS_REGISTER_OPERAND_TYPE
129 133
130 #define IS_NOT_REGISTER_OPERAND_TYPE(Name, _) \ 134 #define IS_NOT_REGISTER_OPERAND_TYPE(Name, _, __) \
131 CHECK(!Bytecodes::IsRegisterOperandType(OperandType::k##Name)); 135 CHECK(!Bytecodes::IsRegisterOperandType(OperandType::k##Name));
132 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OPERAND_TYPE) 136 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OPERAND_TYPE)
133 #undef IS_NOT_REGISTER_OPERAND_TYPE 137 #undef IS_NOT_REGISTER_OPERAND_TYPE
134 138
135 #define IS_REGISTER_INPUT_OPERAND_TYPE(Name, _) \ 139 #define IS_REGISTER_INPUT_OPERAND_TYPE(Name, _, __) \
136 CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::k##Name)); 140 CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
137 REGISTER_INPUT_OPERAND_TYPE_LIST(IS_REGISTER_INPUT_OPERAND_TYPE) 141 REGISTER_INPUT_OPERAND_TYPE_LIST(IS_REGISTER_INPUT_OPERAND_TYPE)
138 #undef IS_REGISTER_INPUT_OPERAND_TYPE 142 #undef IS_REGISTER_INPUT_OPERAND_TYPE
139 143
140 #define IS_NOT_REGISTER_INPUT_OPERAND_TYPE(Name, _) \ 144 #define IS_NOT_REGISTER_INPUT_OPERAND_TYPE(Name, _, __) \
141 CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::k##Name)); 145 CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
142 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE); 146 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE);
143 REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE) 147 REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE)
144 #undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE 148 #undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
145 149
146 #define IS_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \ 150 #define IS_REGISTER_OUTPUT_OPERAND_TYPE(Name, _, __) \
147 CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name)); 151 CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
148 REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_REGISTER_OUTPUT_OPERAND_TYPE) 152 REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_REGISTER_OUTPUT_OPERAND_TYPE)
149 #undef IS_REGISTER_OUTPUT_OPERAND_TYPE 153 #undef IS_REGISTER_OUTPUT_OPERAND_TYPE
150 154
151 #define IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \ 155 #define IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE(Name, _, __) \
152 CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name)); 156 CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
153 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE) 157 NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
154 REGISTER_INPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE) 158 REGISTER_INPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
155 #undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE 159 #undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
156 } 160 }
157 161
158 TEST(Bytecodes, DebugBreak) { 162 TEST(Bytecodes, DebugBreakExistForEachBytecode) {
159 for (uint32_t i = 0; i < Bytecodes::ToByte(Bytecode::kLast); i++) { 163 for (int operand_scale = 1; operand_scale < 8; operand_scale *= 2) {
160 Bytecode bytecode = Bytecodes::FromByte(i); 164 #define CHECK_DEBUG_BREAK_SIZE(Name, ...) \
161 Bytecode debugbreak = Bytecodes::GetDebugBreak(bytecode); 165 { \
162 if (!Bytecodes::IsDebugBreak(debugbreak)) { 166 Bytecode debug_bytecode = \
163 PrintF("Bytecode %s has no matching debug break with length %d\n", 167 Bytecodes::GetDebugBreak(Bytecode::k##Name, operand_scale); \
164 Bytecodes::ToString(bytecode), Bytecodes::Size(bytecode)); 168 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, operand_scale), \
165 CHECK(false); 169 Bytecodes::Size(debug_bytecode, operand_scale)); \
166 } 170 }
171 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE)
172 #undef CHECK_DEBUG_BREAK_SIZE
167 } 173 }
168 } 174 }
169 175
170 } // namespace interpreter 176 } // namespace interpreter
171 } // namespace internal 177 } // namespace internal
172 } // namespace v8 178 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698