Add loadoff[bwl], loadup[id]b opcodes
authorDavid Schleef <ds@schleef.org>
Thu, 5 Aug 2010 21:18:42 +0000 (14:18 -0700)
committerDavid Schleef <ds@schleef.org>
Thu, 5 Aug 2010 21:18:42 +0000 (14:18 -0700)
orc/opcodes.h
orc/orccompiler.c
orc/orcopcodes.c
orc/orcprogram-c.c
orc/orcprogram.h

index f933299..694b891 100644 (file)
@@ -9,7 +9,6 @@ BINARY_UB(avgub, "((orc_uint8)%s + (orc_uint8)%s + 1)>>1")
 BINARY_SB(cmpeqb, "(%s == %s) ? (~0) : 0")
 BINARY_SB(cmpgtsb, "(%s > %s) ? (~0) : 0")
 UNARY_SB(copyb, "%s")
-UNARY_SB(loadb, "%s")
 UNARY_SB(loadpb, "%s")
 BINARY_SB(maxsb, "ORC_MAX(%s, %s)")
 BINARY_UB(maxub, "ORC_MAX((orc_uint8)%s, (orc_uint8)%s)")
@@ -23,7 +22,6 @@ BINARY_SB(shlb, "%s << %s")
 BINARY_SB(shrsb, "%s >> %s")
 BINARY_UB(shrub, "((orc_uint8)%s) >> %s")
 UNARY_SB(signb, "ORC_CLAMP(%s,-1,1)")
-UNARY_SB(storeb, "%s")
 BINARY_SB(subb, "%s - %s")
 BINARY_SB(subssb, "ORC_CLAMP_SB(%s - %s)")
 BINARY_UB(subusb, "ORC_CLAMP_UB((orc_uint8)%s - (orc_uint8)%s)")
@@ -40,7 +38,6 @@ BINARY_UW(avguw, "((orc_uint16)%s + (orc_uint16)%s + 1)>>1")
 BINARY_SW(cmpeqw, "(%s == %s) ? (~0) : 0")
 BINARY_SW(cmpgtsw, "(%s > %s) ? (~0) : 0")
 UNARY_SW(copyw, "%s")
-UNARY_SW(loadw, "%s")
 UNARY_SW(loadpw, "%s")
 BINARY_SW(maxsw, "ORC_MAX(%s, %s)")
 BINARY_UW(maxuw, "ORC_MAX((orc_uint16)%s, (orc_uint16)%s)")
@@ -54,7 +51,6 @@ BINARY_SW(shlw, "%s << %s")
 BINARY_SW(shrsw, "%s >> %s")
 BINARY_UW(shruw, "((orc_uint16)%s) >> %s")
 UNARY_SW(signw, "ORC_CLAMP(%s,-1,1)")
-UNARY_SW(storew, "%s")
 BINARY_SW(subw, "%s - %s")
 BINARY_SW(subssw, "ORC_CLAMP_SW(%s - %s)")
 BINARY_UW(subusw, "ORC_CLAMP_UW((orc_uint16)%s - (orc_uint16)%s)")
@@ -71,7 +67,6 @@ BINARY_UL(avgul, "((orc_uint64)(orc_uint32)%s + (orc_uint64)(orc_uint32)%s + 1)>
 BINARY_SL(cmpeql, "(%s == %s) ? (~0) : 0")
 BINARY_SL(cmpgtsl, "(%s > %s) ? (~0) : 0")
 UNARY_SL(copyl, "%s")
-UNARY_SL(loadl, "%s")
 UNARY_SL(loadpl, "%s")
 BINARY_SL(maxsl, "ORC_MAX(%s, %s)")
 BINARY_UL(maxul, "ORC_MAX((orc_uint32)%s, (orc_uint32)%s)")
@@ -85,7 +80,6 @@ BINARY_SL(shll, "%s << %s")
 BINARY_SL(shrsl, "%s >> %s")
 BINARY_UL(shrul, "((orc_uint32)%s) >> %s")
 UNARY_SL(signl, "ORC_CLAMP(%s,-1,1)")
-UNARY_SL(storel, "%s")
 BINARY_SL(subl, "%s - %s")
 BINARY_SL(subssl, "ORC_CLAMP_SL((orc_int64)%s - (orc_int64)%s)")
 BINARY_UL(subusl, "ORC_CLAMP_UL((orc_int64)(orc_uint32)%s - (orc_int64)(orc_uint32)%s)")
index e11f6d2..7115785 100644 (file)
@@ -236,6 +236,8 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target,
 
   memcpy (compiler->vars, program->vars,
       ORC_N_VARIABLES * sizeof(OrcVariable));
+  memset (compiler->vars + ORC_N_VARIABLES, 0,
+      (ORC_N_COMPILER_VARIABLES - ORC_N_VARIABLES) * sizeof(OrcVariable));
   compiler->n_temp_vars = program->n_temp_vars;
   compiler->n_dup_vars = 0;
 
@@ -294,7 +296,10 @@ orc_program_compile_full (OrcProgram *program, OrcTarget *target,
 
   ORC_INFO("compiling for target \"%s\"", compiler->target->name);
   compiler->target->compile (compiler);
-  if (compiler->error) goto error;
+  if (compiler->error) {
+    compiler->result = ORC_COMPILE_RESULT_UNKNOWN_COMPILE;
+    goto error;
+  }
 
   program->orccode = orc_code_new ();
   program->orccode->exec = program->code_exec;
@@ -414,6 +419,7 @@ orc_compiler_rewrite_insns (OrcCompiler *compiler)
           OrcInstruction *cinsn;
           
           cinsn = compiler->insns + compiler->n_insns;
+          compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
           compiler->n_insns++;
 
           if (var->size == 1) {
@@ -431,6 +437,7 @@ orc_compiler_rewrite_insns (OrcCompiler *compiler)
           OrcInstruction *cinsn;
 
           cinsn = compiler->insns + compiler->n_insns;
+          compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
           compiler->n_insns++;
 
           if (var->size == 1) {
@@ -462,6 +469,7 @@ orc_compiler_rewrite_insns (OrcCompiler *compiler)
           OrcInstruction *cinsn;
           
           cinsn = compiler->insns + compiler->n_insns;
+          compiler->insn_flags[compiler->n_insns] |= ORC_INSN_FLAG_ADDED;
           compiler->n_insns++;
 
           if (var->size == 1) {
@@ -666,6 +674,10 @@ orc_compiler_global_reg_alloc (OrcCompiler *compiler)
       var->alloc = orc_compiler_allocate_register (compiler, TRUE);
       compiler->insn_flags[i] |= ORC_INSN_FLAG_INVARIANT;
     }
+
+    if (opcode->flags & ORC_STATIC_OPCODE_ITERATOR) {
+      compiler->has_iterator_opcode = TRUE;
+    }
   }
 
   if (compiler->alloc_loop_counter && !compiler->error) {
index 6152f6e..37daa65 100644 (file)
@@ -399,6 +399,9 @@ BINARY_SB(cmpeqb, (a == b) ? (~0) : 0)
 BINARY_SB(cmpgtsb, (a > b) ? (~0) : 0)
 UNARY_SB(copyb, a)
 UNARY_SB(loadb, a)
+UNARY_SB(loadoffb, a)
+UNARY_SB(loadupdb, a)
+UNARY_SB(loadupib, a)
 UNARY_SB(loadpb, a)
 BINARY_SB(maxsb, (a > b) ? a : b)
 BINARY_UB(maxub, (a > b) ? a : b)
@@ -430,6 +433,7 @@ BINARY_SW(cmpeqw, (a == b) ? (~0) : 0)
 BINARY_SW(cmpgtsw, (a > b) ? (~0) : 0)
 UNARY_SW(copyw, a)
 UNARY_SW(loadw, a)
+UNARY_SW(loadoffw, a)
 UNARY_SW(loadpw, a)
 BINARY_SW(maxsw, (a > b) ? a : b)
 BINARY_UW(maxuw, (a > b) ? a : b)
@@ -461,6 +465,7 @@ BINARY_SL(cmpeql, (a == b) ? (~0) : 0)
 BINARY_SL(cmpgtsl, (a > b) ? (~0) : 0)
 UNARY_SL(copyl, a)
 UNARY_SL(loadl, a)
+UNARY_SL(loadoffl, a)
 UNARY_SL(loadpl, a)
 BINARY_SL(maxsl, (a > b) ? a : b)
 BINARY_UL(maxul, ((orc_uint32)a > (orc_uint32)b) ? a : b)
@@ -724,6 +729,9 @@ static OrcStaticOpcode opcodes[] = {
   { "cmpgtsb", cmpgtsb, NULL, 0, { 1 }, { 1, 1 }, emulate_cmpgtsb },
   { "copyb", copyb, NULL, 0, { 1 }, { 1 }, emulate_copyb },
   { "loadb", loadb, NULL, ORC_STATIC_OPCODE_LOAD, { 1 }, { 1 }, emulate_loadb },
+  { "loadoffb", loadoffb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 1 }, { 1, 4 }, emulate_loadoffb },
+  { "loadupdb", loadupdb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_ITERATOR, { 1 }, { 1 }, emulate_loadupdb },
+  { "loadupib", loadupib, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_ITERATOR, { 1 }, { 1 }, emulate_loadupib },
   { "loadpb", loadpb, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 1 }, { 1 }, emulate_loadpb },
   { "maxsb", maxsb, NULL, 0, { 1 }, { 1, 1 }, emulate_maxsb },
   { "maxub", maxub, NULL, 0, { 1 }, { 1, 1 }, emulate_maxub },
@@ -756,6 +764,7 @@ static OrcStaticOpcode opcodes[] = {
   { "cmpgtsw", cmpgtsw, NULL, 0, { 2 }, { 2, 2 }, emulate_cmpgtsw },
   { "copyw", copyw, NULL, 0, { 2 }, { 2 }, emulate_copyw },
   { "loadw", loadw, NULL, ORC_STATIC_OPCODE_LOAD, { 2 }, { 2 }, emulate_loadw },
+  { "loadoffw", loadoffw, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 2 }, { 2, 4 }, emulate_loadoffw },
   { "loadpw", loadpw, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 2 }, { 2 }, emulate_loadpw },
   { "maxsw", maxsw, NULL, 0, { 2 }, { 2, 2 }, emulate_maxsw },
   { "maxuw", maxuw, NULL, 0, { 2 }, { 2, 2 }, emulate_maxuw },
@@ -788,6 +797,7 @@ static OrcStaticOpcode opcodes[] = {
   { "cmpgtsl", cmpgtsl, NULL, 0, { 4 }, { 4, 4 }, emulate_cmpgtsl },
   { "copyl", copyl, NULL, 0, { 4 }, { 4 }, emulate_copyl },
   { "loadl", loadl, NULL, ORC_STATIC_OPCODE_LOAD, { 4 }, { 4 }, emulate_loadl },
+  { "loadoffl", loadoffl, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR, { 4 }, { 4, 4 }, emulate_loadoffl },
   { "loadpl", loadpl, NULL, ORC_STATIC_OPCODE_LOAD|ORC_STATIC_OPCODE_SCALAR|ORC_STATIC_OPCODE_INVARIANT, { 4 }, { 4 }, emulate_loadpl },
   { "maxsl", maxsl, NULL, 0, { 4 }, { 4, 4 }, emulate_maxsl },
   { "maxul", maxul, NULL, 0, { 4 }, { 4, 4 }, emulate_maxul },
index 530ee09..1de40a5 100644 (file)
@@ -176,6 +176,11 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
     ORC_ASM_CODE(compiler,"{\n");
   }
 
+#if 0
+  if (!(compiler->target_flags & ORC_TARGET_C_OPCODE)) {
+    ORC_ASM_CODE(compiler,"%*s  int offset = 0;\n", prefix, "");
+  }
+#endif
   ORC_ASM_CODE(compiler,"%*s  int i;\n", prefix, "");
   if (compiler->program->is_2d) {
     ORC_ASM_CODE(compiler,"  int j;\n");
@@ -223,7 +228,9 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
         }
         break;
       case ORC_VAR_TYPE_TEMP:
-        ORC_ASM_CODE(compiler,"  %s var%d;\n", c_get_type_name(var->size), i);
+        if (!(var->last_use == -1 && var->first_use == 0)) {
+          ORC_ASM_CODE(compiler,"  %s var%d;\n", c_get_type_name(var->size), i);
+        }
         break;
       case ORC_VAR_TYPE_SRC:
         ORC_ASM_CODE(compiler,"  const %s *%s ptr%d;\n",
@@ -369,6 +376,7 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
       compiler->error = TRUE;
     }
   }
+#if 0
   /* update pointers */
   for(i=0;i<ORC_N_VARIABLES;i++){
     OrcVariable *var = compiler->vars + i;
@@ -377,6 +385,7 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
       ORC_ASM_CODE (compiler, "%*s    ptr%d++;\n", prefix, "", i);
     }
   }
+#endif
   ORC_ASM_CODE(compiler,"%*s  }\n", prefix, "");
   if (compiler->program->is_2d) {
     ORC_ASM_CODE(compiler,"  }\n");
@@ -656,18 +665,50 @@ c_rule_ ## name (OrcCompiler *p, void *user, OrcInstruction *insn) \
 static void
 c_rule_loadX (OrcCompiler *p, void *user, OrcInstruction *insn)
 {
-  ORC_ASM_CODE(p,"    var%d = *ptr%d;\n", insn->dest_args[0],
+  if (p->insn_flags[insn-p->insns] & ORC_INSN_FLAG_ADDED) {
+    ORC_ASM_CODE(p,"    var%d = ptr%d[i];\n", insn->dest_args[0],
+        insn->src_args[0]);
+  } else {
+    ORC_ASM_CODE(p,"    var%d = ptr%d[offset + i];\n", insn->dest_args[0],
+        insn->src_args[0]);
+  }
+}
+
+static void
+c_rule_loadoffX (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+  ORC_ASM_CODE(p,"    var%d = ptr%d[offset + i+var%d];\n", insn->dest_args[0],
+      insn->src_args[0], insn->src_args[1]);
+}
+
+static void
+c_rule_loadupdb (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+  ORC_ASM_CODE(p,"    var%d = ptr%d[(offset + i)>>1];\n", insn->dest_args[0],
       insn->src_args[0]);
 }
 
 static void
-c_rule_storeX (OrcCompiler *p, void *user, OrcInstruction *insn)
+c_rule_loadupib (OrcCompiler *p, void *user, OrcInstruction *insn)
 {
-  ORC_ASM_CODE(p,"    *ptr%d = var%d;\n", insn->dest_args[0],
+  ORC_ASM_CODE(p,"    var%d = ((offset + i)&1) ? (ptr%d[(offset + i)>>1] + ptr%d[((offset + i)>>1)+1] + 1)>>1 : ptr%d[(offset + i)>>1];\n",
+      insn->dest_args[0], insn->src_args[0], insn->src_args[0],
       insn->src_args[0]);
 }
 
 static void
+c_rule_storeX (OrcCompiler *p, void *user, OrcInstruction *insn)
+{
+  if (p->insn_flags[insn-p->insns] & ORC_INSN_FLAG_ADDED) {
+    ORC_ASM_CODE(p,"    ptr%d[i] = var%d;\n", insn->dest_args[0],
+        insn->src_args[0]);
+  } else {
+    ORC_ASM_CODE(p,"    ptr%d[offset + i] = var%d;\n", insn->dest_args[0],
+        insn->src_args[0]);
+  }
+}
+
+static void
 c_rule_accw (OrcCompiler *p, void *user, OrcInstruction *insn)
 {
   char dest[20], src1[20];
@@ -783,6 +824,11 @@ orc_c_init (void)
   orc_rule_register (rule_set, "loadb", c_rule_loadX, NULL);
   orc_rule_register (rule_set, "loadw", c_rule_loadX, NULL);
   orc_rule_register (rule_set, "loadl", c_rule_loadX, NULL);
+  orc_rule_register (rule_set, "loadoffb", c_rule_loadoffX, NULL);
+  orc_rule_register (rule_set, "loadoffw", c_rule_loadoffX, NULL);
+  orc_rule_register (rule_set, "loadoffl", c_rule_loadoffX, NULL);
+  orc_rule_register (rule_set, "loadupdb", c_rule_loadupdb, NULL);
+  orc_rule_register (rule_set, "loadupib", c_rule_loadupib, NULL);
   orc_rule_register (rule_set, "storeb", c_rule_storeX, NULL);
   orc_rule_register (rule_set, "storew", c_rule_storeX, NULL);
   orc_rule_register (rule_set, "storel", c_rule_storeX, NULL);
index e38b6c9..9a30697 100644 (file)
@@ -269,6 +269,7 @@ struct _OrcOpcodeSet {
 #define ORC_STATIC_OPCODE_LOAD (1<<4)
 #define ORC_STATIC_OPCODE_STORE (1<<5)
 #define ORC_STATIC_OPCODE_INVARIANT (1<<6)
+#define ORC_STATIC_OPCODE_ITERATOR (1<<7)
 
 
 struct _OrcStaticOpcode {
@@ -412,11 +413,13 @@ struct _OrcCompiler {
   int allow_gp_on_stack;
   int loop_counter;
   int size_region;
+  int has_iterator_opcode;
 
   int offset;
 };
 
-#define ORC_INSN_FLAG_INVARIANT 1
+#define ORC_INSN_FLAG_INVARIANT (1<<0)
+#define ORC_INSN_FLAG_ADDED (1<<1)
 
 #define ORC_SRC_ARG(p,i,n) ((p)->vars[(i)->src_args[(n)]].alloc)
 #define ORC_DEST_ARG(p,i,n) ((p)->vars[(i)->dest_args[(n)]].alloc)