
#ifndef ENTCODE_H
#define ENTCODE_H

#include "config.h"
#include "basic_op.h"

#ifndef VC_PROJ
#include <xtensa/tie/xt_hifi2.h>
#include <xtensa/tie/xt_misc.h>
#endif

typedef unsigned int ec_window;

#define CHAR_BIT 8         /* number of bits in a char */
#define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT)
#define EC_UINT_BITS (8)
#define BITRES 3
#define EC_SYM_BITS (8)


#ifndef HW_24BIT
#define EC_CODE_BITS (32)
#define EC_SYM_MAX (255)
#define EC_CODE_SHIFT (23)
#define EC_CODE_TOP (2147483647)
#define EC_CODE_BOT (8388608)
#else
# define EC_CODE_BITS  (24)
# define EC_SYM_MAX    (255)
# define EC_CODE_SHIFT (15)
# define EC_CODE_TOP   (8388607)
# define EC_CODE_BOT   (32768)
#endif




#define EC_CODE_EXTRA (7)

struct ec_ctx
{
	unsigned char *buf;
	unsigned short storage;
	unsigned short end_offs;
	ec_window end_window;
	short nend_bits;
	short nbits_total;
	unsigned short offs;
	unsigned int rng;
	unsigned int val;
	unsigned int ext;
	short rem;
	short error;
};
typedef struct ec_ctx ec_ctx;
typedef struct ec_ctx ec_enc;
typedef struct ec_ctx ec_dec;
/*
static unsigned int ec_range_bytes(ec_ctx *_this)
{
	return _this->offs;
}

static unsigned char *ec_get_buffer(ec_ctx *_this)
{
	return _this->buf;
}
*/
static int ec_get_error(ec_ctx *_this)
{
	return _this->error;
}

static short ec_tell(ec_ctx *_this)
{
	return _this->nbits_total-EC_ILOG(_this->rng);

}

unsigned short ec_tell_frac(ec_ctx *_this);


#endif
