Skip to content

Commit

Permalink
Fix and undeprecate _mm_sll_epi16
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Piolat committed Apr 28, 2024
1 parent 5bcf163 commit cb58965
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions source/inteli/emmintrin.d
Original file line number Diff line number Diff line change
Expand Up @@ -3861,12 +3861,11 @@ unittest
assert(B2.array == correct2);
}

// TODO: undeprecate
/// Shift packed 16-bit integers in `a` left by `count` while shifting in zeros.
/// Bit-shift is a single value in the low-order 64-bit of `count`.
/// If bit-shift > 15, result is defined to be all zeroes.
/// Warning: prefer `_mm_slli_epi16`, less of a trap.
deprecated("Use _mm_slli_epi16 instead.") __m128i _mm_sll_epi16 (__m128i a, __m128i count) pure @trusted
__m128i _mm_sll_epi16 (__m128i a, __m128i count) pure @trusted
{
static if (GDC_or_LDC_with_SSE2)
{
Expand All @@ -3876,14 +3875,31 @@ deprecated("Use _mm_slli_epi16 instead.") __m128i _mm_sll_epi16 (__m128i a, __m1
{
short8 sa = cast(short8)a;
long2 lc = cast(long2)count;
int bits = cast(int)(lc.array[0]);
ulong bits = cast(ulong)(lc.array[0]);
short8 r = void;
foreach(i; 0..8)
r.ptr[i] = cast(short)(cast(ushort)(sa.array[i]) << bits);
if (bits > 15)
r = short8(0);
return cast(int4)r;
}
}

unittest
{
__m128i shift0 = _mm_setzero_si128();
__m128i shiftX = _mm_set1_epi64x(0x8000_0000_0000_0000); // too large shift
__m128i shift2 = _mm_setr_epi32(2, 0, 4, 5);
__m128i A = _mm_setr_epi16(4, -8, 11, -32768, 4, -8, 11, -32768);
short[8] correct0 = (cast(short8)A).array;
short[8] correctX = [0, 0, 0, 0, 0, 0, 0, 0];
short[8] correct2 = [16, -32, 44, 0, 16, -32, 44, 0];
short8 B0 = cast(short8) _mm_sll_epi16(A, shift0);
short8 BX = cast(short8) _mm_sll_epi16(A, shiftX);
short8 B2 = cast(short8) _mm_sll_epi16(A, shift2);
assert(B0.array == correct0);
assert(BX.array == correctX);
assert(B2.array == correct2);
}

/// Shift packed 32-bit integers in `a` left by `imm8` while shifting in zeros.
__m128i _mm_slli_epi32 (__m128i a, int imm8) pure @trusted
Expand Down

0 comments on commit cb58965

Please sign in to comment.