1 --------------------------------------------------------------------------
2 --
3 -- Copyright (C) 1993, Peter J. Ashenden
4 -- Mail: Dept. Computer Science
5 -- University of Adelaide, SA 5005, Australia
6 -- e-mail: petera@cs.adelaide.edu.au
7 --
8 -- This program is free software; you can redistribute it and/or modify
9 -- it under the terms of the GNU General Public License as published by
10 -- the Free Software Foundation; either version 1, or (at your option)
11 -- any later version.
12 --
13 -- This program is distributed in the hope that it will be useful,
14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 -- GNU General Public License for more details.
17 --
18 -- You should have received a copy of the GNU General Public License
19 -- along with this program; if not, write to the Free Software
20 -- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 --
22 --------------------------------------------------------------------------
23 --
24 -- $RCSfile: bv_arithmetic.vhdl,v $ $Revision: 1.1 $ $Date: 2000/05/08 14:36:47 $
25 --
26 --------------------------------------------------------------------------
27 --
28 -- Bit vector arithmetic package specification.
29 --
30 -- Does arithmetic and logical operations on bit vectors, treating them
31 -- as either unsigned or signed (2's complement) integers. Leftmost bit
32 -- is most significant or sign bit, rightmost bit is least significant
33 -- bit. Dyadic operations need the two arguments to be of the same
34 -- length, however their index ranges and directions may differ. Results
35 -- must be of the same length as the operands.
36 --
37 --------------------------------------------------------------------------
38
39 use std.textio.line;
40
41 package bv_arithmetic is
42
43 ----------------------------------------------------------------
44 -- Type conversions
45 ----------------------------------------------------------------
46
47 -- Convert bit vector encoded unsigned integer to natural.
48
49 function bv_to_natural (bv : in bit_vector) return natural;
50
51 -- Convert natural to bit vector encoded unsigned integer.
52 -- (length is used as the size of the result.)
53
54 function natural_to_bv (nat : in natural;
55 length : in natural) return bit_vector;
56
57 -- Convert bit vector encoded signed integer to integer
58
59 function bv_to_integer (bv : in bit_vector) return integer;
60
61 -- Convert integer to bit vector encoded signed integer.
62 -- (length is used as the size of the result.)
63
64 function integer_to_bv (int : in integer;
65 length : in natural) return bit_vector;
66
67 ----------------------------------------------------------------
68 -- Arithmetic operations
69 ----------------------------------------------------------------
70
71 -- Signed addition with overflow detection
72
73 procedure bv_add (bv1, bv2 : in bit_vector;
74 bv_result : out bit_vector;
75 overflow : out boolean);
76
77 -- Signed addition without overflow detection
78
79 function "+" (bv1, bv2 : in bit_vector) return bit_vector;
80
81 -- Signed subtraction with overflow detection
82
83 procedure bv_sub (bv1, bv2 : in bit_vector;
84 bv_result : out bit_vector;
85 overflow : out boolean);
86
87 -- Signed subtraction without overflow detection
88
89 function "-" (bv1, bv2 : in bit_vector) return bit_vector;
90
91 -- Unsigned addition with overflow detection
92
93 procedure bv_addu (bv1, bv2 : in bit_vector;
94 bv_result : out bit_vector;
95 overflow : out boolean);
96
97 -- Unsigned addition without overflow detection
98
99 procedure bv_addu (bv1, bv2 : in bit_vector;
100 bv_result : out bit_vector);
101
102 -- Unsigned subtraction with overflow detection
103
104 procedure bv_subu (bv1, bv2 : in bit_vector;
105 bv_result : out bit_vector;
106 overflow : out boolean);
107
108 -- Unsigned subtraction without overflow detection
109
110 procedure bv_subu (bv1, bv2 : in bit_vector;
111 bv_result : out bit_vector);
112
113 -- Signed negation with overflow detection
114
115 procedure bv_neg (bv : in bit_vector;
116 bv_result : out bit_vector;
117 overflow : out boolean);
118
119 -- Signed negation without overflow detection
120
121 function "-" (bv : in bit_vector) return bit_vector;
122
123 -- Signed multiplication with overflow detection
124
125 procedure bv_mult (bv1, bv2 : in bit_vector;
126 bv_result : out bit_vector;
127 overflow : out boolean);
128
129 -- Signed multiplication without overflow detection
130
131 function "*" (bv1, bv2 : in bit_vector) return bit_vector;
132
133 -- Unsigned multiplication with overflow detection
134
135 procedure bv_multu (bv1, bv2 : in bit_vector;
136 bv_result : out bit_vector;
137 overflow : out boolean);
138
139 -- Unsigned multiplication without overflow detection
140
141 procedure bv_multu (bv1, bv2 : in bit_vector;
142 bv_result : out bit_vector);
143
144 -- Signed division with divide by zero and overflow detection
145
146 procedure bv_div (bv1, bv2 : in bit_vector;
147 bv_result : out bit_vector;
148 div_by_zero : out boolean;
149 overflow : out boolean);
150
151 -- Signed division without divide by zero and overflow detection
152
153 function "/" (bv1, bv2 : in bit_vector) return bit_vector;
154
155 -- Unsigned division with divide by zero detection
156
157 procedure bv_divu (bv1, bv2 : in bit_vector;
158 bv_result : out bit_vector;
159 div_by_zero : out boolean);
160
161 -- Unsigned division without divide by zero detection
162
163 procedure bv_divu (bv1, bv2 : in bit_vector;
164 bv_result : out bit_vector);
165
166 ----------------------------------------------------------------
167 -- Logical operators
168 -- (Provided for VHDL-87, built in for VHDL-93)
169 ----------------------------------------------------------------
170
171 -- Shift left logical (fill with '0' bits)
172
173 function bv_sll (bv : in bit_vector;
174 shift_count : in natural) return bit_vector;
175
176 -- Shift right logical (fill with '0' bits)
177
178 function bv_srl (bv : in bit_vector;
179 shift_count : in natural) return bit_vector;
180
181 -- Shift right arithmetic (fill with copy of sign bit)
182
183 function bv_sra (bv : in bit_vector;
184 shift_count : in natural) return bit_vector;
185
186 -- Rotate left
187
188 function bv_rol (bv : in bit_vector;
189 rotate_count : in natural) return bit_vector;
190
191 -- Rotate right
192
193 function bv_ror (bv : in bit_vector;
194 rotate_count : in natural) return bit_vector;
195
196 ----------------------------------------------------------------
197 -- Arithmetic comparison operators.
198 -- Perform comparisons on bit vector encoded signed integers.
199 -- (For unsigned integers, built in lexical comparison does
200 -- the required operation.)
201 ----------------------------------------------------------------
202
203 -- Signed less than comparison
204
205 function bv_lt (bv1, bv2 : in bit_vector) return boolean;
206
207 -- Signed less than or equal comparison
208
209 function bv_le (bv1, bv2 : in bit_vector) return boolean;
210
211 -- Signed greater than comparison
212
213 function bv_gt (bv1, bv2 : in bit_vector) return boolean;
214
215 -- Signed greater than or equal comparison
216
217 function bv_ge (bv1, bv2 : in bit_vector) return boolean;
218
219 ----------------------------------------------------------------
220 -- Extension operators - convert a bit vector to a longer one
221 ----------------------------------------------------------------
222
223 -- Sign extension - replicate the sign bit of the operand into
224 -- the most significant bits of the result. Length parameter
225 -- determines size of result. If length < bv'length, result is
226 -- rightmost length bits of bv.
227
228 function bv_sext (bv : in bit_vector;
229 length : in natural) return bit_vector;
230
231 -- Zero extension - replicate zero bits into the most significant
232 -- bits of the result. Length parameter determines size of result.
233 -- If length < bv'length, result is rightmost length bits of bv.
234
235 function bv_zext (bv : in bit_vector;
236 length : in natural) return bit_vector;
237
238 end bv_arithmetic;
239
This page was generated using GHDL 0.14 (20040829) [Sokcho edition], a program written by Tristan Gingold