Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libffi / testsuite / libffi.call / cls_multi_ushortchar.c
blob3379eeda1d3c32deac4e667476eb0b6070bd2cc6
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned short/char values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
7 /* { dg-do run { xfail mips64*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
10 unsigned short test_func_fn(unsigned char a1, unsigned short a2,
11 unsigned char a3, unsigned short a4)
13 unsigned short result;
15 result = a1 + a2 + a3 + a4;
17 printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
19 return result;
23 static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
25 unsigned char a1, a3;
26 unsigned short a2, a4;
28 a1 = *(unsigned char *)avals[0];
29 a2 = *(unsigned short *)avals[1];
30 a3 = *(unsigned char *)avals[2];
31 a4 = *(unsigned short *)avals[3];
33 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
37 typedef unsigned short (*test_type)(unsigned char, unsigned short,
38 unsigned char, unsigned short);
40 int main (void)
42 ffi_cif cif;
43 #ifndef USING_MMAP
44 static ffi_closure cl;
45 #endif
46 ffi_closure *pcl;
47 void * args_dbl[5];
48 ffi_type * cl_arg_types[5];
49 ffi_arg res_call;
50 unsigned char a, c;
51 unsigned short b, d, res_closure;
53 #ifdef USING_MMAP
54 pcl = allocate_mmap (sizeof(ffi_closure));
55 #else
56 pcl = &cl;
57 #endif
59 a = 1;
60 b = 2;
61 c = 127;
62 d = 128;
64 args_dbl[0] = &a;
65 args_dbl[1] = &b;
66 args_dbl[2] = &c;
67 args_dbl[3] = &d;
68 args_dbl[4] = NULL;
70 cl_arg_types[0] = &ffi_type_uchar;
71 cl_arg_types[1] = &ffi_type_ushort;
72 cl_arg_types[2] = &ffi_type_uchar;
73 cl_arg_types[3] = &ffi_type_ushort;
74 cl_arg_types[4] = NULL;
76 /* Initialize the cif */
77 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
78 &ffi_type_ushort, cl_arg_types) == FFI_OK);
80 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
81 /* { dg-output "1 2 127 128: 258" } */
82 printf("res: %d\n", res_call);
83 /* { dg-output "\nres: 258" } */
85 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
87 res_closure = (*((test_type)pcl))(1, 2, 127, 128);
88 /* { dg-output "\n1 2 127 128: 258" } */
89 printf("res: %d\n", res_closure);
90 /* { dg-output "\nres: 258" } */
92 exit(0);