mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +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() {
|
||||
|
||||
@@ -5443,6 +5443,7 @@ wuffs_deflate__decoder__decode_blocks(wuffs_deflate__decoder* self,
|
||||
uint32_t v_final = 0;
|
||||
uint32_t v_b0 = 0;
|
||||
uint32_t v_type = 0;
|
||||
wuffs_base__status v_status = NULL;
|
||||
|
||||
uint8_t* iop_a_src = NULL;
|
||||
uint8_t* io0_a_src = NULL;
|
||||
@@ -5532,12 +5533,14 @@ wuffs_deflate__decoder__decode_blocks(wuffs_deflate__decoder* self,
|
||||
a_src.private_impl.buf->meta.ri =
|
||||
iop_a_src - a_src.private_impl.buf->data.ptr;
|
||||
}
|
||||
status = wuffs_deflate__decoder__decode_huffman_fast(self, a_dst, a_src);
|
||||
v_status =
|
||||
wuffs_deflate__decoder__decode_huffman_fast(self, a_dst, a_src);
|
||||
if (a_src.private_impl.buf) {
|
||||
iop_a_src =
|
||||
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
|
||||
}
|
||||
if (status) {
|
||||
if (wuffs_base__status__is_error(v_status)) {
|
||||
status = v_status;
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_end_of_block) {
|
||||
|
||||
@@ -179,9 +179,10 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
|
||||
pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
||||
var final base.u32
|
||||
var b0 base.u32[..255]
|
||||
var type base.u32
|
||||
var final base.u32
|
||||
var b0 base.u32[..255]
|
||||
var type base.u32
|
||||
var status base.status
|
||||
|
||||
while final == 0 {
|
||||
while this.n_bits < 3,
|
||||
@@ -208,7 +209,10 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
|
||||
this.end_of_block = false
|
||||
this.decode_huffman_fast!?(dst:args.dst, src:args.src)
|
||||
status = this.decode_huffman_fast!(dst:args.dst, src:args.src)
|
||||
if status.is_error() {
|
||||
return status
|
||||
}
|
||||
if this.end_of_block {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
// TODO: describe how the xxx_fast version differs from the xxx_slow one, the
|
||||
// assumptions that xxx_fast makes, and how that makes it fast.
|
||||
pri func decoder.decode_huffman_fast!?(dst base.io_writer, src base.io_reader) {
|
||||
pri func decoder.decode_huffman_fast!(dst base.io_writer, src base.io_reader) base.status {
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
|
||||
Reference in new issue
Block a user