Routines for floating point emulation

用于浮点模拟的例程

#include <stdio.h>

4.2 Routines for floating point emulation

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

For compatibility with other compilers, the floating point emulation routines can be renamed with the DECLARE_LIBRARY_RENAMES macro (see Library Calls). In this section, the default names are used.

Presently the library does not support XFmode, which is used for long double on some architectures.

4.2.1 Arithmetic functions

Runtime Function: float __addsf3 (float a, float b)
Runtime Function: double __adddf3 (double a, double b)
Runtime Function: long double __addtf3 (long double a, long double b)
Runtime Function: long double __addxf3 (long double a, long double b)
These functions return the sum of a and b.

Runtime Function: float __subsf3 (float a, float b)
Runtime Function: double __subdf3 (double a, double b)
Runtime Function: long double __subtf3 (long double a, long double b)
Runtime Function: long double __subxf3 (long double a, long double b)
These functions return the difference between b and a; that is, a - b.

Runtime Function: float __mulsf3 (float a, float b)
Runtime Function: double __muldf3 (double a, double b)
Runtime Function: long double __multf3 (long double a, long double b)
Runtime Function: long double __mulxf3 (long double a, long double b)
These functions return the product of a and b.

Runtime Function: float __divsf3 (float a, float b)
Runtime Function: double __divdf3 (double a, double b)
Runtime Function: long double __divtf3 (long double a, long double b)
Runtime Function: long double __divxf3 (long double a, long double b)
These functions return the quotient of a and b; that is, a / b.

Runtime Function: float __negsf2 (float a)
Runtime Function: double __negdf2 (double a)
Runtime Function: long double __negtf2 (long double a)
Runtime Function: long double __negxf2 (long double a)
These functions return the negation of a. They simply flip the sign bit, so they can produce negative zero and negative NaN.

4.2.2 Conversion functions

Runtime Function: double __extendsfdf2 (float a)
Runtime Function: long double __extendsftf2 (float a)
Runtime Function: long double __extendsfxf2 (float a)
Runtime Function: long double __extenddftf2 (double a)
Runtime Function: long double __extenddfxf2 (double a)
These functions extend a to the wider mode of their return type.

Runtime Function: double __truncxfdf2 (long double a)
Runtime Function: double __trunctfdf2 (long double a)
Runtime Function: float __truncxfsf2 (long double a)
Runtime Function: float __trunctfsf2 (long double a)
Runtime Function: float __truncdfsf2 (double a)
These functions truncate a to the narrower mode of their return type, rounding toward zero.

Runtime Function: int __fixsfsi (float a)
Runtime Function: int __fixdfsi (double a)
Runtime Function: int __fixtfsi (long double a)
Runtime Function: int __fixxfsi (long double a)
These functions convert a to a signed integer, rounding toward zero.

Runtime Function: long __fixsfdi (float a)
Runtime Function: long __fixdfdi (double a)
Runtime Function: long __fixtfdi (long double a)
Runtime Function: long __fixxfdi (long double a)
These functions convert a to a signed long, rounding toward zero.

Runtime Function: long long __fixsfti (float a)
Runtime Function: long long __fixdfti (double a)
Runtime Function: long long __fixtfti (long double a)
Runtime Function: long long __fixxfti (long double a)
These functions convert a to a signed long long, rounding toward zero.

Runtime Function: unsigned int __fixunssfsi (float a)
Runtime Function: unsigned int __fixunsdfsi (double a)
Runtime Function: unsigned int __fixunstfsi (long double a)
Runtime Function: unsigned int __fixunsxfsi (long double a)
These functions convert a to an unsigned integer, rounding toward zero. Negative values all become zero.

Runtime Function: unsigned long __fixunssfdi (float a)
Runtime Function: unsigned long __fixunsdfdi (double a)
Runtime Function: unsigned long __fixunstfdi (long double a)
Runtime Function: unsigned long __fixunsxfdi (long double a)
These functions convert a to an unsigned long, rounding toward zero. Negative values all become zero.

Runtime Function: unsigned long long __fixunssfti (float a)
Runtime Function: unsigned long long __fixunsdfti (double a)
Runtime Function: unsigned long long __fixunstfti (long double a)
Runtime Function: unsigned long long __fixunsxfti (long double a)
These functions convert a to an unsigned long long, rounding toward zero. Negative values all become zero.

Runtime Function: float __floatsisf (int i)
Runtime Function: double __floatsidf (int i)
Runtime Function: long double __floatsitf (int i)
Runtime Function: long double __floatsixf (int i)
These functions convert i, a signed integer, to floating point.

Runtime Function: float __floatdisf (long i)
Runtime Function: double __floatdidf (long i)
Runtime Function: long double __floatditf (long i)
Runtime Function: long double __floatdixf (long i)
These functions convert i, a signed long, to floating point.

Runtime Function: float __floattisf (long long i)
Runtime Function: double __floattidf (long long i)
Runtime Function: long double __floattitf (long long i)
Runtime Function: long double __floattixf (long long i)
These functions convert i, a signed long long, to floating point.

Runtime Function: float __floatunsisf (unsigned int i)
Runtime Function: double __floatunsidf (unsigned int i)
Runtime Function: long double __floatunsitf (unsigned int i)
Runtime Function: long double __floatunsixf (unsigned int i)
These functions convert i, an unsigned integer, to floating point.

Runtime Function: float __floatundisf (unsigned long i)
Runtime Function: double __floatundidf (unsigned long i)
Runtime Function: long double __floatunditf (unsigned long i)
Runtime Function: long double __floatundixf (unsigned long i)
These functions convert i, an unsigned long, to floating point.

Runtime Function: float __floatuntisf (unsigned long long i)
Runtime Function: double __floatuntidf (unsigned long long i)
Runtime Function: long double __floatuntitf (unsigned long long i)
Runtime Function: long double __floatuntixf (unsigned long long i)
These functions convert i, an unsigned long long, to floating point.

4.2.3 Comparison functions

There are two sets of basic comparison functions.

Runtime Function: int __cmpsf2 (float a, float b)
Runtime Function: int __cmpdf2 (double a, double b)
Runtime Function: int __cmptf2 (long double a, long double b)
These functions calculate a <=> b. That is, if a is less than b, they return -1; if a is greater than b, they return 1; and if a and b are equal they return 0. If either argument is NaN they return 1, but you should not rely on this; if NaN is a possibility, use one of the higher-level comparison functions.

Runtime Function: int __unordsf2 (float a, float b)
Runtime Function: int __unorddf2 (double a, double b)
Runtime Function: int __unordtf2 (long double a, long double b)
These functions return a nonzero value if either argument is NaN, otherwise 0.

There is also a complete group of higher level functions which correspond directly to comparison operators. They implement the ISO C semantics 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))
    return E;
  return __cmpXf2 (a, b);
where E is a constant chosen to give the proper behavior for NaN. Thus, the meaning of the return value is different for each set. Do not rely on this implementation; only the semantics documented below are guaranteed.

Runtime Function: int __eqsf2 (float a, float b)
Runtime Function: int __eqdf2 (double a, double b)
Runtime Function: int __eqtf2 (long double a, long double b)
These functions return zero if neither argument is NaN, and a and b are equal.

Runtime Function: int __nesf2 (float a, float b)
Runtime Function: int __nedf2 (double a, double b)
Runtime Function: int __netf2 (long double a, long double b)
These functions return a nonzero value if either argument is NaN, or if a and b are unequal.

Runtime Function: int __gesf2 (float a, float b)
Runtime Function: int __gedf2 (double a, double b)
Runtime Function: int __getf2 (long double a, long double b)
These functions return a value greater than or equal to zero if neither argument is NaN, and a is greater than or equal to b.

Runtime Function: int __ltsf2 (float a, float b)
Runtime Function: int __ltdf2 (double a, double b)
Runtime Function: int __lttf2 (long double a, long double b)
These functions return a value less than zero if neither argument is NaN, and a is strictly less than b.

Runtime Function: int __lesf2 (float a, float b)
Runtime Function: int __ledf2 (double a, double b)
Runtime Function: int __letf2 (long double a, long double b)
These functions return a value less than or equal to zero if neither argument is NaN, and a is less than or equal to b.

Runtime Function: int __gtsf2 (float a, float b)
Runtime Function: int __gtdf2 (double a, double b)
Runtime Function: int __gttf2 (long double a, long double b)
These functions return a value greater than zero if neither argument is NaN, and a is strictly greater than b.

4.2.4 Other floating-point functions

Runtime Function: float __powisf2 (float a, int b)
Runtime Function: double __powidf2 (double a, int b)
Runtime Function: long double __powitf2 (long double a, int b)
Runtime Function: long double __powixf2 (long double a, int b)
These functions convert raise a to the power b.

Runtime Function: complex float __mulsc3 (float a, float b, float c, float d)
Runtime Function: complex double __muldc3 (double a, double b, double c, double d)
Runtime Function: complex long double __multc3 (long double a, long double b, long double c, long double d)
Runtime Function: complex long double __mulxc3 (long double a, long double b, long double c, long double d)
These functions return the product of a + ib and c + id, following the rules of C99 Annex G.

Runtime Function: complex float __divsc3 (float a, float b, float c, float d)
Runtime Function: complex double __divdc3 (double a, double b, double c, double d)
Runtime Function: complex long double __divtc3 (long double a, long double b, long double c, long double d)
Runtime Function: complex long double __divxc3 (long double a, long double b, long double c, long double d)
These functions return the quotient of a + ib and c + id (i.e., (a + ib) / (c + id)), following the rules of C99 Annex G.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,254评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,875评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,682评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,896评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,015评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,152评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,208评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,962评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,388评论 1 304
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,700评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,867评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,551评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,186评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,901评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,142评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,689评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,757评论 2 351

推荐阅读更多精彩内容