GCC __attribute__((mode(XX)) 实际上做了什么? [英] What does GCC __attribute__((mode(XX)) actually do?

查看:21
本文介绍了GCC __attribute__((mode(XX)) 实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这源于今天早些时候关于 bignum 库和 gcc 特定于 C 语言的 hacks 的问题.具体来说,使用了这两个声明:

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)));

在 32 位系统上和

typedef unsigned int dword_t __attribute__((mode(TI)));

在 64 位系统上.

我假设这是对 C 语言的扩展,因此无法实现它在当前 (C99) 标准中实现的任何目标.

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.

所以我的问题很简单:这个假设是否正确?这些语句对底层内存有什么作用?我认为结果是我有 2*sizeof(uint32_t) 用于 32 位系统中的 dword2*sizeof(uint64_t)64 位系统,我说的对吗?

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 2*sizeof(uint32_t) for a dword in 32-bit systems and 2*sizeof(uint64_t) for 64-bit systems, am I correct?

推荐答案

这些允许您显式指定类型的大小,而不依赖于编译器或机器语义,例如long"或int"的大小.

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.

我从那个页面引用:

QI:一个与最小的可寻址单元,通常为 8位.

QI: An integer that is as wide as the smallest addressable unit, usually 8 bits.

HI: 一个整数,宽两倍一个 QI 模式整数,通常为 16 位.

HI: An integer, twice as wide as a QI mode integer, usually 16 bits.

SI:一个整数,宽度是 QI 的四倍模式整数,通常为 32 位.

SI: An integer, four times as wide as a QI mode integer, usually 32 bits.

DI:一个整数,宽度是 QI 的八倍模式整数,通常为 64 位.

DI: An integer, eight times as wide as a QI mode integer, usually 64 bits.

SF:A浮点值,与 SI 一样宽模式整数,通常为 32 位.

SF: A floating point value, as wide as a SI mode integer, usually 32 bits.

DF:A浮点值,与 DI 一样宽模式整数,通常为 64 位.

DF: A floating point value, as wide as a DI mode integer, usually 64 bits.

所以 DI 本质上是 sizeof(char) * 8.

进一步的解释,包括TI模式,可以看这里(可能比第一个链接更好,但都提供参考).

Further explanation, including TI mode, can be found here (possibly better than the first link, but both provided for reference).

所以 TI 本质上是 sizeof(char) * 16(128 位).

So TI is essentially sizeof(char) * 16 (128 bits).

这篇关于GCC __attribute__((mode(XX)) 实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆