1 /* Area: fp and variadics
2 Purpose: check fp inputs and returns work on variadics, even the fixed params
5 Originator: <david.gilbert@linaro.org> 2011-01-25
7 Intended to stress the difference in ABI on ARM vfp
16 /* prints out all the parameters, and returns the sum of them all.
17 * 'x' is the number of variadic parameters all of which are double in this test
19 double float_va_fn(unsigned int x
, double y
,...)
28 printf("%u: %.1f :", x
, y
);
33 double arg
=va_arg(ap
, double);
35 printf(" %d:%.1f ", i
, arg
);
39 printf(" total: %.1f\n", total
);
48 ffi_type
*arg_types
[5];
51 unsigned int firstarg
;
54 /* First test, pass float_va_fn(0,2.0) - note there are no actual
55 * variadic parameters, but it's declared variadic so the ABI may be
57 /* Call it statically and then via ffi */
58 resfp
=float_va_fn(0,2.0);
59 /* { dg-output "0: 2.0 : total: 2.0" } */
60 printf("compiled: %.1f\n", resfp
);
61 /* { dg-output "\ncompiled: 2.0" } */
63 arg_types
[0] = &ffi_type_uint
;
64 arg_types
[1] = &ffi_type_double
;
66 CHECK(ffi_prep_cif_var(&cif
, FFI_DEFAULT_ABI
, 2, 2,
67 &ffi_type_double
, arg_types
) == FFI_OK
);
71 values
[0] = &firstarg
;
72 values
[1] = &doubles
[0];
73 ffi_call(&cif
, FFI_FN(float_va_fn
), &resfp
, values
);
74 /* { dg-output "\n0: 2.0 : total: 2.0" } */
75 printf("ffi: %.1f\n", resfp
);
76 /* { dg-output "\nffi: 2.0" } */
78 /* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */
79 /* Call it statically and then via ffi */
80 resfp
=float_va_fn(2,2.0,3.0,4.0);
81 /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
82 printf("compiled: %.1f\n", resfp
);
83 /* { dg-output "\ncompiled: 11.0" } */
85 arg_types
[0] = &ffi_type_uint
;
86 arg_types
[1] = &ffi_type_double
;
87 arg_types
[2] = &ffi_type_double
;
88 arg_types
[3] = &ffi_type_double
;
90 CHECK(ffi_prep_cif_var(&cif
, FFI_DEFAULT_ABI
, 2, 4,
91 &ffi_type_double
, arg_types
) == FFI_OK
);
97 values
[0] = &firstarg
;
98 values
[1] = &doubles
[0];
99 values
[2] = &doubles
[1];
100 values
[3] = &doubles
[2];
101 ffi_call(&cif
, FFI_FN(float_va_fn
), &resfp
, values
);
102 /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
103 printf("ffi: %.1f\n", resfp
);
104 /* { dg-output "\nffi: 11.0" } */