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

Unified Diff: test/unittests/interpreter/bytecodes-unittest.cc

Issue 1325983002: [Intepreter] Extend and move Register class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug in test. Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
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..355fce6bd7a62e68f8e668c6f07d2f4557b9b453
--- /dev/null
+++ b/test/unittests/interpreter/bytecodes-unittest.cc
@@ -0,0 +1,61 @@
+// 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 "src/v8.h"
+
+#include "src/interpreter/bytecode-array-builder.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 = Bytecodes::RegisterIndexToOperand(i);
+ uint8_t index = Bytecodes::RegisterIndexFromOperand(operand_value);
+ CHECK_EQ(i, index);
+ }
+}
+
+
+TEST(OperandConversion, Parameters) {
+ 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
+#define COUNT_OF(x) static_cast<int>(sizeof(x) / sizeof(x[0]))
+ for (int p = 0; p < COUNT_OF(parameter_counts); p++) {
+ int parameter_count = parameter_counts[p];
+ for (int i = 0; i <= parameter_count; i++) {
+ uint8_t operand_value =
+ Bytecodes::ParameterIndexToOperand(i, parameter_count);
+ uint8_t index =
+ Bytecodes::ParameterIndexFromOperand(operand_value, parameter_count);
+ CHECK_EQ(i, index);
+ }
+ }
+#undef COUNT_OF
+}
+
+
+TEST(OperandConversion, RegistersParametersNoOverlap) {
+ uint8_t operand_count[255] = {0};
+
+ 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.
+ uint8_t register_operand = Bytecodes::RegisterIndexToOperand(i);
+ operand_count[register_operand] += 1;
+ CHECK_EQ(operand_count[register_operand], 1);
+ }
+
+ int parameter_count = Bytecodes::MaximumNumberOfParameters();
+ for (int i = 0; i <= parameter_count; i++) {
+ uint8_t parameter_operand =
+ Bytecodes::ParameterIndexToOperand(i, parameter_count);
+ operand_count[parameter_operand] += 1;
+ CHECK_EQ(operand_count[parameter_operand], 1);
+ }
+}
+
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
« src/interpreter/bytecodes.cc ('K') | « src/objects.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698