topic altfp_div megafunction only produces correct result on the last calculation in FPGA Intellectual Property
https://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182155#M14651
<P>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: </P><P></P> <P></P>data_in_a and data_in_b are test vectors (fp-encoded binary numbers) generated in the testbench. Their values are: <P></P><CODE>
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
</CODE> <P></P> <P></P>a_int and b_int are the integer representations of the floating-point number using the altfp_convert megafunction. <P></P> <P></P>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). <P></P> <P></P><A href="http://i.imgur.com/9usvX.png">http://i.imgur.com/9usvX.png</A> <P></P> <P></P>However, if I do a single simulation with only 1 calculation, I get the correct results: <P></P><A href="http://imgur.com/X8DVa.png">http://imgur.com/X8DVa.png</A> <P></P> <P></P>**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 <P></P> <P></P> <P></P>**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.Wed, 13 Jul 2011 01:59:44 GMTAltera_Forum2011-07-13T01:59:44Zaltfp_div megafunction only produces correct result on the last calculation
https://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182155#M14651
<P>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: </P><P></P> <P></P>data_in_a and data_in_b are test vectors (fp-encoded binary numbers) generated in the testbench. Their values are: <P></P><CODE>
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
</CODE> <P></P> <P></P>a_int and b_int are the integer representations of the floating-point number using the altfp_convert megafunction. <P></P> <P></P>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). <P></P> <P></P><A href="http://i.imgur.com/9usvX.png">http://i.imgur.com/9usvX.png</A> <P></P> <P></P>However, if I do a single simulation with only 1 calculation, I get the correct results: <P></P><A href="http://imgur.com/X8DVa.png">http://imgur.com/X8DVa.png</A> <P></P> <P></P>**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 <P></P> <P></P> <P></P>**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.Wed, 13 Jul 2011 01:59:44 GMThttps://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182155#M14651Altera_Forum2011-07-13T01:59:44ZRe: altfp_div megafunction only produces correct result on the last calculation
https://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182156#M14652
<P>How do you know that using a timed assignment will achieve correct timing related to clk? </P><P></P>If you mean to set the data on the rising edge of clk, use a statement that waits for the edge...Wed, 13 Jul 2011 12:47:25 GMThttps://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182156#M14652Altera_Forum2011-07-13T12:47:25ZRe: altfp_div megafunction only produces correct result on the last calculation
https://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182157#M14653
<P>OK, that works. I've never had problems before using timed assignments...</P>Wed, 13 Jul 2011 23:04:37 GMThttps://community.intel.com/t5/FPGA-Intellectual-Property/altfp-div-megafunction-only-produces-correct-result-on-the-last/m-p/182157#M14653Altera_Forum2011-07-13T23:04:37Z