Home | History | Annotate | Download | only in cctest
      1 // Copyright 2015 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 #include "src/v8.h"
      6 
      7 #include "src/objects.h"
      8 #include "src/ostreams.h"
      9 #include "test/cctest/cctest.h"
     10 
     11 using namespace v8::internal;
     12 
     13 #define FLOAT_TEST(type, lane_count)                     \
     14   {                                                      \
     15     float nan = std::numeric_limits<float>::quiet_NaN(); \
     16     float lanes[lane_count] = {0};                       \
     17     Handle<type> a = factory->New##type(lanes);          \
     18     Handle<type> b = factory->New##type(lanes);          \
     19     CHECK(a->BitwiseEquals(*b));                         \
     20     CHECK(a->SameValue(*b));                             \
     21     CHECK(a->SameValueZero(*b));                         \
     22     CHECK_EQ(a->Hash(), b->Hash());                      \
     23     for (int i = 0; i < lane_count; i++) {               \
     24       a->set_lane(i, -0.0);                              \
     25       CHECK(!a->BitwiseEquals(*b));                      \
     26       CHECK_NE(a->Hash(), b->Hash());                    \
     27       CHECK(!a->SameValue(*b));                          \
     28       CHECK(a->SameValueZero(*b));                       \
     29       b->set_lane(i, -0.0);                              \
     30       CHECK(a->BitwiseEquals(*b));                       \
     31       CHECK_EQ(a->Hash(), b->Hash());                    \
     32       CHECK(a->SameValue(*b));                           \
     33       CHECK(a->SameValueZero(*b));                       \
     34       a->set_lane(i, nan);                               \
     35       CHECK(!a->BitwiseEquals(*b));                      \
     36       CHECK(!a->SameValue(*b));                          \
     37       CHECK(!a->SameValueZero(*b));                      \
     38       CHECK_NE(a->Hash(), b->Hash());                    \
     39       b->set_lane(i, nan);                               \
     40       CHECK(a->BitwiseEquals(*b));                       \
     41       CHECK_EQ(a->Hash(), b->Hash());                    \
     42       CHECK(a->SameValue(*b));                           \
     43       CHECK(a->SameValueZero(*b));                       \
     44     }                                                    \
     45   }
     46 
     47 #define INT_TEST(type, lane_count, lane_type)   \
     48   {                                             \
     49     lane_type lanes[lane_count] = {0};          \
     50     Handle<type> a = factory->New##type(lanes); \
     51     Handle<type> b = factory->New##type(lanes); \
     52     CHECK(a->BitwiseEquals(*b));                \
     53     CHECK(a->SameValue(*b));                    \
     54     CHECK(a->SameValueZero(*b));                \
     55     CHECK_EQ(a->Hash(), b->Hash());             \
     56     for (int i = 0; i < lane_count; i++) {      \
     57       a->set_lane(i, i + 1);                    \
     58       CHECK(!a->BitwiseEquals(*b));             \
     59       CHECK_NE(a->Hash(), b->Hash());           \
     60       CHECK(!a->SameValue(*b));                 \
     61       CHECK(!a->SameValueZero(*b));             \
     62       b->set_lane(i, i + 1);                    \
     63       CHECK(a->BitwiseEquals(*b));              \
     64       CHECK_EQ(a->Hash(), b->Hash());           \
     65       CHECK(a->SameValue(*b));                  \
     66       CHECK(a->SameValueZero(*b));              \
     67       a->set_lane(i, -(i + 1));                 \
     68       CHECK(!a->BitwiseEquals(*b));             \
     69       CHECK_NE(a->Hash(), b->Hash());           \
     70       CHECK(!a->SameValue(*b));                 \
     71       CHECK(!a->SameValueZero(*b));             \
     72       b->set_lane(i, -(i + 1));                 \
     73       CHECK(a->BitwiseEquals(*b));              \
     74       CHECK_EQ(a->Hash(), b->Hash());           \
     75       CHECK(a->SameValue(*b));                  \
     76       CHECK(a->SameValueZero(*b));              \
     77     }                                           \
     78   }
     79 
     80 #define BOOL_TEST(type, lane_count)             \
     81   {                                             \
     82     bool lanes[lane_count] = {false};           \
     83     Handle<type> a = factory->New##type(lanes); \
     84     Handle<type> b = factory->New##type(lanes); \
     85     CHECK(a->BitwiseEquals(*b));                \
     86     CHECK(a->SameValue(*b));                    \
     87     CHECK(a->SameValueZero(*b));                \
     88     CHECK_EQ(a->Hash(), b->Hash());             \
     89     for (int i = 0; i < lane_count; i++) {      \
     90       a->set_lane(i, true);                     \
     91       CHECK(!a->BitwiseEquals(*b));             \
     92       CHECK_NE(a->Hash(), b->Hash());           \
     93       CHECK(!a->SameValue(*b));                 \
     94       CHECK(!a->SameValueZero(*b));             \
     95       b->set_lane(i, true);                     \
     96       CHECK(a->BitwiseEquals(*b));              \
     97       CHECK_EQ(a->Hash(), b->Hash());           \
     98       CHECK(a->SameValue(*b));                  \
     99       CHECK(a->SameValueZero(*b));              \
    100     }                                           \
    101   }
    102 
    103 TEST(SimdTypes) {
    104   CcTest::InitializeVM();
    105   Isolate* isolate = CcTest::i_isolate();
    106   Factory* factory = isolate->factory();
    107 
    108   HandleScope sc(isolate);
    109 
    110   FLOAT_TEST(Float32x4, 4)
    111   INT_TEST(Int32x4, 4, int32_t)
    112   INT_TEST(Uint32x4, 4, uint32_t)
    113   BOOL_TEST(Bool32x4, 4)
    114   INT_TEST(Int16x8, 8, int16_t)
    115   INT_TEST(Uint16x8, 8, uint16_t)
    116   BOOL_TEST(Bool16x8, 8)
    117   INT_TEST(Int8x16, 16, int8_t)
    118   INT_TEST(Uint8x16, 16, uint8_t)
    119   BOOL_TEST(Bool8x16, 16)
    120 }
    121