Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.target / spu / tag_manager.c
blob24a206c4b95997fd73a5507bf8e76c523d9f79ad
1 /* Copyright (C) 2007 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 2 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 COPYING. If not, write to the Free
15 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
16 02110-1301, USA. */
18 /* { dg-do run } */
20 #include <spu_mfcio.h>
21 #include <stdlib.h>
23 /* This test directly accesses the internal table used
24 by the MFC tag manager. */
25 extern vector unsigned int __mfc_tag_table;
28 /* This tag tests invalid tag release. Invalid tag release does
29 nothing to the tag table. */
30 void
31 test_tag_release01 (void)
33 unsigned int copy;
34 copy = spu_extract (__mfc_tag_table, 0);
36 mfc_tag_release (35);
37 if (copy != spu_extract (__mfc_tag_table, 0))
38 abort ();
41 /* More invalid release tests. */
42 void
43 test_tag_release_invalid (void)
45 unsigned int copy;
46 copy = spu_extract (__mfc_tag_table, 0);
48 if (mfc_tag_release (32) != MFC_TAG_INVALID)
49 abort ();
50 if (copy != spu_extract (__mfc_tag_table, 0))
51 abort ();
53 if (mfc_tag_release (17) != MFC_TAG_INVALID)
54 abort ();
55 if (copy != spu_extract (__mfc_tag_table, 0))
56 abort ();
59 /* Invalid multiple-tag release tests. */
60 void
61 test_tag_group_release_invalid (void)
63 unsigned int copy;
64 copy = spu_extract (__mfc_tag_table, 0);
66 if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
67 abort ();
68 if (copy != spu_extract (__mfc_tag_table, 0))
69 abort ();
71 if (mfc_multi_tag_release (28, 10) != MFC_TAG_INVALID)
72 abort ();
73 if (copy != spu_extract (__mfc_tag_table, 0))
74 abort ();
76 if (mfc_multi_tag_release (17, 10) != MFC_TAG_INVALID)
77 abort ();
78 if (copy != spu_extract (__mfc_tag_table, 0))
79 abort ();
81 if (mfc_multi_tag_release (32, 10) != MFC_TAG_INVALID)
82 abort ();
83 if (copy != spu_extract (__mfc_tag_table, 0))
84 abort ();
87 /* The tag table should be in a pristine mode to run this test. */
88 void
89 test_tag_reserve01 (void)
91 unsigned int correct_table[32] =
93 0x80000000, 0xC0000000, 0xE0000000,
94 0xF0000000, 0xF8000000, 0xFC000000, 0xFE000000,
95 0xFF000000, 0xFF800000, 0xFFC00000, 0xFFE00000,
96 0xFFF00000, 0xFFF80000, 0xFFFC0000, 0xFFFE0000,
97 0xFFFF0000, 0xFFFF8000, 0xFFFFC000, 0xFFFFE000,
98 0xFFFFF000, 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00,
99 0xFFFFFF00, 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0,
100 0xFFFFFFF0, 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE,
101 0xFFFFFFFF
104 unsigned int tag;
105 unsigned int i;
107 for (i = 0; i < 32; i++)
109 tag = mfc_tag_reserve ();
110 if (tag != i)
111 abort ();
114 for (i = 0; i < 32; i++)
116 tag = mfc_tag_reserve ();
117 if (tag != MFC_TAG_INVALID)
118 abort ();
121 for (i = 0; i < 32; i++)
123 mfc_tag_release (i);
124 if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
125 abort ();
129 /* The tag table should be in a pristine mode to run this test. */
130 void
131 test_tag_reserve02 (void)
133 unsigned int correct_table[32] =
135 0x80000000, 0xC0000000, 0xA0000000, 0xF0000000,
136 0xA8000000, 0xFC000000, 0xAA000000, 0xFF000000,
137 0xAA800000, 0xFFC00000, 0xAAA00000, 0xFFF00000,
138 0xAAA80000, 0xFFFC0000, 0xAAAA0000, 0xFFFF0000,
139 0xAAAA8000, 0xFFFFC000, 0xAAAAA000, 0xFFFFF000,
140 0xAAAAA800, 0xFFFFFC00, 0xAAAAAA00, 0xFFFFFF00,
141 0xAAAAAA80, 0xFFFFFFC0, 0xAAAAAAA0, 0xFFFFFFF0,
142 0xAAAAAAA8, 0xFFFFFFFC, 0xAAAAAAAA, 0xFFFFFFFF
145 unsigned int correct_table2[32] =
147 0x80000000, 0xEAAAAAAA, 0xA0000000, 0xFAAAAAAA,
148 0xA8000000, 0xFEAAAAAA, 0xAA000000, 0xFFAAAAAA,
149 0xAA800000, 0xFFEAAAAA, 0xAAA00000, 0xFFFAAAAA,
150 0xAAA80000, 0xFFFEAAAA, 0xAAAA0000, 0xFFFFAAAA,
151 0xAAAA8000, 0xFFFFEAAA, 0xAAAAA000, 0xFFFFFAAA,
152 0xAAAAA800, 0xFFFFFEAA, 0xAAAAAA00, 0xFFFFFFAA,
153 0xAAAAAA80, 0xFFFFFFEA, 0xAAAAAAA0, 0xFFFFFFFA,
154 0xAAAAAAA8, 0xFFFFFFFE, 0xAAAAAAAA, 0xFFFFFFFF
157 unsigned int tag;
158 unsigned int i;
160 /* Reserve all 32 tags. */
161 for (i = 0; i < 32; i++)
163 tag = mfc_tag_reserve();
164 if (tag != i)
165 abort ();
168 for (i = 0; i < 32; i++)
170 tag = mfc_tag_reserve();
171 if (tag != MFC_TAG_INVALID)
172 abort ();
175 /* Release only 16 tags with a stride of 2. */
176 for (i = 0; i < 32; i += 2)
178 mfc_tag_release (i);
179 if (spu_extract (__mfc_tag_table, 0) != correct_table[i])
180 abort ();
183 /* Release the other 16 tags with a stride of 2. */
184 for (i = 1; i < 32; i += 2)
186 mfc_tag_release (i);
187 if (spu_extract (__mfc_tag_table, 0) != correct_table2[i])
188 abort ();
192 /* The tag table should be in a pristine mode to run this test. */
193 void
194 test_tag_reserve03 (void)
196 unsigned int tag;
197 unsigned int i;
199 /* Reserve all 32 tags. */
200 for (i = 0; i < 32; i++)
202 tag = mfc_tag_reserve ();
203 if (tag != i)
204 abort ();
207 for (i = 0; i < 32; i++)
209 tag = mfc_tag_reserve ();
210 if (tag != MFC_TAG_INVALID)
211 abort ();
214 /* Release only 16 tags with a stride of 2. */
215 for (i = 0; i < 32; i += 2)
216 mfc_tag_release (i);
218 /* Now let's re-reserve those tags. */
219 for (i = 0; i < 32; i += 2)
221 tag = mfc_tag_reserve ();
222 if (tag != i)
223 abort ();
226 /* Release all tags. */
227 for (i = 0; i < 32; i++)
228 mfc_tag_release (i);
230 if (spu_extract (__mfc_tag_table,0) != 0xFFFFFFFF)
231 abort ();
235 void
236 test_tag_group_reserve (void)
238 unsigned int tag;
239 unsigned int i;
240 unsigned int copy;
242 /* Reserve all tags. */
243 for (i = 0; i < 32; i++)
244 mfc_tag_reserve();
246 /* Release the first 4. */
247 for (i = 0; i < 4; i++)
248 mfc_tag_release (i);
250 /* Release tag 5 to 7. */
251 for (i = 5; i < 8; i++)
252 mfc_tag_release (i);
254 /* Release tag 9 to 19. */
255 for (i = 9; i < 20; i++)
256 mfc_tag_release (i);
258 /* Tag table should be 0xF77FF000. */
259 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
260 abort ();
263 /* Verify invalid release is detected. */
264 copy = spu_extract (__mfc_tag_table, 0);
265 if (mfc_multi_tag_release (1, 5) != MFC_TAG_INVALID)
266 abort ();
267 if (copy != spu_extract (__mfc_tag_table, 0))
268 abort ();
271 /* Reserve multiple tags. */
272 tag = mfc_multi_tag_reserve (5);
273 if (tag != 9)
274 abort ();
276 /* Tag table should be 0xF703F000. */
277 if (spu_extract (__mfc_tag_table, 0) != 0xF703F000)
278 abort ();
281 /* Release 5 tags in the group. */
282 mfc_multi_tag_release (tag, 5);
284 /* Tag table should be 0xF77FF000. */
285 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
286 abort ();
289 /* This call should not do anything. */
290 mfc_multi_tag_release (32, 5);
292 /* Tag table should be 0xF77FF000. */
293 if (spu_extract (__mfc_tag_table, 0) != 0xF77FF000)
294 abort ();
299 main (void)
301 test_tag_release01 ();
302 test_tag_release_invalid ();
303 test_tag_group_release_invalid ();
305 test_tag_reserve01 ();
306 test_tag_reserve02 ();
307 test_tag_reserve03 ();
309 test_tag_group_reserve ();
311 return 0;