OpenCores
URL https://opencores.org/ocsvn/pavr/pavr/trunk

Subversion Repositories pavr

[/] [pavr/] [trunk/] [src/] [std_util.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 doru
-- <File header>
2
-- Project
3
--    pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
4
--    AVR core, but about 3x faster in terms of both clock frequency and MIPS.
5
--    The increase in speed comes from a relatively deep pipeline. The original
6
--    AVR core has only two pipeline stages (fetch and execute), while pAVR has
7
--    6 pipeline stages:
8
--       1. PM    (read Program Memory)
9
--       2. INSTR (load Instruction)
10
--       3. RFRD  (decode Instruction and read Register File)
11
--       4. OPS   (load Operands)
12
--       5. ALU   (execute ALU opcode or access Unified Memory)
13
--       6. RFWR  (write Register File)
14
-- Version
15
--    0.32
16
-- Date
17
--    2002 August 07
18
-- Author
19
--    Doru Cuturela, doruu@yahoo.com
20
-- License
21
--    This program is free software; you can redistribute it and/or modify
22
--    it under the terms of the GNU General Public License as published by
23
--    the Free Software Foundation; either version 2 of the License, or
24
--    (at your option) any later version.
25
--    This program is distributed in the hope that it will be useful,
26
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
27
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
--    GNU General Public License for more details.
29
--    You should have received a copy of the GNU General Public License
30
--    along with this program; if not, write to the Free Software
31
--    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
-- </File header>
33
 
34
 
35
 
36
-- <File info>
37
-- This file contains:
38
--    - Type conversion routines ofted used throughout the other source files in
39
--       this project
40
--    - Basic arithmetic functions
41
--       *** Multiplication is not yet defined! It will be defined here.
42
--    - Sign and zero-extend functions
43
--    - Vector comparision function
44
-- </File info>
45
 
46
 
47
 
48
-- <File body>
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.std_logic_arith.all;
52
use ieee.std_logic_signed.all;
53
 
54
 
55
 
56
package std_util is
57
   function std_logic_vector_to_int(vec: std_logic_vector) return integer;
58
   function std_logic_vector_to_nat(vec: std_logic_vector) return natural;
59
   function int_to_std_logic_vector(i, len: integer) return std_logic_vector;
60
 
61
   function "+"(a: std_logic_vector; b: std_logic_vector) return std_logic_vector;
62
   function "+"(a: std_logic_vector; b: integer) return std_logic_vector;
63
   function "-"(a: std_logic_vector; b: std_logic_vector) return std_logic_vector;
64
   function "-"(a: std_logic_vector; b: integer) return std_logic_vector;
65
 
66
   function sign_extend(a: std_logic_vector; wxtd: natural) return std_logic_vector;
67
   function zero_extend(a: std_logic_vector; wxtd: natural) return std_logic_vector;
68
 
69
   function cmp_std_logic_vector(a: std_logic_vector; b: std_logic_vector) return std_logic;
70
end;
71
 
72
 
73
 
74
package body std_util is
75
 
76
   function std_logic_vector_to_int(vec: std_logic_vector) return integer is
77
      variable i: integer;
78
   begin
79
      i := conv_integer(vec);
80
      return(i);
81
   end;
82
 
83
 
84
   function std_logic_vector_to_nat(vec: std_logic_vector) return natural is
85
      variable tmp: std_logic_vector(vec'length downto 0);
86
      variable n: natural;
87
   begin
88
      assert (vec'length < 32)
89
         report "Error: vector length > 31 in function `std_logic_vector_to_nat'."
90
         severity failure;
91
      tmp := '0' & vec;
92
      n := conv_integer(tmp);
93
      return(n);
94
   end;
95
 
96
 
97
   function int_to_std_logic_vector(i, len: integer) return std_logic_vector is
98
      variable r: std_logic_vector(len - 1 downto 0);
99
      variable r1: std_logic_vector(len downto 0);
100
   begin
101
      r1 := conv_std_logic_vector(i, len + 1);
102
      r := r1(len - 1 downto 0);
103
      return(r);
104
   end;
105
 
106
 
107
   function "+"(a: std_logic_vector; b: std_logic_vector) return std_logic_vector is
108
   begin
109
      return(signed(a) + signed(b));
110
   end;
111
 
112
 
113
   function "+"(a: std_logic_vector; b: integer) return std_logic_vector is
114
   begin
115
      return(signed(a) + b);
116
   end;
117
 
118
 
119
   function "-"(a: std_logic_vector; b: std_logic_vector) return std_logic_vector is
120
   begin
121
      return(signed(a) - signed(b));
122
   end;
123
 
124
 
125
   function "-"(a: std_logic_vector; b: integer) return std_logic_vector is
126
   begin
127
      return (signed(a) - b);
128
   end;
129
 
130
 
131
   function sign_extend(a: std_logic_vector; wxtd: natural) return std_logic_vector is
132
      variable r: std_logic_vector(wxtd - 1 downto 0);
133
   begin
134
      assert (a'length <= wxtd)
135
         report "Error: vector length > extended vector length in function `sign_extend'."
136
         severity failure;
137
      for i in 0 to a'length-1 loop
138
         r(i) := a(i);
139
      end loop;
140
      for i in a'length to wxtd - 1 loop
141
         r(i) := a(a'length - 1);
142
      end loop;
143
      return r;
144
   end;
145
 
146
 
147
   function zero_extend(a: std_logic_vector; wxtd: natural) return std_logic_vector is
148
      variable r: std_logic_vector(wxtd - 1 downto 0);
149
   begin
150
      assert (a'length <= wxtd)
151
         report "Error: vector length > extended vector length in function `sign_extend'."
152
         severity failure;
153
      for i in 0 to a'length-1 loop
154
         r(i) := a(i);
155
      end loop;
156
      for i in a'length to wxtd - 1 loop
157
         r(i) := '0';
158
      end loop;
159
      return r;
160
   end;
161
 
162
 
163
   function cmp_std_logic_vector(a: std_logic_vector; b: std_logic_vector) return std_logic is
164
      variable r: std_logic;
165
   begin
166
      assert (a'length = b'length)
167
         report "Error: vectors don't have the same length in function `cmp_std_logic_vector'."
168
         severity failure;
169
      r := '1';
170
      for i in 0 to a'length - 1 loop
171
         if (a(i) /= b(i)) then
172
            r := '0';
173
         end if;
174
      end loop;
175
      return r;
176
   end;
177
 
178
end;
179
-- </File body>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.