@@ -6099,10 +6099,10 @@ void testVectorSwizzleBinaryOnlyOneSideSide1Scattered()
60996099 runBinarySwizzleAndCheck (pattern, a, b);
61006100}
61016101
6102- // Test VectorShr(VectorZip{Lower,Higher}(x, x), 8) → VectorExtend{Low,High}(x, i16x8, Signed)
6102+ // Test VectorShr(VectorZip{Lower,Higher}(x, x), 8) -> VectorExtend{Low,High}(x, i16x8, Signed)
61036103void testVectorShrZipToExtend ()
61046104{
6105- // Test ExtendLow: VectorShr(VectorZipLower(x, x), 8) → VectorExtendLow(x, i16x8, Signed)
6105+ // Test ExtendLow: VectorShr(VectorZipLower(x, x), 8) -> VectorExtendLow(x, i16x8, Signed)
61066106 {
61076107 alignas (16 ) v128_t vectors[2 ];
61086108 Procedure proc;
@@ -6125,14 +6125,14 @@ void testVectorShrZipToExtend()
61256125 auto code = compileProc (proc);
61266126
61276127 // Input i8x16: {-5, 127, -128, 0, 1, -1, 42, -42, 99, 100, 101, 102, 103, 104, 105, 106}
6128- vectors[0 ].u8x16 [0 ] = static_cast <uint8_t >(-5 ); // 0xFB → sign-extend to 0xFFFB = -5
6129- vectors[0 ].u8x16 [1 ] = 127 ; // 0x7F → 0x007F = 127
6130- vectors[0 ].u8x16 [2 ] = static_cast <uint8_t >(-128 ); // 0x80 → 0xFF80 = -128
6131- vectors[0 ].u8x16 [3 ] = 0 ; // 0x00 → 0x0000 = 0
6132- vectors[0 ].u8x16 [4 ] = 1 ; // 0x01 → 0x0001 = 1
6133- vectors[0 ].u8x16 [5 ] = static_cast <uint8_t >(-1 ); // 0xFF → 0xFFFF = -1
6134- vectors[0 ].u8x16 [6 ] = 42 ; // 0x2A → 0x002A = 42
6135- vectors[0 ].u8x16 [7 ] = static_cast <uint8_t >(-42 ); // 0xD6 → 0xFFD6 = -42
6128+ vectors[0 ].u8x16 [0 ] = static_cast <uint8_t >(-5 ); // 0xFB -> sign-extend to 0xFFFB = -5
6129+ vectors[0 ].u8x16 [1 ] = 127 ; // 0x7F -> 0x007F = 127
6130+ vectors[0 ].u8x16 [2 ] = static_cast <uint8_t >(-128 ); // 0x80 -> 0xFF80 = -128
6131+ vectors[0 ].u8x16 [3 ] = 0 ; // 0x00 -> 0x0000 = 0
6132+ vectors[0 ].u8x16 [4 ] = 1 ; // 0x01 -> 0x0001 = 1
6133+ vectors[0 ].u8x16 [5 ] = static_cast <uint8_t >(-1 ); // 0xFF -> 0xFFFF = -1
6134+ vectors[0 ].u8x16 [6 ] = 42 ; // 0x2A -> 0x002A = 42
6135+ vectors[0 ].u8x16 [7 ] = static_cast <uint8_t >(-42 ); // 0xD6 -> 0xFFD6 = -42
61366136 // Upper 8 bytes (not used by ExtendLow, but fill them)
61376137 for (unsigned i = 8 ; i < 16 ; ++i)
61386138 vectors[0 ].u8x16 [i] = 99 + (i - 8 );
@@ -6150,7 +6150,7 @@ void testVectorShrZipToExtend()
61506150 CHECK (vectors[1 ].u16x8 [7 ] == static_cast <uint16_t >(-42 ));
61516151 }
61526152
6153- // Test ExtendHigh: VectorShr(VectorZipHigher(x, x), 8) → VectorExtendHigh(x, i16x8, Signed)
6153+ // Test ExtendHigh: VectorShr(VectorZipHigher(x, x), 8) -> VectorExtendHigh(x, i16x8, Signed)
61546154 {
61556155 alignas (16 ) v128_t vectors[2 ];
61566156 Procedure proc;
@@ -6175,14 +6175,14 @@ void testVectorShrZipToExtend()
61756175 // Input: lower 8 bytes don't matter for ExtendHigh, upper 8 bytes are tested
61766176 for (unsigned i = 0 ; i < 8 ; ++i)
61776177 vectors[0 ].u8x16 [i] = 0 ;
6178- vectors[0 ].u8x16 [8 ] = static_cast <uint8_t >(-10 ); // 0xF6 → -10
6179- vectors[0 ].u8x16 [9 ] = 50 ; // 0x32 → 50
6180- vectors[0 ].u8x16 [10 ] = static_cast <uint8_t >(-128 ); // 0x80 → -128
6181- vectors[0 ].u8x16 [11 ] = 127 ; // 0x7F → 127
6182- vectors[0 ].u8x16 [12 ] = 0 ; // 0x00 → 0
6183- vectors[0 ].u8x16 [13 ] = static_cast <uint8_t >(-1 ); // 0xFF → -1
6184- vectors[0 ].u8x16 [14 ] = 1 ; // 0x01 → 1
6185- vectors[0 ].u8x16 [15 ] = static_cast <uint8_t >(-100 ); // 0x9C → -100
6178+ vectors[0 ].u8x16 [8 ] = static_cast <uint8_t >(-10 ); // 0xF6 -> -10
6179+ vectors[0 ].u8x16 [9 ] = 50 ; // 0x32 -> 50
6180+ vectors[0 ].u8x16 [10 ] = static_cast <uint8_t >(-128 ); // 0x80 -> -128
6181+ vectors[0 ].u8x16 [11 ] = 127 ; // 0x7F -> 127
6182+ vectors[0 ].u8x16 [12 ] = 0 ; // 0x00 -> 0
6183+ vectors[0 ].u8x16 [13 ] = static_cast <uint8_t >(-1 ); // 0xFF -> -1
6184+ vectors[0 ].u8x16 [14 ] = 1 ; // 0x01 -> 1
6185+ vectors[0 ].u8x16 [15 ] = static_cast <uint8_t >(-100 ); // 0x9C -> -100
61866186
61876187 invoke<void >(*code, vectors);
61886188
@@ -6358,6 +6358,74 @@ void testVectorShrZipToExtendI64()
63586358 }
63596359}
63606360
6361+ // VectorShr(VectorZip{Lower,Higher}(x, x), shift) is a sign extension only when the zip lane is
6362+ // exactly half the width of the shift lane.
6363+ void testVectorShrZipWithMismatchedLane ()
6364+ {
6365+ auto runOne = [](B3 ::Opcode zipOp, SIMDLane zipLane, SIMDLane shrLane, int32_t shiftAmount) {
6366+ alignas (16 ) v128_t vectors[2 ];
6367+ Procedure proc;
6368+ BasicBlock* root = proc.addBlock ();
6369+ auto arguments = cCallArgumentValues<void *>(proc, root);
6370+ Value* address = arguments[0 ];
6371+ Value* input = root->appendNew <MemoryValue>(proc, Load, V128 , Origin (), address);
6372+ Value* zipped = root->appendNew <SIMDValue>(proc, Origin (), zipOp, B3 ::V128 , zipLane, SIMDSignMode::None, input, input);
6373+ Value* shifted = root->appendNew <SIMDValue>(proc, Origin (), VectorShr, B3 ::V128 , shrLane, SIMDSignMode::Signed, zipped, root->appendNew <Const32Value>(proc, Origin (), shiftAmount));
6374+ root->appendNew <MemoryValue>(proc, Store, Origin (), shifted, address, static_cast <int32_t >(sizeof (v128_t )));
6375+ root->appendNew <Value>(proc, Return, Origin ());
6376+
6377+ auto code = compileProc (proc);
6378+
6379+ for (unsigned i = 0 ; i < 16 ; ++i)
6380+ vectors[0 ].u8x16 [i] = static_cast <uint8_t >(i * 0x37 + 0x91 );
6381+ v128_t source = vectors[0 ];
6382+
6383+ unsigned zipBytes = elementByteSize (zipLane);
6384+ unsigned halfCount = 16 / zipBytes / 2 ;
6385+ unsigned base = zipOp == VectorZipLower ? 0 : halfCount;
6386+ v128_t zippedExpected;
6387+ for (unsigned i = 0 ; i < halfCount; ++i) {
6388+ for (unsigned j = 0 ; j < 2 ; ++j)
6389+ memcpySpan (std::span { zippedExpected.u8x16 }.subspan ((2 * i + j) * zipBytes, zipBytes), std::span { source.u8x16 }.subspan ((base + i) * zipBytes, zipBytes));
6390+ }
6391+
6392+ invoke<void >(*code, vectors);
6393+
6394+ unsigned shrBytes = elementByteSize (shrLane);
6395+ for (unsigned lane = 0 ; lane < 16 / shrBytes; ++lane) {
6396+ int64_t element = 0 ;
6397+ for (unsigned byte = shrBytes; byte--;)
6398+ element = (element << 8 ) | zippedExpected.u8x16 [lane * shrBytes + byte];
6399+ unsigned unusedBits = 64 - shrBytes * 8 ;
6400+ int64_t expected = (static_cast <int64_t >(static_cast <uint64_t >(element) << unusedBits) >> unusedBits) >> shiftAmount;
6401+ uint64_t actual = 0 ;
6402+ for (unsigned byte = shrBytes; byte--;)
6403+ actual = (actual << 8 ) | vectors[1 ].u8x16 [lane * shrBytes + byte];
6404+ uint64_t mask = shrBytes == 8 ? std::numeric_limits<uint64_t >::max () : (1ULL << (shrBytes * 8 )) - 1 ;
6405+ CHECK_EQ (actual, static_cast <uint64_t >(expected) & mask);
6406+ }
6407+ };
6408+
6409+ struct ShrCase {
6410+ SIMDLane shrLane;
6411+ int32_t shiftAmount;
6412+ SIMDLane matchingZipLane;
6413+ };
6414+ constexpr ShrCase shrCases[] = {
6415+ { SIMDLane::i16x8, 8 , SIMDLane::i8x16 },
6416+ { SIMDLane::i32x4, 16 , SIMDLane::i16x8 },
6417+ { SIMDLane::i64x2, 32 , SIMDLane::i32x4 },
6418+ };
6419+ for (auto shrCase : shrCases) {
6420+ for (SIMDLane zipLane : { SIMDLane::i8x16, SIMDLane::i16x8, SIMDLane::i32x4 }) {
6421+ if (zipLane == shrCase.matchingZipLane )
6422+ continue ;
6423+ for (B3 ::Opcode zipOp : { VectorZipLower, VectorZipHigher })
6424+ runOne (zipOp, zipLane, shrCase.shrLane , shrCase.shiftAmount );
6425+ }
6426+ }
6427+ }
6428+
63616429#endif // ENABLE(B3_JIT)
63626430
63636431WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
0 commit comments