| 1 |
/* Area: fp and variadics |
| 2 |
Purpose: check fp inputs and returns work on variadics, even the fixed params |
| 3 |
Limitations: None |
| 4 |
PR: none |
| 5 |
Originator: <[email protected]> 2011-01-25 |
| 6 |
|
| 7 |
Intended to stress the difference in ABI on ARM vfp |
| 8 |
*/ |
| 9 |
|
| 10 |
/* { dg-do run } */ |
| 11 |
|
| 12 |
#include <stdarg.h> |
| 13 |
|
| 14 |
#include "ffitest.h" |
| 15 |
|
| 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 |
| 18 |
*/ |
| 19 |
double float_va_fn(unsigned int x, double y,...) |
| 20 |
{ |
| 21 |
double total=0.0; |
| 22 |
va_list ap; |
| 23 |
unsigned int i; |
| 24 |
|
| 25 |
total+=(double)x; |
| 26 |
total+=y; |
| 27 |
|
| 28 |
printf("%u: %.1f :", x, y); |
| 29 |
|
| 30 |
va_start(ap, y); |
| 31 |
for(i=0;i<x;i++) |
| 32 |
{ |
| 33 |
double arg=va_arg(ap, double); |
| 34 |
total+=arg; |
| 35 |
printf(" %d:%.1f ", i, arg); |
| 36 |
} |
| 37 |
va_end(ap); |
| 38 |
|
| 39 |
printf(" total: %.1f\n", total); |
| 40 |
|
| 41 |
return total; |
| 42 |
} |
| 43 |
|
| 44 |
int main (void) |
| 45 |
{ |
| 46 |
ffi_cif cif; |
| 47 |
|
| 48 |
ffi_type *arg_types[5]; |
| 49 |
void *values[5]; |
| 50 |
double doubles[5]; |
| 51 |
unsigned int firstarg; |
| 52 |
double resfp; |
| 53 |
|
| 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 |
| 56 |
* different. */ |
| 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" } */ |
| 62 |
|
| 63 |
arg_types[0] = &ffi_type_uint; |
| 64 |
arg_types[1] = &ffi_type_double; |
| 65 |
arg_types[2] = NULL; |
| 66 |
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 2, |
| 67 |
&ffi_type_double, arg_types) == FFI_OK); |
| 68 |
|
| 69 |
firstarg = 0; |
| 70 |
doubles[0] = 2.0; |
| 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" } */ |
| 77 |
CHECK_DOUBLE_EQ(resfp, 2); |
| 78 |
|
| 79 |
/* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */ |
| 80 |
/* Call it statically and then via ffi */ |
| 81 |
resfp=float_va_fn(2,2.0,3.0,4.0); |
| 82 |
/* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ |
| 83 |
printf("compiled: %.1f\n", resfp); |
| 84 |
/* { dg-output "\ncompiled: 11.0" } */ |
| 85 |
CHECK_DOUBLE_EQ(resfp, 11); |
| 86 |
|
| 87 |
arg_types[0] = &ffi_type_uint; |
| 88 |
arg_types[1] = &ffi_type_double; |
| 89 |
arg_types[2] = &ffi_type_double; |
| 90 |
arg_types[3] = &ffi_type_double; |
| 91 |
arg_types[4] = NULL; |
| 92 |
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 4, |
| 93 |
&ffi_type_double, arg_types) == FFI_OK); |
| 94 |
|
| 95 |
firstarg = 2; |
| 96 |
doubles[0] = 2.0; |
| 97 |
doubles[1] = 3.0; |
| 98 |
doubles[2] = 4.0; |
| 99 |
values[0] = &firstarg; |
| 100 |
values[1] = &doubles[0]; |
| 101 |
values[2] = &doubles[1]; |
| 102 |
values[3] = &doubles[2]; |
| 103 |
ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values); |
| 104 |
/* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */ |
| 105 |
printf("ffi: %.1f\n", resfp); |
| 106 |
/* { dg-output "\nffi: 11.0" } */ |
| 107 |
CHECK_DOUBLE_EQ(resfp, 11); |
| 108 |
|
| 109 |
exit(0); |
| 110 |
} |