annotate libgcc/libgcov-profiler.c @ 120:f93fa5091070

fix conv1.c
author mir3636
date Thu, 08 Mar 2018 14:53:42 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Routines required for instrumenting a program. */
kono
parents:
diff changeset
2 /* Compile this one with gcc. */
kono
parents:
diff changeset
3 /* Copyright (C) 1989-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "libgcov.h"
kono
parents:
diff changeset
27 #if !defined(inhibit_libc)
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 /* Detect whether target can support atomic update of profilers. */
kono
parents:
diff changeset
30 #if __SIZEOF_LONG_LONG__ == 4 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
kono
parents:
diff changeset
31 #define GCOV_SUPPORTS_ATOMIC 1
kono
parents:
diff changeset
32 #else
kono
parents:
diff changeset
33 #if __SIZEOF_LONG_LONG__ == 8 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
kono
parents:
diff changeset
34 #define GCOV_SUPPORTS_ATOMIC 1
kono
parents:
diff changeset
35 #else
kono
parents:
diff changeset
36 #define GCOV_SUPPORTS_ATOMIC 0
kono
parents:
diff changeset
37 #endif
kono
parents:
diff changeset
38 #endif
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #ifdef L_gcov_interval_profiler
kono
parents:
diff changeset
41 /* If VALUE is in interval <START, START + STEPS - 1>, then increases the
kono
parents:
diff changeset
42 corresponding counter in COUNTERS. If the VALUE is above or below
kono
parents:
diff changeset
43 the interval, COUNTERS[STEPS] or COUNTERS[STEPS + 1] is increased
kono
parents:
diff changeset
44 instead. */
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 void
kono
parents:
diff changeset
47 __gcov_interval_profiler (gcov_type *counters, gcov_type value,
kono
parents:
diff changeset
48 int start, unsigned steps)
kono
parents:
diff changeset
49 {
kono
parents:
diff changeset
50 gcov_type delta = value - start;
kono
parents:
diff changeset
51 if (delta < 0)
kono
parents:
diff changeset
52 counters[steps + 1]++;
kono
parents:
diff changeset
53 else if (delta >= steps)
kono
parents:
diff changeset
54 counters[steps]++;
kono
parents:
diff changeset
55 else
kono
parents:
diff changeset
56 counters[delta]++;
kono
parents:
diff changeset
57 }
kono
parents:
diff changeset
58 #endif
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 #if defined(L_gcov_interval_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
kono
parents:
diff changeset
61 /* If VALUE is in interval <START, START + STEPS - 1>, then increases the
kono
parents:
diff changeset
62 corresponding counter in COUNTERS. If the VALUE is above or below
kono
parents:
diff changeset
63 the interval, COUNTERS[STEPS] or COUNTERS[STEPS + 1] is increased
kono
parents:
diff changeset
64 instead. Function is thread-safe. */
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 void
kono
parents:
diff changeset
67 __gcov_interval_profiler_atomic (gcov_type *counters, gcov_type value,
kono
parents:
diff changeset
68 int start, unsigned steps)
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 gcov_type delta = value - start;
kono
parents:
diff changeset
71 if (delta < 0)
kono
parents:
diff changeset
72 __atomic_fetch_add (&counters[steps + 1], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
73 else if (delta >= steps)
kono
parents:
diff changeset
74 __atomic_fetch_add (&counters[steps], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
75 else
kono
parents:
diff changeset
76 __atomic_fetch_add (&counters[delta], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
77 }
kono
parents:
diff changeset
78 #endif
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 #ifdef L_gcov_pow2_profiler
kono
parents:
diff changeset
81 /* If VALUE is a power of two, COUNTERS[1] is incremented. Otherwise
kono
parents:
diff changeset
82 COUNTERS[0] is incremented. */
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 void
kono
parents:
diff changeset
85 __gcov_pow2_profiler (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 if (value == 0 || (value & (value - 1)))
kono
parents:
diff changeset
88 counters[0]++;
kono
parents:
diff changeset
89 else
kono
parents:
diff changeset
90 counters[1]++;
kono
parents:
diff changeset
91 }
kono
parents:
diff changeset
92 #endif
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 #if defined(L_gcov_pow2_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
kono
parents:
diff changeset
95 /* If VALUE is a power of two, COUNTERS[1] is incremented. Otherwise
kono
parents:
diff changeset
96 COUNTERS[0] is incremented. Function is thread-safe. */
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 void
kono
parents:
diff changeset
99 __gcov_pow2_profiler_atomic (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
100 {
kono
parents:
diff changeset
101 if (value == 0 || (value & (value - 1)))
kono
parents:
diff changeset
102 __atomic_fetch_add (&counters[0], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
103 else
kono
parents:
diff changeset
104 __atomic_fetch_add (&counters[1], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106 #endif
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 /* Tries to determine the most common value among its inputs. Checks if the
kono
parents:
diff changeset
110 value stored in COUNTERS[0] matches VALUE. If this is the case, COUNTERS[1]
kono
parents:
diff changeset
111 is incremented. If this is not the case and COUNTERS[1] is not zero,
kono
parents:
diff changeset
112 COUNTERS[1] is decremented. Otherwise COUNTERS[1] is set to one and
kono
parents:
diff changeset
113 VALUE is stored to COUNTERS[0]. This algorithm guarantees that if this
kono
parents:
diff changeset
114 function is called more than 50% of the time with one value, this value
kono
parents:
diff changeset
115 will be in COUNTERS[0] in the end.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 In any case, COUNTERS[2] is incremented. If USE_ATOMIC is set to 1,
kono
parents:
diff changeset
118 COUNTERS[2] is updated with an atomic instruction. */
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 static inline void
kono
parents:
diff changeset
121 __gcov_one_value_profiler_body (gcov_type *counters, gcov_type value,
kono
parents:
diff changeset
122 int use_atomic)
kono
parents:
diff changeset
123 {
kono
parents:
diff changeset
124 if (value == counters[0])
kono
parents:
diff changeset
125 counters[1]++;
kono
parents:
diff changeset
126 else if (counters[1] == 0)
kono
parents:
diff changeset
127 {
kono
parents:
diff changeset
128 counters[1] = 1;
kono
parents:
diff changeset
129 counters[0] = value;
kono
parents:
diff changeset
130 }
kono
parents:
diff changeset
131 else
kono
parents:
diff changeset
132 counters[1]--;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 if (use_atomic)
kono
parents:
diff changeset
135 __atomic_fetch_add (&counters[2], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
136 else
kono
parents:
diff changeset
137 counters[2]++;
kono
parents:
diff changeset
138 }
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 #ifdef L_gcov_one_value_profiler
kono
parents:
diff changeset
141 void
kono
parents:
diff changeset
142 __gcov_one_value_profiler (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
143 {
kono
parents:
diff changeset
144 __gcov_one_value_profiler_body (counters, value, 0);
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146 #endif
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 #if defined(L_gcov_one_value_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 /* Update one value profilers (COUNTERS) for a given VALUE.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 CAVEAT: Following function is not thread-safe, only total number
kono
parents:
diff changeset
153 of executions (COUNTERS[2]) is update with an atomic instruction.
kono
parents:
diff changeset
154 Problem is that one cannot atomically update two counters
kono
parents:
diff changeset
155 (COUNTERS[0] and COUNTERS[1]), for more information please read
kono
parents:
diff changeset
156 following email thread:
kono
parents:
diff changeset
157 https://gcc.gnu.org/ml/gcc-patches/2016-08/msg00024.html. */
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 void
kono
parents:
diff changeset
160 __gcov_one_value_profiler_atomic (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
161 {
kono
parents:
diff changeset
162 __gcov_one_value_profiler_body (counters, value, 1);
kono
parents:
diff changeset
163 }
kono
parents:
diff changeset
164 #endif
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 #ifdef L_gcov_indirect_call_topn_profiler
kono
parents:
diff changeset
167 /* Tries to keep track the most frequent N values in the counters where
kono
parents:
diff changeset
168 N is specified by parameter TOPN_VAL. To track top N values, 2*N counter
kono
parents:
diff changeset
169 entries are used.
kono
parents:
diff changeset
170 counter[0] --- the accumative count of the number of times one entry in
kono
parents:
diff changeset
171 in the counters gets evicted/replaced due to limited capacity.
kono
parents:
diff changeset
172 When this value reaches a threshold, the bottom N values are
kono
parents:
diff changeset
173 cleared.
kono
parents:
diff changeset
174 counter[1] through counter[2*N] records the top 2*N values collected so far.
kono
parents:
diff changeset
175 Each value is represented by two entries: count[2*i+1] is the ith value, and
kono
parents:
diff changeset
176 count[2*i+2] is the number of times the value is seen. */
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 static void
kono
parents:
diff changeset
179 __gcov_topn_value_profiler_body (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 unsigned i, found = 0, have_zero_count = 0;
kono
parents:
diff changeset
182 gcov_type *entry;
kono
parents:
diff changeset
183 gcov_type *lfu_entry = &counters[1];
kono
parents:
diff changeset
184 gcov_type *value_array = &counters[1];
kono
parents:
diff changeset
185 gcov_type *num_eviction = &counters[0];
kono
parents:
diff changeset
186 gcov_unsigned_t topn_val = GCOV_ICALL_TOPN_VAL;
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 /* There are 2*topn_val values tracked, each value takes two slots in the
kono
parents:
diff changeset
189 counter array. */
kono
parents:
diff changeset
190 for (i = 0; i < (topn_val << 2); i += 2)
kono
parents:
diff changeset
191 {
kono
parents:
diff changeset
192 entry = &value_array[i];
kono
parents:
diff changeset
193 if (entry[0] == value)
kono
parents:
diff changeset
194 {
kono
parents:
diff changeset
195 entry[1]++ ;
kono
parents:
diff changeset
196 found = 1;
kono
parents:
diff changeset
197 break;
kono
parents:
diff changeset
198 }
kono
parents:
diff changeset
199 else if (entry[1] == 0)
kono
parents:
diff changeset
200 {
kono
parents:
diff changeset
201 lfu_entry = entry;
kono
parents:
diff changeset
202 have_zero_count = 1;
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204 else if (entry[1] < lfu_entry[1])
kono
parents:
diff changeset
205 lfu_entry = entry;
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 if (found)
kono
parents:
diff changeset
209 return;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 /* lfu_entry is either an empty entry or an entry
kono
parents:
diff changeset
212 with lowest count, which will be evicted. */
kono
parents:
diff changeset
213 lfu_entry[0] = value;
kono
parents:
diff changeset
214 lfu_entry[1] = 1;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 #define GCOV_ICALL_COUNTER_CLEAR_THRESHOLD 3000
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 /* Too many evictions -- time to clear bottom entries to
kono
parents:
diff changeset
219 avoid hot values bumping each other out. */
kono
parents:
diff changeset
220 if (!have_zero_count
kono
parents:
diff changeset
221 && ++*num_eviction >= GCOV_ICALL_COUNTER_CLEAR_THRESHOLD)
kono
parents:
diff changeset
222 {
kono
parents:
diff changeset
223 unsigned i, j;
kono
parents:
diff changeset
224 gcov_type *p, minv;
kono
parents:
diff changeset
225 gcov_type* tmp_cnts
kono
parents:
diff changeset
226 = (gcov_type *)alloca (topn_val * sizeof (gcov_type));
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 *num_eviction = 0;
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 for (i = 0; i < topn_val; i++)
kono
parents:
diff changeset
231 tmp_cnts[i] = 0;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 /* Find the largest topn_val values from the group of
kono
parents:
diff changeset
234 2*topn_val values and put them into tmp_cnts. */
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 for (i = 0; i < 2 * topn_val; i += 2)
kono
parents:
diff changeset
237 {
kono
parents:
diff changeset
238 p = 0;
kono
parents:
diff changeset
239 for (j = 0; j < topn_val; j++)
kono
parents:
diff changeset
240 {
kono
parents:
diff changeset
241 if (!p || tmp_cnts[j] < *p)
kono
parents:
diff changeset
242 p = &tmp_cnts[j];
kono
parents:
diff changeset
243 }
kono
parents:
diff changeset
244 if (value_array[i + 1] > *p)
kono
parents:
diff changeset
245 *p = value_array[i + 1];
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 minv = tmp_cnts[0];
kono
parents:
diff changeset
249 for (j = 1; j < topn_val; j++)
kono
parents:
diff changeset
250 {
kono
parents:
diff changeset
251 if (tmp_cnts[j] < minv)
kono
parents:
diff changeset
252 minv = tmp_cnts[j];
kono
parents:
diff changeset
253 }
kono
parents:
diff changeset
254 /* Zero out low value entries. */
kono
parents:
diff changeset
255 for (i = 0; i < 2 * topn_val; i += 2)
kono
parents:
diff changeset
256 {
kono
parents:
diff changeset
257 if (value_array[i + 1] < minv)
kono
parents:
diff changeset
258 {
kono
parents:
diff changeset
259 value_array[i] = 0;
kono
parents:
diff changeset
260 value_array[i + 1] = 0;
kono
parents:
diff changeset
261 }
kono
parents:
diff changeset
262 }
kono
parents:
diff changeset
263 }
kono
parents:
diff changeset
264 }
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 /* These two variables are used to actually track caller and callee. Keep
kono
parents:
diff changeset
267 them in TLS memory so races are not common (they are written to often).
kono
parents:
diff changeset
268 The variables are set directly by GCC instrumented code, so declaration
kono
parents:
diff changeset
269 here must match one in tree-profile.c. */
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 #if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
kono
parents:
diff changeset
272 __thread
kono
parents:
diff changeset
273 #endif
kono
parents:
diff changeset
274 gcov_type *__gcov_indirect_call_topn_counters ATTRIBUTE_HIDDEN;
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 #if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
kono
parents:
diff changeset
277 __thread
kono
parents:
diff changeset
278 #endif
kono
parents:
diff changeset
279 void *__gcov_indirect_call_topn_callee ATTRIBUTE_HIDDEN;
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 #ifdef TARGET_VTABLE_USES_DESCRIPTORS
kono
parents:
diff changeset
282 #define VTABLE_USES_DESCRIPTORS 1
kono
parents:
diff changeset
283 #else
kono
parents:
diff changeset
284 #define VTABLE_USES_DESCRIPTORS 0
kono
parents:
diff changeset
285 #endif
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 /* This fucntion is instrumented at function entry to track topn indirect
kono
parents:
diff changeset
288 calls to CUR_FUNC. */
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 void
kono
parents:
diff changeset
291 __gcov_indirect_call_topn_profiler (gcov_type value, void* cur_func)
kono
parents:
diff changeset
292 {
kono
parents:
diff changeset
293 void *callee_func = __gcov_indirect_call_topn_callee;
kono
parents:
diff changeset
294 /* If the C++ virtual tables contain function descriptors then one
kono
parents:
diff changeset
295 function may have multiple descriptors and we need to dereference
kono
parents:
diff changeset
296 the descriptors to see if they point to the same function. */
kono
parents:
diff changeset
297 if (cur_func == callee_func
kono
parents:
diff changeset
298 || (VTABLE_USES_DESCRIPTORS && callee_func
kono
parents:
diff changeset
299 && *(void **) cur_func == *(void **) callee_func))
kono
parents:
diff changeset
300 __gcov_topn_value_profiler_body (__gcov_indirect_call_topn_counters, value);
kono
parents:
diff changeset
301 }
kono
parents:
diff changeset
302 #endif
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 #ifdef L_gcov_indirect_call_profiler_v2
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 /* These two variables are used to actually track caller and callee. Keep
kono
parents:
diff changeset
307 them in TLS memory so races are not common (they are written to often).
kono
parents:
diff changeset
308 The variables are set directly by GCC instrumented code, so declaration
kono
parents:
diff changeset
309 here must match one in tree-profile.c */
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 #if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
kono
parents:
diff changeset
312 __thread
kono
parents:
diff changeset
313 #endif
kono
parents:
diff changeset
314 void * __gcov_indirect_call_callee;
kono
parents:
diff changeset
315 #if defined(HAVE_CC_TLS) && !defined (USE_EMUTLS)
kono
parents:
diff changeset
316 __thread
kono
parents:
diff changeset
317 #endif
kono
parents:
diff changeset
318 gcov_type * __gcov_indirect_call_counters;
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 /* By default, the C++ compiler will use function addresses in the
kono
parents:
diff changeset
321 vtable entries. Setting TARGET_VTABLE_USES_DESCRIPTORS to nonzero
kono
parents:
diff changeset
322 tells the compiler to use function descriptors instead. The value
kono
parents:
diff changeset
323 of this macro says how many words wide the descriptor is (normally 2).
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 It is assumed that the address of a function descriptor may be treated
kono
parents:
diff changeset
326 as a pointer to a function. */
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 /* Tries to determine the most common value among its inputs. */
kono
parents:
diff changeset
329 void
kono
parents:
diff changeset
330 __gcov_indirect_call_profiler_v2 (gcov_type value, void* cur_func)
kono
parents:
diff changeset
331 {
kono
parents:
diff changeset
332 /* If the C++ virtual tables contain function descriptors then one
kono
parents:
diff changeset
333 function may have multiple descriptors and we need to dereference
kono
parents:
diff changeset
334 the descriptors to see if they point to the same function. */
kono
parents:
diff changeset
335 if (cur_func == __gcov_indirect_call_callee
kono
parents:
diff changeset
336 || (__LIBGCC_VTABLE_USES_DESCRIPTORS__ && __gcov_indirect_call_callee
kono
parents:
diff changeset
337 && *(void **) cur_func == *(void **) __gcov_indirect_call_callee))
kono
parents:
diff changeset
338 __gcov_one_value_profiler_body (__gcov_indirect_call_counters, value, 0);
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 __gcov_indirect_call_callee = NULL;
kono
parents:
diff changeset
341 }
kono
parents:
diff changeset
342 #endif
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 #ifdef L_gcov_time_profiler
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346 /* Counter for first visit of each function. */
kono
parents:
diff changeset
347 gcov_type __gcov_time_profiler_counter ATTRIBUTE_HIDDEN;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 #endif
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 #ifdef L_gcov_average_profiler
kono
parents:
diff changeset
352 /* Increase corresponding COUNTER by VALUE. FIXME: Perhaps we want
kono
parents:
diff changeset
353 to saturate up. */
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 void
kono
parents:
diff changeset
356 __gcov_average_profiler (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
357 {
kono
parents:
diff changeset
358 counters[0] += value;
kono
parents:
diff changeset
359 counters[1] ++;
kono
parents:
diff changeset
360 }
kono
parents:
diff changeset
361 #endif
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 #if defined(L_gcov_average_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
kono
parents:
diff changeset
364 /* Increase corresponding COUNTER by VALUE. FIXME: Perhaps we want
kono
parents:
diff changeset
365 to saturate up. Function is thread-safe. */
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 void
kono
parents:
diff changeset
368 __gcov_average_profiler_atomic (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
369 {
kono
parents:
diff changeset
370 __atomic_fetch_add (&counters[0], value, __ATOMIC_RELAXED);
kono
parents:
diff changeset
371 __atomic_fetch_add (&counters[1], 1, __ATOMIC_RELAXED);
kono
parents:
diff changeset
372 }
kono
parents:
diff changeset
373 #endif
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 #ifdef L_gcov_ior_profiler
kono
parents:
diff changeset
376 /* Bitwise-OR VALUE into COUNTER. */
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 void
kono
parents:
diff changeset
379 __gcov_ior_profiler (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
380 {
kono
parents:
diff changeset
381 *counters |= value;
kono
parents:
diff changeset
382 }
kono
parents:
diff changeset
383 #endif
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 #if defined(L_gcov_ior_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
kono
parents:
diff changeset
386 /* Bitwise-OR VALUE into COUNTER. Function is thread-safe. */
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 void
kono
parents:
diff changeset
389 __gcov_ior_profiler_atomic (gcov_type *counters, gcov_type value)
kono
parents:
diff changeset
390 {
kono
parents:
diff changeset
391 __atomic_fetch_or (&counters[0], value, __ATOMIC_RELAXED);
kono
parents:
diff changeset
392 }
kono
parents:
diff changeset
393 #endif
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 #endif /* inhibit_libc */