VHDL: use the length of an integer generic to determine number of select lines

前端 未结 5 1576
-上瘾入骨i
-上瘾入骨i 2021-02-08 08:34

I\'m trying to create a reusable barrel shifter; it takes an input array of bits and shifts them a certain number of positions (determined by another input). I want to parameter

5条回答
  •  隐瞒了意图╮
    2021-02-08 09:19

    You can use the math library to calculate log2 and ceil of the logarit result to declare the size of SHIFT_CNT.

    use IEEE.math_real.all;
    

    or specific functions

    use IEEE.math_real."ceil";
    use IEEE.math_real."log2";
    

    For example you want to calculate clog2 of value a

    result := integer(ceil(log2(real(a))));
    

    If you just use these function to calculate paramater, your code is synthesizable (I did it).

    If you don't want use it in entities, you can declare them in a library or generic with these functions.

提交回复
热议问题