Pull out duplicate short_read_src code.

name                          old speed      new speed       delta
lzw_puffs_decode_20k/clang     127MB/s ± 0%    127MB/s ± 0%  +0.40%  (p=0.008 n=5+5)
lzw_puffs_decode_100k/clang    176MB/s ± 0%    176MB/s ± 0%  +0.23%  (p=0.008 n=5+5)
gif_puffs_decode_1k/clang      380MB/s ± 1%    389MB/s ± 2%  +2.26%  (p=0.008 n=5+5)
gif_puffs_decode_10k/clang     136MB/s ± 0%    137MB/s ± 0%  +0.59%  (p=0.016 n=4+5)
gif_puffs_decode_100k/clang    121MB/s ± 0%    121MB/s ± 0%  +0.33%  (p=0.008 n=5+5)
gif_puffs_decode_1000k/clang   124MB/s ± 0%    124MB/s ± 0%  +0.25%  (p=0.008 n=5+5)
lzw_puffs_decode_20k/gcc       150MB/s ± 1%    151MB/s ± 0%  +0.97%  (p=0.008 n=5+5)
lzw_puffs_decode_100k/gcc      207MB/s ± 0%    197MB/s ± 0%  -4.84%  (p=0.008 n=5+5)
gif_puffs_decode_1k/gcc        413MB/s ± 1%    406MB/s ± 1%  -1.71%  (p=0.008 n=5+5)
gif_puffs_decode_10k/gcc       147MB/s ± 0%    158MB/s ± 0%  +7.15%  (p=0.008 n=5+5)
gif_puffs_decode_100k/gcc      136MB/s ± 0%    138MB/s ± 0%  +1.68%  (p=0.008 n=5+5)
gif_puffs_decode_1000k/gcc     139MB/s ± 0%    142MB/s ± 0%  +2.07%  (p=0.008 n=5+5)
This commit is contained in:
Nigel Tao committed 2017-07-02 16:11:51 +10:00
1 parent d974988eab
commit 187bde7540
4 files changed
+105 -72

No files matched your search

+68 -60
View File
@@ -250,6 +250,14 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
#define PUFFS_LOW_BITS(x, n) ((x) & ((1 << (n)) - 1))
#if defined(__clang__) || defined(__GNUC__)
#define PUFFS_LIKELY(expr) (__builtin_expect((expr), 1))
#define PUFFS_UNLIKELY(expr) (__builtin_expect((expr), 0))
#else
#define PUFFS_LIKELY(expr) (expr)
#define PUFFS_UNLIKELY(expr) (expr)
#endif
#endif // PUFFS_BASE_IMPL_H
// ---------------- Status Codes Implementations
@@ -466,11 +474,8 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
}
while (true) {
PUFFS_COROUTINE_STATE(3);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
goto suspend;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_c = t_0;
@@ -559,6 +564,12 @@ suspend:
exit:
self->private_impl.status = status;
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
goto suspend;
}
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
@@ -599,11 +610,8 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
v_i = 0;
while (v_i < 6) {
PUFFS_COROUTINE_STATE(1);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_c[v_i] = t_0;
@@ -636,6 +644,12 @@ suspend:
goto exit;
exit:
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
}
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
@@ -678,11 +692,8 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
v_i = 0;
while (v_i < 7) {
PUFFS_COROUTINE_STATE(1);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_c[v_i] = t_0;
@@ -698,29 +709,20 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
v_i = 0;
while (v_i < v_gct_size) {
PUFFS_COROUTINE_STATE(2);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_1 = *b_rptr_src++;
self->private_impl.f_gct[(3 * v_i) + 0] = t_1;
PUFFS_COROUTINE_STATE(3);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_2 = *b_rptr_src++;
self->private_impl.f_gct[(3 * v_i) + 1] = t_2;
PUFFS_COROUTINE_STATE(4);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_3 = *b_rptr_src++;
self->private_impl.f_gct[(3 * v_i) + 2] = t_3;
@@ -751,6 +753,12 @@ suspend:
goto exit;
exit:
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
}
puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
@@ -783,11 +791,8 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
PUFFS_COROUTINE_STATE(0);
PUFFS_COROUTINE_STATE(1);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_label = t_0;
@@ -800,11 +805,8 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
}
while (true) {
PUFFS_COROUTINE_STATE(2);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_1 = *b_rptr_src++;
v_block_size = t_1;
@@ -846,6 +848,12 @@ suspend:
goto exit;
exit:
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
}
puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
@@ -897,11 +905,8 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
v_i = 0;
while (v_i < 9) {
PUFFS_COROUTINE_STATE(1);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_c[v_i] = t_0;
@@ -914,11 +919,8 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
return puffs_gif_error_todo_unsupported_local_color_table;
}
PUFFS_COROUTINE_STATE(2);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_1 = *b_rptr_src++;
v_lw = t_1;
@@ -929,11 +931,8 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
((uint32_t)(v_lw)));
while (true) {
PUFFS_COROUTINE_STATE(3);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_2 = *b_rptr_src++;
v_block_size = t_2;
@@ -1003,6 +1002,12 @@ suspend:
goto exit;
exit:
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
return status;
}
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
@@ -1105,11 +1110,8 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
while (true) {
while (v_n_bits < v_width) {
PUFFS_COROUTINE_STATE(1);
if (b_rptr_src == b_rend_src) {
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
goto suspend;
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
goto short_read_src;
}
uint8_t t_0 = *b_rptr_src++;
v_bits |= (((uint32_t)(t_0)) << v_n_bits);
@@ -1230,4 +1232,10 @@ suspend:
exit:
self->private_impl.status = status;
return status;
short_read_src:
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
? puffs_gif_error_unexpected_eof
: puffs_gif_status_short_read;
goto suspend;
}