From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: libstdc++: Extend memcmp optimization in std::lexicographical_compare
Date: Tue, 9 Jun 2020 00:02:22 +0100 [thread overview]
Message-ID: <20200608230222.GT4137376@redhat.com> (raw)
In-Reply-To: <20200608210806.GS4137376@redhat.com>
On 08/06/20 22:08 +0100, Jonathan Wakely wrote:
>On 08/06/20 19:20 +0100, Jonathan Wakely wrote:
>>On 05/06/20 22:24 +0200, François Dumont via Libstdc++ wrote:
>>>Hi
>>>
>>>Â Â Â Here is the last of my algo patches this time to extend the
>>>memcmp optimization to std::deque iterators and _GLIBCXX_DEBUG
>>>mode.
>>>
>>>Â Â Â To do so I had to return int in implementation details of
>>>lexicographical_compare to make sure we can treat a deque iterator
>>>range by chunk in a performant way.
>
>Here's a simpler version, which doesn't alter anything for the
>existing code (i.e. all iterators that aren't deque iterators) and
>also fixes the infinite loop bug.
>
>This seems simpler and less invasive.
>
>Please take a look.
I've actually tested it in debug mode now, and ...
>diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc
>index 888ac803ae5..db6a301655f 100644
>--- a/libstdc++-v3/include/debug/safe_iterator.tcc
>+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
>@@ -470,6 +470,80 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> return __equal_aux1(__first1, __last1, __first2);
> }
>
>+ template<typename _Ite1, typename _Seq1, typename _Cat1,
>+ typename _II2>
>+ int
This should return bool here.
>+ __lexicographical_compare_aux(
>+ const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
>+ const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
>+ _II2 __first2, _II2 __last2)
>+ {
>+ typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
>+ __glibcxx_check_valid_range2(__first1, __last1, __dist1);
>+ __glibcxx_check_valid_range(__first2, __last2);
>+
>+ if (__dist1.second > ::__gnu_debug::__dp_equality)
>+ return std::__lexicographical_compare_aux(__first1.base(),
>+ __last1.base(),
>+ __first2, __last2);
>+ return std::__lexicographical_compare_aux1(__first1, __last1,
>+ __first2, __last2);
>+ }
>+
>+ template<typename _II1,
>+ typename _Ite2, typename _Seq2, typename _Cat2>
>+ int
And here.
>+ __lexicographical_compare_aux(
>+ _II1 __first1, _II1 __last1,
>+ const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
>+ const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
>+ {
>+ __glibcxx_check_valid_range(__first1, __last1);
>+ typename ::__gnu_debug::_Distance_traits<_II1>::__type __dist2;
>+ __glibcxx_check_valid_range2(__first2, __last2, __dist2);
>+
>+ if (__dist2.second > ::__gnu_debug::__dp_equality)
>+ return std::__lexicographical_compare_aux(__first1, __last1,
>+ __first2.base(),
>+ __last2.base());
>+ return std::__lexicographical_compare_aux1(__first1, __last1,
>+ __first2, __last2);
>+ }
>+
>+ template<typename _Ite1, typename _Seq1, typename _Cat1,
>+ typename _Ite2, typename _Seq2, typename _Cat2>
>+ int
And here.
>+ __lexicographical_compare_aux(
>+ const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __first1,
>+ const ::__gnu_debug::_Safe_iterator<_Ite1, _Seq1, _Cat1>& __last1,
>+ const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __first2,
>+ const ::__gnu_debug::_Safe_iterator<_Ite2, _Seq2, _Cat2>& __last2)
>+ {
>+ typename ::__gnu_debug::_Distance_traits<_Ite1>::__type __dist1;
>+ __glibcxx_check_valid_range2(__first1, __last1, __dist1);
>+ typename ::__gnu_debug::_Distance_traits<_Ite2>::__type __dist2;
>+ __glibcxx_check_valid_range2(__first2, __last2, __dist2);
>+
>+ if (__dist1.second > ::__gnu_debug::__dp_equality)
>+ {
>+ if (__dist2.second > ::__gnu_debug::__dp_equality)
>+ return std::__lexicographical_compare_aux(__first1.base(),
>+ __last1.base(),
>+ __first2.base(),
>+ __last2.base());
>+ return std::__lexicographical_compare_aux(__first1.base(),
>+ __last1.base(),
>+ __first2, __last2);
>+ }
>+
>+ if (__dist2.second > ::__gnu_debug::__dp_equality)
>+ return std::__lexicographical_compare_aux(__first1, __last1,
>+ __first2.base(),
>+ __last2.base());
>+ return std::__lexicographical_compare_aux1(__first1, __last1,
>+ __first2, __last2);
>+ }
>+
> _GLIBCXX_END_NAMESPACE_VERSION
> } // namespace std
next prev parent reply other threads:[~2020-06-08 23:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-05 20:24 François Dumont
2020-06-08 18:20 ` Jonathan Wakely
2020-06-08 21:08 ` Jonathan Wakely
2020-06-08 23:02 ` Jonathan Wakely [this message]
2020-06-09 16:11 ` Jonathan Wakely
2020-06-09 16:12 ` Jonathan Wakely
2020-06-09 20:42 ` François Dumont
2020-06-09 20:53 ` Jonathan Wakely
2020-06-10 6:18 ` François Dumont
2020-06-10 14:49 ` Jonathan Wakely
2020-06-10 16:40 ` François Dumont
2020-06-10 17:14 ` Jonathan Wakely
2020-06-09 10:24 ` Jonathan Wakely
2020-06-09 20:35 ` François Dumont
2020-06-09 20:50 ` Jonathan Wakely
2020-06-09 20:20 ` François Dumont
2020-06-09 20:38 ` Jonathan Wakely
2020-06-08 20:07 ` Jonathan Wakely
2020-06-08 21:05 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200608230222.GT4137376@redhat.com \
--to=jwakely@redhat.com \
--cc=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).