1 /*
2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef VPX_DSP_X86_HIGHBD_INV_TXFM_SSE2_H_
12 #define VPX_DSP_X86_HIGHBD_INV_TXFM_SSE2_H_
13
14 #include <emmintrin.h> // SSE2
15 #include "./vpx_config.h"
16 #include "vpx/vpx_integer.h"
17 #include "vpx_dsp/inv_txfm.h"
18 #include "vpx_dsp/x86/txfm_common_sse2.h"
19
add_dc_clamp(const __m128i * const min,const __m128i * const max,const __m128i * const dc,const __m128i * const in)20 static INLINE __m128i add_dc_clamp(const __m128i *const min,
21 const __m128i *const max,
22 const __m128i *const dc,
23 const __m128i *const in) {
24 __m128i out;
25 out = _mm_adds_epi16(*in, *dc);
26 out = _mm_max_epi16(out, *min);
27 out = _mm_min_epi16(out, *max);
28 return out;
29 }
30
highbd_idct_1_add_kernel(const tran_low_t * input,uint16_t * dest,int stride,int bd,const int size)31 static INLINE void highbd_idct_1_add_kernel(const tran_low_t *input,
32 uint16_t *dest, int stride, int bd,
33 const int size) {
34 const __m128i zero = _mm_setzero_si128();
35 // Faster than _mm_set1_epi16((1 << bd) - 1).
36 const __m128i one = _mm_set1_epi16(1);
37 const __m128i max = _mm_sub_epi16(_mm_slli_epi16(one, bd), one);
38 int a1, i, j;
39 tran_low_t out;
40 __m128i dc, d;
41
42 out = HIGHBD_WRAPLOW(dct_const_round_shift(input[0] * cospi_16_64), bd);
43 out = HIGHBD_WRAPLOW(dct_const_round_shift(out * cospi_16_64), bd);
44 a1 = ROUND_POWER_OF_TWO(out, (size == 8) ? 5 : 6);
45 dc = _mm_set1_epi16(a1);
46
47 for (i = 0; i < size; ++i) {
48 for (j = 0; j < (size >> 3); ++j) {
49 d = _mm_load_si128((const __m128i *)(&dest[j * 8]));
50 d = add_dc_clamp(&zero, &max, &dc, &d);
51 _mm_store_si128((__m128i *)(&dest[j * 8]), d);
52 }
53 dest += stride;
54 }
55 }
56
clamp_high_sse2(__m128i value,int bd)57 static INLINE __m128i clamp_high_sse2(__m128i value, int bd) {
58 __m128i ubounded, retval;
59 const __m128i zero = _mm_set1_epi16(0);
60 const __m128i one = _mm_set1_epi16(1);
61 const __m128i max = _mm_sub_epi16(_mm_slli_epi16(one, bd), one);
62 ubounded = _mm_cmpgt_epi16(value, max);
63 retval = _mm_andnot_si128(ubounded, value);
64 ubounded = _mm_and_si128(ubounded, max);
65 retval = _mm_or_si128(retval, ubounded);
66 retval = _mm_and_si128(retval, _mm_cmpgt_epi16(retval, zero));
67 return retval;
68 }
69
70 #endif // VPX_DSP_X86_HIGHBD_INV_TXFM_SSE2_H_
71