mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Create constant width SAD versions for 8 and 16 pixels
This commit is contained in:
parent
a13fc51003
commit
d2db0086e1
|
@ -27,10 +27,65 @@
|
|||
#include "kvazaar.h"
|
||||
#include "strategyselector.h"
|
||||
|
||||
|
||||
uint32_t kvz_reg_sad_sse41(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
||||
const int32_t width, const int32_t height, const uint32_t stride1,
|
||||
static uint32_t reg_sad_w8(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
||||
const int32_t height, const uint32_t stride1,
|
||||
const uint32_t stride2)
|
||||
{
|
||||
__m128i sse_inc = _mm_setzero_si128();
|
||||
uint64_t result = 0;
|
||||
int32_t y;
|
||||
|
||||
const int32_t height_xmm_bytes = height & ~1;
|
||||
const int32_t height_parity = height & 1;
|
||||
|
||||
for (y = 0; y < height_xmm_bytes; y += 2) {
|
||||
__m128d a_d = _mm_setzero_pd();
|
||||
__m128d b_d = _mm_setzero_pd();
|
||||
|
||||
a_d = _mm_loadl_pd(a_d, (const double *)(data1 + (y + 0) * stride1));
|
||||
b_d = _mm_loadl_pd(b_d, (const double *)(data2 + (y + 0) * stride2));
|
||||
a_d = _mm_loadh_pd(a_d, (const double *)(data1 + (y + 1) * stride1));
|
||||
b_d = _mm_loadh_pd(b_d, (const double *)(data2 + (y + 1) * stride2));
|
||||
|
||||
__m128i a = _mm_castpd_si128(a_d);
|
||||
__m128i b = _mm_castpd_si128(b_d);
|
||||
|
||||
__m128i curr_sads = _mm_sad_epu8(a, b);
|
||||
sse_inc = _mm_add_epi64(sse_inc, curr_sads);
|
||||
}
|
||||
if (height_parity) {
|
||||
__m64 a = *(__m64 *)(data1 + y * stride1);
|
||||
__m64 b = *(__m64 *)(data2 + y * stride2);
|
||||
__m64 sads = _mm_sad_pu8(a, b);
|
||||
result = (uint64_t)sads;
|
||||
}
|
||||
__m128i sse_inc_2 = _mm_shuffle_epi32(sse_inc, _MM_SHUFFLE(1, 0, 3, 2));
|
||||
__m128i sad = _mm_add_epi64 (sse_inc, sse_inc_2);
|
||||
|
||||
result += _mm_cvtsi128_si32(sad);
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint32_t reg_sad_w16(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
||||
const int32_t height, const uint32_t stride1,
|
||||
const uint32_t stride2)
|
||||
{
|
||||
__m128i sse_inc = _mm_setzero_si128();
|
||||
int32_t y;
|
||||
for (y = 0; y < height; y++) {
|
||||
__m128i a = _mm_loadu_si128((__m128i const*) &data1[y * stride1]);
|
||||
__m128i b = _mm_loadu_si128((__m128i const*) &data2[y * stride2]);
|
||||
__m128i curr_sads = _mm_sad_epu8(a, b);
|
||||
sse_inc = _mm_add_epi64(sse_inc, curr_sads);
|
||||
}
|
||||
__m128i sse_inc_2 = _mm_shuffle_epi32(sse_inc, _MM_SHUFFLE(1, 0, 3, 2));
|
||||
__m128i sad = _mm_add_epi64 (sse_inc, sse_inc_2);
|
||||
return _mm_cvtsi128_si32(sad);
|
||||
}
|
||||
|
||||
static uint32_t reg_sad_arbitrary(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
||||
const int32_t width, const int32_t height, const uint32_t stride1,
|
||||
const uint32_t stride2)
|
||||
{
|
||||
int32_t y, x;
|
||||
__m128i sse_inc = _mm_setzero_si128();
|
||||
|
@ -67,6 +122,18 @@ uint32_t kvz_reg_sad_sse41(const kvz_pixel * const data1, const kvz_pixel * cons
|
|||
return _mm_cvtsi128_si32(sad);
|
||||
}
|
||||
|
||||
uint32_t kvz_reg_sad_sse41(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
||||
const int32_t width, const int32_t height, const uint32_t stride1,
|
||||
const uint32_t stride2)
|
||||
{
|
||||
if (width == 8)
|
||||
return reg_sad_w8(data1, data2, height, stride1, stride2);
|
||||
if (width == 16)
|
||||
return reg_sad_w16(data1, data2, height, stride1, stride2);
|
||||
else
|
||||
return reg_sad_arbitrary(data1, data2, width, height, stride1, stride2);
|
||||
}
|
||||
|
||||
#endif //COMPILE_INTEL_SSE41
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue