-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.vhd
173 lines (155 loc) · 4.57 KB
/
types.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
--------------------------------------------------------------------------------
-- Title : Types
-- Project : FFT
-- File : types.vhd
-- Authors : Djordje & Dusan
-- Created : Sun Dec 4
-- Version : 1.0
-- Description : Commonly used types around the project.
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
--! Commonly used types around the project.
package types is
--! Number of bits per word
constant word_size : integer := 16;
--! A type representing complex numbers with #word_size precision
type complex is record
--! Real part
re : signed(word_size - 1 downto 0);
--! Imaginary part
im : signed(word_size - 1 downto 0);
end record;
--! A #complex with double precision.
type complex_double is record
--! Real part
re : signed(2 * word_size - 1 downto 0);
--! Imaginary part
im : signed(2 * word_size - 1 downto 0);
end record;
--! Helper type for representing vectors of #complex numbers
type complex_vector is array (natural range <>) of complex;
--! Converts a pair of integers to a complex number
--! @param re_arg The real part of the new complex number
--! @param im_arg The real part of the new complex number
--! @return The new complex number
function pair2complex (
re_arg, im_arg : integer
) return complex;
--! Adds two #complex numbers
--! @param a Addant
--! @param b Adder
--! @return Addition
function "+"(
a, b : complex
) return complex;
--! Adds two #complex_double numbers
--! @param a Addant
--! @param b Adder
--! @return Addition
function "+"(
a, b : complex_double
) return complex_double;
--! Subtracts two #complex numbers
--! @param a Subtractee
--! @param b Subtractor
--! @return Substraction
function "-"(
a, b : complex
) return complex;
--! Subtracts two #complex_double numbers
--! @param a Subtractee
--! @param b Subtractor
--! @return Substraction
function "-"(
a, b : complex_double
) return complex_double;
--! Multiplies two #complex numbers
--! @param a Multiplicant
--! @param b Multiplier
--! @return Multiplication
function "*"(
a, b : complex
) return complex_double;
end package types;
package body types is
--! Converts a pair of integers to a complex number
--! @param re_arg The real part of the new complex number
--! @param im_arg The real part of the new complex number
--! @return The new complex number
function pair2complex (
re_arg, im_arg : integer
) return complex is
begin
return (
re => to_signed(re_arg, word_size),
im => to_signed(im_arg, word_size)
);
end function pair2complex;
--! Adds two #complex numbers
--! @param a Addant
--! @param b Adder
--! @return Addition
function "+"(
a, b : complex
) return complex is
begin
return (
re => a.re + b.re,
im => a.im + b.im
);
end function "+";
--! Adds two #complex_double numbers
--! @param a Addant
--! @param b Adder
--! @return Addition
function "+"(
a, b : complex_double
) return complex_double is
begin
return (
re => a.re + b.re,
im => a.im + b.im
);
end function "+";
--! Subtracts two #complex numbers
--! @param a Subtractee
--! @param b Subtractor
--! @return Substraction
function "-"(
a, b : complex
) return complex is
begin
return (
re => a.re - b.re,
im => a.im - b.im
);
end function "-";
--! Subtracts two #complex_double numbers
--! @param a Subtractee
--! @param b Subtractor
--! @return Substraction
function "-"(
a, b : complex_double
) return complex_double is
begin
return (
re => a.re - b.re,
im => a.im - b.im
);
end function "-";
--! Multiplies two #complex numbers
--! @param a Multiplicant
--! @param b Multiplier
--! @return Multiplication
function "*"(
a, b : complex
) return complex_double is
begin
return (
a.re * b.re - a.im * b.im,
a.re * b.im + a.im * b.re
);
end function "*";
end package body types;