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

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 test, bug spotted by bots. 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
« no previous file with comments | « src/objects.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..82d3b01474052f862af65dad412dba2555e7739f
--- /dev/null
+++ b/test/unittests/interpreter/bytecodes-unittest.cc
@@ -0,0 +1,63 @@
+// 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) {
+ int parameter_counts[] = {7, 13, 99};
+
+ size_t count = sizeof(parameter_counts) / sizeof(parameter_counts[0]);
+ for (size_t p = 0; p < count; 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) {
+ std::vector<uint8_t> operand_count(256);
+
+ 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() + 1;
+ 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
« no previous file with comments | « src/objects.cc ('k') | test/unittests/unittests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698