Add an iterate step argument

This commit is contained in:
Nigel Tao committed 2018-05-03 22:34:24 +10:00
1 parent 92682e6ccc
commit a73e56712d
9 files changed
+120 -57

No files matched your search

+12 -6
View File
@@ -241,18 +241,20 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
b.printf("uint8_t* %s%s = %sslice_%s.ptr;\n", vPrefix, name, iPrefix, name)
// TODO: look at n.HasContinue() and n.HasBreak().
unrollCount := int(n.UnrollCount().ConstValue().Int64())
if unrollCount != 1 {
unroll := n.Unroll().SmallPowerOf2Value()
step := n.Step().SmallPowerOf2Value()
// TODO: remove the "step == 1" hack.
if uStep := unroll * step; uStep != 1 && step == 1 {
b.printf("uint8_t* %send0_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n",
iPrefix, name, iPrefix, name, iPrefix, name, unrollCount, unrollCount)
iPrefix, name, iPrefix, name, iPrefix, name, uStep, uStep)
b.printf("while (%s%s < %send0_%s) {\n", vPrefix, name, iPrefix, name)
for i := 0; i < unrollCount; i++ {
for i := 0; i < unroll; i++ {
for _, o := range n.Body() {
if err := g.writeStatement(b, o, depth); err != nil {
return err
}
}
b.printf("%s%s++;\n", vPrefix, name)
b.printf("%s%s += %d;\n", vPrefix, name, step)
}
b.writes("}\n")
}
@@ -260,7 +262,11 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
b.printf("uint8_t* %send1_%s = %sslice_%s.ptr + %sslice_%s.len;\n",
iPrefix, name, iPrefix, name, iPrefix, name)
b.printf("while (%s%s < %send1_%s) {\n", vPrefix, name, iPrefix, name)
for _, o := range n.Body() {
tail := n.Tail()
if step == 1 {
tail = n.Body()
}
for _, o := range tail {
if err := g.writeStatement(b, o, depth); err != nil {
return err
}