SSE2: 53% faster TransformColor[Inverse]

Changed the code (again) to process 4 pixels at a time. Loop is more
involved, but overall it's faster.

Removed the SSE4.1 implementation which is now slower than SSE2.

Change-Id: I7734e371033ad8929ace7f7e1373ba930d9bb5f1
This commit is contained in:
Pascal Massimino
2015-06-23 21:37:18 +02:00
parent 49073da6d6
commit fc6c75a2a2
3 changed files with 39 additions and 73 deletions

View File

@ -35,40 +35,6 @@ static void SubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixels) {
VP8LSubtractGreenFromBlueAndRed_C(argb_data + i, num_pixels - i);
}
//------------------------------------------------------------------------------
// Color Transform
static WEBP_INLINE void TransformColor(const VP8LMultipliers* const m,
uint32_t* argb_data, int num_pixels) {
// Shuffle constant to spread green and red to some *upper* byte locations.
const __m128i kCst_g0rg = _mm_set_epi8(5, -1, -1, -1, 6, -1, 5, -1,
1, -1, -1, -1, 2, -1, 1, -1);
// Shuffling constant to collect deltas from uint32 to uint8 locations.
const __m128i kCstShuffle = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1,
-1, 12, -1, 8, -1, 4, -1, 0);
// Used to collect the two parts of the delta (horizontal add) with madd.
const __m128i kCstAdd = _mm_set1_epi16(1);
// sign-extended multiplying constants, pre-shifted by 5.
#define CST(X) (((int16_t)(m->X << 8)) >> 5) // sign-extend
const __m128i mults = _mm_set_epi16(
CST(green_to_red_), 0, CST(red_to_blue_), CST(green_to_blue_),
CST(green_to_red_), 0, CST(red_to_blue_), CST(green_to_blue_));
#undef CST
int i;
for (i = 0; i + 2 <= num_pixels; i += 2) {
const __m128i in = _mm_loadl_epi64((__m128i*)&argb_data[i]); // argb
const __m128i A = _mm_shuffle_epi8(in, kCst_g0rg); // g | 0 | r | g
const __m128i B = _mm_mulhi_epi16(A, mults); // dr | 0 | db1 | db2
const __m128i C = _mm_madd_epi16(B, kCstAdd); // dr | 0 | db | 0
const __m128i D = _mm_shuffle_epi8(C, kCstShuffle); // 0 | dr | 0 | db
const __m128i out = _mm_sub_epi8(in, D);
_mm_storel_epi64((__m128i*)&argb_data[i], out);
}
// fallthrough and finish off with plain-C
VP8LTransformColor_C(m, argb_data + i, num_pixels - i);
}
//------------------------------------------------------------------------------
// Entry point
@ -76,7 +42,6 @@ extern void VP8LEncDspInitSSE41(void);
WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitSSE41(void) {
VP8LSubtractGreenFromBlueAndRed = SubtractGreenFromBlueAndRed;
VP8LTransformColor = TransformColor;
}
#else // !WEBP_USE_SSE41