简体   繁体   English

如何定义80位大小的变量

[英]How to define a 80-bit size variable

I need to declare a 80bit size variable in C program compiled by gcc (I need it to pass data to asm procedure which works on fpu, which is called by this program written in C) 我需要在由gcc编译的C程序中声明一个80位大小的变量(我需要将其传递给可在fpu上运行的asm过程的数据,此过程由用C编写的程序调用)
My architecture is AMD x64 我的架构是AMD x64
I tried long double , __float80 , but for them sizeof returns 12 instead of 10 . 我尝试了long double __float80 ,但是对于他们来说sizeof返回12而不是10 So how to declare such variable? 那么如何声明这样的变量呢?

The size includes padding for alignment, it is nevertheless a 80 bit value. 该大小包括用于对齐的填充,但是它还是80位的值。 The manual says: 手册说:

-m96bit-long-double -m96bit-long-double

-m128bit-long-double -m128bit-long-double

These switches control the size of long double type. 这些开关控制long double类型的大小。 The x86-32 application binary interface specifies the size to be 96 bits, so -m96bit-long-double is the default in 32-bit mode. x86-32应用程序二进制接口将大小指定为96位,因此-m96bit-long-double是32位模式下的默认值。

Modern architectures (Pentium and newer) prefer long double to be aligned to an 8- or 16-byte boundary. 现代体系结构(奔腾和更新的体系结构)更喜欢将long double对齐到8字节或16字节的边界。 In arrays or structures conforming to the ABI, this is not possible. 在符合ABI的阵列或结构中,这是不可能的。 So specifying -m128bit-long-double aligns long double to a 16-byte boundary by padding the long double with an additional 32-bit zero. 因此,指定-m128bit-long-double可以通过将long double填充额外的32位零来将long double与16字节边界对齐。

In the x86-64 compiler, -m128bit-long-double is the default choice as its ABI specifies that long double is aligned on 16-byte boundary. 在x86-64编译器中,-m128bit-long-double是默认选择,因为其ABI指定long double在16字节边界上对齐。

Notice that neither of these options enable any extra precision over the x87 standard of 80 bits for a long double. 请注意,对于长双精度,这两个选项均未对80位的x87标准启用任何额外的精度。

Warning: if you override the default value for your target ABI, this changes the size of structures and arrays containing long double variables, as well as modifying the function calling convention for functions taking long double. 警告:如果您覆盖目标ABI的默认值,则这将更改包含长双精度变量的结构和数组的大小,并修改采用长双精度的函数的函数调用约定。 Hence they are not binary-compatible with code compiled without that switch. 因此,它们与没有该开关的编译代码不二进制兼容。

-mlong-double-64 -mlong-double-64

-mlong-double-80 -mlong-double-80

-mlong-double-128 -mlong-double-128

These switches control the size of long double type. 这些开关控制long double类型的大小。 A size of 64 bits makes the long double type equivalent to the double type. 64位的大小使long double类型等效于double类型。 This is the default for 32-bit Bionic C library. 这是32位Bionic C库的默认设置。 A size of 128 bits makes the long double type equivalent to the __float128 type. 128位的大小使long double类型等效于__float128类型。 This is the default for 64-bit Bionic C library. 这是64位Bionic C库的默认设置。

Warning: if you override the default value for your target ABI, this changes the size of structures and arrays containing long double variables, as well as modifying the function calling convention for functions taking long double. 警告:如果您覆盖目标ABI的默认值,则这将更改包含长双精度变量的结构和数组的大小,并修改采用长双精度的函数的函数调用约定。 Hence they are not binary-compatible with code compiled without that switch. 因此,它们与没有该开关的编译代码不二进制兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM