arith_utils.vhd

来自「VHDL的基本数学运算库,非常好用」· VHDL 代码 · 共 66 行

VHD
66
字号
--------------------------------------------------------------------------------- Title       : Utility functions-- Project     : VHDL Library of Arithmetic Units--------------------------------------------------------------------------------- File        : arith_utils.vhd-- Author      : Reto Zimmermann  <zimmi@iis.ee.ethz.ch>-- Company     : Integrated Systems Laboratory, ETH Zurich-- Date        : 1997/11/04--------------------------------------------------------------------------------- Copyright (c) 1998 Integrated Systems Laboratory, ETH Zurich--------------------------------------------------------------------------------- Description :-- Package of utility functions used in code for arithmetic units.-------------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;-------------------------------------------------------------------------------package arith_utils is    function log2ceil (n : integer) return integer;  function log2floor (n : integer) return integer;end arith_utils;-------------------------------------------------------------------------------package body arith_utils is  -- purpose: computes ceil(log2(n))  function log2ceil (n : integer) return integer is    variable m, p : integer;  begin    m := 0;    p := 1;    for i in 0 to n loop      if p < n then        m := m + 1;        p := p * 2;      end if;    end loop;    return m;  end log2ceil;      -- purpose: computes floor(log2(n))  function log2floor (n : integer) return integer is    variable m, p : integer;  begin    m := -1;    p := 1;    for i in 0 to n loop      if p <= n then        m := m + 1;        p := p * 2;      end if;    end loop;    return m;  end log2floor;    end arith_utils;-------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?