FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6514 Discussions

altfp_div megafunction only produces correct result on the last calculation

Altera_Forum
Honored Contributor II
1,053 Views

I have a project that requires division so I decided to use the altfp_div megafunction to do this. During testing of this megafunction, I've noticed that it only produces the correct result for the very last calculation (every operation prior to the last one is incorrect). If I do the simulation with only one operation, I get the correct result. I have attached a screenshot of the ModelSim simulation: 

 

data_in_a and data_in_b are test vectors (fp-encoded binary numbers) generated in the testbench. Their values are: 

data_in_a <= 32'H42200000;//dec'40 data_in_b <= 32'H421EBEBE; //dec'39.68627 //result = 1 # 40; data_in_a <= 32'H425C0000; //dec'55 data_in_b <= 32'H425B8189; //dec'54.8765 //result = 1 # 40; data_in_a <= 32'H42700000; //dec'60 data_in_b <= 32'H426F98AE; //dec'59.8991 //result = 1 # 40 data_in_a <= 32'H41200000; //dec'10 data_in_b <= 32'H40A00000; //dec'5 //result = 2 # 40; data_in_a <= 32'H40400000; //dec'3 data_in_b <= 32'H3F800000; //dec'1 //result = 3 # 40; data_in_a <= 32'H41400000; //dec'12 data_in_b <= 32'H40400000; //dec'3 //result = 4  

 

a_int and b_int are the integer representations of the floating-point number using the altfp_convert megafunction. 

 

div is the result of data_in_a/data_in_b. The results are obviously incorrect. div should be [0,2,0,1,1,1,2,3,4] but it is instead [0,2,0,2,2,4,4,5,4]. Only the last calculation is ever correct (I've tried this with different numbers of input vectors). 

 

http://i.imgur.com/9usvX.png  

 

However, if I do a single simulation with only 1 calculation, I get the correct results: 

http://imgur.com/X8DVa.png  

 

**EDIT: I am using Quartus II ver 10.0 Build 262, ModelSim-Altera ver 6.3g_p1, altfp_div single precision (32bits), output latency 6, all ports connected, optimized for speed 

 

 

**EDIT 2: I tested it in hardware using SignalTap to look at the results and it works in hardware. It produces the correct results for all calculations so I guess it's a simulation error somewhere/somehow.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
341 Views

How do you know that using a timed assignment will achieve correct timing related to clk?  

If you mean to set the data on the rising edge of clk, use a statement that waits for the edge...
0 Kudos
Altera_Forum
Honored Contributor II
341 Views

OK, that works. I've never had problems before using timed assignments...

0 Kudos
Reply