代码块来自mozilla firefox&#39s 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,我不知道为什么它不能被矢量化。
答案 0 :(得分:0)
我怀疑这是因为变量“i”位于“if”-statement的范围内。因此,它不完全属于“for-loop”范围,就像在
中一样for(int i = 0; / * etc. * / 在这种情况下,编译器的逻辑就像是:“我不仅需要制作具有所需值的gammatable filles,而且要将相同的值分配给”i“和”循环结束“。因此,没有矢量化。