Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Created September 29, 2015 16:05
Show Gist options
  • Save christiaanb/5141c1dcc9585ba7b389 to your computer and use it in GitHub Desktop.
Save christiaanb/5141c1dcc9585ba7b389 to your computer and use it in GitHub Desktop.
, { "BlackBox" :
{ "name" : "CLaSH.Sized.Vector.fold"
, "type" : "fold :: (a -> a -> a) -> Vec (n+1) a -> a"
, "comment" : "THIS ONLY WORKS FOR POWER OF TWO LENGTH VECTORS"
, "templateD" :
"-- fold begin
fold_~SYM[0] : block
function pow2Index (d,n : in natural) return natural is
begin
return (2 ** d - 2 ** n);
end function;
signal intermediate : ~TYPM[1](0 to (2*~LENGTH[~TYP[1]])-2);
constant levels : natural := (natural (ceil (log2 (real (~LENGTH[~TYP[1]])))));
begin
intermediate(0 to ~LENGTH[~TYP[1]]-1) <= ~ARG[1];
tree_depth : for d in levels-1 downto 0 generate
tree_nf_loop: for i in 0 to (natural(2**d) - 1) generate
~INST 0
~OUTPUT <= intermediate(pow2Index(levels+1,d+1)+i)~ ~TYPO~
~INPUT <= intermediate(pow2Index(levels+1,d+2)+(2*i))~ ~TYPO~
~INPUT <= intermediate(pow2Index(levels+1,d+2)+(2*i)+1)~ ~TYPO~
~INST
end generate;
end generate;
~RESULT <= intermediate((2*~LENGTH[~TYP[1]])-2);
end block;
-- fold end"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment