Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12453 Discussions

sqrtf custom instruction gives sometimes absolutely wrong results

Altera_Forum
Honored Contributor II
882 Views

I use Quartus 13.1.0.182 web edition with a Cyclone III FPGA 

The project is compiled with the Floating point custom instruction 2.0 from Qsys. 

 

My code calculates the square root and some times the results is absolutely wrong. 

I checked (in disassembly) that custom instruction 251 is called like expected. 

 

Here is the code: 

 

#include "altera_nios_custom_instr_floating_point_2.h" float temp1, sinDelta, debugVal, cosDelta; temp1 = sinDelta * sinDelta; debugVal = 1.0f - temp1; cosDelta = sqrtf(debugVal);  

 

And here are the variables results (obtained during debugging): 

 

sinDelta: 0.000162738579 (0x392aa4ce) 

temp1: 2.64838445e-008 (0x32e37e97) 

debugVal: 0.99999994 (0x3f7fffff) 

cosDelta: 0.5 (0x3f000000) 

 

The cosDelta should be around "1". Is seems the custom square root encounters issues with results near 1! 

 

Do I do something wrong or is it an Altera implementation bug?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
139 Views

Looks that way, probably failing to increment the exponent when the mantissa is rounded up. 

 

FWIW you'll probably get better precision from calculating one of sqrt((1+sin)*(1-sin)) or sqrt(0.5 - sin*sin + 0.5).
Altera_Forum
Honored Contributor II
139 Views

 

--- Quote Start ---  

Looks that way, probably failing to increment the exponent when the mantissa is rounded up. 

 

FWIW you'll probably get better precision from calculating one of sqrt((1+sin)*(1-sin)) or sqrt(0.5 - sin*sin + 0.5). 

--- Quote End ---  

 

 

Thank you for your reply. 

 

Even if your fix works in this special case (not already test), I don't really trust this sqrt hardware function! There is no guaranty it would not do the same with an other rounded. I should ask Altera directly
Altera_Forum
Honored Contributor II
139 Views

Neither of those expressions will help the bug, just give extra precision. 

And I should also have suggested: sqrt((0.5+sin+0.5)*(0.5-sin-0.5)).
Altera_Forum
Honored Contributor II
139 Views

Its a bug and will be fixed....

Reply