forked from OSVVM/OSVVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemorySupportPkg.vhd
281 lines (257 loc) · 11.5 KB
/
MemorySupportPkg.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
--
-- File Name: MemorySupportPkg.vhd
-- Design Unit Name: MemorySupportPkg
-- Revision: STANDARD VERSION
--
-- Maintainer: Jim Lewis email: [email protected]
-- Contributor(s):
-- Jim Lewis email: [email protected]
--
-- Description
-- Defines the storage policies: X, NoX, and orig
-- Supports MemoryGenericPkg
-- Policies are implemented in instances in MemoryPkg
--
-- Developed for:
-- SynthWorks Design Inc.
-- VHDL Training Classes
-- 11898 SW 128th Ave. Tigard, Or 97223
-- http://www.SynthWorks.com
--
-- Revision History:
-- Date Version Description
-- 10/2022 2022.10 Minor changes
-- 08/2022 2022.08 Initial revision
--
--
-- This file is part of OSVVM.
--
-- Copyright (c) 2022 by SynthWorks Design Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
library IEEE ;
use IEEE.std_logic_1164.all ;
use IEEE.numeric_std.all ;
use IEEE.numeric_std_unsigned.all ;
use IEEE.math_real.all ;
use work.AlertLogPkg.all ;
package MemorySupportPkg is
subtype MemoryBaseType is integer_vector ;
-- -----------------------------------------------
-- Memory Policy X
-- Maintains fidelity of X and U
-- Each integer value stores 16 bits of data and 16 bits o X and U
-- Bit size unlimited
--
subtype MemoryBaseType_X is integer_vector ;
function SizeMemoryBaseType_X(Size : integer) return integer ;
function ToMemoryBaseType_X (Slv : std_logic_vector ; Size : integer) return integer_vector ;
function FromMemoryBaseType_X(Mem : integer_vector ; Size : integer) return std_logic_vector ;
function InitMemoryBaseType_X(Size : integer) return integer_vector ;
-- -----------------------------------------------
-- Memory Policy NoX
-- X and U are stored as a 0
-- Each integer value stores 32 bits of data
-- Bit size unlimited
-- For larger word widths, uses half storage as X
--
subtype MemoryBaseType_NoX is integer_vector ;
function SizeMemoryBaseType_NoX(Size : integer) return integer ;
function ToMemoryBaseType_NoX (Slv : std_logic_vector ; Size : integer) return integer_vector ;
function FromMemoryBaseType_NoX(Mem : integer_vector ; Size : integer) return std_logic_vector ;
function InitMemoryBaseType_NoX(Size : integer) return integer_vector ;
-- -----------------------------------------------
-- Memory policy orig
-- For backward compatibility only
-- upto 31 bits of data
-- X or U in any bit and the word becomes X
--
subtype MemoryBaseType_orig is integer_vector ;
function SizeMemoryBaseType_orig(Size : integer) return integer ;
function ToMemoryBaseType_orig (Slv : std_logic_vector ; Size : integer) return integer_vector ;
function FromMemoryBaseType_orig(Mem : integer_vector ; Size : integer) return std_logic_vector ;
function InitMemoryBaseType_orig(Size : integer) return integer_vector ;
end MemorySupportPkg ;
package body MemorySupportPkg is
------------------------------------------------------------
-- Memory Policy X
-- Maintains fidelity of X and U
-- Each integer value stores 16 bits of data and 16 bits o X and U
------------------------------------------------------------
------------------------------------------------------------
function SizeMemoryBaseType_X(Size : integer) return integer is
------------------------------------------------------------
begin
return integer(Ceil(real(Size)/16.0)) ;
end function SizeMemoryBaseType_X ;
------------------------------------------------------------
function ToMemoryBaseType_X(Slv : std_logic_vector ; Size : integer) return integer_vector is
------------------------------------------------------------
variable NormalizedSlv : std_logic_vector(Size*16-1 downto 0) ;
variable Bits16 : std_logic_vector(15 downto 0) ;
variable BitIsX : std_logic_vector(15 downto 0) ;
variable BitVal : std_logic_vector(15 downto 0) ;
variable result : integer_vector (Size-1 downto 0) ;
begin
NormalizedSlv := Resize(Slv, Size*16) ;
for MemIndex in result'reverse_range loop
Bits16 := NormalizedSlv(16*MemIndex+15 downto 16*MemIndex) ;
for BitIndex in 0 to 15 loop
if Is_X(Bits16(BitIndex)) then
BitIsX(BitIndex) := '1' ;
BitVal(BitIndex) := '1' when Bits16(BitIndex) = 'U' else '0' ;
else
BitIsX(BitIndex) := '0' ;
BitVal(BitIndex) := Bits16(BitIndex) ;
end if ;
end loop ;
result(MemIndex) := to_integer(signed(BitIsX & BitVal)) ;
end loop ;
return result ;
end function ToMemoryBaseType_X ;
------------------------------------------------------------
function FromMemoryBaseType_X(Mem : integer_vector ; Size : integer) return std_logic_vector is
------------------------------------------------------------
constant NumIntegers : integer := Mem'length ;
alias NormalizedMem : integer_vector(NumIntegers-1 downto 0) is Mem ;
variable NormalizedSlv : std_logic_vector(NumIntegers*16-1 downto 0) ;
variable Bits16 : std_logic_vector(15 downto 0) ;
variable BitIsX : std_logic_vector(15 downto 0) ;
variable BitVal : std_logic_vector(15 downto 0) ;
begin
for MemIndex in NormalizedMem'reverse_range loop
(BitIsX, BitVal) := std_logic_vector(to_signed(NormalizedMem(MemIndex), 32)) ;
for BitIndex in 0 to 15 loop
if BitIsX(BitIndex) = '1' then
Bits16(BitIndex) := 'U' when BitVal(BitIndex) = '1' else 'X' ;
else
Bits16(BitIndex) := BitVal(BitIndex) ;
end if ;
end loop ;
NormalizedSlv(16*MemIndex+15 downto 16*MemIndex) := Bits16 ;
end loop ;
return NormalizedSlv(Size-1 downto 0) ;
end function FromMemoryBaseType_X ;
------------------------------------------------------------
function InitMemoryBaseType_X(Size : integer) return integer_vector is
------------------------------------------------------------
constant BaseU : integer_vector(0 to Size-1) := (others => -1) ;
begin
return BaseU ;
end function InitMemoryBaseType_X ;
------------------------------------------------------------
-- Memory Policy NoX
-- X and U are stored as a 0
-- Each integer value stores 32 bits of data
------------------------------------------------------------
------------------------------------------------------------
function SizeMemoryBaseType_NoX(Size : integer) return integer is
------------------------------------------------------------
begin
return integer(Ceil(real(Size)/32.0)) ;
end function SizeMemoryBaseType_NoX ;
------------------------------------------------------------
function ToMemoryBaseType_NoX(Slv : std_logic_vector ; Size : integer) return integer_vector is
------------------------------------------------------------
variable NormalizedSlv : std_logic_vector(Size*32-1 downto 0) ;
variable Bits32 : std_logic_vector(31 downto 0) ;
variable BitVal : std_logic_vector(31 downto 0) ;
variable result : integer_vector (Size-1 downto 0) ;
begin
NormalizedSlv := Resize(Slv, Size*32) ;
for MemIndex in result'reverse_range loop
Bits32 := NormalizedSlv(32*MemIndex+31 downto 32*MemIndex) ;
for BitIndex in 0 to 31 loop
if Is_X(Bits32(BitIndex)) then
BitVal(BitIndex) := '0' ;
else
BitVal(BitIndex) := Bits32(BitIndex) ;
end if ;
end loop ;
result(MemIndex) := to_integer(signed(BitVal)) ;
end loop ;
return result ;
end function ToMemoryBaseType_NoX ;
------------------------------------------------------------
function FromMemoryBaseType_NoX(Mem : integer_vector ; Size : integer) return std_logic_vector is
------------------------------------------------------------
constant NumIntegers : integer := Mem'length ;
alias NormalizedMem : integer_vector(NumIntegers-1 downto 0) is Mem ;
variable NormalizedSlv : std_logic_vector(NumIntegers*32-1 downto 0) ;
variable Bits32 : std_logic_vector(31 downto 0) ;
variable BitVal : std_logic_vector(31 downto 0) ;
begin
for MemIndex in NormalizedMem'reverse_range loop
Bits32 := std_logic_vector(to_signed(NormalizedMem(MemIndex), 32)) ;
NormalizedSlv(32*MemIndex+31 downto 32*MemIndex) := Bits32 ;
end loop ;
return NormalizedSlv(Size-1 downto 0) ;
end function FromMemoryBaseType_NoX ;
------------------------------------------------------------
function InitMemoryBaseType_NoX(Size : integer) return integer_vector is
------------------------------------------------------------
constant BaseU : integer_vector(0 to Size-1) := (others => 0) ;
begin
return BaseU ;
end function InitMemoryBaseType_NoX ;
------------------------------------------------------------
-- Memory policy orig
-- For backward compatibility only
-- upto 31 bits of data
-- X or U in any bit and the word becomes X
------------------------------------------------------------
------------------------------------------------------------
function SizeMemoryBaseType_orig(Size : integer) return integer is
------------------------------------------------------------
begin
-- would be better as an alert, but not worth the pain since this is deprecated
assert Size < 32 report "MemoryPkg.MemInit/NewID. DataWidth = " & to_string(Size) & " must be < 32 " severity FAILURE ;
return 1 ;
end function SizeMemoryBaseType_orig ;
------------------------------------------------------------
function ToMemoryBaseType_orig(Slv : std_logic_vector ; Size : integer) return integer_vector is
------------------------------------------------------------
variable result : integer ;
begin
if (Is_X(Slv)) then
result := -1 ;
else
result := to_integer( Slv ) ;
end if ;
return (1 => result) ;
end function ToMemoryBaseType_orig ;
------------------------------------------------------------
function FromMemoryBaseType_orig(Mem : integer_vector ; Size : integer) return std_logic_vector is
------------------------------------------------------------
variable Data : std_logic_vector(Size-1 downto 0) ;
begin
if Mem(Mem'left) >= 0 then
-- Get the Word from the Array
Data := to_slv(Mem(Mem'left), Size) ;
elsif Mem(Mem'left) = -1 then
-- X in Word, return all X
Data := (Data'range => 'X') ;
else
-- Location Uninitialized, return all X
Data := (Data'range => 'U') ;
end if ;
return Data ;
end function FromMemoryBaseType_orig ;
------------------------------------------------------------
function InitMemoryBaseType_orig(Size : integer) return integer_vector is
------------------------------------------------------------
begin
return (1 => integer'left) ;
end function InitMemoryBaseType_orig ;
end MemorySupportPkg ;