Made a second version of ec_{en|de}code optimised for encoding bits (no div
required) and using it in ec_{en|de}c_bits()
diff --git a/libcelt/entdec.c b/libcelt/entdec.c
index 76b8c90..3b25dd5 100644
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -88,13 +88,13 @@
   unsigned  ft;
   t=0;
   while(_ftb>EC_UNIT_BITS){
-    s=ec_decode(_this,EC_UNIT_MASK+1);
+    s=ec_decode_bin(_this,EC_UNIT_BITS);
     ec_dec_update(_this,s,s+1,EC_UNIT_MASK+1);
     t=t<<EC_UNIT_BITS|s;
     _ftb-=EC_UNIT_BITS;
   }
   ft=1U<<_ftb;
-  s=ec_decode(_this,ft);
+  s=ec_decode_bin(_this,_ftb);
   ec_dec_update(_this,s,s+1,ft);
   t=t<<_ftb|s;
   return t;
diff --git a/libcelt/entdec.h b/libcelt/entdec.h
index 423c574..f5feb1a 100644
--- a/libcelt/entdec.h
+++ b/libcelt/entdec.h
@@ -42,6 +42,7 @@
            up to and including the one encoded is fh, then the returned value
            will fall in the range [fl,fh).*/
 unsigned ec_decode(ec_dec *_this,unsigned _ft);
+unsigned ec_decode_bin(ec_dec *_this,unsigned bits);
 /*Advance the decoder past the next symbol using the frequency information the
    symbol was encoded with.
   Exactly one call to ec_decode() must have been made so that all necessary
diff --git a/libcelt/entenc.c b/libcelt/entenc.c
index 1ff0760..7859f63 100644
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -70,11 +70,11 @@
   while(_ftb>EC_UNIT_BITS){
     _ftb-=EC_UNIT_BITS;
     fl=(unsigned)(_fl>>_ftb)&EC_UNIT_MASK;
-    ec_encode(_this,fl,fl+1,EC_UNIT_MASK+1);
+    ec_encode_bin(_this,fl,fl+1,EC_UNIT_BITS);
   }
   ft=1<<_ftb;
   fl=(unsigned)_fl&ft-1;
-  ec_encode(_this,fl,fl+1,ft);
+  ec_encode_bin(_this,fl,fl+1,_ftb);
 }
 
 void ec_enc_bits64(ec_enc *_this,ec_uint64 _fl,int _ftb){
diff --git a/libcelt/entenc.h b/libcelt/entenc.h
index ebaed88..9b3ab6d 100644
--- a/libcelt/entenc.h
+++ b/libcelt/entenc.h
@@ -42,6 +42,7 @@
         decoded value will fall.
   _ft: The sum of the frequencies of all the symbols*/
 void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
+void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits);
 /*Encodes a sequence of raw bits in the stream.
   _fl:  The bits to encode.
   _ftb: The number of bits to encode.
diff --git a/libcelt/rangedec.c b/libcelt/rangedec.c
index 072e9c6..685ee25 100644
--- a/libcelt/rangedec.c
+++ b/libcelt/rangedec.c
@@ -168,6 +168,15 @@
   return _ft-EC_MINI(s+1,_ft);
 }
 
+unsigned ec_decode_bin(ec_dec *_this,unsigned bits){
+   unsigned s;
+   ec_uint32 ft;
+   ft = (ec_uint32)1<<bits;
+   _this->nrm=_this->rng>>bits;
+   s=(unsigned)((_this->dif-1)/_this->nrm);
+   return ft-EC_MINI(s+1,ft);
+}
+
 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
   ec_uint32 s;
   s=_this->nrm*(_ft-_fh);
diff --git a/libcelt/rangeenc.c b/libcelt/rangeenc.c
index 7fcd3d1..177fcb2 100644
--- a/libcelt/rangeenc.c
+++ b/libcelt/rangeenc.c
@@ -92,6 +92,18 @@
   ec_enc_normalize(_this);
 }
 
+void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
+   ec_uint32 r, ft;
+   r=_this->rng>>bits;
+   ft = (ec_uint32)1<<bits;
+   if(_fl>0){
+      _this->low+=_this->rng-r*(ft-_fl);
+      _this->rng=r*(_fh-_fl);
+   }
+   else _this->rng-=r*(ft-_fh);
+   ec_enc_normalize(_this);
+}
+
 long ec_enc_tell(ec_enc *_this,int _b){
   ec_uint32 r;
   int       l;