mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Add skip32_fast method
This commit is contained in:
1 parent
bb4477d91f
commit
2599476d2c
6 files changed
+75
-24
No files matched your search
@@ -116,6 +116,10 @@ func (g *gen) writeBuiltinIO(b *buffer, recv *a.Expr, method t.ID, args []*a.Nod
|
|||||||
func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, rp replacementPolicy, depth uint32) error {
|
func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []*a.Node, rp replacementPolicy, depth uint32) error {
|
||||||
// TODO: don't hard-code the recv being a_src.
|
// TODO: don't hard-code the recv being a_src.
|
||||||
switch method {
|
switch method {
|
||||||
|
case t.IDPeekU8:
|
||||||
|
b.writes("(*ioptr_src)")
|
||||||
|
return nil
|
||||||
|
|
||||||
case t.IDSetLimit:
|
case t.IDSetLimit:
|
||||||
b.printf("wuffs_base__io_reader__set_limit(&%ssrc, ioptr_src,", aPrefix)
|
b.printf("wuffs_base__io_reader__set_limit(&%ssrc, ioptr_src,", aPrefix)
|
||||||
// TODO: update the ioptr variables?
|
// TODO: update the ioptr variables?
|
||||||
@@ -132,8 +136,16 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
|||||||
aPrefix, aPrefix)
|
aPrefix, aPrefix)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case t.IDPeekU8:
|
case t.IDSkip32Fast:
|
||||||
b.writes("(*ioptr_src)")
|
// Generate a two part expression using the comma operator: "(pointer
|
||||||
|
// increment, return_empty_struct call)". The final part is a function
|
||||||
|
// call (to a static inline function) instead of a struct literal, to
|
||||||
|
// avoid a "expression result unused" compiler error.
|
||||||
|
b.writes("(ioptr_src += ")
|
||||||
|
if err := g.writeExpr(b, args[1].Arg().Value(), rp, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
b.writes(", wuffs_base__return_empty_struct())")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@
|
|||||||
- Redesigned iterate blocks.
|
- Redesigned iterate blocks.
|
||||||
- Added a `base.image_config` type.
|
- Added a `base.image_config` type.
|
||||||
- Added a `reset` method.
|
- Added a `reset` method.
|
||||||
- Added `peek_uxx` methods.
|
- Added `peek_uxx` and `skip32_fast` methods.
|
||||||
- Tweaked how marks and limits work.
|
- Tweaked how marks and limits work.
|
||||||
- Supported animated (not just single frame) GIFs.
|
- Supported animated (not just single frame) GIFs.
|
||||||
- Marked the `std/gif` LZW decoder as private.
|
- Marked the `std/gif` LZW decoder as private.
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ var Funcs = []string{
|
|||||||
"io_reader.read_u64be?()(ret u64)",
|
"io_reader.read_u64be?()(ret u64)",
|
||||||
"io_reader.read_u64le?()(ret u64)",
|
"io_reader.read_u64le?()(ret u64)",
|
||||||
|
|
||||||
// TODO: these methods should have an explicit precondition on "available()
|
// TODO: these should have an explicit precondition "available() >= N". For
|
||||||
// >= N". For now, that's implicitly checked (i.e. hard coded).
|
// now, that's implicitly checked (i.e. hard coded).
|
||||||
"io_reader.peek_u8()(ret u8)",
|
"io_reader.peek_u8()(ret u8)",
|
||||||
"io_reader.peek_u16be()(ret u16)",
|
"io_reader.peek_u16be()(ret u16)",
|
||||||
"io_reader.peek_u16le()(ret u16)",
|
"io_reader.peek_u16le()(ret u16)",
|
||||||
@@ -184,6 +184,12 @@ var Funcs = []string{
|
|||||||
"io_reader.skip32?(n u32)()",
|
"io_reader.skip32?(n u32)()",
|
||||||
"io_reader.skip64?(n u64)()",
|
"io_reader.skip64?(n u64)()",
|
||||||
|
|
||||||
|
// TODO: this should have explicit preconditions "actual <= worst_case" and
|
||||||
|
// "worst_case <= available()". As an implementation restriction, we also
|
||||||
|
// require that worst_case has a constant value. For now, that's all
|
||||||
|
// implicitly checked (i.e. hard coded).
|
||||||
|
"io_reader.skip32_fast!(actual u32, worst_case u32)()",
|
||||||
|
|
||||||
// ---- io_writer
|
// ---- io_writer
|
||||||
|
|
||||||
"io_writer.write_u8?(x u8)()",
|
"io_writer.write_u8?(x u8)()",
|
||||||
|
|||||||
+31
-9
@@ -969,16 +969,38 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (*big.Int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if recvTyp.IsIOType() {
|
} else if recvTyp.IsIOType() {
|
||||||
if method >= t.IDPeekU8 {
|
advance, update := (*big.Int)(nil), false
|
||||||
|
|
||||||
|
if method == t.IDSkip32Fast {
|
||||||
|
args := n.Args()
|
||||||
|
if len(args) != 2 {
|
||||||
|
return nil, nil, fmt.Errorf("check: internal error: bad skip32_fast arguments")
|
||||||
|
}
|
||||||
|
actual := args[0].Arg().Value()
|
||||||
|
worstCase := args[1].Arg().Value()
|
||||||
|
if err := q.proveBinaryOp(t.IDXBinaryLessEq, actual, worstCase); err == errFailed {
|
||||||
|
return nil, nil, fmt.Errorf("check: could not prove skip32_fast precondition: %s <= %s",
|
||||||
|
actual.Str(q.tm), worstCase.Str(q.tm))
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
advance, update = worstCase.ConstValue(), true
|
||||||
|
if advance == nil {
|
||||||
|
return nil, nil, fmt.Errorf("check: skip32_fast worst_case is not a constant value")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if method >= t.IDPeekU8 {
|
||||||
if m := method - t.IDPeekU8; m < t.ID(len(ioMethodAdvances)) {
|
if m := method - t.IDPeekU8; m < t.ID(len(ioMethodAdvances)) {
|
||||||
if advance := ioMethodAdvances[m]; advance != nil {
|
advance, update = ioMethodAdvances[m], false
|
||||||
if ok, err := q.optimizeIOMethodAdvance(recv, advance, false); err != nil {
|
}
|
||||||
return nil, nil, err
|
}
|
||||||
} else if !ok {
|
|
||||||
return nil, nil, fmt.Errorf("check: could not prove %s precondition: %s.available() >= %v",
|
if advance != nil {
|
||||||
method.Str(q.tm), recv.Str(q.tm), advance)
|
if ok, err := q.optimizeIOMethodAdvance(recv, advance, update); err != nil {
|
||||||
}
|
return nil, nil, err
|
||||||
}
|
} else if !ok {
|
||||||
|
return nil, nil, fmt.Errorf("check: could not prove %s precondition: %s.available() >= %v",
|
||||||
|
method.Str(q.tm), recv.Str(q.tm), advance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,6 +224,10 @@ func (q *checker) optimizeSuspendible(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, update bool) (retOK bool, retErr error) {
|
func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, update bool) (retOK bool, retErr error) {
|
||||||
|
// TODO: do two passes? The first one to non-destructively check retOK. The
|
||||||
|
// second one to drop facts if indeed retOK? Otherwise, an advance
|
||||||
|
// precondition failure will lose some of the facts in its error message.
|
||||||
|
|
||||||
retErr = q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
retErr = q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||||
// TODO: update (discard?) any facts that merely mention
|
// TODO: update (discard?) any facts that merely mention
|
||||||
// receiver.available(), even if they aren't an exact match.
|
// receiver.available(), even if they aren't an exact match.
|
||||||
@@ -271,6 +275,11 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, up
|
|||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rcv.Cmp(advance) == 0 {
|
||||||
|
// TODO: delete the (adjusted) fact, as newRCV will be zero, and
|
||||||
|
// "foo.advance() >= 0" is redundant.
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new a.Expr to hold the adjusted RHS constant value, newRCV.
|
// Create a new a.Expr to hold the adjusted RHS constant value, newRCV.
|
||||||
newRCV := big.NewInt(0).Sub(rcv, advance)
|
newRCV := big.NewInt(0).Sub(rcv, advance)
|
||||||
id, err := q.tm.Insert(newRCV.String())
|
id, err := q.tm.Insert(newRCV.String())
|
||||||
|
|||||||
+12
-10
@@ -494,11 +494,12 @@ const (
|
|||||||
IDWriteU64BE = ID(0x16E)
|
IDWriteU64BE = ID(0x16E)
|
||||||
IDWriteU64LE = ID(0x16F)
|
IDWriteU64LE = ID(0x16F)
|
||||||
|
|
||||||
IDSetLimit = ID(0x180)
|
IDSetLimit = ID(0x180)
|
||||||
IDSetMark = ID(0x181)
|
IDSetMark = ID(0x181)
|
||||||
IDSinceMark = ID(0x182)
|
IDSinceMark = ID(0x182)
|
||||||
IDSkip32 = ID(0x183)
|
IDSkip32 = ID(0x183)
|
||||||
IDSkip64 = ID(0x184)
|
IDSkip32Fast = ID(0x184)
|
||||||
|
IDSkip64 = ID(0x185)
|
||||||
|
|
||||||
IDCopyFromHistory32 = ID(0x190)
|
IDCopyFromHistory32 = ID(0x190)
|
||||||
IDCopyFromReader32 = ID(0x191)
|
IDCopyFromReader32 = ID(0x191)
|
||||||
@@ -751,11 +752,12 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDWriteU64BE: "write_u64be",
|
IDWriteU64BE: "write_u64be",
|
||||||
IDWriteU64LE: "write_u64le",
|
IDWriteU64LE: "write_u64le",
|
||||||
|
|
||||||
IDSetLimit: "set_limit",
|
IDSetLimit: "set_limit",
|
||||||
IDSetMark: "set_mark",
|
IDSetMark: "set_mark",
|
||||||
IDSinceMark: "since_mark",
|
IDSinceMark: "since_mark",
|
||||||
IDSkip32: "skip32",
|
IDSkip32: "skip32",
|
||||||
IDSkip64: "skip64",
|
IDSkip32Fast: "skip32_fast",
|
||||||
|
IDSkip64: "skip64",
|
||||||
|
|
||||||
IDCopyFromHistory32: "copy_from_history32",
|
IDCopyFromHistory32: "copy_from_history32",
|
||||||
IDCopyFromReader32: "copy_from_reader32",
|
IDCopyFromReader32: "copy_from_reader32",
|
||||||
|
|||||||
Reference in new issue
Block a user