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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include <ejit/ejit.h>
#include <assert.h>
#include "do_jit.h"
struct args
{
int8_t a;
int16_t b;
int32_t c;
long d;
uint16_t e;
float f;
double g;
float h;
};
int main(int argc, char *argv[])
{
(void)argv;
bool do_jit = argc > 1;
struct ejit_operand operands[9] = {
EJIT_OPERAND_GPR(0, EJIT_POINTER),
EJIT_OPERAND_GPR(1, EJIT_INT8),
EJIT_OPERAND_GPR(2, EJIT_INT16),
EJIT_OPERAND_GPR(3, EJIT_INT32),
EJIT_OPERAND_GPR(4, EJIT_TYPE(long)),
EJIT_OPERAND_GPR(5, EJIT_UINT16),
EJIT_OPERAND_FPR(0, EJIT_FLOAT),
EJIT_OPERAND_FPR(1, EJIT_DOUBLE),
EJIT_OPERAND_FPR(2, EJIT_FLOAT)
};
struct ejit_func *f = ejit_create_func(EJIT_POINTER, 9, operands);
EJIT_STXI(f, int8_t,
EJIT_GPR(1), EJIT_GPR(0), offsetof(struct args, a)); // a
EJIT_STXI(f, int16_t,
EJIT_GPR(2), EJIT_GPR(0), offsetof(struct args, b)); // b
EJIT_STXI(f, int32_t,
EJIT_GPR(3), EJIT_GPR(0), offsetof(struct args, c)); // c
EJIT_STXI(f, long,
EJIT_GPR(4), EJIT_GPR(0), offsetof(struct args, d)); // d
EJIT_STXI(f, uint16_t,
EJIT_GPR(5), EJIT_GPR(0), offsetof(struct args, e)); // e
EJIT_STXI(f, float,
EJIT_FPR(0), EJIT_GPR(0), offsetof(struct args, f)); // f
EJIT_STXI(f, double,
EJIT_FPR(1), EJIT_GPR(0), offsetof(struct args, g)); // g
EJIT_STXI(f, float,
EJIT_FPR(2), EJIT_GPR(0), offsetof(struct args, h)); // h
ejit_retr(f, EJIT_GPR(0));
ejit_select_compile_func(f, 6, 3, EJIT_USE64(long), do_jit, true);
struct args in = { 0, 1, 2, 3, 4, 5, 6, 7 };
struct args out;
struct ejit_arg args[9] = {
EJIT_ARG(&out, void *),
EJIT_ARG(in.a, int8_t),
EJIT_ARG(in.b, int16_t),
EJIT_ARG(in.c, int32_t),
EJIT_ARG(in.d, long),
EJIT_ARG(in.e, uint16_t),
EJIT_ARG(in.f, float),
EJIT_ARG(in.g, double),
EJIT_ARG(in.h, float)
};
assert((void *)ejit_run_func_i(f, 9, args) == &out);
assert(in.a == out.a);
assert(in.b == out.b);
assert(in.c == out.c);
assert(in.d == out.d);
assert(in.e == out.e);
assert(in.f == out.f);
assert(in.g == out.g);
assert(in.h == out.h);
ejit_destroy_func(f);
}
|