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

Side by Side Diff: test/cctest/compiler/compiler/value-helper.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback, rebase and "git cl format" Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #ifndef V8_CCTEST_COMPILER_VALUE_HELPER_H_
6 #define V8_CCTEST_COMPILER_VALUE_HELPER_H_
7
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/node.h"
10 #include "src/compiler/node-matchers.h"
11 #include "src/isolate.h"
12 #include "src/objects.h"
13 #include "test/cctest/cctest.h"
14 #include "v8.h"
15
16 namespace v8 {
17 namespace internal {
18 namespace compiler {
19
20 // A collection of utilities related to numerical and heap values, including
21 // example input values of various types, including int32_t, uint32_t, double,
22 // etc.
23 class ValueHelper {
24 public:
25 Isolate* isolate_;
26
27 ValueHelper() : isolate_(CcTest::InitIsolateOnce()) {}
28
29 template <typename T>
30 void CheckConstant(T expected, Node* node) {
31 CHECK_EQ(expected, ValueOf<T>(node->op()));
32 }
33
34 void CheckFloat64Constant(double expected, Node* node) {
35 CHECK_EQ(IrOpcode::kFloat64Constant, node->opcode());
36 CHECK_EQ(expected, ValueOf<double>(node->op()));
37 }
38
39 void CheckNumberConstant(double expected, Node* node) {
40 CHECK_EQ(IrOpcode::kNumberConstant, node->opcode());
41 CHECK_EQ(expected, ValueOf<double>(node->op()));
42 }
43
44 void CheckInt32Constant(int32_t expected, Node* node) {
45 CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
46 CHECK_EQ(expected, ValueOf<int32_t>(node->op()));
47 }
48
49 void CheckUint32Constant(int32_t expected, Node* node) {
50 CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
51 CHECK_EQ(expected, ValueOf<uint32_t>(node->op()));
52 }
53
54 void CheckHeapConstant(Object* expected, Node* node) {
55 CHECK_EQ(IrOpcode::kHeapConstant, node->opcode());
56 CHECK_EQ(expected, *ValueOf<Handle<Object> >(node->op()));
57 }
58
59 void CheckTrue(Node* node) {
60 CheckHeapConstant(isolate_->heap()->true_value(), node);
61 }
62
63 void CheckFalse(Node* node) {
64 CheckHeapConstant(isolate_->heap()->false_value(), node);
65 }
66
67 static std::vector<double> float64_vector() {
68 static const double nan = v8::base::OS::nan_value();
69 static const double values[] = {
70 0.125, 0.25, 0.375, 0.5,
71 1.25, -1.75, 2, 5.125,
72 6.25, 0.0, -0.0, 982983.25,
73 888, 2147483647.0, -999.75, 3.1e7,
74 -2e66, 3e-88, -2147483648.0, V8_INFINITY,
75 -V8_INFINITY, nan, 2147483647.375, 2147483647.75,
76 2147483648.0, 2147483648.25, 2147483649.25, -2147483647.0,
77 -2147483647.125, -2147483647.875, -2147483648.25, -2147483649.5};
78 return std::vector<double>(&values[0], &values[ARRAY_SIZE(values)]);
79 }
80
81 static const std::vector<int32_t> int32_vector() {
82 std::vector<uint32_t> values = uint32_vector();
83 return std::vector<int32_t>(values.begin(), values.end());
84 }
85
86 static const std::vector<uint32_t> uint32_vector() {
87 static const uint32_t kValues[] = {
88 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
89 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
90 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
91 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
92 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
93 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
94 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
95 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
96 return std::vector<uint32_t>(&kValues[0], &kValues[ARRAY_SIZE(kValues)]);
97 }
98
99 static const std::vector<double> nan_vector(size_t limit = 0) {
100 static const double nan = v8::base::OS::nan_value();
101 static const double values[] = {-nan, -V8_INFINITY * -0.0,
102 -V8_INFINITY * 0.0, V8_INFINITY * -0.0,
103 V8_INFINITY * 0.0, nan};
104 return std::vector<double>(&values[0], &values[ARRAY_SIZE(values)]);
105 }
106 };
107
108 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... }
109 // Watch out, these macros aren't hygenic; they pollute your scope. Thanks STL.
110 #define FOR_INPUTS(ctype, itype, var) \
111 std::vector<ctype> var##_vec = ValueHelper::itype##_vector(); \
112 for (std::vector<ctype>::iterator var = var##_vec.begin(); \
113 var != var##_vec.end(); ++var)
114
115 #define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var)
116 #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var)
117 #define FOR_FLOAT64_INPUTS(var) FOR_INPUTS(double, float64, var)
118 }
119 }
120 } // namespace v8::internal::compiler
121
122 #endif // V8_CCTEST_COMPILER_VALUE_HELPER_H_
OLDNEW
« no previous file with comments | « test/cctest/compiler/compiler/test-structured-machine-assembler.cc ('k') | test/cctest/compiler/function-tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698