2013-07-09 42 views
0

我學習使用內在函數而不是asm內聯。昨天,他們在工作,但我今天總是遇到錯誤。什麼也沒變。C++固有的未聲明

#include <iostream> 
#include <intrin.h> // immintrin.h, smmintrin.h ... tried all, never worked 

using namespace std; 

    int main() 
    { 
     _m256_zeroupper(); // __mm256_zeroupper(); does not work too 
     _mm128 x; // __mm128 x; does not work too 
     _mm256 y; // __mm256 y; does not work too 
     _m256_zeroupper(); // __mm256_zeroupper(); does not work too 
     cout << "Hello world!" << endl; 
     return 0; 
    } 

以下是錯誤。我嘗試了所有不同的內在頭文件,但錯誤是一樣的。還重新安裝了gcc,但沒有奏效。

我在哪裏錯了?我需要添加什麼來實際聲明這些內部變量和函數?

C:\indirmeDenemesi\hello_intrin\main.cpp||In function 'int main()':| 
C:\indirmeDenemesi\hello_intrin\main.cpp|8|error: '_mm256_zeroupper' was not declared in this scope| 
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: '_mm128' was not declared in this scope| 
C:\indirmeDenemesi\hello_intrin\main.cpp|9|error: expected ';' before 'x'| 
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: '_mm256' was not declared in this scope| 
C:\indirmeDenemesi\hello_intrin\main.cpp|10|error: expected ';' before 'y'| 
||=== Build finished: 5 errors, 0 warnings (0 minutes, 0 seconds) ===| 

在具有64位窗口的64位cpu上使用64位最新版本的gcc。 CPU是FX8150。 Tried -march = bdver1 -mtune = bdver1它產生了數百個垃圾錯誤。

所有這些意味着我的CPU是否正在死亡?

編輯:一些其他項目正在工作,但我沒有改變任何東西。這必須是項目特定的事情。 使用code :: blocks,當我右鍵單擊一個頭並選擇「open」時,它會給出錯誤「找不到」,但是在編譯相關的時候不會給出任何錯誤,只是intrinsinc命令的錯誤。工作項目也是如此(它們編譯所有內容並工作,但在右鍵單擊並打開時沒有找到頭文件)。也許其他一些Windows服務正在干擾?我不知道,但編譯器錯誤正在消失,並不時再來。重新安裝代碼塊也沒有解決。只有一些項目可以使用內在函數,而其他項目不能(即使所有項目具有相同的標題)。

以下代碼不起作用。

#include <iostream> 
#include <immintrin.h> 
using namespace std; 

int main() 
{ 
    _m256_zeroupper(); 

    __mm128 x; 

    __mm256 y; 

    _m256_zeroupper(); 
    cout << "Hello world!" << endl; 
    return 0; 
} 
+0

什麼編譯選項您使用,包括?你有沒有啓用正確的處理器類型? –

+0

請記住,編譯器內在函數非常適合編譯器。查看[在線文檔](http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Target-Builtins.html#Target-Builtins),瞭解其目標在GCC中可用的功能。 –

+0

FX-8150 Tried -march = bdver1 -mtune = bdver1它產生了數百個垃圾錯誤。 –

回答

5

三件事應該讓你的代碼工作:

  1. 確保您使用的-mavx編譯標誌。

  2. 您的變量應聲明爲__m256而不是_mm256

  3. 確保您immintrin.h

+0

或更好,'-march = native'或'-march = haswell',而不只是'-mavx'。另請參閱https://stackoverflow.com/questions/38662287/issue-with-m256-type-of-intel-intrinsics回覆:gcc的'tune = generic'將未對齊的256b加載/存儲分割爲'movdqu' /'vinsertf128'。或者使用'-mavx -mno-avx256-split-unaligned-load -mno-avx256-split-unaligned-store',除非你實際調整了SnB,並且你的數據實際上大部分時間都是未調整的。 –