-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstd_logic_arithext.vhd
48 lines (48 loc) · 1.99 KB
/
std_logic_arithext.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--------------------------------------------------------------------------
-- --
-- --
-- This source file may be used and distributed without restriction --
-- provided that this copyright statement is not removed from the file --
-- and that any derivative work contains this copyright notice. --
-- --
-- Package name: STD_LOGIC_ARITHEXT --
-- Purpose: --
-- A set of arithemtic, conversion, and comparison functions --
-- STD_LOGIC --
-- --
--------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
package std_logic_arithext is
function LOGIC_SIGN_EXT(ARG: STD_LOGIC; SIZE: INTEGER) return STD_LOGIC_VECTOR;
function LOGIC_ZERO_EXT(ARG: STD_LOGIC; SIZE: INTEGER) return STD_LOGIC_VECTOR;
end std_logic_arithext;
library IEEE;
use IEEE.std_logic_1164.all;
package body std_logic_arithext is
function LOGIC_SIGN_EXT(ARG: STD_LOGIC; SIZE: INTEGER) return STD_LOGIC_VECTOR is
subtype rtype is STD_LOGIC_VECTOR (SIZE-1 downto 0);
variable result: rtype;
-- synopsys built_in SYN_ZERO_EXTEND
begin
if (ARG = '0') then
result := rtype'(others => '0');
elsif (ARG = '1') then
result := rtype'(others => '1');
elsif (ARG = 'X') then
result := rtype'(others => 'X');
end if;
return result;
end;
function LOGIC_ZERO_EXT(ARG: STD_LOGIC; SIZE: INTEGER) return STD_LOGIC_VECTOR is
subtype rtype is STD_LOGIC_VECTOR (SIZE-1 downto 0);
variable result: rtype;
begin
result := rtype'(others => '0');
result(0) := ARG;
if (result(0) = 'X') then
result := rtype'(others => 'X');
end if;
return result;
end;
end std_logic_arithext;