PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.target / spu / tag_manager.c
blob4b3ab9f8ddae2b482960e088c1f73241db1d8cb4
1 /* Copyright (C) 2007, 2009 Free Software Foundation, Inc.
3 This file is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3 of the License, or (at your option)
6 any later version.
8 This file is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 for more details.
13 You should have received a copy of the GNU General Public License
14 along with this file; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
17 /* { dg-do run } */
19 #include <spu_mfcio.h>
20 #include <stdlib.h>
22 /* This test directly accesses the internal table used
23 by the MFC tag manager. */
24 extern vector unsigned int __mfc_tag_table;
27 /* This tag tests invalid tag release. Invalid tag release does
28 nothing to the tag table. */
29 void
30 test_tag_release01 (void)
32 unsigned int copy;
33 copy = spu_extract (__mfc_tag_table, 0);
35 mfc_tag_release (35);
36 if (copy != spu_extract (__mfc_tag_table, 0))
37 abort ();
40 /* More invalid release tests. */
41 void
42 test_tag_release_invalid (void)
44 unsigned int copy;
45 copy = spu_extract (__mfc_tag_table, 0);
47 if (mfc_tag_release (32) != MFC_TAG_INVALID)
48 abort ();
49 if (copy != spu_extract (__mfc_tag_table, 0))
50 abort ();
52 if (mfc_tag_release (17) != MFC_TAG_INVALID)
53 abort ();
54 if (copy != spu_extract (__mfc_tag_table, 0))
55 abort ();
58 /* Invalid multiple-tag release tests. */
59 void
60 test_tag_group_release_invalid (void)
62 unsigned int copy;
63 copy = spu_extract (__mfc_tag_table, 0);
65 if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
66 abort ();
67 if (copy != spu_extract (__mfc_tag_table, 0))
68 abort ();
70 if (mfc_multi_tag_release (28, 10) != MFC_TAG_INVALID)
71 abort ();
72 if (copy != spu_extract (__mfc_tag_table, 0))
73 abort ();
75 if (mfc_multi_tag_release (17, 10) != MFC_TAG_INVALID)
76 abort ();
77 if (copy != spu_extract (__mfc_tag_table, 0))
78 abort ();
80 if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
81 abort ();
82 if (copy != spu_extract (__mfc_tag_table, 0))
83 abort ();
86 /* The tag table should be in a pristine mode to run this test. */
87 void
88 test_tag_reserve01 (void)
90 unsigned int correct_table[32] =
92 0x80000000, 0xC0000000, 0xE0000000,
93 0xF0000000, 0xF8000000, 0xFC000000, 0xFE000000,
94 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
95 0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000,
96 0xFFFF0000, 0xFFFF8000, 0xFFFFC000, 0xFFFFE000,
97 0xFFFFF000, 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00,
98 0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0,
99 0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE,
100 0xFFFFFFFF
103 unsigned int tag;
104 unsigned int i;
106 for (i = 0; i < 32; i++)
108 tag = mfc_tag_reserve ();
109 if (tag != i)
110 abort ();
113 for (i = 0; i < 32; i++)
115 tag = mfc_tag_reserve ();
116 if (tag != MFC_TAG_INVALID)
117 abort ();
120 for (i = 0; i < 32; i++)
122 mfc_tag_release (i);
123 if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
124 abort ();
128 /* The tag table should be in a pristine mode to run this test. */
129 void
130 test_tag_reserve02 (void)
132 unsigned int correct_table[32] =
134 0x80000000, 0xC0000000, 0xA0000000, 0xF0000000,
135 0xA8000000, 0xFC000000, 0xAA000000, 0xFF000000,
136 0xAA800000, 0xFFC00000, 0xAAA00000, 0xFFF00000,
137 0xAAA80000, 0xFFFC0000, 0xAAAA0000, 0xFFFF0000,
138 0xAAAA8000, 0xFFFFC000, 0xAAAAA000, 0xFFFFF000,
139 0xAAAAA800, 0xFFFFFC00, 0xAAAAAA00, 0xFFFFFF00,
140 0xAAAAAA80, 0xFFFFFFC0, 0xAAAAAAA0, 0xFFFFFFF0,
141 0xAAAAAAA8, 0xFFFFFFFC, 0xAAAAAAAA, 0xFFFFFFFF
144 unsigned int correct_table2[32] =
146 0x80000000, 0xEAAAAAAA, 0xA0000000, 0xFAAAAAAA,
147 0xA8000000, 0xFEAAAAAA, 0xAA000000, 0xFFAAAAAA,
148 0xAA800000, 0xFFEAAAAA, 0xAAA00000, 0xFFFAAAAA,
149 0xAAA80000, 0xFFFEAAAA, 0xAAAA0000, 0xFFFFAAAA,
150 0xAAAA8000, 0xFFFFEAAA, 0xAAAAA000, 0xFFFFFAAA,
151 0xAAAAA800, 0xFFFFFEAA, 0xAAAAAA00, 0xFFFFFFAA,
152 0xAAAAAA80, 0xFFFFFFEA, 0xAAAAAAA0, 0xFFFFFFFA,
153 0xAAAAAAA8, 0xFFFFFFFE, 0xAAAAAAAA, 0xFFFFFFFF
156 unsigned int tag;
157 unsigned int i;
159 /* Reserve all 32 tags. */
160 for (i = 0; i < 32; i++)
162 tag = mfc_tag_reserve();
163 if (tag != i)
164 abort ();
167 for (i = 0; i < 32; i++)
169 tag = mfc_tag_reserve();
170 if (tag != MFC_TAG_INVALID)
171 abort ();
174 /* Release only 16 tags with a stride of 2. */
175 for (i = 0; i < 32; i += 2)
177 mfc_tag_release (i);
178 if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
179 abort ();
182 /* Release the other 16 tags with a stride of 2. */
183 for (i = 1; i < 32; i += 2)
185 mfc_tag_release (i);
186 if (spu_extract (__mfc_tag_table, 0) != correct_table2[i])
187 abort ();
191 /* The tag table should be in a pristine mode to run this test. */
192 void
193 test_tag_reserve03 (void)
195 unsigned int tag;
196 unsigned int i;
198 /* Reserve all 32 tags. */
199 for (i = 0; i < 32; i++)
201 tag = mfc_tag_reserve ();
202 if (tag != i)
203 abort ();
206 for (i = 0; i < 32; i++)
208 tag = mfc_tag_reserve ();
209 if (tag != MFC_TAG_INVALID)
210 abort ();
213 /* Release only 16 tags with a stride of 2. */
214 for (i = 0; i < 32; i += 2)
215 mfc_tag_release (i);
217 /* Now let's re-reserve those tags. */
218 for (i = 0; i < 32; i += 2)
220 tag = mfc_tag_reserve ();
221 if (tag != i)
222 abort ();
225 /* Release all tags. */
226 for (i = 0; i < 32; i++)
227 mfc_tag_release (i);
229 if (spu_extract (__mfc_tag_table,0) != 0xFFFFFFFF)
230 abort ();
234 void
235 test_tag_group_reserve (void)
237 unsigned int tag;
238 unsigned int i;
239 unsigned int copy;
241 /* Reserve all tags. */
242 for (i = 0; i < 32; i++)
243 mfc_tag_reserve();
245 /* Release the first 4. */
246 for (i = 0; i < 4; i++)
247 mfc_tag_release (i);
249 /* Release tag 5 to 7. */
250 for (i = 5; i < 8; i++)
251 mfc_tag_release (i);
253 /* Release tag 9 to 19. */
254 for (i = 9; i < 20; i++)
255 mfc_tag_release (i);
257 /* Tag table should be 0xF77FF000. */
258 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
259 abort ();
262 /* Verify invalid release is detected. */
263 copy = spu_extract (__mfc_tag_table, 0);
264 if (mfc_multi_tag_release (1, 5) != MFC_TAG_INVALID)
265 abort ();
266 if (copy != spu_extract (__mfc_tag_table, 0))
267 abort ();
270 /* Reserve multiple tags. */
271 tag = mfc_multi_tag_reserve (5);
272 if (tag != 9)
273 abort ();
275 /* Tag table should be 0xF703F000. */
276 if (spu_extract (__mfc_tag_table, 0) != 0xF703F000)
277 abort ();
280 /* Release 5 tags in the group. */
281 mfc_multi_tag_release (tag, 5);
283 /* Tag table should be 0xF77FF000. */
284 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
285 abort ();
288 /* This call should not do anything. */
289 mfc_multi_tag_release (32, 5);
291 /* Tag table should be 0xF77FF000. */
292 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
293 abort ();
298 main (void)
300 test_tag_release01 ();
301 test_tag_release_invalid ();
302 test_tag_group_release_invalid ();
304 test_tag_reserve01 ();
305 test_tag_reserve02 ();
306 test_tag_reserve03 ();
308 test_tag_group_reserve ();
310 return 0;