1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/* Simple test of vararg passing for problematic types with and without
double values passed between them. */
#include "dfp-dbg.h"
#include <stdarg.h>
DTYPE a[10];
double b[10];
union U {
DTYPE d;
unsigned int i[INTS];
};
void
compare (double r, double s, unsigned int *p, unsigned int *q, int n, int line)
{
int i;
for (i = 0; i < n; i++)
if (r != s || p[i] != q[i])
#ifdef DBG
{
int j;
failures++;
printf ("line %-3d", line);
for (j = 0; j < n; j++)
printf (" %08x", p[j]);
printf (" %10.2g\n ", r);
for (j = 0; j < n; j++)
printf (" %08x", q[j]);
printf (" %10.2g\n\n", s);
return;
}
#else
__builtin_abort ();
#endif
}
void
bar0 (int n, ...)
{
union U u;
int j;
va_list ap;
va_start (ap, n);
for (j = 0; j < n; j++)
a[j] = va_arg (ap, DTYPE);
va_end (ap);
}
void
bar1 (int n, ...)
{
union U u;
int j;
va_list ap;
va_start (ap, n);
for (j = 0; j < n; j++)
{
a[j] = va_arg (ap, DTYPE);
b[j] = va_arg (ap, double);
}
va_end (ap);
}
void
bar2 (int n, ...)
{
union U u;
int j;
va_list ap;
va_start (ap, n);
for (j = 0; j < n; j++)
{
b[j] = va_arg (ap, double);
a[j] = va_arg (ap, DTYPE);
}
va_end (ap);
}
void
doit ()
{
DTYPE x, y, z;
union U u1, u2;
/* Sanity check that test setup is right, especially for long double
which can be changed by command line option. */
if (INTS * 4 != sizeof (DTYPE))
{
#ifdef DBG
printf ("test error: INTS = %d, sizeof (DTYPE) = %d\n",
INTS, sizeof (DTYPE));
#endif
__builtin_abort ();
}
x = ONE / THREE;
y = ONE / SEVEN;
z = ONE / ELEVEN;
bar0 (1, x);
u1.d = x; u2.d = a[0]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
bar0 (2, x, y);
u1.d = x; u2.d = a[0]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
bar0 (3, x, y, z);
u1.d = x; u2.d = a[0]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
u1.d = z; u2.d = a[2]; compare (0.0, 0.0, u1.i, u2.i, INTS, __LINE__);
bar1 (1, x, 1.5);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
bar1 (2, x, 1.5, y, 2.5);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (2.5, b[1], u1.i, u2.i, INTS, __LINE__);
bar1 (3, x, 1.5, y, 2.5, z, 3.5);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (2.5, b[1], u1.i, u2.i, INTS, __LINE__);
u1.d = z; u2.d = a[2]; compare (3.5, b[2], u1.i, u2.i, INTS, __LINE__);
bar2 (1, 1.5, x);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
bar2 (2, 1.5, x, 2.5, y);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (2.5, b[1], u1.i, u2.i, INTS, __LINE__);
bar2 (3, 1.5, x, 2.5, y, 3.5, z);
u1.d = x; u2.d = a[0]; compare (1.5, b[0], u1.i, u2.i, INTS, __LINE__);
u1.d = y; u2.d = a[1]; compare (2.5, b[1], u1.i, u2.i, INTS, __LINE__);
u1.d = z; u2.d = a[2]; compare (3.5, b[2], u1.i, u2.i, INTS, __LINE__);
}
|