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

Subversion Repositories openfpu64

[/] [openfpu64/] [trunk/] [nios-driver/] [fpu.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 bro
#include <stdio.h>
2
#include "system.h"
3
#include <unistd.h>
4
#include "alt_types.h"
5
#include <stdlib.h>
6
#include <stdio.h>
7
#include "system.h"
8
#include <unistd.h>
9
#include "alt_types.h"
10
#include "io.h"
11
#include "fpu.h"
12
#include "sys/alt_timestamp.h"
13
#include "altera_avalon_performance_counter.h"
14
#include <time.h>
15
#include <sys/alt_irq.h>
16
 
17
/*******************************************************
18
 * To use this library/driver, add the fpu.[ch] files to your application
19
 * and add these linker flags.
20
 * Click right on your application, choose properties, C/C++ Build
21
 * -> Linker -> General and type
22
 * "-Wl,--wrap,__adddf3,--wrap,__subdf3,--wrap,__muldf3"
23
 * For each implemented function, add another --wrap,__functioname
24
 * *****************************************************/
25
 
26
#define MODE_ADD 0
27
#define MODE_SUB 4
28
#define MODE_MUL 8
29
#define MODE_DIV 12
30
/* See fpu_package.vhd for definition*/
31
 
32
double __wrap___adddf3(double a, double b)
33
{
34
    volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000);
35
    volatile int dpcontext = alt_irq_disable_all();
36
    volatile double c;
37
 
38
    register alt_u32 * temp_a = (alt_u32 *) &a;
39
    register alt_u32 * temp_b = (alt_u32 *) &b;
40
    alt_u32 result2[2];
41
 
42
    /*
43
       printf("a0 %08lx!\n", temp_a[0]);
44
       printf("a1 %08lx!\n", temp_a[1]);
45
       printf("b0 %08lx!\n", temp_a[0]);
46
       printf("b1 %08lx!\n", temp_b[1]);
47
    /**/
48
    //PERF_BEGIN(PERFORMANCE_COUNTER_BASE,3);
49
 
50
    fpu_regs[0+MODE_ADD] = temp_a[1];
51
    fpu_regs[1] = temp_a[0];
52
    fpu_regs[2] = temp_b[1];
53
    fpu_regs[3] = temp_b[0];
54
 
55
    result2[1]=fpu_regs[0];
56
    result2[0]=fpu_regs[1];
57
    /*
58
       printf("result 0 %08lx!\n", result2[0]);
59
       printf("result 1 %08lx!\n", result2[1]);
60
    /**/
61
    c=*((double *) (result2));
62
    //PERF_END(PERFORMANCE_COUNTER_BASE,3);
63
    alt_irq_enable_all(dpcontext);
64
    return c;
65
}
66
 
67
 
68
double __wrap___subdf3(double a, double b)
69
{
70
    volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000);
71
    volatile int dpcontext = alt_irq_disable_all();
72
    volatile double c;
73
 
74
    register alt_u32 * temp_a = (alt_u32 *) &a;
75
    register alt_u32 * temp_b = (alt_u32 *) &b;
76
    alt_u32 result2[2];
77
 
78
    fpu_regs[0+MODE_SUB] = temp_a[1];
79
    fpu_regs[1] = temp_a[0];
80
    fpu_regs[2] = temp_b[1];
81
    fpu_regs[3] = temp_b[0];
82
 
83
    result2[1]=fpu_regs[0];
84
    result2[0]=fpu_regs[1];
85
 
86
    c=*((double *) (result2));
87
 
88
    alt_irq_enable_all(dpcontext);
89
    return c;
90
}
91
 
92
 
93
double __wrap___muldf3 (double a , double b)
94
{
95
    //printf("mul called\n");
96
    volatile alt_u32 * fpu_regs = (alt_u32 *) (OPENFPU64_0_BASE+0x80000000);
97
    int dpcontext = alt_irq_disable_all();
98
    double c;
99
 
100
    register alt_u32 * temp_a = (alt_u32 *) &a;
101
    register alt_u32 * temp_b = (alt_u32 *) &b;
102
    alt_u32 result2[2];
103
 
104
 
105
    printf("a0 %08lx!\n", temp_a[0]);
106
    printf("a1 %08lx!\n", temp_a[1]);
107
    printf("b0 %08lx!\n", temp_a[0]);
108
    printf("b1 %08lx!\n", temp_b[1]);
109
    /**/
110
    //PERF_BEGIN(PERFORMANCE_COUNTER_BASE,3);
111
 
112
    fpu_regs[0+MODE_MUL] = temp_a[1];
113
    fpu_regs[1] = temp_a[0];
114
    fpu_regs[2] = temp_b[1];
115
    fpu_regs[3] = temp_b[0];
116
 
117
    result2[1]=fpu_regs[0];
118
    result2[0]=fpu_regs[1];
119
 
120
    printf("result 0 %08lx!\n", result2[0]);
121
    printf("result 1 %08lx!\n", result2[1]);
122
    /**/
123
    c=*((double *) (result2));
124
    //PERF_END(PERFORMANCE_COUNTER_BASE,3);
125
 
126
    alt_irq_enable_all(dpcontext);
127
    return c;
128
}
129
 
130
 
131
 
132
 
133
double __wrap___divdf3 (double a , double b){
134
    printf("div called\n");
135
    return a;
136
};

powered by: WebSVN 2.1.0

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