OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libffi/] [testsuite/] [libffi.call/] [cls_align_longdouble_split2.c] - Blame information for rev 841

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 732 jeremybenn
/*      Area:                   ffi_call, closure_call
2
        Purpose:                Check structure alignment of long double.
3
        Limitations:    none.
4
        PR:                             none.
5
        Originator:             Blake Chaffin   6/18/2007
6
*/
7
 
8
/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
9
/* { dg-do run { xfail strongarm*-*-* } } */
10
/* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
11
/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
12
 
13
#include "ffitest.h"
14
 
15
typedef struct cls_struct_align {
16
  long double a;
17
  long double b;
18
  long double c;
19
  long double d;
20
  long double e;
21
  double f;
22
  long double g;
23
} cls_struct_align;
24
 
25
cls_struct_align cls_struct_align_fn(
26
        cls_struct_align        a1,
27
        cls_struct_align        a2)
28
{
29
        struct cls_struct_align r;
30
 
31
        r.a = a1.a + a2.a;
32
        r.b = a1.b + a2.b;
33
        r.c = a1.c + a2.c;
34
        r.d = a1.d + a2.d;
35
        r.e = a1.e + a2.e;
36
        r.f = a1.f + a2.f;
37
        r.g = a1.g + a2.g;
38
 
39
        printf("%Lg %Lg %Lg %Lg %Lg %g %Lg %Lg %Lg %Lg %Lg %Lg %g %Lg: "
40
                "%Lg %Lg %Lg %Lg %Lg %g %Lg\n",
41
                a1.a, a1.b, a1.c, a1.d, a1.e, a1.f, a1.g,
42
                a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g,
43
                r.a, r.b, r.c, r.d, r.e, r.f, r.g);
44
 
45
        return r;
46
}
47
 
48
static void
49
cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args,
50
                    void* userdata __UNUSED__)
51
{
52
        struct cls_struct_align a1, a2;
53
 
54
        a1 = *(struct cls_struct_align*)(args[0]);
55
        a2 = *(struct cls_struct_align*)(args[1]);
56
 
57
        *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2);
58
}
59
 
60
int main (void)
61
{
62
        ffi_cif cif;
63
        void *code;
64
        ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
65
        void* args_dbl[3];
66
        ffi_type* cls_struct_fields[8];
67
        ffi_type cls_struct_type;
68
        ffi_type* dbl_arg_types[3];
69
 
70
        cls_struct_type.size = 0;
71
        cls_struct_type.alignment = 0;
72
        cls_struct_type.type = FFI_TYPE_STRUCT;
73
        cls_struct_type.elements = cls_struct_fields;
74
 
75
        struct cls_struct_align g_dbl = { 1, 2, 3, 4, 5, 6, 7 };
76
        struct cls_struct_align f_dbl = { 8, 9, 10, 11, 12, 13, 14 };
77
        struct cls_struct_align res_dbl;
78
 
79
        cls_struct_fields[0] = &ffi_type_longdouble;
80
        cls_struct_fields[1] = &ffi_type_longdouble;
81
        cls_struct_fields[2] = &ffi_type_longdouble;
82
        cls_struct_fields[3] = &ffi_type_longdouble;
83
        cls_struct_fields[4] = &ffi_type_longdouble;
84
        cls_struct_fields[5] = &ffi_type_double;
85
        cls_struct_fields[6] = &ffi_type_longdouble;
86
        cls_struct_fields[7] = NULL;
87
 
88
        dbl_arg_types[0] = &cls_struct_type;
89
        dbl_arg_types[1] = &cls_struct_type;
90
        dbl_arg_types[2] = NULL;
91
 
92
        CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
93
                dbl_arg_types) == FFI_OK);
94
 
95
        args_dbl[0] = &g_dbl;
96
        args_dbl[1] = &f_dbl;
97
        args_dbl[2] = NULL;
98
 
99
        ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl);
100
        /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
101
        printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl.a, res_dbl.b,
102
                res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g);
103
        /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
104
 
105
        CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK);
106
 
107
        res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl);
108
        /* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
109
        printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl.a, res_dbl.b,
110
                res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g);
111
        /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
112
 
113
  exit(0);
114
}
115
 
116
 
117
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.