OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "src/v8.h" | |
6 | |
7 #include "src/interpreter/bytecode-array-builder.h" | |
8 #include "test/unittests/test-utils.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 namespace interpreter { | |
13 | |
14 TEST(OperandConversion, Registers) { | |
15 for (int i = 0; i < 128; i++) { | |
16 uint8_t operand_value = Bytecodes::RegisterIndexToOperand(i); | |
17 uint8_t index = Bytecodes::RegisterIndexFromOperand(operand_value); | |
18 CHECK_EQ(i, index); | |
19 } | |
20 } | |
21 | |
22 | |
23 TEST(OperandConversion, Parameters) { | |
24 int parameter_counts[] = {7, 13, 99}; | |
rmcilroy
2015/09/02 11:42:42
nit - could you just use a std::vector here instea
oth
2015/09/02 14:02:20
Done. With uniform initialization, this is a fine
| |
25 #define COUNT_OF(x) static_cast<int>(sizeof(x) / sizeof(x[0])) | |
26 for (int p = 0; p < COUNT_OF(parameter_counts); p++) { | |
27 int parameter_count = parameter_counts[p]; | |
28 for (int i = 0; i <= parameter_count; i++) { | |
29 uint8_t operand_value = | |
30 Bytecodes::ParameterIndexToOperand(i, parameter_count); | |
31 uint8_t index = | |
32 Bytecodes::ParameterIndexFromOperand(operand_value, parameter_count); | |
33 CHECK_EQ(i, index); | |
34 } | |
35 } | |
36 #undef COUNT_OF | |
37 } | |
38 | |
39 | |
40 TEST(OperandConversion, RegistersParametersNoOverlap) { | |
41 uint8_t operand_count[255] = {0}; | |
42 | |
43 for (int i = 0; i < 128; i++) { | |
rmcilroy
2015/09/02 11:42:42
nit - /s/128/kMaxRegisterIndex
oth
2015/09/02 14:02:20
Done.
| |
44 uint8_t register_operand = Bytecodes::RegisterIndexToOperand(i); | |
45 operand_count[register_operand] += 1; | |
46 CHECK_EQ(operand_count[register_operand], 1); | |
47 } | |
48 | |
49 int parameter_count = Bytecodes::MaximumNumberOfParameters(); | |
50 for (int i = 0; i <= parameter_count; i++) { | |
51 uint8_t parameter_operand = | |
52 Bytecodes::ParameterIndexToOperand(i, parameter_count); | |
53 operand_count[parameter_operand] += 1; | |
54 CHECK_EQ(operand_count[parameter_operand], 1); | |
55 } | |
56 } | |
57 | |
58 | |
59 } // namespace interpreter | |
60 } // namespace internal | |
61 } // namespace v8 | |
OLD | NEW |