aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-08-02 20:54:08 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-08-02 20:54:08 +0300
commit9251fddfdfb11b9e1b2dff643aa20ec82e9f7036 (patch)
treefa6045ac60ab66cfd04b820d50b9f92f86f2bfc7
parent6c12792402503705bf921d56ea3b309408bb417a (diff)
downloadcopyjit-9251fddfdfb11b9e1b2dff643aa20ec82e9f7036.tar.gz
copyjit-9251fddfdfb11b9e1b2dff643aa20ec82e9f7036.zip
add return values to main loop
-rw-r--r--lib/imm.h56
-rw-r--r--ops/common.h13
-rw-r--r--ops/end.c3
-rw-r--r--src/copyjit.c5
-rw-r--r--src/copyjit.h2
-rw-r--r--src/main.c11
6 files changed, 43 insertions, 47 deletions
diff --git a/lib/imm.h b/lib/imm.h
index 0aaf608..1ee7e1e 100644
--- a/lib/imm.h
+++ b/lib/imm.h
@@ -1,51 +1,43 @@
#ifndef COPYJIT_IMM_H
#define COPYJIT_IMM_H
unsigned char gen_addia[] = {
- 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0xbe, 0x95,
- 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x48, 0x03, 0x35, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_addia_len = 28;
+unsigned int gen_addia_len = 20;
unsigned char gen_addio[] = {
- 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0x3e, 0x97,
- 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x4c, 0x03, 0x05, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_addio_len = 28;
+unsigned int gen_addio_len = 20;
unsigned char gen_addix[] = {
- 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0x3e, 0x96,
- 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x48, 0x03, 0x15, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_addix_len = 28;
+unsigned int gen_addix_len = 20;
unsigned char gen_addiy[] = {
- 0x97, 0x07, 0x00, 0x00, 0x93, 0x87, 0x47, 0x01, 0x9c, 0x63, 0xbe, 0x96,
- 0x17, 0x03, 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
+ 0x48, 0x03, 0x0d, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_addiy_len = 28;
+unsigned int gen_addiy_len = 20;
unsigned char gen_lia[] = {
- 0x97, 0x05, 0x00, 0x00, 0x93, 0x85, 0x25, 0x01, 0x8c, 0x61, 0x17, 0x03,
- 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00
+ 0x48, 0x8b, 0x35, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_lia_len = 26;
+unsigned int gen_lia_len = 20;
unsigned char gen_lio[] = {
- 0x17, 0x07, 0x00, 0x00, 0x13, 0x07, 0x27, 0x01, 0x18, 0x63, 0x17, 0x03,
- 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00
+ 0x4c, 0x8b, 0x05, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_lio_len = 26;
+unsigned int gen_lio_len = 20;
unsigned char gen_lix[] = {
- 0x17, 0x06, 0x00, 0x00, 0x13, 0x06, 0x26, 0x01, 0x10, 0x62, 0x17, 0x03,
- 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00
+ 0x48, 0x8b, 0x15, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_lix_len = 26;
+unsigned int gen_lix_len = 20;
unsigned char gen_liy[] = {
- 0x97, 0x06, 0x00, 0x00, 0x93, 0x86, 0x26, 0x01, 0x94, 0x62, 0x17, 0x03,
- 0x00, 0x00, 0x67, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00
+ 0x48, 0x8b, 0x0d, 0x05, 0x00, 0x00, 0x00, 0xe9, 0x08, 0x00, 0x00, 0x00,
+ 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
};
-unsigned int gen_liy_len = 26;
+unsigned int gen_liy_len = 20;
#endif /* COPYJIT_OPS_H */
diff --git a/ops/common.h b/ops/common.h
index 546b064..6b124b3 100644
--- a/ops/common.h
+++ b/ops/common.h
@@ -6,19 +6,22 @@
typedef unsigned long reg_t;
typedef signed long sreg_t;
-typedef void (*op_call)(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o);
+typedef reg_t (*op_call)(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o);
#define NEXT_OP(sp, a, x, y, o) \
- ((op_call)(&__next_op))((sp), (a), (x), (y), (o));
+ return ((op_call)(&__next_op))((sp), (a), (x), (y), (o));
-#define JUMP(target, sp, a, x, y, o) \
+#define CALL(target, sp, a, x, y, o) \
((op_call)(target))((sp), (a), (x), (y), (o));
+#define JUMP(target, sp, a, x, y, o) \
+ return CALL(target, sp, a, x, y, o);
+
#define BRANCH(target, cond, sp, a, x, y, o) \
- ((op_call)((cond) ? (void *)(target) : (void *)&__next_op)) \
+ return ((op_call)((cond) ? (void *)(target) : (void *)&__next_op)) \
((sp), (a), (x), (y), (o)); \
-#define DEFINE_OP(name) void _op(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o)
+#define DEFINE_OP(name) reg_t _op(reg_t *sp, reg_t a, reg_t x, reg_t y, reg_t o)
#define UNUSED(x) (void)(x);
diff --git a/ops/end.c b/ops/end.c
index 3abf4e0..34f2d9d 100644
--- a/ops/end.c
+++ b/ops/end.c
@@ -6,8 +6,7 @@ DEFINE_OP(end)
{
UNUSED(sp);
UNUSED(a);
- UNUSED(x);
UNUSED(y);
UNUSED(o);
- return;
+ return x;
}
diff --git a/src/copyjit.c b/src/copyjit.c
index f09cb99..393c8e1 100644
--- a/src/copyjit.c
+++ b/src/copyjit.c
@@ -476,9 +476,10 @@ void compile_finish(ctx_t *ctx)
__builtin___clear_cache(ctx->buf, ctx->buf + ctx->size);
}
-void run(ctx_t *ctx)
+unsigned long run(ctx_t *ctx)
{
void *sp = malloc(4096);
- JUMP(ctx->buf, sp, 0, 0, 0, 0);
+ unsigned long a = CALL(ctx->buf, sp, 0, 0, 0, 0);
free(sp);
+ return a;
}
diff --git a/src/copyjit.h b/src/copyjit.h
index 6c0a247..d752144 100644
--- a/src/copyjit.h
+++ b/src/copyjit.h
@@ -32,6 +32,6 @@ void *compile_sly(ctx_t *ctx, unsigned long i);
void compile_start(ctx_t *ctx);
void compile_finish(ctx_t *ctx);
-void run(ctx_t *ctx);
+unsigned long run(ctx_t *ctx);
#endif /* HMMJIT_H */
diff --git a/src/main.c b/src/main.c
index 78f9f9e..de287f6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: copyleft-next-0.3.1 */
#include <stdint.h>
+#include <stdio.h>
#include <stddef.h>
#include "copyjit.h"
@@ -10,12 +11,12 @@ int main()
ctx_t ctx;
compile_start(&ctx);
- compile_fast_lia(&ctx, 0); // total in a
+ compile_fast_lix(&ctx, 0); // total in x
- compile_fast_liy(&ctx, 0);
+ compile_fast_liy(&ctx, 0); // iter in y
- void *top = compile_movxa(&ctx); // iter + total in a
- compile_add(&ctx);
+ void *top = compile_add(&ctx); // iter + total in a
+ compile_movxa(&ctx); // move total to x
compile_incy(&ctx); // increment iter
compile_fast_lio(&ctx, 1000000000); // limit in o
@@ -30,5 +31,5 @@ int main()
compile_finish(&ctx);
- run(&ctx);
+ printf("%lu\n", run(&ctx));
}