c-为什么代码块没有被VC2013自动矢量化



代码块来自mozilla firefox的qcms transform_util.c

    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\niniverse\mozilla-central\gfx\qcms\transform_util.c(490):信息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.

但是上面的循环没有if/break/continue,我不知道为什么它不能被矢量化。

我怀疑这是由于变量"I"位于"if"-语句的范围内。因此,它不像那样完全属于"for loop"范围

for(int i=0;/*等)*/在这种情况下,编译器的逻辑会是这样的:"我不仅需要用所需的值制作可游戏化的填充,还需要在循环结束时为"I"分配相同的值"。因此,没有矢量化。

最新更新