⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 incgray.vhd

📁 VHDL的基本数学运算库,非常好用
💻 VHD
字号:
--------------------------------------------------------------------------------- Title       : Parallel-prefix Gray incrementer-- Project     : VHDL Library of Arithmetic Units--------------------------------------------------------------------------------- File        : IncGray.vhd-- Author      : Reto Zimmermann  <zimmi@iis.ee.ethz.ch>-- Company     : Integrated Systems Laboratory, ETH Zurich-- Date        : 1998/01/12--------------------------------------------------------------------------------- Copyright (c) 1998 Integrated Systems Laboratory, ETH Zurich--------------------------------------------------------------------------------- Description :-- Incrementer for Gray numbers using parallel-prefix propagate-lookahead-- logic.-- Bases on the following algorithm:--   P = A(n-1) xor A(n-2) xor ... xor A(0)--   Z(0) = A(0) xnor P--   Z(i) = A(i) xor (A(i-1) and not A(i-2) and not A(i-3) ...--                           and not A(0) and P)              ; i = 1, ..., n-2--   Z(n-1) = A(n-1) xor (not A(n-3) and not A(n-4) ... and not A(0) and P)-------------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;library arith_lib;use arith_lib.arith_lib.all;-------------------------------------------------------------------------------entity IncGray is  generic (width : integer := 16;  	-- word width	   speed : integer := 0);  -- performance parameter  port (A : in std_logic_vector(width-1 downto 0);  -- operand	Z : out std_logic_vector(width-1 downto 0));  -- resultend IncGray;-------------------------------------------------------------------------------architecture Behavioral of IncGray is  signal BI, BO : std_logic_vector(width-1 downto 0);  -- unsigned  signal BIuns, BOuns : unsigned(width-1 downto 0);  -- unsignedbegin  -- Gray to binary conversion  g2b : process (A)    variable biv : std_logic_vector(width downto 0);  begin    biv(width) := '0';    for i in width-1 downto 0 loop      biv(i) := biv(i+1) xor A(i);    end loop;        BI <= biv(width-1 downto 0);  end process g2b;  -- type conversion: std_logic_vector -> unsigned  BIuns <= unsigned(BI);  -- Increment  BOuns <= BIuns + 1;  -- type conversion: unsigned -> std_logic_vector  BO <= std_logic_vector(BOuns);  -- binary to Gray conversion  b2g : process (BO)    variable bov : std_logic_vector(width downto 0);  begin    bov := '0' & BO;    for i in 0 to width-1 loop      Z(i) <= bov(i+1) xor bov(i);    end loop;  end process b2g;end Behavioral;-------------------------------------------------------------------------------architecture Structural of IncGray is   signal PI, PO : std_logic_vector(width-2 downto 0);  -- prefix prop. in/out  signal P : std_logic;  		-- parity bit  signal T1 : std_logic_vector(width-1 downto 2);  -- temp.  signal T2 : std_logic_vector(width-1 downto 0);  -- temp.begin  -- calculate parity bit P  parity : RedXor    generic map (width)    port map (A, P);  -- calculate prefix input propagate signal (PI = not A(i))  PI(width-2 downto 1) <= not A(width-3 downto 0);  -- feed slow P signal into prefix circuit for slow architecture  speed1 : if speed = 0 generate      PI(0) <= P;  end generate speed1;  speed2 : if speed /= 0 generate    PI(0) <= '1';  end generate speed2;  -- calculate prefix output prop. signal (PO = not A(i-2) ... and not A(0))  prefix : PrefixAnd    generic map (width-1, speed)    port map (PI, PO);  -- calculate (A and PO)  T1(width-2 downto 2) <= A(width-3 downto 1) and PO(width-3 downto 1);  -- special case  T1(width-1) <= PO(width-2);  -- calculate (T1 and P) in fast architecture  bits : for i in width-1 downto 2 generate    speed3 : if speed = 0 generate      T2(i) <= T1(i);    end generate speed3;    speed4 : if speed /= 0 generate      T2(i) <= T1(i) and P;    end generate speed4;  end generate bits;  -- special cases  T2(1) <= A(0) and P;  T2(0) <= not P;  -- calculate result bits  Z <= A xor T2(width-1 downto 0);end Structural;-------------------------------------------------------------------------------

⌨️ 快捷键说明

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