Commit 6f2ffa17 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

More explicit casting to shup up VS.

parent 8e055aaa
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
/* Reference samples have to be sign extended */ \ /* Reference samples have to be sign extended */ \
state->last_out = (state->last_out ^ m) - m; \ state->last_out = (state->last_out ^ m) - m; \
} \ } \
put_##KIND(strm, state->last_out); \ put_##KIND(strm, (uint32_t)state->last_out); \
state->flush_start++; \ state->flush_start++; \
} \ } \
\ \
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
data = xmax - d; \ data = xmax - d; \
} \ } \
} \ } \
put_##KIND(strm, data); \ put_##KIND(strm, (uint32_t)data); \
} \ } \
state->last_out = data; \ state->last_out = data; \
} else { \ } else { \
...@@ -135,49 +135,49 @@ ...@@ -135,49 +135,49 @@
static inline void put_msb_32(struct aec_stream *strm, uint32_t data) static inline void put_msb_32(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data >> 24; *strm->next_out++ = (unsigned char)(data >> 24);
*strm->next_out++ = data >> 16; *strm->next_out++ = (unsigned char)(data >> 16);
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
} }
static inline void put_msb_24(struct aec_stream *strm, uint32_t data) static inline void put_msb_24(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data >> 16; *strm->next_out++ = (unsigned char)(data >> 16);
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
} }
static inline void put_msb_16(struct aec_stream *strm, uint32_t data) static inline void put_msb_16(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
} }
static inline void put_lsb_32(struct aec_stream *strm, uint32_t data) static inline void put_lsb_32(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
*strm->next_out++ = data >> 16; *strm->next_out++ = (unsigned char)(data >> 16);
*strm->next_out++ = data >> 24; *strm->next_out++ = (unsigned char)(data >> 24);
} }
static inline void put_lsb_24(struct aec_stream *strm, uint32_t data) static inline void put_lsb_24(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
*strm->next_out++ = data >> 16; *strm->next_out++ = (unsigned char)(data >> 16);
} }
static inline void put_lsb_16(struct aec_stream *strm, uint32_t data) static inline void put_lsb_16(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
*strm->next_out++ = data >> 8; *strm->next_out++ = (unsigned char)(data >> 8);
} }
static inline void put_8(struct aec_stream *strm, uint32_t data) static inline void put_8(struct aec_stream *strm, uint32_t data)
{ {
*strm->next_out++ = data; *strm->next_out++ = (unsigned char)data;
} }
FLUSH(msb_32) FLUSH(msb_32)
...@@ -195,7 +195,7 @@ static inline void check_rsi_end(struct aec_stream *strm) ...@@ -195,7 +195,7 @@ static inline void check_rsi_end(struct aec_stream *strm)
*/ */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (state->rsip - state->rsi_buffer == state->rsi_size) { if (state->rsi_size == (size_t)(state->rsip - state->rsi_buffer)) {
state->flush_output(strm); state->flush_output(strm);
state->flush_start = state->rsi_buffer; state->flush_start = state->rsi_buffer;
state->rsip = state->rsi_buffer; state->rsip = state->rsi_buffer;
...@@ -237,7 +237,7 @@ static inline void fill_acc(struct aec_stream *strm) ...@@ -237,7 +237,7 @@ static inline void fill_acc(struct aec_stream *strm)
} }
static inline uint32_t direct_get(struct aec_stream *strm, unsigned int n) static inline uint32_t direct_get(struct aec_stream *strm, int n)
{ {
/** /**
Get n bit from input stream Get n bit from input stream
...@@ -264,8 +264,10 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) ...@@ -264,8 +264,10 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
*/ */
uint32_t fs = 0; uint32_t fs = 0;
#if HAVE_DECL___BUILTIN_CLZLL||HAVE_BSR64 #if HAVE_DECL___BUILTIN_CLZLL
uint32_t lz; int lz;
#elif HAVE_BSR64
unsigned long lz;
#endif #endif
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
...@@ -413,7 +415,7 @@ static int m_split_fs(struct aec_stream *strm) ...@@ -413,7 +415,7 @@ static int m_split_fs(struct aec_stream *strm)
static int m_split(struct aec_stream *strm) static int m_split(struct aec_stream *strm)
{ {
int i, k; uint32_t i, k;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (BUFFERSPACE(strm)) { if (BUFFERSPACE(strm)) {
...@@ -464,7 +466,7 @@ static int m_zero_output(struct aec_stream *strm) ...@@ -464,7 +466,7 @@ static int m_zero_output(struct aec_stream *strm)
static int m_zero_block(struct aec_stream *strm) static int m_zero_block(struct aec_stream *strm)
{ {
int i, zero_blocks, b, zero_bytes; uint32_t i, zero_blocks, b, zero_bytes;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (fs_ask(strm) == 0) if (fs_ask(strm) == 0)
...@@ -473,7 +475,7 @@ static int m_zero_block(struct aec_stream *strm) ...@@ -473,7 +475,7 @@ static int m_zero_block(struct aec_stream *strm)
fs_drop(strm); fs_drop(strm);
if (zero_blocks == ROS) { if (zero_blocks == ROS) {
b = (state->rsip - state->rsi_buffer) / strm->block_size; b = (int)(state->rsip - state->rsi_buffer) / strm->block_size;
zero_blocks = MIN(strm->rsi - b, 64 - (b % 64)); zero_blocks = MIN(strm->rsi - b, 64 - (b % 64));
} else if (zero_blocks > ROS) { } else if (zero_blocks > ROS) {
zero_blocks--; zero_blocks--;
...@@ -535,7 +537,7 @@ static int m_se_decode(struct aec_stream *strm) ...@@ -535,7 +537,7 @@ static int m_se_decode(struct aec_stream *strm)
static int m_se(struct aec_stream *strm) static int m_se(struct aec_stream *strm)
{ {
int i; uint32_t i;
int32_t m, d1; int32_t m, d1;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
...@@ -605,7 +607,7 @@ static int m_uncomp_copy(struct aec_stream *strm) ...@@ -605,7 +607,7 @@ static int m_uncomp_copy(struct aec_stream *strm)
static int m_uncomp(struct aec_stream *strm) static int m_uncomp(struct aec_stream *strm)
{ {
int i; uint32_t i;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
if (BUFFERSPACE(strm)) { if (BUFFERSPACE(strm)) {
...@@ -701,7 +703,7 @@ int aec_decode_init(struct aec_stream *strm) ...@@ -701,7 +703,7 @@ int aec_decode_init(struct aec_stream *strm)
} }
if (strm->flags & AEC_DATA_SIGNED) { if (strm->flags & AEC_DATA_SIGNED) {
state->xmin = -(1ULL << (strm->bits_per_sample - 1)); state->xmin = -(1LL << (strm->bits_per_sample - 1));
state->xmax = (1ULL << (strm->bits_per_sample - 1)) - 1; state->xmax = (1ULL << (strm->bits_per_sample - 1)) - 1;
} else { } else {
state->xmin = 0; state->xmin = 0;
......
...@@ -70,30 +70,69 @@ ...@@ -70,30 +70,69 @@
struct internal_state { struct internal_state {
int (*mode)(struct aec_stream *); int (*mode)(struct aec_stream *);
int id; /* option ID */
int id_len; /* bit length of code option identification key */ /* option ID */
int (**id_table)(struct aec_stream *); /* table maps IDs to states */ int id;
/* bit length of code option identification key */
int id_len;
/* table maps IDs to states */
int (**id_table)(struct aec_stream *);
void (*flush_output)(struct aec_stream *); void (*flush_output)(struct aec_stream *);
int64_t last_out; /* previous output for post-processing */
int64_t xmin; /* minimum integer for post-processing */ /* previous output for post-processing */
int64_t xmax; /* maximum integer for post-processing */ int64_t last_out;
int in_blklen; /* length of uncompressed input block
should be the longest possible block */ /* minimum integer for post-processing */
int out_blklen; /* length of output block in bytes */ int64_t xmin;
int n, i; /* counter for samples */
uint64_t acc; /* accumulator for currently used bit sequence */ /* maximum integer for post-processing */
int bitp; /* bit pointer to the next unused bit in int64_t xmax;
accumulator */
int fs; /* last fundamental sequence in accumulator */ /* length of uncompressed input block should be the longest
int ref; /* 1 if current block has reference sample */ possible block */
int pp; /* 1 if postprocessor has to be used */ uint32_t in_blklen;
int bytes_per_sample; /* storage size of samples in bytes */
uint32_t *rsi_buffer; /* output buffer holding one reference /* length of output block in bytes */
sample interval */ uint32_t out_blklen;
uint32_t *rsip; /* current position of output in rsi_buffer */
size_t rsi_size; /* rsi in bytes */ /* counter for samples */
uint32_t *flush_start; /* first not yet flushed byte in rsi_buffer */ uint32_t n, i;
int se_table[182]; /* table for decoding second extension option */
/* accumulator for currently used bit sequence */
uint64_t acc;
/* bit pointer to the next unused bit in accumulator */
int bitp;
/* last fundamental sequence in accumulator */
int fs;
/* 1 if current block has reference sample */
int ref;
/* 1 if postprocessor has to be used */
int pp;
/* storage size of samples in bytes */
uint32_t bytes_per_sample;
/* output buffer holding one reference sample interval */
uint32_t *rsi_buffer;
/* current position of output in rsi_buffer */
uint32_t *rsip;
/* rsi in bytes */
size_t rsi_size;
/* first not yet flushed byte in rsi_buffer */
uint32_t *flush_start;
/* table for decoding second extension option */
int se_table[182];
} decode_state; } decode_state;
#endif /* DECODE_H */ #endif /* DECODE_H */
...@@ -70,18 +70,18 @@ static inline void emit(struct internal_state *state, ...@@ -70,18 +70,18 @@ static inline void emit(struct internal_state *state,
if (bits <= state->bits) { if (bits <= state->bits) {
state->bits -= bits; state->bits -= bits;
*state->cds += data << state->bits; *state->cds += (uint8_t)(data << state->bits);
} else { } else {
bits -= state->bits; bits -= state->bits;
*state->cds++ += (uint64_t)data >> bits; *state->cds++ += (uint8_t)((uint64_t)data >> bits);
while (bits > 8) { while (bits > 8) {
bits -= 8; bits -= 8;
*state->cds++ = data >> bits; *state->cds++ = (uint8_t)(data >> bits);
} }
state->bits = 8 - bits; state->bits = 8 - bits;
*state->cds = data << state->bits; *state->cds = (uint8_t)(data << state->bits);
} }
} }
...@@ -108,20 +108,20 @@ static inline void emitfs(struct internal_state *state, int fs) ...@@ -108,20 +108,20 @@ static inline void emitfs(struct internal_state *state, int fs)
static inline void copy64(uint8_t *dst, uint64_t src) static inline void copy64(uint8_t *dst, uint64_t src)
{ {
dst[0] = src >> 56; dst[0] = (uint8_t)(src >> 56);
dst[1] = src >> 48; dst[1] = (uint8_t)(src >> 48);
dst[2] = src >> 40; dst[2] = (uint8_t)(src >> 40);
dst[3] = src >> 32; dst[3] = (uint8_t)(src >> 32);
dst[4] = src >> 24; dst[4] = (uint8_t)(src >> 24);
dst[5] = src >> 16; dst[5] = (uint8_t)(src >> 16);
dst[6] = src >> 8; dst[6] = (uint8_t)(src >> 8);
dst[7] = src; dst[7] = (uint8_t)src;
} }
static inline void emitblock_fs(struct aec_stream *strm, int k, int ref) static inline void emitblock_fs(struct aec_stream *strm, int k, int ref)
{ {
int i; uint32_t i;
int used; /* used bits in 64 bit accumulator */ uint32_t used; /* used bits in 64 bit accumulator */
uint64_t acc; /* accumulator */ uint64_t acc; /* accumulator */
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
...@@ -171,57 +171,57 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref) ...@@ -171,57 +171,57 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref)
switch (p & ~7) { switch (p & ~7) {
case 0: case 0:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
o[2] = a >> 40; o[2] = (uint8_t)(a >> 40);
o[3] = a >> 32; o[3] = (uint8_t)(a >> 32);
o[4] = a >> 24; o[4] = (uint8_t)(a >> 24);
o[5] = a >> 16; o[5] = (uint8_t)(a >> 16);
o[6] = a >> 8; o[6] = (uint8_t)(a >> 8);
o += 7; o += 7;
break; break;
case 8: case 8:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
o[2] = a >> 40; o[2] = (uint8_t)(a >> 40);
o[3] = a >> 32; o[3] = (uint8_t)(a >> 32);
o[4] = a >> 24; o[4] = (uint8_t)(a >> 24);
o[5] = a >> 16; o[5] = (uint8_t)(a >> 16);
a >>= 8; a >>= 8;
o += 6; o += 6;
break; break;
case 16: case 16:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
o[2] = a >> 40; o[2] = (uint8_t)(a >> 40);
o[3] = a >> 32; o[3] = (uint8_t)(a >> 32);
o[4] = a >> 24; o[4] = (uint8_t)(a >> 24);
a >>= 16; a >>= 16;
o += 5; o += 5;
break; break;
case 24: case 24:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
o[2] = a >> 40; o[2] = (uint8_t)(a >> 40);
o[3] = a >> 32; o[3] = (uint8_t)(a >> 32);
a >>= 24; a >>= 24;
o += 4; o += 4;
break; break;
case 32: case 32:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
o[2] = a >> 40; o[2] = (uint8_t)(a >> 40);
a >>= 32; a >>= 32;
o += 3; o += 3;
break; break;
case 40: case 40:
o[0] = a >> 56; o[0] = (uint8_t)(a >> 56);
o[1] = a >> 48; o[1] = (uint8_t)(a >> 48);
a >>= 40; a >>= 40;
o += 2; o += 2;
break; break;
case 48: case 48:
*o++ = a >> 56; *o++ = (uint8_t)(a >> 56);
a >>= 48; a >>= 48;
break; break;
default: default:
...@@ -230,7 +230,7 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref) ...@@ -230,7 +230,7 @@ static inline void emitblock(struct aec_stream *strm, int k, int ref)
} }
} }
*o = a; *o = (uint8_t)a;
state->cds = o; state->cds = o;
state->bits = p % 8; state->bits = p % 8;
} }
...@@ -248,9 +248,9 @@ static void preprocess_unsigned(struct aec_stream *strm) ...@@ -248,9 +248,9 @@ static void preprocess_unsigned(struct aec_stream *strm)
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
const uint32_t *restrict x = state->data_raw; const uint32_t *restrict x = state->data_raw;
uint32_t *restrict d = state->data_pp; uint32_t *restrict d = state->data_pp;
uint32_t xmax = state->xmax; uint32_t xmax = (uint32_t)state->xmax;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
int i; unsigned int i;
d[0] = x[0]; d[0] = x[0];
for (i = 0; i < rsi; i++) { for (i = 0; i < rsi; i++) {
...@@ -282,11 +282,11 @@ static void preprocess_signed(struct aec_stream *strm) ...@@ -282,11 +282,11 @@ static void preprocess_signed(struct aec_stream *strm)
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
uint32_t *restrict d = state->data_pp; uint32_t *restrict d = state->data_pp;
int32_t *restrict x = (int32_t *)state->data_raw; int32_t *restrict x = (int32_t *)state->data_raw;
uint64_t m = 1ULL << (strm->bits_per_sample - 1); uint32_t m = 1ULL << (strm->bits_per_sample - 1);
int64_t xmax = state->xmax; int64_t xmax = state->xmax;
int64_t xmin = state->xmin; int64_t xmin = state->xmin;
uint32_t rsi = strm->rsi * strm->block_size - 1; uint32_t rsi = strm->rsi * strm->block_size - 1;
int i; unsigned int i;
d[0] = (uint32_t)x[0]; d[0] = (uint32_t)x[0];
x[0] = (x[0] ^ m) - m; x[0] = (x[0] ^ m) - m;
...@@ -296,15 +296,15 @@ static void preprocess_signed(struct aec_stream *strm) ...@@ -296,15 +296,15 @@ static void preprocess_signed(struct aec_stream *strm)
if (x[i + 1] < x[i]) { if (x[i + 1] < x[i]) {
D = (int64_t)x[i] - x[i + 1]; D = (int64_t)x[i] - x[i + 1];
if (D <= xmax - x[i]) if (D <= xmax - x[i])
d[i + 1] = 2 * D - 1; d[i + 1] = 2 * (uint32_t)D - 1;
else else
d[i + 1] = xmax - x[i + 1]; d[i + 1] = (uint32_t)xmax - x[i + 1];
} else { } else {
D = (int64_t)x[i + 1] - x[i]; D = (int64_t)x[i + 1] - x[i];
if (D <= x[i] - xmin) if (D <= x[i] - xmin)
d[i + 1] = 2 * D; d[i + 1] = 2 * (uint32_t)D;
else else
d[i + 1] = x[i + 1] - xmin; d[i + 1] = x[i + 1] - (uint32_t)xmin;
} }
} }
state->ref = 1; state->ref = 1;
...@@ -317,7 +317,7 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k) ...@@ -317,7 +317,7 @@ static inline uint64_t block_fs(struct aec_stream *strm, int k)
Sum FS of all samples in block for given splitting position. Sum FS of all samples in block for given splitting position.
*/ */
int i; uint32_t i;
uint64_t fs = 0; uint64_t fs = 0;
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
...@@ -410,7 +410,7 @@ static uint32_t assess_splitting_option(struct aec_stream *strm) ...@@ -410,7 +410,7 @@ static uint32_t assess_splitting_option(struct aec_stream *strm)
} }
state->k = k_min; state->k = k_min;
return len_min; return (uint32_t)len_min;
} }
static uint32_t assess_se_option(struct aec_stream *strm) static uint32_t assess_se_option(struct aec_stream *strm)
...@@ -421,9 +421,9 @@ static uint32_t assess_se_option(struct aec_stream *strm) ...@@ -421,9 +421,9 @@ static uint32_t assess_se_option(struct aec_stream *strm)
If length is above limit just return UINT32_MAX. If length is above limit just return UINT32_MAX.