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

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

Issue 2135273002: [interpreter] Reduce dependencies in bytecodes.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix static const Register definitions for bot in roll for Windows. Created 4 years, 5 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
« no previous file with comments | « test/unittests/interpreter/bytecode-decoder-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bytecode-register.h"
9 #include "src/interpreter/bytecodes.h" 10 #include "src/interpreter/bytecodes.h"
10 #include "test/unittests/interpreter/bytecode-utils.h"
11 #include "test/unittests/test-utils.h" 11 #include "test/unittests/test-utils.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 namespace interpreter { 15 namespace interpreter {
16 16
17 TEST(OperandConversion, Registers) { 17 TEST(OperandConversion, Registers) {
18 int register_count = 128; 18 int register_count = 128;
19 int step = register_count / 7; 19 int step = register_count / 7;
20 for (int i = 0; i < register_count; i += step) { 20 for (int i = 0; i < register_count; i += step) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \ 139 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name) && \
140 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \ 140 !Bytecodes::IsPrefixScalingBytecode(Bytecode::k##Name)) { \
141 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \ 141 Bytecode debug_bytecode = Bytecodes::GetDebugBreak(Bytecode::k##Name); \
142 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \ 142 CHECK_EQ(Bytecodes::Size(Bytecode::k##Name, kOperandScale), \
143 Bytecodes::Size(debug_bytecode, kOperandScale)); \ 143 Bytecodes::Size(debug_bytecode, kOperandScale)); \
144 } 144 }
145 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE) 145 BYTECODE_LIST(CHECK_DEBUG_BREAK_SIZE)
146 #undef CHECK_DEBUG_BREAK_SIZE 146 #undef CHECK_DEBUG_BREAK_SIZE
147 } 147 }
148 148
149 TEST(Bytecodes, DecodeBytecodeAndOperands) {
150 struct BytecodesAndResult {
151 const uint8_t bytecode[32];
152 const size_t length;
153 int parameter_count;
154 const char* output;
155 };
156
157 const BytecodesAndResult cases[] = {
158 {{B(LdaSmi), U8(1)}, 2, 0, " LdaSmi [1]"},
159 {{B(Wide), B(LdaSmi), U16(1000)}, 4, 0, " LdaSmi.Wide [1000]"},
160 {{B(ExtraWide), B(LdaSmi), U32(100000)},
161 6,
162 0,
163 "LdaSmi.ExtraWide [100000]"},
164 {{B(LdaSmi), U8(-1)}, 2, 0, " LdaSmi [-1]"},
165 {{B(Wide), B(LdaSmi), U16(-1000)}, 4, 0, " LdaSmi.Wide [-1000]"},
166 {{B(ExtraWide), B(LdaSmi), U32(-100000)},
167 6,
168 0,
169 "LdaSmi.ExtraWide [-100000]"},
170 {{B(Star), R8(5)}, 2, 0, " Star r5"},
171 {{B(Wide), B(Star), R16(136)}, 4, 0, " Star.Wide r136"},
172 {{B(Wide), B(Call), R16(134), R16(135), U16(2), U16(177)},
173 10,
174 0,
175 "Call.Wide r134, r135, #2, [177]"},
176 {{B(Ldar),
177 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())},
178 2,
179 3,
180 " Ldar a1"},
181 {{B(Wide), B(CreateObjectLiteral), U16(513), U16(1027), U8(165)},
182 7,
183 0,
184 "CreateObjectLiteral.Wide [513], [1027], #165"},
185 {{B(ExtraWide), B(JumpIfNull), U32(123456789)},
186 6,
187 0,
188 "JumpIfNull.ExtraWide [123456789]"},
189 };
190
191 for (size_t i = 0; i < arraysize(cases); ++i) {
192 // Generate reference string by prepending formatted bytes.
193 std::stringstream expected_ss;
194 std::ios default_format(nullptr);
195 default_format.copyfmt(expected_ss);
196 // Match format of Bytecodes::Decode() for byte representations.
197 expected_ss.fill('0');
198 expected_ss.flags(std::ios::right | std::ios::hex);
199 for (size_t b = 0; b < cases[i].length; b++) {
200 expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b])
201 << ' ';
202 }
203 expected_ss.copyfmt(default_format);
204 expected_ss << cases[i].output;
205
206 // Generate decoded byte output.
207 std::stringstream actual_ss;
208 Bytecodes::Decode(actual_ss, cases[i].bytecode, cases[i].parameter_count);
209
210 // Compare.
211 CHECK_EQ(actual_ss.str(), expected_ss.str());
212 }
213 }
214
215 TEST(Bytecodes, DebugBreakForPrefixBytecodes) { 149 TEST(Bytecodes, DebugBreakForPrefixBytecodes) {
216 CHECK_EQ(Bytecode::kDebugBreakWide, 150 CHECK_EQ(Bytecode::kDebugBreakWide,
217 Bytecodes::GetDebugBreak(Bytecode::kWide)); 151 Bytecodes::GetDebugBreak(Bytecode::kWide));
218 CHECK_EQ(Bytecode::kDebugBreakExtraWide, 152 CHECK_EQ(Bytecode::kDebugBreakExtraWide,
219 Bytecodes::GetDebugBreak(Bytecode::kExtraWide)); 153 Bytecodes::GetDebugBreak(Bytecode::kExtraWide));
220 } 154 }
221 155
222 TEST(Bytecodes, PrefixMappings) { 156 TEST(Bytecodes, PrefixMappings) {
223 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide}; 157 Bytecode prefixes[] = {Bytecode::kWide, Bytecode::kExtraWide};
224 TRACED_FOREACH(Bytecode, prefix, prefixes) { 158 TRACED_FOREACH(Bytecode, prefix, prefixes) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 std::set<std::string> names; 240 std::set<std::string> names;
307 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); 241 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone));
308 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); 242 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead));
309 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); 243 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite));
310 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); 244 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite));
311 CHECK_EQ(names.size(), 4); 245 CHECK_EQ(names.size(), 4);
312 } 246 }
313 } // namespace interpreter 247 } // namespace interpreter
314 } // namespace internal 248 } // namespace internal
315 } // namespace v8 249 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/interpreter/bytecode-decoder-unittest.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698