c - 如何定义 80 位大小的变量

标签 c gcc assembly nasm

我需要在 gcc 编译的 C 程序中声明一个 80 位大小的变量(我需要它来将数据传递给工作在 fpu 上的 asm 过程,它被这个用 C 编写的程序调用)
我的架构是 AMD x64
我尝试了 long double__float80,但对于它们,sizeof 返回 12 而不是 10。 那么如何声明这样的变量呢?

最佳答案

该大小包括用于对齐的填充,但它仍然是一个 80 位值。 manual说:

-m96bit-long-double

-m128bit-long-double

These switches control the size of long double type. The x86-32 application binary interface specifies the size to be 96 bits, so -m96bit-long-double is the default in 32-bit mode.

Modern architectures (Pentium and newer) prefer long double to be aligned to an 8- or 16-byte boundary. In arrays or structures conforming to the ABI, this is not possible. So specifying -m128bit-long-double aligns long double to a 16-byte boundary by padding the long double with an additional 32-bit zero.

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.

Notice that neither of these options enable any extra precision over the x87 standard of 80 bits for a long double.

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. Hence they are not binary-compatible with code compiled without that switch.

-mlong-double-64

-mlong-double-80

-mlong-double-128

These switches control the size of long double type. A size of 64 bits makes the long double type equivalent to the double type. This is the default for 32-bit Bionic C library. A size of 128 bits makes the long double type equivalent to the __float128 type. This is the default for 64-bit Bionic C library.

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. Hence they are not binary-compatible with code compiled without that switch.

关于c - 如何定义 80 位大小的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730626/

相关文章:

C 在函数中初始化一个字符数组,或者我应该将它作为参数传递

c - 如何解析 C 中的整数命令行参数?

c - 如何在C中使用open mp同时执行两个不同的函数

C 头文件问题 : #include and "undefined reference"

c++ - LD_PRELOAD 未按预期工作

c++ - 为什么在使用局部变量时这个带有 mov 算术的有效程序集不能编译?

c - 使用 C 打开目录

c++ - 如何强制将常量 C 表达式求值用作 .S 文件中的常量?

assembly - 为什么除了 GOT 之外还有 PLT,而不是仅仅使用 GOT?

windows - 实现 x86 到 x64 汇编代码切换