mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
cgen: emit "break/continue" not "goto", part 1
name old speed new speed delta wuffs_jpeg_decode_19k_8bpp/clang11 229MB/s ± 0% 241MB/s ± 0% +5.29% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/clang11 205MB/s ± 0% 213MB/s ± 0% +3.89% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/clang11 375MB/s ± 0% 386MB/s ± 0% +3.01% (p=0.008 n=5+5) wuffs_jpeg_decode_77k_24bpp/clang11 326MB/s ± 0% 341MB/s ± 0% +4.80% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_420/clang11 339MB/s ± 0% 356MB/s ± 0% +5.14% (p=0.008 n=5+5) wuffs_jpeg_decode_552k_24bpp_444/clang11 475MB/s ± 0% 484MB/s ± 0% +2.04% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/clang11 343MB/s ± 0% 362MB/s ± 0% +5.77% (p=0.008 n=5+5) wuffs_jpeg_decode_19k_8bpp/gcc10 245MB/s ± 0% 245MB/s ± 0% -0.07% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_progressive/gcc10 254MB/s ± 0% 252MB/s ± 0% -0.52% (p=0.008 n=5+5) wuffs_jpeg_decode_30k_24bpp_sequential/gcc10 514MB/s ± 0% 513MB/s ± 0% ~ (p=0.151 n=5+5) wuffs_jpeg_decode_77k_24bpp/gcc10 434MB/s ± 0% 433MB/s ± 0% -0.35% (p=0.016 n=5+4) wuffs_jpeg_decode_552k_24bpp_420/gcc10 459MB/s ± 0% 458MB/s ± 0% -0.12% (p=0.016 n=5+4) wuffs_jpeg_decode_552k_24bpp_444/gcc10 486MB/s ± 0% 486MB/s ± 0% -0.03% (p=0.008 n=5+5) wuffs_jpeg_decode_4002k_24bpp/gcc10 467MB/s ± 0% 465MB/s ± 0% -0.26% (p=0.016 n=5+4)
This commit is contained in:
1 parent
8d9d6c1292
commit
f155db4d5c
5 files changed
+75
-32
No files matched your search
@@ -39,6 +39,7 @@ type funk struct {
|
||||
varResumables map[t.ID]bool
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]string
|
||||
activeLoops a.LoopStack
|
||||
coroSuspPoint uint32
|
||||
ioManips uint32
|
||||
tempW uint32
|
||||
|
||||
@@ -473,6 +473,7 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error
|
||||
return nil
|
||||
}
|
||||
name0 := assigns[0].AsAssign().LHS().Ident().Str(g.tm)
|
||||
g.currFunk.activeLoops.Push(n)
|
||||
b.writes("{\n")
|
||||
|
||||
// TODO: don't assume that the slice is a slice of base.u8. In
|
||||
@@ -526,6 +527,7 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error
|
||||
}
|
||||
|
||||
b.writes("}\n")
|
||||
g.currFunk.activeLoops.Pop()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -538,6 +540,13 @@ func (g *gen) writeStatementJump(b *buffer, n *a.Jump, depth uint32) error {
|
||||
if n.Keyword() == t.IDBreak {
|
||||
keyword = "break"
|
||||
}
|
||||
// TODO: apply to all generated code, not just
|
||||
// wuffs_jpeg__decoder__fill_bitstream.
|
||||
if (n.JumpTarget() == g.currFunk.activeLoops.Top()) &&
|
||||
(g.currFunk.cName == "wuffs_jpeg__decoder__fill_bitstream") {
|
||||
b.printf("%s;\n", keyword)
|
||||
return nil
|
||||
}
|
||||
b.printf("goto label__%s__%s;\n", jt, keyword)
|
||||
return nil
|
||||
}
|
||||
@@ -624,13 +633,19 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
|
||||
if n.HasContinue() {
|
||||
// TODO: apply to all generated code, not just
|
||||
// wuffs_jpeg__decoder__fill_bitstream.
|
||||
stagedRollout := g.currFunk.cName != "wuffs_jpeg__decoder__fill_bitstream"
|
||||
|
||||
if n.HasDeepContinue() || (stagedRollout && n.HasContinue()) {
|
||||
jt, err := g.currFunk.jumpTarget(g.tm, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.printf("label__%s__continue:;\n", jt)
|
||||
}
|
||||
g.currFunk.activeLoops.Push(n)
|
||||
|
||||
condition := buffer(nil)
|
||||
if err := g.writeExpr(&condition, n.Condition(), false, 0); err != nil {
|
||||
return err
|
||||
@@ -643,7 +658,9 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
|
||||
}
|
||||
}
|
||||
b.writes("}\n")
|
||||
if n.HasBreak() {
|
||||
|
||||
g.currFunk.activeLoops.Pop()
|
||||
if n.HasDeepBreak() || (stagedRollout && n.HasBreak()) {
|
||||
jt, err := g.currFunk.jumpTarget(g.tm, n)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+48
-22
@@ -100,15 +100,31 @@ const (
|
||||
FlagsPublic = Flags(0x00000100)
|
||||
FlagsHasBreak = Flags(0x00000200)
|
||||
FlagsHasContinue = Flags(0x00000400)
|
||||
FlagsGlobalIdent = Flags(0x00000800)
|
||||
FlagsClassy = Flags(0x00001000)
|
||||
FlagsSubExprHasEffect = Flags(0x00002000)
|
||||
FlagsRetsError = Flags(0x00004000)
|
||||
FlagsPrivateData = Flags(0x00008000)
|
||||
FlagsChoosy = Flags(0x00010000)
|
||||
FlagsHasChooseCPUArch = Flags(0x00020000)
|
||||
FlagsHasDeepBreak = Flags(0x00000800)
|
||||
FlagsHasDeepContinue = Flags(0x00001000)
|
||||
FlagsGlobalIdent = Flags(0x00002000)
|
||||
FlagsClassy = Flags(0x00004000)
|
||||
FlagsSubExprHasEffect = Flags(0x00008000)
|
||||
FlagsRetsError = Flags(0x00010000)
|
||||
FlagsPrivateData = Flags(0x00020000)
|
||||
FlagsChoosy = Flags(0x00040000)
|
||||
FlagsHasChooseCPUArch = Flags(0x00080000)
|
||||
)
|
||||
|
||||
func breakFlags(deep bool) Flags {
|
||||
if deep {
|
||||
return FlagsHasBreak | FlagsHasDeepBreak
|
||||
}
|
||||
return FlagsHasBreak
|
||||
}
|
||||
|
||||
func continueFlags(deep bool) Flags {
|
||||
if deep {
|
||||
return FlagsHasContinue | FlagsHasDeepContinue
|
||||
}
|
||||
return FlagsHasContinue
|
||||
}
|
||||
|
||||
func (f Flags) AsEffect() Effect { return Effect(f) }
|
||||
|
||||
type Effect uint8
|
||||
@@ -253,12 +269,14 @@ type Loop interface {
|
||||
AsNode() *Node
|
||||
HasBreak() bool
|
||||
HasContinue() bool
|
||||
HasDeepBreak() bool
|
||||
HasDeepContinue() bool
|
||||
Keyword() t.ID
|
||||
Label() t.ID
|
||||
Asserts() []*Node
|
||||
Body() []*Node
|
||||
SetHasBreak()
|
||||
SetHasContinue()
|
||||
SetHasBreak(deep bool)
|
||||
SetHasContinue(deep bool)
|
||||
}
|
||||
|
||||
type LoopStack []Loop
|
||||
@@ -282,6 +300,10 @@ func (s *LoopStack) Pop() Loop {
|
||||
return l
|
||||
}
|
||||
|
||||
func (s *LoopStack) Top() Loop {
|
||||
return (*s)[len(*s)-1]
|
||||
}
|
||||
|
||||
type Raw Node
|
||||
|
||||
func (n *Raw) AsNode() *Node { return (*Node)(n) }
|
||||
@@ -632,6 +654,8 @@ type Iterate Node
|
||||
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) HasDeepBreak() bool { return n.flags&FlagsHasDeepBreak != 0 }
|
||||
func (n *Iterate) HasDeepContinue() bool { return n.flags&FlagsHasDeepContinue != 0 }
|
||||
func (n *Iterate) Keyword() t.ID { return t.IDIterate }
|
||||
func (n *Iterate) Advance() t.ID { return n.id0 }
|
||||
func (n *Iterate) Label() t.ID { return n.id1 }
|
||||
@@ -645,8 +669,8 @@ func (n *Iterate) Body() []*Node { return n.list2 }
|
||||
|
||||
func (n *Iterate) SetBody(body []*Node) { n.list2 = body }
|
||||
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 (n *Iterate) SetHasBreak(deep bool) { n.flags |= breakFlags(deep) }
|
||||
func (n *Iterate) SetHasContinue(deep bool) { n.flags |= continueFlags(deep) }
|
||||
|
||||
func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t.ID, asserts []*Node) *Iterate {
|
||||
return &Iterate{
|
||||
@@ -671,18 +695,20 @@ func NewIterate(label t.ID, assigns []*Node, length t.ID, advance t.ID, unroll t
|
||||
// TODO: should we be able to unroll while loops too?
|
||||
type While Node
|
||||
|
||||
func (n *While) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *While) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
|
||||
func (n *While) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
|
||||
func (n *While) Keyword() t.ID { return t.IDWhile }
|
||||
func (n *While) Label() t.ID { return n.id1 }
|
||||
func (n *While) Condition() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *While) Asserts() []*Node { return n.list1 }
|
||||
func (n *While) Body() []*Node { return n.list2 }
|
||||
func (n *While) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *While) HasBreak() bool { return n.flags&FlagsHasBreak != 0 }
|
||||
func (n *While) HasContinue() bool { return n.flags&FlagsHasContinue != 0 }
|
||||
func (n *While) HasDeepBreak() bool { return n.flags&FlagsHasDeepBreak != 0 }
|
||||
func (n *While) HasDeepContinue() bool { return n.flags&FlagsHasDeepContinue != 0 }
|
||||
func (n *While) Keyword() t.ID { return t.IDWhile }
|
||||
func (n *While) Label() t.ID { return n.id1 }
|
||||
func (n *While) Condition() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *While) Asserts() []*Node { return n.list1 }
|
||||
func (n *While) Body() []*Node { return n.list2 }
|
||||
|
||||
func (n *While) SetBody(body []*Node) { n.list2 = body }
|
||||
func (n *While) SetHasBreak() { n.flags |= FlagsHasBreak }
|
||||
func (n *While) SetHasContinue() { n.flags |= FlagsHasContinue }
|
||||
func (n *While) SetBody(body []*Node) { n.list2 = body }
|
||||
func (n *While) SetHasBreak(deep bool) { n.flags |= breakFlags(deep) }
|
||||
func (n *While) SetHasContinue(deep bool) { n.flags |= continueFlags(deep) }
|
||||
|
||||
func (n *While) IsWhileTrue() bool {
|
||||
condition := n.mhs.AsExpr()
|
||||
|
||||
+4
-3
@@ -805,7 +805,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
if len(p.loops) == 0 {
|
||||
// No-op.
|
||||
} else if label == 0 {
|
||||
loop = p.loops[len(p.loops)-1]
|
||||
loop = p.loops.Top()
|
||||
if loop.Label() != 0 {
|
||||
return nil, fmt.Errorf(`parse: unlabeled %s for labeled %s.%s at %s:%d`,
|
||||
x.Str(p.tm), loop.Keyword().Str(p.tm), loop.Label().Str(p.tm), p.filename, p.line())
|
||||
@@ -827,10 +827,11 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
x.Str(p.tm), sepStr, labelStr, p.filename, p.line())
|
||||
}
|
||||
|
||||
deep := loop != p.loops.Top()
|
||||
if x == t.IDBreak {
|
||||
loop.SetHasBreak()
|
||||
loop.SetHasBreak(deep)
|
||||
} else {
|
||||
loop.SetHasContinue()
|
||||
loop.SetHasContinue(deep)
|
||||
}
|
||||
n := a.NewJump(x, label)
|
||||
n.SetJumpTarget(loop)
|
||||
|
||||
@@ -41415,25 +41415,23 @@ wuffs_jpeg__decoder__fill_bitstream(
|
||||
self->private_impl.f_bitstream_wi = v_wi;
|
||||
}
|
||||
v_wi = self->private_impl.f_bitstream_wi;
|
||||
label__0__continue:;
|
||||
while ((v_wi < 2048u) && (((uint64_t)(io2_a_src - iop_a_src)) > 0u)) {
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c < 255u) {
|
||||
self->private_data.f_bitstream_buffer[v_wi] = v_c;
|
||||
v_wi += 1u;
|
||||
iop_a_src += 1u;
|
||||
goto label__0__continue;
|
||||
continue;
|
||||
} else if (((uint64_t)(io2_a_src - iop_a_src)) <= 1u) {
|
||||
goto label__0__break;
|
||||
break;
|
||||
} else if ((wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u) > 0u) {
|
||||
goto label__0__break;
|
||||
break;
|
||||
} else {
|
||||
self->private_data.f_bitstream_buffer[v_wi] = 255u;
|
||||
v_wi += 1u;
|
||||
iop_a_src += 2u;
|
||||
}
|
||||
}
|
||||
label__0__break:;
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) > 1u) {
|
||||
if ((wuffs_base__peek_u8be__no_bounds_check(iop_a_src) >= 255u) && ((wuffs_base__peek_u16le__no_bounds_check(iop_a_src) >> 8u) > 0u)) {
|
||||
v_new_wi = (wuffs_base__u32__min(v_wi, 1784u) + 264u);
|
||||
|
||||
Reference in new issue
Block a user