aboutsummaryrefslogtreecommitdiff
path: root/tests/escapei_double.c
blob: bae6902f3f4fa0f74e0b34b4339c4bd68f826aef (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
35
36
37
38
39
40
41
42
43
44
45
#include <ejit/ejit.h>
#include <assert.h>
#include "do_jit.h"

static double func(int32_t a, double b) {
	return b + a;
}

static double escape_func(size_t argc, const struct ejit_arg args[argc])
{
	assert(argc == 2);
	assert(args[0].type == EJIT_INT32);
	assert(args[1].type == EJIT_DOUBLE);
	int32_t a = args[0].i32;
	double b = args[1].d;
	return func(a, b);
}

int main(int argc, char *argv[])
{
	(void)argv;
	bool do_jit = argc > 1;
	struct ejit_operand operands[2] = {
		EJIT_OPERAND_GPR(0, EJIT_POINTER),
		EJIT_OPERAND_GPR(1, EJIT_POINTER)
	};

	struct ejit_func *f = ejit_create_func(EJIT_DOUBLE, 2, operands);
	EJIT_LDXI(f, int32_t, EJIT_GPR(0), EJIT_GPR(0), 0);
	EJIT_LDXI(f, double, EJIT_FPR(0), EJIT_GPR(1), 0);

	struct ejit_operand args[2] = {
		EJIT_OPERAND_GPR(0, EJIT_INT32),
		EJIT_OPERAND_FPR(0, EJIT_DOUBLE)
	};
	ejit_escapei_f(f, escape_func, 2, args);
	ejit_retval_d(f, EJIT_FPR(0));
	ejit_retr_d(f, EJIT_FPR(0));

	ejit_select_compile_func(f, 2, 1, false, do_jit);

	double d = 22.0f;
	int32_t i = 20;
	assert(erff2(f, EJIT_ARG(&i, void *), EJIT_ARG(&d, void *)) == 42.0f);
}