aboutsummaryrefslogtreecommitdiff
path: root/tests/escapei_double.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/escapei_double.c')
-rw-r--r--tests/escapei_double.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/escapei_double.c b/tests/escapei_double.c
new file mode 100644
index 0000000..3165ece
--- /dev/null
+++ b/tests/escapei_double.c
@@ -0,0 +1,43 @@
+#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()
+{
+ 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_f(f, EJIT_FPR(0));
+ ejit_retr_f(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);
+}