Hi All,I'm trying to outsource an equation using floating point variables to another system block within my design. In my Nios code, the two variables (say, x and y) are defined as floats, which are sent out to individual ALTFP_SQRT blocks. The SQRT blocks take single precision binary values as inputs, which are in the IEEE 754 format of Sign,Exponent,Mantissa. Now by defining the values as floats, I assumed that this would be the format that the binary output from Nios would take, but when checking it with SignalTap, it would seem that it's just putting them out as 32-bit straight binary. What's the best way to get around this? Is there a simple definition I'm missing, or is it something more complex? I've enabled the floating point custom instruction in Nios, but that doesn't seem to make any difference, and due to the size constraints within my design, I can't use the CONVERT Megafunctions to switch from straight binary to single precision. Any ideas? Thanks
Do you mean that the value is being written as an integer?That will mean that somewhere in the C you are casting (maybe implicitly) the 'float' to an 'int' and the relevant conversion function is being called. You need to use define your IO location as 'float *'. It might be good enough to define a union of float and int and copy the data value through it (you do need to have a variable of the union type, just using casts - *(int *)&float_variable - isn't required to force the compiler to do the reads and writes in the correct order).
If you added your code to this post that would be useful.Also if you are just calculating square root you might find it handy to integrate it as a custom instruction instead. You can instruct the compiler that the hardware is present by compiling with the -mcustom-fsins=N flag where "N" is the custom instruction number you assigned when adding it to the system. When you call "sqrt()" from math.h it'll target your hardware instead of a software library. Here are more details: http://www.alterawiki.com/wiki/single-precision_-mcustom-*_options