1
typedef float v4sf __attribute__ ((mode(V4SF)));

这是在 GCC 中。有人知道等价语法吗?

VS 2010 会显示__attribute__没有这种类型的存储类,并且没有定义模式。

我在网上搜索,它说

相当于__attribute__( aligned( size ) )在 GCC

这对于以前的 unix 开发人员或编写可在多个平台上工作的代码的人很有帮助,在 GCC 中您可以使用 属性(aligned(...))获得相同的结果

有关更多信息,请参见此处:http: //gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Type-Attributes.html#Type-Attributes

完整的 GCC 代码在这里: http: //pastebin.com/bKkTTmH1

4

2 回答 2

5

如果你正在寻找 VC++ 中的对齐指令,它是__declspec(align(16)). (或任何你想要的对齐方式)

示例用法是这样的:

__declspec(align(16)) float x[] = {1.,2.,3.,4.};

http://msdn.microsoft.com/en-us/library/83ythb65.aspx

请注意,attribute(在 GCC 中)和__declspec(在 VC++ 中)都是特定于编译器的扩展。

编辑 :

现在我再看一下代码,这将需要更多的工作,而不仅仅是用__attribute__VC++ 等价物替换该行以使其在 VC++ 中编译。

如果您正在使用这些宏/函数,则 VC++ 没有:

  • __builtin_ia32_xorps
  • __builtin_ia32_loadups
  • __builtin_ia32_mulps
  • __builtin_ia32_addps
  • __builtin_ia32_storeups

你最好用SSE 内在函数替换所有这些——这将适用于 GCC 和 VC++。


这是转换为内在函数的代码:

float *mv_mult(float mat[SIZE][SIZE], float vec[SIZE]) {
    static float ret[SIZE];
    float temp[4];
    int i, j;
    __m128 m, v, r;

    for (i = 0; i < SIZE; i++) {
        r = _mm_xor_ps(r, r);

        for (j = 0; j < SIZE; j += 4) {
            m = _mm_loadu_ps(&mat[i][j]);
            v = _mm_loadu_ps(&vec[j]);
            v = _mm_mul_ps(m, v);
            r = _mm_add_ps(r, v);
        }

        _mm_storeu_ps(temp, r);
        ret[i] = temp[0] + temp[1] + temp[2] + temp[3];
    }

    return ret;
}
于 2011-11-28T00:11:12.067 回答