From 479544ce80aad4c3405057d4e5146e1859a3b66b Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Thu, 21 Apr 2022 21:04:32 +0300 Subject: [PATCH 1/4] Untag dispatch Towards #189 --- stl/inc/execution | 56 ++++++++++------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/stl/inc/execution b/stl/inc/execution index 450b4cb552..261db1a43d 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -4424,33 +4424,17 @@ _FwdIt2 exclusive_scan(_ExPo&&, const _FwdIt1 _First, const _FwdIt1 _Last, _FwdI return _Dest; } -template -_FwdIt2 _Inclusive_scan_per_chunk( - _FwdIt1 _First, const _FwdIt1 _Last, _FwdIt2 _Dest, _BinOp _Reduce_op, _Ty& _Val, _No_init_tag) { - // Local-sum for parallel inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall sum in - // _Val. - // pre: _Val is *uninitialized* && _First != _Last - _Construct_in_place(_Val, *_First); - for (;;) { - *_Dest = _Val; - ++_Dest; - ++_First; - if (_First == _Last) { - return _Dest; - } - - _Val = _Reduce_op(_STD move(_Val), *_First); - } -} - -template >>, int> = 0> +template _FwdIt2 _Inclusive_scan_per_chunk( _FwdIt1 _First, const _FwdIt1 _Last, _FwdIt2 _Dest, _BinOp _Reduce_op, _Ty& _Val, _Ty_fwd&& _Predecessor) { // local-sum for parallel inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall sum in // _Val. // pre: _Val is *uninitialized* && _First != _Last - _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), *_First)); + if (!is_same_v<_No_init_tag, remove_const_t>>) { + _Construct_in_place(_Val, *_First); + } else { + _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), *_First)); + } for (;;) { *_Dest = _Val; ++_Dest; @@ -4756,33 +4740,17 @@ _FwdIt2 transform_exclusive_scan(_ExPo&&, const _FwdIt1 _First, const _FwdIt1 _L return _Dest; } -template -_FwdIt2 _Transform_inclusive_scan_per_chunk(_FwdIt1 _First, const _FwdIt1 _Last, _FwdIt2 _Dest, _BinOp _Reduce_op, - _UnaryOp _Transform_op, _Ty& _Val, _No_init_tag) { - // Local-sum for parallel transform_inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall - // sum in _Val. - // pre: _Val is *uninitialized* && _First != _Last - _Construct_in_place(_Val, _Transform_op(*_First)); - for (;;) { - *_Dest = _Val; - ++_Dest; - ++_First; - if (_First == _Last) { - return _Dest; - } - - _Val = _Reduce_op(_STD move(_Val), _Transform_op(*_First)); - } -} - -template >>, int> = 0> +template _FwdIt2 _Transform_inclusive_scan_per_chunk(_FwdIt1 _First, const _FwdIt1 _Last, _FwdIt2 _Dest, _BinOp _Reduce_op, _UnaryOp _Transform_op, _Ty& _Val, _Ty_fwd&& _Predecessor) { // local-sum for parallel transform_inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall // sum in _Val // pre: _Val is *uninitialized* && _First != _Last - _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), _Transform_op(*_First))); + if (is_same_v<_No_init_tag, remove_const_t>>) { + _Construct_in_place(_Val, _Transform_op(*_First)); + } else { + _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), _Transform_op(*_First))); + } for (;;) { *_Dest = _Val; ++_Dest; From 3a7f796b385f94fb14e8b979546dc696c007bc5a Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Thu, 21 Apr 2022 21:15:24 +0300 Subject: [PATCH 2/4] not not --- stl/inc/execution | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/execution b/stl/inc/execution index 261db1a43d..d148c9c35a 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -4430,7 +4430,7 @@ _FwdIt2 _Inclusive_scan_per_chunk( // local-sum for parallel inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall sum in // _Val. // pre: _Val is *uninitialized* && _First != _Last - if (!is_same_v<_No_init_tag, remove_const_t>>) { + if (is_same_v<_No_init_tag, remove_const_t>>) { _Construct_in_place(_Val, *_First); } else { _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), *_First)); From fb7c30cc3192fd52457de4b3a4caa25b4d1c56a8 Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Thu, 21 Apr 2022 21:24:02 +0300 Subject: [PATCH 3/4] control flow newlines --- stl/inc/execution | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/inc/execution b/stl/inc/execution index d148c9c35a..49092ecd3a 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -4435,6 +4435,7 @@ _FwdIt2 _Inclusive_scan_per_chunk( } else { _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), *_First)); } + for (;;) { *_Dest = _Val; ++_Dest; @@ -4751,6 +4752,7 @@ _FwdIt2 _Transform_inclusive_scan_per_chunk(_FwdIt1 _First, const _FwdIt1 _Last, } else { _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), _Transform_op(*_First))); } + for (;;) { *_Dest = _Val; ++_Dest; From a00c9bd801eb5c3749361cf53e1d920854dc769d Mon Sep 17 00:00:00 2001 From: Alex Guteniev Date: Thu, 21 Apr 2022 21:28:05 +0300 Subject: [PATCH 4/4] constexpr --- stl/inc/execution | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/execution b/stl/inc/execution index 49092ecd3a..97c1682530 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -4430,7 +4430,7 @@ _FwdIt2 _Inclusive_scan_per_chunk( // local-sum for parallel inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall sum in // _Val. // pre: _Val is *uninitialized* && _First != _Last - if (is_same_v<_No_init_tag, remove_const_t>>) { + if constexpr (is_same_v<_No_init_tag, remove_const_t>>) { _Construct_in_place(_Val, *_First); } else { _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), *_First)); @@ -4747,7 +4747,7 @@ _FwdIt2 _Transform_inclusive_scan_per_chunk(_FwdIt1 _First, const _FwdIt1 _Last, // local-sum for parallel transform_inclusive_scan; writes local inclusive prefix sums into _Dest and stores overall // sum in _Val // pre: _Val is *uninitialized* && _First != _Last - if (is_same_v<_No_init_tag, remove_const_t>>) { + if constexpr (is_same_v<_No_init_tag, remove_const_t>>) { _Construct_in_place(_Val, _Transform_op(*_First)); } else { _Construct_in_place(_Val, _Reduce_op(_STD forward<_Ty_fwd>(_Predecessor), _Transform_op(*_First)));