如何在gcc中编译内部代码

时间:2016-06-16 18:45:43

标签: linux gcc

我正在尝试编译此代码:

#include <sys/types.h>
#include <argp.h>
#include <stdlib.h>
#include <xmmintrin.h>

__attribute__((noinline)) void vadd(float *a, float *b, size_t size)
{
    size_t i;
    for (i=0; i<size; i+=4)
    {
        __m128 v1 = _mm_load_ps(a + i);  //loads up 4 floats into a __m128
        __m128 v2 = _mm_load_ps(b + i);  //loads up 4 floats into a __m128
        __m128 v3 = _mm_add_ps(v1, v2);
        _mm_store_ps(a+i, v3);
    }
}

__attribute__((noinline)) void sadd(float *a, float *b, size_t size)
{
    size_t i;
    for(i=0; i<size; i++)
    {
        a[i] += b[i];
    }
}

int main (void)
{
    size_t size = 300000000;
    float *a = (float *)calloc(size, sizeof(float));
    float *b = (float *)calloc(size, sizeof(float));

    vadd(a, b, size);
    sadd(a, b, size);
}

我收到此错误:

/usr/lib/gcc/i486-linux-gnu/4.8/include/mmintrin.h: In function   ‘_mm_cvtsi32_si64’:
/usr/lib/gcc/i486-linux-gnu/4.8/include/mmintrin.h:61:3: error: can’t convert between vector values of different size
return (__m64) __builtin_ia32_vec_init_v2si (__i, 0);

有没有办法解决这个问题?

0 个答案:

没有答案