LIBRARY ieee; USE ieee.std_logic_1164.all; library std ; use std.standard.all ; ENTITY logic3 IS generic ( n : natural :=5; k : natural := 23 ); PORT( clock, reset, readyfsmtologic: IN STD_logic; datafsmtologic00,datafsmtologic01 : in std_logic_vector(5 downto 0); datalogictofsm00,datalogictofsm01 : out std_logic_vector(5 downto 0); k_top:in integer; donelogictofsm : out std_logic ); END logic3; ARCHITECTURE archlogic OF logic3 IS type state_type is (idle,start,calc_delay,endcalc); signal state: state_type; subtype n_t is natural range 0 to 5; type gf3_vector1 is array (1 downto 0) of std_logic_vector(n downto 0); type gf3_vectormnoz is array (1 downto 0) of std_logic_vector(2*n+1 downto 0); type gf3_vector2 is array(1 downto 0) of std_logic_vector(3*n downto 0); signal poly_in0top, poly_in1top : std_logic_vector(n downto 0); signal fnewpoly0,fnewpoly1 : std_logic_vector(n downto 0); signal calcdonetop: std_logic; type gf3_vector_tab is array (natural range <>) of gf3_vector1; signal count : integer := 1; constant d : integer := 3; ------------------------------------------------------------------------------------------------------------ FUNCTION normalize ( l : gf3_vector1 ) RETURN gf3_vector1 IS ALIAS lv : gf3_vector1 IS l; VARIABLE result : gf3_vector1; BEGIN result(0):=lv(1); result(1):=lv(0); RETURN result; END normalize; ---------------------------------------------------------------------------------------------------------- FUNCTION sumuj ( l,r : gf3_vector1 ) RETURN gf3_vector1 IS ALIAS lv : gf3_vector1 IS l; ALIAS rv : gf3_vector1 IS r; VARIABLE result : gf3_vector1; variable t:std_logic_vector(l(0)'length -1 downto 0); BEGIN IF ( r'LENGTH > l'LENGTH ) THEN ASSERT FALSE REPORT "lewy argument jest mniejszy od prawego" SEVERITY FAILURE; ELSE t:=( lv(0) or rv(1) ) xor ( lv(1) or rv(0) ); result(0):= (lv(1) or rv(1)) xor t; result(1):= (lv(0) or rv(0)) xor t; IF (l'LENGTH /= r'LENGTH) THEN FOR i IN (rv'LENGTH ) TO result'LENGTH -1 LOOP result(1)(i) := lv(1)(i); result(0)(i) := lv(0)(i); END LOOP; END IF; END IF; RETURN result; END sumuj; ------------------------------------------------------------------------------------------------------------------- FUNCTION sumujmnoz ( l,r : gf3_vectormnoz ) RETURN gf3_vectormnoz IS ALIAS lv : gf3_vectormnoz IS l; ALIAS rv : gf3_vectormnoz IS r; VARIABLE result : gf3_vectormnoz; variable t:std_logic_vector(l(0)'length -1 downto 0); BEGIN IF ( r'LENGTH > l'LENGTH ) THEN ASSERT FALSE REPORT "lewy argument jest mniejszy od prawego" SEVERITY FAILURE; ELSE t:=( lv(0) or rv(1) ) xor ( lv(1) or rv(0) ); result(0):= (lv(1) or rv(1)) xor t; result(1):= (lv(0) or rv(0)) xor t; IF (l'LENGTH /= r'LENGTH) THEN FOR i IN (rv'LENGTH ) TO result'LENGTH -1 LOOP result(1)(i) := lv(1)(i); result(0)(i) := lv(0)(i); END LOOP; END IF; END IF; RETURN result; END sumujmnoz; ----------------------------------------------------------------------------------------------------------- FUNCTION rolfun (l:gf3_vector1) return gf3_vector1 is alias lv: gf3_vector1 is l; variable result: gf3_vector1; begin for i in 1 to result(0)'LENGTH-1 loop result(1)(i) := lv(1)(i-1); result(0)(i) := lv(0)(i-1); end loop; result(1)(0):='0'; result(0)(0):='0'; return result; end rolfun; ---------------------------------------------------------------------------------------------------------- FUNCTION rolfunmnoz (l:gf3_vectormnoz) return gf3_vectormnoz is alias lv: gf3_vectormnoz is l; variable result: gf3_vectormnoz; begin for i in 1 to result(0)'LENGTH-1 loop result(1)(i) := lv(1)(i-1); result(0)(i) := lv(0)(i-1); end loop; result(1)(0):='0'; result(0)(0):='0'; return result; end rolfunmnoz; ----------------------------------------------------------------------------------------------------------------- FUNCTION mnoz (l,r:gf3_vector1 ; polytab: gf3_vector_tab) RETURN gf3_vector1 is ALIAS lv : gf3_vector1 IS l; ALIAS rv : gf3_vector1 IS r; variable result, tmp2, pomocnicza:gf3_vector1; variable tmp, tmp3:gf3_vectormnoz; variable pomocnicza1:std_logic_vector(1 downto 0); begin result(1):=(others=>'0'); result(0):=(others=>'0'); tmp(1):=(others=>'0'); tmp(0):=(others=>'0'); tmp2(1):=(others=>'0'); tmp2(0):=(others=>'0'); pomocnicza(1):=(others=>'0'); pomocnicza(0):=(others=>'0'); tmp3(1):=(others=>'0'); tmp3(0):=(others=>'0'); for i in 0 to l(1)'LENGTH -1 loop pomocnicza1:=(lv(1)(i))&(lv(0)(i)); if( pomocnicza1="10" ) then tmp3(1):=(others=>'0'); tmp3(0):=(others=>'0'); pomocnicza:=normalize(rv); tmp3(1)(r(1)'LENGTH -1 downto 0):=pomocnicza(1); tmp3(0)(r(1)'LENGTH -1 downto 0):=pomocnicza(0); if (i > 0) then for j in 0 to i-1 loop tmp3:=rolfunmnoz(tmp3); end loop; end if; tmp := sumujmnoz (tmp, tmp3); elsif(pomocnicza1="01") then tmp3(1):=(others=>'0'); tmp3(0):=(others=>'0'); pomocnicza:=rv; tmp3(1)(r(1)'LENGTH -1 downto 0):=pomocnicza(1); tmp3(0)(r(1)'LENGTH -1 downto 0):=pomocnicza(0); if (i > 0) then for j in 0 to i-1 loop tmp3:=rolfunmnoz(tmp3); end loop; end if; tmp := sumujmnoz (tmp, tmp3); end if; end loop; --tmp(0):=(others=>'0'); --tmp(1):=(others=>'0'); for i in 0 to l(1)'LENGTH -2 loop result(1)(i) := tmp(1)(i); result(0)(i) := tmp(0)(i); end loop; for i in l(1)'LENGTH -1 to tmp(1)'LENGTH-1 loop pomocnicza1:=(tmp(1)(i))&(tmp(0)(i)); if( pomocnicza1="10" ) then tmp2 := normalize(polytab(i - l(1)'LENGTH + 1)); result := sumuj (tmp2,result); end if; pomocnicza1:=(tmp(1)(i))&(tmp(0)(i)); if( pomocnicza1="01" ) then result := sumuj ( polytab(i - l(1)'LENGTH +1), result); end if; end loop; return result; END mnoz; ---------------------------------------------------------------------------------------------------------------- procedure main( n: natural; k:integer; signal poly_in0, poly_in1: in std_logic_vector; signal poly_out0, poly_out1: out std_logic_vector; signal calcdone: out std_logic ) is variable vPoly, vPoly0, vPoly1, vPoly2, vBetha1,pomocnicza: gf3_vector1; variable vpolytab : gf3_vector_tab (2*n -3 downto 0); variable vpolybetha : gf3_vector_tab ( n-1 downto 0); variable vPoly3: gf3_vector2; variable vnewPoly, vpomPoly ,vpomPoly2: gf3_vector_tab (n downto 0); variable pomocnicza1:std_logic_vector(1 downto 0); begin calcdone<='0'; vpoly0(1) := poly_in1; vpoly0(0) := poly_in0; pomocnicza1:=( poly_in1(n))&(poly_in0(n)); if ( pomocnicza1= "10") then pomocnicza(1) := poly_in1; pomocnicza(0) := poly_in0; vpoly0 := normalize(pomocnicza); end if; for i in 0 to 2*n - 3 loop vpolytab(i)(1):=(others=>'0'); vpolytab(i)(0):=(others=>'0'); end loop; vPoly := normalize(vpoly0); vPoly(1)(n):='0'; vPoly(0)(n):='0'; vPoly1 := vPoly; vpolytab(0) := vPoly; for i in 1 to (2*n -3) loop vPoly := rolfun(vpolytab(i-1)); pomocnicza1:=( vPoly(1)(n))&(vPoly(0)(n) ); if ( pomocnicza1= "10") then vPoly2 := normalize(vPoly1); vPoly := sumuj(vPoly, vPoly2); end if; pomocnicza1:=( vPoly(1)(n))&(vPoly(0)(n) ); if ( pomocnicza1= "01") then vPoly := sumuj(vPoly, vPoly1); end if; vPoly(1)(n):='0'; vPoly(0)(n):='0'; vpolytab(i) := vPoly; end loop; if( k > (n*3) - 3 ) then vPoly2 := vpolytab(n*2 -3); for i in 1 to ( k - ((n*3)-3) ) loop vPoly := rolfun(vPoly2); pomocnicza1:=( vPoly(1)(n))&(vPoly(0)(n) ); if ( pomocnicza1= "10") then vPoly2 := normalize(vPoly1); vPoly := sumuj(vPoly, vPoly2); end if; pomocnicza1:=( vPoly(1)(n))&(vPoly(0)(n) ); if ( pomocnicza1= "01") then vPoly := sumuj(vPoly, vPoly1); end if; vPoly(1)(n):='0'; vPoly(0)(n):='0'; vPoly2 := vPoly; end loop; vBetha1 := vPoly2; elsif( k'0'); vBetha1(0):=(others=>'0'); vBetha1(1)(k):='0'; vBetha1(0)(k):='1'; else vBetha1 := vpolytab( k-n ); end if; vpolybetha(0) := vBetha1; for i in 1 to n-1 loop vPoly3(1):=(others=>'0'); vPoly3(0):=(others=>'0'); vPoly := vpolybetha(i-1); for j in 0 to n loop vPoly3(1)(3*j):=vPoly(1)(j); vPoly3(0)(3*j):=vPoly(0)(j); end loop; vPoly(1):=(others=>'0'); vPoly(0):=(others=>'0'); for j in 0 to n-1 loop vPoly(1)(j):=vPoly3(1)(j); vPoly(0)(j):=vPoly3(0)(j); end loop; for j in n to 3*n-3 loop pomocnicza1:=( vPoly3(1)(j))&(vPoly3(0)(j) ); if ( pomocnicza1= "10") then vPoly2 := normalize ( vpolytab (j-n) ); vPoly := sumuj(vPoly, vPoly2); elsif ( pomocnicza1= "01") then vPoly2:= vpolytab (j-n); vPoly := sumuj(vPoly, vPoly2); end if; end loop; vpolybetha(i) := vPoly; end loop; vPoly(1):=(others=>'0'); vPoly(0):=(others=>'0'); for i in 0 to n loop vnewPoly(i) := vPoly; vpomPoly(i) := vPoly; vpomPoly2(i):=vPoly; end loop; vPoly(1)(0):='0'; vPoly(0)(0):='1'; vnewPoly(n) := vPoly; vPomPoly2(n):=vPoly; for i in 0 to n-1 loop vPoly2:= normalize(vpolybetha(i)); for j in n downto n-i loop vpomPoly(j) := mnoz(vpomPoly2(j), vPoly2, vpolytab); pomocnicza:=vpomPoly(j); end loop; for j in n downto n-i loop vnewPoly(j-1) :=sumuj(vnewPoly(j-1),vpomPoly(j)); end loop; vpomPoly2:=vnewPoly; end loop; for i in 0 to n loop vPoly2 := vnewPoly(i); vPoly(1)(i):=vPoly2(1)(0); vPoly(0)(i):=vPoly2(0)(0); end loop; poly_out1<=vPoly(1); poly_out0<=vPoly(0); calcdone<='1'; end main; BEGIN ---------------------------------------------------------------------------------------------------------------------------------- seq: process(clock, reset) is begin if(reset='1') then state<=idle; donelogictofsm<='0'; --datalogictofsm00<=(others=>'0'); --datalogictofsm01<=(others=>'0'); elsif (clock'event and clock='1') then case state is when idle => if(readyfsmtologic='1') then state<=start; else state<=idle; end if; when start => datalogictofsm00<=(others=>'0'); datalogictofsm01<=(others=>'0'); poly_in0top<=datafsmtologic00(n downto 0); poly_in1top<=datafsmtologic01(n downto 0); --poly_in0top <= datafsmtologic0; --poly_in1top <= datafsmtologic1; state <= calc_delay; when calc_delay => if(count=d or calcdonetop='1') then datalogictofsm00(n downto 0) <= fnewpoly0; datalogictofsm01(n downto 0) <= fnewpoly1; --datalogictofsm00(n downto 0)<= datalogictofsm0; --datalogictofsm01(n downto 0)<= datalogictofsm1; donelogictofsm<='1'; state<=endcalc; count<=1; else main(n,k, poly_in0top, poly_in1top, fnewpoly0, fnewpoly1,calcdonetop); --fnewpoly0<=not poly_in0top; --fnewpoly1<=not poly_in1top; count<=count+1; state<=calc_delay; end if; when endcalc => donelogictofsm<='0'; calcdonetop<='0'; state<=idle; when others => state<=idle; end case; end if; end process seq; end archlogic;