OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/ostreams.h" | 8 #include "src/ostreams.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 | 10 |
11 using namespace v8::internal; | 11 using namespace v8::internal; |
12 | 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 } |
13 | 46 |
14 TEST(SameValue) { | 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) { |
15 CcTest::InitializeVM(); | 104 CcTest::InitializeVM(); |
16 Isolate* isolate = CcTest::i_isolate(); | 105 Isolate* isolate = CcTest::i_isolate(); |
17 Factory* factory = isolate->factory(); | 106 Factory* factory = isolate->factory(); |
18 | 107 |
19 HandleScope sc(isolate); | 108 HandleScope sc(isolate); |
20 | 109 |
21 float nan = std::numeric_limits<float>::quiet_NaN(); | 110 FLOAT_TEST(Float32x4, 4) |
22 | 111 INT_TEST(Int32x4, 4, int32_t) |
23 Handle<Float32x4> a = factory->NewFloat32x4(0, 0, 0, 0); | 112 BOOL_TEST(Bool32x4, 4) |
24 Handle<Float32x4> b = factory->NewFloat32x4(0, 0, 0, 0); | 113 INT_TEST(Int16x8, 8, int16_t) |
25 CHECK(a->SameValue(*b)); | 114 BOOL_TEST(Bool16x8, 8) |
26 for (int i = 0; i < 4; i++) { | 115 INT_TEST(Int8x16, 16, int8_t) |
27 a->set_lane(i, nan); | 116 BOOL_TEST(Bool8x16, 16) |
28 CHECK(!a->SameValue(*b)); | |
29 CHECK(!a->SameValueZero(*b)); | |
30 b->set_lane(i, nan); | |
31 CHECK(a->SameValue(*b)); | |
32 CHECK(a->SameValueZero(*b)); | |
33 a->set_lane(i, -0.0); | |
34 CHECK(!a->SameValue(*b)); | |
35 b->set_lane(i, 0); | |
36 CHECK(!a->SameValue(*b)); | |
37 CHECK(a->SameValueZero(*b)); | |
38 b->set_lane(i, -0.0); | |
39 CHECK(a->SameValue(*b)); | |
40 CHECK(a->SameValueZero(*b)); | |
41 | |
42 a->set_lane(i, 0); | |
43 b->set_lane(i, 0); | |
44 } | |
45 } | 117 } |
OLD | NEW |