📄 subvz.vhd
字号:
--------------------------------------------------------------------------------- Title : Parallel-prefix subtractor with carry-in, overflow, zero flag-- Project : VHDL Library of Arithmetic Units--------------------------------------------------------------------------------- File : SubVZ.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 :-- Binary subtractor using parallel-prefix carry-lookahead logic with:-- - carry-in (CI), subtracted-- - 2's complement overflow flag (V)-- - zero flag (only valid for CI = 0)-------------------------------------------------------------------------------library ieee;use ieee.std_logic_1164.all;use ieee.numeric_std.all;library arith_lib;use arith_lib.arith_lib.all;-------------------------------------------------------------------------------entity SubVZ is generic (width : positive := 8; -- word width speed : speedType := fast); -- performance parameter port (A, B : in std_logic_vector(width-1 downto 0); -- operands CI : in std_logic; -- carry in (subtracted) S : out std_logic_vector(width-1 downto 0); -- sum V, Z : out std_logic); -- overflow and zero flagend SubVZ;-------------------------------------------------------------------------------architecture Behavioral of SubVZ is signal Auns, Buns, CIuns, Suns : signed(width downto 0); -- unsigned constant MaxSgn : integer := 2**(width-1) - 1; -- largest signed number constant MinSgn : integer := - 2**(width-1); -- smallest signed numberbegin -- type conversion: std_logic_vector -> unsigned Auns <= resize(signed(A), width+1); Buns <= resize(signed(B), width+1); CIuns <= (0 => CI, others => '0'); -- subtraction Suns <= Auns - Buns - CIuns; -- type conversion: unsigned -> std_logic_vector S <= std_logic_vector(Suns(width-1 downto 0)); -- calculate overflow flag V <= '0' when ((Suns >= MinSgn) and (Suns <= MaxSgn)) else '1'; -- calculate zero flag Z <= '1' when Suns = 0 else '0';end Behavioral;-------------------------------------------------------------------------------architecture Structural of SubVZ is signal BI : std_logic_vector(width-1 downto 0); -- B inverted signal CII : std_logic; -- CI inverted signal GI, PI : std_logic_vector(width-1 downto 0); -- prefix gen./prop. in signal GO, PO : std_logic_vector(width-1 downto 0); -- prefix gen./prop. out signal PT : std_logic_vector(width-1 downto 0); -- adder propagate tempbegin -- invert B and CI for subtraction BI <= not B; CII <= not CI; -- calculate prefix input generate/propagate signal (0) GI(0) <= (A(0) and BI(0)) or (A(0) and CII) or (BI(0) and CII); PI(0) <= A(0) xor BI(0); -- calculate adder propagate signal (0) (PT = A xor B) PT(0) <= PI(0); -- calculate prefix input generate/propagate signals (1 to width-1) preproc : for i in width-1 downto 1 generate GI(i) <= A(i) and BI(i); PI(i) <= A(i) xor BI(i); -- calculate adder propagate signal (1 to width-1) (PT = A xor B) PT(i) <= PI(i); end generate preproc; -- calculate prefix output generate/propagate signals prefix : PrefixAndOr generic map (width, speed) port map (GI, PI, GO, PO); -- calculate sum and overflow bits S <= PT xor GO(width-2 downto 0) & CII; V <= GO(width-1) xor GO(width-2); Z <= PO(width-1);end Structural;-------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -