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

Subversion Repositories fpu100

[/] [fpu100/] [tags/] [arelease/] [test_bench/] [SoftFloat/] [softfloat/] [SoftFloat-source.txt] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jidan
 
2
SoftFloat Release 2b Source Documentation
3
 
4
John R. Hauser
5
2002 May 27
6
 
7
 
8
----------------------------------------------------------------------------
9
Introduction
10
 
11
SoftFloat is a software implementation of floating-point that conforms to
12
the IEC/IEEE Standard for Binary Floating-Point Arithmetic.  SoftFloat can
13
support four floating-point formats:  single precision, double precision,
14
extended double precision, and quadruple precision.  All operations required
15
by the IEEE Standard are implemented, except for conversions to and from
16
decimal.  SoftFloat is distributed in the form of C source code, so a
17
C compiler is needed to compile the code.  Support for the extended double-
18
precision and quadruple-precision formats is dependent on the C compiler
19
implementing a 64-bit integer type.
20
 
21
This document gives information needed for compiling and/or porting
22
SoftFloat.
23
 
24
The source code for SoftFloat is intended to be relatively machine-
25
independent and should be compilable using most any ISO/ANSI C compiler.  At
26
the time of this writing, SoftFloat has been successfully compiled with the
27
GNU C Compiler (`gcc') for several platforms.
28
 
29
 
30
----------------------------------------------------------------------------
31
Limitations
32
 
33
As supplied, SoftFloat requires an ISO/ANSI-style C compiler.  No attempt
34
has been made to accomodate compilers that are not ISO-conformant.  Older
35
``K&R-style'' compilers are not adequate for compiling SoftFloat.  All
36
testing I have done so far has been with the GNU C Compiler.  Compilation
37
with other compilers should be possible but has not been tested by me.
38
 
39
The SoftFloat sources assume that source code file names can be longer than
40
8 characters.  In order to compile under an MS-DOS-type system, many of the
41
source files will need to be renamed, and the source and makefiles edited
42
appropriately.  Once compiled, the SoftFloat binary does not depend on the
43
existence of long file names.
44
 
45
The underlying machine is assumed to be binary with a word size that is a
46
power of 2.  Bytes are 8 bits.  Arithmetic on signed integers must modularly
47
wrap around on overflows (as is already required for unsigned integers
48
in C).
49
 
50
Support for the extended double-precision and quadruple-precision formats
51
depends on the C compiler implementing a 64-bit integer type.  If the
52
largest integer type supported by the C compiler is 32 bits, SoftFloat is
53
limited to the single- and double-precision formats.
54
 
55
 
56
----------------------------------------------------------------------------
57
Contents
58
 
59
    Introduction
60
    Limitations
61
    Contents
62
    Legal Notice
63
    SoftFloat Source Directory Structure
64
    SoftFloat Source Files
65
        processors/*.h
66
        softfloat/bits*/*/softfloat.h
67
        softfloat/bits*/*/milieu.h
68
        softfloat/bits*/*/softfloat-specialize
69
        softfloat/bits*/softfloat-macros
70
        softfloat/bits*/softfloat.c
71
    Steps to Creating a `softfloat.o'
72
    Making `softfloat.o' a Library
73
    Testing SoftFloat
74
    Timing SoftFloat
75
    Compiler Options and Efficiency
76
    Processor-Specific Optimization of `softfloat.c' Using `softfloat-macros'
77
    Contact Information
78
 
79
 
80
 
81
----------------------------------------------------------------------------
82
Legal Notice
83
 
84
SoftFloat was written by John R. Hauser.  This work was made possible in
85
part by the International Computer Science Institute, located at Suite 600,
86
1947 Center Street, Berkeley, California 94704.  Funding was partially
87
provided by the National Science Foundation under grant MIP-9311980.  The
88
original version of this code was written as part of a project to build
89
a fixed-point vector processor in collaboration with the University of
90
California at Berkeley, overseen by Profs. Nelson Morgan and John Wawrzynek.
91
 
92
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
93
has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
94
TIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
95
PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL
96
LOSSES, COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO
97
FURTHERMORE EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER
98
SCIENCE INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES,
99
COSTS, OR OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE
100
SOFTWARE.
101
 
102
Derivative works are acceptable, even for commercial purposes, provided
103
that the minimal documentation requirements stated in the source code are
104
satisfied.
105
 
106
 
107
----------------------------------------------------------------------------
108
SoftFloat Source Directory Structure
109
 
110
Because SoftFloat is targeted to multiple platforms, its source code
111
is slightly scattered between target-specific and target-independent
112
directories and files.  The directory structure is as follows:
113
 
114
    processors
115
    softfloat
116
        bits64
117
            templates
118
            386-Win32-GCC
119
            SPARC-Solaris-GCC
120
        bits32
121
            templates
122
            386-Win32-GCC
123
            SPARC-Solaris-GCC
124
 
125
The two topmost directories and their contents are:
126
 
127
    softfloat    - Most of the source code needed for SoftFloat.
128
    processors   - Target-specific header files that are not specific to
129
                       SoftFloat.
130
 
131
The `softfloat' directory is further split into two parts:
132
 
133
    bits64       - SoftFloat implementation using 64-bit integers.
134
    bits32       - SoftFloat implementation using only 32-bit integers.
135
 
136
Within these directories are subdirectories for each of the targeted
137
platforms.  The SoftFloat source code is distributed with targets
138
`386-Win32-GCC' and `SPARC-Solaris-GCC' (and perhaps others) already
139
prepared for both the 32-bit and 64-bit implementations.  Source files that
140
are not within these target-specific subdirectories are intended to be
141
target-independent.
142
 
143
The naming convention used for the target-specific directories is
144
`--'.  The names of the supplied
145
target directories should be interpreted as follows:
146
 
147
  :
148
    386          - Intel 386-compatible processor.
149
    SPARC        - SPARC processor (as used by Sun computers).
150
  :
151
    Win32        - Microsoft Win32 executable.
152
    Solaris      - Sun Solaris executable.
153
  :
154
    GCC          - GNU C Compiler.
155
 
156
You do not need to maintain this convention if you do not want to.
157
 
158
Alongside the supplied target-specific directories is a `templates'
159
directory containing a set of ``generic'' target-specific source files.  A
160
new target directory can be created by copying the `templates' directory and
161
editing the files inside.  (Complete instructions for porting SoftFloat to a
162
new target are in the section _Steps to Creating a `softfloat.o'_.)  Note
163
that the `templates' directory will not work as a target directory without
164
some editing.  To avoid confusion, it would be wise to refrain from editing
165
the files inside `templates' directly.
166
 
167
 
168
----------------------------------------------------------------------------
169
SoftFloat Source Files
170
 
171
The purpose of each source file is described below.  In the following,
172
the `*' symbol is used in place of the name of a specific target, such as
173
`386-Win32-GCC' or `SPARC-Solaris-GCC', or in place of some other text, as
174
in `bits*' for either `bits32' or `bits64'.
175
 
176
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177
processors/*.h
178
 
179
The target-specific `processors' header file defines integer types
180
of various sizes, and also defines certain C preprocessor macros that
181
characterize the target.  The two examples supplied are `386-GCC.h' and
182
`SPARC-GCC.h'.  The naming convention used for processor header files is
183
`-.h'.
184
 
185
If 64-bit integers are supported by the compiler, the macro name `BITS64'
186
should be defined here along with the corresponding 64-bit integer
187
types.  In addition, the function-like macro `LIT64' must be defined for
188
constructing 64-bit integer literals (constants).  The `LIT64' macro is used
189
consistently in the SoftFloat code to annotate 64-bit literals.
190
 
191
If `BITS64' is not defined, only the 32-bit version of SoftFloat can be
192
compiled.  If `BITS64' _is_ defined, either can be compiled.
193
 
194
If an inlining attribute (such as an `inline' keyword) is provided by the
195
compiler, the macro `INLINE' should be defined to the appropriate keyword.
196
If not, `INLINE' can be set to the keyword `static'.  The `INLINE' macro
197
appears in the SoftFloat source code before every function that should
198
be inlined by the compiler.  SoftFloat depends on inlining to obtain
199
good speed.  Even if inlining cannot be forced with a language keyword,
200
the compiler may still be able to perform inlining on its own as an
201
optimization.  If a command-line option is needed to convince the compiler
202
to perform this optimization, this should be assured in the makefile.  (See
203
the section _Compiler Options and Efficiency_ below.)
204
 
205
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206
softfloat/bits*/*/softfloat.h
207
 
208
The target-specific `softfloat.h' header file defines the SoftFloat
209
interface as seen by clients.
210
 
211
Unlike the actual function definitions in `softfloat.c', the declarations
212
in `softfloat.h' do not use any of the types defined by the `processors'
213
header file.  This is done so that clients will not have to include the
214
`processors' header file in order to use SoftFloat.  Nevertheless, the
215
target-specific declarations in `softfloat.h' must match what `softfloat.c'
216
expects.  For example, if `int32' is defined as `int' in the `processors'
217
header file, then in `softfloat.h' the output of `float32_to_int32' should
218
be stated as `int', although in `softfloat.c' it is given in target-
219
independent form as `int32'.
220
 
221
For the `bits64' implementation of SoftFloat, the macro names `FLOATX80' and
222
`FLOAT128' must be defined in order for the extended double-precision and
223
quadruple-precision formats to be enabled in the code.  Conversely, either
224
or both of the extended formats can be disabled by simply removing the
225
`#define' of the respective macro.  When an extended format is not enabled,
226
none of the functions that either input or output the format are defined,
227
and no space is taken up in `softfloat.o' by such functions.  There is no
228
provision for disabling the usual single- and double-precision formats.
229
 
230
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
231
softfloat/bits*/*/milieu.h
232
 
233
The target-specific `milieu.h' header file provides declarations that are
234
needed to compile SoftFloat.  In addition, deviations from ISO/ANSI C by
235
the compiler (such as names not properly declared in system header files)
236
are corrected in this header if possible.
237
 
238
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
239
softfloat/bits*/*/softfloat-specialize
240
 
241
This target-specific C source fragment defines:
242
 
243
-- whether tininess for underflow is detected before or after rounding by
244
       default;
245
-- what (if anything) special happens when exceptions are raised;
246
-- how signaling NaNs are distinguished from quiet NaNs;
247
-- the default generated quiet NaNs; and
248
-- how NaNs are propagated from function inputs to output.
249
 
250
These details are not decided by the IEC/IEEE Standard.  This fragment is
251
included verbatim within `softfloat.c' when SoftFloat is compiled.
252
 
253
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
254
softfloat/bits*/softfloat-macros
255
 
256
This target-independent C source fragment defines a number of arithmetic
257
functions used as primitives within the `softfloat.c' source.  Most of
258
the functions defined here are intended to be inlined for efficiency.
259
This fragment is included verbatim within `softfloat.c' when SoftFloat is
260
compiled.
261
 
262
Target-specific variations on this file are possible.  See the section
263
_Processor-Specific Optimization of `softfloat.c' Using `softfloat-macros'_
264
below.
265
 
266
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267
softfloat/bits*/softfloat.c
268
 
269
The target-independent `softfloat.c' source file contains the body of the
270
SoftFloat implementation.
271
 
272
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
273
 
274
The inclusion of the files above within each other (using `#include') can be
275
shown graphically as follows:
276
 
277
    softfloat/bits*/softfloat.c
278
        softfloat/bits*/*/milieu.h
279
            processors/*.h
280
        softfloat/bits*/*/softfloat.h
281
        softfloat/bits*/*/softfloat-specialize
282
        softfloat/bits*/softfloat-macros
283
 
284
Note in particular that `softfloat.c' does not include the `processors'
285
header file directly.  Rather, `softfloat.c' includes the target-specific
286
`milieu.h' header file, which in turn includes the appropriate processor
287
header file.
288
 
289
 
290
----------------------------------------------------------------------------
291
Steps to Creating a `softfloat.o'
292
 
293
Porting and/or compiling SoftFloat involves the following steps:
294
 
295
1. If one does not already exist, create an appropriate `.h' file in the
296
   `processors' directory.
297
 
298
2. If `BITS64' is defined in the `processors' header file, choose whether
299
   to compile the 32-bit or 64-bit implementation of SoftFloat.  If
300
   `BITS64' is not defined, your only choice is the 32-bit implementation.
301
   The remaining steps occur within either the `bits32' or `bits64'
302
   subdirectories.
303
 
304
3. If one does not already exist, create an appropriate target-specific
305
   subdirectory by copying the given `templates' directory.
306
 
307
4. In the target-specific subdirectory, edit the files `softfloat-specialize'
308
   and `softfloat.h' to define the desired exception handling functions
309
   and mode control values.  In the `softfloat.h' header file, ensure also
310
   that all declarations give the proper target-specific type (such as
311
   `int' or `long') corresponding to the target-independent type used in
312
   `softfloat.c' (such as `int32').  None of the type names declared in the
313
   `processors' header file should appear in `softfloat.h'.
314
 
315
5. In the target-specific subdirectory, edit the files `milieu.h' and
316
   `Makefile' to reflect the current environment.
317
 
318
6. In the target-specific subdirectory, execute `make'.
319
 
320
For the targets that are supplied, if the expected compiler is available
321
(usually `gcc'), it should only be necessary to execute `make' in the
322
target-specific subdirectory.
323
 
324
 
325
----------------------------------------------------------------------------
326
Making `softfloat.o' a Library
327
 
328
SoftFloat is not made into a software library by the supplied makefile.
329
If desired, `softfloat.o' can easily be put into its own library (in Unix,
330
`softfloat.a') using the usual system tool (in Unix, `ar').
331
 
332
 
333
----------------------------------------------------------------------------
334
Testing SoftFloat
335
 
336
SoftFloat can be tested using the `testsoftfloat' program by the same
337
author.  The `testsoftfloat' program is part of the TestFloat package
338
available at the Web page `http://www.cs.berkeley.edu/~jhauser/arithmetic/
339
TestFloat.html'.
340
 
341
 
342
----------------------------------------------------------------------------
343
Timing SoftFloat
344
 
345
A program called `timesoftfloat' for timing the SoftFloat functions is
346
included with the SoftFloat source code.  Compiling `timesoftfloat' should
347
pose no difficulties once `softfloat.o' exists.  The supplied makefile
348
will create a `timesoftfloat' executable by default after generating
349
`softfloat.o'.  See `timesoftfloat.txt' for documentation about using
350
`timesoftfloat'.
351
 
352
 
353
----------------------------------------------------------------------------
354
Compiler Options and Efficiency
355
 
356
In order to get good speed with SoftFloat, it is important that the compiler
357
inline the routines that have been marked `INLINE' in the code.  Even if
358
inlining cannot be forced by an appropriate definition of the `INLINE'
359
macro, the compiler may still be able to perform inlining on its own as
360
an optimization.  In that case, the makefile should be edited to give the
361
compiler whatever option is required to cause it to inline small functions.
362
 
363
 
364
----------------------------------------------------------------------------
365
Processor-Specific Optimization of `softfloat.c' Using `softfloat-macros'
366
 
367
The `softfloat-macros' source fragment defines arithmetic functions used
368
as primitives by `softfloat.c'.  This file has been written in a target-
369
independent form.  For a given target, it may be possible to improve on
370
these functions using target-specific and/or non-ISO-C features (such
371
as `asm' statements).  For example, one of the ``macro'' functions takes
372
two word-size integers and returns their full product in two words.
373
This operation can be done directly in hardware on many processors; but
374
because it is not available through standard C, the function defined in
375
`softfloat-macros' uses four multiplications to achieve the same result.
376
 
377
To address these shortcomings, a customized version of `softfloat-macros'
378
can be created in any of the target-specific subdirectories.  A simple
379
modification to the target's makefile should be sufficient to ensure that
380
the custom version is used instead of the generic one.
381
 
382
 
383
----------------------------------------------------------------------------
384
Contact Information
385
 
386
At the time of this writing, the most up-to-date information about
387
SoftFloat and the latest release can be found at the Web page `http://
388
www.cs.berkeley.edu/~jhauser/arithmetic/SoftFloat.html'.
389
 
390
 

powered by: WebSVN 2.1.0

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