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

Unified Diff: test/cctest/heap/test-heap.cc

Issue 2695653005: Revert of Remove SIMD.js from V8. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/interpreter/bytecode_expectations/ForOf.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/heap/test-heap.cc
diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc
index dab10aace812dd5340ca9784a9536154edff857e..886cde6f5e72cadce8cf4cc4cad7dae0f9be49a9 100644
--- a/test/cctest/heap/test-heap.cc
+++ b/test/cctest/heap/test-heap.cc
@@ -68,6 +68,10 @@
Heap* heap = CcTest::heap();
CheckMap(heap->meta_map(), MAP_TYPE, Map::kSize);
CheckMap(heap->heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
+#define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
+ CheckMap(heap->type##_map(), SIMD128_VALUE_TYPE, Type::kSize);
+ SIMD128_TYPES(SIMD128_TYPE)
+#undef SIMD128_TYPE
CheckMap(heap->fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
CheckMap(heap->string_map(), STRING_TYPE, kVariableSizeSentinel);
}
@@ -319,6 +323,206 @@
CheckFindCodeObject(isolate);
}
+
+
+template <typename T, typename LANE_TYPE, int LANES>
+static void CheckSimdValue(T* value, LANE_TYPE lane_values[LANES],
+ LANE_TYPE other_value) {
+ // Check against lane_values, and check that all lanes can be set to
+ // other_value without disturbing the other lanes.
+ for (int i = 0; i < LANES; i++) {
+ CHECK_EQ(lane_values[i], value->get_lane(i));
+ }
+ for (int i = 0; i < LANES; i++) {
+ value->set_lane(i, other_value); // change the value
+ for (int j = 0; j < LANES; j++) {
+ if (i != j)
+ CHECK_EQ(lane_values[j], value->get_lane(j));
+ else
+ CHECK_EQ(other_value, value->get_lane(j));
+ }
+ value->set_lane(i, lane_values[i]); // restore the lane
+ }
+ CHECK(value->BooleanValue()); // SIMD values are 'true'.
+}
+
+
+TEST(SimdObjects) {
+ CcTest::InitializeVM();
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ HandleScope sc(isolate);
+
+ // Float32x4
+ {
+ float lanes[4] = {1, 2, 3, 4};
+ float quiet_NaN = std::numeric_limits<float>::quiet_NaN();
+ float signaling_NaN = std::numeric_limits<float>::signaling_NaN();
+
+ Handle<Float32x4> value = factory->NewFloat32x4(lanes);
+ CHECK(value->IsFloat32x4());
+ CheckSimdValue<Float32x4, float, 4>(*value, lanes, 3.14f);
+
+ // Check special lane values.
+ value->set_lane(1, -0.0);
+ CHECK_EQ(-0.0f, value->get_lane(1));
+ CHECK(std::signbit(value->get_lane(1))); // Sign bit should be preserved.
+ value->set_lane(2, quiet_NaN);
+ CHECK(std::isnan(value->get_lane(2)));
+ value->set_lane(3, signaling_NaN);
+ CHECK(std::isnan(value->get_lane(3)));
+
+#ifdef OBJECT_PRINT
+ // Check value printing.
+ {
+ value = factory->NewFloat32x4(lanes);
+ std::ostringstream os;
+ value->Float32x4Print(os);
+ CHECK_EQ("1, 2, 3, 4", os.str());
+ }
+ {
+ float special_lanes[4] = {0, -0.0, quiet_NaN, signaling_NaN};
+ value = factory->NewFloat32x4(special_lanes);
+ std::ostringstream os;
+ value->Float32x4Print(os);
+ // Value printing doesn't preserve signed zeroes.
+ CHECK_EQ("0, 0, NaN, NaN", os.str());
+ }
+#endif // OBJECT_PRINT
+ }
+ // Int32x4
+ {
+ int32_t lanes[4] = {1, 2, 3, 4};
+
+ Handle<Int32x4> value = factory->NewInt32x4(lanes);
+ CHECK(value->IsInt32x4());
+ CheckSimdValue<Int32x4, int32_t, 4>(*value, lanes, 3);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Int32x4Print(os);
+ CHECK_EQ("1, 2, 3, 4", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Uint32x4
+ {
+ uint32_t lanes[4] = {1, 2, 3, 4};
+
+ Handle<Uint32x4> value = factory->NewUint32x4(lanes);
+ CHECK(value->IsUint32x4());
+ CheckSimdValue<Uint32x4, uint32_t, 4>(*value, lanes, 3);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Uint32x4Print(os);
+ CHECK_EQ("1, 2, 3, 4", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Bool32x4
+ {
+ bool lanes[4] = {true, false, true, false};
+
+ Handle<Bool32x4> value = factory->NewBool32x4(lanes);
+ CHECK(value->IsBool32x4());
+ CheckSimdValue<Bool32x4, bool, 4>(*value, lanes, false);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Bool32x4Print(os);
+ CHECK_EQ("true, false, true, false", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Int16x8
+ {
+ int16_t lanes[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ Handle<Int16x8> value = factory->NewInt16x8(lanes);
+ CHECK(value->IsInt16x8());
+ CheckSimdValue<Int16x8, int16_t, 8>(*value, lanes, 32767);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Int16x8Print(os);
+ CHECK_EQ("1, 2, 3, 4, 5, 6, 7, 8", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Uint16x8
+ {
+ uint16_t lanes[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ Handle<Uint16x8> value = factory->NewUint16x8(lanes);
+ CHECK(value->IsUint16x8());
+ CheckSimdValue<Uint16x8, uint16_t, 8>(*value, lanes, 32767);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Uint16x8Print(os);
+ CHECK_EQ("1, 2, 3, 4, 5, 6, 7, 8", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Bool16x8
+ {
+ bool lanes[8] = {true, false, true, false, true, false, true, false};
+
+ Handle<Bool16x8> value = factory->NewBool16x8(lanes);
+ CHECK(value->IsBool16x8());
+ CheckSimdValue<Bool16x8, bool, 8>(*value, lanes, false);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Bool16x8Print(os);
+ CHECK_EQ("true, false, true, false, true, false, true, false", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Int8x16
+ {
+ int8_t lanes[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+ Handle<Int8x16> value = factory->NewInt8x16(lanes);
+ CHECK(value->IsInt8x16());
+ CheckSimdValue<Int8x16, int8_t, 16>(*value, lanes, 127);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Int8x16Print(os);
+ CHECK_EQ("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Uint8x16
+ {
+ uint8_t lanes[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+ Handle<Uint8x16> value = factory->NewUint8x16(lanes);
+ CHECK(value->IsUint8x16());
+ CheckSimdValue<Uint8x16, uint8_t, 16>(*value, lanes, 127);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Uint8x16Print(os);
+ CHECK_EQ("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16", os.str());
+#endif // OBJECT_PRINT
+ }
+ // Bool8x16
+ {
+ bool lanes[16] = {true, false, true, false, true, false, true, false,
+ true, false, true, false, true, false, true, false};
+
+ Handle<Bool8x16> value = factory->NewBool8x16(lanes);
+ CHECK(value->IsBool8x16());
+ CheckSimdValue<Bool8x16, bool, 16>(*value, lanes, false);
+
+#ifdef OBJECT_PRINT
+ std::ostringstream os;
+ value->Bool8x16Print(os);
+ CHECK_EQ(
+ "true, false, true, false, true, false, true, false, true, false, "
+ "true, false, true, false, true, false",
+ os.str());
+#endif // OBJECT_PRINT
+ }
+}
+
TEST(Tagging) {
CcTest::InitializeVM();
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/interpreter/bytecode_expectations/ForOf.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698