mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Simplify cgen output for copy_from_slice
This commit is contained in:
1 parent
b5c47e273f
commit
f60723f624
3 files changed
+30
-12
No files matched your search
@@ -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 {
|
if err := g.writeExpr(b, foo, rp, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.writes(")+(")
|
if fIndex != nil {
|
||||||
if err := g.writeExpr(b, fIndex, rp, depth); err != nil {
|
b.writes(")+(")
|
||||||
return err
|
if err := g.writeExpr(b, fIndex, rp, depth); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.writes("),(")
|
b.writes("),(")
|
||||||
if err := g.writeExpr(b, bar, rp, depth); err != nil {
|
if err := g.writeExpr(b, bar, rp, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.writes(")+(")
|
if bIndex != nil {
|
||||||
if err := g.writeExpr(b, bIndex, rp, depth); err != nil {
|
b.writes(")+(")
|
||||||
return err
|
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.
|
// TODO: don't assume that the slice is a slice of base.u8.
|
||||||
b.writes("), 8)")
|
b.writes("), 8)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchFooIndexIndexPlus8 matches n with "foo[index:index + 8]". It returns
|
// matchFooIndexIndexPlus8 matches n with "foo[index:index + 8]" or "foo[:8]".
|
||||||
// nil values if there isn't a match.
|
// It returns a nil foo if there isn't a match.
|
||||||
func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
|
func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
|
||||||
if n.Operator() != t.IDColon {
|
if n.Operator() != t.IDColon {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -400,10 +404,19 @@ func matchFooIndexIndexPlus8(n *a.Expr) (foo *a.Expr, index *a.Expr) {
|
|||||||
foo = n.LHS().AsExpr()
|
foo = n.LHS().AsExpr()
|
||||||
index = n.MHS().AsExpr()
|
index = n.MHS().AsExpr()
|
||||||
rhs := n.RHS().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
|
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 nil, nil
|
||||||
}
|
}
|
||||||
return foo, index
|
return foo, index
|
||||||
|
|||||||
@@ -9656,7 +9656,7 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
|
|||||||
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
|
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
|
||||||
while (true) {
|
while (true) {
|
||||||
memcpy((self->private_impl.f_output) + (v_o),
|
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) {
|
if (v_steps <= 0) {
|
||||||
goto label_2_break;
|
goto label_2_break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
var steps base.u32 = (this.lm1s[c] as base.u32) >> 3
|
||||||
while true {
|
while true {
|
||||||
assert o <= (o + 8) via "a <= (a + b): 0 <= b"(b:8)
|
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 {
|
if steps <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user