cdef(highbd): Remove unnecessary loop code.
[aom.git] / test / log2_test.cc
blobd7840c68b23ff4c404a2d83cff6ce42d992f34f9
1 /*
2 * Copyright (c) 2018, 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 #include <math.h>
14 #include "aom_ports/bitops.h"
15 #include "av1/common/entropymode.h"
16 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
18 TEST(Log2Test, GetMsb) {
19 // Test small numbers exhaustively.
20 for (unsigned int n = 1; n < 10000; n++) {
21 EXPECT_EQ(get_msb(n), static_cast<int>(floor(log2(n))));
24 // Test every power of 2 and the two adjacent numbers.
25 for (int exponent = 2; exponent < 32; exponent++) {
26 const unsigned int power_of_2 = 1U << exponent;
27 EXPECT_EQ(get_msb(power_of_2 - 1), exponent - 1);
28 EXPECT_EQ(get_msb(power_of_2), exponent);
29 EXPECT_EQ(get_msb(power_of_2 + 1), exponent);
33 TEST(Log2Test, Av1CeilLog2) {
34 // Test small numbers exhaustively.
35 EXPECT_EQ(av1_ceil_log2(0), 0);
36 for (int n = 1; n < 10000; n++) {
37 EXPECT_EQ(av1_ceil_log2(n), static_cast<int>(ceil(log2(n))));
40 // Test every power of 2 and the two adjacent numbers.
41 for (int exponent = 2; exponent < 31; exponent++) {
42 const int power_of_2 = 1 << exponent;
43 EXPECT_EQ(av1_ceil_log2(power_of_2 - 1), exponent);
44 EXPECT_EQ(av1_ceil_log2(power_of_2), exponent);
45 // The current implementation of av1_ceil_log2 only works up to 2^30.
46 if (exponent < 30) {
47 EXPECT_EQ(av1_ceil_log2(power_of_2 + 1), exponent + 1);