av1_convolve_ x,y _avx2() -- use 256 bit load/store
[aom.git] / test / acm_random.h
blob78c6c870a8d159d5b90f4c0fadd1bde376880f0f
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #ifndef TEST_ACM_RANDOM_H_
13 #define TEST_ACM_RANDOM_H_
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17 #include "aom/aom_integer.h"
19 namespace libaom_test {
21 class ACMRandom {
22 public:
23 ACMRandom() : random_(DeterministicSeed()) {}
25 explicit ACMRandom(int seed) : random_(seed) {}
27 void Reset(int seed) { random_.Reseed(seed); }
29 uint32_t Rand31(void) {
30 return random_.Generate(testing::internal::Random::kMaxRange);
33 uint16_t Rand16(void) {
34 const uint32_t value =
35 random_.Generate(testing::internal::Random::kMaxRange);
36 return (value >> 15) & 0xffff;
39 int16_t Rand15Signed(void) {
40 const uint32_t value =
41 random_.Generate(testing::internal::Random::kMaxRange);
42 return (value >> 17) & 0xffff;
45 int16_t Rand9Signed(void) {
46 // Use 9 bits: values between 255 (0x0FF) and -256 (0x100).
47 const uint32_t value = random_.Generate(512);
48 return static_cast<int16_t>(value) - 256;
51 uint8_t Rand8(void) {
52 const uint32_t value =
53 random_.Generate(testing::internal::Random::kMaxRange);
54 // There's a bit more entropy in the upper bits of this implementation.
55 return (value >> 23) & 0xff;
58 uint8_t Rand8Extremes(void) {
59 // Returns a random value near 0 or near 255, to better exercise
60 // saturation behavior.
61 const uint8_t r = Rand8();
62 return r < 128 ? r << 4 : r >> 4;
65 int PseudoUniform(int range) { return random_.Generate(range); }
67 int operator()(int n) { return PseudoUniform(n); }
69 static int DeterministicSeed(void) { return 0xbaba; }
71 private:
72 testing::internal::Random random_;
75 } // namespace libaom_test
77 #endif // TEST_ACM_RANDOM_H_