2014-10-02 61 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