aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 78f9f9e173d1797d35264c845b1524a036d55dfc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* SPDX-License-Identifier: copyleft-next-0.3.1 */

#include <stdint.h>
#include <stddef.h>

#include "copyjit.h"

int main()
{
	ctx_t ctx;
	compile_start(&ctx);

	compile_fast_lia(&ctx, 0); // total in a

	compile_fast_liy(&ctx, 0);

	void *top = compile_movxa(&ctx); // iter + total in a
	compile_add(&ctx);

	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);

	run(&ctx);
}