Merge -r 127928:132243 from trunk
[official-gcc.git] / gcc / config / spu / mfc_multi_tag_reserve.c
blobce3b24d000ee47c4e9a12c4d7ed90ca62f1b3a11
1 /* Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version.
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA. */
29 #include <spu_mfcio.h>
30 extern vector unsigned int __mfc_tag_table;
32 /* Reserve a sequential group of tags for exclusive use. The number of
33 tags to be reserved is specified by the <number_of_tags> parameter.
34 This routine returns the first tag ID for a sequential list of
35 available tags and marks them as reserved. The reserved group
36 of tags is in the range starting from the returned tag through
37 the returned tag + <number_of_tags>-1.
39 If the number of tags requested exceeds the number of available
40 sequential tags, then MFC_DMA_TAG_INVALID is returned indicating
41 that the request could not be serviced. */
43 unsigned int
44 __mfc_multi_tag_reserve (unsigned int number_of_tags)
46 vector unsigned int table_copy;
47 vector unsigned int one = (vector unsigned int)
48 { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
49 vector unsigned int count_busy, is_valid;
50 vector unsigned int count_total;
51 vector unsigned int count_avail = (vector unsigned int) { 0, 0, 0, 0 };
52 vector unsigned int index = (vector unsigned int) { 0, 0, 0, 0 };
54 table_copy = __mfc_tag_table;
57 /* count_busy: number of consecutive busy tags
58 count_avail: number of consecutive free tags
59 table_copy: temporary copy of the tag table
60 count_total: sum of count_busy and count_avail
61 index: index of the current working tag */
64 table_copy = spu_sl (table_copy, count_avail);
66 count_busy = spu_cntlz (table_copy);
67 table_copy = spu_sl (table_copy, count_busy);
68 count_avail = spu_cntlz (spu_xor(table_copy, -1));
69 count_total = spu_add (count_busy, count_avail);
70 index = spu_add (index, count_total);
72 while (spu_extract (count_avail, 0) < number_of_tags
73 && spu_extract (table_copy, 0) != 0);
75 index = spu_sub (index, count_avail);
77 /* is_valid is set to 0xFFFFFFFF if table_copy == 0, 0 otherwise. */
78 is_valid = spu_cmpeq (table_copy, 0);
79 index = spu_sel (index, is_valid, is_valid);
81 /* Now I need to actually mark the tags as used. */
82 table_copy = spu_sl (one, number_of_tags);
83 table_copy = spu_rl (table_copy, -number_of_tags - spu_extract (index, 0));
84 table_copy = spu_sel (table_copy, __mfc_tag_table, table_copy);
85 __mfc_tag_table = spu_sel (table_copy, __mfc_tag_table, is_valid);
87 return spu_extract (index, 0);