Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

c - What does GCC __attribute__((mode(XX)) actually do?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 essentially sizeof(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 essentially sizeof(char) * 16 (128 bits).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...