annotate libgomp/ordered.c @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1 /* Copyright (C) 2005-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
111
kono
parents: 0
diff changeset
4 This file is part of the GNU Offloading and Multi Processing Library
kono
parents: 0
diff changeset
5 (libgomp).
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Libgomp is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 /* This file handles the ORDERED construct. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "libgomp.h"
111
kono
parents: 0
diff changeset
29 #include <stdarg.h>
kono
parents: 0
diff changeset
30 #include <string.h>
kono
parents: 0
diff changeset
31 #include "doacross.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 /* This function is called when first allocating an iteration block. That
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 is, the thread is not currently on the queue. The work-share lock must
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 be held on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 gomp_ordered_first (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 unsigned index;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 index = ws->ordered_cur + ws->ordered_num_used;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 if (index >= team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 index -= team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ws->ordered_team_ids[index] = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 /* If this is the first and only thread in the queue, then there is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 no one to release us when we get to our ordered section. Post to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 our own release queue now so that we won't block later. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 if (ws->ordered_num_used++ == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 gomp_sem_post (team->ordered_release[thr->ts.team_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 /* This function is called when completing the last iteration block. That
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 is, there are no more iterations to perform and so the thread should be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 removed from the queue entirely. Because of the way ORDERED blocks are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 managed, it follows that we currently own access to the ORDERED block,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 and should now pass it on to the next thread. The work-share lock must
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 be held on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 gomp_ordered_last (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 unsigned next_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 /* We're no longer the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 ws->ordered_owner = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 /* If we're not the last thread in the queue, then wake the next. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if (--ws->ordered_num_used > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 unsigned next = ws->ordered_cur + 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 if (next == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 next = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ws->ordered_cur = next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 next_id = ws->ordered_team_ids[next];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 gomp_sem_post (team->ordered_release[next_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /* This function is called when allocating a subsequent allocation block.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 That is, we're done with the current iteration block and we're allocating
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 another. This is the logical combination of a call to gomp_ordered_last
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 followed by a call to gomp_ordered_first. The work-share lock must be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 held on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 gomp_ordered_next (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 unsigned index, next_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 /* We're no longer the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ws->ordered_owner = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 /* If there's only one thread in the queue, that must be us. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 if (ws->ordered_num_used == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 /* We have a similar situation as in gomp_ordered_first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 where we need to post to our own release semaphore. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 gomp_sem_post (team->ordered_release[thr->ts.team_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 /* If the queue is entirely full, then we move ourself to the end of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 the queue merely by incrementing ordered_cur. Only if it's not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 full do we have to write our id. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (ws->ordered_num_used < team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 index = ws->ordered_cur + ws->ordered_num_used;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 if (index >= team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 index -= team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 ws->ordered_team_ids[index] = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 index = ws->ordered_cur + 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 if (index == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 index = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 ws->ordered_cur = index;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 next_id = ws->ordered_team_ids[index];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 gomp_sem_post (team->ordered_release[next_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /* This function is called when a statically scheduled loop is first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 being created. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 gomp_ordered_static_init (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 gomp_sem_post (team->ordered_release[0]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 /* This function is called when a statically scheduled loop is moving to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 the next allocation block. Static schedules are not first come first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 served like the others, so we're to move to the numerically next thread,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 not the next thread on a list. The work-share lock should *not* be held
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 gomp_ordered_static_next (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 unsigned id = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 ws->ordered_owner = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 /* This thread currently owns the lock. Increment the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 if (++id == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 id = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 ws->ordered_team_ids[0] = id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 gomp_sem_post (team->ordered_release[id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 /* This function is called when we need to assert that the thread owns the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 ordered section. Due to the problem of posted-but-not-waited semaphores,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 this needs to happen before completing a loop iteration. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 gomp_ordered_sync (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 /* Work share constructs can be orphaned. But this clearly means that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 we are the only thread, and so we automatically own the section. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 /* ??? I believe it to be safe to access this data without taking the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 ws->lock. The only presumed race condition is with the previous
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 thread on the queue incrementing ordered_cur such that it points
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 to us, concurrently with our check below. But our team_id is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 already present in the queue, and the other thread will always
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 post to our release semaphore. So the two cases are that we will
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 either win the race an momentarily block on the semaphore, or lose
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 the race and find the semaphore already unlocked and so not block.
111
kono
parents: 0
diff changeset
214 Either way we get correct results.
kono
parents: 0
diff changeset
215 However, there is an implicit flush on entry to an ordered region,
kono
parents: 0
diff changeset
216 so we do need to have a barrier here. If we were taking a lock
kono
parents: 0
diff changeset
217 this could be MEMMODEL_RELEASE since the acquire would be coverd
kono
parents: 0
diff changeset
218 by the lock. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
111
kono
parents: 0
diff changeset
220 __atomic_thread_fence (MEMMODEL_ACQ_REL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 if (ws->ordered_owner != thr->ts.team_id)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 gomp_sem_wait (team->ordered_release[thr->ts.team_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 ws->ordered_owner = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 /* This function is called by user code when encountering the start of an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 ORDERED block. We must check to see if the current thread is at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 head of the queue, and if not, block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 #ifdef HAVE_ATTRIBUTE_ALIAS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 extern void GOMP_ordered_start (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 __attribute__((alias ("gomp_ordered_sync")));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 GOMP_ordered_start (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 gomp_ordered_sync ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 /* This function is called by user code when encountering the end of an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 ORDERED block. With the current ORDERED implementation there's nothing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 for us to do.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 However, the current implementation has a flaw in that it does not allow
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 the next thread into the ORDERED section immediately after the current
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 thread exits the ORDERED section in its last iteration. The existance
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 of this function allows the implementation to change. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 GOMP_ordered_end (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
111
kono
parents: 0
diff changeset
256
kono
parents: 0
diff changeset
257 /* DOACROSS initialization. */
kono
parents: 0
diff changeset
258
kono
parents: 0
diff changeset
259 #define MAX_COLLAPSED_BITS (__SIZEOF_LONG__ * __CHAR_BIT__)
kono
parents: 0
diff changeset
260
kono
parents: 0
diff changeset
261 void
kono
parents: 0
diff changeset
262 gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size)
kono
parents: 0
diff changeset
263 {
kono
parents: 0
diff changeset
264 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
265 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
266 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
267 unsigned int i, bits[MAX_COLLAPSED_BITS], num_bits = 0;
kono
parents: 0
diff changeset
268 unsigned long ent, num_ents, elt_sz, shift_sz;
kono
parents: 0
diff changeset
269 struct gomp_doacross_work_share *doacross;
kono
parents: 0
diff changeset
270
kono
parents: 0
diff changeset
271 if (team == NULL || team->nthreads == 1)
kono
parents: 0
diff changeset
272 return;
kono
parents: 0
diff changeset
273
kono
parents: 0
diff changeset
274 for (i = 0; i < ncounts; i++)
kono
parents: 0
diff changeset
275 {
kono
parents: 0
diff changeset
276 /* If any count is 0, GOMP_doacross_{post,wait} can't be called. */
kono
parents: 0
diff changeset
277 if (counts[i] == 0)
kono
parents: 0
diff changeset
278 return;
kono
parents: 0
diff changeset
279
kono
parents: 0
diff changeset
280 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
281 {
kono
parents: 0
diff changeset
282 unsigned int this_bits;
kono
parents: 0
diff changeset
283 if (counts[i] == 1)
kono
parents: 0
diff changeset
284 this_bits = 1;
kono
parents: 0
diff changeset
285 else
kono
parents: 0
diff changeset
286 this_bits = __SIZEOF_LONG__ * __CHAR_BIT__
kono
parents: 0
diff changeset
287 - __builtin_clzl (counts[i] - 1);
kono
parents: 0
diff changeset
288 if (num_bits + this_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
289 {
kono
parents: 0
diff changeset
290 bits[i] = this_bits;
kono
parents: 0
diff changeset
291 num_bits += this_bits;
kono
parents: 0
diff changeset
292 }
kono
parents: 0
diff changeset
293 else
kono
parents: 0
diff changeset
294 num_bits = MAX_COLLAPSED_BITS + 1;
kono
parents: 0
diff changeset
295 }
kono
parents: 0
diff changeset
296 }
kono
parents: 0
diff changeset
297
kono
parents: 0
diff changeset
298 if (ws->sched == GFS_STATIC)
kono
parents: 0
diff changeset
299 num_ents = team->nthreads;
kono
parents: 0
diff changeset
300 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
301 num_ents = counts[0];
kono
parents: 0
diff changeset
302 else
kono
parents: 0
diff changeset
303 num_ents = (counts[0] - 1) / chunk_size + 1;
kono
parents: 0
diff changeset
304 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
305 {
kono
parents: 0
diff changeset
306 elt_sz = sizeof (unsigned long);
kono
parents: 0
diff changeset
307 shift_sz = ncounts * sizeof (unsigned int);
kono
parents: 0
diff changeset
308 }
kono
parents: 0
diff changeset
309 else
kono
parents: 0
diff changeset
310 {
kono
parents: 0
diff changeset
311 elt_sz = sizeof (unsigned long) * ncounts;
kono
parents: 0
diff changeset
312 shift_sz = 0;
kono
parents: 0
diff changeset
313 }
kono
parents: 0
diff changeset
314 elt_sz = (elt_sz + 63) & ~63UL;
kono
parents: 0
diff changeset
315
kono
parents: 0
diff changeset
316 doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
kono
parents: 0
diff changeset
317 + shift_sz);
kono
parents: 0
diff changeset
318 doacross->chunk_size = chunk_size;
kono
parents: 0
diff changeset
319 doacross->elt_sz = elt_sz;
kono
parents: 0
diff changeset
320 doacross->ncounts = ncounts;
kono
parents: 0
diff changeset
321 doacross->flattened = false;
kono
parents: 0
diff changeset
322 doacross->array = (unsigned char *)
kono
parents: 0
diff changeset
323 ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
kono
parents: 0
diff changeset
324 & ~(uintptr_t) 63);
kono
parents: 0
diff changeset
325 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
326 {
kono
parents: 0
diff changeset
327 unsigned int shift_count = 0;
kono
parents: 0
diff changeset
328 doacross->flattened = true;
kono
parents: 0
diff changeset
329 for (i = ncounts; i > 0; i--)
kono
parents: 0
diff changeset
330 {
kono
parents: 0
diff changeset
331 doacross->shift_counts[i - 1] = shift_count;
kono
parents: 0
diff changeset
332 shift_count += bits[i - 1];
kono
parents: 0
diff changeset
333 }
kono
parents: 0
diff changeset
334 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
335 *(unsigned long *) (doacross->array + ent * elt_sz) = 0;
kono
parents: 0
diff changeset
336 }
kono
parents: 0
diff changeset
337 else
kono
parents: 0
diff changeset
338 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
339 memset (doacross->array + ent * elt_sz, '\0',
kono
parents: 0
diff changeset
340 sizeof (unsigned long) * ncounts);
kono
parents: 0
diff changeset
341 if (ws->sched == GFS_STATIC && chunk_size == 0)
kono
parents: 0
diff changeset
342 {
kono
parents: 0
diff changeset
343 unsigned long q = counts[0] / num_ents;
kono
parents: 0
diff changeset
344 unsigned long t = counts[0] % num_ents;
kono
parents: 0
diff changeset
345 doacross->boundary = t * (q + 1);
kono
parents: 0
diff changeset
346 doacross->q = q;
kono
parents: 0
diff changeset
347 doacross->t = t;
kono
parents: 0
diff changeset
348 }
kono
parents: 0
diff changeset
349 ws->doacross = doacross;
kono
parents: 0
diff changeset
350 }
kono
parents: 0
diff changeset
351
kono
parents: 0
diff changeset
352 /* DOACROSS POST operation. */
kono
parents: 0
diff changeset
353
kono
parents: 0
diff changeset
354 void
kono
parents: 0
diff changeset
355 GOMP_doacross_post (long *counts)
kono
parents: 0
diff changeset
356 {
kono
parents: 0
diff changeset
357 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
358 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
359 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
360 unsigned long ent;
kono
parents: 0
diff changeset
361 unsigned int i;
kono
parents: 0
diff changeset
362
kono
parents: 0
diff changeset
363 if (__builtin_expect (doacross == NULL, 0))
kono
parents: 0
diff changeset
364 {
kono
parents: 0
diff changeset
365 __sync_synchronize ();
kono
parents: 0
diff changeset
366 return;
kono
parents: 0
diff changeset
367 }
kono
parents: 0
diff changeset
368
kono
parents: 0
diff changeset
369 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
370 ent = thr->ts.team_id;
kono
parents: 0
diff changeset
371 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
372 ent = counts[0];
kono
parents: 0
diff changeset
373 else
kono
parents: 0
diff changeset
374 ent = counts[0] / doacross->chunk_size;
kono
parents: 0
diff changeset
375 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
376 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
377
kono
parents: 0
diff changeset
378 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
379 {
kono
parents: 0
diff changeset
380 unsigned long flattened
kono
parents: 0
diff changeset
381 = (unsigned long) counts[0] << doacross->shift_counts[0];
kono
parents: 0
diff changeset
382
kono
parents: 0
diff changeset
383 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
384 flattened |= (unsigned long) counts[i]
kono
parents: 0
diff changeset
385 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
386 flattened++;
kono
parents: 0
diff changeset
387 if (flattened == __atomic_load_n (array, MEMMODEL_ACQUIRE))
kono
parents: 0
diff changeset
388 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
389 else
kono
parents: 0
diff changeset
390 __atomic_store_n (array, flattened, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
391 return;
kono
parents: 0
diff changeset
392 }
kono
parents: 0
diff changeset
393
kono
parents: 0
diff changeset
394 __atomic_thread_fence (MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
395 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
396 {
kono
parents: 0
diff changeset
397 if (counts[i] + 1UL != __atomic_load_n (&array[i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
398 __atomic_store_n (&array[i], counts[i] + 1UL, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
399 }
kono
parents: 0
diff changeset
400 }
kono
parents: 0
diff changeset
401
kono
parents: 0
diff changeset
402 /* DOACROSS WAIT operation. */
kono
parents: 0
diff changeset
403
kono
parents: 0
diff changeset
404 void
kono
parents: 0
diff changeset
405 GOMP_doacross_wait (long first, ...)
kono
parents: 0
diff changeset
406 {
kono
parents: 0
diff changeset
407 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
408 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
409 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
410 va_list ap;
kono
parents: 0
diff changeset
411 unsigned long ent;
kono
parents: 0
diff changeset
412 unsigned int i;
kono
parents: 0
diff changeset
413
kono
parents: 0
diff changeset
414 if (__builtin_expect (doacross == NULL, 0))
kono
parents: 0
diff changeset
415 {
kono
parents: 0
diff changeset
416 __sync_synchronize ();
kono
parents: 0
diff changeset
417 return;
kono
parents: 0
diff changeset
418 }
kono
parents: 0
diff changeset
419
kono
parents: 0
diff changeset
420 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
421 {
kono
parents: 0
diff changeset
422 if (ws->chunk_size == 0)
kono
parents: 0
diff changeset
423 {
kono
parents: 0
diff changeset
424 if (first < doacross->boundary)
kono
parents: 0
diff changeset
425 ent = first / (doacross->q + 1);
kono
parents: 0
diff changeset
426 else
kono
parents: 0
diff changeset
427 ent = (first - doacross->boundary) / doacross->q
kono
parents: 0
diff changeset
428 + doacross->t;
kono
parents: 0
diff changeset
429 }
kono
parents: 0
diff changeset
430 else
kono
parents: 0
diff changeset
431 ent = first / ws->chunk_size % thr->ts.team->nthreads;
kono
parents: 0
diff changeset
432 }
kono
parents: 0
diff changeset
433 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
434 ent = first;
kono
parents: 0
diff changeset
435 else
kono
parents: 0
diff changeset
436 ent = first / doacross->chunk_size;
kono
parents: 0
diff changeset
437 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
438 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
439
kono
parents: 0
diff changeset
440 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
441 {
kono
parents: 0
diff changeset
442 unsigned long flattened
kono
parents: 0
diff changeset
443 = (unsigned long) first << doacross->shift_counts[0];
kono
parents: 0
diff changeset
444 unsigned long cur;
kono
parents: 0
diff changeset
445
kono
parents: 0
diff changeset
446 va_start (ap, first);
kono
parents: 0
diff changeset
447 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
448 flattened |= (unsigned long) va_arg (ap, long)
kono
parents: 0
diff changeset
449 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
450 cur = __atomic_load_n (array, MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
451 if (flattened < cur)
kono
parents: 0
diff changeset
452 {
kono
parents: 0
diff changeset
453 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
454 va_end (ap);
kono
parents: 0
diff changeset
455 return;
kono
parents: 0
diff changeset
456 }
kono
parents: 0
diff changeset
457 doacross_spin (array, flattened, cur);
kono
parents: 0
diff changeset
458 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
459 va_end (ap);
kono
parents: 0
diff changeset
460 return;
kono
parents: 0
diff changeset
461 }
kono
parents: 0
diff changeset
462
kono
parents: 0
diff changeset
463 do
kono
parents: 0
diff changeset
464 {
kono
parents: 0
diff changeset
465 va_start (ap, first);
kono
parents: 0
diff changeset
466 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
467 {
kono
parents: 0
diff changeset
468 unsigned long thisv
kono
parents: 0
diff changeset
469 = (unsigned long) (i ? va_arg (ap, long) : first) + 1;
kono
parents: 0
diff changeset
470 unsigned long cur = __atomic_load_n (&array[i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
471 if (thisv < cur)
kono
parents: 0
diff changeset
472 {
kono
parents: 0
diff changeset
473 i = doacross->ncounts;
kono
parents: 0
diff changeset
474 break;
kono
parents: 0
diff changeset
475 }
kono
parents: 0
diff changeset
476 if (thisv > cur)
kono
parents: 0
diff changeset
477 break;
kono
parents: 0
diff changeset
478 }
kono
parents: 0
diff changeset
479 va_end (ap);
kono
parents: 0
diff changeset
480 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
481 break;
kono
parents: 0
diff changeset
482 cpu_relax ();
kono
parents: 0
diff changeset
483 }
kono
parents: 0
diff changeset
484 while (1);
kono
parents: 0
diff changeset
485 __sync_synchronize ();
kono
parents: 0
diff changeset
486 }
kono
parents: 0
diff changeset
487
kono
parents: 0
diff changeset
488 typedef unsigned long long gomp_ull;
kono
parents: 0
diff changeset
489
kono
parents: 0
diff changeset
490 void
kono
parents: 0
diff changeset
491 gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts, gomp_ull chunk_size)
kono
parents: 0
diff changeset
492 {
kono
parents: 0
diff changeset
493 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
494 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
495 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
496 unsigned int i, bits[MAX_COLLAPSED_BITS], num_bits = 0;
kono
parents: 0
diff changeset
497 unsigned long ent, num_ents, elt_sz, shift_sz;
kono
parents: 0
diff changeset
498 struct gomp_doacross_work_share *doacross;
kono
parents: 0
diff changeset
499
kono
parents: 0
diff changeset
500 if (team == NULL || team->nthreads == 1)
kono
parents: 0
diff changeset
501 return;
kono
parents: 0
diff changeset
502
kono
parents: 0
diff changeset
503 for (i = 0; i < ncounts; i++)
kono
parents: 0
diff changeset
504 {
kono
parents: 0
diff changeset
505 /* If any count is 0, GOMP_doacross_{post,wait} can't be called. */
kono
parents: 0
diff changeset
506 if (counts[i] == 0)
kono
parents: 0
diff changeset
507 return;
kono
parents: 0
diff changeset
508
kono
parents: 0
diff changeset
509 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
510 {
kono
parents: 0
diff changeset
511 unsigned int this_bits;
kono
parents: 0
diff changeset
512 if (counts[i] == 1)
kono
parents: 0
diff changeset
513 this_bits = 1;
kono
parents: 0
diff changeset
514 else
kono
parents: 0
diff changeset
515 this_bits = __SIZEOF_LONG_LONG__ * __CHAR_BIT__
kono
parents: 0
diff changeset
516 - __builtin_clzll (counts[i] - 1);
kono
parents: 0
diff changeset
517 if (num_bits + this_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
518 {
kono
parents: 0
diff changeset
519 bits[i] = this_bits;
kono
parents: 0
diff changeset
520 num_bits += this_bits;
kono
parents: 0
diff changeset
521 }
kono
parents: 0
diff changeset
522 else
kono
parents: 0
diff changeset
523 num_bits = MAX_COLLAPSED_BITS + 1;
kono
parents: 0
diff changeset
524 }
kono
parents: 0
diff changeset
525 }
kono
parents: 0
diff changeset
526
kono
parents: 0
diff changeset
527 if (ws->sched == GFS_STATIC)
kono
parents: 0
diff changeset
528 num_ents = team->nthreads;
kono
parents: 0
diff changeset
529 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
530 num_ents = counts[0];
kono
parents: 0
diff changeset
531 else
kono
parents: 0
diff changeset
532 num_ents = (counts[0] - 1) / chunk_size + 1;
kono
parents: 0
diff changeset
533 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
534 {
kono
parents: 0
diff changeset
535 elt_sz = sizeof (unsigned long);
kono
parents: 0
diff changeset
536 shift_sz = ncounts * sizeof (unsigned int);
kono
parents: 0
diff changeset
537 }
kono
parents: 0
diff changeset
538 else
kono
parents: 0
diff changeset
539 {
kono
parents: 0
diff changeset
540 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
541 elt_sz = sizeof (gomp_ull) * ncounts;
kono
parents: 0
diff changeset
542 else if (sizeof (gomp_ull) == 2 * sizeof (unsigned long))
kono
parents: 0
diff changeset
543 elt_sz = sizeof (unsigned long) * 2 * ncounts;
kono
parents: 0
diff changeset
544 else
kono
parents: 0
diff changeset
545 abort ();
kono
parents: 0
diff changeset
546 shift_sz = 0;
kono
parents: 0
diff changeset
547 }
kono
parents: 0
diff changeset
548 elt_sz = (elt_sz + 63) & ~63UL;
kono
parents: 0
diff changeset
549
kono
parents: 0
diff changeset
550 doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
kono
parents: 0
diff changeset
551 + shift_sz);
kono
parents: 0
diff changeset
552 doacross->chunk_size_ull = chunk_size;
kono
parents: 0
diff changeset
553 doacross->elt_sz = elt_sz;
kono
parents: 0
diff changeset
554 doacross->ncounts = ncounts;
kono
parents: 0
diff changeset
555 doacross->flattened = false;
kono
parents: 0
diff changeset
556 doacross->boundary = 0;
kono
parents: 0
diff changeset
557 doacross->array = (unsigned char *)
kono
parents: 0
diff changeset
558 ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
kono
parents: 0
diff changeset
559 & ~(uintptr_t) 63);
kono
parents: 0
diff changeset
560 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
561 {
kono
parents: 0
diff changeset
562 unsigned int shift_count = 0;
kono
parents: 0
diff changeset
563 doacross->flattened = true;
kono
parents: 0
diff changeset
564 for (i = ncounts; i > 0; i--)
kono
parents: 0
diff changeset
565 {
kono
parents: 0
diff changeset
566 doacross->shift_counts[i - 1] = shift_count;
kono
parents: 0
diff changeset
567 shift_count += bits[i - 1];
kono
parents: 0
diff changeset
568 }
kono
parents: 0
diff changeset
569 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
570 *(unsigned long *) (doacross->array + ent * elt_sz) = 0;
kono
parents: 0
diff changeset
571 }
kono
parents: 0
diff changeset
572 else
kono
parents: 0
diff changeset
573 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
574 memset (doacross->array + ent * elt_sz, '\0',
kono
parents: 0
diff changeset
575 sizeof (unsigned long) * ncounts);
kono
parents: 0
diff changeset
576 if (ws->sched == GFS_STATIC && chunk_size == 0)
kono
parents: 0
diff changeset
577 {
kono
parents: 0
diff changeset
578 gomp_ull q = counts[0] / num_ents;
kono
parents: 0
diff changeset
579 gomp_ull t = counts[0] % num_ents;
kono
parents: 0
diff changeset
580 doacross->boundary_ull = t * (q + 1);
kono
parents: 0
diff changeset
581 doacross->q_ull = q;
kono
parents: 0
diff changeset
582 doacross->t = t;
kono
parents: 0
diff changeset
583 }
kono
parents: 0
diff changeset
584 ws->doacross = doacross;
kono
parents: 0
diff changeset
585 }
kono
parents: 0
diff changeset
586
kono
parents: 0
diff changeset
587 /* DOACROSS POST operation. */
kono
parents: 0
diff changeset
588
kono
parents: 0
diff changeset
589 void
kono
parents: 0
diff changeset
590 GOMP_doacross_ull_post (gomp_ull *counts)
kono
parents: 0
diff changeset
591 {
kono
parents: 0
diff changeset
592 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
593 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
594 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
595 unsigned long ent;
kono
parents: 0
diff changeset
596 unsigned int i;
kono
parents: 0
diff changeset
597
kono
parents: 0
diff changeset
598 if (__builtin_expect (doacross == NULL, 0))
kono
parents: 0
diff changeset
599 {
kono
parents: 0
diff changeset
600 __sync_synchronize ();
kono
parents: 0
diff changeset
601 return;
kono
parents: 0
diff changeset
602 }
kono
parents: 0
diff changeset
603
kono
parents: 0
diff changeset
604 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
605 ent = thr->ts.team_id;
kono
parents: 0
diff changeset
606 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
607 ent = counts[0];
kono
parents: 0
diff changeset
608 else
kono
parents: 0
diff changeset
609 ent = counts[0] / doacross->chunk_size_ull;
kono
parents: 0
diff changeset
610
kono
parents: 0
diff changeset
611 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
612 {
kono
parents: 0
diff changeset
613 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
614 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
615 gomp_ull flattened
kono
parents: 0
diff changeset
616 = counts[0] << doacross->shift_counts[0];
kono
parents: 0
diff changeset
617
kono
parents: 0
diff changeset
618 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
619 flattened |= counts[i] << doacross->shift_counts[i];
kono
parents: 0
diff changeset
620 flattened++;
kono
parents: 0
diff changeset
621 if (flattened == __atomic_load_n (array, MEMMODEL_ACQUIRE))
kono
parents: 0
diff changeset
622 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
623 else
kono
parents: 0
diff changeset
624 __atomic_store_n (array, flattened, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
625 return;
kono
parents: 0
diff changeset
626 }
kono
parents: 0
diff changeset
627
kono
parents: 0
diff changeset
628 __atomic_thread_fence (MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
629 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
630 {
kono
parents: 0
diff changeset
631 gomp_ull *array = (gomp_ull *) (doacross->array
kono
parents: 0
diff changeset
632 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
633
kono
parents: 0
diff changeset
634 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
635 {
kono
parents: 0
diff changeset
636 if (counts[i] + 1UL != __atomic_load_n (&array[i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
637 __atomic_store_n (&array[i], counts[i] + 1UL, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
638 }
kono
parents: 0
diff changeset
639 }
kono
parents: 0
diff changeset
640 else
kono
parents: 0
diff changeset
641 {
kono
parents: 0
diff changeset
642 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
643 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
644
kono
parents: 0
diff changeset
645 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
646 {
kono
parents: 0
diff changeset
647 gomp_ull cull = counts[i] + 1UL;
kono
parents: 0
diff changeset
648 unsigned long c = (unsigned long) cull;
kono
parents: 0
diff changeset
649 if (c != __atomic_load_n (&array[2 * i + 1], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
650 __atomic_store_n (&array[2 * i + 1], c, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
651 c = cull >> (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ / 2);
kono
parents: 0
diff changeset
652 if (c != __atomic_load_n (&array[2 * i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
653 __atomic_store_n (&array[2 * i], c, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
654 }
kono
parents: 0
diff changeset
655 }
kono
parents: 0
diff changeset
656 }
kono
parents: 0
diff changeset
657
kono
parents: 0
diff changeset
658 /* DOACROSS WAIT operation. */
kono
parents: 0
diff changeset
659
kono
parents: 0
diff changeset
660 void
kono
parents: 0
diff changeset
661 GOMP_doacross_ull_wait (gomp_ull first, ...)
kono
parents: 0
diff changeset
662 {
kono
parents: 0
diff changeset
663 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
664 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
665 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
666 va_list ap;
kono
parents: 0
diff changeset
667 unsigned long ent;
kono
parents: 0
diff changeset
668 unsigned int i;
kono
parents: 0
diff changeset
669
kono
parents: 0
diff changeset
670 if (__builtin_expect (doacross == NULL, 0))
kono
parents: 0
diff changeset
671 {
kono
parents: 0
diff changeset
672 __sync_synchronize ();
kono
parents: 0
diff changeset
673 return;
kono
parents: 0
diff changeset
674 }
kono
parents: 0
diff changeset
675
kono
parents: 0
diff changeset
676 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
677 {
kono
parents: 0
diff changeset
678 if (ws->chunk_size_ull == 0)
kono
parents: 0
diff changeset
679 {
kono
parents: 0
diff changeset
680 if (first < doacross->boundary_ull)
kono
parents: 0
diff changeset
681 ent = first / (doacross->q_ull + 1);
kono
parents: 0
diff changeset
682 else
kono
parents: 0
diff changeset
683 ent = (first - doacross->boundary_ull) / doacross->q_ull
kono
parents: 0
diff changeset
684 + doacross->t;
kono
parents: 0
diff changeset
685 }
kono
parents: 0
diff changeset
686 else
kono
parents: 0
diff changeset
687 ent = first / ws->chunk_size_ull % thr->ts.team->nthreads;
kono
parents: 0
diff changeset
688 }
kono
parents: 0
diff changeset
689 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
690 ent = first;
kono
parents: 0
diff changeset
691 else
kono
parents: 0
diff changeset
692 ent = first / doacross->chunk_size_ull;
kono
parents: 0
diff changeset
693
kono
parents: 0
diff changeset
694 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
695 {
kono
parents: 0
diff changeset
696 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
697 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
698 gomp_ull flattened = first << doacross->shift_counts[0];
kono
parents: 0
diff changeset
699 unsigned long cur;
kono
parents: 0
diff changeset
700
kono
parents: 0
diff changeset
701 va_start (ap, first);
kono
parents: 0
diff changeset
702 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
703 flattened |= va_arg (ap, gomp_ull)
kono
parents: 0
diff changeset
704 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
705 cur = __atomic_load_n (array, MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
706 if (flattened < cur)
kono
parents: 0
diff changeset
707 {
kono
parents: 0
diff changeset
708 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
709 va_end (ap);
kono
parents: 0
diff changeset
710 return;
kono
parents: 0
diff changeset
711 }
kono
parents: 0
diff changeset
712 doacross_spin (array, flattened, cur);
kono
parents: 0
diff changeset
713 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
714 va_end (ap);
kono
parents: 0
diff changeset
715 return;
kono
parents: 0
diff changeset
716 }
kono
parents: 0
diff changeset
717
kono
parents: 0
diff changeset
718 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
719 {
kono
parents: 0
diff changeset
720 gomp_ull *array = (gomp_ull *) (doacross->array
kono
parents: 0
diff changeset
721 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
722 do
kono
parents: 0
diff changeset
723 {
kono
parents: 0
diff changeset
724 va_start (ap, first);
kono
parents: 0
diff changeset
725 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
726 {
kono
parents: 0
diff changeset
727 gomp_ull thisv
kono
parents: 0
diff changeset
728 = (i ? va_arg (ap, gomp_ull) : first) + 1;
kono
parents: 0
diff changeset
729 gomp_ull cur = __atomic_load_n (&array[i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
730 if (thisv < cur)
kono
parents: 0
diff changeset
731 {
kono
parents: 0
diff changeset
732 i = doacross->ncounts;
kono
parents: 0
diff changeset
733 break;
kono
parents: 0
diff changeset
734 }
kono
parents: 0
diff changeset
735 if (thisv > cur)
kono
parents: 0
diff changeset
736 break;
kono
parents: 0
diff changeset
737 }
kono
parents: 0
diff changeset
738 va_end (ap);
kono
parents: 0
diff changeset
739 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
740 break;
kono
parents: 0
diff changeset
741 cpu_relax ();
kono
parents: 0
diff changeset
742 }
kono
parents: 0
diff changeset
743 while (1);
kono
parents: 0
diff changeset
744 }
kono
parents: 0
diff changeset
745 else
kono
parents: 0
diff changeset
746 {
kono
parents: 0
diff changeset
747 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
748 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
749 do
kono
parents: 0
diff changeset
750 {
kono
parents: 0
diff changeset
751 va_start (ap, first);
kono
parents: 0
diff changeset
752 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
753 {
kono
parents: 0
diff changeset
754 gomp_ull thisv
kono
parents: 0
diff changeset
755 = (i ? va_arg (ap, gomp_ull) : first) + 1;
kono
parents: 0
diff changeset
756 unsigned long t
kono
parents: 0
diff changeset
757 = thisv >> (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ / 2);
kono
parents: 0
diff changeset
758 unsigned long cur
kono
parents: 0
diff changeset
759 = __atomic_load_n (&array[2 * i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
760 if (t < cur)
kono
parents: 0
diff changeset
761 {
kono
parents: 0
diff changeset
762 i = doacross->ncounts;
kono
parents: 0
diff changeset
763 break;
kono
parents: 0
diff changeset
764 }
kono
parents: 0
diff changeset
765 if (t > cur)
kono
parents: 0
diff changeset
766 break;
kono
parents: 0
diff changeset
767 t = thisv;
kono
parents: 0
diff changeset
768 cur = __atomic_load_n (&array[2 * i + 1], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
769 if (t < cur)
kono
parents: 0
diff changeset
770 {
kono
parents: 0
diff changeset
771 i = doacross->ncounts;
kono
parents: 0
diff changeset
772 break;
kono
parents: 0
diff changeset
773 }
kono
parents: 0
diff changeset
774 if (t > cur)
kono
parents: 0
diff changeset
775 break;
kono
parents: 0
diff changeset
776 }
kono
parents: 0
diff changeset
777 va_end (ap);
kono
parents: 0
diff changeset
778 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
779 break;
kono
parents: 0
diff changeset
780 cpu_relax ();
kono
parents: 0
diff changeset
781 }
kono
parents: 0
diff changeset
782 while (1);
kono
parents: 0
diff changeset
783 }
kono
parents: 0
diff changeset
784 __sync_synchronize ();
kono
parents: 0
diff changeset
785 }