Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:The GCC low-level runtime library   [Contents][Index]


3.2 Routines for floating point emulation

The software floating point library is used on machines which do nothave hardware support for floating point. It is also used whenever-msoft-float is used to disable generation of floating pointinstructions. (Not all targets support this switch.)

For compatibility with other compilers, the floating point emulationroutines can be renamed with theDECLARE_LIBRARY_RENAMES macro(seeImplicit Calls to Library Routines). In this section, the default names are used.

Presently the library does not supportXFmode, which is usedforlong double on some architectures.

3.2.1 Arithmetic functions

Runtime Function:float__addsf3(floata, floatb)
Runtime Function:double__adddf3(doublea, doubleb)
Runtime Function:long double__addtf3(long doublea, long doubleb)
Runtime Function:long double__addxf3(long doublea, long doubleb)

These functions return the sum ofa andb.

Runtime Function:float__subsf3(floata, floatb)
Runtime Function:double__subdf3(doublea, doubleb)
Runtime Function:long double__subtf3(long doublea, long doubleb)
Runtime Function:long double__subxf3(long doublea, long doubleb)

These functions return the difference betweenb anda;that is,a -b.

Runtime Function:float__mulsf3(floata, floatb)
Runtime Function:double__muldf3(doublea, doubleb)
Runtime Function:long double__multf3(long doublea, long doubleb)
Runtime Function:long double__mulxf3(long doublea, long doubleb)

These functions return the product ofa andb.

Runtime Function:float__divsf3(floata, floatb)
Runtime Function:double__divdf3(doublea, doubleb)
Runtime Function:long double__divtf3(long doublea, long doubleb)
Runtime Function:long double__divxf3(long doublea, long doubleb)

These functions return the quotient ofa andb; that is,a /b.

Runtime Function:float__negsf2(floata)
Runtime Function:double__negdf2(doublea)
Runtime Function:long double__negtf2(long doublea)
Runtime Function:long double__negxf2(long doublea)

These functions return the negation ofa. They simply flip thesign bit, so they can produce negative zero and negative NaN.

3.2.2 Conversion functions

Runtime Function:double__extendsfdf2(floata)
Runtime Function:long double__extendsftf2(floata)
Runtime Function:long double__extendsfxf2(floata)
Runtime Function:long double__extenddftf2(doublea)
Runtime Function:long double__extenddfxf2(doublea)

These functions extenda to the wider mode of their returntype.

Runtime Function:double__truncxfdf2(long doublea)
Runtime Function:double__trunctfdf2(long doublea)
Runtime Function:float__truncxfsf2(long doublea)
Runtime Function:float__trunctfsf2(long doublea)
Runtime Function:float__truncdfsf2(doublea)

These functions truncatea to the narrower mode of their returntype, rounding toward zero.

Runtime Function:int__fixsfsi(floata)
Runtime Function:int__fixdfsi(doublea)
Runtime Function:int__fixtfsi(long doublea)
Runtime Function:int__fixxfsi(long doublea)

These functions converta to a signed integer, rounding toward zero.

Runtime Function:long__fixsfdi(floata)
Runtime Function:long__fixdfdi(doublea)
Runtime Function:long__fixtfdi(long doublea)
Runtime Function:long__fixxfdi(long doublea)

These functions converta to a signed long, rounding toward zero.

Runtime Function:long long__fixsfti(floata)
Runtime Function:long long__fixdfti(doublea)
Runtime Function:long long__fixtfti(long doublea)
Runtime Function:long long__fixxfti(long doublea)

These functions converta to a signed long long, rounding toward zero.

Runtime Function:unsigned int__fixunssfsi(floata)
Runtime Function:unsigned int__fixunsdfsi(doublea)
Runtime Function:unsigned int__fixunstfsi(long doublea)
Runtime Function:unsigned int__fixunsxfsi(long doublea)

These functions converta to an unsigned integer, roundingtoward zero. Negative values all become zero.

Runtime Function:unsigned long__fixunssfdi(floata)
Runtime Function:unsigned long__fixunsdfdi(doublea)
Runtime Function:unsigned long__fixunstfdi(long doublea)
Runtime Function:unsigned long__fixunsxfdi(long doublea)

These functions converta to an unsigned long, roundingtoward zero. Negative values all become zero.

Runtime Function:unsigned long long__fixunssfti(floata)
Runtime Function:unsigned long long__fixunsdfti(doublea)
Runtime Function:unsigned long long__fixunstfti(long doublea)
Runtime Function:unsigned long long__fixunsxfti(long doublea)

These functions converta to an unsigned long long, roundingtoward zero. Negative values all become zero.

Runtime Function:float__floatsisf(inti)
Runtime Function:double__floatsidf(inti)
Runtime Function:long double__floatsitf(inti)
Runtime Function:long double__floatsixf(inti)

These functions converti, a signed integer, to floating point.

Runtime Function:float__floatdisf(longi)
Runtime Function:double__floatdidf(longi)
Runtime Function:long double__floatditf(longi)
Runtime Function:long double__floatdixf(longi)

These functions converti, a signed long, to floating point.

Runtime Function:float__floattisf(long longi)
Runtime Function:double__floattidf(long longi)
Runtime Function:long double__floattitf(long longi)
Runtime Function:long double__floattixf(long longi)

These functions converti, a signed long long, to floating point.

Runtime Function:float__floatunsisf(unsigned inti)
Runtime Function:double__floatunsidf(unsigned inti)
Runtime Function:long double__floatunsitf(unsigned inti)
Runtime Function:long double__floatunsixf(unsigned inti)

These functions converti, an unsigned integer, to floating point.

Runtime Function:float__floatundisf(unsigned longi)
Runtime Function:double__floatundidf(unsigned longi)
Runtime Function:long double__floatunditf(unsigned longi)
Runtime Function:long double__floatundixf(unsigned longi)

These functions converti, an unsigned long, to floating point.

Runtime Function:float__floatuntisf(unsigned long longi)
Runtime Function:double__floatuntidf(unsigned long longi)
Runtime Function:long double__floatuntitf(unsigned long longi)
Runtime Function:long double__floatuntixf(unsigned long longi)

These functions converti, an unsigned long long, to floating point.

Runtime Function:void__fixsfbitint(UBILtype *r, int32_trprec, floata)
Runtime Function:void__fixdfbitint(UBILtype *r, int32_trprec, doublea)
Runtime Function:void__fixxfbitint(UBILtype *r, int32_trprec, __float80a)
Runtime Function:void__fixtfbitint(UBILtype *r, int32_trprec, _Float128a)

These functions converta to bit-precise integerr, rounding toward zero.Ifrprec is positive, it converts to unsigned bit-precise integer andnegative values all become zero, ifrprec is negative, it convertsto signed bit-precise integer.

Runtime Function:float__floatbitintsf(UBILtype *i, int32_tiprec)
Runtime Function:double__floatbitintdf(UBILtype *i, int32_tiprec)
Runtime Function:__float80__floatbitintxf(UBILtype *i, int32_tiprec)
Runtime Function:_Float128__floatbitinttf(UBILtype *i, int32_tiprec)
Runtime Function:_Float16__floatbitinthf(UBILtype *i, int32_tiprec)
Runtime Function:__bf16__floatbitintbf(UBILtype *i, int32_tiprec)

These functions convert bit-precise integeri to floating point. Ifiprec is positive, it is conversion from unsigned bit-precise integer,otherwise from signed bit-precise integer.

3.2.3 Comparison functions

There are two sets of basic comparison functions.

Runtime Function:CMPtype__cmpsf2(floata, floatb)
Runtime Function:CMPtype__cmpdf2(doublea, doubleb)
Runtime Function:CMPtype__cmptf2(long doublea, long doubleb)

These functions calculatea <=> b. That is, ifa is lessthanb, they return −1; ifa is greater thanb, theyreturn 1; and ifa andb are equal they return 0. Ifeither argument is NaN they return 1, but you should not rely on this;if NaN is a possibility, use one of the higher-level comparisonfunctions.

Runtime Function:CMPtype__unordsf2(floata, floatb)
Runtime Function:CMPtype__unorddf2(doublea, doubleb)
Runtime Function:CMPtype__unordtf2(long doublea, long doubleb)

These functions return a nonzero value if either argument is NaN, otherwise 0.

There is also a complete group of higher level functions whichcorrespond directly to comparison operators. They implement the ISO Csemantics for floating-point comparisons, taking NaN into account.Pay careful attention to the return values defined for each set.Under the hood, all of these routines are implemented as

  if (__unordXf2 (a, b))    returnE;  return __cmpXf2 (a, b);

whereE is a constant chosen to give the proper behavior forNaN. Thus, the meaning of the return value is different for each set.Do not rely on this implementation; only the semantics documentedbelow are guaranteed.

Runtime Function:CMPtype__eqsf2(floata, floatb)
Runtime Function:CMPtype__eqdf2(doublea, doubleb)
Runtime Function:CMPtype__eqtf2(long doublea, long doubleb)

These functions return zero if neither argument is NaN, anda andb are equal.

Runtime Function:CMPtype__nesf2(floata, floatb)
Runtime Function:CMPtype__nedf2(doublea, doubleb)
Runtime Function:CMPtype__netf2(long doublea, long doubleb)

These functions return a nonzero value if either argument is NaN, orifa andb are unequal.

Runtime Function:CMPtype__gesf2(floata, floatb)
Runtime Function:CMPtype__gedf2(doublea, doubleb)
Runtime Function:CMPtype__getf2(long doublea, long doubleb)

These functions return a value greater than or equal to zero ifneither argument is NaN, anda is greater than or equal tob.

Runtime Function:CMPtype__ltsf2(floata, floatb)
Runtime Function:CMPtype__ltdf2(doublea, doubleb)
Runtime Function:CMPtype__lttf2(long doublea, long doubleb)

These functions return a value less than zero if neither argument isNaN, anda is strictly less thanb.

Runtime Function:CMPtype__lesf2(floata, floatb)
Runtime Function:CMPtype__ledf2(doublea, doubleb)
Runtime Function:CMPtype__letf2(long doublea, long doubleb)

These functions return a value less than or equal to zero if neitherargument is NaN, anda is less than or equal tob.

Runtime Function:CMPtype__gtsf2(floata, floatb)
Runtime Function:CMPtype__gtdf2(doublea, doubleb)
Runtime Function:CMPtype__gttf2(long doublea, long doubleb)

These functions return a value greater than zero if neither argumentis NaN, anda is strictly greater thanb.

Comparison functions return aCMPtype which is a signed integer oftarget-dependent size. TypicallyCMPtype will be word-sized, butother backends may override this with theTARGET_LIBGCC_CMP_RETURN_MODEhook. Of note, AArch64 uses an single-int as the return type, and AVR usesa quarter-int.

3.2.4 Other floating-point functions

Runtime Function:float__powisf2(floata, intb)
Runtime Function:double__powidf2(doublea, intb)
Runtime Function:long double__powitf2(long doublea, intb)
Runtime Function:long double__powixf2(long doublea, intb)

These functions convert raisea to the powerb.

Runtime Function:complex float__mulsc3(floata, floatb, floatc, floatd)
Runtime Function:complex double__muldc3(doublea, doubleb, doublec, doubled)
Runtime Function:complex long double__multc3(long doublea, long doubleb, long doublec, long doubled)
Runtime Function:complex long double__mulxc3(long doublea, long doubleb, long doublec, long doubled)

These functions return the product ofa + ib andc + id, following the rules of C99 Annex G.

Runtime Function:complex float__divsc3(floata, floatb, floatc, floatd)
Runtime Function:complex double__divdc3(doublea, doubleb, doublec, doubled)
Runtime Function:complex long double__divtc3(long doublea, long doubleb, long doublec, long doubled)
Runtime Function:complex long double__divxc3(long doublea, long doubleb, long doublec, long doubled)

These functions return the quotient ofa + ib andc + id (i.e.,(a + ib) / (c+ id)), following the rules of C99 Annex G.


Next:Routines for decimal floating point emulation, Previous:Routines for integer arithmetic, Up:The GCC low-level runtime library   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp