Chromium Code Reviews| 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 <vector> | |
| 6 | |
| 7 #include "src/v8.h" | |
| 8 | |
| 9 #include "src/interpreter/bytecodes.h" | |
| 10 #include "test/unittests/test-utils.h" | |
| 11 | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 namespace interpreter { | |
| 16 | |
| 17 TEST(OperandConversion, Registers) { | |
| 18 for (int i = 0; i < 128; i++) { | |
| 19 uint8_t operand_value = Register(i).ToOperand(); | |
| 20 Register r = Register::FromOperand(operand_value); | |
| 21 CHECK_EQ(i, r.index()); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 | |
| 26 TEST(OperandConversion, Parameters) { | |
| 27 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
| |
| 28 | |
| 29 for (size_t p = 0; p < parameter_counts.size(); p++) { | |
| 30 int parameter_count = parameter_counts[p]; | |
| 31 for (int i = 0; i <= parameter_count; i++) { | |
| 32 Register r = Register::FromParameterIndex(i, parameter_count); | |
| 33 uint8_t operand_value = r.ToOperand(); | |
| 34 Register s = Register::FromOperand(operand_value); | |
| 35 CHECK_EQ(i, s.ToParameterIndex(parameter_count)); | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 | |
| 41 TEST(OperandConversion, RegistersParametersNoOverlap) { | |
| 42 uint8_t operand_count[255] = {0}; | |
| 43 | |
| 44 for (int i = 0; i <= Register::kMaxRegisterIndex; i++) { | |
| 45 Register r = Register(i); | |
| 46 uint8_t operand = r.ToOperand(); | |
| 47 operand_count[operand] += 1; | |
| 48 CHECK_EQ(operand_count[operand], 1); | |
| 49 } | |
| 50 | |
| 51 int parameter_count = Register::MaxParameterIndex(); | |
| 52 for (int i = 0; i <= parameter_count; i++) { | |
| 53 Register r = Register::FromParameterIndex(i, parameter_count); | |
| 54 uint8_t operand = r.ToOperand(); | |
| 55 operand_count[operand] += 1; | |
| 56 CHECK_EQ(operand_count[operand], 1); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 } // namespace interpreter | |
| 61 } // namespace internal | |
| 62 } // namespace v8 | |
| OLD | NEW |