📄 synopsys.vhd
字号:
end; function ">="(L: INTEGER; R: SIGNED) return BOOLEAN is -- pragma label_applies_to geq constant length: INTEGER := R'length; begin return is_less_or_equal(CONV_SIGNED(R, length), CONV_SIGNED(L, length)); -- pragma label geq end; -- for internal use only. Assumes SIGNED arguments of equal length. function bitwise_eql(L: BIT_VECTOR; R: BIT_VECTOR) return BOOLEAN is -- pragma built_in SYN_EQL begin for i in L'range loop if L(i) /= R(i) then return FALSE; end if; end loop; return TRUE; end; -- for internal use only. Assumes SIGNED arguments of equal length. function bitwise_neq(L: BIT_VECTOR; R: BIT_VECTOR) return BOOLEAN is -- pragma built_in SYN_NEQ begin for i in L'range loop if L(i) = R(i) then return FALSE; end if; end loop; return TRUE; end; function "="(L: UNSIGNED; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length); begin return bitwise_eql( BIT_VECTOR( CONV_UNSIGNED(L, length) ), BIT_VECTOR( CONV_UNSIGNED(R, length) ) ); end; function "="(L: SIGNED; R: SIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length); begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: UNSIGNED; R: SIGNED) return BOOLEAN is constant length: INTEGER := max(L'length + 1, R'length); begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: SIGNED; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length + 1); begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: UNSIGNED; R: INTEGER) return BOOLEAN is constant length: INTEGER := L'length + 1; begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: INTEGER; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := R'length + 1; begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: SIGNED; R: INTEGER) return BOOLEAN is constant length: INTEGER := L'length; begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "="(L: INTEGER; R: SIGNED) return BOOLEAN is constant length: INTEGER := R'length; begin return bitwise_eql( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: UNSIGNED; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length); begin return bitwise_neq( BIT_VECTOR( CONV_UNSIGNED(L, length) ), BIT_VECTOR( CONV_UNSIGNED(R, length) ) ); end; function "/="(L: SIGNED; R: SIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length); begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: UNSIGNED; R: SIGNED) return BOOLEAN is constant length: INTEGER := max(L'length + 1, R'length); begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: SIGNED; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := max(L'length, R'length + 1); begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: UNSIGNED; R: INTEGER) return BOOLEAN is constant length: INTEGER := L'length + 1; begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: INTEGER; R: UNSIGNED) return BOOLEAN is constant length: INTEGER := R'length + 1; begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: SIGNED; R: INTEGER) return BOOLEAN is constant length: INTEGER := L'length; begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function "/="(L: INTEGER; R: SIGNED) return BOOLEAN is constant length: INTEGER := R'length; begin return bitwise_neq( BIT_VECTOR( CONV_SIGNED(L, length) ), BIT_VECTOR( CONV_SIGNED(R, length) ) ); end; function SHL(ARG: UNSIGNED; COUNT: UNSIGNED) return UNSIGNED is constant control_msb: INTEGER := COUNT'length - 1; variable control: UNSIGNED (control_msb downto 0); constant result_msb: INTEGER := ARG'length-1; subtype rtype is UNSIGNED (result_msb downto 0); variable result, temp: rtype; begin control := COUNT; result := ARG; for i in 0 to control_msb loop if (2**i < result_msb) and (control(i) = '1') then temp := rtype'(others => '0'); temp(result_msb downto 2**i) := result(result_msb - 2**i downto 0); result := temp; end if; end loop; return result; end; function SHL(ARG: SIGNED; COUNT: UNSIGNED) return SIGNED is constant control_msb: INTEGER := COUNT'length - 1; variable control: UNSIGNED (control_msb downto 0); constant result_msb: INTEGER := ARG'length-1; subtype rtype is SIGNED (result_msb downto 0); variable result, temp: rtype; begin control := COUNT; result := ARG; for i in 0 to control_msb loop if (2**i < result_msb) and (control(i) = '1') then temp := rtype'(others => '0'); temp(result_msb downto 2**i) := result(result_msb - 2**i downto 0); result := temp; end if; end loop; return result; end; function SHR(ARG: UNSIGNED; COUNT: UNSIGNED) return UNSIGNED is constant control_msb: INTEGER := COUNT'length - 1; variable control: UNSIGNED (control_msb downto 0); constant result_msb: INTEGER := ARG'length-1; subtype rtype is UNSIGNED (result_msb downto 0); variable result, temp: rtype; begin control := COUNT; result := ARG; for i in 0 to control_msb loop if (2**i < result_msb) and (control(i) = '1') then temp := rtype'(others => '0'); temp(result_msb - 2**i downto 0) := result(result_msb downto 2**i); result := temp; end if; end loop; return result; end; function SHR(ARG: SIGNED; COUNT: UNSIGNED) return SIGNED is constant control_msb: INTEGER := COUNT'length - 1; variable control: UNSIGNED (control_msb downto 0); constant result_msb: INTEGER := ARG'length-1; subtype rtype is SIGNED (result_msb downto 0); variable result, temp: rtype; variable sign_bit: BIT; begin control := COUNT; result := ARG; sign_bit := ARG(ARG'left); for i in 0 to control_msb loop if (2**i < result_msb) and (control(i) = '1') then temp := rtype'(others => sign_bit); temp(result_msb - 2**i downto 0) := result(result_msb downto 2**i); result := temp; end if; end loop; return result; end; function CONV_INTEGER(ARG: INTEGER) return INTEGER is begin return ARG; end; function CONV_INTEGER(ARG: UNSIGNED) return INTEGER is variable result: INTEGER; -- synopsys built_in SYN_UNSIGNED_TO_INTEGER; begin -- synopsys synthesis_off assert ARG'length <= 31 report "ARG is too large in CONV_INTEGER" severity FAILURE; result := 0; for i in ARG'range loop result := result * 2; if ARG(i) = '1' then result := result + 1; end if; end loop; return result; -- synopsys synthesis_on end; function CONV_INTEGER(ARG: SIGNED) return INTEGER is variable result: INTEGER; -- synopsys built_in SYN_SIGNED_TO_INTEGER; begin -- synopsys synthesis_off assert ARG'length <= 32 report "ARG is too large in CONV_INTEGER" severity FAILURE; result := 0; for i in ARG'range loop if i /= ARG'left then result := result * 2; if ARG(i) = '1' then result := result + 1; end if; end if; end loop; if ARG(ARG'left) = '1' then if ARG'length = 32 then result := (result - 2**30) - 2**30; else result := result - (2 ** (ARG'length-1)); end if; end if; return result; -- synopsys synthesis_on end; function CONV_INTEGER(ARG: BIT) return SMALL_INT is begin if ARG = '0' then return 0; else return 1; end if; end; -- convert an integer to a unsigned BIT_VECTOR function CONV_UNSIGNED(ARG: INTEGER; SIZE: INTEGER) return UNSIGNED is variable result: UNSIGNED(SIZE-1 downto 0); variable temp: integer; -- synopsys built_in SYN_INTEGER_TO_UNSIGNED begin -- synopsys synthesis_off temp := ARG; for i in 0 to SIZE-1 loop if (temp mod 2) = 1 then result(i) := '1'; else result(i) := '0'; end if; temp := temp / 2; end loop; return result; -- synopsys synthesis_on end; function CONV_UNSIGNED(ARG: UNSIGNED; SIZE: INTEGER) return UNSIGNED is constant msb: INTEGER := min(ARG'length, SIZE) - 1; subtype rtype is UNSIGNED (SIZE-1 downto 0); variable new_bounds: UNSIGNED (ARG'length-1 downto 0); variable result: rtype; -- synopsys built_in SYN_ZERO_EXTEND begin -- synopsys synthesis_off result := rtype'(others => '0'); new_bounds := ARG; result(msb downto 0) := new_bounds(msb downto 0); return result; -- synopsys synthesis_on end; function CONV_UNSIGNED(ARG: SIGNED; SIZE: INTEGER) return UNSIGNED is constant msb: INTEGER := min(ARG'length, SIZE) - 1; subtype rtype is UNSIGNED (SIZE-1 downto 0); variable new_bounds: UNSIGNED (ARG'length-1 downto 0); variable result: rtype; -- synopsys built_in SYN_SIGN_EXTEND begin -- synopsys synthesis_off result := rtype'(others => ARG(ARG'left)); new_bounds := UNSIGNED(ARG); result(msb downto 0) := new_bounds(msb downto 0); return result; -- synopsys synthesis_on end; function CONV_UNSIGNED(ARG: BIT; SIZE: INTEGER) return UNSIGNED is subtype rtype is UNSIGNED (SIZE-1 downto 0); variable result: rtype; -- synopsys built_in SYN_ZERO_EXTEND begin -- synopsys synthesis_off result := rtype'(others => '0'); result(0) := ARG; return result; -- synopsys synthesis_on end; -- convert an integer to a 2's complement BIT_VECTOR function CONV_SIGNED(ARG: INTEGER; SIZE: INTEGER) return SIGNED is variable result: SIGNED (SIZE-1 downto 0); variable temp: integer; variable negative: boolean; -- synopsys built_in SYN_INTEGER_TO_SIGNED begin -- synopsys synthesis_off temp := ARG; if temp < 0 then -- In order to make the "/2" operation like a shift, -- we need to make the arg a positive number. temp := (temp + (2**30)) + (2**30); negative := TRUE; else negative := FALSE; end if; for i in 0 to SIZE-1 loop if (temp mod 2) = 1 then result(i) := '1'; else result(i) := '0'; end if; temp := temp / 2; end loop; -- If we are converting a >31 bit number which is negative, -- the high bits have been calculated incorrectly. if negative and (SIZE > 31) then for i in 31 to SIZE-1 loop result(i) := '1'; end loop; end if; return result; -- synopsys synthesis_on end; function CONV_SIGNED(ARG: UNSIGNED; SIZE: INTEGER) return SIGNED is constant msb: INTEGER := min(ARG'length, SIZE) - 1; subtype rtype is SIGNED (SIZE-1 downto 0); variable new_bounds : SIGNED (ARG'length-1 downto 0); variable result: rtype; -- synopsys built_in SYN_ZERO_EXTEND begin -- synopsys synthesis_off result := rtype'(others => '0'); new_bounds := SIGNED(ARG); result(msb downto 0) := new_bounds(msb downto 0); return result; -- synopsys synthesis_on end; function CONV_SIGNED(ARG: SIGNED; SIZE: INTEGER) return SIGNED is constant msb: INTEGER := min(ARG'length, SIZE) - 1; subtype rtype is SIGNED (SIZE-1 downto 0); variable new_bounds : SIGNED (ARG'length-1 downto 0); variable result: rtype; -- synopsys built_in SYN_SIGN_EXTEND begin -- synopsys synthesis_off result := rtype'(others => ARG(ARG'left)); new_bounds := ARG; result(msb downto 0) := new_bounds(msb downto 0); return result; -- synopsys synthesis_on end; function CONV_SIGNED(ARG: BIT; SIZE: INTEGER) return SIGNED is subtype rtype is SIGNED (SIZE-1 downto 0); variable result: rtype; -- synopsys built_in SYN_ZERO_EXTEND begin -- synopsys synthesis_off result := rtype'(others => '0'); result(0) := ARG; return result; -- synopsys synthesis_on end; function AND_REDUCE(ARG: BIT_VECTOR) return BIT is variable result: BIT; begin result := '1'; for i in ARG'range loop result := result and ARG(i); end loop; return result; end; function NAND_REDUCE(ARG: BIT_VECTOR) return BIT is begin return not AND_REDUCE(ARG); end; function OR_REDUCE(ARG: BIT_VECTOR) return BIT is variable result: BIT; begin result := '0'; for i in ARG'range loop result := result or ARG(i); end loop; return result; end; function NOR_REDUCE(ARG: BIT_VECTOR) return BIT is begin return not OR_REDUCE(ARG); end; function XOR_REDUCE(ARG: BIT_VECTOR) return BIT is variable result: BIT; begin result := '0'; for i in ARG'range loop result := result xor ARG(i); end loop; return result; end; function XNOR_REDUCE(ARG: BIT_VECTOR) return BIT is begin return not XOR_REDUCE(ARG); end;end synopsys;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -