OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 CheckSmi(isolate, -42, "-42"); | 208 CheckSmi(isolate, -42, "-42"); |
209 | 209 |
210 // Check ToString for Numbers | 210 // Check ToString for Numbers |
211 CheckNumber(isolate, 1.1, "1.1"); | 211 CheckNumber(isolate, 1.1, "1.1"); |
212 | 212 |
213 CheckFindCodeObject(isolate); | 213 CheckFindCodeObject(isolate); |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 template <typename T, typename LANE_TYPE, int LANES> | 217 template <typename T, typename LANE_TYPE, int LANES> |
218 static void CheckSimdLanes(T* value) { | 218 static void CheckSimdValue(T* value, LANE_TYPE lane_values[LANES], |
219 // Get the original values, and check that all lanes can be set to new values | 219 LANE_TYPE other_value) { |
220 // without disturbing the other lanes. | 220 // Check against lane_values, and check that all lanes can be set to |
221 LANE_TYPE lane_values[LANES]; | 221 // other_value without disturbing the other lanes. |
222 for (int i = 0; i < LANES; i++) { | 222 for (int i = 0; i < LANES; i++) { |
223 lane_values[i] = value->get_lane(i); | 223 CHECK_EQ(lane_values[i], value->get_lane(i)); |
224 } | 224 } |
225 for (int i = 0; i < LANES; i++) { | 225 for (int i = 0; i < LANES; i++) { |
226 lane_values[i] += 1; | 226 value->set_lane(i, other_value); // change the value |
227 value->set_lane(i, lane_values[i]); | |
228 for (int j = 0; j < LANES; j++) { | 227 for (int j = 0; j < LANES; j++) { |
229 CHECK_EQ(lane_values[j], value->get_lane(j)); | 228 if (i != j) |
| 229 CHECK_EQ(lane_values[j], value->get_lane(j)); |
| 230 else |
| 231 CHECK_EQ(other_value, value->get_lane(j)); |
230 } | 232 } |
| 233 value->set_lane(i, lane_values[i]); // restore the lane |
231 } | 234 } |
| 235 CHECK(value->BooleanValue()); // SIMD values are 'true'. |
232 } | 236 } |
233 | 237 |
234 | 238 |
235 TEST(SimdObjects) { | 239 TEST(SimdObjects) { |
236 CcTest::InitializeVM(); | 240 CcTest::InitializeVM(); |
237 Isolate* isolate = CcTest::i_isolate(); | 241 Isolate* isolate = CcTest::i_isolate(); |
238 Factory* factory = isolate->factory(); | 242 Factory* factory = isolate->factory(); |
239 | 243 |
240 HandleScope sc(isolate); | 244 HandleScope sc(isolate); |
241 | 245 |
242 Handle<Float32x4> value = factory->NewFloat32x4(1, 2, 3, 4); | 246 // Float32x4 |
243 CHECK(value->IsFloat32x4()); | 247 { |
244 CHECK(value->BooleanValue()); // SIMD values map to true. | 248 float lanes[4] = {1, 2, 3, 4}; |
245 CHECK_EQ(value->get_lane(0), 1); | 249 float quiet_NaN = std::numeric_limits<float>::quiet_NaN(); |
246 CHECK_EQ(value->get_lane(1), 2); | 250 float signaling_NaN = std::numeric_limits<float>::signaling_NaN(); |
247 CHECK_EQ(value->get_lane(2), 3); | |
248 CHECK_EQ(value->get_lane(3), 4); | |
249 | 251 |
250 CheckSimdLanes<Float32x4, float, 4>(*value); | 252 Handle<Float32x4> value = factory->NewFloat32x4(lanes); |
| 253 CHECK(value->IsFloat32x4()); |
| 254 CheckSimdValue<Float32x4, float, 4>(*value, lanes, 3.14f); |
251 | 255 |
252 // Check all lanes, and special lane values. | 256 // Check special lane values. |
253 value->set_lane(0, 0); | 257 value->set_lane(1, -0.0); |
254 CHECK_EQ(0, value->get_lane(0)); | 258 CHECK_EQ(-0.0, value->get_lane(1)); |
255 value->set_lane(1, -0.0); | 259 CHECK(std::signbit(value->get_lane(1))); // Sign bit should be preserved. |
256 CHECK_EQ(-0.0, value->get_lane(1)); | 260 value->set_lane(2, quiet_NaN); |
257 CHECK(std::signbit(value->get_lane(1))); // Sign bit is preserved. | 261 CHECK(std::isnan(value->get_lane(2))); |
258 float quiet_NaN = std::numeric_limits<float>::quiet_NaN(); | 262 value->set_lane(3, signaling_NaN); |
259 float signaling_NaN = std::numeric_limits<float>::signaling_NaN(); | 263 CHECK(std::isnan(value->get_lane(3))); |
260 value->set_lane(2, quiet_NaN); | |
261 CHECK(std::isnan(value->get_lane(2))); | |
262 value->set_lane(3, signaling_NaN); | |
263 CHECK(std::isnan(value->get_lane(3))); | |
264 | 264 |
265 // Check SIMD value printing. | 265 #ifdef OBJECT_PRINT |
| 266 // Check value printing. |
| 267 { |
| 268 value = factory->NewFloat32x4(lanes); |
| 269 std::ostringstream os; |
| 270 value->Float32x4Print(os); |
| 271 CHECK_EQ("1, 2, 3, 4", os.str()); |
| 272 } |
| 273 { |
| 274 float special_lanes[4] = {0, -0.0, quiet_NaN, signaling_NaN}; |
| 275 value = factory->NewFloat32x4(special_lanes); |
| 276 std::ostringstream os; |
| 277 value->Float32x4Print(os); |
| 278 // Value printing doesn't preserve signed zeroes. |
| 279 CHECK_EQ("0, 0, NaN, NaN", os.str()); |
| 280 } |
| 281 #endif // OBJECT_PRINT |
| 282 } |
| 283 // Int32x4 |
266 { | 284 { |
267 value = factory->NewFloat32x4(1, 2, 3, 4); | 285 int32_t lanes[4] = {-1, 0, 1, 2}; |
| 286 |
| 287 Handle<Int32x4> value = factory->NewInt32x4(lanes); |
| 288 CHECK(value->IsInt32x4()); |
| 289 CheckSimdValue<Int32x4, int32_t, 4>(*value, lanes, 3); |
| 290 |
| 291 #ifdef OBJECT_PRINT |
268 std::ostringstream os; | 292 std::ostringstream os; |
269 value->Float32x4Print(os); | 293 value->Int32x4Print(os); |
270 CHECK_EQ("1, 2, 3, 4", os.str()); | 294 CHECK_EQ("-1, 0, 1, 2", os.str()); |
| 295 #endif // OBJECT_PRINT |
271 } | 296 } |
| 297 // Bool32x4 |
272 { | 298 { |
273 value = factory->NewFloat32x4(0, -0.0, quiet_NaN, signaling_NaN); | 299 bool lanes[4] = {true, true, true, false}; |
| 300 |
| 301 Handle<Bool32x4> value = factory->NewBool32x4(lanes); |
| 302 CHECK(value->IsBool32x4()); |
| 303 CheckSimdValue<Bool32x4, bool, 4>(*value, lanes, false); |
| 304 |
| 305 #ifdef OBJECT_PRINT |
274 std::ostringstream os; | 306 std::ostringstream os; |
275 value->Float32x4Print(os); | 307 value->Bool32x4Print(os); |
276 // Value printing doesn't preserve signed zeroes. | 308 CHECK_EQ("true, true, true, false", os.str()); |
277 CHECK_EQ("0, 0, NaN, NaN", os.str()); | 309 #endif // OBJECT_PRINT |
| 310 } |
| 311 // Int16x8 |
| 312 { |
| 313 int16_t lanes[8] = {-1, 0, 1, 2, 3, 4, 5, -32768}; |
| 314 |
| 315 Handle<Int16x8> value = factory->NewInt16x8(lanes); |
| 316 CHECK(value->IsInt16x8()); |
| 317 CheckSimdValue<Int16x8, int16_t, 8>(*value, lanes, 32767); |
| 318 |
| 319 #ifdef OBJECT_PRINT |
| 320 std::ostringstream os; |
| 321 value->Int16x8Print(os); |
| 322 CHECK_EQ("-1, 0, 1, 2, 3, 4, 5, -32768", os.str()); |
| 323 #endif // OBJECT_PRINT |
| 324 } |
| 325 // Bool16x8 |
| 326 { |
| 327 bool lanes[8] = {true, true, true, true, true, true, true, false}; |
| 328 |
| 329 Handle<Bool16x8> value = factory->NewBool16x8(lanes); |
| 330 CHECK(value->IsBool16x8()); |
| 331 CheckSimdValue<Bool16x8, bool, 8>(*value, lanes, false); |
| 332 |
| 333 #ifdef OBJECT_PRINT |
| 334 std::ostringstream os; |
| 335 value->Bool16x8Print(os); |
| 336 CHECK_EQ("true, true, true, true, true, true, true, false", os.str()); |
| 337 #endif // OBJECT_PRINT |
| 338 } |
| 339 // Int8x16 |
| 340 { |
| 341 int8_t lanes[16] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -128}; |
| 342 |
| 343 Handle<Int8x16> value = factory->NewInt8x16(lanes); |
| 344 CHECK(value->IsInt8x16()); |
| 345 CheckSimdValue<Int8x16, int8_t, 16>(*value, lanes, 127); |
| 346 |
| 347 #ifdef OBJECT_PRINT |
| 348 std::ostringstream os; |
| 349 value->Int8x16Print(os); |
| 350 CHECK_EQ("-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -128", |
| 351 os.str()); |
| 352 #endif // OBJECT_PRINT |
| 353 } |
| 354 // Bool8x16 |
| 355 { |
| 356 bool lanes[16] = {true, true, true, true, true, true, true, false, |
| 357 true, true, true, true, true, true, true, false}; |
| 358 |
| 359 Handle<Bool8x16> value = factory->NewBool8x16(lanes); |
| 360 CHECK(value->IsBool8x16()); |
| 361 CheckSimdValue<Bool8x16, bool, 16>(*value, lanes, false); |
| 362 |
| 363 #ifdef OBJECT_PRINT |
| 364 std::ostringstream os; |
| 365 value->Bool8x16Print(os); |
| 366 CHECK_EQ( |
| 367 "true, true, true, true, true, true, true, false, true, true, true, " |
| 368 "true, true, true, true, false", |
| 369 os.str()); |
| 370 #endif // OBJECT_PRINT |
278 } | 371 } |
279 } | 372 } |
280 | 373 |
281 | 374 |
282 TEST(Tagging) { | 375 TEST(Tagging) { |
283 CcTest::InitializeVM(); | 376 CcTest::InitializeVM(); |
284 int request = 24; | 377 int request = 24; |
285 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); | 378 CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request))); |
286 CHECK(Smi::FromInt(42)->IsSmi()); | 379 CHECK(Smi::FromInt(42)->IsSmi()); |
287 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); | 380 CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); |
(...skipping 5825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6113 array->address(), | 6206 array->address(), |
6114 array->address() + array->Size()); | 6207 array->address() + array->Size()); |
6115 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == | 6208 CHECK(reinterpret_cast<void*>(buffer->Get(1)) == |
6116 HeapObject::RawField(heap->empty_fixed_array(), | 6209 HeapObject::RawField(heap->empty_fixed_array(), |
6117 FixedArrayBase::kLengthOffset)); | 6210 FixedArrayBase::kLengthOffset)); |
6118 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == | 6211 CHECK(reinterpret_cast<void*>(buffer->Get(2)) == |
6119 HeapObject::RawField(heap->empty_fixed_array(), | 6212 HeapObject::RawField(heap->empty_fixed_array(), |
6120 FixedArrayBase::kLengthOffset)); | 6213 FixedArrayBase::kLengthOffset)); |
6121 delete buffer; | 6214 delete buffer; |
6122 } | 6215 } |
OLD | NEW |