diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 21:28:39 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-08-04 21:28:39 +0300 |
| commit | bf993be4a04bc7279f7d49ae18f185e1dca36479 (patch) | |
| tree | aa38bf9ea3c172a2847e818ff05599a15fe1c2cb /examples | |
| parent | 09f8df9f7e1166be48cdd6b1caba0f6771dd753e (diff) | |
| download | copyjit-bf993be4a04bc7279f7d49ae18f185e1dca36479.tar.gz copyjit-bf993be4a04bc7279f7d49ae18f185e1dca36479.zip | |
move main.c to examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/main.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 0000000..94e372b --- /dev/null +++ b/examples/main.c @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: copyleft-next-0.3.1 */ + +#include <stdint.h> +#include <stdio.h> +#include <stddef.h> + +#include "../src/copyjit.h" + +int main() +{ + ctx_t ctx; + compile_start(&ctx); + + compile_fast_lix(&ctx, 0); // total in x + + compile_fast_liy(&ctx, 0); // iter in y + + 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 + compile_subyo(&ctx); + + compile_fast_lio(&ctx, (uintptr_t)top); // branch target in o + /* if we already know the offset, we could generate a ban with immediate + * offsets to save one register? */ + compile_ban(&ctx); + + compile_end(&ctx); + + compile_finish(&ctx); + + printf("%lu\n", run(&ctx)); +} |
