2011-03-15 117 views
0

在我的項目中,我需要確定CPU支持的SIMD指令集。問題是,當我嘗試做一個測試編譯時,我得到了一系列重複多次的錯誤,比如編譯器多次解析代碼。確定支持SIMD指令的原因是因爲我試圖將Windows開發人員的DES bitslice實現適用於GPGPU(特別是CUDA),以適用於Windows & Linux。編譯時重複語法錯誤

所以,這裏的地方就行出現我的錯誤37

// File Name: Arch.h 
// Purpose: Determine CPU architecture (x86 or x86-64) and to determine instruction set supported by 
//   the CPU (MMX, SSE2 or neither) 
// 
// Authors: Daniel Beard and Michael Campbell 

//If CPU is x86-64 then use x86-64 include 
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) 
#include "x86-64.h" 
#endif 

//Determine if CPU architecture is 32-bit, then determine which compiler is being used, finally determine if GCC (GNUC) or MS Visual C++ compiler is being used 
#if defined(i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86) 
    #if defined(__GNUC__) 
    #define cpuid(func,ax,bx,cx,dx)\ 
     __asm__ __volatile__ ("cpuid":\ 
     "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func)); 
    int a,b,c,d; 
    cpuid(0x1,a,b,c,d); 
    if ((d & 0x17)== 1) 
    { 
     #include "x86-mmx.h" 
    } 
    else if (d & 0x1A) == 1) 
    { 
     #include "x86-sse.h" 
    } 
    else if((d & 0x17) != 1 || (d & 0x1A) != 1) 
    { 
     #include "x86-any.h" 
    } 
    #endif 

    #if defined(_MSC_VER) 
     #include<intrin.h> 
     int CPUInfo[4] = {0}; 
     __cpuid(CPUInfo, 1); 
     if((CPUInfo[3] & 0x1A) == 1) 
     { 
      #include "x86-sse.h" 
     } 
     else if((CPUInfo[3] & 0x17) == 1) 
     { 
      #include "x86-mmx.h" 
     } 
     else if((CPUInfo[3] & 0x17) != 1 || (CPUInfo[3] & 0x1A) != 1) 
     { 
      #include "x86-any.h" 
     } 
    #endif 
#endif 

這裏是我得到的錯誤(還有他們的86,但他們重複相同的一系列錯誤/行號一路下行):

Error 1 error C2059: syntax error : ','     line 37 
Error 2 error C2143: syntax error : missing ')' before 'constant'  line 37 
Error 3 error C2143: syntax error : missing '{' before 'constant'  line 37 
Error 4 error C2059: syntax error : '<Unknown>'    line 37 
Error 5 error C2059: syntax error : ')'     line 37 
Error 6 error C2059: syntax error : 'if'     line 38 
Error 7 error C2059: syntax error : 'else'     line 42 
Error 8 error C2059: syntax error : 'else'     line 46 
Error 9 error C2374: 'CPUInfo' : redefinition; multiple initialization  line 36 
+2

你不能像正常一樣#包含這個文件,它需要包含在函數內才能正確編譯。不知道該功能應該看起來像當然,找到一個示例用法,如果這個頭。 – 2011-03-15 20:01:57

+1

編譯器通常會在第一個錯誤後嘗試繼續,因爲它們可能能夠在代碼中找到多個問題。問題在於C++很難解析,而且很多時候,第一個錯誤使編譯器混淆不清,導致錯誤地解釋代碼的其餘部分,並拋出許多不同的錯誤。試着修復第一個問題,看看其餘的問題是否會消失(或者至少你得到了一些更好的診斷) – 2011-03-15 20:02:12

回答

1

第一錯誤是在第36行 - 聲稱一個CPUInfo已經存在 - 修正了第一和休息可自行消失。

在Visual Studio中的選項,進入「項目和解決方案」,「一般」,並取消選中「始終顯示錯誤列表......」

這將離開你與輸出窗口 - 您可以使用F8鍵導航到您通常應該關心的第一個警告/錯誤。

+0

那麼,這樣就消除了多個初始化錯誤,但前8個仍然存在。 – Trigulus 2011-03-15 19:57:22

+0

@Trigulus:顯示完整的代碼 - 包含此文件的內容是什麼? – Erik 2011-03-15 19:59:52

+0

有14個文件包含arch.h; x86.Sse.S,x86-sse.h,x86-mmx.S,x86-mmx.h,x86-any.h,x86-64.S,x86-64.h,memory.h, DES_std.h,DES_bs.h,DES_bs.c和common.h 對於Hans:這個arch.h是一個自定義的arch.h.它應該由gcc或make生成(我從來沒有想出哪個)。 其中的一些文件我對他們的工作有了一些瞭解,比如我認爲確定體系結構大小的arch文件。我不確定爲什麼包括記憶和共同點。 DES_std.h包含在DES_bs.c中 – Trigulus 2011-03-15 20:47:46