Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

Trigonometric functions with FPU

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,

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok mikedsouze , thank you very much.

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

    Best regards,