Commit 4c81fbf1 authored by Wim Taymans's avatar Wim Taymans

program: only reuse constants of the same size and value

When reusing an existing constant, make sure not only the value but also
the size is the same. We then also need to make a name based on the size
and value so that we can store the same value for different sizes.

Fixes problem with the bayer functions that used 255 as a 16 and 8 bit
constant. This was not detected in the unit test because both the backup
and asm functions do the same error, but it could be seen when a new
backup function was checked against a older ORC.
parent 8f648754
......@@ -565,7 +565,7 @@ orc_compiler_rewrite_insns (OrcCompiler *compiler)
if (var->vartype == ORC_VAR_TYPE_SRC ||
var->vartype == ORC_VAR_TYPE_DEST) {
OrcInstruction *cinsn;
cinsn = compiler->insns + compiler->n_insns;
compiler->n_insns++;
......
......@@ -307,13 +307,22 @@ orc_parse_full (const char *code, OrcProgram ***programs, char **log)
for(i=offset+1,j=0;i<n_tokens;i++,j++){
char *end;
double unused ORC_GNUC_UNUSED;
char varname[20];
args[j] = token[i];
unused = strtod (token[i], &end);
if (end != token[i]) {
orc_program_add_constant_str (parser->program, opcode_arg_size(o, j),
token[i], token[i]);
int id;
/* make a unique name based on value and size */
sprintf (varname, "_%d.%s", opcode_arg_size(o, j), token[i]);
id = orc_program_add_constant_str (parser->program, opcode_arg_size(o, j),
token[i], varname);
/* it's possible we reused an existing variable, get its name so
* that we can refer to it in the opcode */
args[j] = parser->program->vars[id].name;
}
args[j] = token[i];
}
orc_program_append_str_2 (parser->program, token[offset], flags,
......
......@@ -585,7 +585,8 @@ orc_program_add_constant_str (OrcProgram *program, int size,
}
for(j=0;j<program->n_const_vars;j++){
if (program->vars[ORC_VAR_C1 + j].value.i == program->vars[i].value.i) {
if (program->vars[ORC_VAR_C1 + j].value.i == program->vars[i].value.i &&
program->vars[ORC_VAR_C1 + j].size == size) {
return ORC_VAR_C1 + j;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment