1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include <xmmintrin.h>
13
14 #include "config/aom_config.h"
15 #include "aom/aom_integer.h"
16 #include "aom_dsp/aom_dsp_common.h"
17
18 // Load 8 16 bit values. If the source is 32 bits then pack down with
19 // saturation.
load_tran_low(const tran_low_t * a)20 static inline __m128i load_tran_low(const tran_low_t *a) {
21 const __m128i a_low = _mm_load_si128((const __m128i *)a);
22 return _mm_packs_epi32(a_low, *(const __m128i *)(a + 4));
23 }
24
unpack_trans(__m128i a,__m128i * a_1,__m128i * a_2)25 static inline void unpack_trans(__m128i a, __m128i *a_1, __m128i *a_2) {
26 const __m128i one = _mm_set1_epi16(1);
27 const __m128i a_hi = _mm_mulhi_epi16(a, one);
28 const __m128i a_lo = _mm_mullo_epi16(a, one);
29 *a_1 = _mm_unpacklo_epi16(a_lo, a_hi);
30 *a_2 = _mm_unpackhi_epi16(a_lo, a_hi);
31 }
32
33 // Store 8 16 bit values. If the destination is 32 bits then sign extend the
34 // values by multiplying by 1.
store_tran_low(__m128i a,tran_low_t * b)35 static inline void store_tran_low(__m128i a, tran_low_t *b) {
36 __m128i a_1, a_2;
37 unpack_trans(a, &a_1, &a_2);
38 _mm_store_si128((__m128i *)(b), a_1);
39 _mm_store_si128((__m128i *)(b + 4), a_2);
40 }
41 // Stores the second result at an offset of 8 (instead of 4) to match the output
42 // with that of AVX2 implementation and the function is similar to
43 // store_tran_low().
store_tran_low_offset_4(__m128i a,tran_low_t * b)44 static inline void store_tran_low_offset_4(__m128i a, tran_low_t *b) {
45 __m128i a_1, a_2;
46 unpack_trans(a, &a_1, &a_2);
47 _mm_store_si128((__m128i *)(b), a_1);
48 _mm_store_si128((__m128i *)(b + 8), a_2);
49 }
50