-------------------------------------------------------------------------------------------------- -- -- -- Copyright (c) 1992-1999, Knowledge Based Silicon Corporation -- -- Copyright (c) 1999-2003, SEDA Intuit Designs Sdn. Bhd. -- -- Copyright (c) 2003 , exsedia Sdn. Bhd. -- -- Worldwide Rights Reserved. -- -- -- -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- -- -- -- File name : Nimbus_bit.vhdl -- -- File Description : Macro-Function VHDL package. -- -- Version : R100 -- -- Author : Eric C. Smith -- -- Date : 12/8/94 -- -- -- -- -- -- Authors' Note: This new version of the package eliminates all -- -- nested function calls (function calls within the body of other -- -- function definitions), removes the INIT function, gives all function -- -- definitions an explicit 'result' variable used in return statements, -- -- and reorders the definitions in the package body so that they are -- -- in the same order as their declarations. -- -- -- -- ECS -- -- -- -------------------------------------------------------------------------------------------------- package Nimbus_bit is function BOOL2BIT (A: boolean) return bit; function BIT2BOOL (A: bit) return boolean; -- ******************************************************************************************* -- ******************************************************************************************* function ADD (A, B: bit_vector; C: bit) return bit_vector; function ADD (A, B: bit_vector) return bit_vector; function ADD (A, B: bit) return bit_vector; function ADD (A, B, C: bit) return bit_vector; function ADDNC (A, B: bit_vector) return bit_vector; function ADDNC (A, B: bit_vector; C: bit) return bit_vector; function ADDNC (A, B: bit) return bit; function ADDNC (A, B, C: bit) return bit; function BAND (A: bit_vector) return bit; function BOR (A: bit_vector) return bit; function BXOR (A: bit_vector) return bit; function CAT (A, B: bit_vector) return bit_vector; function CAT (A, B: bit) return bit_vector; function CAT (A: bit; B: bit_vector) return bit_vector; function CAT (A: bit_vector; B: bit) return bit_vector; function CMP (A, B: bit_vector) return bit_vector; function CMP (A, B: bit) return bit_vector; function CMPL2 (A: bit_vector) return bit_vector; function CMPL2 (A: bit) return bit_vector; function CMPL2NC (A: bit_vector) return bit_vector; function CMPL2NC (A: bit) return bit; function DECO (A: bit_vector) return bit_vector; function DECO (A: bit) return bit_vector; function DECR (A: bit_vector) return bit_vector; function DECR (A: bit) return bit_vector; function DECRNC (A: bit_vector) return bit_vector; function DECRNC (A: bit) return bit; function DMUX (A: bit; B: bit_vector) return bit_vector; function DMUX (A, B: bit) return bit_vector; function FAND (A, B: bit_vector) return bit_vector; function FAND (A, B, C: bit_vector) return bit_vector; function FAND (A, B, C, D: bit_vector) return bit_vector; function FAND (A, B, C, D, E: bit_vector) return bit_vector; function FAND (A, B, C, D, E, F: bit_vector) return bit_vector; function FAND (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FAND (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FAND (A, B: bit) return bit; function FAND (A, B, C: bit) return bit; function FAND (A, B, C, D: bit) return bit; function FAND (A, B, C, D, E: bit) return bit; function FAND (A, B, C, D, E, F: bit) return bit; function FAND (A, B, C, D, E, F, G: bit) return bit; function FAND (A, B, C, D, E, F, G, H: bit) return bit; function FFOR (A, B: bit_vector) return bit_vector; function FFOR (A, B, C: bit_vector) return bit_vector; function FFOR (A, B, C, D: bit_vector) return bit_vector; function FFOR (A, B, C, D, E: bit_vector) return bit_vector; function FFOR (A, B, C, D, E, F: bit_vector) return bit_vector; function FFOR (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FFOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FFOR (A, B: bit) return bit; function FFOR (A, B, C: bit) return bit; function FFOR (A, B, C, D: bit) return bit; function FFOR (A, B, C, D, E: bit) return bit; function FFOR (A, B, C, D, E, F: bit) return bit; function FFOR (A, B, C, D, E, F, G: bit) return bit; function FFOR (A, B, C, D, E, F, G, H: bit) return bit; function FNAND (A, B: bit_vector) return bit_vector; function FNAND (A, B, C: bit_vector) return bit_vector; function FNAND (A, B, C, D: bit_vector) return bit_vector; function FNAND (A, B, C, D, E: bit_vector) return bit_vector; function FNAND (A, B, C, D, E, F: bit_vector) return bit_vector; function FNAND (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FNAND (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FNAND (A, B: bit) return bit; function FNAND (A, B, C: bit) return bit; function FNAND (A, B, C, D: bit) return bit; function FNAND (A, B, C, D, E: bit) return bit; function FNAND (A, B, C, D, E, F: bit) return bit; function FNAND (A, B, C, D, E, F, G: bit) return bit; function FNAND (A, B, C, D, E, F, G, H: bit) return bit; function FNOR (A, B: bit_vector) return bit_vector; function FNOR (A, B, C: bit_vector) return bit_vector; function FNOR (A, B, C, D: bit_vector) return bit_vector; function FNOR (A, B, C, D, E: bit_vector) return bit_vector; function FNOR (A, B, C, D, E, F: bit_vector) return bit_vector; function FNOR (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FNOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FNOR (A, B: bit) return bit; function FNOR (A, B, C: bit) return bit; function FNOR (A, B, C, D: bit) return bit; function FNOR (A, B, C, D, E: bit) return bit; function FNOR (A, B, C, D, E, F: bit) return bit; function FNOR (A, B, C, D, E, F, G: bit) return bit; function FNOR (A, B, C, D, E, F, G, H: bit) return bit; function FNOT (A: bit_vector) return bit_vector; function FNOT (A: bit) return bit; function FXNOR (A, B: bit_vector) return bit_vector; function FXNOR (A, B, C: bit_vector) return bit_vector; function FXNOR (A, B, C, D: bit_vector) return bit_vector; function FXNOR (A, B, C, D, E: bit_vector) return bit_vector; function FXNOR (A, B, C, D, E, F: bit_vector) return bit_vector; function FXNOR (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FXNOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FXNOR (A, B: bit) return bit; function FXNOR (A, B, C: bit) return bit; function FXNOR (A, B, C, D: bit) return bit; function FXNOR (A, B, C, D, E: bit) return bit; function FXNOR (A, B, C, D, E, F: bit) return bit; function FXNOR (A, B, C, D, E, F, G: bit) return bit; function FXNOR (A, B, C, D, E, F, G, H: bit) return bit; function FXOR (A, B: bit_vector) return bit_vector; function FXOR (A, B, C: bit_vector) return bit_vector; function FXOR (A, B, C, D: bit_vector) return bit_vector; function FXOR (A, B, C, D, E: bit_vector) return bit_vector; function FXOR (A, B, C, D, E, F: bit_vector) return bit_vector; function FXOR (A, B, C, D, E, F, G: bit_vector) return bit_vector; function FXOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector; function FXOR (A, B: bit) return bit; function FXOR (A, B, C: bit) return bit; function FXOR (A, B, C, D: bit) return bit; function FXOR (A, B, C, D, E: bit) return bit; function FXOR (A, B, C, D, E, F: bit) return bit; function FXOR (A, B, C, D, E, F, G: bit) return bit; function FXOR (A, B, C, D, E, F, G, H: bit) return bit; function INCR (A: bit_vector) return bit_vector; function INCR (A: bit) return bit_vector; function INCRNC (A: bit_vector) return bit_vector; function INCRNC (A: bit) return bit; function MUL (A, B: bit_vector) return bit_vector; function MUL (A, B: bit) return bit_vector; function MUX (A, B: bit_vector) return bit; function MUX (A: bit_vector; B: bit) return bit; function NMUX (A, B: bit_vector; C: bit) return bit_vector; function NMUX (A, B, C: bit) return bit; function REFL (A: bit_vector) return bit_vector; function ROTL (A: bit_vector) return bit_vector; function ROTL (A: bit) return bit; function ROTR (A: bit_vector) return bit_vector; function ROTR (A: bit) return bit; function SHL0 (A: bit_vector) return bit_vector; function SHL0 (A: bit) return bit; function SHL1 (A: bit_vector) return bit_vector; function SHL1 (A: bit) return bit; function SHLIN (A: bit_vector; B: bit) return bit_vector; function SHLIN (A, B: bit) return bit; function SHR0 (A: bit_vector) return bit_vector; function SHR0 (A: bit) return bit; function SHR1 (A: bit_vector) return bit_vector; function SHR1 (A: bit) return bit; function SHRIN (A: bit_vector; B: bit) return bit_vector; function SHRIN (A, B: bit) return bit; function SUB (A, B: bit_vector) return bit_vector; function SUB (A, B: bit_vector; C: bit) return bit_vector; function SUB (A, B: bit) return bit_vector; function SUB (A, B, C: bit) return bit_vector; function SUBNC (A, B: bit_vector) return bit_vector; function SUBNC (A, B: bit_vector; C: bit) return bit_vector; function SUBNC (A, B: bit) return bit; function SUBNC (A, B, C: bit) return bit; end Nimbus_bit; -- ******************************************************************************************* -- ******************************************************************************************* package body Nimbus_bit is function BOOL2BIT (A: boolean) return bit is begin if (A = TRUE) then return '1'; else return '0'; end if; end BOOL2BIT; function BIT2BOOL (A: bit) return boolean is begin if (A = '1') then return TRUE; else return FALSE; end if; end BIT2BOOL; -- ***************************************************************** -- Nimbus macro functions begin at this point -- ***************************************************************** function ADD (A, B, C: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := A xor B xor C; result(1) := (A and B) or (A and C) or (B and C); return result; end ADD; function ADD (A, B: bit_vector; C: bit) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; variable j : integer; begin carry := C; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return (carry & result); end ADD; function ADD (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; variable j : integer; begin carry := '0'; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor carry; carry:= (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return (carry & result); end ADD; function ADD (A, B: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := A xor B; result(1) := A and B; return result; end ADD; function ADDNC (A, B: bit_vector; C: bit) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; variable j : integer; begin carry := C; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return result; end ADDNC; function ADDNC (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; variable j : integer; begin carry := '0'; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor carry; carry := (A(i) and B(j)) or (A(i) and carry) or (B(j) and carry); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return result; end ADDNC; function ADDNC (A, B: bit) return bit is variable result : bit; begin result := A xor B; return result; end ADDNC; function ADDNC (A, B, C: bit) return bit is variable result : bit; begin result := A xor B xor C; return result; end ADDNC; -- ***************************************************************** function BAND (A: bit_vector) return bit is variable result : bit; begin result := '1'; for i in A'range loop result := result and A(i); end loop; return result; end BAND; -- ***************************************************************** function BOR (A: bit_vector) return bit is variable result : bit; begin result := '0'; for i in A'range loop result := result or A(i); end loop; return result; end BOR; -- ***************************************************************** function BXOR (A: bit_vector) return bit is variable result : bit; begin result := A(A'low); for i in A'low+1 to A'high loop result := result xor A(i); end loop; return result; end BXOR; -- ***************************************************************** function CAT (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'length + B'length - 1 downto 0); begin result := A & B; return result; end CAT; function CAT (A, B: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(1) := A; result(0) := B; return result; end CAT; function CAT (A: bit; B: bit_vector) return bit_vector is variable result : bit_vector(B'length downto 0); begin result(B'length) := A; result(B'length - 1 downto 0) := B; return result; end CAT; function CAT (A: bit_vector; B: bit) return bit_vector is variable result : bit_vector(A'length downto 0); begin result := A & B; return result; end CAT; -- ***************************************************************** function CMP (A, B: bit_vector) return bit_vector is variable result : bit_vector (1 downto 0); variable j : integer; variable temp : bit_vector (1 downto 0); begin result := "00"; j := B'left; if (A'left > A'right) then for i in A'left downto A'right loop temp := (A(i) and not B(j)) & (not A(i) and B(j)); result(0) := result(0) or (temp(0) and (result(0) nor result(1))); result(1) := result(1) or (temp(1) and (result(0) nor result(1))); if (B'left > B'right) then j := j - 1; else j := j + 1; end if; end loop; else for i in A'left to A'right loop temp := (A(i) and not B(j)) & (not A(i) and B(j)); result(0) := result(0) or (temp(0) and (result(0) nor result(1))); result(1) := result(1) or (temp(1) and (result(0) nor result(1))); if (B'left > B'right) then j := j - 1; else j := j + 1; end if; end loop; end if; return result; end CMP; function CMP (A, B: bit) return bit_vector is variable result : bit_vector (1 downto 0); begin result := (A and not B) & (not A and B); return result; end CMP; -- ***************************************************************** function CMPL2 (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; begin carry := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := not A(i) xor carry; carry := not A(i) and carry; end loop; else for i in A'right downto A'left loop result(i) := not A(i) xor carry; carry := not A(i) and carry; end loop; end if; return (carry & result); end CMPL2; function CMPL2 (A: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := A; result(1) := not A; return result; end CMPL2; function CMPL2NC (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; begin carry := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := not A(i) xor carry; carry := not A(i) and carry; end loop; else for i in A'right downto A'left loop result(i) := not A(i) xor carry; carry := not A(i) and carry; end loop; end if; return result; end CMPL2NC; function CMPL2NC (A: bit) return bit is variable result : bit; begin result := A; return result; end CMPL2NC; -- ***************************************************************** function DECO (A: bit_vector) return bit_vector is variable result : bit_vector(((2**A'length)-1) downto 0); variable temp : bit_vector(A'range); variable temp2 : bit_vector(A'range); variable temp3 : bit_vector(A'range); variable carry : bit; begin for i in temp'range loop temp(i) := '0'; end loop; for i in result'range loop result(i) := '1'; end loop; for i in result'low to result'high loop temp2 := not(A xor temp); for j in temp2'range loop result(i) := result(i) and temp2(j); end loop; temp3 := temp; carry := '1'; if (temp'left > temp'right) then for i in temp'right to temp'left loop temp(i) := temp3(i) xor carry; carry := temp3(i) and carry; end loop; else for i in temp'right downto temp'left loop temp(i) := temp3(i) xor carry; carry := temp3(i) and carry; end loop; end if; end loop; return result; end DECO; function DECO (A: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result := A & not A; return result; end DECO; -- ***************************************************************** function DECR (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; begin borrow := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor borrow; borrow := not A(i) and borrow; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor borrow; borrow := not A(i) and borrow; end loop; end if; return (borrow & result); end DECR; function DECR (A: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := not A; result(1) := not A; return result; end DECR; function DECRNC (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; begin borrow := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor borrow; borrow := not A(i) and borrow; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor borrow; borrow := not A(i) and borrow; end loop; end if; return result; end DECRNC; function DECRNC (A: bit) return bit is variable result : bit; begin result := not A; return result; end DECRNC; -- ***************************************************************** function DMUX (A: bit; B: bit_vector) return bit_vector is variable result : bit_vector(((2**B'length)-1) downto 0); variable temp : bit_vector(B'range); variable temp3 : bit_vector(B'range); variable temp2 : bit_vector(B'length downto 0); variable carry : bit; begin for i in temp'range loop temp(i) := '0'; end loop; for i in result'range loop result(i) := '1'; end loop; for i in result'low to result'high loop temp2 := not(B xor temp) & A; for j in temp2'range loop result(i) := result(i) and temp2(j); end loop; temp3 := temp; carry := '1'; if (temp'left > temp'right) then for i in temp'right to temp'left loop temp(i) := temp3(i) xor carry; carry := temp3(i) and carry; end loop; else for i in temp'right downto temp'left loop temp(i) := temp3(i) xor carry; carry := temp3(i) and carry; end loop; end if; end loop; return result; end DMUX; function DMUX (A, B: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result := (B and A) & ((not B) and A); return result; end DMUX; -- ***************************************************************** function FAND (A, B: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B; return result; end FAND; function FAND (A, B, C: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C; return result; end FAND; function FAND (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C and D; return result; end FAND; function FAND (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C and D and E; return result; end FAND; function FAND (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C and D and E and F; return result; end FAND; function FAND (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C and D and E and F and G; return result; end FAND; function FAND (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A and B and C and D and E and F and G and H; return result; end FAND; function FAND (A, B: bit) return bit is variable result : bit; begin result := A and B; return result; end FAND; function FAND (A, B, C: bit) return bit is variable result : bit; begin result := A and B and C; return result; end FAND; function FAND (A, B, C, D: bit) return bit is variable result : bit; begin result := A and B and C and D; return result; end FAND; function FAND (A, B, C, D, E: bit) return bit is variable result : bit; begin result := A and B and C and D and E; return result; end FAND; function FAND (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := A and B and C and D and E and F; return result; end FAND; function FAND (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := A and B and C and D and E and F and G; return result; end FAND; function FAND (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := A and B and C and D and E and F and G and H; return result; end FAND; -- ***************************************************************** function FFOR (A, B: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B; return result; end FFOR; function FFOR (A, B, C: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C; return result; end FFOR; function FFOR (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C or D; return result; end FFOR; function FFOR (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C or D or E; return result; end FFOR; function FFOR (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C or D or E or F; return result; end FFOR; function FFOR (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C or D or E or F or G; return result; end FFOR; function FFOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A or B or C or D or E or F or G or H; return result; end FFOR; function FFOR (A, B: bit) return bit is variable result : bit; begin result := A or B; return result; end FFOR; function FFOR (A, B, C: bit) return bit is variable result : bit; begin result := A or B or C; return result; end FFOR; function FFOR (A, B, C, D: bit) return bit is variable result : bit; begin result := A or B or C or D; return result; end FFOR; function FFOR (A, B, C, D, E: bit) return bit is variable result : bit; begin result := A or B or C or D or E; return result; end FFOR; function FFOR (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := A or B or C or D or E or F; return result; end FFOR; function FFOR (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := A or B or C or D or E or F or G; return result; end FFOR; function FFOR (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := A or B or C or D or E or F or G or H; return result; end FFOR; -- ***************************************************************** function FNAND (A, B: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B); return result; end FNAND; function FNAND (A, B, C: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C); return result; end FNAND; function FNAND (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C and D); return result; end FNAND; function FNAND (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C and D and E); return result; end FNAND; function FNAND (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C and D and E and F); return result; end FNAND; function FNAND (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C and D and E and F and G); return result; end FNAND; function FNAND (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A and B and C and D and E and F and G and H); return result; end FNAND; function FNAND (A, B: bit) return bit is variable result : bit; begin result := not (A and B); return result; end FNAND; function FNAND (A, B, C: bit) return bit is variable result : bit; begin result := not (A and B and C); return result; end FNAND; function FNAND (A, B, C, D: bit) return bit is variable result : bit; begin result := not (A and B and C and D); return result; end FNAND; function FNAND (A, B, C, D, E: bit) return bit is variable result : bit; begin result := not (A and B and C and D and E); return result; end FNAND; function FNAND (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := not (A and B and C and D and E and F); return result; end FNAND; function FNAND (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := not (A and B and C and D and E and F and G); return result; end FNAND; function FNAND (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := not (A and B and C and D and E and F and G and H); return result; end FNAND; -- ***************************************************************** function FNOR (A, B: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B); return result; end FNOR; function FNOR (A, B, C: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C); return result; end FNOR; function FNOR (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C or D); return result; end FNOR; function FNOR (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C or D or E); return result; end FNOR; function FNOR (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C or D or E or F); return result; end FNOR; function FNOR (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C or D or E or F or G); return result; end FNOR; function FNOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not (A or B or C or D or E or F or G or H); return result; end FNOR; function FNOR (A, B: bit) return bit is variable result : bit; begin result := not (A or B); return result; end FNOR; function FNOR (A, B, C: bit) return bit is variable result : bit; begin result := not (A or B or C); return result; end FNOR; function FNOR (A, B, C, D: bit) return bit is variable result : bit; begin result := not (A or B or C or D); return result; end FNOR; function FNOR (A, B, C, D, E: bit) return bit is variable result : bit; begin result := not (A or B or C or D or E); return result; end FNOR; function FNOR (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := not (A or B or C or D or E or F); return result; end FNOR; function FNOR (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := not (A or B or C or D or E or F or G); return result; end FNOR; function FNOR (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := not (A or B or C or D or E or F or G or H); return result; end FNOR; -- ***************************************************************** function FNOT (A: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := not A; return result; end FNOT; function FNOT (A: bit) return bit is variable result : bit; begin result := not A; return result; end FNOT; -- ***************************************************************** function FXNOR (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B); return result; end FXNOR; function FXNOR (A, B, C: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C); return result; end FXNOR; function FXNOR (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C xor D); return result; end FXNOR; function FXNOR (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C xor D xor E); return result; end FXNOR; function FXNOR (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C xor D xor E xor F); return result; end FXNOR; function FXNOR (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C xor D xor E xor F xor G); return result; end FXNOR; function FXNOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector(A'high downto A'low); begin result := not (A xor B xor C xor D xor E xor F xor G xor H); return result; end FXNOR; function FXNOR (A, B: bit) return bit is variable result : bit; begin result := not (A xor B); return result; end FXNOR; function FXNOR (A, B, C: bit) return bit is variable result : bit; begin result := not (A xor B xor C); return result; end FXNOR; function FXNOR (A, B, C, D: bit) return bit is variable result : bit; begin result := not (A xor B xor C xor D); return result; end FXNOR; function FXNOR (A, B, C, D, E: bit) return bit is variable result : bit; begin result := not (A xor B xor C xor D xor E); return result; end FXNOR; function FXNOR (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := not (A xor B xor C xor D xor E xor F); return result; end FXNOR; function FXNOR (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := not (A xor B xor C xor D xor E xor F xor G); return result; end FXNOR; function FXNOR (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := not (A xor B xor C xor D xor E xor F xor G xor H); return result; end FXNOR; -- ***************************************************************** function FXOR (A, B: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B; return result; end FXOR; function FXOR (A, B, C: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C; return result; end FXOR; function FXOR (A, B, C, D: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C xor D; return result; end FXOR; function FXOR (A, B, C, D, E: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C xor D xor E; return result; end FXOR; function FXOR (A, B, C, D, E, F: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C xor D xor E xor F; return result; end FXOR; function FXOR (A, B, C, D, E, F, G: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C xor D xor E xor F xor G; return result; end FXOR; function FXOR (A, B, C, D, E, F, G, H: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result := A xor B xor C xor D xor E xor F xor G xor H; return result; end FXOR; function FXOR (A, B: bit) return bit is variable result : bit; begin result := A xor B; return result; end FXOR; function FXOR (A, B, C: bit) return bit is variable result : bit; begin result := A xor B xor C; return result; end FXOR; function FXOR (A, B, C, D: bit) return bit is variable result : bit; begin result := A xor B xor C xor D; return result; end FXOR; function FXOR (A, B, C, D, E: bit) return bit is variable result : bit; begin result := A xor B xor C xor D xor E; return result; end FXOR; function FXOR (A, B, C, D, E, F: bit) return bit is variable result : bit; begin result := A xor B xor C xor D xor E xor F; return result; end FXOR; function FXOR (A, B, C, D, E, F, G: bit) return bit is variable result : bit; begin result := A xor B xor C xor D xor E xor F xor G; return result; end FXOR; function FXOR (A, B, C, D, E, F, G, H: bit) return bit is variable result : bit; begin result := A xor B xor C xor D xor E xor F xor G xor H; return result; end FXOR; -- ***************************************************************** function INCR (A : bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; begin carry := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor carry; carry := A(i) and carry; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor carry; carry := A(i) and carry; end loop; end if; return (carry & result); end INCR; function INCR (A: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := not A; result(1) := A; return result; end INCR; function INCRNC (A : bit_vector) return bit_vector is variable result : bit_vector(A'range); variable carry : bit; begin carry := '1'; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor carry; carry := A(i) and carry; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor carry; carry := A(i) and carry; end loop; end if; return result; end INCRNC; function INCRNC (A: bit) return bit is variable result : bit; begin result := not A; return result; end INCRNC; -- ***************************************************************** function MUL (A, B: bit_vector) return bit_vector is variable result : bit_vector((2*A'length)-1 downto 0); variable part : bit_vector((2*A'length)-1 downto 0); variable temp : bit_vector((2*A'length)-1 downto 0); variable i : integer; variable j : integer; variable x : integer; variable A_reg : bit_vector(A'length-1 downto 0); variable B_reg : bit_vector(B'length-1 downto 0); variable carry : bit; variable k : integer; begin A_reg := A; B_reg := B; for i in result'range loop result(i) := '0'; temp(i) := '0'; end loop; x := 0; for j in B_reg'low to B_reg'high loop for i in part'range loop part(i) := '0'; end loop; for i in A_reg'low to A_reg'high loop part(x + i) := A_reg(i) and B_reg(j); end loop; x := x + 1; temp := result; carry := '0'; for i in part'right to part'left loop result(i) := part(i) xor temp(i) xor carry; carry := (part(i) and temp(i)) or (part(i) and carry) or (temp(i) and carry); end loop; end loop; return result; end MUL; function MUL (A, B: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result := '0' & (A and B); return result; end MUL; -- ***************************************************************** function MUX (A, B: bit_vector) return bit is variable G : bit_vector(A'range); variable C : bit_vector(B'range); variable result : bit; variable temp : bit_vector(B'length downto 0); variable carry : bit; variable temp2 : bit_vector(B'range); begin for i in C'range loop C(i) := '0'; end loop; for i in G'range loop G(i) := '1'; end loop; for i in A'reverse_range loop temp := not(B xor C) & A(i); for j in temp'range loop G(i) := G(i) and temp(j); end loop; temp2 := C; carry := '1'; if (B'left > B'right) then for j in B'right to B'left loop C(j) := temp2(j) xor carry; carry := temp2(j) and carry; end loop; end if; if (B'left < B'right) then for j in B'right downto B'left loop C(j) := temp2(j) xor carry; carry := temp2(j) and carry; end loop; end if; end loop; result := '0'; for i in G'range loop result := result or G(i); end loop; return result; end MUX; function MUX (A: bit_vector; B: bit) return bit is variable result : bit; begin result := (A(A'low) and not B) or (A(A'high) and B); return result; end MUX; -- ***************************************************************** function NMUX (A, B: bit_vector; C: bit) return bit_vector is variable result : bit_vector(A'range); variable j : integer; begin j := B'left; if (A'left > A'right) then for i in A'left downto A'right loop result(i) := (A(i) and not C) or (B(j) and C); if (B'left > B'right) then j := j - 1; else j := j + 1; end if; end loop; else for i in A'left to A'right loop result(i) := (A(i) and not C) or (B(j) and C); if (B'left > B'right) then j := j - 1; else j := j + 1; end if; end loop; end if; return result; end NMUX; function NMUX (A, B, C: bit) return bit is variable result : bit; begin result := (A and not C) or (B and C); return result; end NMUX; -- ***************************************************************** function REFL (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); begin if (A'left > A'right) then for i in A'left downto A'right loop result(i) := A(A'high - i); end loop; else for i in A'left to A'right loop result(i) := A(A'high - i); end loop; end if; return result; end REFL; -- ***************************************************************** function ROTL (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable temp : bit; begin temp := A(A'left); if (A'left > A'right) then for i in result'right+1 to result'left loop result(i) := A(i - 1); end loop; else for i in result'right-1 downto result'left loop result(i) := A(i + 1); end loop; end if; result(result'right) := temp; return result; end ROTL; function ROTL (A: bit) return bit is variable result : bit; begin result := A; return result; end ROTL; -- ***************************************************************** function ROTR (A: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable temp : bit; begin temp := A(A'right); if (A'left > A'right) then for i in result'left-1 downto result'right loop result(i) := A(i + 1); end loop; else for i in result'left+1 to result'right loop result(i) := A(i - 1); end loop; end if; result(result'left) := temp; return result; end ROTR; function ROTR (A: bit) return bit is variable result : bit; begin result := A; return result; end ROTR; -- ***************************************************************** function SHL0 (A: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result(result'right) := '0'; if (A'left > A'right) then for i in result'right+1 to result'left loop result(i) := A(i - 1); end loop; else for i in result'right-1 downto result'left loop result(i) := A(i + 1); end loop; end if; return result; end SHL0; function SHL0 (A: bit) return bit is variable result : bit; begin result := '0'; return result; end SHL0; -- ***************************************************************** function SHL1 (A: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result(result'right) := '1'; if (A'left > A'right) then for i in result'right+1 to result'left loop result(i) := A(i - 1); end loop; else for i in result'right-1 downto result'left loop result(i) := A(i + 1); end loop; end if; return result; end SHL1; function SHL1 (A: bit) return bit is variable result : bit; begin result := '1'; return result; end SHL1; -- ***************************************************************** function SHLIN (A: bit_vector; B: bit) return bit_vector is variable result : bit_vector (A'range); begin result(result'right) := B; if (A'left > A'right) then for i in result'right+1 to result'left loop result(i) := A(i - 1); end loop; else for i in result'right-1 downto result'left loop result(i) := A(i + 1); end loop; end if; return result; end SHLIN; function SHLIN (A, B: bit) return bit is variable result : bit; begin result := B; return result; end SHLIN; -- ***************************************************************** function SHR0 (A: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result(result'left) := '0'; if (A'left > A'right) then for i in result'left-1 downto result'right loop result(i) := A(i + 1); end loop; else for i in result'left+1 to result'right loop result(i) := A(i - 1); end loop; end if; return result; end SHR0; function SHR0 (A: bit) return bit is variable result : bit; begin result := '0'; return result; end SHR0; -- ***************************************************************** function SHR1 (A: bit_vector) return bit_vector is variable result : bit_vector (A'range); begin result(result'left) := '1'; if (A'left > A'right) then for i in result'left-1 downto result'right loop result(i) := A(i + 1); end loop; else for i in result'left+1 to result'right loop result(i) := A(i - 1); end loop; end if; return result; end SHR1; function SHR1 (A: bit) return bit is variable result : bit; begin result := '1'; return result; end SHR1; -- ***************************************************************** function SHRIN (A: bit_vector; B: bit) return bit_vector is variable result : bit_vector (A'range); begin result(result'left) := B; if (A'left > A'right) then for i in result'left-1 downto result'right loop result(i) := A(i + 1); end loop; else for i in result'left+1 to result'right loop result(i) := A(i - 1); end loop; end if; return result; end SHRIN; function SHRIN (A, B: bit) return bit is variable result : bit; begin result := B; return result; end SHRIN; -- ***************************************************************** function SUB (A, B, C: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := A xor B xor C; result(1) := ((not A) and (C or B)) or (C and B); return result; end SUB; function SUB (A, B: bit_vector; C: bit) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; variable j : integer; begin borrow := C; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return (borrow & result); end SUB; function SUB (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; variable j : integer; begin borrow := '0'; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return (borrow & result); end SUB; function SUB (A, B: bit) return bit_vector is variable result : bit_vector(1 downto 0); begin result(0) := A xor B; result(1) := (not A) and B; return result; end SUB; function SUBNC (A, B: bit_vector) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; variable j : integer; begin borrow := '0'; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return result; end SUBNC; function SUBNC (A, B: bit_vector; C: bit) return bit_vector is variable result : bit_vector(A'range); variable borrow : bit; variable j : integer; begin borrow := C; j := B'right; if (A'left > A'right) then for i in A'right to A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; else for i in A'right downto A'left loop result(i) := A(i) xor B(j) xor borrow; borrow := ((not A(i)) and (borrow or B(j))) or (borrow and B(j)); if (B'left > B'right) then j := j + 1; else j := j - 1; end if; end loop; end if; return result; end SUBNC; function SUBNC (A, B: bit) return bit is variable result : bit; begin result := A xor B; return result; end SUBNC; function SUBNC (A, B, C: bit) return bit is variable result : bit; begin result := A xor B xor C; return result; end SUBNC; -- ***************************************************************** end Nimbus_bit;