Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12602 Discussions

How to use fpu custom instruction ?

Altera_Forum
Honored Contributor II
1,478 Views

I work on a NIOSII with a fpu provided by Altera (taking into account +, -, *, and / operations on float). So when I write C code : A + B (where A and B are float type), assembler code use custom instruction (instead of 'addsf2' function call). 

When I look to the Compiler (nios2-elf-g++ - version 3.4.1 installed with NIOSII IDE v6.0) option flag, the option '-mcustom-fpu-cfg=60-2' is set. 

 

Now, I use a complement fpu instructions (for float comparisons and cast to integer type) thanks to custom instructions (I use at the same time the Altera's fpu). So when I write C code : A > B (where A and B are float type), assembler code DO NOT use custom instruction (but use math library function "gtsf2" call). I just want to have the custom instruction call in place of 'gtsf2' function call (Important, I want to avoid the instruction 'call __gtsf2'). 

 

what is the way for use custom instruction call in place of gtsf2 function call ?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
470 Views

 

--- Quote Start ---  

originally posted by cizard@Sep 14 2006, 12:27 AM 

so when i write c code : a > b (where a and b are float type), assembler code do not use custom instruction (but use math library function "gtsf2" call). 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=18261) 

--- quote end ---  

 

--- Quote End ---  

 

 

I actually had this problem running Altera&#39;s floating point profile example. If I set the project to Release mode, it would no longer use the FPU instructions. I had to modify the compiler flags via right-clicking on the project folder, selecting Properties, then C/C++ Build, the release mode, then Tool Settings/Compiler/General and set the optimization level to -O1 instead of the default of -O2. Then when I looked at the generated .s file, I saw the code written by the compiler was correct (use Compiler flag -save-temps to be able to see the generated .s file).
0 Kudos
Altera_Forum
Honored Contributor II
470 Views

...Settings/Compiler/General and set the optimization level to -O1 instead of the default of -O2. Then when I looked at the generated .s file, I saw the code written by the compiler was correct ...<div align='right'><{post_snapback}> (index.php?act=findpost&pid=18262)</div> 

 

--- Quote End ---  

 

 

I confirm the behaviour of nios2-gcc, when I set (in Debug or Release mode) an optimization option (-O1 or -O2), and I write A + B (with A and B are float type) with the Altera&#39;s fpu, there is not "custom" instruction in assembler. If I use no optimization option (-O0), custom instruction is used (in release or debug mode)!!! 

 

For my project, I do not use optimization option (-O0), so altera&#39;s fpu custom instruction is used (only for +, -, /, * operations). That is OK. 

But for other float oprations (like >,<, cast into int, ...), I use my own fpu part, 

so when I write C code : A > B (where A and B are float type), assembler code DO NOT use custom instruction (but use math library function "gtsf2" call). 

 

So, what is the way for use custom instruction call in place of gtsf2 function call ?
0 Kudos
Altera_Forum
Honored Contributor II
470 Views

I looked through the GCC source and it indeed looks like a bug in the NIOS compiler.  

 

Search for &#39;nios2_output_fpu_insn_cmps&#39; in 

C:\altera\kits\nios2_60\bin\nios2-gnutools\src 

 

Note that it is never called or referenced by any of the code. I don&#39;t know much aboug GCC, but that looks like a pretty obvious problem. Want to report this to the Nios crew? If you do make a report, also report the bug of the optimizer not using the FPU. That&#39;s a pretty seriously bug.
0 Kudos
Altera_Forum
Honored Contributor II
470 Views

I recommend turning on the objdump file generation in the Nios II IDE (under the preferences). By specifying -save-temps you are getting the assembler output, however the custom instructions for those floating point operations don&#39;t get pulled in until link time (so you&#39;ll see them in the objdump). 

 

So here&#39;s the order: 

 

1) Compiler creates the assembly and object files (containing calls to the generic math libraries) 

2) During linking the linker figures out if the library should be pulled in or a custom library/hardware 

3) After linking completes you have an elf and the objdump file is created based on it.  

 

I hope that helps clarify the issue.
0 Kudos
Reply