Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL IEEE Package for Real Number Arithmetic

Status
Not open for further replies.

VHDLStarter

Newbie level 6
Joined
Mar 10, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,434
I apologize for making another thread so soon, but I could use some help on another topic. From my understanding in order to represent real numbers you have to use floating point or fixed point numbers and most implementations use the IEEE 754 standard. So, my question are as follows:

1. What libraries support a complete implementation of floating point or fixed point numbers. Would these libraries suffice? **broken link removed**

2. I am using the program ModelSim how would I import these libraries and are they compatible?

3. If I knew my number would be a set length (for example 99.999) would I use fixed point or floating point (I'm guessing fixed point).

4. What would be one way to have a number in a text document. Say .1 is written, how would I convert that to a floating point representation do some arithmetic (division, add, subtract, multiply, etc) and then return the result.

For example, say I have .44 in the text document, read it in and I multiply that real number by 2. I get .88, which I then write to a text document as the output.

Any help on this matter is greatly appreciated. I could really use it. Just to be clear the goal of what I am trying to accomplish: I have a real number in a text document, read it in, do some arithmetic, and output it to another text document. If anyone one could answer one of the above question it would be very helpful. Thank you.
 

1. What libraries support a complete implementation of floating point or fixed point numbers. Would these libraries suffice? **broken link removed**

The Fixed point libraries are great. I have used them for a couple of years in modelsim and altera with no problems. The fixed point package is really just a way to make your life easier. You can do all the same things with the numeric_std package. On the other hand, the floating point libraries are supported by both altera and modelsim but I would not use them for real designs. floating point requires a serious amount of pipelining and these libraries do not provide it. You are much better off using the floating point IP blocks that the vendors have been providing for years.

2. I am using the program ModelSim how would I import these libraries and are they compatible?

No need to import them, modelsim have come with them for at least 2 years, and since modelsim 10 they have nearly full VHDL 2008 support (in previous versions the libraries were just 93 campatibility versions, but still worked the same).

3. If I knew my number would be a set length (for example 99.999) would I use fixed point or floating point (I'm guessing fixed point).

FPGAs dont like floating point very much. It uses a lot of logic and has a high latency. On the other hand fixed point is just integer arithmatic.

4. What would be one way to have a number in a text document. Say .1 is written, how would I convert that to a floating point representation do some arithmetic (division, add, subtract, multiply, etc) and then return the result.

For example, say I have .44 in the text document, read it in and I multiply that real number by 2. I get .88, which I then write to a text document as the output.

the textio supports the reading an writing of reals from text files, but Im not sure on the formatting (I think it has to be of the format n.meM). The VHDL 2008 float and fixed libraries both have functions for converting real types to float/fixed, so reading and writing from a text file is pretty trivial. If you want to write your own format, you'll have to write a string conversion function. Again, this isnt too much of a problem.
 
Thank you very much that was very helpful. But, what do you mean by "On the other hand fixed point is just integer arithmatic." Do you mean to say that I don't need a floating point package to calculate what I am trying to accomplish? I am trying to keep it as synthesizable as possible (within reason). Can you elaborate on the fixed point arithmetic involved? If you could just briefly go over how to handle division, addition, multiplication, etc that would point me in the right direction.

Furthermore let me elaborate on my project. I basically take a number from a text file, read it in, and compute e^X using taylor series, which requires division, addition, multiplication, etc. So, I'm going to need to round the number to the nearest thousandth (for example, 0.100 is inputted, e^(0.100) = 1.10517, so the program will output 1.105), and output that result in a text document. So, the main thing I am concerned with is how to represent that number as a standard logic vector (real to slv conversion if needed) and how do this arithmetic? Again, I really appreciate your help. Thanks again.
 
Last edited:

Thank you very much that was very helpful. But, what do you mean by "On the other hand fixed point is just integer arithmatic." Do you mean to say that I don't need a floating point package to calculate what I am trying to accomplish? I am trying to keep it as synthesizable as possible (within reason). Can you elaborate on the fixed point arithmetic involved? If you could just briefly go over how to handle division, addition, multiplication, etc that would point me in the right direction.

fixed point is basically just offset integer arithmatic, so you just treat your number as an integer with an imaginary division by 2^n (ie. an imaginary load of leading 0's). This is made easier with the fixed point packages because you can decalre your signals like this:

Code:
signal a : ufxied(7 downto 0); --range 0 to 255
signal b : ufixed(-1 downto -7); -- range 0 to 1 - 2^-7 ie small range
signal c : ufixed(7 downto -7); --range 0 to 256 - 2^-7 ie. large a range as the first, but more accuracy

.......
c <= a * b; --ranges all handled with the types, no need to worry about offsets

addition, subtraction and multiplication can be done just using the +, - and * functions. Division can be done with the / function, but it is not pipelined which will mean a very slow divider. Most vendors provide a fixed point divider IP core to take care of this, but you will probably have to do a few type conversions to get the numbers into the input, but its quite straight forward.

If you need any more info on fixed point, just ask away.

Furthermore let me elaborate on my project. I basically take a number from a text file, read it in, and compute e^X using taylor series, which requires division, addition, multiplication, etc. So, I'm going to need to round the number to the nearest thousandth (for example, 0.100 is inputted, e^(0.100) = 1.10517, so the program will output 1.105), and output that result in a text document. So, the main thing I am concerned with is how to represent that number as a standard logic vector (real to slv conversion if needed) and how do this arithmetic? Again, I really appreciate your help. Thanks again.

You are thinking in decimal. You may have to work out what kind of accuracy is essential for you. Fixed point can only be accurate to the smallest bit (2^-n) so if if you need really precise accuracy, then you need a lot of bits. Otherwise you will need floating point which is usually 32 bits, and you will have to use IP cores, and say goodbye to all your logic.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top