Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Reduction with 0 loop iterations is not well defined #263

Open
dkoeplin opened this issue Apr 17, 2018 · 5 comments
Open

Reduction with 0 loop iterations is not well defined #263

dkoeplin opened this issue Apr 17, 2018 · 5 comments
Assignees

Comments

@dkoeplin
Copy link
Collaborator

val reg = Reg[Int]
Reduce(reg)(0 by 1){i => ... }{ ... }

Case 1: The contents of reg after the loop is effectively unchanged. Is this the desired behavior?

val out = Reduce(0)(0 by 1){i => ... }{ ... }

Case 2: [Needs to be confirmed] The contents of out is still not well defined. Should be 0?

@dkoeplin dkoeplin self-assigned this Apr 17, 2018
@dkoeplin dkoeplin added the bug label Apr 17, 2018
@mattfel1
Copy link
Member

I think this is the desired behavior. A loop that runs for 0 iters is a noop.

In codegen there is a ctr_trivial signal that is used to mask out any memory enable signals in that controller's subtree, so the register here should just hold its init value or whatever value was written in it already.

@dkoeplin
Copy link
Collaborator Author

I could see the argument for the second case writing 0 to the output register though, since that's considered to be the zero value for the operation and you would probably expect a sum of an empty vector to be zero, for example, instead of undefined.

@mattfel1
Copy link
Member

In the second case, does that zero correspond only to the zero value of the reduce, or does it also set the init value of the Reg that is created? If the Reg takes the default zero value and not the value provided to the Reduce, then I agree we need to do a write. But if we can use it for the init value of the Reg as well then we don't need to do anything

@dkoeplin
Copy link
Collaborator Author

It also sets the initial value of the accumulator. Does the accumulator get reset when the Reduce has 0 iterations?

@mattfel1
Copy link
Member

I don't think it gets reset but it's easy to make that the case if that's how we want it. I think I've seen this case in some apps and I put an explicit .reset to be sure.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants