Forum Discussion

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

how to use the floating point hardware in nios II custom instructions

hi

i want to compare the speed difference of floating point calc between custom instruction floating point and software.

this is my code:# include <stdio.h># include <altera_avalon_pio_regs.h># include "altera_avalon_pio_regs.h"# include "system.h"

int main()

{

printf("Hello from Nios II!\n");

float a=3.1415926;

float b=1.2578;

float c=0;

while(1)

{

IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE,0xf);

c=a*b;

IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE,0x0);

c=a-b;

IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE,0xf);

c=b-a;

IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE,0x0);

}

return 0;

}

in the code,i use pio to estimate the calc time roughly,

firstly, i delete the floating point hardware, generate the hdl, compile the quartus project, build the software, then i find the calc time is 2.3us(the sys clk is 100M);

then, i add the floating point hardware, and redo these steps, i find the calc time is still 2.3us

i guess the nios did not use the floating point hardware, how can i fix this problem?

is there any examples to show me how to use it?

thanks!

14 Replies