merge kaps
[libfirm] / ir / tv / IeeeCC754 / BasicOp / fltcalc / BasicOptest.cc
1 /*
2 ##########################################################################
3 #                                                                        #
4 # Program: IeeeCC754                                                     #
5 #                                                                        #
6 # Description:                                                           #
7 #   IeeeCC754 or IEEE 754 Compliance Checker is a precision and range    #
8 #   independent tool to test whether an implementation of                #
9 #   floating-point arithmetic (in hardware or software) is compliant     #
10 #   with the principles of the IEEE 754-854 floating-point standards.    #
11 #   You can find out more about the testing tool IeeeCC754 at            #
12 #                                                                        #
13 #         http://win-www.uia.ac.be/u/cant/ieeecc754.html                 #
14 #                                                                        #
15 #   This tool is in parts based on and greatly benefited from the        #
16 #   the program FPTEST developed by Jerome Coonen. For a full            #
17 #   description of the extensions to FPTEST and a reference to           #
18 #   the original Coonen program, please refer to the URL given above.    #
19 #   For the options available with the program IeeeCC754 and its         #
20 #   compatibility with David Hough's hexadecimal UCB format, we          #
21 #   also refer to the file readme.usage.                                 #
22 #                                                                        #
23 #  Usage: see readme.usage                                               #
24 #                                                                        #
25 #  Responsible authors:                                                  #
26 #         Brigitte Verdonk                                               #
27 #         Annie Cuyt                                                     #
28 #                                                                        #
29 #  Contributors:                                                         #
30 #         Johan Bogo (1998-1999)                                         #
31 #         Tim Gevers (10-12/2000)                                        #
32 #         Debby Ooms (1996-1997)                                         #
33 #         Geert Vermuyten (1996-1997)                                    #
34 #         Dennis Verschaeren (09/1996-06/2000)                           #
35 #                                                                        #
36 #  Copyright (C) 2000  University of Antwerp                             #
37 #                                                                        #
38 #  This program can be obtained from the authors, free, but WITHOUT ANY  #
39 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or     #
40 #  FITNESS FOR A PARTICULAR PURPOSE.                                     #
41 #                                                                        #
42 #  Contact:                                                              #
43 #       Brigitte.Verdonk@uia.ua.ac.be                                    #
44 #       Department of Mathematics and Computer Science                   #
45 #       University of Antwerp (UIA)                                      #
46 #       Universiteitsplein 1                                             #
47 #       B2610 Antwerp, BELGIUM                                           #
48 #                                                                        #
49 ##########################################################################
50
51 Filename:
52        $RCSfile$
53
54 Last updated:
55        $Date$
56
57 */
58
59 #include <math.h>
60 #include <DriverFloatRepr.h>
61 extern "C" {
62 #include <fltcalc.h>
63 }
64
65 DriverFloatRepr DriverFloatRepr::operator + (DriverFloatRepr& fl)
66 {
67   void *res = alloca(::fc_get_buffer_length());
68   void *op1 = alloca(::fc_get_buffer_length());
69   void *op2 = alloca(::fc_get_buffer_length());
70
71   to(op1);
72   fl.to(op2);
73
74   SetLibRound();
75
76   // cout << "op1 : " << endl << op1 << endl << flush;
77   // cout << "op2 : " << endl << op2 << endl << flush;
78   GetLibExceptions();
79   ::fc_add(op1, op2, res);
80   // cout << "res: " << res << endl << flush; // debug
81
82   GetLibExceptions();
83   DriverFloatRepr r(res);
84   return r;
85 }
86 DriverFloatRepr DriverFloatRepr::operator - (DriverFloatRepr &fl)
87 {
88   void *res = alloca(::fc_get_buffer_length());
89   void *op1 = alloca(::fc_get_buffer_length());
90   void *op2 = alloca(::fc_get_buffer_length());
91
92   to(op1);
93   fl.to(op2);
94
95   SetLibRound();
96
97   // cout << "op1 : " << endl << op1 << endl << flush;
98   // cout << "op2 : " << endl << op2 << endl << flush;
99   ::fc_sub(op1, op2, res);
100   // cout << "res: " << res << endl << flush; // debug
101
102   GetLibExceptions();
103   DriverFloatRepr r(res);
104   return r;
105 }
106
107 DriverFloatRepr DriverFloatRepr::operator * (DriverFloatRepr &fl)
108 {
109   void *res = alloca(::fc_get_buffer_length());
110   void *op1 = alloca(::fc_get_buffer_length());
111   void *op2 = alloca(::fc_get_buffer_length());
112
113   to(op1);
114   fl.to(op2);
115
116   SetLibRound();
117
118   // cout << "op1 : " << endl << op1 << endl << flush;
119   // cout << "op2 : " << endl << op2 << endl << flush;
120   ::fc_mul(op1, op2, res);
121   // cout << "res: " << res << endl << flush; // debug
122
123   GetLibExceptions();
124   DriverFloatRepr r(res);
125   return r;
126 }
127
128 DriverFloatRepr DriverFloatRepr::operator / (DriverFloatRepr &fl)
129 {
130   void *res = alloca(::fc_get_buffer_length());
131   void *op1 = alloca(::fc_get_buffer_length());
132   void *op2 = alloca(::fc_get_buffer_length());
133
134   to(op1);
135   fl.to(op2);
136
137   SetLibRound();
138
139   // cout << "op1 : " << endl << op1 << endl << flush;
140   // cout << "op2 : " << endl << op2 << endl << flush;
141   ::fc_div(op1, op2, res);
142   // cout << "res: " << res << endl << flush; // debug
143
144   GetLibExceptions();
145   DriverFloatRepr r(res);
146   // DriverFloatRepr r(op1); // debug
147   return r;
148 }
149
150
151 DriverFloatRepr DriverFloatRepr::operator % (DriverFloatRepr &fl)
152 {
153   DriverFloatRepr r(0l);
154   return r;
155 }
156
157 DriverFloatRepr DriverFloatRepr::sqrt()
158 {
159   DriverFloatRepr r(0l);
160   return r;
161 }