mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 08:47:28 +01:00
Make deflate's decode_huffman_fast ! not !?
name old speed new speed delta wuffs_deflate_decode_1k/clang 138MB/s ± 0% 139MB/s ± 0% +0.75% (p=0.008 n=5+5) wuffs_deflate_decode_10k/clang 233MB/s ± 0% 226MB/s ± 0% -2.83% (p=0.008 n=5+5) wuffs_deflate_decode_100k/clang 273MB/s ± 0% 259MB/s ± 1% -5.20% (p=0.008 n=5+5) wuffs_deflate_decode_1k/gcc 158MB/s ± 1% 157MB/s ± 0% ~ (p=0.151 n=5+5) wuffs_deflate_decode_10k/gcc 266MB/s ± 1% 261MB/s ± 0% -1.95% (p=0.008 n=5+5) wuffs_deflate_decode_100k/gcc 314MB/s ± 0% 316MB/s ± 0% +0.48% (p=0.032 n=5+5)
This commit is contained in:
1 parent
7748216b57
commit
a80962d502
6 files changed
+75
-27
No files matched your search
@@ -185,6 +185,7 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
|
||||
if err := g.findVars(); err != nil {
|
||||
return err
|
||||
}
|
||||
g.findDerivedVars()
|
||||
|
||||
if err := g.writeFuncImplPrologue(&g.currFunk.bPrologue); err != nil {
|
||||
return err
|
||||
@@ -257,7 +258,9 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
}
|
||||
}
|
||||
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Effect().Optional() ||
|
||||
(g.currFunk.returnsStatus && (len(g.currFunk.derivedVars) > 0)) {
|
||||
// TODO: rename the "status" variable to "ret"?
|
||||
b.printf("wuffs_base__status status = NULL;\n")
|
||||
}
|
||||
b.writes("\n")
|
||||
@@ -268,7 +271,6 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
g.findDerivedVars()
|
||||
if g.currFunk.derivedVars != nil {
|
||||
for _, o := range g.currFunk.astFunc.In().Fields() {
|
||||
o := o.AsField()
|
||||
@@ -332,7 +334,9 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeFuncImplEpilogue(b *buffer) error {
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Effect().Optional() ||
|
||||
(g.currFunk.returnsStatus && (len(g.currFunk.derivedVars) > 0)) {
|
||||
|
||||
b.writes("goto exit;exit:") // The goto avoids the "unused label" warning.
|
||||
}
|
||||
|
||||
@@ -346,7 +350,9 @@ func (g *gen) writeFuncImplEpilogue(b *buffer) error {
|
||||
b.writes("\n")
|
||||
}
|
||||
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Effect().Optional() ||
|
||||
(g.currFunk.returnsStatus && (len(g.currFunk.derivedVars) > 0)) {
|
||||
|
||||
if g.currFunk.astFunc.Public() {
|
||||
b.writes("if (wuffs_base__status__is_error(status)) { " +
|
||||
"self->private_impl.magic = WUFFS_BASE__DISABLED; }\n")
|
||||
|
||||
@@ -81,7 +81,8 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
|
||||
}
|
||||
depth++
|
||||
|
||||
if err := g.writeStatementAssign0(b, op, lhs, rhs); err != nil {
|
||||
hack, err := g.writeStatementAssign0(b, op, lhs, rhs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lhs != nil {
|
||||
@@ -89,22 +90,52 @@ func (g *gen) writeStatementAssign(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr,
|
||||
return err
|
||||
}
|
||||
}
|
||||
if hack {
|
||||
if err := g.writeLoadExprDerivedVars(b, rhs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
|
||||
func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr) (bool, error) {
|
||||
if err := g.writeBuiltinQuestionCall(b, rhs, 0); err != errNoSuchBuiltin {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
if (lhs == nil) || rhs.Effect().Coroutine() {
|
||||
doWork, hack := (lhs == nil) || rhs.Effect().Optional(), false
|
||||
if !doWork && (rhs.Operator() == t.IDOpenParen) && (len(g.currFunk.derivedVars) > 0) {
|
||||
// TODO: tighten this heuristic for filtering out all but user-defined
|
||||
// method receivers.
|
||||
method := rhs.LHS().AsExpr()
|
||||
if (method == nil) || !method.LHS().MType().IsPointerType() {
|
||||
return false, nil
|
||||
}
|
||||
for _, arg := range rhs.Args() {
|
||||
v := arg.AsArg().Value()
|
||||
// TODO: walk v, not just check it for an exact match for
|
||||
// "args.foo", for some foo in derivedVars?
|
||||
if v.Operator() != t.IDDot {
|
||||
continue
|
||||
}
|
||||
if vLHS := v.LHS().AsExpr(); vLHS.Operator() != 0 || vLHS.Ident() != t.IDArgs {
|
||||
continue
|
||||
}
|
||||
if _, ok := g.currFunk.derivedVars[v.Ident()]; ok {
|
||||
doWork, hack = true, true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if doWork {
|
||||
if err := g.writeSaveExprDerivedVars(b, rhs); err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
if op == t.IDEqQuestion {
|
||||
if g.currFunk.tempW > maxTemp {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
return false, fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
temp := g.currFunk.tempW
|
||||
g.currFunk.tempW++
|
||||
@@ -112,20 +143,22 @@ func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
b.printf("wuffs_base__status %s%d = ", tPrefix, temp)
|
||||
} else if rhs.Effect().Coroutine() {
|
||||
if err := g.writeCoroSuspPoint(b, false); err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
b.writes("status = ")
|
||||
} else if rhs.Effect().Optional() {
|
||||
b.writes("status = ")
|
||||
}
|
||||
|
||||
if err := g.writeExpr(b, rhs, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(";\n")
|
||||
if !hack {
|
||||
if err := g.writeExpr(b, rhs, 0); err != nil {
|
||||
return false, err
|
||||
}
|
||||
b.writes(";\n")
|
||||
|
||||
if err := g.writeLoadExprDerivedVars(b, rhs); err != nil {
|
||||
return err
|
||||
if err := g.writeLoadExprDerivedVars(b, rhs); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
if op != t.IDEqQuestion && rhs.Effect().Optional() {
|
||||
@@ -137,7 +170,7 @@ func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return hack, nil
|
||||
}
|
||||
|
||||
func (g *gen) writeStatementAssign1(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
|
||||
@@ -364,7 +397,9 @@ func (g *gen) writeStatementJump(b *buffer, n *a.Jump, depth uint32) error {
|
||||
func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
retExpr := n.Value()
|
||||
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Effect().Optional() ||
|
||||
(g.currFunk.returnsStatus && (len(g.currFunk.derivedVars) > 0)) {
|
||||
|
||||
isOK := false
|
||||
b.writes("status = ")
|
||||
if retExpr.Operator() == 0 && retExpr.Ident() == t.IDOk {
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
var errNeedDerivedVar = errors.New("internal: need derived var")
|
||||
var errNeedDerivedVar = errors.New("cgen: internal error: need derived var")
|
||||
|
||||
func (g *gen) needDerivedVar(name t.ID) bool {
|
||||
for _, o := range g.currFunk.astFunc.Body() {
|
||||
|
||||
Reference in new issue
Block a user