]> granicus.if.org Git - libvpx/commitdiff
vpx_dsp/get_prob: make clip_prob branchless
authorJames Zern <jzern@google.com>
Wed, 28 Sep 2016 02:43:03 +0000 (19:43 -0700)
committerJames Zern <jzern@google.com>
Wed, 28 Sep 2016 18:51:46 +0000 (11:51 -0700)
+ 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

vpx_dsp/prob.h

index 3127a00bb9798f488d27991aa8c0d8a1a5f8b7cd..4402cd30a5e932ab9b77fdb0f67e78d835446f8e 100644 (file)
@@ -43,13 +43,14 @@ 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));
+  {
+    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) {