aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-10-30 15:14:33 +0000
committerJonathan Wakely <jwakely@redhat.com>2020-10-30 20:58:08 +0000
commita1343e5c74093124d7fbce6052d838f47a8eeb20 (patch)
treee97bbf1e90e45518d94fd278478cf60bde60d08c
parentd1e5d82af819025df9d9a81e8c591690e299924a (diff)
downloadgcc-a1343e5c74093124d7fbce6052d838f47a8eeb20.zip
gcc-a1343e5c74093124d7fbce6052d838f47a8eeb20.tar.gz
gcc-a1343e5c74093124d7fbce6052d838f47a8eeb20.tar.bz2
libstdc++: Use double for unordered container load factors [PR 96958]
These calculations were changed to use long double nearly ten years ago in order to get more precision than float: https://gcc.gnu.org/pipermail/libstdc++/2011-September/036420.html However, double should be sufficient, whlie being potentially faster than long double, and not requiring soft FP calculations for targets without native long double support. libstdc++-v3/ChangeLog: PR libstdc++/96958 * include/bits/hashtable_policy.h (_Prime_rehash_policy) (_Power2_rehash_policy): Use double instead of long double.
-rw-r--r--libstdc++-v3/include/bits/hashtable_policy.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index cea5e54..7fed87f 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -458,7 +458,7 @@ namespace __detail
// Return a bucket count appropriate for n elements
std::size_t
_M_bkt_for_elements(std::size_t __n) const
- { return __builtin_ceill(__n / (long double)_M_max_load_factor); }
+ { return __builtin_ceill(__n / (double)_M_max_load_factor); }
// __n_bkt is current bucket count, __n_elt is current element count,
// and __n_ins is number of elements to be inserted. Do we need to
@@ -559,7 +559,7 @@ namespace __detail
_M_next_resize = size_t(-1);
else
_M_next_resize
- = __builtin_floorl(__res * (long double)_M_max_load_factor);
+ = __builtin_floorl(__res * (double)_M_max_load_factor);
return __res;
}
@@ -567,7 +567,7 @@ namespace __detail
// Return a bucket count appropriate for n elements
std::size_t
_M_bkt_for_elements(std::size_t __n) const noexcept
- { return __builtin_ceill(__n / (long double)_M_max_load_factor); }
+ { return __builtin_ceill(__n / (double)_M_max_load_factor); }
// __n_bkt is current bucket count, __n_elt is current element count,
// and __n_ins is number of elements to be inserted. Do we need to
@@ -582,16 +582,16 @@ namespace __detail
// If _M_next_resize is 0 it means that we have nothing allocated so
// far and that we start inserting elements. In this case we start
// with an initial bucket size of 11.
- long double __min_bkts
+ double __min_bkts
= std::max<std::size_t>(__n_elt + __n_ins, _M_next_resize ? 0 : 11)
- / (long double)_M_max_load_factor;
+ / (double)_M_max_load_factor;
if (__min_bkts >= __n_bkt)
return { true,
_M_next_bkt(std::max<std::size_t>(__builtin_floorl(__min_bkts) + 1,
__n_bkt * _S_growth_factor)) };
_M_next_resize
- = __builtin_floorl(__n_bkt * (long double)_M_max_load_factor);
+ = __builtin_floorl(__n_bkt * (double)_M_max_load_factor);
return { false, 0 };
}
else