Here is the new version for the floating point multiplier. The thread
is from July but I just had the time to rework on it.
This version is basically the same except some amelioration like the
result is forced to zero when one of the input value is a denormalized
number or zero. For the case that the value is infinite or NaN the
result is forced to infinite except if multiplied by zero.
There is also a C++ test bench generator to build a verilog test bench
with random value and some fix corner case. That generator is based on
the float25 class in the old OGA model. The generator for now is
relatively basic and could be ameliorated.
Actually there seem to have a bug somewhere in the code. The bug seem to
be a rounding problem that cause a variation of "1" in the result of the
multiplication. I'm not sure if it's from the C++ code or the verilog
that is the cause of the bug.
Timothy Normand Miller wrote:
> Yeah. Use the new_model code, and define an actual class for float25
> that limits the precision and also has this new behavior as well.
>
> On 7/30/07, Nicolas Boulay <[EMAIL PROTECTED]> wrote:
>
>> For the float25, is it possible to use the C model to see the beavior
>> of this inf*zero=zero feature ?
>>
// Open Graphics float25 multiplier tb generator
// Written by André Pouliot
//Created : 2008/02/03
/*
DUAL LICENSING
(0) This "Work" is defined to be this document or source code, parts of
this document or source code, or derivative works of this document or
source code. Use of the Work, in whole or in part, must comply with
the licensing terms below.
(1) This Work is licensed under the GNU General Public License (GPL) as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. You have the right to
use and modify this Work. If you distribute this work in "binary" form
(see (7)), you must publish your modified form of this Work in accordance
with the GPL license.
(2) This Work is also licensed as a proprietary work, all rights
belonging to Traversal Technology. Traversal Technology may use this
Work under those terms and has the right to publish, license, and sell
this Work and derivative works as they see fit. To remove these rights,
you must remove this clause.
(3) Use of this Work without clause (2) forfeits the right to use any
trademarks owned by Traversal Technology, the Open Graphics Project, or
related organizations. This is the only circumstance where modification
of this license by a third party is permitted.
(4) Patches, modifications, changes, and extensions (collectively,
"Modifications") to this Work that are submitted to the Open Graphics
Project, the Open Graphics Mailing List, directly to Traversal Technology,
or to an agent thereof must be SIGNED by the author of said Modification
(including the words "signed off by" and the author's name), granting
Traversal Technology copyright privileges under clause (2), as well as
clause (1). Unsigned Modifications will be ignored. Your inclusion of
the signature implies that you have read and agreed with this license
and have verified that you are in compliance with applicable law.
(5) Modifications committed directly to an officially recognized source
code repository are signed implicitly. Those who have write access to
such a repository and who commit Modifications to that repository grant
rights to Traversal Technology under clause (2), as well as clause (1),
by virtue of having write access and choosing to submit Modifications.
(6) It is the responsibility of the submitter of a Modification to ensure
that they have the right to submit the Modification and that they have
all the necessary permissions (including without limitation, patents
and copyrights) from any other contributors or third parties.
(7) An implementation of this Work that is considered analogous to a
"binary distribution" is defined as any form that is not easily
readable by humans ("non-preferred"), which includes, but is not
limited to: Fixed-function IC (e.g. ASIC), fixed-function IC masks
or other fabrication intermediate step, variable-function IC (e.g.
FPGA), FPGA bitfile, compiled or translated simulation model.
(8) The submitter of a Modification assigns copyright of the Modification
to Traversal Technology. Depending on your local laws, you may be able
to assign joint copyright to Traversal Technology and yourself.
Alternatively, you may need to assign copyright exclusively to
Traversal Technology. Assigning joint copyright to Traversal
Technology and yourself is preferable because it will allow you to
make unrestricted use of your work in the future.
(9) The submitter of a Modification forfeits the right to any patents
covered by This Work and pledges to not enforce any patents covered by
This Work.
(10) At your discretion, you are encouraged to add comments to the
"Contributions" section of this Work, indicating the nature of your
Modification.
*/
#include "float25.hpp"
#include <iostream>
#include <stdio.h>
//generate the double+1 for the number of loop
#define loopIteration 10
using namespace std;
int main()
{
float25 temp1;
float25 temp2;
float25 temp3;
float25 temp4;
float25 temp5;
float rand1, rand2;
/*temp1 = 1.5;
temp2 = 15.0;
temp3 = temp1*temp2;
temp4 = rand();
temp5 = rand();
*/
//printf("%x %x %x \n", some_int>>7, some_int2>>7, some_int3>>7);
cout << "module tb_floatmult25();" << endl << endl;
cout << "reg clock;" << endl;
cout << "reg [24:0] mult_input_a, mult_input_b;" << endl;
cout << "wire [24:0] mult_output;" << endl << endl;
cout << "floatmult25 mult (clock, mult_input_a, mult_input_b, mult_output); " << endl;
cout << "always #5 clock <= !clock;" << endl << endl;
cout << "initial begin" << endl;
cout << " clock = 0;" << endl;
cout << " mult_input_a = 'h0;" << endl;
cout << " mult_input_b = 'h0;" << endl;
cout << " pe; pe; pe; pe; pe;" << endl;
cout << " test_mult('h7f0000, 'h7f0000, 'h7f0000);//1*1=1" << endl;
cout << " test_mult('h17f0000, 'h7f0000, 'h17f0000);//-1*1=-1" << endl;
cout << " test_mult('h7f0000, 'h17f0000, 'h17f0000);//1*1=-1" << endl;
cout << " test_mult('h7f0000, 'h0, 'h0);//1*0=0" << endl;
cout << " test_mult('h0, 'h17f0000, 'h0);//0*-1=0" << endl;
cout << " test_mult('hff0000, 'h0, 'h0);//inf*0=0" << endl;
cout << " test_mult('h0, 'hff0000, 'h0);//0*inf=0" << endl;
cout << " test_mult('hff0000, 'h34fff0, 'hff0000);//inf*x=inf" << endl;
cout << " test_mult('h1ff0000, 'h34fff0, 'h1ff0000);//-inf*x=-inf" << endl;
cout << " // generated code begin" << endl;
for (int i=-loopIteration;i < loopIteration; i++)
{
(i == 0) ? temp1 = rand() : temp1 = rand()*i/abs(i);//rand1;
temp2 = rand();//rand2;
temp3 = temp1 * temp2;
unsigned int some_int = *(int *)&temp1;
unsigned int some_int2 = *(int *)&temp2;
unsigned int some_int3 = *(int *)&temp3;
cout << " //next value( In A : "<< temp1<<", In B : "<< temp2<<", Out : "<< temp3<<")"<<endl;
printf(" test_mult('h%x, 'h%x, 'h%x); \n", some_int>>7, some_int2>>7, some_int3>>7);
}
cout << " // generated code end" << endl << endl;
cout << " $display(\"End of simulation\");" << endl;
cout << " $finish;" << endl;
cout << "end" << endl << endl;
cout << "task test_mult;" << endl;
cout << "input [24:0] ina, inb, outc;" << endl;
cout << "begin" << endl;
cout << " mult_input_a = ina;" << endl;
cout << " mult_input_b = inb;" << endl;
cout << " pe; pe; pe; pe; pe;" << endl;
cout << " if (mult_output != outc) begin" << endl;
cout << " $display(\"Value mismatch In_a : %h In_b %h: Out_not: %h Result : %h \",ina, inb, outc, mult_output );" << endl;
cout << " end" << endl;
cout << "end" << endl;
cout << "endtask" << endl << endl;
cout << "task pe;" << endl;
cout << " begin" << endl;
cout << " @(posedge clock);" << endl;
cout << " end " << endl;
cout << "endtask" << endl << endl;
cout << "endmodule" << endl;
//cout << "Hello, new world!" << temp4 << temp5 << endl;
return 0;
}
module tb_floatmult25();
reg clock;
reg [24:0] mult_input_a, mult_input_b;
wire [24:0] mult_output;
floatmult25 mult (clock, mult_input_a, mult_input_b, mult_output);
always #5 clock <= !clock;
initial begin
// do reset or whatever
// ...
clock = 0;
mult_input_a = 'h0;
mult_input_b = 'h0;
pe; pe; pe; pe; pe;
test_mult('h7f0000, 'h7f0000, 'h7f0000);
test_mult('h17f0000, 'h7f0000, 'h17f0000);
test_mult('h7f0000, 'h0, 'h0);
test_mult('h1fe0000, 'h0, 'h0);
test_mult('hff0000, 'h0, 'h0);
test_mult('hff0000, 'h34fff0, 'hff0000);
test_mult('h1ff0000, 'h34fff0, 'h1ff0000);
test_mult('h7f8000, 'h82e000, 'h836800);
// ... more generated code...
$finish;
end
task test_mult;
input [24:0] ina, inb, outc;
begin
mult_input_a = ina;
mult_input_b = inb;
pe; pe; pe; pe; pe;
if (mult_output != outc) begin
$display("Value mismatch In_a : %h In_b %h: Out_not: %h
Result : %h ",ina, inb, outc, mult_output );
// end else begin
// $display("Value match In_a : %h In_b %h: Out_not: %h Result :
%h ",ina, inb, outc, mult_output );
end
end
endtask
task pe;
begin
@(posedge clock);
end
endtask
endmodule
CXX := g++
CXXFLAGS := -g -Wall
Generator_SOURCES = float25.cpp TbGenMult_float25.cpp
TbGenerator: $(Generator_SOURCES)
$(CXX) $+ -o$@
TbGenerator > TbAutoGenMult_float25.v
simulMult: float25Mult.v TbAutoGenMult_float25.v
iverilog -o$@ float25Mult.v TbAutoGenMult_float25.v
startSimul: simulMult
simulMult > result.log
all : $(Generator_SOURCES)
$(CXX) $+ -o TbGenerator
TbGenerator > TbAutoGenMult_float25.v
iverilog -o simulMult float25Mult.v TbAutoGenMult_float25.v
simulMult > result.log
clean:
rm -f simulMult TbGenerator TbAutoGenMult_float25.v result.log
PHONY: TbGenerator simulMult_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)