OpenCores
URL https://opencores.org/ocsvn/openfpu64/openfpu64/trunk

Subversion Repositories openfpu64

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 10 to Rev 11
    Reverse comparison

Rev 10 → Rev 11

/openfpu64/trunk/README
1,3 → 1,84
Todo: add some description.
OpenFPU64
============================
Peter Hüwe
V.0.1, Januar 2009, License: CC-by-sa
:author initials: PH
:email: peterhuewe@gmx.d
:license: CC-by-sa
 
About OpenFPU64
---------------
OpenFPU64 is a free and open source implementation of a double precision floating point unit.
 
The openFPU64 currently features:
* double precision
* Addition/Subtraction
* Multiplication
* rounding (to nearest even)
* subnormals/denormals
* validated against IEEE754 using TestFloat (http://www.jhauser.us/arithmetic/TestFloat.html)
* Compatible with Avalon Bus
* Wishbone interface will be provided soon
 
The openFPU is tested with a Cyclone II and a CycloneIII fpga.
 
Usage in QuartusII SOPC (tm)
----------------------------
In order to use openFPU64 copy all VHDL files (*.vhd) and the TCL file (openfpu64_hw.tcl) to the root directory of your QuartusII Project.
(alternative: 'make quartus_distribution' and copy everything in openfpu64_quartus/ to the root directory of your Quartus II project)
 
Then open the QuartusII and from Quartus launch the SOPC Builder.
 
In SOPC Builder click new component in the left pane and select
File -> open and open the openfpu64_hw.tcl file.
 
By clicking on finish, the openFPU64 is added to your library.
 
Now add openFPU64 to your SOPC-design by double clicking on it, click Generate as usual.
In some rare cases your have to assign new Base and End Adresses,
clicking "System->Auto-Assign Base Adresses" does resolve this.
 
Now click Generate as usual, close SOPC Builder afterwards and compile your design as usual using Quartus.
 
 
 
Driver/Libary in NiosII:
------------------------
add the openfpu64.c and openfpu64.h files (in nios-driver)to your NiosII Project.
To use this library/driver, add the fpu.[ch] files to your application
and add these linker flags.
Click right on your application, choose properties, C/C++ Build
-> Linker -> General and type
"-Wl,--wrap,__adddf3,--wrap,__subdf3,--wrap,__muldf3"
For each implemented function, add another --wrap,__functioname
 
 
 
Development:
------------
If you'd like to do some development on openFPU64, you can use the Makefile together with GHDL (http://ghdl.free.fr/)
 
You can create several different testbenches by issuing one of these commands:
* empty_testsuite
* addsub_testsuite
* custom_testsuite
* add_testsuite
* sub_testsuite
* mul_testsuite
 
The custom_testsuite contains several hand crafted testsuites for ADD/SUB/MUL, the others are quite big (45k,95k testcases) and generated using TestFloat.
 
The testbench is made up of openfpu64_tb.head.vhd, openfpu64_tb.tail.vhd and the testscases in tests/.
 
If you want to change the testbench structure please DO NOT change openfpu64_tb.vhd but rather openfpu64_tb.head.vhd, otherwise your changes will be overwritten by make *_testsuite.
 
The empty testsuite is for 'resetting' the openfpu64_tb to be committed to svn.
Please use make empty_testsuite before checking your sources in.
 
 
 
Note:
-----
QuartusII, Nios, Cyclone, QuartusII SOPC Builders are registered Trademarks of Altera Corporation, 101 Innovation Drive, San Jose, California 95134, USA. All rights reserved.
 
Meanwhile, for questions contact me at peterhuewe@gmx.de and I'm glad to help you out
/openfpu64/trunk/nios-driver/fpu.h
0,0 → 1,25
#ifndef FPU_H_
#define FPU_H_
 
#include <stdio.h>
#include "system.h"
#include <unistd.h>
#include "alt_types.h"
#include <stdlib.h>
#include <stdio.h>
#include "system.h"
#include <unistd.h>
#include "alt_types.h"
#include "io.h"
#include "fpu.h"
#include "sys/alt_timestamp.h"
#include "altera_avalon_performance_counter.h"
#include <time.h>
#include <sys/alt_irq.h>
 
double __wrap___adddf3(double a, double b);
double __wrap___subdf3(double a, double b);
double __wrap___muldf3(double a, double b);
//double __wrap___adddf3(double a, double b);
 
#endif /* FPU_H_ */
openfpu64/trunk/nios-driver/fpu.h Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: openfpu64/trunk/nios-driver/fpu.c =================================================================== --- openfpu64/trunk/nios-driver/fpu.c (nonexistent) +++ openfpu64/trunk/nios-driver/fpu.c (revision 11) @@ -0,0 +1,136 @@ +#include +#include "system.h" +#include +#include "alt_types.h" +#include +#include +#include "system.h" +#include +#include "alt_types.h" +#include "io.h" +#include "fpu.h" +#include "sys/alt_timestamp.h" +#include "altera_avalon_performance_counter.h" +#include +#include + +/******************************************************* + * To use this library/driver, add the fpu.[ch] files to your application + * and add these linker flags. + * Click right on your application, choose properties, C/C++ Build + * -> Linker -> General and type + * "-Wl,--wrap,__adddf3,--wrap,__subdf3,--wrap,__muldf3" + * For each implemented function, add another --wrap,__functioname + * *****************************************************/ + +#define MODE_ADD 0 +#define MODE_SUB 4 +#define MODE_MUL 8 +#define MODE_DIV 12 +/* See fpu_package.vhd for definition*/ + +double __wrap___adddf3(double a, double b) +{ + volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000); + volatile int dpcontext = alt_irq_disable_all(); + volatile double c; + + register alt_u32 * temp_a = (alt_u32 *) &a; + register alt_u32 * temp_b = (alt_u32 *) &b; + alt_u32 result2[2]; + + /* + printf("a0 %08lx!\n", temp_a[0]); + printf("a1 %08lx!\n", temp_a[1]); + printf("b0 %08lx!\n", temp_a[0]); + printf("b1 %08lx!\n", temp_b[1]); + /**/ + //PERF_BEGIN(PERFORMANCE_COUNTER_BASE,3); + + fpu_regs[0+MODE_ADD] = temp_a[1]; + fpu_regs[1] = temp_a[0]; + fpu_regs[2] = temp_b[1]; + fpu_regs[3] = temp_b[0]; + + result2[1]=fpu_regs[0]; + result2[0]=fpu_regs[1]; + /* + printf("result 0 %08lx!\n", result2[0]); + printf("result 1 %08lx!\n", result2[1]); + /**/ + c=*((double *) (result2)); + //PERF_END(PERFORMANCE_COUNTER_BASE,3); + alt_irq_enable_all(dpcontext); + return c; +} + + +double __wrap___subdf3(double a, double b) +{ + volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000); + volatile int dpcontext = alt_irq_disable_all(); + volatile double c; + + register alt_u32 * temp_a = (alt_u32 *) &a; + register alt_u32 * temp_b = (alt_u32 *) &b; + alt_u32 result2[2]; + + fpu_regs[0+MODE_SUB] = temp_a[1]; + fpu_regs[1] = temp_a[0]; + fpu_regs[2] = temp_b[1]; + fpu_regs[3] = temp_b[0]; + + result2[1]=fpu_regs[0]; + result2[0]=fpu_regs[1]; + + c=*((double *) (result2)); + + alt_irq_enable_all(dpcontext); + return c; +} + + +double __wrap___muldf3 (double a , double b) +{ + //printf("mul called\n"); + volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000); + int dpcontext = alt_irq_disable_all(); + double c; + + register alt_u32 * temp_a = (alt_u32 *) &a; + register alt_u32 * temp_b = (alt_u32 *) &b; + alt_u32 result2[2]; + + + printf("a0 %08lx!\n", temp_a[0]); + printf("a1 %08lx!\n", temp_a[1]); + printf("b0 %08lx!\n", temp_a[0]); + printf("b1 %08lx!\n", temp_b[1]); + /**/ + //PERF_BEGIN(PERFORMANCE_COUNTER_BASE,3); + + fpu_regs[0+MODE_MUL] = temp_a[1]; + fpu_regs[1] = temp_a[0]; + fpu_regs[2] = temp_b[1]; + fpu_regs[3] = temp_b[0]; + + result2[1]=fpu_regs[0]; + result2[0]=fpu_regs[1]; + + printf("result 0 %08lx!\n", result2[0]); + printf("result 1 %08lx!\n", result2[1]); + /**/ + c=*((double *) (result2)); + //PERF_END(PERFORMANCE_COUNTER_BASE,3); + + alt_irq_enable_all(dpcontext); + return c; +} + + + + +double __wrap___divdf3 (double a , double b){ + printf("div called\n"); + return a; +}; \ No newline at end of file
openfpu64/trunk/nios-driver/fpu.c Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: openfpu64/trunk/Makefile =================================================================== --- openfpu64/trunk/Makefile (revision 10) +++ openfpu64/trunk/Makefile (revision 11) @@ -21,6 +21,9 @@ %: %.vhd work/%.o $(GHDLE) $@ +empty_testsuite: + cat openfpu64_tb.head.vhd openfpu64_tb.tail.vhd > openfpu64_tb.vhd + addsub_testsuite: cat openfpu64_tb.head.vhd tests/openfpu64_tb.addsub.inc.vhd openfpu64_tb.tail.vhd > openfpu64_tb.vhd

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.