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

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

Issue 1906963002: Fix interpreter unittest for embedded constant pools. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | 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/bytecodes.h" 9 #include "src/interpreter/bytecodes.h"
10 #include "test/unittests/test-utils.h" 10 #include "test/unittests/test-utils.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 TEST(Bytecodes, DecodeBytecodeAndOperands) { 171 TEST(Bytecodes, DecodeBytecodeAndOperands) {
172 struct BytecodesAndResult { 172 struct BytecodesAndResult {
173 const uint8_t bytecode[32]; 173 const uint8_t bytecode[32];
174 const size_t length; 174 const size_t length;
175 int parameter_count; 175 int parameter_count;
176 const char* output; 176 const char* output;
177 }; 177 };
178 178
179 #define B(Name) static_cast<uint8_t>(Bytecode::k##Name) 179 #define B(Name) static_cast<uint8_t>(Bytecode::k##Name)
180 #define REG_OFFSET \
181 (InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize)
182 #define REG(i) static_cast<uint8_t>(REG_OFFSET - (i))
183 #define REG_HI(i) static_cast<uint8_t>((REG_OFFSET - (i)) >> 8)
oth 2016/04/22 09:35:30 An alternative would be to have two macros here:
180 const BytecodesAndResult cases[] = { 184 const BytecodesAndResult cases[] = {
181 #if V8_TARGET_LITTLE_ENDIAN 185 #if V8_TARGET_LITTLE_ENDIAN
182 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, 186 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"},
183 {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"}, 187 {{B(Wide), B(LdaSmi), 0xe8, 0x03}, 4, 0, " LdaSmi.Wide [1000]"},
184 {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00}, 188 {{B(ExtraWide), B(LdaSmi), 0xa0, 0x86, 0x01, 0x00},
185 6, 189 6,
186 0, 190 0,
187 "LdaSmi.ExtraWide [100000]"}, 191 "LdaSmi.ExtraWide [100000]"},
188 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, 192 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"},
189 {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"}, 193 {{B(Wide), B(LdaSmi), 0x18, 0xfc}, 4, 0, " LdaSmi.Wide [-1000]"},
190 {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff}, 194 {{B(ExtraWide), B(LdaSmi), 0x60, 0x79, 0xfe, 0xff},
191 6, 195 6,
192 0, 196 0,
193 "LdaSmi.ExtraWide [-100000]"}, 197 "LdaSmi.ExtraWide [-100000]"},
194 {{B(Star), 0xf5}, 2, 0, " Star r5"}, 198 {{B(Star), REG(5)}, 2, 0, " Star r5"},
195 {{B(Wide), B(Star), 0x72, 0xff}, 4, 0, " Star.Wide r136"}, 199 {{B(Wide), B(Star), REG(136), REG_HI(136)}, 4, 0, " Star.Wide r136"},
196 {{B(Wide), B(Call), 0x74, 0xff, 0x73, 0xff, 0x02, 0x00, 0xb1, 0x00}, 200 {{B(Wide), B(Call), REG(134), REG_HI(134), REG(135), REG_HI(135), 0x02,
201 0x00, 0xb1, 0x00},
197 10, 202 10,
198 0, 203 0,
199 "Call.Wide r134, r135, #2, [177]"}, 204 "Call.Wide r134, r135, #2, [177]"},
200 {{B(Ldar), 205 {{B(Ldar),
201 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, 206 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())},
202 2, 207 2,
203 3, 208 3,
204 " Ldar a1"}, 209 " Ldar a1"},
205 {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5}, 210 {{B(Wide), B(CreateObjectLiteral), 0x01, 0x02, 0x03, 0x04, 0xa5},
206 7, 211 7,
207 0, 212 0,
208 "CreateObjectLiteral.Wide [513], [1027], #165"}, 213 "CreateObjectLiteral.Wide [513], [1027], #165"},
209 {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07}, 214 {{B(ExtraWide), B(JumpIfNull), 0x15, 0xcd, 0x5b, 0x07},
210 6, 215 6,
211 0, 216 0,
212 "JumpIfNull.ExtraWide [123456789]"}, 217 "JumpIfNull.ExtraWide [123456789]"},
213 #elif V8_TARGET_BIG_ENDIAN 218 #elif V8_TARGET_BIG_ENDIAN
214 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"}, 219 {{B(LdaSmi), 0x01}, 2, 0, " LdaSmi [1]"},
215 {{B(Wide), B(LdaSmi), 0x03, 0xe8}, 4, 0, " LdaSmi.Wide [1000]"}, 220 {{B(Wide), B(LdaSmi), 0x03, 0xe8}, 4, 0, " LdaSmi.Wide [1000]"},
216 {{B(ExtraWide), B(LdaSmi), 0x00, 0x01, 0x86, 0xa0}, 221 {{B(ExtraWide), B(LdaSmi), 0x00, 0x01, 0x86, 0xa0},
217 6, 222 6,
218 0, 223 0,
219 "LdaSmi.ExtraWide [100000]"}, 224 "LdaSmi.ExtraWide [100000]"},
220 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"}, 225 {{B(LdaSmi), 0xff}, 2, 0, " LdaSmi [-1]"},
221 {{B(Wide), B(LdaSmi), 0xfc, 0x18}, 4, 0, " LdaSmi.Wide [-1000]"}, 226 {{B(Wide), B(LdaSmi), 0xfc, 0x18}, 4, 0, " LdaSmi.Wide [-1000]"},
222 {{B(ExtraWide), B(LdaSmi), 0xff, 0xfe, 0x79, 0x60}, 227 {{B(ExtraWide), B(LdaSmi), 0xff, 0xfe, 0x79, 0x60},
223 6, 228 6,
224 0, 229 0,
225 "LdaSmi.ExtraWide [-100000]"}, 230 "LdaSmi.ExtraWide [-100000]"},
226 {{B(Star), 0xf5}, 2, 0, " Star r5"}, 231 {{B(Star), REG(5)}, 2, 0, " Star r5"},
227 {{B(Wide), B(Star), 0xff, 0x72}, 4, 0, " Star.Wide r136"}, 232 {{B(Wide), B(Star), REG_HI(136), REG(136)}, 4, 0, " Star.Wide r136"},
228 {{B(Wide), B(Call), 0xff, 0x74, 0xff, 0x73, 0x00, 0x02, 0x00, 0xb1}, 233 {{B(Wide), B(Call), REG_HI(134), REG(134), REG_HI(135), REG(135), 0x00,
234 0x02, 0x00, 0xb1},
229 10, 235 10,
230 0, 236 0,
231 "Call.Wide r134, r135, #2, [177]"}, 237 "Call.Wide r134, r135, #2, [177]"},
232 {{B(Ldar), 238 {{B(Ldar),
233 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())}, 239 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())},
234 2, 240 2,
235 3, 241 3,
236 " Ldar a1"}, 242 " Ldar a1"},
237 {{B(Wide), B(CreateObjectLiteral), 0x02, 0x01, 0x04, 0x03, 0xa5}, 243 {{B(Wide), B(CreateObjectLiteral), 0x02, 0x01, 0x04, 0x03, 0xa5},
238 7, 244 7,
239 0, 245 0,
240 "CreateObjectLiteral.Wide [513], [1027], #165"}, 246 "CreateObjectLiteral.Wide [513], [1027], #165"},
241 {{B(ExtraWide), B(JumpIfNull), 0x07, 0x5b, 0xcd, 0x15}, 247 {{B(ExtraWide), B(JumpIfNull), 0x07, 0x5b, 0xcd, 0x15},
242 6, 248 6,
243 0, 249 0,
244 "JumpIfNull.ExtraWide [123456789]"}, 250 "JumpIfNull.ExtraWide [123456789]"},
245 #else 251 #else
246 #error "Unknown Architecture" 252 #error "Unknown Architecture"
247 #endif 253 #endif
248 }; 254 };
249 #undef B 255 #undef B
256 #undef REG_OFFSET
257 #undef REG
258 #undef REG_HI
250 259
251 for (size_t i = 0; i < arraysize(cases); ++i) { 260 for (size_t i = 0; i < arraysize(cases); ++i) {
252 // Generate reference string by prepending formatted bytes. 261 // Generate reference string by prepending formatted bytes.
253 std::stringstream expected_ss; 262 std::stringstream expected_ss;
254 std::ios default_format(nullptr); 263 std::ios default_format(nullptr);
255 default_format.copyfmt(expected_ss); 264 default_format.copyfmt(expected_ss);
256 // Match format of Bytecodes::Decode() for byte representations. 265 // Match format of Bytecodes::Decode() for byte representations.
257 expected_ss.fill('0'); 266 expected_ss.fill('0');
258 expected_ss.flags(std::ios::right | std::ios::hex); 267 expected_ss.flags(std::ios::right | std::ios::hex);
259 for (size_t b = 0; b < cases[i].length; b++) { 268 for (size_t b = 0; b < cases[i].length; b++) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone)); 347 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kNone));
339 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead)); 348 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kRead));
340 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite)); 349 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kWrite));
341 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite)); 350 names.insert(Bytecodes::AccumulatorUseToString(AccumulatorUse::kReadWrite));
342 CHECK_EQ(names.size(), 4); 351 CHECK_EQ(names.size(), 4);
343 } 352 }
344 353
345 } // namespace interpreter 354 } // namespace interpreter
346 } // namespace internal 355 } // namespace internal
347 } // namespace v8 356 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698