Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

cls_longdouble.c
Go to the documentation of this file.
1 /* Area: ffi_call, closure_call
2 Purpose: Check long double arguments.
3 Limitations: none.
4 PR: none.
5 Originator: Blake Chaffin */
6
7 /* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
8 /* This test is known to PASS on armv7l-unknown-linux-gnueabihf, so I have
9 remove the xfail for arm*-*-* below, until we know more. */
10 /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
11 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
12 /* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*-msys* } } */
13
14 #include "ffitest.h"
15
16 long double cls_ldouble_fn(
17 long double a1,
18 long double a2,
19 long double a3,
20 long double a4,
21 long double a5,
22 long double a6,
23 long double a7,
24 long double a8)
25 {
26 long double r = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8;
27
28 printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: %Lg\n",
29 a1, a2, a3, a4, a5, a6, a7, a8, r);
30
31 return r;
32 }
33
34 static void
35 cls_ldouble_gn(ffi_cif* cif __UNUSED__, void* resp,
36 void** args, void* userdata __UNUSED__)
37 {
38 long double a1 = *(long double*)args[0];
39 long double a2 = *(long double*)args[1];
40 long double a3 = *(long double*)args[2];
41 long double a4 = *(long double*)args[3];
42 long double a5 = *(long double*)args[4];
43 long double a6 = *(long double*)args[5];
44 long double a7 = *(long double*)args[6];
45 long double a8 = *(long double*)args[7];
46
47 *(long double*)resp = cls_ldouble_fn(
48 a1, a2, a3, a4, a5, a6, a7, a8);
49 }
50
51 int main(void)
52 {
53 ffi_cif cif;
54 void* code;
55 ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
56 void* args[9];
57 ffi_type* arg_types[9];
58 long double res = 0;
59
60 long double arg1 = 1;
61 long double arg2 = 2;
62 long double arg3 = 3;
63 long double arg4 = 4;
64 long double arg5 = 5;
65 long double arg6 = 6;
66 long double arg7 = 7;
67 long double arg8 = 8;
68
69 arg_types[0] = &ffi_type_longdouble;
70 arg_types[1] = &ffi_type_longdouble;
71 arg_types[2] = &ffi_type_longdouble;
72 arg_types[3] = &ffi_type_longdouble;
73 arg_types[4] = &ffi_type_longdouble;
74 arg_types[5] = &ffi_type_longdouble;
75 arg_types[6] = &ffi_type_longdouble;
76 arg_types[7] = &ffi_type_longdouble;
77 arg_types[8] = NULL;
78
79 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 8, &ffi_type_longdouble,
80 arg_types) == FFI_OK);
81
82 args[0] = &arg1;
83 args[1] = &arg2;
84 args[2] = &arg3;
85 args[3] = &arg4;
86 args[4] = &arg5;
87 args[5] = &arg6;
88 args[6] = &arg7;
89 args[7] = &arg8;
90 args[8] = NULL;
91
92 ffi_call(&cif, FFI_FN(cls_ldouble_fn), &res, args);
93 /* { dg-output "1 2 3 4 5 6 7 8: 36" } */
94 printf("res: %Lg\n", res);
95 /* { dg-output "\nres: 36" } */
96
97 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ldouble_gn, NULL, code) == FFI_OK);
98
99 res = ((long double(*)(long double, long double, long double, long double,
100 long double, long double, long double, long double))(code))(arg1, arg2,
101 arg3, arg4, arg5, arg6, arg7, arg8);
102 /* { dg-output "\n1 2 3 4 5 6 7 8: 36" } */
103 printf("res: %Lg\n", res);
104 /* { dg-output "\nres: 36" } */
105
106 return 0;
107 }
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
ffitest.h
double
double
Definition: rb_mjit_min_header-2.7.0.h:5923
cls_ldouble_fn
long double cls_ldouble_fn(long double a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7, long double a8)
Definition: cls_longdouble.c:16
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
main
int main(void)
Definition: cls_longdouble.c:51
ffi_prep_cif
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928