Commit e5d3e10e authored by fbarchard@google.com's avatar fbarchard@google.com

Add rounding to FixedDiv

BUG=250
TEST=unittest more exact
R=dingkai@google.com, ryanpetrie@google.com

Review URL: https://webrtc-codereview.appspot.com/1681005

git-svn-id: http://libyuv.googlecode.com/svn/trunk@735 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 567a00f7
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 734 Version: 735
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 734 #define LIBYUV_VERSION 735
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
...@@ -757,7 +757,8 @@ extern const uint32 kRecipTable[4097] = { ...@@ -757,7 +757,8 @@ extern const uint32 kRecipTable[4097] = {
// Divide num by div and return as 16.16 fixed point result. // Divide num by div and return as 16.16 fixed point result.
int FixedDiv_C(int num, int div) { int FixedDiv_C(int num, int div) {
if (static_cast<unsigned int>(div) <= 4097u) { if (static_cast<unsigned int>(div) <= 4097u) {
return static_cast<int>((static_cast<int64>(num) * kRecipTable[div]) >> 16); return static_cast<int>((static_cast<int64>(num) * kRecipTable[div] +
0x8000) >> 16);
} }
return static_cast<int>((static_cast<int64>(num) << 16) / div); return static_cast<int>((static_cast<int64>(num) << 16) / div);
} }
......
...@@ -5423,6 +5423,7 @@ int FixedDiv(int num, int div) { ...@@ -5423,6 +5423,7 @@ int FixedDiv(int num, int div) {
"mull (%2,%%ecx,4) \n" "mull (%2,%%ecx,4) \n"
#endif #endif
"shrd $0x10,%%edx,%%eax \n" "shrd $0x10,%%edx,%%eax \n"
"adc $0,%%eax \n"
"9: \n" "9: \n"
"mov %0, %%eax \n" "mov %0, %%eax \n"
......
...@@ -6616,6 +6616,7 @@ int FixedDiv(int num, int div) { ...@@ -6616,6 +6616,7 @@ int FixedDiv(int num, int div) {
ja largediv ja largediv
mul dword ptr kRecipTable[ecx * 4] mul dword ptr kRecipTable[ecx * 4]
shrd eax, edx, 16 shrd eax, edx, 16
adc eax, 0
ret ret
largediv: largediv:
......
...@@ -42,10 +42,10 @@ TEST_F(libyuvTest, TestFixedDiv) { ...@@ -42,10 +42,10 @@ TEST_F(libyuvTest, TestFixedDiv) {
EXPECT_EQ(0x20000, libyuv::FixedDiv(-40000, -20000)); EXPECT_EQ(0x20000, libyuv::FixedDiv(-40000, -20000));
EXPECT_EQ(-0x20000, libyuv::FixedDiv(40000, -20000)); EXPECT_EQ(-0x20000, libyuv::FixedDiv(40000, -20000));
EXPECT_EQ(-0x20000, libyuv::FixedDiv(-40000, 20000)); EXPECT_EQ(-0x20000, libyuv::FixedDiv(-40000, 20000));
EXPECT_NEAR(0x10000, libyuv::FixedDiv(4095, 4095), 1); EXPECT_EQ(0x10000, libyuv::FixedDiv(4095, 4095));
EXPECT_EQ(0x10000, libyuv::FixedDiv(4096, 4096)); EXPECT_EQ(0x10000, libyuv::FixedDiv(4096, 4096));
EXPECT_EQ(0x10000, libyuv::FixedDiv(4097, 4097)); EXPECT_EQ(0x10000, libyuv::FixedDiv(4097, 4097));
EXPECT_NEAR(123 * 65536, libyuv::FixedDiv(123, 1), 1); EXPECT_EQ(123 * 65536, libyuv::FixedDiv(123, 1));
srandom(time(NULL)); srandom(time(NULL));
MemRandomize(reinterpret_cast<uint8*>(&num[0]), sizeof(num)); MemRandomize(reinterpret_cast<uint8*>(&num[0]), sizeof(num));
......
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