Skip to content

Commit 8ffeb0c

Browse files
authored
Enable __int128_t as difference type in counting_iterator (#6487)
Fixes #6485
1 parent 0e48db8 commit 8ffeb0c

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

libcudacxx/include/cuda/__iterator/counting_iterator.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <cuda/std/__ranges/enable_borrowed_range.h>
4242
#include <cuda/std/__ranges/movable_box.h>
4343
#include <cuda/std/__ranges/view_interface.h>
44+
#include <cuda/std/__type_traits/always_false.h>
4445
#include <cuda/std/__type_traits/conditional.h>
4546
#include <cuda/std/__type_traits/enable_if.h>
4647
#include <cuda/std/__type_traits/is_constructible.h>
@@ -79,13 +80,21 @@ struct __get_wider_signed
7980
{
8081
return ::cuda::std::type_identity<long>{};
8182
}
82-
else
83+
#if _CCCL_HAS_INT128()
84+
else if constexpr (sizeof(_Int) < sizeof(long long))
8385
{
8486
return ::cuda::std::type_identity<long long>{};
8587
}
86-
87-
static_assert(sizeof(_Int) <= sizeof(long long),
88-
"Found integer-like type that is bigger than largest integer like type.");
88+
else // if constexpr (sizeof(_Int) < sizeof(__int128_t))
89+
{
90+
return ::cuda::std::type_identity<__int128_t>{};
91+
}
92+
#else // ^^^ _CCCL_HAS_INT128() ^^^ / vvv !_CCCL_HAS_INT128() vvv
93+
else // if constexpr (sizeof(_Int) < sizeof(long long))
94+
{
95+
return ::cuda::std::type_identity<long long>{};
96+
}
97+
#endif // _CCCL_HAS_INT128()
8998
_CCCL_UNREACHABLE();
9099
}
91100

libcudacxx/test/libcudacxx/cuda/iterators/counting_iterator/iterator_traits.compile.pass.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ _CCCL_CONCEPT HasIteratorCategory =
142142
template <template <class...> class Traits>
143143
__host__ __device__ void test()
144144
{
145+
#if _CCCL_HAS_INT128()
146+
using widest_integer = __int128_t;
147+
#else // ^^^ _CCCL_HAS_INT128() ^^^ / vvv !_CCCL_HAS_INT128() vvv
148+
using widest_integer = long long;
149+
#endif // !_CCCL_HAS_INT128()
150+
145151
{
146152
using Iter = cuda::counting_iterator<char>;
147153
using IterTraits = Traits<Iter>;
@@ -189,7 +195,7 @@ __host__ __device__ void test()
189195
// Same as below, if there is no type larger than long, we can just use that.
190196
static_assert(sizeof(typename IterTraits::difference_type) >= sizeof(long));
191197
static_assert(cuda::std::is_signed_v<typename IterTraits::difference_type>);
192-
static_assert(cuda::std::same_as<typename IterTraits::difference_type, long long>);
198+
static_assert(cuda::std::same_as<typename IterTraits::difference_type, widest_integer>);
193199
static_assert(cuda::std::random_access_iterator<Iter>);
194200
static_assert(cuda::std::__has_random_access_traversal<Iter>);
195201
}
@@ -202,7 +208,7 @@ __host__ __device__ void test()
202208
// https://eel.is/c++draft/range.iota.view#1.3
203209
static_assert(sizeof(typename IterTraits::difference_type) >= sizeof(long long));
204210
static_assert(cuda::std::is_signed_v<typename IterTraits::difference_type>);
205-
static_assert(cuda::std::same_as<typename IterTraits::difference_type, long long>);
211+
static_assert(cuda::std::same_as<typename IterTraits::difference_type, widest_integer>);
206212
static_assert(cuda::std::random_access_iterator<Iter>);
207213
static_assert(cuda::std::__has_random_access_traversal<Iter>);
208214
}

libcudacxx/test/libcudacxx/cuda/iterators/counting_iterator/member_typedefs.compile.pass.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ _CCCL_CONCEPT HasIteratorCategory =
108108

109109
__host__ __device__ void test()
110110
{
111+
#if _CCCL_HAS_INT128()
112+
using widest_integer = __int128_t;
113+
#else // ^^^ _CCCL_HAS_INT128() ^^^ / vvv !_CCCL_HAS_INT128() vvv
114+
using widest_integer = long long;
115+
#endif // !_CCCL_HAS_INT128()
111116
{
112117
using Iter = cuda::counting_iterator<char>;
113118
static_assert(cuda::std::same_as<Iter::iterator_concept, cuda::std::random_access_iterator_tag>);
@@ -155,7 +160,7 @@ __host__ __device__ void test()
155160
// Same as below, if there is no type larger than long, we can just use that.
156161
static_assert(sizeof(Iter::difference_type) >= sizeof(long));
157162
static_assert(cuda::std::is_signed_v<Iter::difference_type>);
158-
static_assert(cuda::std::same_as<Iter::difference_type, long long>);
163+
static_assert(cuda::std::same_as<Iter::difference_type, widest_integer>);
159164
static_assert(cuda::std::random_access_iterator<Iter>);
160165
static_assert(cuda::std::is_trivially_copyable_v<Iter>);
161166
}
@@ -168,7 +173,7 @@ __host__ __device__ void test()
168173
// https://eel.is/c++draft/range.iota.view#1.3
169174
static_assert(sizeof(Iter::difference_type) >= sizeof(long long));
170175
static_assert(cuda::std::is_signed_v<Iter::difference_type>);
171-
static_assert(cuda::std::same_as<Iter::difference_type, long long>);
176+
static_assert(cuda::std::same_as<Iter::difference_type, widest_integer>);
172177
static_assert(cuda::std::random_access_iterator<Iter>);
173178
static_assert(cuda::std::is_trivially_copyable_v<Iter>);
174179
}

libcudacxx/test/libcudacxx/std/ranges/range.factories/range.iota.view/iterator/member_typedefs.compile.pass.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ _CCCL_CONCEPT HasIteratorCategory =
107107

108108
__host__ __device__ void test()
109109
{
110+
#if _CCCL_HAS_INT128()
111+
using widest_integer = __int128_t;
112+
#else // ^^^ _CCCL_HAS_INT128() ^^^ / vvv !_CCCL_HAS_INT128() vvv
113+
using widest_integer = long long;
114+
#endif // !_CCCL_HAS_INT128()
115+
110116
{
111117
const cuda::std::ranges::iota_view<char> io(0);
112118
using Iter = decltype(io.begin());
@@ -155,7 +161,7 @@ __host__ __device__ void test()
155161
// Same as below, if there is no type larger than long, we can just use that.
156162
static_assert(sizeof(Iter::difference_type) >= sizeof(long));
157163
static_assert(cuda::std::is_signed_v<Iter::difference_type>);
158-
static_assert(cuda::std::same_as<Iter::difference_type, long long>);
164+
static_assert(cuda::std::same_as<Iter::difference_type, widest_integer>);
159165
unused(io);
160166
}
161167
{
@@ -168,7 +174,7 @@ __host__ __device__ void test()
168174
// https://eel.is/c++draft/range.iota.view#1.3
169175
static_assert(sizeof(Iter::difference_type) >= sizeof(long long));
170176
static_assert(cuda::std::is_signed_v<Iter::difference_type>);
171-
static_assert(cuda::std::same_as<Iter::difference_type, long long>);
177+
static_assert(cuda::std::same_as<Iter::difference_type, widest_integer>);
172178
unused(io);
173179
}
174180
{

0 commit comments

Comments
 (0)