diff --git a/doc/changelog.md b/doc/changelog.md index 8d92a033..ed191b2f 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -30,6 +30,7 @@ - Added colons to const syntax. - Added double-curly blocks. - Added interfaces. +- Added iterate advance parameter. - Added preprocessor. - Added single-quoted strings. - Added tokens. diff --git a/internal/cgen/base/fundamental-private.h b/internal/cgen/base/fundamental-private.h index 49d52152..f2d035cf 100644 --- a/internal/cgen/base/fundamental-private.h +++ b/internal/cgen/base/fundamental-private.h @@ -85,6 +85,48 @@ wuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) { return z; } +// -------- + +// wuffs_base__iterate_total_advance returns the exclusive pointer-offset at +// which iteration should stop. The overall slice has length total_len, each +// iteration's sub-slice has length iter_len and are placed iter_advance apart. +// +// The iter_advance may not be larger than iter_len. The iter_advance may be +// smaller than iter_len, in which case the sub-slices will overlap. +// +// The return value r satisfies ((0 <= r) && (r <= total_len)). +// +// For example, if total_len = 15, iter_len = 5 and iter_advance = 3, there are +// four iterations at offsets 0, 3, 6 and 9. This function returns 12. +// +// 0123456789012345 +// [....] +// [....] +// [....] +// [....] +// $ +// 0123456789012345 +// +// For example, if total_len = 15, iter_len = 5 and iter_advance = 5, there are +// three iterations at offsets 0, 5 and 10. This function returns 15. +// +// 0123456789012345 +// [....] +// [....] +// [....] +// $ +// 0123456789012345 +static inline size_t // +wuffs_base__iterate_total_advance(size_t total_len, + size_t iter_len, + size_t iter_advance) { + if (total_len >= iter_len) { + size_t n = total_len - iter_len; + return ((n / iter_advance) * iter_advance) + iter_advance; + } + return 0; +} + // ---------------- Numeric Types extern const uint8_t wuffs_base__low_bits_mask__u8[9]; diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index 383f8cde..2015d643 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -35,6 +35,9 @@ const BaseFundamentalPrivateH = "" + "" + "// --------\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__ignore_status(wuffs_base__status z) {\n return wuffs_base__make_empty_struct();\n}\n\nstatic inline wuffs_base__status //\nwuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {\n if (z.repr && (*z.repr == '$')) {\n z.repr = wuffs_base__error__cannot_return_a_suspension;\n }\n return z;\n}\n\n" + "" + + "// --------\n\n// wuffs_base__iterate_total_advance returns the exclusive pointer-offset at\n// which iteration should stop. The overall slice has length total_len, each\n// iteration's sub-slice has length iter_len and are placed iter_advance apart.\n//\n// The iter_advance may not be larger than iter_len. The iter_advance may be\n// smaller than iter_len, in which case the sub-slices will overlap.\n//\n// The return value r satisfies ((0 <= r) && (r <= total_len)).\n//\n// For example, if total_len = 15, iter_len = 5 and iter_advance = 3, there are\n// four iterations at offsets 0, 3, 6 and 9. This function returns 12.\n//\n// 0123456789012345\n// [....]\n// [....]\n// [....]\n// [....]\n// $\n// 0123456789012345\n//\n// For example, if total_len = 15, iter_len = 5 and iter_advance = 5, there are\n// three iterations at offsets 0, 5 and 10. This function returns 15.\n//\n// 0123456789012345\n// [....]\n// [....]\n// [....]\n// $\n// 0123456789012345\nstatic inline size_t //\nwuf" + + "fs_base__iterate_total_advance(size_t total_len,\n size_t iter_len,\n size_t iter_advance) {\n if (total_len >= iter_len) {\n size_t n = total_len - iter_len;\n return ((n / iter_advance) * iter_advance) + iter_advance;\n }\n return 0;\n}\n\n" + + "" + "// ---------------- Numeric Types\n\nextern const uint8_t wuffs_base__low_bits_mask__u8[9];\nextern const uint16_t wuffs_base__low_bits_mask__u16[17];\nextern const uint32_t wuffs_base__low_bits_mask__u32[33];\nextern const uint64_t wuffs_base__low_bits_mask__u64[65];\n\n#define WUFFS_BASE__LOW_BITS_MASK__U8(n) (wuffs_base__low_bits_mask__u8[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U16(n) (wuffs_base__low_bits_mask__u16[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U32(n) (wuffs_base__low_bits_mask__u32[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U64(n) (wuffs_base__low_bits_mask__u64[n])\n\n" + "" + "// --------\n\nstatic inline void //\nwuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_sub(*x, y);\n}\n\n" + diff --git a/internal/cgen/statement.go b/internal/cgen/statement.go index c383ee97..51025fa7 100644 --- a/internal/cgen/statement.go +++ b/internal/cgen/statement.go @@ -424,12 +424,16 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error if err != nil { return err } + advance, err := strconv.Atoi(n.Advance().Str(g.tm)) + if err != nil { + return err + } unroll, err := strconv.Atoi(n.Unroll().Str(g.tm)) if err != nil { return err } for { - if err := g.writeIterateRound(b, assigns, n.Body(), round, depth, length, unroll); err != nil { + if err := g.writeIterateRound(b, assigns, n.Body(), round, depth, length, advance, unroll); err != nil { return err } round++ @@ -570,14 +574,24 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error { return nil } -func (g *gen) writeIterateRound(b *buffer, assigns []*a.Node, body []*a.Node, round uint32, depth uint32, length int, unroll int) error { +func (g *gen) writeIterateRound(b *buffer, assigns []*a.Node, body []*a.Node, round uint32, depth uint32, length int, advance int, unroll int) error { for _, o := range assigns { name := o.AsAssign().LHS().Ident().Str(g.tm) b.printf("%s%s.len = %d;\n", vPrefix, name, length) } name0 := assigns[0].AsAssign().LHS().Ident().Str(g.tm) - b.printf("uint8_t* %send%d_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n", - iPrefix, round, name0, iPrefix, name0, iPrefix, name0, length*unroll, length*unroll) + b.printf("uint8_t* %send%d_%s = %sslice_%s.ptr + ", + iPrefix, round, name0, iPrefix, name0) + if (length == 1) && (advance == 1) && (unroll == 1) { + b.printf("%sslice_%s.len;\n", + iPrefix, name0) + } else if length == advance { + b.printf("((%sslice_%s.len / %d) * %d);\n", + iPrefix, name0, length*unroll, length*unroll) + } else { + b.printf("wuffs_base__iterate_total_advance(%sslice_%s.len, %d, %d);\n", + iPrefix, name0, length*unroll, advance*unroll) + } b.printf("while (%s%s.ptr < %send%d_%s) {\n", vPrefix, name0, iPrefix, round, name0) for i := 0; i < unroll; i++ { for _, o := range body { @@ -587,7 +601,7 @@ func (g *gen) writeIterateRound(b *buffer, assigns []*a.Node, body []*a.Node, ro } for _, o := range assigns { name := o.AsAssign().LHS().Ident().Str(g.tm) - b.printf("%s%s.ptr += %d;\n", vPrefix, name, length) + b.printf("%s%s.ptr += %d;\n", vPrefix, name, advance) } } b.writes("}\n") diff --git a/lang/ast/ast.go b/lang/ast/ast.go index 5b5868c4..fe17c122 100644 --- a/lang/ast/ast.go +++ b/lang/ast/ast.go @@ -170,7 +170,7 @@ type Node struct { // Func funcName receiverPkg receiverName Func // IOBind . . . IOBind // If . . . If - // Iterate unroll label length Iterate + // Iterate advance label length Iterate // Jump keyword label . Jump // Ret keyword . . Ret // Status keyword pkg lit(message) Status @@ -550,12 +550,13 @@ func NewIOBind(keyword t.ID, io *Expr, arg1 *Expr, body []*Node) *IOBind { } // Iterate is -// "iterate.ID1 (assigns)(length:ID2, unroll:ID0), List1 { List2 } else RHS": +// "iterate.ID1 (assigns)(length:ID2, advance:ID0, unroll:LHS), List1 { List2 } else RHS": // - FlagsHasBreak is the iterate has an explicit break // - FlagsHasContinue is the iterate has an explicit continue -// - ID0: unroll +// - ID0: advance // - ID1: <0|label> // - ID2: length +// - LHS: unroll // - RHS: // - List0: assigns // - List1: asserts @@ -566,9 +567,11 @@ func (n *Iterate) AsNode() *Node { return (*Node)(n) } func (n *Iterate) HasBreak() bool { return n.flags&FlagsHasBreak != 0 } func (n *Iterate) HasContinue() bool { return n.flags&FlagsHasContinue != 0 } func (n *Iterate) Keyword() t.ID { return t.IDIterate } -func (n *Iterate) Unroll() t.ID { return n.id0 } +func (n *Iterate) Advance() t.ID { return n.id0 } func (n *Iterate) Label() t.ID { return n.id1 } func (n *Iterate) Length() t.ID { return n.id2 } +func (n *Iterate) Unroll() t.ID { return n.lhs.id2 } +func (n *Iterate) UnrollAsExpr() *Expr { return n.lhs.AsExpr() } func (n *Iterate) ElseIterate() *Iterate { return n.rhs.AsIterate() } func (n *Iterate) Assigns() []*Node { return n.list0 } func (n *Iterate) Asserts() []*Node { return n.list1 } @@ -579,12 +582,13 @@ func (n *Iterate) SetElseIterate(o *Iterate) { n.rhs = o.AsNode() } func (n *Iterate) SetHasBreak() { n.flags |= FlagsHasBreak } func (n *Iterate) SetHasContinue() { n.flags |= FlagsHasContinue } -func NewIterate(label t.ID, assigns []*Node, length t.ID, unroll t.ID, asserts []*Node) *Iterate { +func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t.ID, asserts []*Node) *Iterate { return &Iterate{ kind: KIterate, - id0: unroll, + id0: advance, id1: label, id2: length, + lhs: NewExpr(0, 0, unroll, nil, nil, nil, nil).AsNode(), list0: assigns, list1: asserts, } diff --git a/lang/check/bounds.go b/lang/check/bounds.go index efea8eba..04aee645 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -269,6 +269,9 @@ func (q *checker) bcheckStatement(n *a.Node) error { case a.KIterate: n := n.AsIterate() + if _, err := q.bcheckExpr(n.UnrollAsExpr(), 0); err != nil { + return err + } for _, o := range n.Assigns() { o := o.AsAssign() if err := q.bcheckAssignment(o.LHS(), o.Operator(), o.RHS()); err != nil { @@ -281,6 +284,9 @@ func (q *checker) bcheckStatement(n *a.Node) error { assigns := n.Assigns() for ; n != nil; n = n.ElseIterate() { + if _, err := q.bcheckExpr(n.UnrollAsExpr(), 0); err != nil { + return err + } q.facts = q.facts[:0] for _, o := range assigns { lhs := o.AsAssign().LHS() diff --git a/lang/check/type.go b/lang/check/type.go index 519f35d9..ae9f276a 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -129,6 +129,9 @@ func (q *checker) tcheckStatement(n *a.Node) error { case a.KIterate: for n := n.AsIterate(); n != nil; n = n.ElseIterate() { + if err := q.tcheckExpr(n.UnrollAsExpr(), 0); err != nil { + return err + } for _, o := range n.Assigns() { if err := q.tcheckStatement(o); err != nil { return err diff --git a/lang/parse/parse.go b/lang/parse/parse.go index 6d3c64e0..303d8789 100644 --- a/lang/parse/parse.go +++ b/lang/parse/parse.go @@ -1177,7 +1177,8 @@ func (p *parser) parseIterateBlock(label t.ID, assigns []*a.Node) (*a.Iterate, e p.src = p.src[1:] length := p.peek1() - if !isSmallPositiveInt256(p.tm, length) { + lengthInt := asSmallPositiveInt256(p.tm, length) + if lengthInt == 0 { return nil, fmt.Errorf(`parse: expected length count in [1 ..= 256], got %q at %s:%d`, p.tm.ByID(length), p.filename, p.line()) } @@ -1189,6 +1190,35 @@ func (p *parser) parseIterateBlock(label t.ID, assigns []*a.Node) (*a.Iterate, e } p.src = p.src[1:] + if x := p.peek1(); x != t.IDAdvance { + got := p.tm.ByID(x) + return nil, fmt.Errorf(`parse: expected "advance", got %q at %s:%d`, got, p.filename, p.line()) + } + p.src = p.src[1:] + + if x := p.peek1(); x != t.IDColon { + got := p.tm.ByID(x) + return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line()) + } + p.src = p.src[1:] + + advance := p.peek1() + advanceInt := asSmallPositiveInt256(p.tm, advance) + if advanceInt == 0 { + return nil, fmt.Errorf(`parse: expected advance count in [1 ..= 256], got %q at %s:%d`, + p.tm.ByID(advance), p.filename, p.line()) + } else if advanceInt > lengthInt { + return nil, fmt.Errorf(`parse: advance %d is larger than length %d at %s:%d`, + advanceInt, lengthInt, p.filename, p.line()) + } + p.src = p.src[1:] + + if x := p.peek1(); x != t.IDComma { + got := p.tm.ByID(x) + return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line()) + } + p.src = p.src[1:] + if x := p.peek1(); x != t.IDUnroll { got := p.tm.ByID(x) return nil, fmt.Errorf(`parse: expected "unroll", got %q at %s:%d`, got, p.filename, p.line()) @@ -1202,7 +1232,7 @@ func (p *parser) parseIterateBlock(label t.ID, assigns []*a.Node) (*a.Iterate, e p.src = p.src[1:] unroll := p.peek1() - if !isSmallPositiveInt256(p.tm, unroll) { + if asSmallPositiveInt256(p.tm, unroll) == 0 { return nil, fmt.Errorf(`parse: expected unroll count in [1 ..= 256], got %q at %s:%d`, p.tm.ByID(unroll), p.filename, p.line()) } @@ -1218,7 +1248,7 @@ func (p *parser) parseIterateBlock(label t.ID, assigns []*a.Node) (*a.Iterate, e if err != nil { return nil, err } - n := a.NewIterate(label, assigns, length, unroll, asserts) + n := a.NewIterate(label, assigns, length, advance, unroll, asserts) // TODO: decide how break/continue work with iterate loops. if !p.loops.Push(n) { return nil, fmt.Errorf(`parse: duplicate loop label %s at %s:%d`, @@ -1243,24 +1273,27 @@ func (p *parser) parseIterateBlock(label t.ID, assigns []*a.Node) (*a.Iterate, e return n, nil } -// isSmallPositiveInt256 returns whether id is a numeric literal in the range -// [1 ..= 256]. -func isSmallPositiveInt256(tm *t.Map, id t.ID) bool { +// asSmallPositiveInt256 returns id's value when id is a numeric literal in the +// range [1 ..= 256]. Otherwise, it returns 0. +func asSmallPositiveInt256(tm *t.Map, id t.ID) int { if !id.IsNumLiteral(tm) { - return false + return 0 } s := id.Str(tm) if (len(s) > 3) || (len(s) == 0) || (s[0] < '1') || ('9' < s[0]) { - return false + return 0 } n, s := int(s[0]-'0'), s[1:] for ; len(s) > 0; s = s[1:] { if (s[0] < '0') || ('9' < s[0]) { - return false + return 0 } n = (10 * n) + int(s[0]-'0') } - return n <= 256 + if n > 256 { + return 0 + } + return n } func (p *parser) parseArgNode() (*a.Node, error) { diff --git a/lang/token/list.go b/lang/token/list.go index 81e851da..ae382b6b 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -604,11 +604,13 @@ const ( // -------- 0x200 block. - IDInitialize = ID(0x200) - IDReset = ID(0x201) - IDSet = ID(0x202) - IDUnroll = ID(0x203) - IDUpdate = ID(0x204) + IDAdvance = ID(0x200) + IDInitialize = ID(0x201) + IDLength = ID(0x202) + IDReset = ID(0x203) + IDSet = ID(0x204) + IDUnroll = ID(0x205) + IDUpdate = ID(0x206) // TODO: range/rect methods like intersection and contains? @@ -624,14 +626,13 @@ const ( IDData = ID(0x240) IDHeight = ID(0x241) IDIO = ID(0x242) - IDLength = ID(0x243) - IDLimit = ID(0x244) - IDPrefix = ID(0x245) - IDRow = ID(0x246) - IDStride = ID(0x247) - IDSuffix = ID(0x248) - IDValidUTF8Length = ID(0x249) - IDWidth = ID(0x24A) + IDLimit = ID(0x243) + IDPrefix = ID(0x244) + IDRow = ID(0x245) + IDStride = ID(0x246) + IDSuffix = ID(0x247) + IDValidUTF8Length = ID(0x248) + IDWidth = ID(0x249) IDLimitedSwizzleU32InterleavedFromReader = ID(0x280) IDSwizzleInterleavedFromReader = ID(0x281) @@ -967,7 +968,9 @@ var builtInsByID = [nBuiltInIDs]string{ // -------- 0x200 block. + IDAdvance: "advance", IDInitialize: "initialize", + IDLength: "length", IDReset: "reset", IDSet: "set", IDUnroll: "unroll", @@ -985,7 +988,6 @@ var builtInsByID = [nBuiltInIDs]string{ IDData: "data", IDHeight: "height", IDIO: "io", - IDLength: "length", IDLimit: "limit", IDPrefix: "prefix", IDRow: "row", diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index b2b56d4e..561509a8 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -9162,6 +9162,48 @@ wuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) { return z; } +// -------- + +// wuffs_base__iterate_total_advance returns the exclusive pointer-offset at +// which iteration should stop. The overall slice has length total_len, each +// iteration's sub-slice has length iter_len and are placed iter_advance apart. +// +// The iter_advance may not be larger than iter_len. The iter_advance may be +// smaller than iter_len, in which case the sub-slices will overlap. +// +// The return value r satisfies ((0 <= r) && (r <= total_len)). +// +// For example, if total_len = 15, iter_len = 5 and iter_advance = 3, there are +// four iterations at offsets 0, 3, 6 and 9. This function returns 12. +// +// 0123456789012345 +// [....] +// [....] +// [....] +// [....] +// $ +// 0123456789012345 +// +// For example, if total_len = 15, iter_len = 5 and iter_advance = 5, there are +// three iterations at offsets 0, 5 and 10. This function returns 15. +// +// 0123456789012345 +// [....] +// [....] +// [....] +// $ +// 0123456789012345 +static inline size_t // +wuffs_base__iterate_total_advance(size_t total_len, + size_t iter_len, + size_t iter_advance) { + if (total_len >= iter_len) { + size_t n = total_len - iter_len; + return ((n / iter_advance) * iter_advance) + iter_advance; + } + return 0; +} + // ---------------- Numeric Types extern const uint8_t wuffs_base__low_bits_mask__u8[9]; @@ -16905,7 +16947,7 @@ wuffs_adler32__hasher__update_u32( wuffs_base__slice_u8 i_slice_p = a_x; v_p = i_slice_p; v_p.len = 1; - uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8; + uint8_t* i_end0_p = i_slice_p.ptr + ((i_slice_p.len / 8) * 8); while (v_p.ptr < i_end0_p) { v_s1 += ((uint32_t)(v_p.ptr[0])); v_s2 += v_s1; @@ -16933,7 +16975,7 @@ wuffs_adler32__hasher__update_u32( v_p.ptr += 1; } v_p.len = 1; - uint8_t* i_end1_p = i_slice_p.ptr + (i_slice_p.len / 1) * 1; + uint8_t* i_end1_p = i_slice_p.ptr + i_slice_p.len; while (v_p.ptr < i_end1_p) { v_s1 += ((uint32_t)(v_p.ptr[0])); v_s2 += v_s1; @@ -20805,7 +20847,7 @@ wuffs_crc32__ieee_hasher__update_u32( wuffs_base__slice_u8 i_slice_p = a_x; v_p = i_slice_p; v_p.len = 16; - uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 32) * 32; + uint8_t* i_end0_p = i_slice_p.ptr + ((i_slice_p.len / 32) * 32); while (v_p.ptr < i_end0_p) { v_s ^= ((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) | @@ -20851,7 +20893,7 @@ wuffs_crc32__ieee_hasher__update_u32( v_p.ptr += 16; } v_p.len = 16; - uint8_t* i_end1_p = i_slice_p.ptr + (i_slice_p.len / 16) * 16; + uint8_t* i_end1_p = i_slice_p.ptr + ((i_slice_p.len / 16) * 16); while (v_p.ptr < i_end1_p) { v_s ^= ((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) | @@ -20876,7 +20918,7 @@ wuffs_crc32__ieee_hasher__update_u32( v_p.ptr += 16; } v_p.len = 1; - uint8_t* i_end2_p = i_slice_p.ptr + (i_slice_p.len / 1) * 1; + uint8_t* i_end2_p = i_slice_p.ptr + i_slice_p.len; while (v_p.ptr < i_end2_p) { v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ v_p.ptr[0])] ^ (v_s >> 8)); v_p.ptr += 1; @@ -30111,7 +30153,7 @@ wuffs_png__decoder__filter_1_distance_3_fallback( wuffs_base__slice_u8 i_slice_c = a_curr; v_c = i_slice_c; v_c.len = 3; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 3) * 3; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 3) * 3); while (v_c.ptr < i_end0_c) { v_fa0 += v_c.ptr[0]; v_c.ptr[0] = v_fa0; @@ -30141,7 +30183,7 @@ wuffs_png__decoder__filter_1_distance_4_fallback( wuffs_base__slice_u8 i_slice_c = a_curr; v_c = i_slice_c; v_c.len = 4; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 4) * 4; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 4) * 4); while (v_c.ptr < i_end0_c) { v_fa0 += v_c.ptr[0]; v_c.ptr[0] = v_fa0; @@ -30244,7 +30286,7 @@ wuffs_png__decoder__filter_3_distance_3_fallback( wuffs_base__slice_u8 i_slice_c = a_curr; v_c = i_slice_c; v_c.len = 3; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 3) * 3; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 3) * 3); while (v_c.ptr < i_end0_c) { v_fa0 = ((v_fa0 / 2) + v_c.ptr[0]); v_c.ptr[0] = v_fa0; @@ -30264,7 +30306,7 @@ wuffs_png__decoder__filter_3_distance_3_fallback( i_slice_c.len = ((size_t)(wuffs_base__u64__min(i_slice_c.len, i_slice_p.len))); v_c.len = 3; v_p.len = 3; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 3) * 3; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 3) * 3); while (v_c.ptr < i_end0_c) { v_fa0 = (((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_p.ptr[0]))) / 2))) + v_c.ptr[0]); v_c.ptr[0] = v_fa0; @@ -30299,7 +30341,7 @@ wuffs_png__decoder__filter_3_distance_4_fallback( wuffs_base__slice_u8 i_slice_c = a_curr; v_c = i_slice_c; v_c.len = 4; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 4) * 4; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 4) * 4); while (v_c.ptr < i_end0_c) { v_fa0 = ((v_fa0 / 2) + v_c.ptr[0]); v_c.ptr[0] = v_fa0; @@ -30321,7 +30363,7 @@ wuffs_png__decoder__filter_3_distance_4_fallback( i_slice_c.len = ((size_t)(wuffs_base__u64__min(i_slice_c.len, i_slice_p.len))); v_c.len = 4; v_p.len = 4; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 4) * 4; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 4) * 4); while (v_c.ptr < i_end0_c) { v_fa0 = (((uint8_t)(((((uint32_t)(v_fa0)) + ((uint32_t)(v_p.ptr[0]))) / 2))) + v_c.ptr[0]); v_c.ptr[0] = v_fa0; @@ -30441,7 +30483,7 @@ wuffs_png__decoder__filter_4_distance_3_fallback( i_slice_c.len = ((size_t)(wuffs_base__u64__min(i_slice_c.len, i_slice_p.len))); v_c.len = 3; v_p.len = 3; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 3) * 3; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 3) * 3); while (v_c.ptr < i_end0_c) { v_fb0 = ((uint32_t)(v_p.ptr[0])); v_pp0 = ((v_fa0 + v_fb0) - v_fc0); @@ -30565,7 +30607,7 @@ wuffs_png__decoder__filter_4_distance_4_fallback( i_slice_c.len = ((size_t)(wuffs_base__u64__min(i_slice_c.len, i_slice_p.len))); v_c.len = 4; v_p.len = 4; - uint8_t* i_end0_c = i_slice_c.ptr + (i_slice_c.len / 4) * 4; + uint8_t* i_end0_c = i_slice_c.ptr + ((i_slice_c.len / 4) * 4); while (v_c.ptr < i_end0_c) { v_fb0 = ((uint32_t)(v_p.ptr[0])); v_pp0 = ((v_fa0 + v_fb0) - v_fc0); diff --git a/std/adler32/common_adler32.wuffs b/std/adler32/common_adler32.wuffs index fd3f0783..dd7d66c9 100644 --- a/std/adler32/common_adler32.wuffs +++ b/std/adler32/common_adler32.wuffs @@ -45,7 +45,7 @@ pub func hasher.update_u32!(x: slice base.u8) base.u32 { args.x = args.x[.. 5552] } - iterate (p = args.x)(length: 1, unroll: 8) { + iterate (p = args.x)(length: 1, advance: 1, unroll: 8) { s1 ~mod+= p[0] as base.u32 s2 ~mod+= s1 } diff --git a/std/crc32/common_crc32.wuffs b/std/crc32/common_crc32.wuffs index b695932e..cb94090f 100644 --- a/std/crc32/common_crc32.wuffs +++ b/std/crc32/common_crc32.wuffs @@ -31,7 +31,7 @@ pub func ieee_hasher.update_u32!(x: slice base.u8) base.u32 { // See "Multi-Byte Lookup Tables" in std/crc32/README.md for more detail on // the slicing-by-M algorithm. We use an M of 16. - iterate (p = args.x)(length: 16, unroll: 2) { + iterate (p = args.x)(length: 16, advance: 16, unroll: 2) { s ^= ((p[0x00] as base.u32) << 0) | ((p[0x01] as base.u32) << 8) | ((p[0x02] as base.u32) << 16) | @@ -52,7 +52,7 @@ pub func ieee_hasher.update_u32!(x: slice base.u8) base.u32 { IEEE_TABLE[0x0D][0xFF & (s >> 16)] ^ IEEE_TABLE[0x0E][0xFF & (s >> 8)] ^ IEEE_TABLE[0x0F][0xFF & (s >> 0)] - } else (length: 1, unroll: 1) { + } else (length: 1, advance: 1, unroll: 1) { s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8) } diff --git a/std/png/decode_filter_fallback.wuffs b/std/png/decode_filter_fallback.wuffs index 494bac4f..e6ea0ea5 100644 --- a/std/png/decode_filter_fallback.wuffs +++ b/std/png/decode_filter_fallback.wuffs @@ -43,7 +43,7 @@ pri func decoder.filter_1_distance_3_fallback!(curr: slice base.u8) { var fa1 : base.u8 var fa2 : base.u8 - iterate (c = args.curr)(length: 3, unroll: 1) { + iterate (c = args.curr)(length: 3, advance: 3, unroll: 1) { fa0 ~mod+= c[0] c[0] = fa0 fa1 ~mod+= c[1] @@ -60,7 +60,7 @@ pri func decoder.filter_1_distance_4_fallback!(curr: slice base.u8) { var fa2 : base.u8 var fa3 : base.u8 - iterate (c = args.curr)(length: 4, unroll: 1) { + iterate (c = args.curr)(length: 4, advance: 4, unroll: 1) { fa0 ~mod+= c[0] c[0] = fa0 fa1 ~mod+= c[1] @@ -155,7 +155,7 @@ pri func decoder.filter_3_distance_3_fallback!(curr: slice base.u8, prev: slice var fa2 : base.u8 if args.prev.length() == 0 { - iterate (c = args.curr)(length: 3, unroll: 1) { + iterate (c = args.curr)(length: 3, advance: 3, unroll: 1) { fa0 = (fa0 / 2) ~mod+ c[0] c[0] = fa0 fa1 = (fa1 / 2) ~mod+ c[1] @@ -165,7 +165,7 @@ pri func decoder.filter_3_distance_3_fallback!(curr: slice base.u8, prev: slice } } else { - iterate (c = args.curr, p = args.prev)(length: 3, unroll: 1) { + iterate (c = args.curr, p = args.prev)(length: 3, advance: 3, unroll: 1) { fa0 = ((((fa0 as base.u32) + (p[0] as base.u32)) / 2) as base.u8) ~mod+ c[0] c[0] = fa0 fa1 = ((((fa1 as base.u32) + (p[1] as base.u32)) / 2) as base.u8) ~mod+ c[1] @@ -185,7 +185,7 @@ pri func decoder.filter_3_distance_4_fallback!(curr: slice base.u8, prev: slice var fa3 : base.u8 if args.prev.length() == 0 { - iterate (c = args.curr)(length: 4, unroll: 1) { + iterate (c = args.curr)(length: 4, advance: 4, unroll: 1) { fa0 = (fa0 / 2) ~mod+ c[0] c[0] = fa0 fa1 = (fa1 / 2) ~mod+ c[1] @@ -197,7 +197,7 @@ pri func decoder.filter_3_distance_4_fallback!(curr: slice base.u8, prev: slice } } else { - iterate (c = args.curr, p = args.prev)(length: 4, unroll: 1) { + iterate (c = args.curr, p = args.prev)(length: 4, advance: 4, unroll: 1) { fa0 = ((((fa0 as base.u32) + (p[0] as base.u32)) / 2) as base.u8) ~mod+ c[0] c[0] = fa0 fa1 = ((((fa1 as base.u32) + (p[1] as base.u32)) / 2) as base.u8) ~mod+ c[1] @@ -305,7 +305,7 @@ pri func decoder.filter_4_distance_3_fallback!(curr: slice base.u8, prev: slice var pc1 : base.u32 var pc2 : base.u32 - iterate (c = args.curr, p = args.prev)(length: 3, unroll: 1) { + iterate (c = args.curr, p = args.prev)(length: 3, advance: 3, unroll: 1) { fb0 = p[0] as base.u32 pp0 = (fa0 ~mod+ fb0) ~mod- fc0 pa0 = pp0 ~mod- fa0 @@ -415,7 +415,7 @@ pri func decoder.filter_4_distance_4_fallback!(curr: slice base.u8, prev: slice var pc2 : base.u32 var pc3 : base.u32 - iterate (c = args.curr, p = args.prev)(length: 4, unroll: 1) { + iterate (c = args.curr, p = args.prev)(length: 4, advance: 4, unroll: 1) { fb0 = p[0] as base.u32 pp0 = (fa0 ~mod+ fb0) ~mod- fc0 pa0 = pp0 ~mod- fa0