2014-04-28 12:20:49 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-04-28 12:20:49 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-04-28 12:20:49 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
2014-04-28 12:20:49 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-28 12:20:49 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* \file
|
|
|
|
*/
|
2014-07-11 14:16:32 +00:00
|
|
|
#include "picture-sse2.h"
|
2014-06-13 07:20:02 +00:00
|
|
|
#include "strategyselector.h"
|
2014-07-11 14:16:32 +00:00
|
|
|
|
|
|
|
#if COMPILE_INTEL_SSE2
|
|
|
|
# include "image.h"
|
|
|
|
# include <immintrin.h>
|
|
|
|
# include <assert.h>
|
2014-07-14 10:14:17 +00:00
|
|
|
# include <stdlib.h>
|
2014-07-11 14:16:32 +00:00
|
|
|
|
2014-04-28 12:20:49 +00:00
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
static unsigned reg_sad_sse2(const kvz_pixel * const data1, const kvz_pixel * const data2,
|
2014-04-28 12:20:49 +00:00
|
|
|
const int width, const int height, const unsigned stride1, const unsigned stride2)
|
|
|
|
{
|
|
|
|
int y, x;
|
|
|
|
unsigned sad = 0;
|
|
|
|
__m128i sse_inc = _mm_setzero_si128 ();
|
|
|
|
long long int sse_inc_array[2];
|
|
|
|
|
|
|
|
for (y = 0; y < height; ++y) {
|
|
|
|
for (x = 0; x <= width-16; x+=16) {
|
|
|
|
const __m128i a = _mm_loadu_si128((__m128i const*) &data1[y * stride1 + x]);
|
|
|
|
const __m128i b = _mm_loadu_si128((__m128i const*) &data2[y * stride2 + x]);
|
|
|
|
sse_inc = _mm_add_epi32(sse_inc, _mm_sad_epu8(a,b));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; x < width; ++x) {
|
|
|
|
sad += abs(data1[y * stride1 + x] - data2[y * stride2 + x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_mm_storeu_si128((__m128i*) sse_inc_array, sse_inc);
|
|
|
|
sad += sse_inc_array[0] + sse_inc_array[1];
|
|
|
|
|
|
|
|
return sad;
|
|
|
|
}
|
2014-04-29 08:14:42 +00:00
|
|
|
|
2015-06-30 08:43:48 +00:00
|
|
|
static unsigned sad_8bit_4x4_sse2(const kvz_pixel *buf1, const kvz_pixel *buf2)
|
2014-07-18 14:53:01 +00:00
|
|
|
{
|
|
|
|
const __m128i *const mbuf1 = (const __m128i *)buf1;
|
|
|
|
const __m128i *const mbuf2 = (const __m128i *)buf2;
|
|
|
|
|
|
|
|
__m128i sum = _mm_sad_epu8(_mm_load_si128(mbuf1), _mm_load_si128(mbuf2));
|
|
|
|
|
|
|
|
uint32_t result[4];
|
|
|
|
_mm_storeu_si128((__m128i*)result, sum);
|
|
|
|
return result[0] + result[2];
|
|
|
|
}
|
|
|
|
|
2014-07-11 14:16:32 +00:00
|
|
|
#endif //COMPILE_INTEL_SSE2
|
|
|
|
|
2015-08-12 09:28:55 +00:00
|
|
|
int strategy_register_picture_sse2(void* opaque, uint8_t bitdepth) {
|
2014-07-11 14:16:32 +00:00
|
|
|
bool success = true;
|
|
|
|
#if COMPILE_INTEL_SSE2
|
2015-08-12 09:28:55 +00:00
|
|
|
if (bitdepth == 8){
|
|
|
|
success &= strategyselector_register(opaque, "reg_sad", "sse2", 10, ®_sad_sse2);
|
|
|
|
success &= strategyselector_register(opaque, "sad_4x4", "sse2", 10, &sad_8bit_4x4_sse2);
|
|
|
|
}
|
2014-07-11 14:16:32 +00:00
|
|
|
#endif
|
|
|
|
return success;
|
2014-04-29 08:14:42 +00:00
|
|
|
}
|
2014-07-11 14:16:32 +00:00
|
|
|
|
|
|
|
|