Compare commits

...

2 Commits

Author SHA1 Message Date
James Zern
8b4210940c vpx_dsp/get_prob: relocate den == 0 test
to get_binary_prob(). the only other caller mode_mv_merge_probs() does
its own test on 0.

BUG=chromium:639712

Change-Id: I1178688706baeca2883f7aadbc254abb219a44ce
(cherry picked from commit 93c823e24b7b5b91de729217075c08e9082b80bd)
2016-10-04 15:18:58 -07:00
James Zern
82ea742237 vpx_dsp/get_prob: make clip_prob branchless
+ inline the function directly as there was only one consumer
(get_prob())

this is an attempt to reduce the amount of branches to workaround an amd
bug. this change is mildly faster or neutral across x86-64, arm.

http://support.amd.com/TechDocs/44739_12h_Rev_Gd.pdf
665 Integer Divide Instruction May Cause Unpredictable Behavior

BUG=chromium:639712

Suggested-by: Pascal Massimino <pascal.massimino@gmail.com>
Change-Id: Ia91823aded79aab469dd68095d44300e8df04ed2
(cherry picked from commit 7481edb33f5ea82e29f12e0e872d04ea1a5373cb)
2016-10-04 15:18:58 -07:00

View File

@ -11,6 +11,8 @@
#ifndef VPX_DSP_PROB_H_
#define VPX_DSP_PROB_H_
#include <assert.h>
#include "./vpx_config.h"
#include "./vpx_dsp_common.h"
@ -43,17 +45,20 @@ typedef int8_t vpx_tree_index;
typedef const vpx_tree_index vpx_tree[];
static INLINE vpx_prob clip_prob(int p) {
return (p > 255) ? 255 : (p < 1) ? 1 : p;
}
static INLINE vpx_prob get_prob(unsigned int num, unsigned int den) {
if (den == 0) return 128u;
return clip_prob((int)(((int64_t)num * 256 + (den >> 1)) / den));
assert(den != 0);
{
const int p = (int)(((int64_t)num * 256 + (den >> 1)) / den);
// (p > 255) ? 255 : (p < 1) ? 1 : p;
const int clipped_prob = p | ((255 - p) >> 23) | (p == 0);
return (vpx_prob)clipped_prob;
}
}
static INLINE vpx_prob get_binary_prob(unsigned int n0, unsigned int n1) {
return get_prob(n0, n0 + n1);
const unsigned int den = n0 + n1;
if (den == 0) return 128u;
return get_prob(n0, den);
}
/* This function assumes prob1 and prob2 are already within [1,255] range. */