LCOV - code coverage report
Current view: top level - test/cctest/compiler - value-helper.h (source / functions) Hit Total Coverage
Test: app.info Lines: 12 12 100.0 %
Date: 2017-10-20 Functions: 2 2 100.0 %

          Line data    Source code
       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 <stdint.h>
       9             : 
      10             : #include "src/base/template-utils.h"
      11             : #include "src/compiler/common-operator.h"
      12             : #include "src/compiler/node-matchers.h"
      13             : #include "src/compiler/node.h"
      14             : #include "src/heap/heap-inl.h"
      15             : #include "src/isolate.h"
      16             : #include "src/objects.h"
      17             : #include "test/cctest/cctest.h"
      18             : 
      19             : namespace v8 {
      20             : namespace internal {
      21             : namespace compiler {
      22             : 
      23             : // A collection of utilities related to numerical and heap values, including
      24             : // example input values of various types, including int32_t, uint32_t, double,
      25             : // etc.
      26             : class ValueHelper {
      27             :  public:
      28             :   Isolate* isolate_;
      29             : 
      30             :   ValueHelper() : isolate_(CcTest::InitIsolateOnce()) {}
      31             : 
      32             :   void CheckFloat64Constant(double expected, Node* node) {
      33             :     CHECK_EQ(IrOpcode::kFloat64Constant, node->opcode());
      34             :     CHECK_EQ(expected, OpParameter<double>(node));
      35             :   }
      36             : 
      37             :   void CheckNumberConstant(double expected, Node* node) {
      38             :     CHECK_EQ(IrOpcode::kNumberConstant, node->opcode());
      39             :     CHECK_EQ(expected, OpParameter<double>(node));
      40             :   }
      41             : 
      42             :   void CheckInt32Constant(int32_t expected, Node* node) {
      43             :     CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
      44             :     CHECK_EQ(expected, OpParameter<int32_t>(node));
      45             :   }
      46             : 
      47             :   void CheckUint32Constant(int32_t expected, Node* node) {
      48             :     CHECK_EQ(IrOpcode::kInt32Constant, node->opcode());
      49             :     CHECK_EQ(expected, OpParameter<int32_t>(node));
      50             :   }
      51             : 
      52             :   void CheckHeapConstant(HeapObject* expected, Node* node) {
      53             :     CHECK_EQ(IrOpcode::kHeapConstant, node->opcode());
      54             :     CHECK_EQ(expected, *OpParameter<Handle<HeapObject>>(node));
      55             :   }
      56             : 
      57             :   void CheckTrue(Node* node) {
      58             :     CheckHeapConstant(isolate_->heap()->true_value(), node);
      59             :   }
      60             : 
      61             :   void CheckFalse(Node* node) {
      62             :     CheckHeapConstant(isolate_->heap()->false_value(), node);
      63             :   }
      64             : 
      65             :   static constexpr float float32_array[] = {
      66             :       -std::numeric_limits<float>::infinity(),
      67             :       -2.70497e+38f,
      68             :       -1.4698e+37f,
      69             :       -1.22813e+35f,
      70             :       -1.20555e+35f,
      71             :       -1.34584e+34f,
      72             :       -1.0079e+32f,
      73             :       -6.49364e+26f,
      74             :       -3.06077e+25f,
      75             :       -1.46821e+25f,
      76             :       -1.17658e+23f,
      77             :       -1.9617e+22f,
      78             :       -2.7357e+20f,
      79             :       -9223372036854775808.0f,  // INT64_MIN
      80             :       -1.48708e+13f,
      81             :       -1.89633e+12f,
      82             :       -4.66622e+11f,
      83             :       -2.22581e+11f,
      84             :       -1.45381e+10f,
      85             :       -2147483904.0f,  // First float32 after INT32_MIN
      86             :       -2147483648.0f,  // INT32_MIN
      87             :       -2147483520.0f,  // Last float32 before INT32_MIN
      88             :       -1.3956e+09f,
      89             :       -1.32951e+09f,
      90             :       -1.30721e+09f,
      91             :       -1.19756e+09f,
      92             :       -9.26822e+08f,
      93             :       -6.35647e+08f,
      94             :       -4.00037e+08f,
      95             :       -1.81227e+08f,
      96             :       -5.09256e+07f,
      97             :       -964300.0f,
      98             :       -192446.0f,
      99             :       -28455.0f,
     100             :       -27194.0f,
     101             :       -26401.0f,
     102             :       -20575.0f,
     103             :       -17069.0f,
     104             :       -9167.0f,
     105             :       -960.178f,
     106             :       -113.0f,
     107             :       -62.0f,
     108             :       -15.0f,
     109             :       -7.0f,
     110             :       -1.0f,
     111             :       -0.0256635f,
     112             :       -4.60374e-07f,
     113             :       -3.63759e-10f,
     114             :       -4.30175e-14f,
     115             :       -5.27385e-15f,
     116             :       -1.5707963267948966f,
     117             :       -1.48084e-15f,
     118             :       -2.220446049250313e-16f,
     119             :       -1.05755e-19f,
     120             :       -3.2995e-21f,
     121             :       -1.67354e-23f,
     122             :       -1.11885e-23f,
     123             :       -1.78506e-30f,
     124             :       -5.07594e-31f,
     125             :       -3.65799e-31f,
     126             :       -1.43718e-34f,
     127             :       -1.27126e-38f,
     128             :       -0.0f,
     129             :       0.0f,
     130             :       1.17549e-38f,
     131             :       1.56657e-37f,
     132             :       4.08512e-29f,
     133             :       3.31357e-28f,
     134             :       6.25073e-22f,
     135             :       4.1723e-13f,
     136             :       1.44343e-09f,
     137             :       1.5707963267948966f,
     138             :       5.27004e-08f,
     139             :       9.48298e-08f,
     140             :       5.57888e-07f,
     141             :       4.89988e-05f,
     142             :       0.244326f,
     143             :       1.0f,
     144             :       12.4895f,
     145             :       19.0f,
     146             :       47.0f,
     147             :       106.0f,
     148             :       538.324f,
     149             :       564.536f,
     150             :       819.124f,
     151             :       7048.0f,
     152             :       12611.0f,
     153             :       19878.0f,
     154             :       20309.0f,
     155             :       797056.0f,
     156             :       1.77219e+09f,
     157             :       2147483648.0f,  // INT32_MAX + 1
     158             :       4294967296.0f,  // UINT32_MAX + 1
     159             :       1.51116e+11f,
     160             :       4.18193e+13f,
     161             :       3.59167e+16f,
     162             :       9223372036854775808.0f,   // INT64_MAX + 1
     163             :       18446744073709551616.0f,  // UINT64_MAX + 1
     164             :       3.38211e+19f,
     165             :       2.67488e+20f,
     166             :       1.78831e+21f,
     167             :       9.20914e+21f,
     168             :       8.35654e+23f,
     169             :       1.4495e+24f,
     170             :       5.94015e+25f,
     171             :       4.43608e+30f,
     172             :       2.44502e+33f,
     173             :       2.61152e+33f,
     174             :       1.38178e+37f,
     175             :       1.71306e+37f,
     176             :       3.31899e+38f,
     177             :       3.40282e+38f,
     178             :       std::numeric_limits<float>::infinity(),
     179             :       std::numeric_limits<float>::quiet_NaN(),
     180             :       -std::numeric_limits<float>::quiet_NaN()};
     181             : 
     182             :   static constexpr Vector<const float> float32_vector() {
     183             :     return ArrayVector(float32_array);
     184             :   }
     185             : 
     186             :   static constexpr double float64_array[] = {
     187             :       -2e66,
     188             :       -2.220446049250313e-16,
     189             :       -9223373136366403584.0,
     190             :       -9223372036854775808.0,  // INT64_MIN
     191             :       -2147483649.5,
     192             :       -2147483648.25,
     193             :       -2147483648.0,
     194             :       -2147483647.875,
     195             :       -2147483647.125,
     196             :       -2147483647.0,
     197             :       -999.75,
     198             :       -2e66,
     199             :       -1.75,
     200             :       -1.5707963267948966,
     201             :       -1.0,
     202             :       -0.5,
     203             :       -0.0,
     204             :       0.0,
     205             :       3e-88,
     206             :       0.125,
     207             :       0.25,
     208             :       0.375,
     209             :       0.5,
     210             :       1.0,
     211             :       1.17549e-38,
     212             :       1.56657e-37,
     213             :       1.0000001,
     214             :       1.25,
     215             :       1.5707963267948966,
     216             :       2,
     217             :       3.1e7,
     218             :       5.125,
     219             :       6.25,
     220             :       888,
     221             :       982983.25,
     222             :       2147483647.0,
     223             :       2147483647.375,
     224             :       2147483647.75,
     225             :       2147483648.0,
     226             :       2147483648.25,
     227             :       2147483649.25,
     228             :       9223372036854775808.0,  // INT64_MAX + 1
     229             :       9223373136366403584.0,
     230             :       18446744073709551616.0,  // UINT64_MAX + 1
     231             :       2e66,
     232             :       V8_INFINITY,
     233             :       -V8_INFINITY,
     234             :       std::numeric_limits<double>::quiet_NaN(),
     235             :       -std::numeric_limits<double>::quiet_NaN()};
     236             : 
     237             :   static constexpr Vector<const double> float64_vector() {
     238             :     return ArrayVector(float64_array);
     239             :   }
     240             : 
     241             :   static constexpr uint32_t uint32_array[] = {
     242             :       0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
     243             :       // This row is useful for testing lea optimizations on intel.
     244             :       0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000008, 0x00000009,
     245             :       0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344,
     246             :       0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c,
     247             :       0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
     248             :       0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000,
     249             :       0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff,
     250             :       0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
     251             :       0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
     252             :       // Bit pattern of a quiet NaN and signaling NaN, with or without
     253             :       // additional payload.
     254             :       0x7fc00000, 0x7f800000, 0x7fffffff, 0x7f876543};
     255             : 
     256             :   static constexpr Vector<const uint32_t> uint32_vector() {
     257             :     return ArrayVector(uint32_array);
     258             :   }
     259             : 
     260             :   static constexpr Vector<const int32_t> int32_vector() {
     261             :     return Vector<const int32_t>::cast(uint32_vector());
     262             :   }
     263             : 
     264             :   static constexpr uint64_t uint64_array[] = {
     265             :       0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf,
     266             :       0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000008, 0x00000009,
     267             :       0xffffffffffffffff, 0xfffffffffffffffe, 0xfffffffffffffffd,
     268             :       0x0000000000000000, 0x0000000100000000, 0xffffffff00000000,
     269             :       0x1b09788b00000000, 0x04c5fce800000000, 0xcc0de5bf00000000,
     270             :       0x0000000200000000, 0x0000000300000000, 0x0000000400000000,
     271             :       0x0000000500000000, 0x0000000800000000, 0x0000000900000000,
     272             :       0x273a798e187937a3, 0xece3af835495a16b, 0x0b668ecc11223344, 0x0000009e,
     273             :       0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, 0x88776655,
     274             :       0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00,
     275             :       0x761c4761eeeeeeee, 0x80000000eeeeeeee, 0x88888888dddddddd,
     276             :       0xa0000000dddddddd, 0xddddddddaaaaaaaa, 0xe0000000aaaaaaaa,
     277             :       0xeeeeeeeeeeeeeeee, 0xfffffffdeeeeeeee, 0xf0000000dddddddd,
     278             :       0x007fffffdddddddd, 0x003fffffaaaaaaaa, 0x001fffffaaaaaaaa, 0x000fffff,
     279             :       0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, 0x00003fff,
     280             :       0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff,
     281             :       0x00003fffffffffff, 0x00001fffffffffff, 0x00000fffffffffff,
     282             :       0x000007ffffffffff, 0x000003ffffffffff, 0x000001ffffffffff,
     283             :       0x8000008000000000, 0x8000008000000001, 0x8000000000000400,
     284             :       0x8000000000000401, 0x0000000000000020,
     285             :       // Bit pattern of a quiet NaN and signaling NaN, with or without
     286             :       // additional payload.
     287             :       0x7ff8000000000000, 0x7ff0000000000000, 0x7ff8123456789abc,
     288             :       0x7ff7654321fedcba};
     289             : 
     290             :   static constexpr Vector<const uint64_t> uint64_vector() {
     291             :     return ArrayVector(uint64_array);
     292             :   }
     293             : 
     294             :   static constexpr Vector<const int64_t> int64_vector() {
     295             :     return Vector<const int64_t>::cast(uint64_vector());
     296             :   }
     297             : 
     298             :   static constexpr int16_t int16_array[] = {
     299             :       0, 1, 2, INT16_MAX - 1, INT16_MAX, INT16_MIN, INT16_MIN + 1, -2, -1};
     300             : 
     301             :   static constexpr Vector<const int16_t> int16_vector() {
     302             :     return ArrayVector(int16_array);
     303             :   }
     304             : 
     305             :   static constexpr Vector<const uint16_t> uint16_vector() {
     306             :     return Vector<const uint16_t>::cast(int16_vector());
     307             :   }
     308             : 
     309             :   static constexpr int8_t int8_array[] = {
     310             :       0, 1, 2, INT8_MAX - 1, INT8_MAX, INT8_MIN, INT8_MIN + 1, -2, -1};
     311             : 
     312             :   static constexpr Vector<const int8_t> int8_vector() {
     313             :     return ArrayVector(int8_array);
     314             :   }
     315             : 
     316             :   static constexpr Vector<const uint8_t> uint8_vector() {
     317             :     return Vector<const uint8_t>::cast(ArrayVector(int8_array));
     318             :   }
     319             : 
     320             :   static constexpr uint32_t ror_array[31] = {
     321             :       1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15, 16,
     322             :       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
     323             : 
     324             :   static constexpr Vector<const uint32_t> ror_vector() {
     325             :     return ArrayVector(ror_array);
     326             :   }
     327             : };
     328             : 
     329             : // Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... }
     330             : // Watch out, these macros aren't hygenic; they pollute your scope. Thanks STL.
     331             : #define FOR_INPUTS(ctype, itype, var)                             \
     332             :   Vector<const ctype> var##_vec =                                 \
     333             :       ::v8::internal::compiler::ValueHelper::itype##_vector();    \
     334             :   for (Vector<const ctype>::iterator var = var##_vec.begin(),     \
     335             :                                      var##_end = var##_vec.end(); \
     336             :        var != var##_end; ++var)
     337             : 
     338             : #define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var)
     339             : #define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var)
     340             : #define FOR_INT16_INPUTS(var) FOR_INPUTS(int16_t, int16, var)
     341             : #define FOR_UINT16_INPUTS(var) FOR_INPUTS(uint16_t, uint16, var)
     342             : #define FOR_INT8_INPUTS(var) FOR_INPUTS(int8_t, int8, var)
     343             : #define FOR_UINT8_INPUTS(var) FOR_INPUTS(uint8_t, uint8, var)
     344             : #define FOR_INT64_INPUTS(var) FOR_INPUTS(int64_t, int64, var)
     345             : #define FOR_UINT64_INPUTS(var) FOR_INPUTS(uint64_t, uint64, var)
     346             : #define FOR_FLOAT32_INPUTS(var) FOR_INPUTS(float, float32, var)
     347             : #define FOR_FLOAT64_INPUTS(var) FOR_INPUTS(double, float64, var)
     348             : 
     349             : #define FOR_INT32_SHIFTS(var) for (int32_t var = 0; var < 32; var++)
     350             : 
     351             : #define FOR_UINT32_SHIFTS(var) for (uint32_t var = 0; var < 32; var++)
     352             : 
     353             : // TODO(bmeurer): Drop this crap once we switch to GTest/Gmock.
     354     1336106 : static inline void CheckFloatEq(volatile float x, volatile float y) {
     355     1336106 :   if (std::isnan(x)) {
     356       45782 :     CHECK(std::isnan(y));
     357             :   } else {
     358     1290324 :     CHECK_EQ(x, y);
     359     3870972 :     CHECK_EQ(std::signbit(x), std::signbit(y));
     360             :   }
     361     1336106 : }
     362             : 
     363             : #define CHECK_FLOAT_EQ(lhs, rhs)                      \
     364             :   do {                                                \
     365             :     volatile float tmp = lhs;                         \
     366             :     ::v8::internal::compiler::CheckFloatEq(tmp, rhs); \
     367             :   } while (0)
     368             : 
     369     2988903 : static inline void CheckDoubleEq(volatile double x, volatile double y) {
     370     2988903 :   if (std::isnan(x)) {
     371      324278 :     CHECK(std::isnan(y));
     372             :   } else {
     373     2664625 :     CHECK_EQ(x, y);
     374     7993875 :     CHECK_EQ(std::signbit(x), std::signbit(y));
     375             :   }
     376     2988903 : }
     377             : 
     378             : #define CHECK_DOUBLE_EQ(lhs, rhs)                      \
     379             :   do {                                                 \
     380             :     volatile double tmp = lhs;                         \
     381             :     ::v8::internal::compiler::CheckDoubleEq(tmp, rhs); \
     382             :   } while (0)
     383             : 
     384             : }  // namespace compiler
     385             : }  // namespace internal
     386             : }  // namespace v8
     387             : 
     388             : #endif  // V8_CCTEST_COMPILER_VALUE_HELPER_H_

Generated by: LCOV version 1.10