program: only reuse constants of the same size and value
authorWim Taymans <wtaymans@redhat.com>
Mon, 22 Jun 2015 11:13:36 +0000 (13:13 +0200)
committerWim Taymans <wtaymans@redhat.com>
Mon, 22 Jun 2015 11:13:36 +0000 (13:13 +0200)
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.

orc/orccompiler.c
orc/orcparse.c
orc/orcprogram.c

index 3618f5b..352ec6e 100644 (file)
@@ -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++;
 
index f4d0a28..8d6be4c 100644 (file)
@@ -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,
index 1d749c0..c8e3d47 100644 (file)
@@ -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;
     }
   }