2012-06-13 41 views
1

我試圖使用SSE指令在Windows窗體應用程序在VS 2010和功能,我使用sum_array功能在我的應用程序在以下鏈接 SSE instructions to add all elements of an array錯誤C3645:__clrcall不能編譯爲本地代碼

給出使用

但是當我編譯應用程序它給了以下錯誤

error C3645: 'plot_rectangle::Form1::sum_array' : __clrcall cannot be used on functions compiled to native code 

由於我也使用OpenCV的在我的應用程序功能,所以我不得不選擇FO/CLR編譯器選項那個。

那麼當我們在OpenCV中使用SSE時,該錯誤的解決方案是什麼。

我也試圖在編譯像

之間

#pragma managed(push, off) 
uint32_t sum_array(const uint8_t a[], int n) 
{ 
    const __m128i vk0 = _mm_set1_epi8(0);  // constant vector of all 0s for use with _mm_unpacklo_epi8/_mm_unpackhi_epi8 
    const __m128i vk1 = _mm_set1_epi16(1);  // constant vector of all 1s for use with _mm_madd_epi16 
    __m128i vsum = _mm_set1_epi32(0);   // initialise vector of four partial 32 bit sums 
    uint32_t sum; 
    int i; 

    for (i = 0; i < n; i += 16) 
    { 
     __m128i v = _mm_load_si128((const __m128i *)&a[i]);  // load vector of 8 bit values 
     __m128i vl = _mm_unpacklo_epi8(v, vk0); // unpack to two vectors of 16 bit values 
     __m128i vh = _mm_unpackhi_epi8(v, vk0); 
     vsum = _mm_add_epi32(vsum, _mm_madd_epi16(vl, vk1)); 
     vsum = _mm_add_epi32(vsum, _mm_madd_epi16(vh, vk1)); 
               // unpack and accumulate 16 bit values to 
               // 32 bit partial sum vector 

    } 
    // horizontal add of four 32 bit partial sums and return result 
    vsum = _mm_add_epi32(vsum, _mm_srli_si128(vsum, 8)); 
    vsum = _mm_add_epi32(vsum, _mm_srli_si128(vsum, 4)); 
    sum = _mm_cvtsi128_si32(vsum); 
    return sum; 
} 
#pragma managed(pop) 
但是,讓同樣的錯誤SSE指令。

任何機構請幫我解決這個問題。

回答

3

您不能在編譯爲IL的代碼中使用內聯彙編或SSE內在函數。解決方法很簡單,把它寫在你使用#pragma括管理,這樣一個獨立的輔助函數:

#pragma managed(push, off) 
void func foo(args...) 
{ 
    // It's fine here 
    //... 
} 
#pragma managed(pop) 

並調用它從你的Form1中:: sum_array()方法。

+0

感謝您的回覆。我也通過SSE代碼在雜注之間嘗試過。我也粘貼了代碼,因爲我正在做。但得到同樣的錯誤。 – geeta

+0

當我在#including正確的標題後嘗試它時編譯得很好。正如它應該。你不能得到同樣的錯誤,你肯定會得到一個不同的錯誤。 –

+0

感謝您的回覆。你是對的,它也顯示與編譯指示相關的錯誤來聲明命名空間中的編譯指示。所以現在它正在工作。 – geeta