idct_intrin_sse2.c 5.27 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12
13
14
#include "aom_dsp/x86/inv_txfm_sse2.h"
#include "aom_dsp/x86/txfm_common_sse2.h"
#include "aom_ports/mem.h"
Jingning Han's avatar
Jingning Han committed
15

16
void av1_iht4x4_16_add_sse2(const tran_low_t *input, uint8_t *dest, int stride,
clang-format's avatar
clang-format committed
17
                            int tx_type) {
Jingning Han's avatar
Jingning Han committed
18
19
20
21
  __m128i in[2];
  const __m128i zero = _mm_setzero_si128();
  const __m128i eight = _mm_set1_epi16(8);

22
23
  in[0] = load_input_data(input);
  in[1] = load_input_data(input + 8);
Jingning Han's avatar
Jingning Han committed
24
25
26

  switch (tx_type) {
    case 0:  // DCT_DCT
Luca Barbato's avatar
Luca Barbato committed
27
28
      aom_idct4_sse2(in);
      aom_idct4_sse2(in);
Jingning Han's avatar
Jingning Han committed
29
30
      break;
    case 1:  // ADST_DCT
Luca Barbato's avatar
Luca Barbato committed
31
32
      aom_idct4_sse2(in);
      aom_iadst4_sse2(in);
Jingning Han's avatar
Jingning Han committed
33
34
      break;
    case 2:  // DCT_ADST
Luca Barbato's avatar
Luca Barbato committed
35
36
      aom_iadst4_sse2(in);
      aom_idct4_sse2(in);
Jingning Han's avatar
Jingning Han committed
37
38
      break;
    case 3:  // ADST_ADST
Luca Barbato's avatar
Luca Barbato committed
39
40
      aom_iadst4_sse2(in);
      aom_iadst4_sse2(in);
Jingning Han's avatar
Jingning Han committed
41
      break;
clang-format's avatar
clang-format committed
42
    default: assert(0); break;
Jingning Han's avatar
Jingning Han committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  }

  // Final round and shift
  in[0] = _mm_add_epi16(in[0], eight);
  in[1] = _mm_add_epi16(in[1], eight);

  in[0] = _mm_srai_epi16(in[0], 4);
  in[1] = _mm_srai_epi16(in[1], 4);

  // Reconstruction and Store
  {
    __m128i d0 = _mm_cvtsi32_si128(*(const int *)(dest));
    __m128i d2 = _mm_cvtsi32_si128(*(const int *)(dest + stride * 2));
    d0 = _mm_unpacklo_epi32(d0,
                            _mm_cvtsi32_si128(*(const int *)(dest + stride)));
    d2 = _mm_unpacklo_epi32(
        d2, _mm_cvtsi32_si128(*(const int *)(dest + stride * 3)));
    d0 = _mm_unpacklo_epi8(d0, zero);
    d2 = _mm_unpacklo_epi8(d2, zero);
    d0 = _mm_add_epi16(d0, in[0]);
    d2 = _mm_add_epi16(d2, in[1]);
    d0 = _mm_packus_epi16(d0, d2);
    // store result[0]
    *(int *)dest = _mm_cvtsi128_si32(d0);
    // store result[1]
    d0 = _mm_srli_si128(d0, 4);
    *(int *)(dest + stride) = _mm_cvtsi128_si32(d0);
    // store result[2]
    d0 = _mm_srli_si128(d0, 4);
    *(int *)(dest + stride * 2) = _mm_cvtsi128_si32(d0);
    // store result[3]
    d0 = _mm_srli_si128(d0, 4);
    *(int *)(dest + stride * 3) = _mm_cvtsi128_si32(d0);
  }
}

79
void av1_iht8x8_64_add_sse2(const tran_low_t *input, uint8_t *dest, int stride,
clang-format's avatar
clang-format committed
80
                            int tx_type) {
Jingning Han's avatar
Jingning Han committed
81
82
83
84
85
  __m128i in[8];
  const __m128i zero = _mm_setzero_si128();
  const __m128i final_rounding = _mm_set1_epi16(1 << 4);

  // load input data
86
87
88
89
90
91
92
93
  in[0] = load_input_data(input);
  in[1] = load_input_data(input + 8 * 1);
  in[2] = load_input_data(input + 8 * 2);
  in[3] = load_input_data(input + 8 * 3);
  in[4] = load_input_data(input + 8 * 4);
  in[5] = load_input_data(input + 8 * 5);
  in[6] = load_input_data(input + 8 * 6);
  in[7] = load_input_data(input + 8 * 7);
Jingning Han's avatar
Jingning Han committed
94
95
96

  switch (tx_type) {
    case 0:  // DCT_DCT
Luca Barbato's avatar
Luca Barbato committed
97
98
      aom_idct8_sse2(in);
      aom_idct8_sse2(in);
Jingning Han's avatar
Jingning Han committed
99
100
      break;
    case 1:  // ADST_DCT
Luca Barbato's avatar
Luca Barbato committed
101
102
      aom_idct8_sse2(in);
      aom_iadst8_sse2(in);
Jingning Han's avatar
Jingning Han committed
103
104
      break;
    case 2:  // DCT_ADST
Luca Barbato's avatar
Luca Barbato committed
105
106
      aom_iadst8_sse2(in);
      aom_idct8_sse2(in);
Jingning Han's avatar
Jingning Han committed
107
108
      break;
    case 3:  // ADST_ADST
Luca Barbato's avatar
Luca Barbato committed
109
110
      aom_iadst8_sse2(in);
      aom_iadst8_sse2(in);
Jingning Han's avatar
Jingning Han committed
111
      break;
clang-format's avatar
clang-format committed
112
    default: assert(0); break;
Jingning Han's avatar
Jingning Han committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  }

  // Final rounding and shift
  in[0] = _mm_adds_epi16(in[0], final_rounding);
  in[1] = _mm_adds_epi16(in[1], final_rounding);
  in[2] = _mm_adds_epi16(in[2], final_rounding);
  in[3] = _mm_adds_epi16(in[3], final_rounding);
  in[4] = _mm_adds_epi16(in[4], final_rounding);
  in[5] = _mm_adds_epi16(in[5], final_rounding);
  in[6] = _mm_adds_epi16(in[6], final_rounding);
  in[7] = _mm_adds_epi16(in[7], final_rounding);

  in[0] = _mm_srai_epi16(in[0], 5);
  in[1] = _mm_srai_epi16(in[1], 5);
  in[2] = _mm_srai_epi16(in[2], 5);
  in[3] = _mm_srai_epi16(in[3], 5);
  in[4] = _mm_srai_epi16(in[4], 5);
  in[5] = _mm_srai_epi16(in[5], 5);
  in[6] = _mm_srai_epi16(in[6], 5);
  in[7] = _mm_srai_epi16(in[7], 5);

  RECON_AND_STORE(dest + 0 * stride, in[0]);
  RECON_AND_STORE(dest + 1 * stride, in[1]);
  RECON_AND_STORE(dest + 2 * stride, in[2]);
  RECON_AND_STORE(dest + 3 * stride, in[3]);
  RECON_AND_STORE(dest + 4 * stride, in[4]);
  RECON_AND_STORE(dest + 5 * stride, in[5]);
  RECON_AND_STORE(dest + 6 * stride, in[6]);
  RECON_AND_STORE(dest + 7 * stride, in[7]);
}

144
void av1_iht16x16_256_add_sse2(const tran_low_t *input, uint8_t *dest,
clang-format's avatar
clang-format committed
145
                               int stride, int tx_type) {
Jingning Han's avatar
Jingning Han committed
146
147
148
149
150
151
152
153
  __m128i in0[16], in1[16];

  load_buffer_8x16(input, in0);
  input += 8;
  load_buffer_8x16(input, in1);

  switch (tx_type) {
    case 0:  // DCT_DCT
Luca Barbato's avatar
Luca Barbato committed
154
155
      aom_idct16_sse2(in0, in1);
      aom_idct16_sse2(in0, in1);
Jingning Han's avatar
Jingning Han committed
156
157
      break;
    case 1:  // ADST_DCT
Luca Barbato's avatar
Luca Barbato committed
158
159
      aom_idct16_sse2(in0, in1);
      aom_iadst16_sse2(in0, in1);
Jingning Han's avatar
Jingning Han committed
160
161
      break;
    case 2:  // DCT_ADST
Luca Barbato's avatar
Luca Barbato committed
162
163
      aom_iadst16_sse2(in0, in1);
      aom_idct16_sse2(in0, in1);
Jingning Han's avatar
Jingning Han committed
164
165
      break;
    case 3:  // ADST_ADST
Luca Barbato's avatar
Luca Barbato committed
166
167
      aom_iadst16_sse2(in0, in1);
      aom_iadst16_sse2(in0, in1);
Jingning Han's avatar
Jingning Han committed
168
      break;
clang-format's avatar
clang-format committed
169
    default: assert(0); break;
Jingning Han's avatar
Jingning Han committed
170
171
172
173
174
175
  }

  write_buffer_8x16(dest, in0, stride);
  dest += 8;
  write_buffer_8x16(dest, in1, stride);
}