Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / test / cctest / compiler / value-helper.h
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/v8.h"
9
10 #include "src/compiler/common-operator.h"
11 #include "src/compiler/node.h"
12 #include "src/compiler/node-matchers.h"
13 #include "src/isolate.h"
14 #include "src/objects.h"
15 #include "test/cctest/cctest.h"
16
17 namespace v8 {
18 namespace internal {
19 namespace compiler {
20
21 // A collection of utilities related to numerical and heap values, including
22 // example input values of various types, including int32_t, uint32_t, double,
23 // etc.
24 class ValueHelper {
25  public:
26   Isolate* isolate_;
27
28   ValueHelper() : isolate_(CcTest::InitIsolateOnce()) {}
29
30   void CheckFloat64Constant(double expected, Node* node) {
31     CHECK_EQ(IrOpcode::kFloat64Constant, node->opcode());
32     CHECK_EQ(expected, OpParameter<double>(node));
33   }
34
35   void CheckNumberConstant(double expected, Node* node) {
36     CHECK_EQ(IrOpcode::kNumberConstant, node->opcode());
37     CHECK_EQ(expected, OpParameter<double>(node));
38   }
39
40   void CheckInt32Constant(int32_t expected, Node* node) {
41     CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
42     CHECK_EQ(expected, OpParameter<int32_t>(node));
43   }
44
45   void CheckUint32Constant(int32_t expected, Node* node) {
46     CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
47     CHECK_EQ(expected, OpParameter<uint32_t>(node));
48   }
49
50   void CheckHeapConstant(Object* expected, Node* node) {
51     CHECK_EQ(IrOpcode::kHeapConstant, node->opcode());
52     CHECK_EQ(expected, *OpParameter<Unique<Object> >(node).handle());
53   }
54
55   void CheckTrue(Node* node) {
56     CheckHeapConstant(isolate_->heap()->true_value(), node);
57   }
58
59   void CheckFalse(Node* node) {
60     CheckHeapConstant(isolate_->heap()->false_value(), node);
61   }
62
63   static std::vector<float> float32_vector() {
64     static const float kValues[] = {
65         -std::numeric_limits<float>::infinity(), -2.70497e+38f, -1.4698e+37f,
66         -1.22813e+35f,                           -1.20555e+35f, -1.34584e+34f,
67         -1.0079e+32f,                            -6.49364e+26f, -3.06077e+25f,
68         -1.46821e+25f,                           -1.17658e+23f, -1.9617e+22f,
69         -2.7357e+20f,                            -1.48708e+13f, -1.89633e+12f,
70         -4.66622e+11f,                           -2.22581e+11f, -1.45381e+10f,
71         -1.3956e+09f,                            -1.32951e+09f, -1.30721e+09f,
72         -1.19756e+09f,                           -9.26822e+08f, -6.35647e+08f,
73         -4.00037e+08f,                           -1.81227e+08f, -5.09256e+07f,
74         -964300.0f,                              -192446.0f,    -28455.0f,
75         -27194.0f,                               -26401.0f,     -20575.0f,
76         -17069.0f,                               -9167.0f,      -960.178f,
77         -113.0f,                                 -62.0f,        -15.0f,
78         -7.0f,                                   -0.0256635f,   -4.60374e-07f,
79         -3.63759e-10f,                           -4.30175e-14f, -5.27385e-15f,
80         -1.48084e-15f,                           -1.05755e-19f, -3.2995e-21f,
81         -1.67354e-23f,                           -1.11885e-23f, -1.78506e-30f,
82         -5.07594e-31f,                           -3.65799e-31f, -1.43718e-34f,
83         -1.27126e-38f,                           -0.0f,         0.0f,
84         1.17549e-38f,                            1.56657e-37f,  4.08512e-29f,
85         3.31357e-28f,                            6.25073e-22f,  4.1723e-13f,
86         1.44343e-09f,                            5.27004e-08f,  9.48298e-08f,
87         5.57888e-07f,                            4.89988e-05f,  0.244326f,
88         12.4895f,                                19.0f,         47.0f,
89         106.0f,                                  538.324f,      564.536f,
90         819.124f,                                7048.0f,       12611.0f,
91         19878.0f,                                20309.0f,      797056.0f,
92         1.77219e+09f,                            1.51116e+11f,  4.18193e+13f,
93         3.59167e+16f,                            3.38211e+19f,  2.67488e+20f,
94         1.78831e+21f,                            9.20914e+21f,  8.35654e+23f,
95         1.4495e+24f,                             5.94015e+25f,  4.43608e+30f,
96         2.44502e+33f,                            2.61152e+33f,  1.38178e+37f,
97         1.71306e+37f,                            3.31899e+38f,  3.40282e+38f,
98         std::numeric_limits<float>::infinity()};
99     return std::vector<float>(&kValues[0], &kValues[arraysize(kValues)]);
100   }
101
102   static std::vector<double> float64_vector() {
103     static const double nan = v8::base::OS::nan_value();
104     static const double values[] = {
105         0.125,           0.25,            0.375,          0.5,
106         1.25,            -1.75,           2,              5.125,
107         6.25,            0.0,             -0.0,           982983.25,
108         888,             2147483647.0,    -999.75,        3.1e7,
109         -2e66,           3e-88,           -2147483648.0,  V8_INFINITY,
110         -V8_INFINITY,    nan,             2147483647.375, 2147483647.75,
111         2147483648.0,    2147483648.25,   2147483649.25,  -2147483647.0,
112         -2147483647.125, -2147483647.875, -2147483648.25, -2147483649.5};
113     return std::vector<double>(&values[0], &values[arraysize(values)]);
114   }
115
116   static const std::vector<int32_t> int32_vector() {
117     std::vector<uint32_t> values = uint32_vector();
118     return std::vector<int32_t>(values.begin(), values.end());
119   }
120
121   static const std::vector<uint32_t> uint32_vector() {
122     static const uint32_t kValues[] = {
123         0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
124         // This row is useful for testing lea optimizations on intel.
125         0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000008, 0x00000009,
126         0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
127         0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
128         0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
129         0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
130         0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
131         0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
132         0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
133     return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]);
134   }
135
136   static const std::vector<double> nan_vector(size_t limit = 0) {
137     static const double nan = v8::base::OS::nan_value();
138     static const double values[] = {-nan,               -V8_INFINITY * -0.0,
139                                     -V8_INFINITY * 0.0, V8_INFINITY * -0.0,
140                                     V8_INFINITY * 0.0,  nan};
141     return std::vector<double>(&values[0], &values[arraysize(values)]);
142   }
143
144   static const std::vector<uint32_t> ror_vector() {
145     static const uint32_t kValues[31] = {
146         1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16,
147         17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
148     return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]);
149   }
150 };
151
152 // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... }
153 // Watch out, these macros aren't hygenic; they pollute your scope. Thanks STL.
154 #define FOR_INPUTS(ctype, itype, var)                           \
155   std::vector<ctype> var##_vec = ValueHelper::itype##_vector(); \
156   for (std::vector<ctype>::iterator var = var##_vec.begin();    \
157        var != var##_vec.end(); ++var)
158
159 #define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var)
160 #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var)
161 #define FOR_FLOAT32_INPUTS(var) FOR_INPUTS(float, float32, var)
162 #define FOR_FLOAT64_INPUTS(var) FOR_INPUTS(double, float64, var)
163
164 #define FOR_INT32_SHIFTS(var) for (int32_t var = 0; var < 32; var++)
165
166 #define FOR_UINT32_SHIFTS(var) for (uint32_t var = 0; var < 32; var++)
167
168 }  // namespace compiler
169 }  // namespace internal
170 }  // namespace v8
171
172 #endif  // V8_CCTEST_COMPILER_VALUE_HELPER_H_