0

代码块来自 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\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.

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

4

1 回答 1

0

我怀疑这是因为变量“i”位于“if”语句的范围内。因此,它并不完全属于“for-loop”范围,就像它本来在

for(int i = 0; /* etc. */ 在这种情况下,编译器的逻辑应该是这样的:“我不仅需要使用所需的值进行 gammatable 填充,还需要为“i”分配与循环结束时相同的值"。因此,没有向量化。

于 2014-10-02T08:30:34.747 回答