Limit Debug mode impact: overload __niter_base
François Dumont
frs.dumont@gmail.com
Mon Jun 18 21:02:00 GMT 2018
Hi
   I abandon the idea of providing Debug algos, it would be too much
code to add and maintain. However I haven't quit on reducing Debug mode
performance impact.
   So this patch make use of the existing std::__niter_base to get rid
of the debug layer around __gnu_debug::vector<>::iterator so that
__builtin_memmove replacement can take place.
   As _Safe_iterator<> do not have a constructor taking a pointer I
change algos implementation so that we do not try to instantiate the
iterator type ourselves but rather rely on its operators + or -.
   The small drawback is that for std::equal algo where we can't use
the __glibcxx_can_increment we need to keep the debug layer to make sure
we don't reach past-the-end iterator. So I had to remove usage of
__niter_base when in Debug mode, doing so it also disable potential
usage of __builtin_memcmp when calling std::equal on
std::__cxx1998::vector<> iterators. A rather rare situation I think.
   Note that I don't know how to test that __builtin_memmove has been
indeed used. So I've been through some debug sessions to check that.
   I am not really happy with ChangeLog entry I came up with, I'll try
to improve it before this patch is validated.
   * include/bits/stl_algobase.h
   (__copy_move<_IsMove, _IsSimple, random_access_iterator_tag>
   ::__copy_impl): New.
   (__copy_move<_IsMove, _IsSimple, random_access_iterator_tag>
   ::__copy_m): Use latter.
   (__copy_move<_IsMove, true, random_access_iterator_tag>::__copy_m):
   Add __base_res parameter.
   (__copy_move<_IsMove, true, random_access_iterator_tag>::__copy_m): Add
   __res_base parameter and use it to call __builtin_memmove.
   (__copy_move_a): Adapt.
   (__copy_move_a2): Adapt.
   (__copy_move_backward<_IsMove, _IsSimple, random_access_iterator_tag>
   ::__copy_b_impl): New.
   (__copy_move_backward<_IsMove, _IsSimple, random_access_iterator_tag>
   ::__copy_move_b): Use latter.
   (__copy_move_backward<_IsMove, true, random_access_iterator_tag>
   ::__copy_move_b): Add __res_base parameter and use it to call
   __builtin_memmove.
   (__copy_move_backward_a): Adapt.
   (__copy_move_backward_a2): Adapt.
   (__fill_n_a): Add _OI template parameter.
   (std::equal<>(_II1, _II1, _II2)): Remove usage of __niter_base on
   __first2 in _GLIBCXX_DEBUG mode.
   * include/debug/stl_iterator.h
   (std::__niter_base(const __gnu_cxx::_Safe_iterator<
   __gnu_cxx::__normal_iterator<>, _Sequence>&)): New declaration.
   * include/debug/vector (__niter_base(const __gnu_cxx::_Safe_iterator<
   __gnu_cxx::__normal_iterator<>, _Sequence>&)): New.
Tested under x86_64 linux.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: niter_debug.patch
Type: text/x-patch
Size: 14303 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20180618/72fd4c3f/attachment.bin>
More information about the Libstdc++
mailing list