summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Zapata <jorgeluis.zapata@gmail.com>2024-01-23 01:19:01 +0100
committerJorge Zapata <jorgeluis.zapata@gmail.com>2024-03-12 10:03:58 +0100
commit36c3c1c02d0e67e3b5ef383f9431eb22bfaa9a2a (patch)
treef23e3408917ef4635ae043a466acfc6b2de73132
parente07d0ec03712cbdab0076e4c4928e3042185be13 (diff)
Split the opcode code from the sys opcodes
Move the sys opcodes into its own file Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/148>
-rw-r--r--orc/meson.build3
-rw-r--r--orc/orcinternal.h2
-rw-r--r--orc/orcopcode.c160
-rw-r--r--orc/orcopcode.h1
-rw-r--r--orc/orcopcodes-sys.c (renamed from orc/orcopcodes.c)177
5 files changed, 166 insertions, 177 deletions
diff --git a/orc/meson.build b/orc/meson.build
index 8fc72eb..23dffb9 100644
--- a/orc/meson.build
+++ b/orc/meson.build
@@ -10,7 +10,8 @@ orc_sources = [
'orcexecutor.c',
'orcfunctions.c',
'orconce.c',
- 'orcopcodes.c',
+ 'orcopcode.c',
+ 'orcopcodes-sys.c',
'orcparse.c',
'orcprogram.c',
'orcprogram-c.c',
diff --git a/orc/orcinternal.h b/orc/orcinternal.h
index 812f2cd..d1355a0 100644
--- a/orc/orcinternal.h
+++ b/orc/orcinternal.h
@@ -38,6 +38,8 @@ void orc_compiler_emit_invariants (OrcCompiler *compiler);
int orc_program_has_float (OrcCompiler *compiler);
char* _orc_getenv (const char *var);
+void orc_opcode_sys_init (void);
+
#endif
ORC_END_DECLS
diff --git a/orc/orcopcode.c b/orc/orcopcode.c
new file mode 100644
index 0000000..53844f6
--- /dev/null
+++ b/orc/orcopcode.c
@@ -0,0 +1,160 @@
+#include "config.h"
+
+#include <string.h>
+
+#include <orc/orcprogram.h>
+#include <orc/orcdebug.h>
+#include <orc/orcinternal.h>
+
+/**
+ * SECTION:orcopcode
+ * @title: OrcOpcode
+ * @short_description: Operations
+ */
+
+
+static OrcOpcodeSet *opcode_sets;
+static int n_opcode_sets;
+
+#if 0
+int
+orc_opcode_get_list (OrcOpcode **list)
+{
+ (*list) = opcode_list;
+ return n_opcodes;
+}
+#endif
+
+#if 0
+void
+orc_opcode_register (const char *name, int n_dest, int n_src,
+ OrcOpcodeEmulateFunc emulate, void *user)
+{
+ OrcOpcode *opcode;
+
+ if (n_opcodes == n_opcodes_alloc) {
+ n_opcodes_alloc += 100;
+ opcode_list = realloc(opcode_list, sizeof(OrcOpcode) * n_opcodes_alloc);
+ }
+
+ opcode = opcode_list + n_opcodes;
+
+ opcode->name = strdup (name);
+ opcode->n_src = n_src;
+ opcode->n_dest = n_dest;
+ opcode->emulate = emulate;
+ opcode->emulate_user = user;
+
+ n_opcodes++;
+}
+#endif
+
+int
+orc_opcode_register_static (OrcStaticOpcode *sopcode, char *prefix)
+{
+ int n;
+ int major;
+
+ n = 0;
+ while (sopcode[n].name[0]) {
+ n++;
+ }
+
+ major = n_opcode_sets;
+
+ n_opcode_sets++;
+ opcode_sets = realloc (opcode_sets, sizeof(OrcOpcodeSet)*n_opcode_sets);
+
+ memset (opcode_sets + major, 0, sizeof(OrcOpcodeSet));
+ strncpy(opcode_sets[major].prefix, prefix, sizeof(opcode_sets[major].prefix)-1);
+ opcode_sets[major].n_opcodes = n;
+ opcode_sets[major].opcodes = sopcode;
+ opcode_sets[major].opcode_major = major;
+
+ return major;
+}
+
+OrcOpcodeSet *
+orc_opcode_set_get (const char *name)
+{
+ int i;
+
+ for(i=0;i<n_opcode_sets;i++){
+ if (strcmp (opcode_sets[i].prefix, name) == 0) {
+ return opcode_sets + i;
+ }
+ }
+
+ return NULL;
+}
+
+OrcOpcodeSet *
+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)
+{
+ int j;
+
+ for(j=0;j<opcode_set->n_opcodes;j++){
+ if (strcmp (name, opcode_set->opcodes[j].name) == 0) {
+ return j;
+ }
+ }
+
+ return -1;
+}
+
+OrcStaticOpcode *
+orc_opcode_find_by_name (const char *name)
+{
+ int i;
+ int j;
+
+ for(i=0;i<n_opcode_sets;i++){
+ j = orc_opcode_set_find_by_name (opcode_sets + i, name);
+ if (j >= 0) {
+ return &opcode_sets[i].opcodes[j];
+ }
+ }
+
+ return NULL;
+}
+
+void
+emulate_null (OrcOpcodeExecutor *ex, int offset, int n)
+{
+ /* This is a placeholder for adding new opcodes */
+ ORC_ERROR("emulate_null() called. This is a bug.");
+}
+
+void
+orc_opcode_init (void)
+{
+ orc_opcode_sys_init ();
+}
diff --git a/orc/orcopcode.h b/orc/orcopcode.h
index 5ec858e..6ac3b19 100644
--- a/orc/orcopcode.h
+++ b/orc/orcopcode.h
@@ -47,6 +47,7 @@ struct _OrcStaticOpcode {
ORC_API OrcStaticOpcode * orc_opcode_find_by_name (const char *name);
+/* FIXME 0.5 This should never be API */
ORC_API void orc_opcode_init (void);
ORC_API OrcOpcodeSet *orc_opcode_set_get (const char *name);
diff --git a/orc/orcopcodes.c b/orc/orcopcodes-sys.c
index 9280068..a4bdf19 100644
--- a/orc/orcopcodes.c
+++ b/orc/orcopcodes-sys.c
@@ -1,182 +1,9 @@
-
#include "config.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-
#include <orc/orcprogram.h>
#include <orc/orcdebug.h>
#include <orc/orcinternal.h>
-/**
- * SECTION:orcopcode
- * @title: OrcOpcode
- * @short_description: Operations
- */
-
-
-static OrcOpcodeSet *opcode_sets;
-static int n_opcode_sets;
-
-#define ORC_SB_MAX 127
-#define ORC_SB_MIN (-1-ORC_SB_MAX)
-#define ORC_UB_MAX 255
-#define ORC_UB_MIN 0
-#define ORC_SW_MAX 32767
-#define ORC_SW_MIN (-1-ORC_SW_MAX)
-#define ORC_UW_MAX 65535
-#define ORC_UW_MIN 0
-#define ORC_SL_MAX 2147483647
-#define ORC_SL_MIN (-1-ORC_SL_MAX)
-#define ORC_UL_MAX ORC_UINT64_C(4294967295)
-#define ORC_UL_MIN 0
-
-#define ORC_CLAMP_SB(x) ORC_CLAMP(x,ORC_SB_MIN,ORC_SB_MAX)
-#define ORC_CLAMP_UB(x) ORC_CLAMP(x,ORC_UB_MIN,ORC_UB_MAX)
-#define ORC_CLAMP_SW(x) ORC_CLAMP(x,ORC_SW_MIN,ORC_SW_MAX)
-#define ORC_CLAMP_UW(x) ORC_CLAMP(x,ORC_UW_MIN,ORC_UW_MAX)
-#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)
-
-#if 0
-int
-orc_opcode_get_list (OrcOpcode **list)
-{
- (*list) = opcode_list;
- return n_opcodes;
-}
-#endif
-
-#if 0
-void
-orc_opcode_register (const char *name, int n_dest, int n_src,
- OrcOpcodeEmulateFunc emulate, void *user)
-{
- OrcOpcode *opcode;
-
- if (n_opcodes == n_opcodes_alloc) {
- n_opcodes_alloc += 100;
- opcode_list = realloc(opcode_list, sizeof(OrcOpcode) * n_opcodes_alloc);
- }
-
- opcode = opcode_list + n_opcodes;
-
- opcode->name = strdup (name);
- opcode->n_src = n_src;
- opcode->n_dest = n_dest;
- opcode->emulate = emulate;
- opcode->emulate_user = user;
-
- n_opcodes++;
-}
-#endif
-
-int
-orc_opcode_register_static (OrcStaticOpcode *sopcode, char *prefix)
-{
- int n;
- int major;
-
- n = 0;
- while (sopcode[n].name[0]) {
- n++;
- }
-
- major = n_opcode_sets;
-
- n_opcode_sets++;
- opcode_sets = realloc (opcode_sets, sizeof(OrcOpcodeSet)*n_opcode_sets);
-
- memset (opcode_sets + major, 0, sizeof(OrcOpcodeSet));
- strncpy(opcode_sets[major].prefix, prefix, sizeof(opcode_sets[major].prefix)-1);
- opcode_sets[major].n_opcodes = n;
- opcode_sets[major].opcodes = sopcode;
- opcode_sets[major].opcode_major = major;
-
- return major;
-}
-
-OrcOpcodeSet *
-orc_opcode_set_get (const char *name)
-{
- int i;
-
- for(i=0;i<n_opcode_sets;i++){
- if (strcmp (opcode_sets[i].prefix, name) == 0) {
- return opcode_sets + i;
- }
- }
-
- return NULL;
-}
-
-OrcOpcodeSet *
-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)
-{
- int j;
-
- for(j=0;j<opcode_set->n_opcodes;j++){
- if (strcmp (name, opcode_set->opcodes[j].name) == 0) {
- return j;
- }
- }
-
- return -1;
-}
-
-OrcStaticOpcode *
-orc_opcode_find_by_name (const char *name)
-{
- int i;
- int j;
-
- for(i=0;i<n_opcode_sets;i++){
- j = orc_opcode_set_find_by_name (opcode_sets + i, name);
- if (j >= 0) {
- return &opcode_sets[i].opcodes[j];
- }
- }
-
- return NULL;
-}
-
-void
-emulate_null (OrcOpcodeExecutor *ex, int offset, int n)
-{
- /* This is a placeholder for adding new opcodes */
- ORC_ERROR("emulate_null() called. This is a bug.");
-}
-
#include "orc/orcemulateopcodes.h"
static OrcStaticOpcode opcodes[] = {
@@ -402,9 +229,7 @@ static OrcStaticOpcode opcodes[] = {
};
void
-orc_opcode_init (void)
+orc_opcode_sys_init (void)
{
orc_opcode_register_static (opcodes, "sys");
}
-
-