How to add elements in Vec like a binary tree's leaf nodes?

Viewed 46

assuming n = 2^x elements in Vec,

adding elements in Vec using

vec.reduce(_ +& _)

will end up with element width = w + 2^x - 1

if adding them for every two elements like a tree, the width will be w + x

seems

vec.par.reduce(_ +& _)

works for 4 elements, but not for 8 or 16.

Any workaround?

2 Answers

I suggest you take a look at the experimental Interval type in chisel3. There's some limited documentation here. Intervals were designed for just this situation. You shouldn't even have to change everything, just map the elements of your Vec to Intervals and then reduce them.

Related