 |
|
| Computers Forum Index » Computer Architecture - FPGA » Best way to model a large external ROM in a... |
|
Page 1 of 1 |
|
| Author |
Message |
| TSMGrizzly... |
Posted: Thu Oct 29, 2009 10:21 am |
|
|
|
Guest
|
Hi, I am working on designing a state machine which will read some
data from a relatively large external ROM and process it.
I expect the ROM size to be on the order of 32k x 32 bits, or 64k x 32
bits (quite likely the latter because my data table is just a little
larger than 32k entries at the moment).
Is there a good way to model this in a VHDL testbench in such a way
that XST simulator can handle it?
I don't really want to have to build a gigantic constant assignment
table, but I also suspect that declaring an array of std_logic_vectors
as a signal and then writing them one by one in from a file would
probably take a really long time to execute.
I searched around a while last week but didn't really find any
concrete answers on this...
Cheers,
TSM |
|
|
| Back to top |
|
|
|
| KJ... |
Posted: Thu Oct 29, 2009 11:14 am |
|
|
|
Guest
|
On Oct 29, 6:21 am, TSMGrizzly <sbatt... at (no spam) yahoo.co.jp> wrote:
Quote:
I don't really want to have to build a gigantic constant assignment
table,
Why not? That's the fastest way to accomplish the task...fast both
for development as well as fast sim.
Quote: but I also suspect that declaring an array of std_logic_vectors
as a signal and then writing them one by one in from a file would
probably take a really long time to execute.
Well, the first order of business is that you won't be writing an
array of std_logic_vectors to a file in order model a ROM, you would
be reading them in from a file.
Second, your suspicions are not correct, the sim time to read in and
parse the ROM data would be negligible. The development time to do
this however, would be considerably longer though then simply defining
the constant array. It's up to you to decide on how to spend your
time.
Quote: I searched around a while last week but didn't really find any
concrete answers on this...
You may find an already written model for the part that you'll be
using on
http://www.freemodelfoundry.com/
Kevin Jennings |
|
|
| Back to top |
|
|
|
| TSMGrizzly... |
Posted: Thu Oct 29, 2009 11:31 am |
|
|
|
Guest
|
Quote: I don't really want to have to build a gigantic constant assignment
table,
Why not? That's the fastest way to accomplish the task...fast both
for development as well as fast sim.
Well, because I didn't really want such a long constant table as part
of my testbench, though I suppose I can keep it in package in a
separate file where it would be out of the way.
Quote: Well, the first order of business is that you won't be writing an
array of std_logic_vectors to a file in order model a ROM, you would
be reading them in from a file.
Yes, this is what I meant.. writing the values into the
std_logic_vectors after having read them from the file.
Quote:
Second, your suspicions are not correct, the sim time to read in and
parse the ROM data would be negligible. The development time to do
this however, would be considerably longer though then simply defining
the constant array. It's up to you to decide on how to spend your
time.
I don't really see too much difference in the time spent either way. I
have some code from my last testbench where I read stimulus in from a
text file, so it should be pretty quick to adapt. Admittedly a script
to write the constant table would be a little quicker, so I will
probably go with your suggestion on that.
Awesome, I will take a look.
Thanks for the quick answer! Sorry to be bothering you with such a
trivial question. |
|
|
| Back to top |
|
|
|
| TSMGrizzly... |
Posted: Thu Oct 29, 2009 2:29 pm |
|
|
|
Guest
|
On Oct 29, 10:45 pm, Brian Drummond <brian_drumm... at (no spam) btconnect.com>
wrote:
Quote:
Seconded. If you need to read files created by other tools (e.g. a spreadsheet,
or a binary file like a .bmp) this is a reasonable way to do it, and more
flexible than the above approach. However ISE Simulator has some
not-well-documented obstacles(*) to reading binary files, which is more
straightforward in Modelsim.
(*) As of ISE10:
a) it is opposite-endian to Modelsim's treatment of the same file.
b) ISIM writes an undocumented header before the file contents, and expects to
see that header on any file it reads. You can convert a 3rd party file to/from
ISIM using head, tail and cat to extract/insert the header (on Linux, or the
Windows equivalent commands) but it's a bother.
c) Xilinx have declined to document this header. However there is a Change
Request to fix these issues; I have no idea if/when it will happen.
- Brian
Thanks Brian, good to know. Thankfully I can probably get away with
not using binary files for input.
I am on Linux and we don't have funding at the moment for stuff like
Modelsim licenses, so I'm pretty much bound to the ISE simulator for
now. I know Modelsim is smoother and nicer, but they were not nice
enough to make Modelsim XE for Linux :(
I'll just make the big array of constants, and rewrite the file
whenever I need to make changes to it. |
|
|
| Back to top |
|
|
|
| Brian Drummond... |
Posted: Thu Oct 29, 2009 5:45 pm |
|
|
|
Guest
|
On Thu, 29 Oct 2009 04:31:49 -0700 (PDT), TSMGrizzly <sbattazz at (no spam) yahoo.co.jp>
wrote:
Quote: I don't really want to have to build a gigantic constant assignment
table,
Why not? That's the fastest way to accomplish the task...fast both
for development as well as fast sim.
Well, because I didn't really want such a long constant table as part
of my testbench, though I suppose I can keep it in package in a
separate file where it would be out of the way.
Keep it as a separate file. The tool that creates it simply has to print a few
lines of boilerplate VHDL at each end.
Quote: Second, your suspicions are not correct, the sim time to read in and
parse the ROM data would be negligible. The development time to do
this however, would be considerably longer though then simply defining
the constant array.
Seconded. If you need to read files created by other tools (e.g. a spreadsheet,
or a binary file like a .bmp) this is a reasonable way to do it, and more
flexible than the above approach. However ISE Simulator has some
not-well-documented obstacles(*) to reading binary files, which is more
straightforward in Modelsim.
(*) As of ISE10:
a) it is opposite-endian to Modelsim's treatment of the same file.
b) ISIM writes an undocumented header before the file contents, and expects to
see that header on any file it reads. You can convert a 3rd party file to/from
ISIM using head, tail and cat to extract/insert the header (on Linux, or the
Windows equivalent commands) but it's a bother.
c) Xilinx have declined to document this header. However there is a Change
Request to fix these issues; I have no idea if/when it will happen.
- Brian |
|
|
| Back to top |
|
|
|
| Ben Jones... |
Posted: Fri Oct 30, 2009 12:59 pm |
|
|
|
Guest
|
On Oct 30, 11:10 am, "RCIngham" <robert.ing... at (no spam) gmail.com> wrote:
Quote: snip
If your ROM is *really* big (> 1M locations) you may run into simulator
difficulties if you define the contents as an array of std_logic_vector.
Defining it as an array of integer is most memory-efficient, but you have
to convert it to signed/unsigned and cast to std_logic_vector to drive the
port.
Danger, Will Robinson!
I note that your ROM table is going to contain 32-bit data. Please do
not forget that a VHDL "integer" value does not, repeat NOT,
correspond to a 32-bit two's complement integer! The "standard"
package, last time I checked, contained the immortal line:
type INTEGER is range -2147483647 to 2147483647;
-2147483648, or 2^-31 or 0x80000000, is not, repeat NOT, a valid
integer in VHDL! If there is a possibility that your ROM will contain
this most-negative value then you must check whether your simulator
actually allows it. It probably won't. Of course, if you were hoping
for 32-bit unsigned values in your ROM then that won't fit in an
integer either, for the same reason.
To be honest, a big array of std_logic_vector won't hurt *that* much:
subtype my_rom_data is std_logic_vector(31 downto 0);
type my_rom_type is array(0 to 65535) of my_rom_data;
But I recommend you define it as a constant or a variable, and never
as a signal:
signal x : my_rom_type := (...); -- Noooo!
....because that will really slow everything down.
Cheers,
-Ben- |
|
|
| Back to top |
|
|
|
| Andy... |
Posted: Fri Oct 30, 2009 1:50 pm |
|
|
|
Guest
|
You can also initialize a constant, variable, or signal with a
function call that returns the value to be used for initialization. So
if you have a simple enough algorithm for the contents to code in
vhdl, that might be a simpler way yet.
Oh, and use a constant if this is really a rom, rather than a signal,
for less overhead and better performance.
If you can use an integer (range constraints withstanding), it will be
smaller and more efficient. The VHDL LRM requires AT LEAST the range
-2147483647 to 2147483647 to be implemented for integer, but many
(most?) implementations handle the entire 32 bit two's complement
range. Check your simulator/synthesis tool's standard package
implementation, because there is no "standard" standard package
definition with regard to this. And if they don't implement the full
32 bit signed range, request an enhancement for them to do so.
Andy |
|
|
| Back to top |
|
|
|
| RCIngham... |
Posted: Fri Oct 30, 2009 3:10 pm |
|
|
|
Guest
|
<snip>
Quote:
I'll just make the big array of constants, and rewrite the file
whenever I need to make changes to it.
If your ROM is *really* big (> 1M locations) you may run into simulator
difficulties if you define the contents as an array of std_logic_vector.
Defining it as an array of integer is most memory-efficient, but you have
to convert it to signed/unsigned and cast to std_logic_vector to drive the
port.
An array of bit_vector is 2nd best.
---------------------------------------
This message was sent using the comp.arch.fpga web interface on
http://www.FPGARelated.com |
|
|
| Back to top |
|
|
|
| Brian Drummond... |
Posted: Sat Oct 31, 2009 3:14 am |
|
|
|
Guest
|
On Fri, 30 Oct 2009 06:50:28 -0700 (PDT), Andy <jonesandy at (no spam) comcast.net> wrote:
Quote: You can also initialize a constant, variable, or signal with a
function call that returns the value to be used for initialization. So
if you have a simple enough algorithm for the contents to code in
vhdl, that might be a simpler way yet.
This is good, and any simulator will initialise the ROM fast. If it's junt for
the testbench this is a really good idea.
It is also synthesisable, and XST will handle it correctly ...
BUT
(you just knew there was a BUT coming)
for a reasonably large ROM, or a complex function (e.g. function calls nested 4
levels deep) XST will take an unbelievably long time to synthesise it. There's
an N^2 algorithm in there somewhere; if it takes 15 minutes for a 1000 element
array, it'll take an hour for 2000 elements, 4 hours for 4000, etc...
This is an unbelievably weak area of XST's performance, and every simulator I've
tried proves this poor performance is completely unnecessary.
Quote: If you can use an integer (range constraints withstanding), it will be
smaller and more efficient. The VHDL LRM requires AT LEAST the range
-2147483647 to 2147483647 to be implemented for integer, but many
(most?) implementations handle the entire 32 bit two's complement
range.
Modelsim handles -2^32, ISE Simulator gives a clear error message.
- Brian |
|
|
| Back to top |
|
|
|
| Jonathan Bromley... |
Posted: Sat Oct 31, 2009 3:24 am |
|
|
|
Guest
|
On Fri, 30 Oct 2009 23:14:44 +0000, Brian Drummond wrote:
Quote: for a reasonably large ROM, or a complex function (e.g. function calls nested 4
levels deep) XST will take an unbelievably long time to synthesise it. There's
an N^2 algorithm in there somewhere; if it takes 15 minutes for a 1000 element
array, it'll take an hour for 2000 elements, 4 hours for 4000, etc...
Sounds as though XST is re-invoking the entire function to
compute the value of each individual bit (or word?) of the
ROM. Given the way synthesis tends to focus on each bit
individually, that might be not too surprising. Yuck.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley at (no spam) MYCOMPANY.com
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated. |
|
|
| Back to top |
|
|
|
| Ben Jones... |
Posted: Sun Nov 01, 2009 5:58 pm |
|
|
|
Guest
|
On Oct 30, 11:14 pm, Brian Drummond <brian_drumm... at (no spam) btconnect.com>
wrote:
Quote: ... snip ...
for a reasonably large ROM, or a complex function (e.g. function calls nested 4
levels deep) XST will take an unbelievably long time to synthesise it. There's
an N^2 algorithm in there somewhere; if it takes 15 minutes for a 1000 element
array, it'll take an hour for 2000 elements, 4 hours for 4000, etc...
Is this *still* happening? This has been CRed so many times, and I
know it's been fixed for at least some of the test cases we came up
with internally... if you have some example code that exhibits this in
the latest ISE, and you're willing to share it, let me know and I'll
try to beat the XST team around the head with it again. :-/
-Ben- |
|
|
| Back to top |
|
|
|
| Brian Drummond... |
Posted: Mon Nov 02, 2009 5:46 am |
|
|
|
Guest
|
On Sun, 1 Nov 2009 09:58:10 -0800 (PST), Ben Jones <benjjuk at (no spam) gmail.com> wrote:
Quote: On Oct 30, 11:14 pm, Brian Drummond <brian_drumm... at (no spam) btconnect.com
wrote:
... snip ...
for a reasonably large ROM, or a complex function (e.g. function calls nested 4
levels deep) XST will take an unbelievably long time to synthesise it. There's
an N^2 algorithm in there somewhere; if it takes 15 minutes for a 1000 element
array, it'll take an hour for 2000 elements, 4 hours for 4000, etc...
Is this *still* happening? This has been CRed so many times, and I
know it's been fixed for at least some of the test cases we came up
with internally... if you have some example code that exhibits this in
the latest ISE, and you're willing to share it, let me know and I'll
try to beat the XST team around the head with it again. :-/
I have been informed by a student employee it's still true in ISE11.1 but
haven't verified it myself. Will check in the next couple of days and email you
privately.
Alternatively you may be able to access a pathological testcase attached to
Webcase 717144, as used by above student.
It asserts on every LUT entry, so you can watch it slow down... (and no, the
assert is not the performance bottleneck!)
- Brian |
|
|
| Back to top |
|
|
|
| Ben Jones... |
Posted: Tue Nov 03, 2009 8:46 pm |
|
|
|
Guest
|
On Nov 2, 12:46 am, Brian Drummond <brian_drumm... at (no spam) btconnect.com>
wrote:
Quote: On Sun, 1 Nov 2009 09:58:10 -0800 (PST), Ben Jones <benj... at (no spam) gmail.com> wrote:
On Oct 30, 11:14 pm, Brian Drummond <brian_drumm... at (no spam) btconnect.com
wrote:
... snip ...
for a reasonably large ROM, or a complex function (e.g. function calls nested 4
levels deep) XST will take an unbelievably long time to synthesise it. There's
an N^2 algorithm in there somewhere; if it takes 15 minutes for a 1000 element
array, it'll take an hour for 2000 elements, 4 hours for 4000, etc...
Is this *still* happening? This has been CRed so many times, and I
know it's been fixed for at least some of the test cases we came up
with internally... if you have some example code that exhibits this in
the latest ISE, and you're willing to share it, let me know and I'll
try to beat the XST team around the head with it again. :-/
I have been informed by a student employee it's still true in ISE11.1 but
haven't verified it myself. Will check in the next couple of days and email you
privately.
Alternatively you may be able to access a pathological testcase attached to
Webcase 717144, as used by above student.
It asserts on every LUT entry, so you can watch it slow down... (and no, the
assert is not the performance bottleneck!)
- Brian
Thanks, Brian. I'll check it out. |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Mon Nov 30, 2009 5:08 am
|
|