Call copy_from32 in a trival 1-iteration loop.

Follow-up commits will re-try copy_from32's across I/O boundaries.
This commit is contained in:
Nigel Tao committed 2017-10-07 11:50:50 +11:00
1 parent 2efdf5fab6
commit 0e09aa8c10
3 files changed
+40 -31

No files matched your search

+31 -26
View File
@@ -182,7 +182,7 @@ typedef struct {
} c_decode_blocks[1]; } c_decode_blocks[1];
struct { struct {
uint32_t coro_susp_point; uint32_t coro_susp_point;
uint32_t v_n; uint32_t v_length;
uint64_t scratch; uint64_t scratch;
} c_decode_uncompressed[1]; } c_decode_uncompressed[1];
struct { struct {
@@ -960,7 +960,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
puffs_base_reader1 a_src) { puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint32_t v_n; uint32_t v_length;
uint8_t* b_wptr_dst = NULL; uint8_t* b_wptr_dst = NULL;
uint8_t* b_wstart_dst = NULL; uint8_t* b_wstart_dst = NULL;
@@ -996,7 +996,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
uint32_t coro_susp_point = uint32_t coro_susp_point =
self->private_impl.c_decode_uncompressed[0].coro_susp_point; self->private_impl.c_decode_uncompressed[0].coro_susp_point;
if (coro_susp_point) { if (coro_susp_point) {
v_n = self->private_impl.c_decode_uncompressed[0].v_n; v_length = self->private_impl.c_decode_uncompressed[0].v_length;
} }
switch (coro_susp_point) { switch (coro_susp_point) {
PUFFS_COROUTINE_SUSPENSION_POINT(0); PUFFS_COROUTINE_SUSPENSION_POINT(0);
@@ -1033,33 +1033,38 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
<< 56; << 56;
} }
} }
v_n = t_1; v_length = t_1;
if ((((v_n) & ((1 << (16)) - 1)) + ((v_n) >> (32 - (16)))) != 65535) { if ((((v_length) & ((1 << (16)) - 1)) + ((v_length) >> (32 - (16)))) !=
65535) {
status = PUFFS_FLATE_ERROR_INCONSISTENT_STORED_BLOCK_LENGTH; status = PUFFS_FLATE_ERROR_INCONSISTENT_STORED_BLOCK_LENGTH;
goto exit; goto exit;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(3); v_length = ((v_length) & ((1 << (16)) - 1));
{ while (v_length > 0) {
self->private_impl.c_decode_uncompressed[0].scratch = PUFFS_COROUTINE_SUSPENSION_POINT(3);
((v_n) & ((1 << (16)) - 1)); {
PUFFS_COROUTINE_SUSPENSION_POINT(4); self->private_impl.c_decode_uncompressed[0].scratch = v_length;
size_t t_2 = self->private_impl.c_decode_uncompressed[0].scratch; PUFFS_COROUTINE_SUSPENSION_POINT(4);
if (t_2 > b_wend_dst - b_wptr_dst) { size_t t_2 = self->private_impl.c_decode_uncompressed[0].scratch;
t_2 = b_wend_dst - b_wptr_dst; if (t_2 > b_wend_dst - b_wptr_dst) {
status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE; t_2 = b_wend_dst - b_wptr_dst;
} status = PUFFS_FLATE_SUSPENSION_SHORT_WRITE;
if (t_2 > b_rend_src - b_rptr_src) { }
t_2 = b_rend_src - b_rptr_src; if (t_2 > b_rend_src - b_rptr_src) {
status = PUFFS_FLATE_SUSPENSION_SHORT_READ; t_2 = b_rend_src - b_rptr_src;
} status = PUFFS_FLATE_SUSPENSION_SHORT_READ;
memmove(b_wptr_dst, b_rptr_src, t_2); }
b_wptr_dst += t_2; memmove(b_wptr_dst, b_rptr_src, t_2);
b_rptr_src += t_2; b_wptr_dst += t_2;
if (status) { b_rptr_src += t_2;
self->private_impl.c_decode_uncompressed[0].scratch -= t_2; if (status) {
goto suspend; self->private_impl.c_decode_uncompressed[0].scratch -= t_2;
goto suspend;
}
} }
goto label_0_break;
} }
label_0_break:;
self->private_impl.c_decode_uncompressed[0].coro_susp_point = 0; self->private_impl.c_decode_uncompressed[0].coro_susp_point = 0;
goto exit; goto exit;
} }
@@ -1067,7 +1072,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
goto suspend; goto suspend;
suspend: suspend:
self->private_impl.c_decode_uncompressed[0].coro_susp_point = coro_susp_point; self->private_impl.c_decode_uncompressed[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode_uncompressed[0].v_n = v_n; self->private_impl.c_decode_uncompressed[0].v_length = v_length;
exit: exit:
if (a_dst.buf) { if (a_dst.buf) {
+1 -1
View File
@@ -182,7 +182,7 @@ typedef struct {
} c_decode_blocks[1]; } c_decode_blocks[1];
struct { struct {
uint32_t coro_susp_point; uint32_t coro_susp_point;
uint32_t v_n; uint32_t v_length;
uint64_t scratch; uint64_t scratch;
} c_decode_uncompressed[1]; } c_decode_uncompressed[1];
struct { struct {
+8 -4
View File
@@ -187,12 +187,16 @@ pri func decoder.decode_uncompressed?(dst writer1, src reader1)() {
} }
this.n_bits = 0 this.n_bits = 0
var n u32 = in.src.read_u32le?() var length u32 = in.src.read_u32le?()
if (n.low_bits(n:16) + n.high_bits(n:16)) != 0xFFFF { if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
return error "inconsistent stored block length" return error "inconsistent stored block length"
} }
// TODO: drop the "?" from "copy_from32?"? length = length.low_bits(n:16)
in.dst.copy_from32?(r:in.src, n:n.low_bits(n:16)) while length > 0 {
// TODO: drop the "?" from "copy_from32?"?
in.dst.copy_from32?(r:in.src, n:length)
break
}
} }
pri func decoder.decode_huffman?(dst writer1, src reader1)() { pri func decoder.decode_huffman?(dst writer1, src reader1)() {