Chromium Code Reviews| Index: test/unittests/interpreter/bytecodes-unittest.cc |
| diff --git a/test/unittests/interpreter/bytecodes-unittest.cc b/test/unittests/interpreter/bytecodes-unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b77db9dbf1a26a7ee301ce77994484491adab97 |
| --- /dev/null |
| +++ b/test/unittests/interpreter/bytecodes-unittest.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2014 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 <vector> |
| + |
| +#include "src/v8.h" |
| + |
| +#include "src/interpreter/bytecodes.h" |
| +#include "test/unittests/test-utils.h" |
| + |
| + |
| +namespace v8 { |
| +namespace internal { |
| +namespace interpreter { |
| + |
| +TEST(OperandConversion, Registers) { |
| + for (int i = 0; i < 128; i++) { |
| + uint8_t operand_value = Register(i).ToOperand(); |
| + Register r = Register::FromOperand(operand_value); |
| + CHECK_EQ(i, r.index()); |
| + } |
| +} |
| + |
| + |
| +TEST(OperandConversion, Parameters) { |
| + std::vector<int> parameter_counts{7, 13, 99}; |
|
rmcilroy
2015/09/02 15:22:29
Unfortunately I don't think this will work on Mac
oth
2015/09/02 16:28:06
Done, but with sizeof(parameter_counts[0]) to pres
|
| + |
| + for (size_t p = 0; p < parameter_counts.size(); p++) { |
| + int parameter_count = parameter_counts[p]; |
| + for (int i = 0; i <= parameter_count; i++) { |
| + Register r = Register::FromParameterIndex(i, parameter_count); |
| + uint8_t operand_value = r.ToOperand(); |
| + Register s = Register::FromOperand(operand_value); |
| + CHECK_EQ(i, s.ToParameterIndex(parameter_count)); |
| + } |
| + } |
| +} |
| + |
| + |
| +TEST(OperandConversion, RegistersParametersNoOverlap) { |
| + uint8_t operand_count[255] = {0}; |
| + |
| + for (int i = 0; i <= Register::kMaxRegisterIndex; i++) { |
| + Register r = Register(i); |
| + uint8_t operand = r.ToOperand(); |
| + operand_count[operand] += 1; |
| + CHECK_EQ(operand_count[operand], 1); |
| + } |
| + |
| + int parameter_count = Register::MaxParameterIndex(); |
| + for (int i = 0; i <= parameter_count; i++) { |
| + Register r = Register::FromParameterIndex(i, parameter_count); |
| + uint8_t operand = r.ToOperand(); |
| + operand_count[operand] += 1; |
| + CHECK_EQ(operand_count[operand], 1); |
| + } |
| +} |
| + |
| +} // namespace interpreter |
| +} // namespace internal |
| +} // namespace v8 |