Sčítačky Válcový posouvač INP Demonstrační cvičení 6
Poloviční sčítačka (Half Adder) A B S C 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 A B HA S C S: A C: A 0 1 0 0 1 0 B 0 1 B S <= A xor B; C <= A and B;
Úplná sčítačka (Full Adder) A B CI S COUT 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 A B CI COUT: FA 0 0 1 0 0 1 1 1 CI S COUT S <= A xor B xor Cin; COUT <= (A and B) or (A and CI) or (B and CI); A B S: A 0 1 0 1 1 0 1 0 CI B
Dataflow VHDL: Úplná sčítačka library IEEE; use IEEE.std_logic_1164.all; entity FA is port ( A, B, CI : in std_logic; S, COUT : out std_logic); end FA; architecture RTL of FA is begin S <= A xor B xor CI; COUT <= (A and B) or (A and CI) or (B and CI); end RTL; Poloviční sčítačka library IEEE; use IEEE.std_logic_1164.all; entity HA is port ( A, B : in std_logic; S, C : out std_logic); end HA; architecture RTL of HA is begin S <= A xor B; C <= A and B; end RTL;
Sčítačky: cena vs. rychlost Sériová levná, ale pomalá S postupným přenosem S přeskakováním přenosu CLA - Carry Look Ahead stromový CLA a další
Sčítačky s postupným přenosem (Carry Ripple Adders)
Sčítačka s postupným přenosem genericky ve VHDL N-bitová sčítačka library IEEE; use IEEE.std_logic_1164.all; entity RPADDER is generic (N : in integer := 8); port ( A, B : in std_logic_vector(n-1 downto 0); CI : in std_logic; S : out std_logic_vector(n-1 downto 0); COUT : out std_logic); end RPADDER; architecture RTL1 of RPADDER is component FA port ( A, B, CI : in std_logic; S, COUT : out std_logic); end component; signal C : std_logic_vector(a'length-1 downto 1); begin
Architektura sčítačky genericky begin gen : for j in A'range generate genlsb : if j = 0 generate fa0 : FA port map (A => A(j), B => B(j), CI => CI, S => S(j), COUT => C(1)); end generate; genmid : if (j > 0) and (j < A'length-1) generate fa0 : FA port map (A => A(j), B => B(j), CI => C(j), S => S(j), COUT => C(j+1)); end generate; genmsb : if j = A'length-1 generate fa0 : FA port map (A => A(j), B => B(j), CI => C(j), S => S(j), COUT => COUT); end generate; end generate; end RTL1;
Sčítačky s CLA logikou (Carry-Look Ahead Adders)
Rozšířená sčítačka Ci Ai Bi Si Pi Gi Ci+1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 1 1 0 0 1 0 1 1 1 1 1 0 1 1 P i šířený (propagate) přenos G i generovaný přenos Si = Ai Bi Ci Pi = Ai Bi Gi = Ai.Bi Ci+1 = Pi.Ci + Gi Ai Bi Rozšířená sčítačka: Ci+1 Si Ci Gi Pi
Rozšířená sčítačka ve VHDL library IEEE; use IEEE.std_logic_1164.all; entity FAPG is port ( A, B, CI : in std_logic; S, P, G : out std_logic); end FAPG; architecture RTL of FAPG is signal Gsig, Psig : std_logic; begin Gsig <= A and B; Psig <= A xor B; S <= Psig xor CI; G <= Gsig; P <= Psig; end RTL; P - propagate G - generate Si = Ai Bi Ci Pi = Ai Bi Gi = Ai.Bi C Ci+1 = P Pi.Ci + Gi
A3 4b sčítačka s CLA logikou B3 A2 B2 A1 B1 A0 B0 4 S3 3 3 3 3 C3 C2 C1 S2 G3 P3 4 G2 P2 GP (zde již nevyužito) GG=CO (3 ) Obecně pro N-bitovou CLA: S1 4 4b CLA G1 P1 S0 2 G0 P0 C 0 =CI C 1 =C 0 P 0 +G 0 C 2 =C 1 P 1 +G 1 =C 0 P 0 P 1 +G 0 P 1 +G 1 C 3 =C 2 P 2 +G 2 =C 0 P 0 P 1 P 2 +G 0 P 1 P 2 +G 1 P 2 +G 2 C 4 =C 3 P 3 +G 3 =C 0 P 0 P 1 P 2 P 3 +G 0 P 1 P 2 P 3 +G 1 P 2 P 3 +G 2 P 3 +G 3 GP C 0 =CI C i =C 0 P i-1 +G i-1 GG=CO pro 1<i N, kde G N-1 =CO CI C0
library IEEE; use IEEE.std_logic_1164.all; entity CLAU is port ( P, G : in std_logic_vector(3 downto 0); CI : in std_logic; CO : out std_logic_vector(3 downto 0); GP, GG : out std_logic); end CLAU; architecture RTL of CLAU is begin CO(0) <= CI; CO(1) <= (CI and P(0)) or G(0); CO(2) <= (CI and P(0) and P(1)) or (G(0) and P(1)) or G(1); CO(3) <= (CI and P(0) and P(1) and P(2)) or (G(0) and P(1) and P(2)) or (G(1) and P(2)) or G(2); GG <= (G(0) and P(1) and P(2) and P(3)) or (G(1) and P(2) and P(3)) or (G(2) and P(3)) or G(3); GP <= P(3) and P(2) and P(1) and P(0); end RTL; 4b CLA
Složitost CLA obvodu Kvadratická závislost plochy CLA jednotky na počtu bitů sčítačky! U 16b-CLA je to už neúnosné... Proto pět 4b-CLA sestavíme do stromu (víceúrovňová CLA logika) pro vytvoření 16b sčítačky.
16b sčítačka s 4b CLA (strom CLA) A15 B15 A14 B14 A13 B13 A12 B12 A11 B11 A10 B10 A9 B9 A8 B8 A7 B7 A6 B6 A5 B5 A4 B4 A3 B3 A2 B2 A1 B1 A0 B0 S15 S14 S13 S12 S11 S10 S9 S8 S7 S6 S5 S4 S3 S2 S1 S0 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0 P15 G15 P13 G13 P11 G11 P9 G9 P7 G7 P14 G14 P12 G12 P10 G10 P8 G8 P5 G5 P3 G3 P1 G1 P6 G6 P4 G4 P2 G2 P0 G0 CLAU CLAU CLAU CLAU GP3 GG3 GC3 GP2 GG2 GC2 GP1 GG1 GC1 GP0 GG0 GC0 GP (nevyužito) GG=CO CLAU Popis ve VHDL entity CLA16 is port ( A, B : in std_logic_vector(15 downto 0); CI : in std_logic; S : out std_logic_vector(15 downto 0); CO : out std_logic); end CLA16; architecture RTL of CLA16 is component FAPG port ( A, B, CI : in std_logic; S, P, G : out std_logic); end component; component CLAU port ( P, G : in std_logic_vector(3 downto 0); CI : in std_logic; CO : out std_logic_vector(3 downto 0); GP, GG : out std_logic); end component; CI
Stromová CLA ve VHDL (pokrač.) constant N : integer := 4; -- number of 4 bits signal P, G, C : std_logic_vector(n*4-1 downto 0); signal GP,GG,GC : std_logic_vector(n-1 downto 0); begin fagen : for i in 0 to N*4-1 generate fapg0 : FAPG port map (A => A(i), B => B(i), CI => C(i), S => S(i), P => P(i), G => G(i) ); end generate; claugen : for i in 0 to N-1 generate clau0 : CLAU port map (P => P(i*4+3 downto i*4), G => G(i*4+3 downto i*4), CI => GC(i), CO => C(i*4+3 downto i*4), GP => GP(i), GG => GG(i)); end generate; clau1 : CLAU port map (P => GP, G => GG, CI => CI, CO => GC, GP => open, GG => CO); end RTL; A15 B15 A14 B14 A13 B13 A12 B12 A11 B11 A10 B10 A9 B9 A8 B8 A7 B7 A6 B6 A5 B5 A4 B4 A3 B3 A2 B2 A1 B1 A0 B0 S15 S14 S13 S12 S11 S10 S9 S8 S7 S6 S5 S4 S3 S2 S1 S0 C15 C14 C13 C12 C11 C10 C9 C8 C7 C6 C5 C4 C3 C2 C1 C0 P15 G15 P13 G13 P11 G11 P9 G9 P7 G7 P14 G14 P12 G12 P10 G10 P8 G8 P5 G5 P3 G3 P1 G1 P6 G6 P4 G4 P2 G2 P0 G0 CLAU CLAU CLAU CLAU GP3 GG3 GC3 GP2 GG2 GC2 GP1 GG1 GC1 GP0 GG0 GC0 GP (nevyužito) GG=CO CLAU CI
Válcový posouvač (Barrel Shifter) pro posuvy a rotace (v 1 taktu) neimplementuje se pomocí posuvného registru, vždy pouze jako kombinační obvod!
a0 0 1 2 3 x y mpx b0 4b válcový posouvač pro rotace a1 a2 0 1 2 3 x y 0 1 2 3 x y mpx mpx b1 b2 vpravo b 3 b 2 b 1 b 0 a 3 a 2 a 1 a 0 0 bit a 0 a 3 a 2 a 1 1 bit a3 0 1 2 3 x y mpx b3 a 1 a 0 a 3 a 2 2 bit a 2 a 1 a 0 a 3 3 bit 2
Válcový posunovač (16b) - 16 x 16-vstupový multiplexor drahé řešení - multiplexory (2,2,2,2) levnější (64 x 2-MUX) 0 0 1 1 2 3 3 4 4.. 7... 8.. 15 15 0, 8 0, 4 0, 2 0, 1 Τ = 4 (2, 2, 2, 2)
Válcový posunovač (16b) library IEEE; use IEEE.std_logic_1164.all; entity BARREL is port ( IN0 : in std_logic_vector(15 downto 0); S : in std_logic_vector( 3 downto 0); Y : out std_logic_vector(15 downto 0)); end BARREL; architecture RTL1 of BARREL is constant N : integer := 16; constant M : integer := 4; type arytype is array(m downto 0) of std_logic_vector(n-1 downto 0); signal INTSIG, SHIFT, PASS : arytype; signal ZEROS : std_logic_vector(n-1 downto 0); begin ZEROS <= (others => '0'); INTSIG(0) <= IN0; muxgen : for j in 1 to M generate PASS(j) <= INTSIG(j-1); SHIFT(j) <= INTSIG(j-1)(N-2**(j-1)-1 downto 0) & ZEROS(2**(j-1)-1 downto 0); INTSIG(j) <= PASS(j) when S(j-1) = '0' else SHIFT(j); end generate; Y <= INTSIG(M); end RTL1;
Úlohy: - Navrhněte 16b válcový posouvač s multiplexory (2,4,2), - Navrhněte 4b válcový posouvač (4) pro rotaci vlevo
Literatura Drábek, V.: Výstavba počítačů, skriptum VUT v Brně, 1995. Wakerly, J. F.: Digital Design: Principles and Practices Chang, K. C.: Digital Design and Modeling with VHDL and Synthesis. Chang, K. C.: Digital Systems Design with VHDL and Synthesis.