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.
12366 Discussions

Trigonometric functions with FPU

Altera_Forum
Honored Contributor I
1,185 Views

Hello, 

 

I'm trying to reduce the latency of my arithmetic operations. For that purpose i The CUSTOM FPU INSTRUCTION to my Nios. I've enabled HW and DIV at NIOS2-F. 

Using this Custom Instruction i can get good performance when doing MUL, ADD, SUB, SQRT and DIV operations. 

Now, i want to use some complex sin,atan, cos instruction. 

I have tested sin/cos/atan with/without hardware FPU. The performance is the same. 

When i look to objdump file, the custom functions are not called. 

Is there any configuration I need to set? I'm using Quartus 15 and eclipse. 

 

Thanks in advance, 

 

Best regards,
0 Kudos
7 Replies
Altera_Forum
Honored Contributor I
113 Views

Are you using Floating Point Hardware 2? 

 

I think the CI only support 18 Floating point operations, refer to table 6 of https://www.altera.com/content/dam/altera-www/global/en_us/others/literature/ug/ug_fph2.pdf

 

Trigonometry operations are not part of the 18 floating point operations and as such the performance is not good.
Altera_Forum
Honored Contributor I
113 Views

Thank you mikedsouze for you answer. 

Yes i'm using Floating Point Hardware 2 

 

 

--- Quote Start ---  

i think the ci only support 18 floating point operations 

--- Quote End ---  

 

 

Yes, I think you are right. 

 

Now i tried to use the Altera Floating Point Megafunctions ( SINE, ATAN,COS) as a custom instruction.  

First of all, i generated the VHDL codes, then i added them as a custom instruction to the NIOS2. 

In the "system.h"# define macro declarations was generated for each function like this: 

 

# define alt_ci_ci_fp_atan_0(a,b) __builtin_custom_inii(alt_ci_ci_fp_atan_0_n,(a),(b)) 

# define alt_ci_ci_fp_atan_0_n 0x2 

# define alt_ci_ci_fp_cosine_0(a) __builtin_custom_ini(alt_ci_ci_fp_cosine_0_n,(a)) 

# define alt_ci_ci_fp_cosine_0_n 0x1 

# define alt_ci_ci_fp_sine_0(a) __builtin_custom_ini(alt_ci_ci_fp_sine_0_n,(a)) 

# define alt_ci_ci_fp_sine_0_n 0x3 

 

Unfortunately, it doesn't work. I don't know if what i did is possible or not. 

Thanks, 

 

Best regards
Altera_Forum
Honored Contributor I
113 Views

You ought to be able to compile the trig function library routines to use the custom instructions internally. 

That might give enough of a performance boost.
Altera_Forum
Honored Contributor I
113 Views

I would suggest to you to try to invoke the function directly in your C code. 

 

In your C: 

# include "system.h" 

 

then in your main: 

result_cos = ALT_CI_CI_FP_COSINE_0(a); 

 

Reason is that I have a feeling that the compiler is unable to map the new operations to the newlib. You could try to recompile newlib, rebuild BSP folder.
Altera_Forum
Honored Contributor I
113 Views

Thank you dsl & mikedsouze for your answer. 

 

@dsl: 

--- Quote Start ---  

you ought to be able to compile the trig function library routines to use the custom instructions internally. 

--- Quote End ---  

 

How can I do that ? 

 

@mikedsouze :  

--- Quote Start ---  

reason is that i have a feeling that the compiler is unable to map the new operations to the newlib. you could try to recompile newlib, rebuild bsp folder. 

--- Quote End ---  

 

I have a newlib generated with the BSP but it's empty. Is there any configuration special to do in eclipse to recompile newlib ? 

 

Sorry for wasting your time. 

 

Best regards
Altera_Forum
Honored Contributor I
113 Views

Found somewhere regarding custom instruction: http://www.alterawiki.com/wiki/custom_instructions 

 

Also this:http://www.alterawiki.com/wiki/single-precision_-mcustom-*_options 

 

I think you need to define the -mcusom- GCC flags. 

 

-mcustom-fcoss=1 

-mcustom-fatans=2 

-mcustom-fsins=3
Altera_Forum
Honored Contributor I
113 Views

Ok mikedsouze , thank you very much. 

I'll try your suggestion, i let you know. 

Best regards,
Reply