]> git.sesse.net Git - x264/blobdiff - common/mc.c
x86: Add asm for mbtree fixed point conversion
[x264] / common / mc.c
index 8c63e1b58568e48c6bf40931585f8992a4c570e8..dc39c5eb920c0e95019c490f0ec91ae13f8a5ca0 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * mc.c: motion compensation
  *****************************************************************************
- * Copyright (C) 2003-2015 x264 project
+ * Copyright (C) 2003-2016 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
@@ -526,7 +526,6 @@ static void mbtree_propagate_list( x264_t *h, uint16_t *ref_costs, int16_t (*mvs
 
     for( unsigned i = 0; i < len; i++ )
     {
-#define CLIP_ADD(s,x) (s) = X264_MIN((s)+(x),(1<<15)-1)
         int lists_used = lowres_costs[i]>>LOWRES_COST_SHIFT;
 
         if( !(lists_used & (1 << list)) )
@@ -540,7 +539,7 @@ static void mbtree_propagate_list( x264_t *h, uint16_t *ref_costs, int16_t (*mvs
         /* Early termination for simple case of mv0. */
         if( !M32( mvs[i] ) )
         {
-            CLIP_ADD( ref_costs[mb_y*stride + i], listamount );
+            MC_CLIP_ADD( ref_costs[mb_y*stride + i], listamount );
             continue;
         }
 
@@ -563,10 +562,10 @@ static void mbtree_propagate_list( x264_t *h, uint16_t *ref_costs, int16_t (*mvs
 
         if( mbx < width-1 && mby < height-1 )
         {
-            CLIP_ADD( ref_costs[idx0+0], idx0weight );
-            CLIP_ADD( ref_costs[idx0+1], idx1weight );
-            CLIP_ADD( ref_costs[idx2+0], idx2weight );
-            CLIP_ADD( ref_costs[idx2+1], idx3weight );
+            MC_CLIP_ADD( ref_costs[idx0+0], idx0weight );
+            MC_CLIP_ADD( ref_costs[idx0+1], idx1weight );
+            MC_CLIP_ADD( ref_costs[idx2+0], idx2weight );
+            MC_CLIP_ADD( ref_costs[idx2+1], idx3weight );
         }
         else
         {
@@ -575,20 +574,32 @@ static void mbtree_propagate_list( x264_t *h, uint16_t *ref_costs, int16_t (*mvs
             if( mby < height )
             {
                 if( mbx < width )
-                    CLIP_ADD( ref_costs[idx0+0], idx0weight );
+                    MC_CLIP_ADD( ref_costs[idx0+0], idx0weight );
                 if( mbx+1 < width )
-                    CLIP_ADD( ref_costs[idx0+1], idx1weight );
+                    MC_CLIP_ADD( ref_costs[idx0+1], idx1weight );
             }
             if( mby+1 < height )
             {
                 if( mbx < width )
-                    CLIP_ADD( ref_costs[idx2+0], idx2weight );
+                    MC_CLIP_ADD( ref_costs[idx2+0], idx2weight );
                 if( mbx+1 < width )
-                    CLIP_ADD( ref_costs[idx2+1], idx3weight );
+                    MC_CLIP_ADD( ref_costs[idx2+1], idx3weight );
             }
         }
     }
-#undef CLIP_ADD
+}
+
+/* Conversion between float and Q8.8 fixed point (big-endian) for storage */
+static void mbtree_fix8_pack( uint16_t *dst, float *src, int count )
+{
+    for( int i = 0; i < count; i++ )
+        dst[i] = endian_fix16( (int16_t)(src[i] * 256.0f) );
+}
+
+static void mbtree_fix8_unpack( float *dst, uint16_t *src, int count )
+{
+    for( int i = 0; i < count; i++ )
+        dst[i] = (int16_t)endian_fix16( src[i] ) * (1.0f/256.0f);
 }
 
 void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent )
@@ -648,6 +659,8 @@ void x264_mc_init( int cpu, x264_mc_functions_t *pf, int cpu_independent )
 
     pf->mbtree_propagate_cost = mbtree_propagate_cost;
     pf->mbtree_propagate_list = mbtree_propagate_list;
+    pf->mbtree_fix8_pack      = mbtree_fix8_pack;
+    pf->mbtree_fix8_unpack    = mbtree_fix8_unpack;
 
 #if HAVE_MMX
     x264_mc_init_mmx( cpu, pf );