Skip to content

Commit 9c4717a

Browse files
committedMay 4, 2023
[libc++][PSTL][NFC] Fix the naming in the SIMD backend
Reviewed By: ldionne, #libc Spies: sstefan1, jplehr, libcxx-commits, miyuki Differential Revision: https://reviews.llvm.org/D149787
1 parent 35309db commit 9c4717a

File tree

4 files changed

+92
-89
lines changed

4 files changed

+92
-89
lines changed
 

‎libcxx/include/__pstl/internal/parallel_backend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
namespace __pstl
1818
{
1919
namespace __par_backend = __serial_backend;
20-
}
20+
} // namespace __pstl
2121
#elif defined(_PSTL_PAR_BACKEND_TBB)
2222
# include "parallel_backend_tbb.h"
2323
namespace __pstl

‎libcxx/include/__pstl/internal/unseq_backend_simd.h

+67-64
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _Un
410410
const _Size __block_size = __lane_size / sizeof(_Tp);
411411
if (__n > 2 * __block_size && __block_size > 1)
412412
{
413-
alignas(__lane_size) char __lane_[__lane_size];
414-
_Tp* __lane = reinterpret_cast<_Tp*>(__lane_);
413+
alignas(__lane_size) char __lane_buffer[__lane_size];
414+
_Tp* __lane = reinterpret_cast<_Tp*>(__lane_buffer);
415415

416416
// initializer
417417
_PSTL_PRAGMA_SIMD
@@ -421,8 +421,8 @@ __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _Un
421421
}
422422
// main loop
423423
_Size __i = 2 * __block_size;
424-
const _Size last_iteration = __block_size * (__n / __block_size);
425-
for (; __i < last_iteration; __i += __block_size)
424+
const _Size __last_iteration = __block_size * (__n / __block_size);
425+
for (; __i < __last_iteration; __i += __block_size)
426426
{
427427
_PSTL_PRAGMA_SIMD
428428
for (_Size __j = 0; __j < __block_size; ++__j)
@@ -432,9 +432,9 @@ __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _Un
432432
}
433433
// remainder
434434
_PSTL_PRAGMA_SIMD
435-
for (_Size __j = 0; __j < __n - last_iteration; ++__j)
435+
for (_Size __j = 0; __j < __n - __last_iteration; ++__j)
436436
{
437-
__lane[__j] = __binary_op(__lane[__j], __f(last_iteration + __j));
437+
__lane[__j] = __binary_op(__lane[__j], __f(__last_iteration + __j));
438438
}
439439
// combiner
440440
for (_Size __j = 0; __j < __block_size; ++__j)
@@ -480,18 +480,19 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
480480
template <typename _Tp, typename _BinaryOp>
481481
struct _Combiner
482482
{
483-
_Tp __value;
484-
_BinaryOp* __bin_op; // Here is a pointer to function because of default ctor
483+
_Tp __value_;
484+
_BinaryOp* __bin_op_; // Here is a pointer to function because of default ctor
485485

486-
_LIBCPP_HIDE_FROM_ABI _Combiner() : __value{}, __bin_op(nullptr) {}
486+
_LIBCPP_HIDE_FROM_ABI _Combiner() : __value_{}, __bin_op_(nullptr) {}
487487
_LIBCPP_HIDE_FROM_ABI
488-
_Combiner(const _Tp& value, const _BinaryOp* bin_op) : __value(value), __bin_op(const_cast<_BinaryOp*>(bin_op)) {}
489-
_LIBCPP_HIDE_FROM_ABI _Combiner(const _Combiner& __obj) : __value{}, __bin_op(__obj.__bin_op) {}
488+
_Combiner(const _Tp& __value, const _BinaryOp* __bin_op)
489+
: __value_(__value), __bin_op_(const_cast<_BinaryOp*>(__bin_op)) {}
490+
_LIBCPP_HIDE_FROM_ABI _Combiner(const _Combiner& __obj) : __value_{}, __bin_op_(__obj.__bin_op) {}
490491

491492
_LIBCPP_HIDE_FROM_ABI void
492493
operator()(const _Combiner& __obj)
493494
{
494-
__value = (*__bin_op)(__value, __obj.__value);
495+
__value_ = (*__bin_op_)(__value_, __obj.__value_);
495496
}
496497
};
497498

@@ -504,17 +505,17 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
504505
_BinaryOperation __binary_op, /*Inclusive*/ std::false_type)
505506
{
506507
typedef _Combiner<_Tp, _BinaryOperation> _CombinerType;
507-
_CombinerType __init_{__init, &__binary_op};
508+
_CombinerType __combined_init{__init, &__binary_op};
508509

509510
_PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
510511
_PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
511512
for (_Size __i = 0; __i < __n; ++__i)
512513
{
513-
__result[__i] = __init_.__value;
514+
__result[__i] = __combined_init.__value_;
514515
_PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_)
515-
__init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
516+
__combined_init.__value_ = __binary_op(__combined_init.__value_, __unary_op(__first[__i]));
516517
}
517-
return std::make_pair(__result + __n, __init_.__value);
518+
return std::make_pair(__result + __n, __combined_init.__value_);
518519
}
519520

520521
// Inclusive scan for "+" and arithmetic types
@@ -544,17 +545,17 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
544545
_BinaryOperation __binary_op, std::true_type)
545546
{
546547
typedef _Combiner<_Tp, _BinaryOperation> _CombinerType;
547-
_CombinerType __init_{__init, &__binary_op};
548+
_CombinerType __combined_init{__init, &__binary_op};
548549

549550
_PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
550551
_PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
551552
for (_Size __i = 0; __i < __n; ++__i)
552553
{
553-
__init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
554+
__combined_init.__value_ = __binary_op(__combined_init.__value_, __unary_op(__first[__i]));
554555
_PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_)
555-
__result[__i] = __init_.__value;
556+
__result[__i] = __combined_init.__value_;
556557
}
557-
return std::make_pair(__result + __n, __init_.__value);
558+
return std::make_pair(__result + __n, __combined_init.__value_);
558559
}
559560

560561
// [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
@@ -571,29 +572,29 @@ __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcep
571572
typedef typename std::iterator_traits<_ForwardIterator>::value_type _ValueType;
572573
struct _ComplexType
573574
{
574-
_ValueType __min_val;
575-
_Size __min_ind;
576-
_Compare* __min_comp;
575+
_ValueType __min_val_;
576+
_Size __min_ind_;
577+
_Compare* __min_comp_;
577578

578-
_LIBCPP_HIDE_FROM_ABI _ComplexType() : __min_val{}, __min_ind{}, __min_comp(nullptr) {}
579-
_LIBCPP_HIDE_FROM_ABI _ComplexType(const _ValueType& val, const _Compare* comp)
580-
: __min_val(val), __min_ind(0), __min_comp(const_cast<_Compare*>(comp))
579+
_LIBCPP_HIDE_FROM_ABI _ComplexType() : __min_val_{}, __min_ind_{}, __min_comp_(nullptr) {}
580+
_LIBCPP_HIDE_FROM_ABI _ComplexType(const _ValueType& __val, const _Compare* __comp)
581+
: __min_val_(__val), __min_ind_(0), __min_comp_(const_cast<_Compare*>(__comp))
581582
{
582583
}
583584
_LIBCPP_HIDE_FROM_ABI _ComplexType(const _ComplexType& __obj)
584-
: __min_val(__obj.__min_val), __min_ind(__obj.__min_ind), __min_comp(__obj.__min_comp)
585+
: __min_val_(__obj.__min_val_), __min_ind_(__obj.__min_ind_), __min_comp_(__obj.__min_comp_)
585586
{
586587
}
587588

588589
_PSTL_PRAGMA_DECLARE_SIMD
589590
_LIBCPP_HIDE_FROM_ABI void
590591
operator()(const _ComplexType& __obj)
591592
{
592-
if (!(*__min_comp)(__min_val, __obj.__min_val) &&
593-
((*__min_comp)(__obj.__min_val, __min_val) || __obj.__min_ind - __min_ind < 0))
593+
if (!(*__min_comp_)(__min_val_, __obj.__min_val_) &&
594+
((*__min_comp_)(__obj.__min_val_, __min_val_) || __obj.__min_ind_ - __min_ind_ < 0))
594595
{
595-
__min_val = __obj.__min_val;
596-
__min_ind = __obj.__min_ind;
596+
__min_val_ = __obj.__min_val_;
597+
__min_ind_ = __obj.__min_ind_;
597598
}
598599
}
599600
};
@@ -605,15 +606,15 @@ __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcep
605606
_PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
606607
for (_Size __i = 1; __i < __n; ++__i)
607608
{
608-
const _ValueType __min_val = __init.__min_val;
609+
const _ValueType __min_val = __init.__min_val_;
609610
const _ValueType __current = __first[__i];
610611
if (__comp(__current, __min_val))
611612
{
612-
__init.__min_val = __current;
613-
__init.__min_ind = __i;
613+
__init.__min_val_ = __current;
614+
__init.__min_ind_ = __i;
614615
}
615616
}
616-
return __first + __init.__min_ind;
617+
return __first + __init.__min_ind_;
617618
}
618619

619620
// [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
@@ -630,49 +631,51 @@ __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noex
630631

631632
struct _ComplexType
632633
{
633-
_ValueType __min_val;
634-
_ValueType __max_val;
635-
_Size __min_ind;
636-
_Size __max_ind;
634+
_ValueType __min_val_;
635+
_ValueType __max_val_;
636+
_Size __min_ind_;
637+
_Size __max_ind_;
637638
_Compare* __minmax_comp;
638639

639-
_LIBCPP_HIDE_FROM_ABI _ComplexType() : __min_val{}, __max_val{}, __min_ind{}, __max_ind{}, __minmax_comp(nullptr) {}
640-
_LIBCPP_HIDE_FROM_ABI _ComplexType(const _ValueType& min_val, const _ValueType& max_val, const _Compare* comp)
641-
: __min_val(min_val), __max_val(max_val), __min_ind(0), __max_ind(0),
642-
__minmax_comp(const_cast<_Compare*>(comp))
640+
_LIBCPP_HIDE_FROM_ABI _ComplexType()
641+
: __min_val_{}, __max_val_{}, __min_ind_{}, __max_ind_{}, __minmax_comp(nullptr) {}
642+
_LIBCPP_HIDE_FROM_ABI _ComplexType(
643+
const _ValueType& __min_val, const _ValueType& __max_val, const _Compare* __comp)
644+
: __min_val_(__min_val), __max_val_(__max_val), __min_ind_(0), __max_ind_(0),
645+
__minmax_comp(const_cast<_Compare*>(__comp))
643646
{
644647
}
645648
_LIBCPP_HIDE_FROM_ABI _ComplexType(const _ComplexType& __obj)
646-
: __min_val(__obj.__min_val), __max_val(__obj.__max_val), __min_ind(__obj.__min_ind),
647-
__max_ind(__obj.__max_ind), __minmax_comp(__obj.__minmax_comp)
649+
: __min_val_(__obj.__min_val_), __max_val_(__obj.__max_val_), __min_ind_(__obj.__min_ind_),
650+
__max_ind_(__obj.__max_ind_), __minmax_comp(__obj.__minmax_comp)
648651
{
649652
}
650653

651654
_LIBCPP_HIDE_FROM_ABI void
652655
operator()(const _ComplexType& __obj)
653656
{
654657
// min
655-
if ((*__minmax_comp)(__obj.__min_val, __min_val))
658+
if ((*__minmax_comp)(__obj.__min_val_, __min_val_))
656659
{
657-
__min_val = __obj.__min_val;
658-
__min_ind = __obj.__min_ind;
660+
__min_val_ = __obj.__min_val_;
661+
__min_ind_ = __obj.__min_ind_;
659662
}
660-
else if (!(*__minmax_comp)(__min_val, __obj.__min_val))
663+
else if (!(*__minmax_comp)(__min_val_, __obj.__min_val_))
661664
{
662-
__min_val = __obj.__min_val;
663-
__min_ind = (__min_ind - __obj.__min_ind < 0) ? __min_ind : __obj.__min_ind;
665+
__min_val_ = __obj.__min_val_;
666+
__min_ind_ = (__min_ind_ - __obj.__min_ind_ < 0) ? __min_ind_ : __obj.__min_ind_;
664667
}
665668

666669
// max
667-
if ((*__minmax_comp)(__max_val, __obj.__max_val))
670+
if ((*__minmax_comp)(__max_val_, __obj.__max_val_))
668671
{
669-
__max_val = __obj.__max_val;
670-
__max_ind = __obj.__max_ind;
672+
__max_val_ = __obj.__max_val_;
673+
__max_ind_ = __obj.__max_ind_;
671674
}
672-
else if (!(*__minmax_comp)(__obj.__max_val, __max_val))
675+
else if (!(*__minmax_comp)(__obj.__max_val_, __max_val_))
673676
{
674-
__max_val = __obj.__max_val;
675-
__max_ind = (__max_ind - __obj.__max_ind < 0) ? __obj.__max_ind : __max_ind;
677+
__max_val_ = __obj.__max_val_;
678+
__max_ind_ = (__max_ind_ - __obj.__max_ind_ < 0) ? __obj.__max_ind_ : __max_ind_;
676679
}
677680
}
678681
};
@@ -684,21 +687,21 @@ __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noex
684687
_PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
685688
for (_Size __i = 1; __i < __n; ++__i)
686689
{
687-
auto __min_val = __init.__min_val;
688-
auto __max_val = __init.__max_val;
690+
auto __min_val = __init.__min_val_;
691+
auto __max_val = __init.__max_val_;
689692
auto __current = __first + __i;
690693
if (__comp(*__current, __min_val))
691694
{
692-
__init.__min_val = *__current;
693-
__init.__min_ind = __i;
695+
__init.__min_val_ = *__current;
696+
__init.__min_ind_ = __i;
694697
}
695698
else if (!__comp(*__current, __max_val))
696699
{
697-
__init.__max_val = *__current;
698-
__init.__max_ind = __i;
700+
__init.__max_val_ = *__current;
701+
__init.__max_ind_ = __i;
699702
}
700703
}
701-
return std::make_pair(__first + __init.__min_ind, __first + __init.__max_ind);
704+
return std::make_pair(__first + __init.__min_ind_, __first + __init.__max_ind_);
702705
}
703706

704707
template <class _InputIterator, class _DifferenceType, class _OutputIterator1, class _OutputIterator2,

‎libcxx/include/__pstl/internal/utils.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -69,58 +69,58 @@ struct __no_op {
6969

7070
template <typename _Pred>
7171
class __reorder_pred {
72-
_Pred _M_pred;
72+
_Pred __pred_;
7373

7474
public:
75-
_LIBCPP_HIDE_FROM_ABI explicit __reorder_pred(_Pred __pred) : _M_pred(__pred) {}
75+
_LIBCPP_HIDE_FROM_ABI explicit __reorder_pred(_Pred __pred) : __pred_(__pred) {}
7676

7777
template <typename _FTp, typename _STp>
7878
_LIBCPP_HIDE_FROM_ABI bool operator()(_FTp&& __a, _STp&& __b) {
79-
return _M_pred(std::forward<_STp>(__b), std::forward<_FTp>(__a));
79+
return __pred_(std::forward<_STp>(__b), std::forward<_FTp>(__a));
8080
}
8181
};
8282

8383
//! Like a polymorphic lambda for pred(...,value)
8484
template <typename _Tp, typename _Predicate>
8585
class __equal_value_by_pred {
86-
const _Tp& _M_value;
87-
_Predicate _M_pred;
86+
const _Tp& __value_;
87+
_Predicate __pred_;
8888

8989
public:
9090
_LIBCPP_HIDE_FROM_ABI __equal_value_by_pred(const _Tp& __value, _Predicate __pred)
91-
: _M_value(__value), _M_pred(__pred) {}
91+
: __value_(__value), __pred_(__pred) {}
9292

9393
template <typename _Arg>
9494
_LIBCPP_HIDE_FROM_ABI bool operator()(_Arg&& __arg) {
95-
return _M_pred(std::forward<_Arg>(__arg), _M_value);
95+
return __pred_(std::forward<_Arg>(__arg), __value_);
9696
}
9797
};
9898

9999
//! Like a polymorphic lambda for ==value
100100
template <typename _Tp>
101101
class __equal_value {
102-
const _Tp& _M_value;
102+
const _Tp& __value_;
103103

104104
public:
105-
_LIBCPP_HIDE_FROM_ABI explicit __equal_value(const _Tp& __value) : _M_value(__value) {}
105+
_LIBCPP_HIDE_FROM_ABI explicit __equal_value(const _Tp& __value) : __value_(__value) {}
106106

107107
template <typename _Arg>
108108
_LIBCPP_HIDE_FROM_ABI bool operator()(_Arg&& __arg) const {
109-
return std::forward<_Arg>(__arg) == _M_value;
109+
return std::forward<_Arg>(__arg) == __value_;
110110
}
111111
};
112112

113113
//! Logical negation of ==value
114114
template <typename _Tp>
115115
class __not_equal_value {
116-
const _Tp& _M_value;
116+
const _Tp& __value_;
117117

118118
public:
119-
_LIBCPP_HIDE_FROM_ABI explicit __not_equal_value(const _Tp& __value) : _M_value(__value) {}
119+
_LIBCPP_HIDE_FROM_ABI explicit __not_equal_value(const _Tp& __value) : __value_(__value) {}
120120

121121
template <typename _Arg>
122122
_LIBCPP_HIDE_FROM_ABI bool operator()(_Arg&& __arg) const {
123-
return !(std::forward<_Arg>(__arg) == _M_value);
123+
return !(std::forward<_Arg>(__arg) == __value_);
124124
}
125125
};
126126

‎pstl/include/pstl/internal/unseq_backend_simd.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -532,17 +532,17 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
532532
template <typename _Tp, typename _BinaryOp>
533533
struct _Combiner
534534
{
535-
_Tp __value;
535+
_Tp __value_;
536536
_BinaryOp* __bin_op; // Here is a pointer to function because of default ctor
537537

538-
_Combiner() : __value{}, __bin_op(nullptr) {}
539-
_Combiner(const _Tp& value, const _BinaryOp* bin_op) : __value(value), __bin_op(const_cast<_BinaryOp*>(bin_op)) {}
540-
_Combiner(const _Combiner& __obj) : __value{}, __bin_op(__obj.__bin_op) {}
538+
_Combiner() : __value_{}, __bin_op(nullptr) {}
539+
_Combiner(const _Tp& value, const _BinaryOp* bin_op) : __value_(value), __bin_op(const_cast<_BinaryOp*>(bin_op)) {}
540+
_Combiner(const _Combiner& __obj) : __value_{}, __bin_op(__obj.__bin_op) {}
541541

542542
void
543543
operator()(const _Combiner& __obj)
544544
{
545-
__value = (*__bin_op)(__value, __obj.__value);
545+
__value_ = (*__bin_op)(__value_, __obj.__value);
546546
}
547547
};
548548

@@ -561,12 +561,12 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
561561
_PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
562562
for (_Size __i = 0; __i < __n; ++__i)
563563
{
564-
__result[__i] = __init_.__value;
564+
__result[__i] = __init_.__value_;
565565
_PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_)
566566
_PSTL_PRAGMA_FORCEINLINE
567-
__init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
567+
__init_.__value_ = __binary_op(__init_.__value_, __unary_op(__first[__i]));
568568
}
569-
return std::make_pair(__result + __n, __init_.__value);
569+
return std::make_pair(__result + __n, __init_.__value_);
570570
}
571571

572572
// Inclusive scan for "+" and arithmetic types
@@ -602,11 +602,11 @@ __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryO
602602
for (_Size __i = 0; __i < __n; ++__i)
603603
{
604604
_PSTL_PRAGMA_FORCEINLINE
605-
__init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
605+
__init_.__value_ = __binary_op(__init_.__value_, __unary_op(__first[__i]));
606606
_PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_)
607-
__result[__i] = __init_.__value;
607+
__result[__i] = __init_.__value_;
608608
}
609-
return std::make_pair(__result + __n, __init_.__value);
609+
return std::make_pair(__result + __n, __init_.__value_);
610610
}
611611

612612
// [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.

0 commit comments

Comments
 (0)
Please sign in to comment.