__attribute__((mode(TI))) (128位)

On some targets, the instruction set contains SIMD vector instructions that operate on multiple values contained in one large register at the same time. For example, on the i386 the MMX, 3Dnow! and SSE extensions can be used this way.

The first step in using these extensions is to provide the necessary data types. This should be done using an appropriate typedef:

typedef int v4si attribute ((mode(V4SI)));

The base type int is effectively ignored by the compiler, the actual properties of the new type v4si are defined by the attribute. It defines the machine mode to be used; for vector types these have the form VnB; n should be the number of elements in the vector, and B should be the base mode of the individual elements. The following can be used as base modes:

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.
Not all base types or combinations are always valid; which modes can be used is determined by the target machine. For example, if targetting the i386 MMX extensions, only V8QI, V4HI and V2SI are allowed modes.

There are no V1xx vector modes - they would be identical to the corresponding base mode.

There is no distinction between signed and unsigned vector modes. This distinction is made by the operations that perform on the vectors, not by the data type.

The types defined in this manner are somewhat special, they cannot be used with most normal C operations (i.e., a vector addition can not be represented by a normal addition of two vector type variables). You can declare only variables and use them in function calls and returns, as well as in assignments and some casts. It is possible to cast from one vector type to another, provided they are of the same size (in fact, you can also cast vectors to and from other datatypes of the same size).

A port that supports vector operations provides a set of built-in functions that can be used to operate on vectors. For example, a function to add two vectors and multiply the result by a third could look like this:

v4si f (v4si a, v4si b, v4si c)
{
v4si tmp = __builtin_addv4si (a, b);
return __builtin_mulv4si (tmp, c);
}

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

like GCC promised that “long long” is twice as long as “long”, and broke the promise when they ported GCC to the first 64 bit architecture (MIPS). Now, if you are lucky, you can use typedef int int128_t attribute((mode(TI))); to create a real 128 bit type on some 64 bit platforms.

用法:

typedef int int128  __attribute__((mode(TI)));
long long n;
int128(n)...
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值