aboutsummaryrefslogtreecommitdiff
path: root/libgcc/libgcov-profiler.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgcc/libgcov-profiler.c')
-rw-r--r--libgcc/libgcov-profiler.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index 9417904..f45ef49 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -119,37 +119,35 @@ __gcov_topn_values_profiler_body (gcov_type *counters, gcov_type value,
++counters;
- /* We have GCOV_TOPN_VALUES as we can keep multiple values
- next to each other. */
- unsigned sindex = 0;
-
for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
{
if (value == counters[2 * i])
{
if (use_atomic)
- __atomic_fetch_add (&counters[2 * i + 1], 1, __ATOMIC_RELAXED);
+ __atomic_fetch_add (&counters[2 * i + 1], GCOV_TOPN_VALUES,
+ __ATOMIC_RELAXED);
else
- counters[2 * i + 1]++;
+ counters[2 * i + 1] += GCOV_TOPN_VALUES;
return;
}
- else if (counters[2 * i + 1] == 0)
+ else if (counters[2 * i + 1] <= 0)
{
/* We found an empty slot. */
counters[2 * i] = value;
- counters[2 * i + 1] = 1;
+ counters[2 * i + 1] = GCOV_TOPN_VALUES;
return;
}
-
- if (counters[2 * i + 1] < counters[2 * sindex + 1])
- sindex = i;
}
- /* We haven't found an empty slot, then decrement the smallest. */
- if (use_atomic)
- __atomic_fetch_sub (&counters[2 * sindex + 1], 1, __ATOMIC_RELAXED);
- else
- counters[2 * sindex + 1]--;
+ /* We haven't found an empty slot, then decrement all
+ counter values by one. */
+ for (unsigned i = 0; i < GCOV_TOPN_VALUES; i++)
+ {
+ if (use_atomic)
+ __atomic_fetch_sub (&counters[2 * i + 1], 1, __ATOMIC_RELAXED);
+ else
+ counters[2 * i + 1]--;
+ }
}
#ifdef L_gcov_topn_values_profiler