Community
cancel
Showing results for 
Search instead for 
Did you mean: 

Configurable FPU

Configurable FPU


Disclaimer

I do not support this product, so use it at your own risk. You are welcome to modify it or put it into a commercial product.

I have tested the FPU on a Cyclone III with Quartus II 9.1. Please let me know, whether you succeed to use it on a different hardware.

I appreciate your feedback to michael.schoeggl@avl.com

Introduction

The original fpoint custom instruction distributed with Nios II only supports the 4 arithmetic functions. It misses functions for compare operations (<, <=, >, >=, ==, !=) and for conversion between float and int, which eat up much cpu-time, too.

Nevertheless Altera already provides all these arithmetic functions as altfp_ megafunction-blocks. This FPU implements a wrapper to make the megafunction-blocks available as Nios II custom-instructions.

How to integrate the FPU into your project

  • Put the files into your project directory or somewhere into your sopc library path. 
  • Add the FPU custom instruction to your CPU (don’t forget to remove the fpoint custom instruction!)
  • Move the FPU to the top position of the custom instructions: the numbers for the custom instructions below assume that the FPU has the instruction offset 0.
  • Add the following compiler-flags into your software project. With Quartus II 9.1 the wizard seems to be broken, so add it directly to the makefile at: APP_CFLAGS_USER_FLAGS :=
  • (They will show up at ‘Properties -> Nios II Application Properties -> User flags’.)
  • Compiler-flags for the whole FPU:
  • -mcustom-fabss=0 -mcustom-fnegs=1 -mcustom-fcmpgts=2 -mcustom-fcmpges=3 -mcustom-fcmplts=4 -mcustom-fcmples=5 -mcustom-fcmpeqs=6 -mcustom-fcmpnes=7 -mcustom-fadds=8 -mcustom-fsubs=9 -mcustom-fmuls=10 -mcustom-fdivs=11 -mcustom-floatis=12 -mcustom-floatus=13 -mcustom-fixsi=14 -mcustom-fixsu=15 -fsingle-precision-constant

Restrictions

  • The megafunctions used in the FPU do not support denorm float numbers (numbers smaller than 1e-38), but set them to 0. (I think the original fpoint custom instructions behave just the same.)
  • The FPU can not be compiled for a Cyclone I, which does not have embedded-multipliers.

Detailed description

  • The implementation is just a wrapper for the altfp_ megafunction-blocks distributed with Quartus II.
  • So it should be rather bug-free. It compiles to more than 100 MHz for a Cyclone III.
  • The compiler-flags must be set to activate the custom instructions in your software.
  • The numbers assume, that the FPU has the custom instruction offset 0. 
  • If you have a different offset, you must add your offset to the numbers below.
  • You can individually switch on/off each megafunction block to tune the FPU to your needs.
  • The LEs below show the resource-usage (the whole FPU needs about 2300 LEs.)
  • The implementation is completely re-written, but originally based on YAFPU from JCJB.  


Instruction

LEs

Compiler-flags

Abs / Neg 

20

-mcustom-fabss=0 -mcustom-fnegs=1

Compare

80

-mcustom-fcmpgts=2 -mcustom-fcmpges=3

-mcustom-fcmplts=4 -mcustom-fcmples=5

-mcustom-fcmpeqs=6 -mcustom-fcmpnes=7

Add / Sub  

820

-mcustom-fadds=8 -mcustom-fsubs=9

Multiply    

260

-mcustom-fmuls=10

Divide

340

-mcustom-fdivs=11

Float2Int  

430

-mcustom-floatis=12 -mcustom-floatus=13

Int2Float  

350

-mcustom-fixsi=14 -mcustom-fixsu=15

   

   

 

Additional compiler option

-fsingle-precision-constant

Download mike_fpu.zip

Attachments
Version history
Revision #:
1 of 1
Last update:
‎06-25-2019 03:20 PM
Updated by:
 
Contributors