golomb_coding is always followed by a encode call. Simplify code calling directly it, no reason to pass back output using pointers. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- common/quic.c | 2 ++ common/quic_family_tmpl.c | 6 ++---- common/quic_rgb_tmpl.c | 43 ++++++++++++--------------------------- common/quic_tmpl.c | 39 ++++++++++------------------------- 4 files changed, 28 insertions(+), 62 deletions(-) diff --git a/common/quic.c b/common/quic.c index 90aac85..04f3999 100644 --- a/common/quic.c +++ b/common/quic.c @@ -93,6 +93,8 @@ typedef struct s_bucket { typedef struct Encoder Encoder; +static inline void encode(Encoder *encoder, unsigned int word, unsigned int len); + typedef struct CommonState { unsigned int waitcnt; unsigned int tabrand_seed; diff --git a/common/quic_family_tmpl.c b/common/quic_family_tmpl.c index cda15bd..70fe758 100644 --- a/common/quic_family_tmpl.c +++ b/common/quic_family_tmpl.c @@ -44,11 +44,9 @@ static inline unsigned int FNAME(golomb_code_len)(const BYTE n, const unsigned i return VNAME(family).golomb_code_len[n][l]; } -static void FNAME(golomb_coding)(const BYTE n, const unsigned int l, unsigned int * const codeword, - unsigned int * const codewordlen) +static void FNAME(golomb_coding)(Encoder *encoder, const BYTE n, const unsigned int l) { - *codeword = FNAME(golomb_code)(n, l); - *codewordlen = FNAME(golomb_code_len)(n, l); + encode(encoder, FNAME(golomb_code)(n, l), FNAME(golomb_code_len)(n, l)); } static unsigned int FNAME(golomb_decoding)(const unsigned int l, const unsigned int bits, diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c index 4800ece..e0a05ca 100644 --- a/common/quic_rgb_tmpl.c +++ b/common/quic_rgb_tmpl.c @@ -130,19 +130,15 @@ (int)((_PIXEL_A(channel, curr) + _PIXEL_B(channel, prev)) >> 1)) & bpc_mask)) -#define COMPRESS_ONE_ROW0_0(channel) \ - correlate_row_##channel[0] = family.xlatU2L[GET_##channel(cur_row)]; \ - golomb_coding(correlate_row_##channel[0], find_bucket(channel_##channel, \ - correlate_row_##channel[-1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); - -#define COMPRESS_ONE_ROW0(channel, index) \ - correlate_row_##channel[index] = DECORRELATE_0(channel, &cur_row[index], bpc_mask); \ - golomb_coding(correlate_row_##channel[index], find_bucket(channel_##channel, \ - correlate_row_##channel[index -1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); +#define COMPRESS_ONE_ROW0_0(channel) \ + correlate_row_##channel[0] = family.xlatU2L[GET_##channel(cur_row)]; \ + golomb_coding(encoder, correlate_row_##channel[0], find_bucket(channel_##channel, \ + correlate_row_##channel[-1])->bestcode) + +#define COMPRESS_ONE_ROW0(channel, index) \ + correlate_row_##channel[index] = DECORRELATE_0(channel, &cur_row[index], bpc_mask); \ + golomb_coding(encoder, correlate_row_##channel[index], find_bucket(channel_##channel, \ + correlate_row_##channel[index -1])->bestcode) #define UPDATE_MODEL(index) \ update_model(state, find_bucket(channel_r, correlate_row_r[index - 1]), \ @@ -182,8 +178,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i, spice_assert(end - i > 0); if (i == 0) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_ROW0_0(r); COMPRESS_ONE_ROW0_0(g); COMPRESS_ONE_ROW0_0(b); @@ -201,7 +195,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i, while (stopidx < end) { for (; i <= stopidx; i++) { - unsigned int codeword, codewordlen; COMPRESS_ONE_ROW0(r, i); COMPRESS_ONE_ROW0(g, i); COMPRESS_ONE_ROW0(b, i); @@ -212,8 +205,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, int i, } for (; i < end; i++) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_ROW0(r, i); COMPRESS_ONE_ROW0(g, i); COMPRESS_ONE_ROW0(b, i); @@ -258,18 +249,14 @@ static void FNAME(compress_row0)(Encoder *encoder, const PIXEL *cur_row, #define COMPRESS_ONE_0(channel) \ correlate_row_##channel[0] = family.xlatU2L[(unsigned)((int)GET_##channel(cur_row) - \ (int)GET_##channel(prev_row) ) & bpc_mask]; \ - golomb_coding(correlate_row_##channel[0], \ - find_bucket(channel_##channel, correlate_row_##channel[-1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); + golomb_coding(encoder, correlate_row_##channel[0], \ + find_bucket(channel_##channel, correlate_row_##channel[-1])->bestcode) #define COMPRESS_ONE(channel, index) \ DECORRELATE(channel, &prev_row[index], &cur_row[index],bpc_mask, \ correlate_row_##channel[index]); \ - golomb_coding(correlate_row_##channel[index], \ - find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); + golomb_coding(encoder, correlate_row_##channel[index], \ + find_bucket(channel_##channel, correlate_row_##channel[index - 1])->bestcode) static void FNAME(compress_row_seg)(Encoder *encoder, int i, const PIXEL * const prev_row, @@ -294,8 +281,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i, spice_assert(end - i > 0); if (i == 0) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_0(r); COMPRESS_ONE_0(g); COMPRESS_ONE_0(b); @@ -313,7 +298,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i, for (;;) { while (stopidx < end) { for (; i <= stopidx; i++) { - unsigned int codeword, codewordlen; RLE_PRED_IMP; COMPRESS_ONE(r, i); COMPRESS_ONE(g, i); @@ -325,7 +309,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, int i, } for (; i < end; i++) { - unsigned int codeword, codewordlen; RLE_PRED_IMP; COMPRESS_ONE(r, i); COMPRESS_ONE(g, i); diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c index dc2f81b..8069909 100644 --- a/common/quic_tmpl.c +++ b/common/quic_tmpl.c @@ -82,19 +82,15 @@ static inline void FNAME(correlate)(const PIXEL *prev, PIXEL *curr, const BYTE c #define COMPRESS_ONE_ROW0_0(channel) \ channel->correlate_row[0] = family.xlatU2L[cur_row->a]; \ - golomb_coding(channel->correlate_row[0], \ + golomb_coding(encoder, channel->correlate_row[0], \ find_bucket(channel, \ - channel->correlate_row[-1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); + channel->correlate_row[-1])->bestcode) #define COMPRESS_ONE_ROW0(channel, index) \ channel->correlate_row[index] = FNAME(decorrelate_0)(&cur_row[index], bpc_mask); \ - golomb_coding(channel->correlate_row[index], \ + golomb_coding(encoder, channel->correlate_row[index], \ find_bucket(channel, \ - channel->correlate_row[index - 1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); + channel->correlate_row[index - 1])->bestcode) #define UPDATE_MODEL(index) \ update_model(state, find_bucket(channel, channel->correlate_row[index - 1]), \ @@ -113,8 +109,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i, spice_assert(end - i > 0); if (i == 0) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_ROW0_0(channel); if (state->waitcnt) { @@ -130,7 +124,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i, while (stopidx < end) { for (; i <= stopidx; i++) { - unsigned int codeword, codewordlen; COMPRESS_ONE_ROW0(channel, i); } @@ -139,8 +132,6 @@ static void FNAME(compress_row0_seg)(Encoder *encoder, Channel *channel, int i, } for (; i < end; i++) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_ROW0(channel, i); } state->waitcnt = stopidx - end; @@ -186,17 +177,13 @@ static void FNAME(compress_row0)(Encoder *encoder, Channel *channel, const PIXEL #define COMPRESS_ONE_0(channel) \ channel->correlate_row[0] = family.xlatU2L[(unsigned)((int)GET_a(cur_row) - \ (int)GET_a(prev_row) ) & bpc_mask]; \ - golomb_coding(channel->correlate_row[0], \ - find_bucket(channel, channel->correlate_row[-1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); - -#define COMPRESS_ONE(channel, index) \ - channel->correlate_row[index] = FNAME(decorrelate)(&prev_row[index], &cur_row[index], bpc_mask); \ - golomb_coding(channel->correlate_row[index], \ - find_bucket(channel, channel->correlate_row[index - 1])->bestcode, \ - &codeword, &codewordlen); \ - encode(encoder, codeword, codewordlen); + golomb_coding(encoder, channel->correlate_row[0], \ + find_bucket(channel, channel->correlate_row[-1])->bestcode) + +#define COMPRESS_ONE(channel, index) \ + channel->correlate_row[index] = FNAME(decorrelate)(&prev_row[index], &cur_row[index], bpc_mask); \ + golomb_coding(encoder, channel->correlate_row[index], \ + find_bucket(channel, channel->correlate_row[index - 1])->bestcode) static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i, const PIXEL * const prev_row, @@ -214,8 +201,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i, spice_assert(end - i > 0); if (i == 0) { - unsigned int codeword, codewordlen; - COMPRESS_ONE_0(channel); if (state->waitcnt) { @@ -232,7 +217,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i, for (;;) { while (stopidx < end) { for (; i <= stopidx; i++) { - unsigned int codeword, codewordlen; RLE_PRED_IMP; COMPRESS_ONE(channel, i); } @@ -242,7 +226,6 @@ static void FNAME(compress_row_seg)(Encoder *encoder, Channel *channel, int i, } for (; i < end; i++) { - unsigned int codeword, codewordlen; RLE_PRED_IMP; COMPRESS_ONE(channel, i); } -- 2.17.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel