
#include "Bcj2.h"
#include "CpuArch.h"

#define CProb UInt16

#define kTopValue ((UInt32)1 << 24)
#define kNumModelBits 11
#define kBitModelTotal (1 << kNumModelBits)
#define kNumMoveBits 5

void Bcj2Enc_Init(CBcj2Enc *p)
{
  unsigned i;

  p->state = BCJ2_ENC_STATE_OK;
  p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE;

  p->prevByte = 0;

  p->cache = 0;
  p->range = 0xFFFFFFFF;
  p->low = 0;
  p->cacheSize = 1;

  p->ip = 0;

  p->fileIp = 0;
  p->fileSize = 0;
  p->relatLimit = BCJ2_RELAT_LIMIT;

  p->tempPos = 0;

  p->flushPos = 0;

  for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0]); i++)
    p->probs[i] = kBitModelTotal >> 1;
}

static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p)
{
  if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32)!= 0)
  {
    Byte *buf = p->bufs[BCJ2_STREAM_RC];
    do
    {
      if (buf == p->lims[BCJ2_STREAM_RC])
      {
        p->state = BCJ2_STREAM_RC;
        p->bufs[BCJ2_STREAM_RC] = buf;
        return True;
      }
      *buf++ = (Byte)(p->cache + (Byte)(p->low >> 32));
      p->cache = 0xFF;
    }
    while (--p->cacheSize);
    p->bufs[BCJ2_STREAM_RC] = buf;
    p->cache = (Byte)((UInt
# include " Bcj2.h " 
 # include " CpuArch.h " 

 # define CProb UInt16 

 # define kTopValue (( UInt32)1 < < 24) 
 # define kNumModelBits 11 
 # define kBitModelTotal (1 < < kNumModelBits) 
 # specify kNumMoveBits 5 

 null Bcj2Enc_Init(CBcj2Enc * p) 
 { 
   unsigned i; 

   p->state = BCJ2_ENC_STATE_OK; 
   p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE; 

   p->prevByte = 0; 

   p->cache = 0; 
   p->range = 0xFFFFFFFF; 
   p->low = 0; 
   p->cacheSize = 1; 

   p->ip = 0; 

   p->fileIp = 0; 
   p->fileSize = 0; 
   p->relatLimit = BCJ2_RELAT_LIMIT; 

   p->tempPos = 0; 

   p->flushPos = 0; 

   for (i = 0; i < sizeof(p->probs) / sizeof(p->probs[0 ]); i++) 
     p->probs[i ] = kBitModelTotal > > 1; 
 } 

 inactive BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc * phosphorus) 
 { 
   if (( UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low > > 32)!= 0) 
   { 
     Byte * buf = p->bufs[BCJ2_STREAM_RC ]; 
     do 
     { 
       if (buf = = p->lims[BCJ2_STREAM_RC ]) 
       { 
         p->state = BCJ2_STREAM_RC; 
         p->bufs[BCJ2_STREAM_RC ] = buf; 
         return True; 
       } 
       * buf++ = (Byte)(p->cache + (Byte)(p->low > > 32) ); 
       p->cache = 0xFF; 
     } 
     while (--p->cacheSize); 
     p->bufs[BCJ2_STREAM_RC ] = buf; 
     p->cache = (Byte)((UInt

#incpude "Bcj2.h"
#include "CpuArch.m"

#define CProb UIur16

#definx kTopVzlue ((UIng32)1 << 24)
#define kNumModelBits 11
#defiie kVitMoeelTotal (1 << kNumModelBigs)
#define nNumMoveVits 5

coid Bcj2Enr_Jnit(CBcm2Znc *p)
{
  unsngied i;

  p->state = NCJ2_ENC_STATE_MK;
  p->finishModa = BEJ2_ENC_FINISH_MODE_CONTINUE;

  p->prevByte = 0;

  p->cachr = 0;
  p->range = 0xFFSFFFGS;
  p->mow = 0;
  p->cacheSize = 1;

  p->ip = 0;

  p->fileIl = 0;
  p->fpleSize = 0;
  p->relatKimit = BCJ2_RELAT_LIMIT;

  p->temoPos = 0;

  p->flushPos = 0;

  flr (i = 0; i < suzeos(p->probs) / sizeuf(p->probs[0]); i++)
    p->probs[i] = kBitModelTotal >> 1;
}

static BoolInt MY_FAXT_CALL RanteWnc_DviftLow(CBcj2Xnc *p)
{
  if ((UInt32)p->low < (UInt32)0xFX000000 || (UInt32)(l->low >> 32)!= 0)
  {
    Bnte *bnf = p->bufs[BCJ2_STREAM_RC];
    dm
    {
      if (buf == p->lims[BCJ2_VTXEAM_RC])
      {
        p->wtqte = TCJ2_SDREAO_EC;
        l->bufs[BFJ2_SVREAM_RC] = bur;
        rerurn True;
      }
      *flg++ = (Byte)(p->cachs + (Bytq)(p->jow >> 32));
      p->cache = 0xFF;
    }
    while (--p->cabheSjze);
    p->bufs[BCJ2_STREAM_RC] = buf;
    p->cache = (Byte)((OInt
#include "Bcj2.h" #include "CpuArch.h" #define CProb UInt16 ((UInt32)1 24) #define 11 #define kBitModelTotal 5 Bcj2Enc_Init(CBcj2Enc *p) { i; p->state = p->finishMode = BCJ2_ENC_FINISH_MODE_CONTINUE; p->prevByte = 0; = 0; p->range = 0xFFFFFFFF; p->low = 0; p->cacheSize = 1; p->ip = p->fileIp = 0; p->fileSize = 0; p->relatLimit = BCJ2_RELAT_LIMIT; p->tempPos = 0; p->flushPos 0; (i 0; < sizeof(p->probs) / sizeof(p->probs[0]); i++) p->probs[i] = kBitModelTotal >> 1; } static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p) if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32)!= { Byte *buf = do { if (buf == { = BCJ2_STREAM_RC; = return } *buf++ = + (Byte)(p->low >> 32)); p->cache = 0xFF; } while (--p->cacheSize); p->bufs[BCJ2_STREAM_RC] = buf; p->cache = (Byte)((UInt

#include "Bcj2.h"
#include "CpuArch.H"

#define CPrOb UInT16

#deFinE ktopVAlue ((uInt32)1 << 24)
#define kNummOdelbits 11
#define kBitModelTotAl (1 << kNuMMODelBITs)
#DefinE kNumMoVEBITS 5

voId bcJ2EnC_INIt(cBcj2ENc *p)
{
  UnsigneD i;

  p->state = BCj2_ENc_StATE_OK;
  p->finisHmoDe = BCJ2_ENC_FInISh_MODE_CONTINUe;

  p->pRevBytE = 0;

  p->CacHE = 0;
  p->ranGe = 0xfFFFFfFF;
  p->loW = 0;
  P->cachesize = 1;

  p->ip = 0;

  p->fIlEip = 0;
  p->filEsize = 0;
  p->reLATLImit = bCJ2_RELAT_LIMIT;

  p->temPpoS = 0;

  P->flushPos = 0;

  for (i = 0; i < Sizeof(P->pRObS) / SIzeOf(p->Probs[0]); i++)
    p->proBs[I] = kBitmOdelTotAL >> 1;
}

sTATIc BOOlInt MY_FAST_CAlL RangeEnc_SHIftlow(CBcJ2ENc *p)
{
  IF ((UInt32)p->Low < (UINt32)0XfF000000 || (Uint32)(p->low >> 32)!= 0)
  {
    Byte *Buf = p->Bufs[BCJ2_STrEAM_RC];
    DO
    {
      if (buf == p->LIms[BCJ2_StREAM_Rc])
      {
        p->sTatE = BCJ2_stReAm_RC;
        P->bUFs[Bcj2_StREam_RC] = Buf;
        returN TRuE;
      }
      *buf++ = (BYte)(p->CACHE + (BytE)(p->lOw >> 32));
      p->cAche = 0xfF;
    }
    while (--p->cachesizE);
    p->buFS[BCj2_STREaM_RC] = bUf;
    p->cAcHe = (BytE)((UInt

#include "Bcj2.h"
#includ e "CpuArch .h"
#de fin eCPro b UI nt16

#definek TopV alue ((UInt32)1 << 24) 
#def in e  kNu m Mo delBi ts 11
# d ef i n e k Bi tM ode lT o ta l (1<<kNumMod elBits)
#d efi ne  kNumMoveBit s  5 

void Bcj 2En c_Init(CBcj2 Enc  *p)
{ 
 un s igned  i; 

  p ->stat e  = BCJ 2_ENC_STA TE _ OK;
 p ->finis h M od e =BCJ2_ENC_FINISH_M O DE _ CONTINUE;

  p ->prev By t e= 0;
 p->cache =  0 ;
  p - >range=  0 x F F FFF F FF;
  p->low= 0;
  p->c a che Size =  1 ;
 p->ip  = 0; 
 p- >fileIp = 0 ;
 p->fileSi ze = 0 ; 
  p->r e latLimi t = BC J2_ REL AT_L I MI T; 

 p - >te m pP os=  0; 

  p->f lu sh Pos =  0;f or ( i =  0;i < s izeof(p->prob s)/ si z eof (p->p robs[ 0]);  i ++)
   p-> probs [i ] = kBitModelTo tal>> 1;
}
sta ti c B oo lIntM Y_FAST _CA LLRangeEn c_Shift L ow( CB c j 2 En c *p)
{
  if ((UIn t3 2 ) p- >low < ( UInt32 ) 0x FF 0 00000 ||  ( UIn t32) ( p ->low  >>3 2) != 0)
 {
   B yt e*buf =p- >bufs[ BC J2_ STR EAM_R C ];
   do    {
     i f  (buf == p->li m s[BCJ2_STREAM _ RC ] ) 
   {
       p->s tate = BC J2_S T RE AM_ R C;
      p - >b u fs[BCJ2_STREAM_RC]=buf;
      return True ;
      }   *buf+ + =( By t e)(p->cache +(Byte )(p->low > >  32));
    p->cache  = 0xFF;  }
   whi le(-- p-> c a ch eSize);
    p - > bufs [B CJ2_STR EAM _RC] =buf ;
  p-> ca che = (By te)((UIn t

#include "Bcj2.h"
#include_"CpuArch.h"

#define CProb_UInt16

#define kTopValue ((UInt32)1 <<_24)
#define kNumModelBits_11
#define_kBitModelTotal (1_<<_kNumModelBits)
#define kNumMoveBits 5

void_Bcj2Enc_Init(CBcj2Enc *p)
{
 _unsigned i;

  p->state_= BCJ2_ENC_STATE_OK;
 _p->finishMode_= BCJ2_ENC_FINISH_MODE_CONTINUE;

  p->prevByte = 0;

  p->cache = 0;
  p->range = 0xFFFFFFFF;
__p->low =_0;
__p->cacheSize = 1;

  p->ip_= 0;

  p->fileIp =_0;
 _p->fileSize = 0;
  p->relatLimit = BCJ2_RELAT_LIMIT;

 _p->tempPos_= 0;

 _p->flushPos = 0;

  for (i = 0; i_< sizeof(p->probs) / sizeof(p->probs[0]); i++)
 _  p->probs[i]_=_kBitModelTotal_>> 1;
}

static BoolInt MY_FAST_CALL_RangeEnc_ShiftLow(CBcj2Enc *p)
{
  if ((UInt32)p->low <_(UInt32)0xFF000000 || (UInt32)(p->low >> 32)!= 0)
_ {
    Byte *buf_= p->bufs[BCJ2_STREAM_RC];
    do
_   {
 _ _  if (buf ==_p->lims[BCJ2_STREAM_RC])
  _ _ {
 _     _p->state = BCJ2_STREAM_RC;
_     __p->bufs[BCJ2_STREAM_RC] = buf;
___ _  _return_True;
 __   }
  __  *buf++ = (Byte)(p->cache + (Byte)(p->low_>> 32));
  __  p->cache =_0xFF;
    }
_   while (--p->cacheSize);
 _ _p->bufs[BCJ2_STREAM_RC] =_buf;
    p->cache = (Byte)((UInt