softfloat.txt

来自「基于4个mips核的noc设计」· 文本 代码 · 共 375 行 · 第 1/2 页

TXT
375
字号
SoftFloat Release 2b General DocumentationJohn R. Hauser2002 May 27----------------------------------------------------------------------------IntroductionSoftFloat is a software implementation of floating-point that conforms tothe IEC/IEEE Standard for Binary Floating-Point Arithmetic.  As many as fourformats are supported:  single precision, double precision, extended doubleprecision, and quadruple precision.  All operations required by the standardare implemented, except for conversions to and from decimal.This document gives information about the types defined and the routinesimplemented by SoftFloat.  It does not attempt to define or explain theIEC/IEEE Floating-Point Standard.  Details about the standard are availableelsewhere.----------------------------------------------------------------------------LimitationsSoftFloat is written in C and is designed to work with other C code.  TheSoftFloat header files assume an ISO/ANSI-style C compiler.  No attempthas been made to accomodate compilers that are not ISO-conformant.  Inparticular, the distributed header files will not be acceptable to anycompiler that does not recognize function prototypes.Support for the extended double-precision and quadruple-precision formatsdepends on a C compiler that implements 64-bit integer arithmetic.  If thelargest integer format supported by the C compiler is 32 bits, SoftFloatis limited to only single and double precisions.  When that is the case,all references in this document to extended double precision, quadrupleprecision, and 64-bit integers should be ignored.----------------------------------------------------------------------------Contents    Introduction    Limitations    Contents    Legal Notice    Types and Functions    Rounding Modes    Extended Double-Precision Rounding Precision    Exceptions and Exception Flags    Function Details        Conversion Functions        Standard Arithmetic Functions        Remainder Functions        Round-to-Integer Functions        Comparison Functions        Signaling NaN Test Functions        Raise-Exception Function    Contact Information----------------------------------------------------------------------------Legal NoticeSoftFloat was written by John R. Hauser.  This work was made possible inpart by the International Computer Science Institute, located at Suite 600,1947 Center Street, Berkeley, California 94704.  Funding was partiallyprovided by the National Science Foundation under grant MIP-9311980.  Theoriginal version of this code was written as part of a project to builda fixed-point vector processor in collaboration with the University ofCalifornia at Berkeley, overseen by Profs. Nelson Morgan and John Wawrzynek.THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable efforthas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL ATTIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TOPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALLLOSSES, COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHOFURTHERMORE EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTERSCIENCE INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES,COSTS, OR OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THESOFTWARE.----------------------------------------------------------------------------Types and FunctionsWhen 64-bit integers are supported by the compiler, the `softfloat.h'header file defines four types:  `float32' (single precision), `float64'(double precision), `floatx80' (extended double precision), and `float128'(quadruple precision).  The `float32' and `float64' types are defined interms of 32-bit and 64-bit integer types, respectively, while the `float128'type is defined as a structure of two 64-bit integers, taking into accountthe byte order of the particular machine being used.  The `floatx80' typeis defined as a structure containing one 16-bit and one 64-bit integer, withthe machine's byte order again determining the order within the structure.When 64-bit integers are _not_ supported by the compiler, the `softfloat.h'header file defines only two types:  `float32' and `float64'.  BecauseISO/ANSI C guarantees at least one built-in integer type of 32 bits,the `float32' type is identified with an appropriate integer type.  The`float64' type is defined as a structure of two 32-bit integers, with themachine's byte order determining the order of the fields.In either case, the types in `softfloat.h' are defined such that if a systemimplements the usual C `float' and `double' types according to the IEC/IEEEStandard, then the `float32' and `float64' types should be indistinguishablein memory from the native `float' and `double' types.  (On the other hand,when `float32' or `float64' values are placed in processor registers bythe compiler, the type of registers used may differ from those used for thenative `float' and `double' types.)SoftFloat implements the following arithmetic operations:-- Conversions among all the floating-point formats, and also between   integers (32-bit and 64-bit) and any of the floating-point formats.-- The usual add, subtract, multiply, divide, and square root operations   for all floating-point formats.-- For each format, the floating-point remainder operation defined by the   IEC/IEEE Standard.-- For each floating-point format, a ``round to integer'' operation that   rounds to the nearest integer value in the same format.  (The floating-   point formats can hold integer values, of course.)-- Comparisons between two values in the same floating-point format.The only functions required by the IEC/IEEE Standard that are not providedare conversions to and from decimal.----------------------------------------------------------------------------Rounding ModesAll four rounding modes prescribed by the IEC/IEEE Standard are implementedfor all operations that require rounding.  The rounding mode is selectedby the global variable `float_rounding_mode'.  This variable may be setto one of the values `float_round_nearest_even', `float_round_to_zero',`float_round_down', or `float_round_up'.  The rounding mode is initializedto nearest/even.----------------------------------------------------------------------------Extended Double-Precision Rounding PrecisionFor extended double precision (`floatx80') only, the rounding precisionof the standard arithmetic operations is controlled by the global variable`floatx80_rounding_precision'.  The operations affected are:   floatx80_add   floatx80_sub   floatx80_mul   floatx80_div   floatx80_sqrtWhen `floatx80_rounding_precision' is set to its default value of 80, theseoperations are rounded (as usual) to the full precision of the extendeddouble-precision format.  Setting `floatx80_rounding_precision' to 32or to 64 causes the operations listed to be rounded to reduced precisionequivalent to single precision (`float32') or to double precision(`float64'), respectively.  When rounding to reduced precision, additionalbits in the result significand beyond the rounding point are set to zero.The consequences of setting `floatx80_rounding_precision' to a value otherthan 32, 64, or 80 is not specified.  Operations other than the ones listedabove are not affected by `floatx80_rounding_precision'.----------------------------------------------------------------------------Exceptions and Exception FlagsAll five exception flags required by the IEC/IEEE Standard areimplemented.  Each flag is stored as a unique bit in the global variable`float_exception_flags'.  The positions of the exception flag bits withinthis variable are determined by the bit masks `float_flag_inexact',`float_flag_underflow', `float_flag_overflow', `float_flag_divbyzero', and`float_flag_invalid'.  The exception flags variable is initialized to all 0,meaning no exceptions.An individual exception flag can be cleared with the statement    float_exception_flags &= ~ float_flag_<exception>;where `<exception>' is the appropriate name.  To raise a floating-pointexception, the SoftFloat function `float_raise' should be used (see below).In the terminology of the IEC/IEEE Standard, SoftFloat can detect tininessfor underflow either before or after rounding.  The choice is made bythe global variable `float_detect_tininess', which can be set to either`float_tininess_before_rounding' or `float_tininess_after_rounding'.Detecting tininess after rounding is better because it results in fewer

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?