Skip to content

Commit 85cfb2f

Browse files
committed
Review comments
1 parent 787b48b commit 85cfb2f

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

libcudacxx/include/cuda/__random/pcg_engine.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,34 @@ class __pcg_uint128_fallback
5757
, __lo_{__lo}
5858
{}
5959

60-
_CCCL_API constexpr explicit operator ::cuda::std::uint64_t() const noexcept
60+
[[nodiscard]] _CCCL_API constexpr explicit operator ::cuda::std::uint64_t() const noexcept
6161
{
6262
return __lo_;
6363
}
6464

65-
_CCCL_API constexpr explicit operator ::cuda::std::uint8_t() const noexcept
65+
[[nodiscard]] _CCCL_API constexpr explicit operator ::cuda::std::uint8_t() const noexcept
6666
{
6767
return static_cast<::cuda::std::uint8_t>(__lo_);
6868
}
6969

70-
_CCCL_API constexpr __pcg_uint128_fallback operator|(::cuda::std::uint64_t __rhs) const noexcept
70+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator|(::cuda::std::uint64_t __rhs) const noexcept
7171
{
7272
return __pcg_uint128_fallback(__hi_, __lo_ | __rhs);
7373
}
7474

75-
_CCCL_API constexpr __pcg_uint128_fallback operator^(__pcg_uint128_fallback __rhs) const noexcept
75+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator^(__pcg_uint128_fallback __rhs) const noexcept
7676
{
7777
return __pcg_uint128_fallback(__hi_ ^ __rhs.__hi_, __lo_ ^ __rhs.__lo_);
7878
}
7979

80-
_CCCL_API constexpr int operator&(int __rhs) const noexcept
80+
[[nodiscard]] _CCCL_API constexpr int operator&(int __rhs) const noexcept
8181
{
8282
return __lo_ & static_cast<::cuda::std::uint64_t>(__rhs);
8383
}
8484

85-
_CCCL_API constexpr __pcg_uint128_fallback operator<<(int __shift) const noexcept
85+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator<<(int __shift) const noexcept
8686
{
87+
_CCCL_ASSERT(__shift >= 0 && __shift < 128, "shift value out of range");
8788
if (__shift == 0)
8889
{
8990
return *this;
@@ -99,7 +100,7 @@ class __pcg_uint128_fallback
99100
return __pcg_uint128_fallback((__hi_ << __shift) | (__lo_ >> (64 - __shift)), __lo_ << __shift);
100101
}
101102

102-
_CCCL_API constexpr __pcg_uint128_fallback operator>>(int __shift) const noexcept
103+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator>>(int __shift) const noexcept
103104
{
104105
if (__shift == 0)
105106
{
@@ -116,14 +117,15 @@ class __pcg_uint128_fallback
116117
return __pcg_uint128_fallback(__hi_ >> __shift, (__lo_ >> __shift) | (__hi_ << (64 - __shift)));
117118
}
118119

119-
_CCCL_API constexpr __pcg_uint128_fallback operator+(__pcg_uint128_fallback __rhs) const noexcept
120+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator+(__pcg_uint128_fallback __rhs) const noexcept
120121
{
122+
// TODO: optimize with PTX add.cc
121123
::cuda::std::uint64_t __new_lo = __lo_ + __rhs.__lo_;
122124
::cuda::std::uint64_t __carry = (__new_lo < __lo_) ? 1 : 0;
123125
return __pcg_uint128_fallback(__hi_ + __rhs.__hi_ + __carry, __new_lo);
124126
}
125127

126-
_CCCL_API constexpr __pcg_uint128_fallback operator*(__pcg_uint128_fallback __rhs) const noexcept
128+
[[nodiscard]] _CCCL_API constexpr __pcg_uint128_fallback operator*(__pcg_uint128_fallback __rhs) const noexcept
127129
{
128130
__pcg_uint128_fallback __c(::cuda::mul_hi(__lo_, __rhs.__lo_), __lo_ * __rhs.__lo_);
129131
__c.__hi_ += __hi_ * __rhs.__lo_ + __lo_ * __rhs.__hi_;
@@ -132,24 +134,27 @@ class __pcg_uint128_fallback
132134

133135
_CCCL_API constexpr __pcg_uint128_fallback& operator*=(__pcg_uint128_fallback __rhs) noexcept
134136
{
135-
*this = *this * __rhs;
136-
return *this;
137+
return *this = *this * __rhs;
137138
}
138139

139-
_CCCL_API constexpr bool operator>(int __x) const noexcept
140+
[[nodiscard]] _CCCL_API constexpr bool operator>(int __x) const noexcept
140141
{
141142
return __hi_ != 0 || __lo_ > static_cast<::cuda::std::uint64_t>(__x);
142143
}
143144

144-
_CCCL_API constexpr friend bool operator==(__pcg_uint128_fallback __lhs, __pcg_uint128_fallback __rhs) noexcept
145+
[[nodiscard]] _CCCL_API constexpr friend bool
146+
operator==(__pcg_uint128_fallback __lhs, __pcg_uint128_fallback __rhs) noexcept
145147
{
146148
return __lhs.__hi_ == __rhs.__hi_ && __lhs.__lo_ == __rhs.__lo_;
147149
}
148150

149-
_CCCL_API constexpr friend bool operator!=(__pcg_uint128_fallback __lhs, __pcg_uint128_fallback __rhs) noexcept
151+
#if _CCCL_STD_VER <= 2017
152+
[[nodiscard]] _CCCL_API constexpr friend bool
153+
operator!=(__pcg_uint128_fallback __lhs, __pcg_uint128_fallback __rhs) noexcept
150154
{
151155
return !(__lhs == __rhs);
152156
}
157+
#endif // _CCCL_STD_VER <= 2017
153158
};
154159

155160
//! @brief A 64-bit permuted congruential generator (PCG) random number engine.

0 commit comments

Comments
 (0)