Simplify cgen output for copy_from_slice

This commit is contained in:
Nigel Tao committed 2018-10-21 18:03:54 +11:00
1 parent b5c47e273f
commit f60723f624
3 files changed
+30 -12

No files matched your search

+23 -10
View File
@@ -374,25 +374,29 @@ func (g *gen) writeBuiltinSliceCopyFromSlice8(b *buffer, recv *a.Expr, method t.
if err := g.writeExpr(b, foo, rp, depth); err != nil {
return err
}
b.writes(")+(")
if err := g.writeExpr(b, fIndex, rp, depth); err != nil {
return err
if fIndex != nil {
b.writes(")+(")
if err := g.writeExpr(b, fIndex, rp, depth); err != nil {
return err
}
}
b.writes("),(")
if err := g.writeExpr(b, bar, rp, depth); err != nil {
return err
}
b.writes(")+(")
if err := g.writeExpr(b, bIndex, rp, depth); err != nil {
return err
if bIndex != nil {
b.writes(")+(")
if err := g.writeExpr(b, bIndex, rp, depth); err != nil {
return err
}
}
// TODO: don't assume that the slice is a slice of base.u8.
b.writes("), 8)")
return nil
}
// matchFooIndexIndexPlus8 matches n with "foo[index:index + 8]". It returns
// nil values if there isn't a match.
// matchFooIndexIndexPlus8 matches n with "foo[index:index + 8]" or "foo[:8]".
// It returns a nil foo if there isn't a match.
func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
if n.Operator() != t.IDColon {
return nil, nil
@@ -400,10 +404,19 @@ func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
foo = n.LHS().AsExpr()
index = n.MHS().AsExpr()
rhs := n.RHS().AsExpr()
if index == nil || rhs == nil || rhs.Operator() != t.IDXBinaryPlus || !rhs.LHS().AsExpr().Eq(index) {
if rhs == nil {
return nil, nil
}
if cv := rhs.RHS().AsExpr().ConstValue(); cv == nil || cv.Cmp(eight) != 0 {
if index == nil {
// No-op.
} else if rhs.Operator() != t.IDXBinaryPlus || !rhs.LHS().AsExpr().Eq(index) {
return nil, nil
} else {
rhs = rhs.RHS().AsExpr()
}
if cv := rhs.ConstValue(); cv == nil || cv.Cmp(eight) != 0 {
return nil, nil
}
return foo, index
+1 -1
View File
@@ -9656,7 +9656,7 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
while (true) {
memcpy((self->private_impl.f_output) + (v_o),
(self->private_impl.f_suffixes[v_c]) + (0), 8);
(self->private_impl.f_suffixes[v_c]), 8);
if (v_steps <= 0) {
goto label_2_break;
}
+6 -1
View File
@@ -160,7 +160,12 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
var steps base.u32 = (this.lm1s[c] as base.u32) >> 3
while true {
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8)
this.output[o:o + 8].copy_from_slice!(s:this.suffixes[c][0:0 + 8])
// The final "8" is redundant semantically, but helps the
// wuffs-c code generator recognize that both slices have the
// same constant length, and hence produce efficient C code.
this.output[o:o + 8].copy_from_slice!(s:this.suffixes[c][:8])
if steps <= 0 {
break
}