My questions are:
1.Should i be using the floating point notation for all the 32 bit
numbers in my program wherein the exponent part is 8 bits and the
fractional part is 23 bits?
2.How do i make the following multiply code work for fixed point
numbers?
module multiply(ready,product,multiplier,multiplicand,sign,clk);
input clk;
input sign;
input [31:0] multiplier, multiplicand;
output [63:0] product;
output ready;
reg [63:0] product, product_temp;
reg [31:0] multiplier_copy;
reg [63:0] multiplicand_copy;
reg negative_output;
reg [5:0] bit;
wire ready = !bit;
initial bit = 0;
initial negative_output = 0;
always @( posedge clk )
if( ready ) begin
bit = 6'd32;
product = 0;
product_temp = 0;
multiplicand_copy = (!sign || !multiplicand[31]) ?
{ 32'd0, multiplicand } :
{ 32'd0, ~multiplicand + 1'b1};
multiplier_copy = (!sign || !multiplier[31]) ?
multiplier :
~multiplier + 1'b1;
negative_output = sign &&
((multiplier[31] && !multiplicand[31])
||(!multiplier[31] && multiplicand[31]));
end
else if ( bit > 0 ) begin
if( multiplier_copy[0] == 1'b1 ) product_temp = product_temp +
multiplicand_copy;
product = (!negative_output) ?
product_temp :
~product_temp + 1'b1;
multiplier_copy = multiplier_copy >> 1;
multiplicand_copy = multiplicand_copy << 1;
bit = bit - 1'b1;
end
endmodule
Thanks
Shwetika
> My program deals with real numbers all of which are 32 bits long.I
> have several functions like square root,exponential,cosine and sine in
> my program.I need to convert all my results to fixed point.
Are you planning for synthesis?
I would suggest if it can be done in fixed point, that would
be a better choice. You have to figure out where the binary
point should be for each, not necessarily the same for
all signals.
-- glen
Hi Shwetika,
This is what I understand from your concerns (correct me if I am
wrong):
You want to treat a 32 bit Fixed-Point number as a Floating Point
number: (Treating the bits [30:23] as the Exponent and [22:0] as the
Mantissa) If this is the case then you have to go through the basics
of IEEE Standard 754 for FP Numbers. As for as I know, this is totally
not possible!
Secondly, conversion from Fixed-Point to Floating Point is no easy
task if you are aiming at a synthesiable module. I feel it is beyond
the scope of your project.
So, as the above person's succinct suggestion I would go with Fixed
Point Numbers.
I saw your code, using procedural assignments, "=", inside an 'always'
block is not a good practice. Simulation and Synthesis might not give
the same results.
All the best.
Krishna Praveen M. R.