OSDN Git Service

* src/sh/sysv.S (ffi_call_SYSV): Don't align for double data.
[pf3gnuchains/gcc-fork.git] / libffi / testsuite / libffi.call / float3.c
1 /* Area:        ffi_call
2    Purpose:     Check float arguments with different orders.
3    Limitations: none.
4    PR:          none.
5    Originator:  From the original ffitest.c  */
6
7 /* { dg-do run } */
8 /* { dg-options -mlong-double-128 { target powerpc64*-*-* } } */
9
10 #include "ffitest.h"
11 #include "float.h"
12
13 static double floating_1(float a, double b, long double c)
14 {
15   return (double) a + b + (double) c;
16 }
17
18 static double floating_2(long double a, double b, float c)
19 {
20   return (double) a + b + (double) c;
21 }
22
23 int main (void)
24 {
25   ffi_cif cif;
26   ffi_type *args[MAX_ARGS];
27   void *values[MAX_ARGS];
28   double rd;
29
30   float f;
31   double d;
32   long double ld;
33
34   args[0] = &ffi_type_float;
35   values[0] = &f;
36   args[1] = &ffi_type_double;
37   values[1] = &d;
38   args[2] = &ffi_type_longdouble;
39   values[2] = &ld;
40
41   /* Initialize the cif */
42   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
43                      &ffi_type_double, args) == FFI_OK);
44
45   f = 3.14159;
46   d = (double)1.0/(double)3.0;
47   ld = 2.71828182846L;
48
49   floating_1 (f, d, ld);
50
51   ffi_call(&cif, FFI_FN(floating_1), &rd, values);
52
53   CHECK(rd - floating_1(f, d, ld) < DBL_EPSILON);
54
55   args[0] = &ffi_type_longdouble;
56   values[0] = &ld;
57   args[1] = &ffi_type_double;
58   values[1] = &d;
59   args[2] = &ffi_type_float;
60   values[2] = &f;
61
62   /* Initialize the cif */
63   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
64                      &ffi_type_double, args) == FFI_OK);
65
66   floating_2 (ld, d, f);
67
68   ffi_call(&cif, FFI_FN(floating_2), &rd, values);
69
70   CHECK(rd - floating_2(ld, d, f) < DBL_EPSILON);
71
72   exit (0);
73 }