* [committed] libstdc++: Use double for unordered container load factors [PR 96958]
@ 2020-10-31 0:23 Jonathan Wakely
2020-10-31 1:14 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2020-10-31 0:23 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
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.
Tested powerpc64le-linux. Committed to trunk.
This doesn't fix the PR, because there are also long double
calculations in src/c++11/hashtable_c++0x.cc, so another patch is
needed.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3005 bytes --]
commit a1343e5c74093124d7fbce6052d838f47a8eeb20
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Oct 30 15:14:33 2020
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.
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index cea5e549d253..7fed87f1c76b 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [committed] libstdc++: Use double for unordered container load factors [PR 96958]
2020-10-31 0:23 [committed] libstdc++: Use double for unordered container load factors [PR 96958] Jonathan Wakely
@ 2020-10-31 1:14 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2020-10-31 1:14 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 997 bytes --]
On 31/10/20 00:23 +0000, Jonathan Wakely wrote:
>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.
>
>Tested powerpc64le-linux. Committed to trunk.
>
>This doesn't fix the PR, because there are also long double
>calculations in src/c++11/hashtable_c++0x.cc, so another patch is
>needed.
Here's that other patch. This also fixes some failures I was seeing
when mixing -mabi=ieeelongdouble with -mabi=ibmlongdouble in a local
branch for the ieee128 transition work.
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 4335 bytes --]
commit 943cc2a1b70f2d755b4fed97b1c4b49234d92899
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Oct 31 00:52:57 2020
libstdc++: Use double for unordered container load factors [PR 96958]
My previous commit for this PR changed the types from long double to
double, but didn't change the uses of __builtin_ceill and
__builtin_floorl. It also failed to change the non-inline functions in
src/c++11/hashtable_c++0x.cc. This should fix it properly now.
libstdc++-v3/ChangeLog:
PR libstdc++/96958
* include/bits/hashtable_policy.h (_Prime_rehash_policy)
(_Power2_rehash_policy): Use ceil and floor instead of ceill and
floorl.
* src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy): Likewise.
Use double instead of long double.
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 7fed87f1c76b..28372979c873 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 / (double)_M_max_load_factor); }
+ { return __builtin_ceil(__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 * (double)_M_max_load_factor);
+ = __builtin_floor(__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 / (double)_M_max_load_factor); }
+ { return __builtin_ceil(__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
@@ -587,11 +587,11 @@ namespace __detail
/ (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,
+ _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
__n_bkt * _S_growth_factor)) };
_M_next_resize
- = __builtin_floorl(__n_bkt * (double)_M_max_load_factor);
+ = __builtin_floor(__n_bkt * (double)_M_max_load_factor);
return { false, 0 };
}
else
diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
index 62762f34cafc..4dec2a84641e 100644
--- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc
+++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
@@ -58,7 +58,7 @@ namespace __detail
return 1;
_M_next_resize =
- __builtin_floorl(__fast_bkt[__n] * (long double)_M_max_load_factor);
+ __builtin_floor(__fast_bkt[__n] * (double)_M_max_load_factor);
return __fast_bkt[__n];
}
@@ -81,7 +81,7 @@ namespace __detail
_M_next_resize = size_t(-1);
else
_M_next_resize =
- __builtin_floorl(*__next_bkt * (long double)_M_max_load_factor);
+ __builtin_floor(*__next_bkt * (double)_M_max_load_factor);
return *__next_bkt;
}
@@ -105,16 +105,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,
+ _M_next_bkt(std::max<std::size_t>(__builtin_floor(__min_bkts) + 1,
__n_bkt * _S_growth_factor)) };
_M_next_resize
- = __builtin_floorl(__n_bkt * (long double)_M_max_load_factor);
+ = __builtin_floor(__n_bkt * (double)_M_max_load_factor);
return { false, 0 };
}
else
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-31 1:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-31 0:23 [committed] libstdc++: Use double for unordered container load factors [PR 96958] Jonathan Wakely
2020-10-31 1:14 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).