diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/cmd/wuffs-c/internal/cgen/statement.go index 93a4f74a..5befae89 100644 --- a/cmd/wuffs-c/internal/cgen/statement.go +++ b/cmd/wuffs-c/internal/cgen/statement.go @@ -642,28 +642,25 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia name, name, name) g.currFunk.shortReads = append(g.currFunk.shortReads, name) - b.printf("uint32_t %s%d = %s", tPrefix, temp0, scratchName) + b.printf("uint64_t *scratch = &%s;", scratchName) + b.printf("uint32_t %s%d = *scratch", tPrefix, temp0) switch endianness { case "be": - b.printf("& 0xFF;") - b.printf("%s >>= 8;", scratchName) - b.printf("%s <<= 8;", scratchName) - b.printf("%s |= ((uint64_t)(*ioptr_%s++)) << (56 - %s%d);", - scratchName, name, tPrefix, temp0) + b.writes("& 0xFF; *scratch >>= 8; *scratch <<= 8;") + b.printf("*scratch |= ((uint64_t)(*ioptr_%s++)) << (56 - %s%d);", + name, tPrefix, temp0) case "le": - b.printf(">> 56;") - b.printf("%s <<= 8;", scratchName) - b.printf("%s >>= 8;", scratchName) - b.printf("%s |= ((uint64_t)(*ioptr_%s++)) << %s%d;", - scratchName, name, tPrefix, temp0) + b.writes(">> 56; *scratch <<= 8; *scratch >>= 8;") + b.printf("*scratch |= ((uint64_t)(*ioptr_%s++)) << %s%d;", + name, tPrefix, temp0) } b.printf("if (%s%d == %d) {", tPrefix, temp0, size-8) switch endianness { case "be": - b.printf("%s%d = %s >> (64 - %d);", tPrefix, temp1, scratchName, size) + b.printf("%s%d = *scratch >> (64 - %d);", tPrefix, temp1, size) case "le": - b.printf("%s%d = %s;", tPrefix, temp1, scratchName) + b.printf("%s%d = *scratch;", tPrefix, temp1) } b.printf("break;") b.printf("}") @@ -671,9 +668,9 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia b.printf("%s%d += 8;", tPrefix, temp0) switch endianness { case "be": - b.printf("%s |= ((uint64_t)(%s%d));", scratchName, tPrefix, temp0) + b.printf("*scratch |= ((uint64_t)(%s%d));", tPrefix, temp0) case "le": - b.printf("%s |= ((uint64_t)(%s%d)) << 56;", scratchName, tPrefix, temp0) + b.printf("*scratch |= ((uint64_t)(%s%d)) << 56;", tPrefix, temp0) } b.writes("}}\n") diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index bc61c664..3497a5bd 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -2423,19 +2423,18 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_uncompressed( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_0 = - self->private_impl.c_decode_uncompressed[0].scratch >> 56; - self->private_impl.c_decode_uncompressed[0].scratch <<= 8; - self->private_impl.c_decode_uncompressed[0].scratch >>= 8; - self->private_impl.c_decode_uncompressed[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_0; + uint64_t* scratch = + &self->private_impl.c_decode_uncompressed[0].scratch; + uint32_t t_0 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_0; if (t_0 == 24) { - t_1 = self->private_impl.c_decode_uncompressed[0].scratch; + t_1 = *scratch; break; } t_0 += 8; - self->private_impl.c_decode_uncompressed[0].scratch |= - ((uint64_t)(t_0)) << 56; + *scratch |= ((uint64_t)(t_0)) << 56; } } v_length = t_1; diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 5f8ecf86..a2c48d46 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -2541,17 +2541,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_lsd( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_1 = self->private_impl.c_decode_lsd[0].scratch & 0xFF; - self->private_impl.c_decode_lsd[0].scratch >>= 8; - self->private_impl.c_decode_lsd[0].scratch <<= 8; - self->private_impl.c_decode_lsd[0].scratch |= - ((uint64_t)(*ioptr_src++)) << (56 - t_1); + uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch; + uint32_t t_1 = *scratch & 0xFF; + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_1); if (t_1 == 16) { - t_2 = self->private_impl.c_decode_lsd[0].scratch >> (64 - 24); + t_2 = *scratch >> (64 - 24); break; } t_1 += 8; - self->private_impl.c_decode_lsd[0].scratch |= ((uint64_t)(t_1)); + *scratch |= ((uint64_t)(t_1)); } } v_argb = (t_2 | 4278190080); @@ -2954,18 +2954,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_ae( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_4 = self->private_impl.c_decode_ae[0].scratch >> 56; - self->private_impl.c_decode_ae[0].scratch <<= 8; - self->private_impl.c_decode_ae[0].scratch >>= 8; - self->private_impl.c_decode_ae[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_4; + uint64_t* scratch = &self->private_impl.c_decode_ae[0].scratch; + uint32_t t_4 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_4; if (t_4 == 8) { - t_5 = self->private_impl.c_decode_ae[0].scratch; + t_5 = *scratch; break; } t_4 += 8; - self->private_impl.c_decode_ae[0].scratch |= ((uint64_t)(t_4)) - << 56; + *scratch |= ((uint64_t)(t_4)) << 56; } } self->private_impl.f_num_loops = ((uint32_t)(t_5)); @@ -3090,17 +3089,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_gc( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_2 = self->private_impl.c_decode_gc[0].scratch >> 56; - self->private_impl.c_decode_gc[0].scratch <<= 8; - self->private_impl.c_decode_gc[0].scratch >>= 8; - self->private_impl.c_decode_gc[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_2; + uint64_t* scratch = &self->private_impl.c_decode_gc[0].scratch; + uint32_t t_2 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_2; if (t_2 == 8) { - t_3 = self->private_impl.c_decode_gc[0].scratch; + t_3 = *scratch; break; } t_2 += 8; - self->private_impl.c_decode_gc[0].scratch |= ((uint64_t)(t_2)) << 56; + *scratch |= ((uint64_t)(t_2)) << 56; } } self->private_impl.f_gc_duration = (((uint64_t)(t_3)) * 7056000); @@ -3201,18 +3200,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part0( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_0 = self->private_impl.c_decode_id_part0[0].scratch >> 56; - self->private_impl.c_decode_id_part0[0].scratch <<= 8; - self->private_impl.c_decode_id_part0[0].scratch >>= 8; - self->private_impl.c_decode_id_part0[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_0; + uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch; + uint32_t t_0 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_0; if (t_0 == 8) { - t_1 = self->private_impl.c_decode_id_part0[0].scratch; + t_1 = *scratch; break; } t_0 += 8; - self->private_impl.c_decode_id_part0[0].scratch |= ((uint64_t)(t_0)) - << 56; + *scratch |= ((uint64_t)(t_0)) << 56; } } v_frame_x = ((uint32_t)(t_1)); @@ -3230,18 +3228,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part0( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_2 = self->private_impl.c_decode_id_part0[0].scratch >> 56; - self->private_impl.c_decode_id_part0[0].scratch <<= 8; - self->private_impl.c_decode_id_part0[0].scratch >>= 8; - self->private_impl.c_decode_id_part0[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_2; + uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch; + uint32_t t_2 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_2; if (t_2 == 8) { - t_3 = self->private_impl.c_decode_id_part0[0].scratch; + t_3 = *scratch; break; } t_2 += 8; - self->private_impl.c_decode_id_part0[0].scratch |= ((uint64_t)(t_2)) - << 56; + *scratch |= ((uint64_t)(t_2)) << 56; } } v_frame_y = ((uint32_t)(t_3)); @@ -3266,18 +3263,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part0( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_4 = self->private_impl.c_decode_id_part0[0].scratch >> 56; - self->private_impl.c_decode_id_part0[0].scratch <<= 8; - self->private_impl.c_decode_id_part0[0].scratch >>= 8; - self->private_impl.c_decode_id_part0[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_4; + uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch; + uint32_t t_4 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_4; if (t_4 == 8) { - t_5 = self->private_impl.c_decode_id_part0[0].scratch; + t_5 = *scratch; break; } t_4 += 8; - self->private_impl.c_decode_id_part0[0].scratch |= ((uint64_t)(t_4)) - << 56; + *scratch |= ((uint64_t)(t_4)) << 56; } } v_frame_x += ((uint32_t)(t_5)); @@ -3295,18 +3291,17 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part0( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_6 = self->private_impl.c_decode_id_part0[0].scratch >> 56; - self->private_impl.c_decode_id_part0[0].scratch <<= 8; - self->private_impl.c_decode_id_part0[0].scratch >>= 8; - self->private_impl.c_decode_id_part0[0].scratch |= - ((uint64_t)(*ioptr_src++)) << t_6; + uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch; + uint32_t t_6 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_6; if (t_6 == 8) { - t_7 = self->private_impl.c_decode_id_part0[0].scratch; + t_7 = *scratch; break; } t_6 += 8; - self->private_impl.c_decode_id_part0[0].scratch |= ((uint64_t)(t_6)) - << 56; + *scratch |= ((uint64_t)(t_6)) << 56; } } v_frame_y += ((uint32_t)(t_7)); @@ -3444,20 +3439,18 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id_part1( if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_1 = - self->private_impl.c_decode_id_part1[0].scratch & 0xFF; - self->private_impl.c_decode_id_part1[0].scratch >>= 8; - self->private_impl.c_decode_id_part1[0].scratch <<= 8; - self->private_impl.c_decode_id_part1[0].scratch |= - ((uint64_t)(*ioptr_src++)) << (56 - t_1); + uint64_t* scratch = + &self->private_impl.c_decode_id_part1[0].scratch; + uint32_t t_1 = *scratch & 0xFF; + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_1); if (t_1 == 16) { - t_2 = self->private_impl.c_decode_id_part1[0].scratch >> - (64 - 24); + t_2 = *scratch >> (64 - 24); break; } t_1 += 8; - self->private_impl.c_decode_id_part1[0].scratch |= - ((uint64_t)(t_1)); + *scratch |= ((uint64_t)(t_1)); } } v_argb = (t_2 | 4278190080); diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index e1aa63e1..f426a2e3 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -2341,17 +2341,17 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_4 = self->private_impl.c_decode[0].scratch >> 56; - self->private_impl.c_decode[0].scratch <<= 8; - self->private_impl.c_decode[0].scratch >>= 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(*ioptr_src++)) - << t_4; + uint64_t* scratch = &self->private_impl.c_decode[0].scratch; + uint32_t t_4 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_4; if (t_4 == 8) { - t_5 = self->private_impl.c_decode[0].scratch; + t_5 = *scratch; break; } t_4 += 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_4)) << 56; + *scratch |= ((uint64_t)(t_4)) << 56; } } v_xlen = t_5; @@ -2470,17 +2470,17 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_9 = self->private_impl.c_decode[0].scratch >> 56; - self->private_impl.c_decode[0].scratch <<= 8; - self->private_impl.c_decode[0].scratch >>= 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(*ioptr_src++)) - << t_9; + uint64_t* scratch = &self->private_impl.c_decode[0].scratch; + uint32_t t_9 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_9; if (t_9 == 24) { - t_10 = self->private_impl.c_decode[0].scratch; + t_10 = *scratch; break; } t_9 += 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_9)) << 56; + *scratch |= ((uint64_t)(t_9)) << 56; } } v_checksum_want = t_10; @@ -2498,17 +2498,17 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_11 = self->private_impl.c_decode[0].scratch >> 56; - self->private_impl.c_decode[0].scratch <<= 8; - self->private_impl.c_decode[0].scratch >>= 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(*ioptr_src++)) - << t_11; + uint64_t* scratch = &self->private_impl.c_decode[0].scratch; + uint32_t t_11 = *scratch >> 56; + *scratch <<= 8; + *scratch >>= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << t_11; if (t_11 == 24) { - t_12 = self->private_impl.c_decode[0].scratch; + t_12 = *scratch; break; } t_11 += 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_11)) << 56; + *scratch |= ((uint64_t)(t_11)) << 56; } } v_decoded_length_want = t_12; diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index dea7261b..c8f4ddc5 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -2287,17 +2287,17 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self, if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_0 = self->private_impl.c_decode[0].scratch & 0xFF; - self->private_impl.c_decode[0].scratch >>= 8; - self->private_impl.c_decode[0].scratch <<= 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(*ioptr_src++)) - << (56 - t_0); + uint64_t* scratch = &self->private_impl.c_decode[0].scratch; + uint32_t t_0 = *scratch & 0xFF; + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_0); if (t_0 == 8) { - t_1 = self->private_impl.c_decode[0].scratch >> (64 - 16); + t_1 = *scratch >> (64 - 16); break; } t_0 += 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_0)); + *scratch |= ((uint64_t)(t_0)); } } v_x = t_1; @@ -2366,17 +2366,17 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self, if (WUFFS_BASE__UNLIKELY(ioptr_src == iobounds1_src)) { goto short_read_src; } - uint32_t t_3 = self->private_impl.c_decode[0].scratch & 0xFF; - self->private_impl.c_decode[0].scratch >>= 8; - self->private_impl.c_decode[0].scratch <<= 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(*ioptr_src++)) - << (56 - t_3); + uint64_t* scratch = &self->private_impl.c_decode[0].scratch; + uint32_t t_3 = *scratch & 0xFF; + *scratch >>= 8; + *scratch <<= 8; + *scratch |= ((uint64_t)(*ioptr_src++)) << (56 - t_3); if (t_3 == 24) { - t_4 = self->private_impl.c_decode[0].scratch >> (64 - 32); + t_4 = *scratch >> (64 - 32); break; } t_3 += 8; - self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_3)); + *scratch |= ((uint64_t)(t_3)); } } v_checksum_want = t_4;