gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:28:04 25 4
gpt4 key购买 nike

代码块来自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,我不知道为什么它不能向量化。

最佳答案

我怀疑这是因为变量“i”位于“if”语句的范围内。因此,它并不像

那样完全属于“for-loop”范围

for(int i = 0; /* etc. */ At such, the compiler's logic would have been like: "I need not only to make gammatable filles with needed values, but to assign same value to "i" as at loop end". Therefore, no vectorization.

关于c - 为什么代码块没有被VC2013自动矢量化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26156747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com