c: create code for bypassing OrcExecutor structure
authorDavid Schleef <ds@schleef.org>
Sat, 1 Aug 2009 05:49:11 +0000 (22:49 -0700)
committerDavid Schleef <ds@schleef.org>
Sat, 1 Aug 2009 05:54:19 +0000 (22:54 -0700)
orc/orcprogram-c.c
orc/orcprogram.h
tools/orcc.c

index b33728a..f1b1eba 100644 (file)
@@ -87,6 +87,21 @@ orc_compiler_c_get_default_flags (void)
   return 0;
 }
 
+const char *varnames[] = {
+  "d1", "d2", "d3", "d4",
+  "s1", "s2", "s3", "s4",
+  "s5", "s6", "s7", "s8",
+  "a1", "a2", "a3", "d4",
+  "c1", "c2", "c3", "c4",
+  "c5", "c6", "c7", "c8",
+  "p1", "p2", "p3", "p4",
+  "p5", "p6", "p7", "p8",
+  "t1", "t2", "t3", "t4",
+  "t5", "t6", "t7", "t8",
+  "t9", "t10", "t11", "t12",
+  "t13", "t14", "t15", "t16"
+};
+
 void
 orc_compiler_c_assemble (OrcCompiler *compiler)
 {
@@ -142,8 +157,13 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
             i);
         break;
       case ORC_VAR_TYPE_PARAM:
-        ORC_ASM_CODE(compiler,"  const %s var%d = ex->params[%d];\n",
-            c_get_type_name (var->size), i, i);
+        if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+          ORC_ASM_CODE(compiler,"  const %s var%d = ex->params[%d];\n",
+              c_get_type_name (var->size), i, i);
+        } else {
+          ORC_ASM_CODE(compiler,"  const %s var%d = %s;\n",
+              c_get_type_name (var->size), i, varnames[i]);
+        }
         break;
       default:
         ORC_COMPILER_ERROR(compiler, "bad vartype");
@@ -154,7 +174,11 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
   ORC_ASM_CODE(compiler,"\n");
   if (compiler->program->is_2d) {
     if (compiler->program->constant_m == 0) {
-      ORC_ASM_CODE(compiler,"  for (j = 0; j < ex->params[ORC_VAR_A1]; j++) {\n");
+      if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+        ORC_ASM_CODE(compiler,"  for (j = 0; j < ex->params[ORC_VAR_A1]; j++) {\n");
+      } else {
+        ORC_ASM_CODE(compiler,"  for (j = 0; j < m; j++) {\n");
+      }
     } else {
       ORC_ASM_CODE(compiler,"  for (j = 0; j < %d; j++) {\n",
           compiler->program->constant_m);
@@ -166,12 +190,22 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
       if (var->name == NULL) continue;
       switch (var->vartype) {
         case ORC_VAR_TYPE_SRC:
-          ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(ex->arrays[%d], ex->params[%d] * j);\n",
-              i, i, i);
+          if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+            ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(ex->arrays[%d], ex->params[%d] * j);\n",
+                i, i, i);
+          } else {
+            ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(%s, %s_stride * j);\n",
+                i, varnames[i], varnames[i]);
+          }
           break;
         case ORC_VAR_TYPE_DEST:
-          ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(ex->arrays[%d], ex->params[%d] * j);\n",
-              i, i, i);
+          if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+            ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(ex->arrays[%d], ex->params[%d] * j);\n",
+                i, i, i);
+          } else {
+            ORC_ASM_CODE(compiler,"    var%d = ORC_PTR_OFFSET(%s, %s_stride * j);\n",
+                i, varnames[i], varnames[i]);
+          }
           break;
         default:
           break;
@@ -183,10 +217,18 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
       if (var->name == NULL) continue;
       switch (var->vartype) {
         case ORC_VAR_TYPE_SRC:
-          ORC_ASM_CODE(compiler,"  var%d = ex->arrays[%d];\n", i, i);
+          if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+            ORC_ASM_CODE(compiler,"  var%d = ex->arrays[%d];\n", i, i);
+          } else {
+            ORC_ASM_CODE(compiler,"  var%d = (void *)%s;\n", i, varnames[i]);
+          }
           break;
         case ORC_VAR_TYPE_DEST:
-          ORC_ASM_CODE(compiler,"  var%d = ex->arrays[%d];\n", i, i);
+          if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+            ORC_ASM_CODE(compiler,"  var%d = ex->arrays[%d];\n", i, i);
+          } else {
+            ORC_ASM_CODE(compiler,"  var%d = (void *)%s;\n", i, varnames[i]);
+          }
           break;
         default:
           break;
@@ -196,7 +238,11 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
 
   ORC_ASM_CODE(compiler,"\n");
   if (compiler->program->constant_n == 0) {
-    ORC_ASM_CODE(compiler,"%*s  for (i = 0; i < ex->n; i++) {\n", prefix, "");
+    if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+      ORC_ASM_CODE(compiler,"%*s  for (i = 0; i < ex->n; i++) {\n", prefix, "");
+    } else {
+      ORC_ASM_CODE(compiler,"%*s  for (i = 0; i < n; i++) {\n", prefix, "");
+    }
   } else {
     ORC_ASM_CODE(compiler,"%*s  for (i = 0; i < %d; i++) {\n",
         prefix, "",
index abe23b0..586387d 100644 (file)
@@ -73,7 +73,8 @@ typedef void (*OrcExecutorFunc)(OrcExecutor *ex);
 
 enum {
   ORC_TARGET_C_C99 = (1<<0),
-  ORC_TARGET_C_BARE = (1<<1)
+  ORC_TARGET_C_BARE = (1<<1),
+  ORC_TARGET_C_NOEXEC = (1<<2)
 };
 
 enum {
index 3a3faec..b7006fd 100644 (file)
@@ -11,6 +11,7 @@ void output_code (OrcProgram *p, FILE *output);
 void output_code_header (OrcProgram *p, FILE *output);
 void output_code_test (OrcProgram *p, FILE *output);
 void output_code_backup (OrcProgram *p, FILE *output);
+void output_code_no_orc (OrcProgram *p, FILE *output);
 static void print_defines (FILE *output);
 static void print_exec_header (FILE *output);
 
@@ -119,6 +120,7 @@ main (int argc, char *argv[])
 static void
 print_exec_header (FILE *output)
 {
+#if 0
   fprintf(output,
       "typedef struct _OrcExecutor OrcExecutor;\n"
       "typedef struct _OrcProgram OrcProgram;\n"
@@ -183,6 +185,7 @@ print_exec_header (FILE *output)
       "  ORC_VAR_T14,\n"
       "  ORC_VAR_T15\n"
       "};\n");
+#endif
 }
 
 static void
@@ -384,6 +387,27 @@ output_code_backup (OrcProgram *p, FILE *output)
 }
 
 void
+output_code_no_orc (OrcProgram *p, FILE *output)
+{
+
+  fprintf(output, "void\n");
+  output_prototype (p, output);
+  fprintf(output, "{\n");
+  {
+    OrcCompileResult result;
+
+    result = orc_program_compile_full (p, orc_target_get_by_name("c"),
+        ORC_TARGET_C_BARE | ORC_TARGET_C_NOEXEC);
+    if (ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) {
+      fprintf(output, "%s\n", orc_program_get_asm_code (p));
+    }
+  }
+  fprintf(output, "}\n");
+  fprintf(output, "\n");
+
+}
+
+void
 output_code (OrcProgram *p, FILE *output)
 {
   OrcVariable *var;
@@ -391,13 +415,15 @@ output_code (OrcProgram *p, FILE *output)
 
   fprintf(output, "\n");
   fprintf(output, "/* %s */\n", p->name);
+  fprintf(output, "#ifdef DISABLE_ORC\n");
+  output_code_no_orc (p, output);
+  fprintf(output, "#else\n");
   output_code_backup (p, output);
   fprintf(output, "void\n");
   output_prototype (p, output);
   fprintf(output, "\n");
   fprintf(output, "{\n");
   fprintf(output, "  OrcExecutor _ex, *ex = &_ex;\n");
-  fprintf(output, "#ifndef DISABLE_ORC\n");
   fprintf(output, "  static int p_inited = 0;\n");
   fprintf(output, "  static OrcProgram *p = 0;\n");
   fprintf(output, "\n");
@@ -490,7 +516,6 @@ output_code (OrcProgram *p, FILE *output)
   fprintf(output, "    orc_once_mutex_unlock ();\n");
   fprintf(output, "  }\n");
   fprintf(output, "  ex->program = p;\n");
-  fprintf(output, "#endif\n");
   fprintf(output, "\n");
   if (p->constant_n) {
     fprintf(output, "  ex->n = %d;\n", p->constant_n);
@@ -526,11 +551,7 @@ output_code (OrcProgram *p, FILE *output)
     }
   }
   fprintf(output, "\n");
-  fprintf(output, "#ifndef DISABLE_ORC\n");
   fprintf(output, "  orc_executor_run (ex);\n");
-  fprintf(output, "#else\n");
-  fprintf(output, "  _backup_%s (ex);\n", p->name);
-  fprintf(output, "#endif\n");
   for(i=0;i<4;i++){
     var = &p->vars[ORC_VAR_A1 + i];
     if (var->size) {
@@ -539,6 +560,8 @@ output_code (OrcProgram *p, FILE *output)
     }
   }
   fprintf(output, "}\n");
+  fprintf(output, "#endif\n");
+  fprintf(output, "\n");
 
 }