什么是GCC __attribute __((模式(XX))实际上呢? [英] What does GCC __attribute__((mode(XX)) actually do?
问题描述
这从一个问题,今天早些时候出现在BIGNUM库和gcc黑客特定的主题,以C语言。具体而言,使用这两个声明:
的typedef unsigned int类型dword_t __attribute __((模式(DI)));
在32位系统以及
的typedef unsigned int类型dword_t __attribute __((模式(TI)));
在64位系统上。
我想给这是一个扩展的C语言不存在任何方式来实现不管它实现了在电流(C99)的标准。所以我的问题很简单:就是假设是正确的?而做这些语句做底层的内存?我认为结果是我有 2xsizeof(uint32_t的)
为 DWORD
在32位系统和 2 * sizeof的(uint64_t中)
64位系统,我是正确的?
这允许你显式地指定一个大小为一类,而不依赖于编译器或机器的语义,如长或INT。<大小/ p>
他们被描述在这个页面相当好。
我从该网页引述如下:
齐:一个整数,是一样宽的
最小可寻址单元,通常是8
位。
HI:一个整数,两倍宽
具有益气模式整数,通常是16位。
SI:一个整数,四倍宽为QI
模式整数,通常为32位。
DI:一个
整,八倍宽为QI
模式整数,通常是64位。
SF:一
浮点值,宽为SI
模式整数,通常为32位。
DF:一
浮点值,宽为DI
模式整数,通常是64位。
块引用>所以
DI
本质上是的sizeof(字符)* 8
。进一步说明,包括
TI
模式下,可以发现的此处(可能比第一个环节更好,但两者供参考)。所以
TI
本质上是的sizeof(char)的* 16
(128位)。This arose from a question earlier today on the subject of bignum libraries and gcc specific hacks to the C language. Specifically, these two declarations were used:
typedef unsigned int dword_t __attribute__((mode(DI)));
On 32 bit systems and
typedef unsigned int dword_t __attribute__((mode(TI)));
On 64-bit systems.
I assume given this is an extension to the C language that there exists no way to achieve whatever it achieves in current (C99) standards. So my questions are simple: is that assumption correct? And what do these statements do to the underlying memory? I think the result is I have
2xsizeof(uint32_t)
for adword
in 32-bit systems and2*sizeof(uint64_t)
for 64-bit systems, am I correct?解决方案These allow you to explicitly specify a size for a type without depending on compiler or machine semantics, such as the size of 'long' or 'int'.
They are described fairly well on this page.
I quote from that page:
QI: An integer that is as wide as the smallest addressable unit, usually 8 bits.
HI: An integer, twice as wide as a QI mode integer, usually 16 bits.
SI: An integer, four times as wide as a QI mode integer, usually 32 bits.
DI: An integer, eight times as wide as a QI mode integer, usually 64 bits.
SF: A floating point value, as wide as a SI mode integer, usually 32 bits.
DF: A floating point value, as wide as a DI mode integer, usually 64 bits.
So
DI
is essentiallysizeof(char) * 8
.Further explanation, including
TI
mode, can be found here (possibly better than the first link, but both provided for reference).So
TI
is essentiallysizeof(char) * 16
(128 bits).这篇关于什么是GCC __attribute __((模式(XX))实际上呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!