Add source array sampling type
authorDavid Schleef <ds@schleef.org>
Wed, 18 Nov 2009 10:50:08 +0000 (11:50 +0100)
committerDavid Schleef <ds@schleef.org>
Wed, 18 Nov 2009 10:50:08 +0000 (11:50 +0100)
orc/orcprogram-c.c
orc/orcprogram.c
orc/orcprogram.h

index c03d1c7..37c07df 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <orc/orc.h>
 #include <orc/orcprogram.h>
@@ -102,6 +103,26 @@ const char *varnames[] = {
   "t13", "t14", "t15", "t16"
 };
 
+static void
+get_varname (char *s, OrcCompiler *compiler, int var)
+{
+  if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+    sprintf(s, "ex->arrays[%d]", var);
+  } else {
+    strcpy (s, varnames[var]);
+  }
+}
+
+static void
+get_varname_stride (char *s, OrcCompiler *compiler, int var)
+{
+  if (!(compiler->target_flags & ORC_TARGET_C_NOEXEC)) {
+    sprintf(s, "ex->params[%d]", var);
+  } else {
+    sprintf(s, "%s_stride", varnames[var]);
+  }
+}
+
 void
 orc_compiler_c_assemble (OrcCompiler *compiler)
 {
@@ -190,21 +211,41 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
       if (var->name == NULL) continue;
       switch (var->vartype) {
         case ORC_VAR_TYPE_SRC:
-          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]);
+          {
+            char s1[20], s2[20];
+            get_varname(s1, compiler, i);
+            get_varname_stride(s2, compiler, i);
+            switch (var->sampling_type) {
+              case ORC_SAMPLE_REGULAR:
+                ORC_ASM_CODE(compiler,
+                    "    var%d = ORC_PTR_OFFSET(%s, %s * j);\n",
+                    i, s1, s2);
+                break;
+              case ORC_SAMPLE_TRANSPOSED:
+                ORC_ASM_CODE(compiler,
+                    "    var%d = ORC_PTR_OFFSET(%s, %d * j);\n",
+                    i, s1, var->size);
+                break;
+              case ORC_SAMPLE_NEAREST:
+              case ORC_SAMPLE_BILINEAR:
+              case ORC_SAMPLE_FOUR_TAP:
+                ORC_ASM_CODE(compiler,
+                    "    var%d = ORC_PTR_OFFSET(%s, %s * j);\n",
+                    i, s1, s2);
+                break;
+              default:
+                ORC_COMPILER_ERROR(compiler, "eeek");
+            }
           }
           break;
         case ORC_VAR_TYPE_DEST:
-          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]);
+          {
+            char s1[20], s2[20];
+            get_varname(s1, compiler, i),
+            get_varname_stride(s2, compiler, i),
+            ORC_ASM_CODE(compiler,
+                "    var%d = ORC_PTR_OFFSET(%s, %s * j);\n",
+                i, s1, s2);
           }
           break;
         default:
@@ -214,21 +255,15 @@ orc_compiler_c_assemble (OrcCompiler *compiler)
   } else {
     for(i=0;i<ORC_N_VARIABLES;i++){
       OrcVariable *var = compiler->vars + i;
+      char s[20];
       if (var->name == NULL) continue;
+      get_varname(s, compiler, i);
       switch (var->vartype) {
         case ORC_VAR_TYPE_SRC:
-          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]);
-          }
+          ORC_ASM_CODE(compiler,"  var%d = %s;\n", i, s);
           break;
         case ORC_VAR_TYPE_DEST:
-          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]);
-          }
+          ORC_ASM_CODE(compiler,"  var%d = %s;\n", i, s);
           break;
         default:
           break;
@@ -318,6 +353,27 @@ c_get_name (char *name, OrcCompiler *p, int var)
       sprintf(name, "var%d", var);
       break;
     case ORC_VAR_TYPE_SRC:
+      switch(p->vars[var].sampling_type) {
+        case ORC_SAMPLE_REGULAR:
+          sprintf(name, "var%d[i]", var);
+          break;
+        case ORC_SAMPLE_TRANSPOSED:
+          {
+            char s2[20];
+            get_varname_stride(s2, p, var);
+            sprintf(name, "ORC_PTR_OFFSET(var%d, %s * i)", var, s2);
+          }
+          break;
+        case ORC_SAMPLE_NEAREST:
+        case ORC_SAMPLE_BILINEAR:
+        case ORC_SAMPLE_FOUR_TAP:
+          sprintf(name, "var%d[i]", var);
+          break;
+        default:
+          ORC_COMPILER_ERROR(p, "eeek");
+          break;
+      }
+      break;
     case ORC_VAR_TYPE_DEST:
       sprintf(name, "var%d[i]", var);
       break;
index 666e915..6feba5b 100644 (file)
@@ -400,6 +400,13 @@ orc_program_set_type_name (OrcProgram *program, int var, const char *type_name)
   program->vars[var].type_name = strdup(type_name);
 }
 
+void
+orc_program_set_sampling_type (OrcProgram *program, int var,
+    int sampling_type)
+{
+  program->vars[var].sampling_type = sampling_type;
+}
+
 /**
  * orc_program_append_ds:
  * @program: a pointer to an OrcProgram structure
index 13e368a..0b54de0 100644 (file)
@@ -147,6 +147,14 @@ enum {
   ORC_CONST_SPLAT_L,
 };
 
+enum {
+  ORC_SAMPLE_REGULAR = 0,
+  ORC_SAMPLE_TRANSPOSED,
+  ORC_SAMPLE_NEAREST,
+  ORC_SAMPLE_BILINEAR,
+  ORC_SAMPLE_FOUR_TAP
+};
+
 typedef enum {
   ORC_COMPILE_RESULT_OK = 0,
 
@@ -192,6 +200,7 @@ struct _OrcVariable {
   int ptr_offset;
   int mask_alloc;
   int aligned_data;
+  int sampling_type;
 };
 
 /**
@@ -409,6 +418,7 @@ struct _OrcExecutor {
   /* m is stored in params[ORC_VAR_A1] */
   /* m_index is stored in params[ORC_VAR_A2] */
   /* elapsed time is stored in params[ORC_VAR_A3] */
+  /* source resampling parameters are in params[ORC_VAR_C1..C8] */
 };
 
 /* the alternate view of OrcExecutor */
@@ -427,7 +437,8 @@ struct _OrcExecutorAlt {
   int m;
   int m_index;
   int time;
-  int unused2[ORC_VAR_P1-ORC_VAR_A4];
+  int unused2;
+  int src_resample[8];
   int params[ORC_VAR_T1-ORC_VAR_P1];
   int unused3[ORC_N_VARIABLES - ORC_VAR_T1];
   int accumulators[4];
@@ -507,6 +518,7 @@ int orc_program_add_constant (OrcProgram *program, int size, int value, const ch
 int orc_program_add_parameter (OrcProgram *program, int size, const char *name);
 int orc_program_add_accumulator (OrcProgram *program, int size, const char *name);
 void orc_program_set_type_name (OrcProgram *program, int var, const char *type_name);
+void orc_program_set_sampling_type (OrcProgram *program, int var, int sampling_type);
 
 OrcExecutor * orc_executor_new (OrcProgram *program);
 void orc_executor_free (OrcExecutor *ex);