VHDL:天花板和地板除以两个整数常量

VHDL:天花板和地板除以两个整数常量,vhdl,Vhdl,在VHDL中,我正在寻找一种方法来获取一个实体的两个整数参数,将其中一个除以另一个作为浮点数,然后找到这个浮点数比率的下限和上限,然后将其存储为VHDL整数常量 library ieee; use ieee.std_logic_1164.all; entity something is generic( N: natural := 4; M: natural := 150 ); port( sys_clk

在VHDL中,我正在寻找一种方法来获取一个实体的两个整数参数,将其中一个除以另一个作为浮点数,然后找到这个浮点数比率的下限和上限,然后将其存储为VHDL整数常量

library ieee;
use     ieee.std_logic_1164.all;

entity something is
    generic(
        N: natural := 4;
        M: natural := 150
    );
    port(
        sys_clk     :in  std_logic;
        sys_rst     :in  std_logic;

        datai       :in  std_logic_vector(M-1 downto 0);
        datao       :out std_logic_vector(N-1 downto 0)
    );
end entity;


architecture rtl is something is
    --how to calculate ceiling of  M / N?
    constant ratio_ceiling :integer := integer(real(M)/real(N));

    --how to calculate floor of M / N?
    constant ratio_floor   :integer := integer(real(M)/real(N));

begin

end architecture;
代码:

输出:

C:\something> ghdl -a --std=08 --ieee=synopsys --work=work something.vhd

C:\something> ghdl --elab-run --std=08 --ieee=synopsys something --vcd=waves.vcd --ieee-asserts=disable

something.vhd:33:12:@0ms:(report note): ceil:  38
something.vhd:34:12:@0ms:(report note): floor: 37

不确定你的问题是什么,代码似乎是正确的。如果希望避免所有类型转换和转换,可以使用

固定比率\u上限:整数:=(M+N-1)/N;
固定比率\u楼层:整数:=M/N;

VHDL整数将向下取整,因此工作正常。

这是一个答案还是应该编辑?
C:\something> ghdl -a --std=08 --ieee=synopsys --work=work something.vhd

C:\something> ghdl --elab-run --std=08 --ieee=synopsys something --vcd=waves.vcd --ieee-asserts=disable

something.vhd:33:12:@0ms:(report note): ceil:  38
something.vhd:34:12:@0ms:(report note): floor: 37