What is the equivalent of v4sf and __attribute__ in Visual Studio C++?

泪湿孤枕 提交于 2020-01-12 10:47:02

问题


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

This is in GCC. Anyone knows the equivalence syntax?

VS 2010 will show __attribute__ has no storage class of this type, and mode is not defined.

I searched on the Internet and it said

Equivalent to __attribute__( aligned( size ) ) in GCC

It is helpful for former unix developers or people writing code that works on multiple platforms that in GCC you achieve the same results using attribute( aligned( ... ) )

See here for more information: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Type-Attributes.html#Type-Attributes

The full GCC code is here: http://pastebin.com/bKkTTmH1


回答1:


If you're looking for the alignment directive in VC++ it's __declspec(align(16)). (or whatever you want the alignment to be)

And example usage is this:

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

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

Note that both attribute (in GCC) and __declspec (in VC++) are compiler-specific extensions.

EDIT :

Now that I take a second look at the code, it's gonna take more work than just replacing the __attribute__ line with the VC++ equivalent to get it to compile in VC++.

VC++ doesn't have any if these macros/functions that you are using:

  • __builtin_ia32_xorps
  • __builtin_ia32_loadups
  • __builtin_ia32_mulps
  • __builtin_ia32_addps
  • __builtin_ia32_storeups

You're better off just replacing all of those with SSE intrinsics - which will work on both GCC and VC++.


Here's the code converted to intrinsics:

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



回答2:


V4SF and friends have to do with GCC "vector extensions":

http://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Vector-Extensions.html#Vector%20Extensions

http://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/X86-Built-in-Functions.html

I'm not sure how much - if any of this stuff - is supported in MSVS/MSVC. Here are a few links:

http://www.codeproject.com/KB/recipes/sseintro.aspx?msg=643444

http://msdn.microsoft.com/en-us/library/y0dh78ez%28v=vs.80%29.aspx

http://msdn.microsoft.com/en-us/library/01fth20w.aspx



来源:https://stackoverflow.com/questions/8290177/what-is-the-equivalent-of-v4sf-and-attribute-in-visual-studio-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!