Commit bd88807b authored by Mathis Rosenhauer's avatar Mathis Rosenhauer Committed by Thomas Jahns

turn emitblock macro into function

parent 2fbc4ad9
...@@ -159,101 +159,96 @@ static inline void copy64(uint8_t *dst, uint64_t src) ...@@ -159,101 +159,96 @@ static inline void copy64(uint8_t *dst, uint64_t src)
EMITBLOCK_FS(0); EMITBLOCK_FS(0);
EMITBLOCK_FS(1); EMITBLOCK_FS(1);
#define EMITBLOCK(ref) \ static inline void emitblock(struct aec_stream *strm, int k, int ref)
static inline void emitblock_##ref(struct aec_stream *strm, \ {
int k) \ /**
{ \ Emit the k LSB of a whole block of input data.
/** \ */
Emit the k LSB of a whole block of input data. \
*/ \ uint64_t a;
\ struct internal_state *state = strm->state;
uint64_t a; \ uint32_t *in = state->block + ref;
struct internal_state *state = strm->state; \ uint32_t *in_end = state->block + strm->block_size;
uint32_t *in = state->block + ref; \ uint64_t mask = (1ULL << k) - 1;
uint32_t *in_end = state->block + strm->block_size; \ uint8_t *o = state->cds;
uint64_t mask = (1ULL << k) - 1; \ int p = state->bits;
uint8_t *o = state->cds; \
int p = state->bits; \ a = *o;
\
a = *o; \ while(in < in_end) {
\ a <<= 56;
while(in < in_end) { \ p = (p % 8) + 56;
a <<= 56; \
p = (p % 8) + 56; \ while (p > k && in < in_end) {
\ p -= k;
while (p > k && in < in_end) { \ a += ((uint64_t)(*in++) & mask) << p;
p -= k; \ }
a += ((uint64_t)(*in++) & mask) << p; \
} \ switch (p & ~ 7) {
\ case 0:
switch (p & ~ 7) { \ o[0] = a >> 56;
case 0: \ o[1] = a >> 48;
o[0] = a >> 56; \ o[2] = a >> 40;
o[1] = a >> 48; \ o[3] = a >> 32;
o[2] = a >> 40; \ o[4] = a >> 24;
o[3] = a >> 32; \ o[5] = a >> 16;
o[4] = a >> 24; \ o[6] = a >> 8;
o[5] = a >> 16; \ o += 7;
o[6] = a >> 8; \ break;
o += 7; \ case 8:
break; \ o[0] = a >> 56;
case 8: \ o[1] = a >> 48;
o[0] = a >> 56; \ o[2] = a >> 40;
o[1] = a >> 48; \ o[3] = a >> 32;
o[2] = a >> 40; \ o[4] = a >> 24;
o[3] = a >> 32; \ o[5] = a >> 16;
o[4] = a >> 24; \ a >>= 8;
o[5] = a >> 16; \ o += 6;
a >>= 8; \ break;
o += 6; \ case 16:
break; \ o[0] = a >> 56;
case 16: \ o[1] = a >> 48;
o[0] = a >> 56; \ o[2] = a >> 40;
o[1] = a >> 48; \ o[3] = a >> 32;
o[2] = a >> 40; \ o[4] = a >> 24;
o[3] = a >> 32; \ a >>= 16;
o[4] = a >> 24; \ o += 5;
a >>= 16; \ break;
o += 5; \ case 24:
break; \ o[0] = a >> 56;
case 24: \ o[1] = a >> 48;
o[0] = a >> 56; \ o[2] = a >> 40;
o[1] = a >> 48; \ o[3] = a >> 32;
o[2] = a >> 40; \ a >>= 24;
o[3] = a >> 32; \ o += 4;
a >>= 24; \ break;
o += 4; \ case 32:
break; \ o[0] = a >> 56;
case 32: \ o[1] = a >> 48;
o[0] = a >> 56; \ o[2] = a >> 40;
o[1] = a >> 48; \ a >>= 32;
o[2] = a >> 40; \ o += 3;
a >>= 32; \ break;
o += 3; \ case 40:
break; \ o[0] = a >> 56;
case 40: \ o[1] = a >> 48;
o[0] = a >> 56; \ a >>= 40;
o[1] = a >> 48; \ o += 2;
a >>= 40; \ break;
o += 2; \ case 48:
break; \ *o++ = a >> 56;
case 48: \ a >>= 48;
*o++ = a >> 56; \ break;
a >>= 48; \ default:
break; \ a >>= 56;
default: \ break;
a >>= 56; \ }
break; \
} \
} \
\
*o = a; \
state->cds = o; \
state->bits = p % 8; \
} }
EMITBLOCK(0); *o = a;
EMITBLOCK(1); state->cds = o;
state->bits = p % 8;
}
static void preprocess_unsigned(struct aec_stream *strm) static void preprocess_unsigned(struct aec_stream *strm)
{ {
...@@ -559,13 +554,13 @@ static int m_encode_splitting(struct aec_stream *strm) ...@@ -559,13 +554,13 @@ static int m_encode_splitting(struct aec_stream *strm)
emit(state, state->block[0], strm->bits_per_sample); emit(state, state->block[0], strm->bits_per_sample);
emitblock_fs_1(strm, k); emitblock_fs_1(strm, k);
if (k) if (k)
emitblock_1(strm, k); emitblock(strm, k, 1);
} }
else else
{ {
emitblock_fs_0(strm, k); emitblock_fs_0(strm, k);
if (k) if (k)
emitblock_0(strm, k); emitblock(strm, k, 0);
} }
return m_flush_block(strm); return m_flush_block(strm);
...@@ -576,7 +571,7 @@ static int m_encode_uncomp(struct aec_stream *strm) ...@@ -576,7 +571,7 @@ static int m_encode_uncomp(struct aec_stream *strm)
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
emit(state, (1U << state->id_len) - 1, state->id_len); emit(state, (1U << state->id_len) - 1, state->id_len);
emitblock_0(strm, strm->bits_per_sample); emitblock(strm, strm->bits_per_sample, 0);
return m_flush_block(strm); return m_flush_block(strm);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment