shithub: opus

Download patch

ref: 821945d97c664b648ea645ed2af7c26a8fdc4c19
parent: c8e3b67869af8f17d7b24e1ba6071366845bf633
author: Jean-Marc Valin <[email protected]>
date: Thu Apr 10 09:24:48 EDT 2008

Defining IMUL32 for 32x32=>32 int multiplications and using it in the range
coder

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -47,6 +47,7 @@
 #define celt_assert2(cond, message)
 #endif
 
+#define IMUL32(a,b) ((a)*(b))
 
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
--- a/libcelt/fixed_c5x.h
+++ b/libcelt/fixed_c5x.h
@@ -37,6 +37,15 @@
 
 #include "dsplib.h"
 
+#undef IMUL32
+static inline long IMUL32(long i, long j)
+{
+   long ac0, ac1;
+   ac0 = _lmpy(i>>16,j);
+   ac1 = ac0 + _lmpy(i,j>>16);
+   return _lmpyu(i,j) + (ac1<<16);
+}
+
 #undef MAX16
 #define MAX16(a,b) _max(a,b)
 
--- a/libcelt/rangedec.c
+++ b/libcelt/rangedec.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #endif
 
+#include "arch.h"
 #include "entdec.h"
 #include "mfrngcod.h"
 
@@ -179,9 +180,9 @@
 
 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
   ec_uint32 s;
-  s=_this->nrm*(_ft-_fh);
+  s=IMUL32(_this->nrm,(_ft-_fh));
   _this->dif-=s;
-  _this->rng=_fl>0?_this->nrm*(_fh-_fl):_this->rng-s;
+  _this->rng=_fl>0?IMUL32(_this->nrm,(_fh-_fl)):_this->rng-s;
   ec_dec_normalize(_this);
 }
 
--- a/libcelt/rangeenc.c
+++ b/libcelt/rangeenc.c
@@ -2,6 +2,7 @@
 #include "config.h"
 #endif
 
+#include "arch.h"
 #include "entenc.h"
 #include "mfrngcod.h"
 
@@ -85,10 +86,10 @@
   ec_uint32 r;
   r=_this->rng/_ft;
   if(_fl>0){
-    _this->low+=_this->rng-r*(_ft-_fl);
-    _this->rng=r*(_fh-_fl);
+    _this->low+=_this->rng-IMUL32(r,(_ft-_fl));
+    _this->rng=IMUL32(r,(_fh-_fl));
   }
-  else _this->rng-=r*(_ft-_fh);
+  else _this->rng-=IMUL32(r,(_ft-_fh));
   ec_enc_normalize(_this);
 }
 
@@ -97,10 +98,10 @@
    r=_this->rng>>bits;
    ft = (ec_uint32)1<<bits;
    if(_fl>0){
-      _this->low+=_this->rng-r*(ft-_fl);
-      _this->rng=r*(_fh-_fl);
+     _this->low+=_this->rng-IMUL32(r,(ft-_fl));
+     _this->rng=IMUL32(r,(_fh-_fl));
    }
-   else _this->rng-=r*(ft-_fh);
+   else _this->rng-=IMUL32(r,(ft-_fh));
    ec_enc_normalize(_this);
 }