Commit 03122298 authored by Nathan Egge's avatar Nathan Egge

Replace divides by small values with multiplies.

This ports the OD_DIVU_SMALL code from Daala to AOM so that divides by
 constants smaller than OD_DIVU_DMAX (1024) are done using a multiply.
Added a unit test for OD_DIVU_SMALL in test/divu_small_test.cc.

Change-Id: Id9fee172d54477355571c5d6c12c584fb65769e5
parent 9c48eec7
......@@ -24,6 +24,11 @@ class ACMRandom {
explicit ACMRandom(int seed) : random_(seed) {}
void Reset(int seed) { random_.Reseed(seed); }
uint32_t Rand31(void) {
return random_.Generate(testing::internal::Random::kMaxRange);
}
uint16_t Rand16(void) {
const uint32_t value =
random_.Generate(testing::internal::Random::kMaxRange);
......
/*Daala video codec
Copyright (c) 2013 Daala project contributors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
#include <stdlib.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
#include "vp10/common/odintrin.h"
using libvpx_test::ACMRandom;
TEST(Daala, TestDIVUuptoMAX) {
for (int d = 1; d <= OD_DIVU_DMAX; d++) {
for (uint32_t x = 1; x <= 1000000; x++) {
GTEST_ASSERT_EQ(x/d, OD_DIVU_SMALL(x, d)) << "x=" << x << " d=" << d <<
" x/d=" << (x/d) << " != " << OD_DIVU_SMALL(x, d);
}
}
}
TEST(Daala, TestDIVUrandI31) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
for (int d = 1; d < OD_DIVU_DMAX; d++) {
for (int i = 0; i < 1000000; i++) {
uint32_t x = rnd.Rand31();
GTEST_ASSERT_EQ(x/d, OD_DIVU_SMALL(x, d)) << "x=" << x << " d=" << d <<
" x/d=" << (x/d) << " != " << OD_DIVU_SMALL(x, d);
}
}
}
......@@ -92,6 +92,7 @@ LIBVPX_TEST_SRCS-yes += partial_idct_test.cc
LIBVPX_TEST_SRCS-yes += superframe_test.cc
LIBVPX_TEST_SRCS-yes += tile_independence_test.cc
LIBVPX_TEST_SRCS-yes += boolcoder_test.cc
LIBVPX_TEST_SRCS-yes += divu_small_test.cc
LIBVPX_TEST_SRCS-yes += encoder_parms_get_to_decoder.cc
endif
......
This diff is collapsed.
......@@ -19,7 +19,18 @@ typedef int od_coeff;
typedef int16_t od_dering_in;
#define OD_DIVU_SMALL(_x, _d) ((_x) / (_d))
# define OD_DIVU_DMAX (1024)
extern uint32_t OD_DIVU_SMALL_CONSTS[OD_DIVU_DMAX][2];
/*Translate unsigned division by small divisors into multiplications.*/
# define OD_DIVU_SMALL(_x, _d) \
((uint32_t)((OD_DIVU_SMALL_CONSTS[(_d)-1][0]* \
(uint64_t)(_x)+OD_DIVU_SMALL_CONSTS[(_d)-1][1])>>32)>> \
(OD_ILOG(_d)-1))
# define OD_DIVU(_x, _d) \
(((_d) < OD_DIVU_DMAX)?(OD_DIVU_SMALL((_x), (_d))):((_x)/(_d)))
#define OD_MINI VPXMIN
#define OD_CLAMPI(min, val, max) clamp((val), (min), (max))
......
......@@ -67,8 +67,9 @@ VP10_COMMON_SRCS-yes += common/od_dering.c
VP10_COMMON_SRCS-yes += common/od_dering.h
VP10_COMMON_SRCS-yes += common/dering.c
VP10_COMMON_SRCS-yes += common/dering.h
VP10_COMMON_SRCS-yes += common/odintrin.h
endif
VP10_COMMON_SRCS-yes += common/odintrin.c
VP10_COMMON_SRCS-yes += common/odintrin.h
ifneq ($(CONFIG_VPX_HIGHBITDEPTH),yes)
VP10_COMMON_SRCS-$(HAVE_DSPR2) += common/mips/dspr2/itrans4_dspr2.c
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment