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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [20040709-2.c] - Blame information for rev 688

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 688 jeremybenn
/* Test arithmetics on bitfields.  */
2
 
3
extern void abort (void);
4
extern void exit (int);
5
 
6
unsigned int
7
myrnd (void)
8
{
9
  static unsigned int s = 1388815473;
10
  s *= 1103515245;
11
  s += 12345;
12
  return (s / 65536) % 2048;
13
}
14
 
15
#define T(S)                                    \
16
struct S s##S;                                  \
17
struct S retme##S (struct S x)                  \
18
{                                               \
19
  return x;                                     \
20
}                                               \
21
                                                \
22
unsigned int fn1##S (unsigned int x)            \
23
{                                               \
24
  struct S y = s##S;                            \
25
  y.k += x;                                     \
26
  y = retme##S (y);                             \
27
  return y.k;                                   \
28
}                                               \
29
                                                \
30
unsigned int fn2##S (unsigned int x)            \
31
{                                               \
32
  struct S y = s##S;                            \
33
  y.k += x;                                     \
34
  y.k %= 15;                                    \
35
  return y.k;                                   \
36
}                                               \
37
                                                \
38
unsigned int retit##S (void)                    \
39
{                                               \
40
  return s##S.k;                                \
41
}                                               \
42
                                                \
43
unsigned int fn3##S (unsigned int x)            \
44
{                                               \
45
  s##S.k += x;                                  \
46
  return retit##S ();                           \
47
}                                               \
48
                                                \
49
void test##S (void)                             \
50
{                                               \
51
  int i;                                        \
52
  unsigned int mask, v, a, r;                   \
53
  struct S x;                                   \
54
  char *p = (char *) &s##S;                     \
55
  for (i = 0; i < sizeof (s##S); ++i)            \
56
    *p++ = myrnd ();                            \
57
  if (__builtin_classify_type (s##S.l) == 8)    \
58
    s##S.l = 5.25;                              \
59
  s##S.k = -1;                                  \
60
  mask = s##S.k;                                \
61
  v = myrnd ();                                 \
62
  a = myrnd ();                                 \
63
  s##S.k = v;                                   \
64
  x = s##S;                                     \
65
  r = fn1##S (a);                               \
66
  if (x.i != s##S.i || x.j != s##S.j            \
67
      || x.k != s##S.k || x.l != s##S.l         \
68
      || ((v + a) & mask) != r)                 \
69
    abort ();                                   \
70
  v = myrnd ();                                 \
71
  a = myrnd ();                                 \
72
  s##S.k = v;                                   \
73
  x = s##S;                                     \
74
  r = fn2##S (a);                               \
75
  if (x.i != s##S.i || x.j != s##S.j            \
76
      || x.k != s##S.k || x.l != s##S.l         \
77
      || ((((v + a) & mask) % 15) & mask) != r) \
78
    abort ();                                   \
79
  v = myrnd ();                                 \
80
  a = myrnd ();                                 \
81
  s##S.k = v;                                   \
82
  x = s##S;                                     \
83
  r = fn3##S (a);                               \
84
  if (x.i != s##S.i || x.j != s##S.j            \
85
      || s##S.k != r || x.l != s##S.l           \
86
      || ((v + a) & mask) != r)                 \
87
    abort ();                                   \
88
}
89
 
90
#define pck __attribute__((packed))
91
struct pck A { unsigned short i : 1, l : 1, j : 3, k : 11; }; T(A)
92
struct pck B { unsigned short i : 4, j : 1, k : 11; unsigned int l; }; T(B)
93
struct pck C { unsigned int l; unsigned short i : 4, j : 1, k : 11; }; T(C)
94
struct pck D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
95
struct pck E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
96
struct pck F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
97
struct pck G { unsigned short i : 1, j : 1, k : 6; unsigned long long l; }; T(G)
98
struct pck H { unsigned short i : 6, j : 2, k : 8; unsigned long long l; }; T(H)
99
struct pck I { unsigned short i : 1, j : 6, k : 1; unsigned long long l; }; T(I)
100
struct pck J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
101
struct pck K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
102
struct pck L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
103
struct pck M { unsigned int l; unsigned short k : 6, j : 11, i : 15; }; T(M)
104
struct pck N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
105
struct pck O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
106
struct pck P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
107
struct pck Q { unsigned short k : 12, j : 1, i : 3; unsigned long long l; }; T(Q)
108
struct pck R { unsigned short k : 2, j : 11, i : 3; unsigned long long l; }; T(R)
109
struct pck S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
110
struct pck T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
111
struct pck U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
112
struct pck V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
113
struct pck W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
114
struct pck X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
115
struct pck Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
116
struct pck Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
117
 
118
int
119
main (void)
120
{
121
  testA ();
122
  testB ();
123
  testC ();
124
  testD ();
125
  testE ();
126
  testF ();
127
  testG ();
128
  testH ();
129
  testI ();
130
  testJ ();
131
  testK ();
132
  testL ();
133
  testM ();
134
  testN ();
135
  testO ();
136
  testP ();
137
  testQ ();
138
  testR ();
139
  testS ();
140
  testT ();
141
  testU ();
142
  testV ();
143
  testW ();
144
  testX ();
145
  testY ();
146
  testZ ();
147
  exit (0);
148
}

powered by: WebSVN 2.1.0

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