2016-12-02 92 views
0

我在下面的源彙編有奇怪的錯誤:錯誤:ALIGN'未聲明(在此函數首先使用)與ALIGN定義爲宏

#include <stdio.h> 
#include <stdlib.h> 
#include <mach/mach_time.h> 
#include <mm_malloc.h> 

#ifdef SSE 
#include <x86intrin.h> 
#define ALIGN 16 
void addition_tab(int size, double *a, double *b, double *c) 
{ 

int i; 
// Main loop 
for (i=size-1; i>=0; i-=2) 
{ 
    // Intrinsic SSE syntax 
    const __m128d x = _mm_loadu_pd(a); // Load two x elements 
    const __m128d y = _mm_loadu_pd(b); // Load two y elements 
    const __m128d sum = _mm_add_pd(x, y); // Compute two sum elements 
    _mm_storeu_pd(c, sum); // Store two sum elements 

    // Increment pointers by 2 since SSE vectorizes on 128 bits = 16 bytes = 2*sizeof(double) 
    a += 2; 
    b += 2; 
    c += 2; 
} 

} 
#endif 

int main(int argc, char *argv[]) 
{ 
    // Array index 
    int i; 

    // Array size as argument 
    int size = atoi(argv[1]); 

    // Time elapsed 
    uint64_t t1, t2; 
    float duration; 

    // Two input arrays 
    double *tab_x; 
    double *tab_y; 
    double *tab_z; 

    // Get the timebase info 
    mach_timebase_info_data_t info; 
    mach_timebase_info(&info); 

#ifdef NOVEC 
    // Allocation 
    tab_x = (double*) malloc(size*sizeof(double)); 
    tab_y = (double*) malloc(size*sizeof(double)); 
    tab_z = (double*) malloc(size*sizeof(double)); 
#else 
    // Allocation 
    tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
    tab_y = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
    tab_z = (double*) _mm_malloc(size*sizeof(double),ALIGN); 
#endif 
} 

如果我編譯:

gcc-mp-4.9 -DNOVEC -O0 main.c -o exe 

編譯完成,但有:

gcc-mp-4.9 -DSSE -O3 -msse main.c -o exe 

我得到以下錯誤:

main.c: In function 'main': 
main.c:96:52: error: 'ALIGN' undeclared (first use in this function) 
    tab_x = (double*) _mm_malloc(size*sizeof(double),ALIGN); 

然而,可變ALIGN如果我通過SSE宏與gcc-mp-4.9 -DSSE被定義,是嗎?

感謝您的幫助

+1

是:'-DSSE'定義'SSE'爲precomplier。你確定這個錯誤嗎?這是你的真實代碼嗎?發佈的代碼似乎很好。 – LPs

+0

首先看看我能看到的是'ALIGN'也用於'#編譯AVX256'的情況,但是用那個宏'ALIGN'沒有定義。 – LPs

+0

不過,我已經到main.c中:#ifdef來AVX256 的#include 的#define ALIGN 32 – youpilat13

回答

0

我發現根本原因到腳本:你不分離NOVEC所以用NOVEC宏彙編總是完成。你可以使用其隔離:

if [ "$1" == "novec" ]; then 
# Compile no vectorized and vectorized executables 
$GCC -DNOVEC -O0 main_benchmark.c -o noVectorizedExe 
$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s 
elif [ "$1" == "sse" ]; then 
# Compile with SSE 
$GCC -DSSE -O3 -msse main_benchmark.c -o vectorizedExe 
$GCC -DSSE -O3 -msse main_benchmark.c -S -o vectorizedExe.s 
echo "Test" 
elif [ "$1" == "avx" ]; then 
# Compile with AVX256 
$GCC -DAVX256 -O3 -mavx main_benchmark.c -o vectorizedExe 
$GCC -DAVX256 -O3 -mavx main_benchmark.c -S -o vectorizedExe.s 
fi 

編輯

我發現了它,你有一個錯字!

$GCC -DNOVEV -O0 main_benchmark.c -S -o noVectorizedExe.s 

應該

$GCC -DNOVEC -O0 main_benchmark.c -S -o noVectorizedExe.s 
+0

系統的「NOVEC」編譯想要的,我總想一個沒有量化的版本(noVectorizedExe可執行文件)當我執行這個腳本。你能解釋爲什麼這會是一個問題嗎? – youpilat13

+0

@ youpilat13找到了!看看我的編輯。 ;) – LPs

+0

非常感謝!問候 – youpilat13

相關問題