allocate a loop counter variable
authorDavid Schleef <ds@schleef.org>
Mon, 7 Jun 2010 21:04:04 +0000 (14:04 -0700)
committerDavid Schleef <ds@schleef.org>
Mon, 7 Jun 2010 21:41:00 +0000 (14:41 -0700)
orc/orccompiler.c
orc/orcprogram-sse.c
orc/orcprogram.h

index 5f46b56..90a9617 100644 (file)
@@ -450,6 +450,10 @@ orc_compiler_global_reg_alloc (OrcCompiler *compiler)
         break;
     }
   }
+
+  if (compiler->alloc_loop_counter) {
+    compiler->loop_counter = orc_compiler_allocate_register (compiler, FALSE);
+  }
 }
 
 void
index 3490921..fe07a97 100644 (file)
@@ -165,6 +165,7 @@ orc_compiler_sse_init (OrcCompiler *compiler)
   }
 
   compiler->unroll_shift = 0;
+  //compiler->alloc_loop_counter = TRUE;
 
 }
 
@@ -659,6 +660,12 @@ orc_compiler_sse_assemble (OrcCompiler *compiler)
         (int)ORC_STRUCT_OFFSET(OrcExecutor,counter2), compiler->exec_reg);
     orc_x86_emit_je (compiler, LABEL_REGION2_SKIP);
 
+    if (compiler->loop_counter != ORC_REG_INVALID) {
+      orc_x86_emit_mov_memoffset_reg (compiler, 4,
+          (int)ORC_STRUCT_OFFSET(OrcExecutor, counter2), compiler->exec_reg,
+          compiler->loop_counter);
+    }
+
     ORC_ASM_CODE(compiler, "# LOOP SHIFT %d\n", compiler->loop_shift);
     orc_x86_emit_align (compiler);
     orc_x86_emit_label (compiler, LABEL_INNER_LOOP_START);
@@ -667,9 +674,13 @@ orc_compiler_sse_assemble (OrcCompiler *compiler)
       orc_sse_emit_loop (compiler, ui<<compiler->loop_shift,
           (ui==ui_max-1) << (compiler->loop_shift + compiler->unroll_shift));
     }
-    orc_x86_emit_dec_memoffset (compiler, 4,
-        (int)ORC_STRUCT_OFFSET(OrcExecutor,counter2),
-        compiler->exec_reg);
+    if (compiler->loop_counter != ORC_REG_INVALID) {
+      orc_x86_emit_add_imm_reg (compiler, 4, -1, compiler->loop_counter);
+    } else {
+      orc_x86_emit_dec_memoffset (compiler, 4,
+          (int)ORC_STRUCT_OFFSET(OrcExecutor,counter2),
+          compiler->exec_reg);
+    }
     orc_x86_emit_jne (compiler, LABEL_INNER_LOOP_START);
     orc_x86_emit_label (compiler, LABEL_REGION2_SKIP);
 
index ed13cb2..1d6e2a2 100644 (file)
@@ -35,6 +35,7 @@ typedef void (*OrcExecutorFunc)(OrcExecutor *ex);
 
 #define ORC_GP_REG_BASE 32
 #define ORC_VEC_REG_BASE 64
+#define ORC_REG_INVALID 0
 
 #define ORC_STATIC_OPCODE_N_SRC 4
 #define ORC_STATIC_OPCODE_N_DEST 2
@@ -387,6 +388,9 @@ struct _OrcCompiler {
   int insn_index;
   int need_mask_regs;
   int unroll_shift;
+
+  int alloc_loop_counter;
+  int loop_counter;
 };
 
 #define ORC_SRC_ARG(p,i,n) ((p)->vars[(i)->src_args[(n)]].alloc)