dimitriv / Ziria

A domain-specific-language and compiler for low-level bitstream processing.
92 stars 18 forks source link

the infamous [take optimization] #96

Closed dimitriv closed 9 years ago

dimitriv commented 9 years ago

We used to implement the following optimization (w @cristinaluengoagullo): if we Take one element and that is an array, simply use the address of the yield buffer of the upstream component. This can be seen in the Note [Take optimization] in CgOpt.hs. Unfortunately this optimization breaks down in cases like:

read >>> seq { (x : arr[4] int) <- take; (y : arr[4] int) <- take; .... x y } 

where the value "x" is needed "past" the second take. The use of the address has the effect here that "x" is overwritten and in the continuation x and y actually point to the same memory location. So in dev/ I have disabled this optimization. A quick fix might be to use the address if we are certain that in its scope it's never going to be used past another take. But maybe this calls for a more careful thinking of the execution model? @bradunov

bradunov commented 9 years ago

No need for a quick fix. Let's keep it correct, as it is now. We can keep it in mind for future, if needed.