如何在x86和x86_64上使用Gcc 4.6.0 libquadmath和__float128 [英] How to use Gcc 4.6.0 libquadmath and __float128 on x86 and x86_64
问题描述
long double
type(80bit)来进行浮点运算。我想用新的GCC 4.6扩展 __ float128
来提高精度。就像我得到的那样,这是一个软件模拟的128位精度数学。我应该如何将我的程序从经典的80位双精度浮点数转换为128浮点数与完全精确的软件仿真?
我需要改变什么?编译器的标志,源?
我的程序读取完整的精度值与 strtod
,做了很多不同的操作(例如+ - * / sin,cos,exp和其他来自< math.h>
)和 printf
PPS:有是C语言gcc模式的文档: http://gcc.gnu.org/onlinedocs/gcc /Floating-Types.html
$ b
GNU C编译器支持128位(TFmode)浮动类型。其他类型包括算术运算符:加,减,乘,除;一元算术运算符;关系运算符;相等运算符...在i386,x86_64上支持__float128类型$ b $我应该如何将我的程序从80位的经典长双倍数据转换为四倍数据浮点数128位软件仿真的全精度?我需要改变什么?编译器标志,源代码?
您需要最新的软件,支持 __ float128
类型(4.6和更新)和libquadmath(仅在 x86和x86_64目标上受支持; IA64和HPPA与更新的GCC)。你应该添加链接器标记 -lquadmath
(找不到-lquadmath'
会显示你没有安装libquadmath) / p>
- 添加
#include< quadmath.h>
标题以具有宏和函数定义。 - 您应该将所有
long double
变量定义修改为__ float128
。
- 复数变量可以变为
__ complex128
类型(quadmath.h
)或直接使用typedef _Complex float __attribute __((mode(TC)))_Complex128;
- 所有简单的算术运算都由GCC自动处理(转换为像
__ * tf3()
)这样的辅助函数的调用。 如果使用LDBL _ *
等任何宏,请将它们替换为FLT128 _ *
(完整列表 http://gcc.gnu.org/onlinedocs/ libquadmath / Typedef-and-constants.html#Typedef-and-constants )
- 如果你需要一些特定的常量像pi(
M_PI $ (c $ c>)或e(
),如M_E
),使用预定义的常量(q
suffix(<$ c (code> M_qqM_PIq
和M_Eq
(完整列表 http://gcc.gnu.org/onlinedocs/libquadmath/Typedef-and- constants.html#Typedef-and-constants )
- 用户定义的常量可以用
,像Q
所有的数学函数调用应该被替换为* q
版本1.3000011111111Q
sqrtq()
,sinq()
(完整列表 http: //gcc.gnu.org/onlinedocs/libquadmath/Math-Library-Routines.html#Math-Library-Routing )
- 从字符串中读取四元组与
__ float128 strtoflt128(const char * s,char ** sp)
- http://gcc.gnu.org/onlinedocs/libquadmath/strtoflt128.html#strtoflt128 (警告,在较旧的libquadmags中,strtoflt128可能会有一些错误,请仔细检查)
- 打印
__ float128
是在quadmath_snprintf
函数的帮助下完成的。在最近使用glibc的linux发行版中,函数将被libquadmath自动注册以处理Q
(也可以是q
)长度a,a,e,E,f,f,g,
sprintf
s,就像L
长时间加倍一样。示例:printf(%Qe,1.2Q)
, http://gcc.gnu.org/onlinedocs/libquadmath/quadmath_005fsnprintf.html#quadmath_005fsnprintf
- 如果你需要一些特定的常量像pi(
您应该也知道,既然4.6 Gfortran将使用DOUBLE PRECISION的 __ float128
类型,如果 -fdefault-real-8
被给出了,没有选项 -fdefault-double-8
。这可能是个问题,因为在软件计算中,128位双精度比许多平台上的标准精度双精度要慢得多。 (感谢glennglockwood http://glennklockwood.blogspot.com/2014/ 02 / linux-perf-libquadmath-and-gfortrans.html )
I have medium size C99 program which uses long double
type (80bit) for floating-point computation. I want to improve precision with new GCC 4.6 extension __float128
. As I get, it is a software-emulated 128-bit precision math.
How should I convert my program from classic long double of 80-bit to quad floats of 128 bit with software emulation of full precision? What need I change? Compiler flags, sources?
My program have reading of full precision values with strtod
, doing a lot of different operations on them (like +-*/ sin, cos, exp and other from <math.h>
) and printf
-ing of them.
PS: despite that float128 is declared only for Fortran (REAL*16), the libquadmath is written in C and it uses float128. I'm unsure will GCC convert operations on float128 to runtime library or not and I'm unsure how to migrate from long double to __float128 in my sources.
PPS: There is a documentation on "C" language gcc mode: http://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html
"GNU C compiler supports ... 128 bit (TFmode) floating types. Support for additional types includes the arithmetic operators: add, subtract, multiply, divide; unary arithmetic operators; relational operators; equality operators ... __float128 types are supported on i386, x86_64"
How should I convert my program from classic long double of 80-bit to quad floats of 128 bit with software emulation of full precision? What need I change? Compiler flags, sources?
You need recent software, GCC version with support of __float128
type (4.6 and newer) and libquadmath (supported only on x86 and x86_64 targets; in IA64 and HPPA with newer GCC). You should add linker flag -lquadmath
(the cannot find -lquadmath'
will show that you have no libquadmath installed)
- Add
#include <quadmath.h>
header to have macro and function definitions. - You should modify all
long double
variable definitions to__float128
. - Complex variables may be changed to
__complex128
type (quadmath.h
) or directly withtypedef _Complex float __attribute__((mode(TC))) _Complex128;
- All simple arithmetic operations are automatically handled by GCC (converted to calls of helper functions like
__*tf3()
). - If you use any macro like
LDBL_*
, replace them withFLT128_*
(full list http://gcc.gnu.org/onlinedocs/libquadmath/Typedef-and-constants.html#Typedef-and-constants) - If you need some specific constants like pi (
M_PI
) or e (M_E
) with quadruple precision, use predefined constants withq
suffix (M_*q
), likeM_PIq
andM_Eq
(full list http://gcc.gnu.org/onlinedocs/libquadmath/Typedef-and-constants.html#Typedef-and-constants) - User-defined constants may be written with
Q
suffix, like1.3000011111111Q
- All math function calls should be replaced with
*q
versions, likesqrtq()
,sinq()
(full list http://gcc.gnu.org/onlinedocs/libquadmath/Math-Library-Routines.html#Math-Library-Routines) - Reading quad-float from string should be done with
__float128 strtoflt128 (const char *s, char **sp)
- http://gcc.gnu.org/onlinedocs/libquadmath/strtoflt128.html#strtoflt128 (Warning, in older libquadmaths there may be some bugs in strtoflt128, do a double check) - Printing the
__float128
is done with help ofquadmath_snprintf
function. On linux distributions with recent glibc the function will be automagically registered by libquadmath to handleQ
(may be alsoq
) length modifier ofa, A, e, E, f, F, g, G
conversion specifiers in allprintf
s/sprintf
s, like it didL
for long doubles. Example:printf ("%Qe", 1.2Q)
, http://gcc.gnu.org/onlinedocs/libquadmath/quadmath_005fsnprintf.html#quadmath_005fsnprintf
You should also know, that since 4.6 Gfortran will use __float128
type for DOUBLE PRECISION, if the option -fdefault-real-8
was given and there were no option -fdefault-double-8
. This may be problem, since 128 long double is much slower than standard long double on many platforms due to software computation. (Thanks to post by glennglockwood http://glennklockwood.blogspot.com/2014/02/linux-perf-libquadmath-and-gfortrans.html)
这篇关于如何在x86和x86_64上使用Gcc 4.6.0 libquadmath和__float128的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!