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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [bprob/] [g++-bprob-1.C] - Blame information for rev 715

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

Line No. Rev Author Line
1 693 jeremybenn
/* Check that various C constructs (in C++) don't cause problems for
2
 * profile-directed block ordering.
3
 
4
   Most of this test is the same as bprob-1.c and gcov-4.c in
5
   gcc.misc-tests.  The "count" comments are left in to make comparisons
6
   easier; they are ignored for this test. */
7
 
8
extern "C" void abort (void);
9
 
10
/* Check for loops. */
11
 
12
int for_val1;
13
int for_val2;
14
int for_temp;
15
 
16
int
17
test_for1 (int n)
18
{
19
  int i;
20
  for_temp = 1;                         /* count(3) */
21
  for (i = 0; i < n; i++)
22
    for_temp++;                         /* count(9) */
23
  return for_temp;                      /* count(3) */
24
}
25
 
26
int
27
test_for2 (int m, int n, int o)
28
{
29
  int i, j, k;
30
  for_temp = 1;                         /* count(6) */
31
  for (i = 0; i < n; i++)
32
    for (j = 0; j < m; j++)
33
      for (k = 0; k < o; k++)
34
        for_temp++;                     /* count(81) */
35
  return for_temp;                      /* count(6) */
36
}
37
 
38
int
39
call_for ()
40
{
41
  for_val1 += test_for1 (0);
42
  for_val1 += test_for1 (2);
43
  for_val1 += test_for1 (7);
44
 
45
  for_val2 += test_for2 (0, 0, 0);
46
  for_val2 += test_for2 (1, 0, 0);
47
  for_val2 += test_for2 (1, 3, 0);
48
  for_val2 += test_for2 (1, 3, 1);
49
  for_val2 += test_for2 (3, 1, 5);
50
  for_val2 += test_for2 (3, 7, 3);
51
}
52
 
53
/* Check the use of goto. */
54
 
55
int goto_val;
56
 
57
int
58
test_goto1 (int f)
59
{
60
  if (f)                                /* count(2) */
61
    goto lab1;                          /* count(1) */
62
  return 1;                             /* count(1) */
63
lab1:
64
  return 2;                             /* count(1) */
65
}
66
 
67
int
68
test_goto2 (int f)
69
{
70
  int i;
71
  for (i = 0; i < 10; i++)              /* count(15) */
72
    if (i == f) goto lab2;              /* count(14) */
73
  return 4;                             /* count(1) */
74
lab2:
75
  return 8;                             /* count(1) */
76
}
77
 
78
void
79
call_goto ()
80
{
81
  goto_val += test_goto1 (0);
82
  goto_val += test_goto1 (1);
83
  goto_val += test_goto2 (3);
84
  goto_val += test_goto2 (30);
85
}
86
 
87
/* Check nested if-then-else statements. */
88
 
89
int ifelse_val1;
90
int ifelse_val2;
91
int ifelse_val3;
92
 
93
int
94
test_ifelse1 (int i, int j)
95
{
96
  int result = 0;
97
  if (i)                                /* count(5) */
98
    if (j)                              /* count(3) */
99
      result = 4;                       /* count(3) */
100
    else
101
      result = 1024;
102
  else
103
    if (j)                              /* count(2) */
104
      result = 1;                       /* count(1) */
105
    else
106
      result = 2;                       /* count(1) */
107
  if (i > j)                            /* count(5) */
108
    result *= 2;                        /* count(1) */
109
  if (i > 10)                           /* count(5) */
110
    if (j > 10)                         /* count(1) */
111
      result *= 4;                      /* count(1) */
112
  return result;                        /* count(5) */
113
}
114
 
115
int
116
test_ifelse2 (int i)
117
{
118
  int result = 0;
119
  if (!i)                               /* count(6) */
120
    result = 1;                         /* count(1) */
121
  if (i == 1)                           /* count(6) */
122
    result = 1024;
123
  if (i == 2)                           /* count(6) */
124
    result = 2;                         /* count(3) */
125
  if (i == 3)                           /* count(6) */
126
    return 8;                           /* count(2) */
127
  if (i == 4)                           /* count(4) */
128
    return 2048;
129
  return result;                        /* count(4) */
130
}
131
 
132
int
133
test_ifelse3 (int i, int j)
134
{
135
  int result = 1;
136
  if (i > 10 && j > i && j < 20)        /* count(11) */
137
    result = 16;                        /* count(1) */
138
  if (i > 20)                           /* count(11) */
139
    if (j > i)                          /* count(5) */
140
      if (j < 30)                       /* count(2) */
141
        result = 32;                    /* count(1) */
142
  if (i == 3 || j == 47 || i == j)      /* count(11) */
143
    result = 64;                        /* count(3) */
144
  return result;                        /* count(11) */
145
}
146
 
147
void
148
call_ifelse ()
149
{
150
  ifelse_val1 += test_ifelse1 (0, 2);
151
  ifelse_val1 += test_ifelse1 (0, 0);
152
  ifelse_val1 += test_ifelse1 (1, 2);
153
  ifelse_val1 += test_ifelse1 (10, 2);
154
  ifelse_val1 += test_ifelse1 (11, 11);
155
 
156
  ifelse_val2 += test_ifelse2 (0);
157
  ifelse_val2 += test_ifelse2 (2);
158
  ifelse_val2 += test_ifelse2 (2);
159
  ifelse_val2 += test_ifelse2 (2);
160
  ifelse_val2 += test_ifelse2 (3);
161
  ifelse_val2 += test_ifelse2 (3);
162
 
163
  ifelse_val3 += test_ifelse3 (11, 19);
164
  ifelse_val3 += test_ifelse3 (25, 27);
165
  ifelse_val3 += test_ifelse3 (11, 22);
166
  ifelse_val3 += test_ifelse3 (11, 10);
167
  ifelse_val3 += test_ifelse3 (21, 32);
168
  ifelse_val3 += test_ifelse3 (21, 20);
169
  ifelse_val3 += test_ifelse3 (1, 2);
170
  ifelse_val3 += test_ifelse3 (32, 31);
171
  ifelse_val3 += test_ifelse3 (3, 0);
172
  ifelse_val3 += test_ifelse3 (0, 47);  /* count(1) */
173
  ifelse_val3 += test_ifelse3 (65, 65); /* count(1) */
174
}
175
 
176
/* Check switch statements. */
177
 
178
int switch_val, switch_m;
179
 
180
int
181
test_switch (int i, int j)
182
{
183
  int result = 0;                       /* count(5) */
184
 
185
  switch (i)                            /* count(5) */
186
    {
187
      case 1:
188
        result = 2;                     /* count(1) */
189
        break;
190
      case 2:
191
        result = 1024;
192
        break;
193
      case 3:
194
      case 4:
195
        if (j == 2)                     /* count(3) */
196
          return 4;                     /* count(1) */
197
        result = 8;                     /* count(2) */
198
        break;
199
      default:
200
        result = 32;                    /* count(1) */
201
        switch_m++;                     /* count(1) */
202
        break;
203
    }
204
  return result;                        /* count(4) */
205
}
206
 
207
void
208
call_switch ()
209
{
210
  switch_val += test_switch (1, 0);
211
  switch_val += test_switch (3, 0);
212
  switch_val += test_switch (3, 2);
213
  switch_val += test_switch (4, 0);
214
  switch_val += test_switch (16, 0);
215
  switch_val += switch_m;
216
}
217
 
218
int
219
main()
220
{
221
  call_for ();
222
  call_goto ();
223
  call_ifelse ();
224
  call_switch ();
225
  if ((for_val1 != 12)
226
      || (for_val2 != 87)
227
      || (goto_val != 15)
228
      || (ifelse_val1 != 31)
229
      || (ifelse_val2 != 23)
230
      || (ifelse_val3 != 246)
231
      || (switch_val != 55))
232
    abort ();
233
  return 0;
234
}

powered by: WebSVN 2.1.0

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