2014-10-02 66 views
0

Autovectorized代碼塊是從Mozilla Firefox瀏覽器的QCMS transform_util.c爲什麼代碼塊不被VC2013

void build_output_lut(struct curveType *trc, 
       uint16_t **output_gamma_lut, size_t *output_gamma_lut_length) 
{ 
     if (trc->type == PARAMETRIC_CURVE_TYPE) { 
       float gamma_table[256]; 
       uint16_t i; 
       uint16_t *output = malloc(sizeof(uint16_t)*256); 

       if (!output) { 
         *output_gamma_lut = NULL; 
         return; 
       } 

       compute_curve_gamma_table_type_parametric(gamma_table, trc->parameter, trc->count); 
       *output_gamma_lut_length = 256; 
       for(i = 0; i < 256; i++) { 
         output[i] = (uint16_t)(gamma_table[i] * 65535); 
       } 
       *output_gamma_lut = output; 
     } else { 
       if (trc->count == 0) { 
         *output_gamma_lut = build_linear_table(4096); 
         *output_gamma_lut_length = 4096; 
       } else if (trc->count == 1) { 
         float gamma = 1./u8Fixed8Number_to_float(trc->data[0]); 
         *output_gamma_lut = build_pow_table(gamma, 4096); 
         *output_gamma_lut_length = 4096; 
       } else { 
         //XXX: the choice of a minimum of 256 here is not backed by any theory, 
         //  measurement or data, however it is what lcms uses. 
         *output_gamma_lut_length = trc->count; 
         if (*output_gamma_lut_length < 256) 
           *output_gamma_lut_length = 256; 

         *output_gamma_lut = invert_lut(trc->data, trc->count, *output_gamma_lut_length); 
       } 
     } 

} 

這個循環:

  for(i = 0; i < 256; i++) { 
        output[i] = (uint16_t)(gamma_table[i] * 65535); 
      } 

VC2013會顯示:

e:\ mozilla \ hg \ nightly \ mozilla-central \ gfx \ qcms \ transform_util.c(490):info C5002:由於「500」,循環未向量化

MSDN(http://msdn.microsoft.com/en-us/library/jj658585.aspx)表示:

// Code 500 is emitted if the loop has non-vectorizable flow. 
// This can include "if", "break", "continue", the conditional 
// operator "?", or function calls. 
// It also encompasses correct definition and use of the induction 
// variable "i", in that the increment "++i" or "i++" must be the last 
// statement in the loop. 

但上面的循環有沒有,如果/休息/繼續,我不知道爲什麼它不能被量化。

回答

0

我懷疑這是由於變量「我」位於「if」語句的範圍。因此它不完全屬於「for循環」範圍像它會一直在

的for(int i = 0;/*等*/ 在這樣的,編譯器的邏輯會像: 「我不僅需要製作具有所需值的可修正填充的填充,而且要將相同的值賦給」i「,因爲沒有向量化。因此,沒有矢量化。

+0

我嘗試將uint16_t置於if語句之外,但也會產生警告,我不明白你的最後一部分的意思 – xunxun 2014-10-03 00:51:46

+0

好的,簡言之:恕我直言是矢量化的,變量「i」必須在MSDN例子中的for循環內部聲明,最後部分的意思是: MSDN示例:填充具有值的變量,變量「i」具有for循環範圍 - >無法訪問,可以在過程中刪除。 你的代碼:使用值填充數組,變量「i」具有「if」scope - >可訪問超越+必須具有值,好像for循環實際發生 - >不能向量化 – HighPredator 2014-10-03 06:35:39

+0

感謝您的解釋。我明白。 – xunxun 2014-10-04 15:45:30