summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Zapata <jorgeluis.zapata@gmail.com>2024-01-23 00:47:36 +0100
committerJorge Zapata <jorgeluis.zapata@gmail.com>2024-03-12 10:03:58 +0100
commit2a9a1637166d6ddfe5dda6564a7d05dbf3749f15 (patch)
tree79778414b5349829da244dec91e77e4001250301
parentc8ddd610f4a8385d59ce9a2b65542c3b68703a9f (diff)
Move the target code into its own source file
Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/148>
-rw-r--r--orc/meson.build1
-rw-r--r--orc/orcopcode.h4
-rw-r--r--orc/orcopcodes.c145
-rw-r--r--orc/orctarget.c123
4 files changed, 150 insertions, 123 deletions
diff --git a/orc/meson.build b/orc/meson.build
index 62cf077..7c95b0a 100644
--- a/orc/meson.build
+++ b/orc/meson.build
@@ -14,6 +14,7 @@ orc_sources = [
'orcprogram.c',
'orcprogram-c.c',
'orcrule.c',
+ 'orctarget.c',
'orcutils.c',
]
diff --git a/orc/orcopcode.h b/orc/orcopcode.h
index 1e669b3..5ec858e 100644
--- a/orc/orcopcode.h
+++ b/orc/orcopcode.h
@@ -57,6 +57,10 @@ ORC_API int orc_opcode_set_find_by_name (OrcOpcodeSet *opcode_set, const char *n
ORC_API int orc_opcode_register_static (OrcStaticOpcode *sopcode, char *prefix);
+#ifdef ORC_ENABLE_UNSTABLE_API
+ORC_API OrcOpcodeSet * orc_opcode_set_find_by_opcode (OrcStaticOpcode * opcode);
+#endif
+
ORC_END_DECLS
#endif
diff --git a/orc/orcopcodes.c b/orc/orcopcodes.c
index 1d7f051..9d6d560 100644
--- a/orc/orcopcodes.c
+++ b/orc/orcopcodes.c
@@ -20,11 +20,6 @@
static OrcOpcodeSet *opcode_sets;
static int n_opcode_sets;
-static OrcTarget *targets[ORC_N_TARGETS];
-static int n_targets;
-
-static OrcTarget *default_target;
-
#define ORC_SB_MAX 127
#define ORC_SB_MIN (-1-ORC_SB_MAX)
#define ORC_UB_MAX 255
@@ -45,97 +40,6 @@ static OrcTarget *default_target;
#define ORC_CLAMP_SL(x) ORC_CLAMP(x,ORC_SL_MIN,ORC_SL_MAX)
#define ORC_CLAMP_UL(x) ORC_CLAMP(x,ORC_UL_MIN,ORC_UL_MAX)
-
-void
-orc_target_register (OrcTarget *target)
-{
- targets[n_targets] = target;
- n_targets++;
-
- if (target->executable) {
- default_target = target;
- }
-}
-
-OrcTarget *
-orc_target_get_by_name (const char *name)
-{
- int i;
-
- if (name == NULL) return orc_target_get_default();
-
- for(i=0;i<n_targets;i++){
- if (strcmp (name, targets[i]->name) == 0) {
- return targets[i];
- }
- }
-
- return NULL;
-}
-
-OrcTarget *
-orc_target_get_default (void)
-{
- OrcTarget *target = NULL;
- const char *const name = _orc_getenv ("ORC_TARGET");
-
- if (name) {
- target = orc_target_get_by_name (name);
- if (!target) {
- ORC_ERROR ("Target '%s' not found, using default", name);
- }
- }
-
- free ((void *)name);
-
- if (target != NULL) {
- return target;
- }
-
- return default_target;
-}
-
-const char *
-orc_target_get_name (OrcTarget *target)
-{
- if (target == NULL) return NULL;
- return target->name;
-}
-
-unsigned int
-orc_target_get_default_flags (OrcTarget *target)
-{
- if (target == NULL) return 0;
- return target->get_default_flags();
-}
-
-const char *
-orc_target_get_preamble (OrcTarget *target)
-{
- if (target->get_asm_preamble == NULL) return "";
-
- return target->get_asm_preamble ();
-}
-
-const char *
-orc_target_get_asm_preamble (const char *target)
-{
- OrcTarget *t;
-
- t = orc_target_get_by_name (target);
- if (t == NULL) return "";
-
- return orc_target_get_preamble (t);
-}
-
-const char *
-orc_target_get_flag_name (OrcTarget *target, int shift)
-{
- if (target->get_flag_name == NULL) return "";
-
- return target->get_flag_name (shift);
-}
-
#if 0
int
orc_opcode_get_list (OrcOpcode **list)
@@ -189,33 +93,6 @@ orc_rule_set_new (OrcOpcodeSet *opcode_set, OrcTarget *target,
return rule_set;
}
-OrcRule *
-orc_target_get_rule (OrcTarget *target, OrcStaticOpcode *opcode,
- unsigned int target_flags)
-{
- OrcRule *rule;
- int i;
- int j;
- int k;
-
- for(k=0;k<n_opcode_sets;k++){
- j = opcode - opcode_sets[k].opcodes;
-
- if (j < 0 || j >= opcode_sets[k].n_opcodes) continue;
- if (opcode_sets[k].opcodes + j != opcode) continue;
-
- for(i=target->n_rule_sets-1;i>=0;i--){
- if (target->rule_sets[i].opcode_major != opcode_sets[k].opcode_major) continue;
- if (target->rule_sets[i].required_target_flags & (~target_flags)) continue;
-
- rule = target->rule_sets[i].rules + j;
- if (rule->emit) return rule;
- }
- }
-
- return NULL;
-}
-
int
orc_opcode_register_static (OrcStaticOpcode *sopcode, char *prefix)
{
@@ -261,6 +138,28 @@ orc_opcode_set_get_nth (int opcode_major)
return opcode_sets + opcode_major;
}
+OrcOpcodeSet *
+orc_opcode_set_find_by_opcode (OrcStaticOpcode * opcode)
+{
+ int k;
+ int j;
+
+ /* Pointer arithmetic to find a pointer inside an array ...
+ */
+ for (k = 0; k < n_opcode_sets; k++) {
+ j = opcode - opcode_sets[k].opcodes;
+
+ if (j < 0 || j >= opcode_sets[k].n_opcodes) continue;
+ if (opcode_sets[k].opcodes + j != opcode) continue;
+
+ return &opcode_sets[k];
+ }
+
+ return NULL;
+}
+
+/* FIXME This is wrongly named, you are finding the index of the opcode on a specific opcode set
+ */
int
orc_opcode_set_find_by_name (OrcOpcodeSet *opcode_set, const char *name)
{
diff --git a/orc/orctarget.c b/orc/orctarget.c
new file mode 100644
index 0000000..86f4fb2
--- /dev/null
+++ b/orc/orctarget.c
@@ -0,0 +1,123 @@
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <orc/orctarget.h>
+#include <orc/orcinternal.h>
+
+static OrcTarget *targets[ORC_N_TARGETS];
+static int n_targets;
+
+static OrcTarget *default_target;
+
+void
+orc_target_register (OrcTarget *target)
+{
+ targets[n_targets] = target;
+ n_targets++;
+
+ if (target->executable) {
+ default_target = target;
+ }
+}
+
+OrcTarget *
+orc_target_get_by_name (const char *name)
+{
+ int i;
+
+ if (name == NULL) return orc_target_get_default();
+
+ for(i=0;i<n_targets;i++){
+ if (strcmp (name, targets[i]->name) == 0) {
+ return targets[i];
+ }
+ }
+
+ return NULL;
+}
+
+OrcTarget *
+orc_target_get_default (void)
+{
+ const char *const envvar = _orc_getenv ("ORC_BACKEND");
+
+ if (envvar != NULL) {
+ OrcTarget *const target = orc_target_get_by_name (envvar);
+
+ if (target != NULL)
+ return target;
+ }
+
+ return default_target;
+}
+
+const char *
+orc_target_get_name (OrcTarget *target)
+{
+ if (target == NULL) return NULL;
+ return target->name;
+}
+
+unsigned int
+orc_target_get_default_flags (OrcTarget *target)
+{
+ if (target == NULL) return 0;
+ return target->get_default_flags();
+}
+
+const char *
+orc_target_get_preamble (OrcTarget *target)
+{
+ if (target->get_asm_preamble == NULL) return "";
+
+ return target->get_asm_preamble ();
+}
+
+const char *
+orc_target_get_asm_preamble (const char *target)
+{
+ OrcTarget *t;
+
+ t = orc_target_get_by_name (target);
+ if (t == NULL) return "";
+
+ return orc_target_get_preamble (t);
+}
+
+const char *
+orc_target_get_flag_name (OrcTarget *target, int shift)
+{
+ if (target->get_flag_name == NULL) return "";
+
+ return target->get_flag_name (shift);
+}
+
+/* FIXME the order of parameters should not be this,
+ * first the target + flags, then the opcode
+ */
+OrcRule *
+orc_target_get_rule (OrcTarget *target, OrcStaticOpcode *opcode,
+ unsigned int target_flags)
+{
+ OrcOpcodeSet *opcode_set;
+ OrcRule *rule;
+ int i;
+ int j;
+
+
+ /* FIXME yes, we are iterating twice */
+ opcode_set = orc_opcode_set_find_by_opcode (opcode);
+ j = orc_opcode_set_find_by_name (opcode_set, opcode->name);
+
+ for (i = target->n_rule_sets - 1; i >= 0; i--) {
+ if (target->rule_sets[i].opcode_major != opcode_set->opcode_major) continue;
+ if (target->rule_sets[i].required_target_flags & (~target_flags)) continue;
+
+ /* A rule set has the same number of rules as the opcode_set has opcodes */
+ rule = target->rule_sets[i].rules + j;
+ if (rule->emit) return rule;
+ }
+
+ return NULL;
+}