OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 372 } |
373 for (int i = 0; i < 8; i++) { | 373 for (int i = 0; i < 8; i++) { |
374 CHECK_EQ(-i, t.i16x8_high[i]); | 374 CHECK_EQ(-i, t.i16x8_high[i]); |
375 } | 375 } |
376 for (int i = 0; i < 16; i++) { | 376 for (int i = 0; i < 16; i++) { |
377 CHECK_EQ(-i, t.i8x16_high[i]); | 377 CHECK_EQ(-i, t.i8x16_high[i]); |
378 } | 378 } |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
| 382 #define CHECK_EQ_32X4(field, v0, v1, v2, v3) \ |
| 383 CHECK_EQ(v0, t.field[0]); \ |
| 384 CHECK_EQ(v1, t.field[1]); \ |
| 385 CHECK_EQ(v2, t.field[2]); \ |
| 386 CHECK_EQ(v3, t.field[3]); |
| 387 |
| 388 TEST(Swizzle) { |
| 389 if (!CpuFeatures::IsSupported(NEON)) return; |
| 390 |
| 391 // Allocate an executable page of memory. |
| 392 size_t actual_size; |
| 393 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 394 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 395 CHECK(buffer); |
| 396 Isolate* isolate = CcTest::i_isolate(); |
| 397 HandleScope handles(isolate); |
| 398 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 399 v8::internal::CodeObjectRequired::kYes); |
| 400 MacroAssembler* masm = &assembler; // Create a pointer for the __ macro. |
| 401 |
| 402 typedef struct { |
| 403 int32_t _32x4_3210[4]; // identity |
| 404 int32_t _32x4_1032[4]; // high / low swap |
| 405 int32_t _32x4_0000[4]; // vdup's |
| 406 int32_t _32x4_1111[4]; |
| 407 int32_t _32x4_2222[4]; |
| 408 int32_t _32x4_3333[4]; |
| 409 int32_t _32x4_2103[4]; // rotate left |
| 410 int32_t _32x4_0321[4]; // rotate right |
| 411 int32_t _32x4_1132[4]; // irregular |
| 412 int32_t _32x4_1132_in_place[4]; // irregular, in-place |
| 413 } T; |
| 414 T t; |
| 415 |
| 416 __ stm(db_w, sp, r4.bit() | r5.bit() | r6.bit() | r7.bit() | lr.bit()); |
| 417 |
| 418 const Register kScratch = r5; |
| 419 |
| 420 // Make test vector [0, 1, 2, 3] |
| 421 __ veor(q1, q1, q1); // Zero |
| 422 for (int i = 0; i < 4; i++) { |
| 423 __ mov(r4, Operand(i)); |
| 424 __ ReplaceLane(q1, q1, r4, NeonS32, i); |
| 425 } |
| 426 __ Swizzle(q0, q1, kScratch, Neon32, 0x3210); |
| 427 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_3210)))); |
| 428 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 429 |
| 430 __ Swizzle(q0, q1, kScratch, Neon32, 0x1032); |
| 431 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_1032)))); |
| 432 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 433 |
| 434 __ Swizzle(q0, q1, kScratch, Neon32, 0x0000); |
| 435 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_0000)))); |
| 436 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 437 |
| 438 __ Swizzle(q0, q1, kScratch, Neon32, 0x1111); |
| 439 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_1111)))); |
| 440 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 441 |
| 442 __ Swizzle(q0, q1, kScratch, Neon32, 0x2222); |
| 443 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_2222)))); |
| 444 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 445 |
| 446 __ Swizzle(q0, q1, kScratch, Neon32, 0x3333); |
| 447 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_3333)))); |
| 448 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 449 |
| 450 __ Swizzle(q0, q1, kScratch, Neon32, 0x2103); |
| 451 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_2103)))); |
| 452 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 453 |
| 454 __ Swizzle(q0, q1, kScratch, Neon32, 0x0321); |
| 455 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_0321)))); |
| 456 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 457 |
| 458 __ Swizzle(q0, q1, kScratch, Neon32, 0x1132); |
| 459 __ add(r4, r0, Operand(static_cast<int32_t>(offsetof(T, _32x4_1132)))); |
| 460 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 461 |
| 462 __ vmov(q0, q1); |
| 463 __ Swizzle(q0, q0, kScratch, Neon32, 0x1132); |
| 464 __ add(r4, r0, |
| 465 Operand(static_cast<int32_t>(offsetof(T, _32x4_1132_in_place)))); |
| 466 __ vst1(Neon8, NeonListOperand(q0), NeonMemOperand(r4)); |
| 467 |
| 468 __ ldm(ia_w, sp, r4.bit() | r5.bit() | r6.bit() | r7.bit() | pc.bit()); |
| 469 |
| 470 CodeDesc desc; |
| 471 masm->GetCode(&desc); |
| 472 Handle<Code> code = isolate->factory()->NewCode( |
| 473 desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
| 474 #ifdef DEBUG |
| 475 OFStream os(stdout); |
| 476 code->Print(os); |
| 477 #endif |
| 478 F3 f = FUNCTION_CAST<F3>(code->entry()); |
| 479 Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); |
| 480 USE(dummy); |
| 481 CHECK_EQ_32X4(_32x4_3210, 0, 1, 2, 3); |
| 482 CHECK_EQ_32X4(_32x4_1032, 2, 3, 0, 1); |
| 483 CHECK_EQ_32X4(_32x4_0000, 0, 0, 0, 0); |
| 484 CHECK_EQ_32X4(_32x4_1111, 1, 1, 1, 1); |
| 485 CHECK_EQ_32X4(_32x4_2222, 2, 2, 2, 2); |
| 486 CHECK_EQ_32X4(_32x4_3333, 3, 3, 3, 3); |
| 487 CHECK_EQ_32X4(_32x4_2103, 3, 0, 1, 2); |
| 488 CHECK_EQ_32X4(_32x4_0321, 1, 2, 3, 0); |
| 489 CHECK_EQ_32X4(_32x4_1132, 2, 3, 1, 1); |
| 490 CHECK_EQ_32X4(_32x4_1132_in_place, 2, 3, 1, 1); |
| 491 } |
| 492 |
382 #undef __ | 493 #undef __ |
OLD | NEW |