more support for 2d
authorDavid Schleef <ds@schleef.org>
Sun, 26 Jul 2009 07:08:49 +0000 (00:08 -0700)
committerDavid Schleef <ds@schleef.org>
Sun, 26 Jul 2009 07:08:49 +0000 (00:08 -0700)
orc/orcparse.c
orc/orcprogram-c.c
orc/orcprogram.c
orc/orcprogram.h
tools/orcc.c

index 88ee0a6..3819635 100644 (file)
@@ -115,6 +115,19 @@ orc_parse (const char *code, OrcProgram ***programs)
         parser->programs[parser->n_programs] = parser->program;
         parser->n_programs++;
         parser->creg_index = 1;
+      } else if (strcmp (token[0], ".flags") == 0) {
+        int i;
+        for(i=1;i<n_tokens;i++){
+          if (!strcmp (token[i], "2d")) {
+            orc_program_set_2d (parser->program);
+          }
+        }
+      } else if (strcmp (token[0], ".n") == 0) {
+        int size = strtol (token[1], NULL, 0);
+        orc_program_set_constant_n (parser->program, size);
+      } else if (strcmp (token[0], ".m") == 0) {
+        int size = strtol (token[1], NULL, 0);
+        orc_program_set_constant_m (parser->program, size);
       } else if (strcmp (token[0], ".source") == 0) {
         int size = strtol (token[1], NULL, 0);
         int var;
index 4368bdc..0510eb5 100644 (file)
@@ -101,6 +101,9 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
     ORC_ASM_CODE(compiler,"{\n");
   }
   ORC_ASM_CODE(compiler,"  int i;\n");
+  if (compiler->program->is_2d) {
+    ORC_ASM_CODE(compiler,"  int j;\n");
+  }
 
   for(i=0;i<ORC_N_VARIABLES;i++){
     OrcVariable *var = compiler->vars + i;
@@ -147,7 +150,20 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
   }
 
   ORC_ASM_CODE(compiler,"\n");
-  ORC_ASM_CODE(compiler,"  for (i = 0; i < ex->n; i++) {\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");
+    } else {
+      ORC_ASM_CODE(compiler,"  for (j = 0; j < %d; j++) {\n",
+          compiler->program->constant_m);
+    }
+  }
+  if (compiler->program->constant_n == 0) {
+    ORC_ASM_CODE(compiler,"  for (i = 0; i < ex->n; i++) {\n");
+  } else {
+    ORC_ASM_CODE(compiler,"  for (i = 0; i < %d; i++) {\n",
+        compiler->program->constant_n);
+  }
 
   for(j=0;j<compiler->n_insns;j++){
     insn = compiler->insns + j;
@@ -164,6 +180,9 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
     }
   }
   ORC_ASM_CODE(compiler,"  }\n");
+  if (compiler->program->is_2d) {
+    ORC_ASM_CODE(compiler,"  }\n");
+  }
 
   for(i=0;i<ORC_N_VARIABLES;i++){
     OrcVariable *var = compiler->vars + i;
index c2efe81..3d24a54 100644 (file)
@@ -183,6 +183,16 @@ orc_program_set_2d (OrcProgram *program)
   program->is_2d = TRUE;
 }
 
+void orc_program_set_constant_n (OrcProgram *program, int n)
+{
+  program->constant_n = n;
+}
+
+void orc_program_set_constant_m (OrcProgram *program, int m)
+{
+  program->constant_m = m;
+}
+
 /**
  * orc_program_set_backup_function:
  * @program: a pointer to an OrcProgram structure
index f6fb283..8b9d109 100644 (file)
@@ -456,6 +456,8 @@ void orc_opcode_init (void);
 const char * orc_program_get_name (OrcProgram *program);
 void orc_program_set_name (OrcProgram *program, const char *name);
 void orc_program_set_2d (OrcProgram *program);
+void orc_program_set_constant_n (OrcProgram *program, int n);
+void orc_program_set_constant_m (OrcProgram *program, int m);
 
 void orc_program_append (OrcProgram *p, const char *opcode, int arg0, int arg1, int arg2);
 void orc_program_append_str (OrcProgram *p, const char *opcode,
index e1605fc..d3ca585 100644 (file)
@@ -213,56 +213,82 @@ const char *enumnames[] = {
 };
 
 void
-output_code_header (OrcProgram *p, FILE *output)
+output_prototype (OrcProgram *p, FILE *output)
 {
   OrcVariable *var;
   int i;
+  int need_comma;
 
-  fprintf(output, "void %s (", p->name);
+  fprintf(output, "%s (", p->name);
+  need_comma = FALSE;
   for(i=0;i<4;i++){
     var = &p->vars[ORC_VAR_D1 + i];
     if (var->size) {
+      if (need_comma) fprintf(output, ", ");
       if (var->type_name) {
-        fprintf(output, "%s * %s", var->type_name,
+        fprintf(output, "%s * %s", var->type_name,
             varnames[ORC_VAR_D1 + i]);
       } else {
-        fprintf(output, "uint%d_t * %s", var->size*8,
+        fprintf(output, "uint%d_t * %s", var->size*8,
             varnames[ORC_VAR_D1 + i]);
       }
+      need_comma = TRUE;
     }
   }
   for(i=0;i<4;i++){
     var = &p->vars[ORC_VAR_A1 + i];
     if (var->size) {
+      if (need_comma) fprintf(output, ", ");
       if (var->type_name) {
-        fprintf(output, "%s * %s", var->type_name,
+        fprintf(output, "%s * %s", var->type_name,
             varnames[ORC_VAR_A1 + i]);
       } else {
-        fprintf(output, "uint%d_t * %s", var->size*8,
+        fprintf(output, "uint%d_t * %s", var->size*8,
             varnames[ORC_VAR_A1 + i]);
       }
+      need_comma = TRUE;
     }
   }
   for(i=0;i<8;i++){
     var = &p->vars[ORC_VAR_S1 + i];
     if (var->size) {
+      if (need_comma) fprintf(output, ", ");
       if (var->type_name) {
-        fprintf(output, "%s * %s", var->type_name,
+        fprintf(output, "%s * %s", var->type_name,
             varnames[ORC_VAR_S1 + i]);
       } else {
-        fprintf(output, "uint%d_t * %s", var->size*8,
+        fprintf(output, "uint%d_t * %s", var->size*8,
             varnames[ORC_VAR_S1 + i]);
       }
+      need_comma = TRUE;
     }
   }
   for(i=0;i<8;i++){
     var = &p->vars[ORC_VAR_P1 + i];
     if (var->size) {
-      fprintf(output, "int %s, ", varnames[ORC_VAR_P1 + i]);
+      if (need_comma) fprintf(output, ", ");
+      fprintf(output, "int %s", varnames[ORC_VAR_P1 + i]);
+      need_comma = TRUE;
     }
   }
-  fprintf(output, "int n);\n");
+  if (p->constant_n == 0) {
+    if (need_comma) fprintf(output, ", ");
+    fprintf(output, "int n");
+    need_comma = TRUE;
+  }
+  if (p->is_2d && p->constant_m == 0) {
+    if (need_comma) fprintf(output, ", ");
+    fprintf(output, "int m");
+  }
+  fprintf(output, ")");
+}
 
+void
+output_code_header (OrcProgram *p, FILE *output)
+{
+  fprintf(output, "void ");
+  output_prototype (p, output);
+  fprintf(output, ";\n");
 }
 
 void
@@ -296,50 +322,8 @@ output_code (OrcProgram *p, FILE *output)
   fprintf(output, "/* %s */\n", p->name);
   output_code_backup (p, output);
   fprintf(output, "void\n");
-  fprintf(output, "%s (", p->name);
-  for(i=0;i<4;i++){
-    var = &p->vars[ORC_VAR_D1 + i];
-    if (var->size) {
-      if (var->type_name) {
-        fprintf(output, "%s * %s, ", var->type_name,
-            varnames[ORC_VAR_D1 + i]);
-      } else {
-        fprintf(output, "uint%d_t * %s, ", var->size*8,
-            varnames[ORC_VAR_D1 + i]);
-      }
-    }
-  }
-  for(i=0;i<4;i++){
-    var = &p->vars[ORC_VAR_A1 + i];
-    if (var->size) {
-      if (var->type_name) {
-        fprintf(output, "%s * %s, ", var->type_name,
-            varnames[ORC_VAR_A1 + i]);
-      } else {
-        fprintf(output, "uint%d_t * %s, ", var->size*8,
-            varnames[ORC_VAR_A1 + i]);
-      }
-    }
-  }
-  for(i=0;i<8;i++){
-    var = &p->vars[ORC_VAR_S1 + i];
-    if (var->size) {
-      if (var->type_name) {
-        fprintf(output, "%s * %s, ", var->type_name,
-            varnames[ORC_VAR_S1 + i]);
-      } else {
-        fprintf(output, "uint%d_t * %s, ", var->size*8,
-            varnames[ORC_VAR_S1 + i]);
-      }
-    }
-  }
-  for(i=0;i<8;i++){
-    var = &p->vars[ORC_VAR_P1 + i];
-    if (var->size) {
-      fprintf(output, "int %s, ", varnames[ORC_VAR_P1 + i]);
-    }
-  }
-  fprintf(output, "int n)\n");
+  output_prototype (p, output);
+  fprintf(output, "\n");
   fprintf(output, "{\n");
   fprintf(output, "  static int p_inited = 0;\n");
   fprintf(output, "  static OrcProgram *p = NULL;\n");
@@ -351,6 +335,17 @@ output_code (OrcProgram *p, FILE *output)
   fprintf(output, "      OrcCompileResult result;\n");
   fprintf(output, "\n");
   fprintf(output, "      p = orc_program_new ();\n");
+  if (p->constant_n != 0) {
+    fprintf(output, "      orc_program_set_constant_n (p, %d);\n",
+        p->constant_n);
+  }
+  if (p->is_2d) {
+    fprintf(output, "      orc_program_set_2d (p);\n");
+    if (p->constant_m != 0) {
+      fprintf(output, "      orc_program_set_constant_m (p, %d);\n",
+          p->constant_m);
+    }
+  }
   fprintf(output, "      orc_program_set_name (p, \"%s\");\n", p->name);
   fprintf(output, "      orc_program_set_backup_function (p, _backup_%s);\n",
       p->name);
@@ -432,7 +427,18 @@ output_code (OrcProgram *p, FILE *output)
   //fprintf(output, "  orc_executor_set_program (ex, p);\n");
   fprintf(output, "  ex->program = p;\n");
   //fprintf(output, "  orc_executor_set_n (ex, n);\n");
-  fprintf(output, "  ex->n = n;\n");
+  if (p->constant_n) {
+    fprintf(output, "  ex->n = %d;\n", p->constant_n);
+  } else {
+    fprintf(output, "  ex->n = n;\n");
+  }
+  if (p->is_2d) {
+    if (p->constant_m) {
+      fprintf(output, "  ORC_EXECUTOR_M(ex) = %d;\n", p->constant_m);
+    } else {
+      fprintf(output, "  ORC_EXECUTOR_M(ex) = m;\n");
+    }
+  }
   for(i=0;i<4;i++){
     var = &p->vars[ORC_VAR_D1 + i];
     if (var->size) {
@@ -487,6 +493,17 @@ output_code_test (OrcProgram *p, FILE *output)
   fprintf(output, "\n");
   fprintf(output, "    printf (\"%s:\\n\");\n", p->name);
   fprintf(output, "    p = orc_program_new ();\n");
+  if (p->constant_n != 0) {
+    fprintf(output, "      orc_program_set_constant_n (p, %d);\n",
+        p->constant_n);
+  }
+  if (p->is_2d) {
+    fprintf(output, "      orc_program_set_2d (p);\n");
+    if (p->constant_m != 0) {
+      fprintf(output, "      orc_program_set_constant_m (p, %d);\n",
+          p->constant_m);
+    }
+  }
   fprintf(output, "    orc_program_set_name (p, \"%s\");\n", p->name);
   fprintf(output, "    orc_program_set_backup_function (p, _backup_%s);\n",
       p->name);