fdct4x4_test.cc 11.4 KB
Newer Older
Daniel Kang's avatar
Daniel Kang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <math.h>
#include <stdlib.h>
#include <string.h>

#include "third_party/googletest/src/include/gtest/gtest.h"
16
17
18
19
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
Daniel Kang's avatar
Daniel Kang committed
20

Yaowu Xu's avatar
Yaowu Xu committed
21
#include "./vp9_rtcd.h"
22
23
24
25
#include "vp9/common/vp9_entropy.h"
#include "vpx/vpx_integer.h"

extern "C" {
26
void vp9_idct4x4_16_add_c(const int16_t *input, uint8_t *output, int pitch);
Daniel Kang's avatar
Daniel Kang committed
27
28
}

Daniel Kang's avatar
Daniel Kang committed
29
using libvpx_test::ACMRandom;
Daniel Kang's avatar
Daniel Kang committed
30

Daniel Kang's avatar
Daniel Kang committed
31
namespace {
32
33
34
35
36
37
38
39
const int kNumCoeffs = 16;
typedef void (*fdct_t)(const int16_t *in, int16_t *out, int stride);
typedef void (*idct_t)(const int16_t *in, uint8_t *out, int stride);
typedef void (*fht_t) (const int16_t *in, int16_t *out, int stride,
                       int tx_type);
typedef void (*iht_t) (const int16_t *in, uint8_t *out, int stride,
                       int tx_type);

40
41
42
typedef std::tr1::tuple<fdct_t, idct_t, int> dct_4x4_param_t;
typedef std::tr1::tuple<fht_t, iht_t, int> ht_4x4_param_t;

43
void fdct4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
44
  vp9_fdct4x4_c(in, out, stride);
Jingning Han's avatar
Jingning Han committed
45
}
46
47

void fht4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
48
  vp9_fht4x4_c(in, out, stride, tx_type);
Jingning Han's avatar
Jingning Han committed
49
50
}

Alex Converse's avatar
Alex Converse committed
51
52
53
54
void fwht4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
  vp9_fwht4x4_c(in, out, stride);
}

55
class Trans4x4TestBase {
Jingning Han's avatar
Jingning Han committed
56
 public:
57
  virtual ~Trans4x4TestBase() {}
Jingning Han's avatar
Jingning Han committed
58
59

 protected:
60
61
62
63
  virtual void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) = 0;

  virtual void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) = 0;

Alex Converse's avatar
Alex Converse committed
64
  void RunAccuracyCheck(int limit) {
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    uint32_t max_error = 0;
    int64_t total_error = 0;
    const int count_test_block = 10000;
    for (int i = 0; i < count_test_block; ++i) {
      DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
      DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, kNumCoeffs);
      DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
      DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);

      // Initialize a test block with input range [-255, 255].
      for (int j = 0; j < kNumCoeffs; ++j) {
        src[j] = rnd.Rand8();
        dst[j] = rnd.Rand8();
        test_input_block[j] = src[j] - dst[j];
      }

      REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
                                      test_temp_block, pitch_));
      REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_));

      for (int j = 0; j < kNumCoeffs; ++j) {
        const uint32_t diff = dst[j] - src[j];
        const uint32_t error = diff * diff;
        if (max_error < error)
          max_error = error;
        total_error += error;
      }
    }
Jingning Han's avatar
Jingning Han committed
94

Alex Converse's avatar
Alex Converse committed
95
96
97
    EXPECT_GE(static_cast<uint32_t>(limit), max_error)
        << "Error: 4x4 FHT/IHT has an individual round trip error > "
        << limit;
98

Alex Converse's avatar
Alex Converse committed
99
100
101
    EXPECT_GE(count_test_block * limit, total_error)
        << "Error: 4x4 FHT/IHT has average round trip error > " << limit
        << " per block";
Jingning Han's avatar
Jingning Han committed
102
103
  }

104
105
106
107
108
109
110
111
112
113
114
115
116
117
  void RunCoeffCheck() {
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    const int count_test_block = 5000;
    DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);

    for (int i = 0; i < count_test_block; ++i) {
      // Initialize a test block with input range [-255, 255].
      for (int j = 0; j < kNumCoeffs; ++j)
        input_block[j] = rnd.Rand8() - rnd.Rand8();

      fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
      REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
Daniel Kang's avatar
Daniel Kang committed
118

119
120
121
      // The minimum quant value is 4.
      for (int j = 0; j < kNumCoeffs; ++j)
        EXPECT_EQ(output_block[j], output_ref_block[j]);
Daniel Kang's avatar
Daniel Kang committed
122
123
124
    }
  }

125
126
127
128
129
130
131
132
133
134
135
136
137
138
  void RunMemCheck() {
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    const int count_test_block = 5000;
    DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);

    for (int i = 0; i < count_test_block; ++i) {
      // Initialize a test block with input range [-255, 255].
      for (int j = 0; j < kNumCoeffs; ++j) {
        input_block[j] = rnd.Rand8() - rnd.Rand8();
        input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
      }
139
      if (i == 0) {
140
141
        for (int j = 0; j < kNumCoeffs; ++j)
          input_extreme_block[j] = 255;
142
      } else if (i == 1) {
143
144
        for (int j = 0; j < kNumCoeffs; ++j)
          input_extreme_block[j] = -255;
145
      }
146
147
148
149
150
151
152
153
154
155
156
157

      fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
      REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
                                      output_block, pitch_));

      // The minimum quant value is 4.
      for (int j = 0; j < kNumCoeffs; ++j) {
        EXPECT_EQ(output_block[j], output_ref_block[j]);
        EXPECT_GE(4 * DCT_MAX_VALUE, abs(output_block[j]))
            << "Error: 16x16 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
      }
    }
Daniel Kang's avatar
Daniel Kang committed
158
159
  }

Alex Converse's avatar
Alex Converse committed
160
  void RunInvAccuracyCheck(int limit) {
161
162
163
164
165
166
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    const int count_test_block = 1000;
    DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, int16_t, coeff, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
    DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
Daniel Kang's avatar
Daniel Kang committed
167

168
169
170
171
172
173
174
    for (int i = 0; i < count_test_block; ++i) {
      // Initialize a test block with input range [-255, 255].
      for (int j = 0; j < kNumCoeffs; ++j) {
        src[j] = rnd.Rand8();
        dst[j] = rnd.Rand8();
        in[j] = src[j] - dst[j];
      }
Daniel Kang's avatar
Daniel Kang committed
175

176
177
178
179
180
181
182
      fwd_txfm_ref(in, coeff, pitch_, tx_type_);

      REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));

      for (int j = 0; j < kNumCoeffs; ++j) {
        const uint32_t diff = dst[j] - src[j];
        const uint32_t error = diff * diff;
Alex Converse's avatar
Alex Converse committed
183
184
        EXPECT_GE(static_cast<uint32_t>(limit), error)
            << "Error: 4x4 IDCT has error " << error
185
186
            << " at index " << j;
      }
Daniel Kang's avatar
Daniel Kang committed
187
188
189
    }
  }

190
191
192
193
194
195
196
  int pitch_;
  int tx_type_;
  fht_t fwd_txfm_ref;
};

class Trans4x4DCT
    : public Trans4x4TestBase,
197
      public ::testing::TestWithParam<dct_4x4_param_t> {
198
199
200
201
202
203
204
205
206
 public:
  virtual ~Trans4x4DCT() {}

  virtual void SetUp() {
    fwd_txfm_ = GET_PARAM(0);
    inv_txfm_ = GET_PARAM(1);
    tx_type_  = GET_PARAM(2);
    pitch_    = 4;
    fwd_txfm_ref = fdct4x4_ref;
Daniel Kang's avatar
Daniel Kang committed
207
  }
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  virtual void TearDown() { libvpx_test::ClearSystemState(); }

 protected:
  void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
    fwd_txfm_(in, out, stride);
  }
  void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
    inv_txfm_(out, dst, stride);
  }

  fdct_t fwd_txfm_;
  idct_t inv_txfm_;
};

TEST_P(Trans4x4DCT, AccuracyCheck) {
Alex Converse's avatar
Alex Converse committed
223
  RunAccuracyCheck(1);
Jingning Han's avatar
Jingning Han committed
224
}
Daniel Kang's avatar
Daniel Kang committed
225

226
227
228
TEST_P(Trans4x4DCT, CoeffCheck) {
  RunCoeffCheck();
}
229

230
231
232
TEST_P(Trans4x4DCT, MemCheck) {
  RunMemCheck();
}
Daniel Kang's avatar
Daniel Kang committed
233

234
TEST_P(Trans4x4DCT, InvAccuracyCheck) {
Alex Converse's avatar
Alex Converse committed
235
  RunInvAccuracyCheck(1);
236
237
238
239
}

class Trans4x4HT
    : public Trans4x4TestBase,
240
      public ::testing::TestWithParam<ht_4x4_param_t> {
241
242
243
244
245
246
247
248
249
 public:
  virtual ~Trans4x4HT() {}

  virtual void SetUp() {
    fwd_txfm_ = GET_PARAM(0);
    inv_txfm_ = GET_PARAM(1);
    tx_type_  = GET_PARAM(2);
    pitch_    = 4;
    fwd_txfm_ref = fht4x4_ref;
Daniel Kang's avatar
Daniel Kang committed
250
  }
251
  virtual void TearDown() { libvpx_test::ClearSystemState(); }
Daniel Kang's avatar
Daniel Kang committed
252

253
254
255
256
257
258
259
260
261
262
263
264
265
266
 protected:
  void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
    fwd_txfm_(in, out, stride, tx_type_);
  }

  void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
    inv_txfm_(out, dst, stride, tx_type_);
  }

  fht_t fwd_txfm_;
  iht_t inv_txfm_;
};

TEST_P(Trans4x4HT, AccuracyCheck) {
Alex Converse's avatar
Alex Converse committed
267
  RunAccuracyCheck(1);
268
269
270
271
272
273
274
275
276
277
278
}

TEST_P(Trans4x4HT, CoeffCheck) {
  RunCoeffCheck();
}

TEST_P(Trans4x4HT, MemCheck) {
  RunMemCheck();
}

TEST_P(Trans4x4HT, InvAccuracyCheck) {
Alex Converse's avatar
Alex Converse committed
279
  RunInvAccuracyCheck(1);
Jingning Han's avatar
Jingning Han committed
280
}
Daniel Kang's avatar
Daniel Kang committed
281

Alex Converse's avatar
Alex Converse committed
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
class Trans4x4WHT
    : public Trans4x4TestBase,
      public ::testing::TestWithParam<dct_4x4_param_t> {
 public:
  virtual ~Trans4x4WHT() {}

  virtual void SetUp() {
    fwd_txfm_ = GET_PARAM(0);
    inv_txfm_ = GET_PARAM(1);
    tx_type_  = GET_PARAM(2);
    pitch_    = 4;
    fwd_txfm_ref = fwht4x4_ref;
  }
  virtual void TearDown() { libvpx_test::ClearSystemState(); }

 protected:
  void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
    fwd_txfm_(in, out, stride);
  }
  void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
    inv_txfm_(out, dst, stride);
  }

  fdct_t fwd_txfm_;
  idct_t inv_txfm_;
};

TEST_P(Trans4x4WHT, AccuracyCheck) {
  RunAccuracyCheck(0);
}

TEST_P(Trans4x4WHT, CoeffCheck) {
  RunCoeffCheck();
}

TEST_P(Trans4x4WHT, MemCheck) {
  RunMemCheck();
}

TEST_P(Trans4x4WHT, InvAccuracyCheck) {
  RunInvAccuracyCheck(0);
}
324
325
326
327
328
329
330
331
332
using std::tr1::make_tuple;

INSTANTIATE_TEST_CASE_P(
    C, Trans4x4DCT,
    ::testing::Values(
        make_tuple(&vp9_fdct4x4_c, &vp9_idct4x4_16_add_c, 0)));
INSTANTIATE_TEST_CASE_P(
    C, Trans4x4HT,
    ::testing::Values(
333
334
335
336
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 0),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 1),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 2),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 3)));
Alex Converse's avatar
Alex Converse committed
337
338
339
340
INSTANTIATE_TEST_CASE_P(
    C, Trans4x4WHT,
    ::testing::Values(
        make_tuple(&vp9_fwht4x4_c, &vp9_iwht4x4_16_add_c, 0)));
341

342
#if HAVE_NEON_ASM
James Zern's avatar
James Zern committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
INSTANTIATE_TEST_CASE_P(
    NEON, Trans4x4DCT,
    ::testing::Values(
        make_tuple(&vp9_fdct4x4_c,
                   &vp9_idct4x4_16_add_neon, 0)));
INSTANTIATE_TEST_CASE_P(
    DISABLED_NEON, Trans4x4HT,
    ::testing::Values(
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 0),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 1),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 2),
        make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 3)));
#endif

Alex Converse's avatar
Alex Converse committed
357
358
359
360
361
362
363
#if CONFIG_USE_X86INC && HAVE_MMX
INSTANTIATE_TEST_CASE_P(
    MMX, Trans4x4WHT,
    ::testing::Values(
        make_tuple(&vp9_fwht4x4_mmx, &vp9_iwht4x4_16_add_c, 0)));
#endif

364
365
366
367
368
369
370
371
372
#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
    SSE2, Trans4x4DCT,
    ::testing::Values(
        make_tuple(&vp9_fdct4x4_sse2,
                   &vp9_idct4x4_16_add_sse2, 0)));
INSTANTIATE_TEST_CASE_P(
    SSE2, Trans4x4HT,
    ::testing::Values(
373
374
375
376
        make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 0),
        make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 1),
        make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 2),
        make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 3)));
377
378
#endif

379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#if HAVE_AVX2
INSTANTIATE_TEST_CASE_P(
    AVX2, Trans4x4DCT,
    ::testing::Values(
        make_tuple(&vp9_fdct4x4_avx2,
                   &vp9_idct4x4_16_add_c, 0)));
INSTANTIATE_TEST_CASE_P(
    AVX2, Trans4x4HT,
    ::testing::Values(
        make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 0),
        make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 1),
        make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 2),
        make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 3)));
#endif

Daniel Kang's avatar
Daniel Kang committed
394
}  // namespace