Skip to content

Commit 4641944

Browse files
authored
Merge pull request #197 from cppalliance/improve_macros
Improve macros
2 parents 47577f0 + 564aeb4 commit 4641944

19 files changed

+57
-66
lines changed

include/boost/crypt2/detail/assert.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#endif
3737

38-
#if !defined(NDEBUG) && !defined(BOOST_CRYPT_HAS_CUDA)
38+
#if !defined(NDEBUG) && !BOOST_CRYPT_HAS_CUDA
3939

4040
namespace boost::crypt::assert_detail {
4141

include/boost/crypt2/detail/clear_mem.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <boost/crypt2/detail/config.hpp>
99
#include <boost/crypt2/detail/compat.hpp>
1010

11-
#ifdef BOOST_CRYPT_HAS_CUDA
11+
#if BOOST_CRYPT_HAS_CUDA
1212

1313
#include <cuda/std/span>
1414
#include <cuda/std/array>

include/boost/crypt2/detail/compat.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
#include <boost/crypt2/detail/config.hpp>
1212

13-
#if !defined(BOOST_CRYPT_HAS_CUDA)
13+
#if !BOOST_CRYPT_HAS_CUDA
1414
#include <boost/crypt2/detail/expected.hpp>
1515
#endif
1616

17-
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
17+
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !BOOST_CRYPT_HAS_CUDA
1818

1919
#include <span>
2020
#include <array>
@@ -26,7 +26,7 @@
2626
#include <utility>
2727
#include <bit>
2828

29-
#elif defined(BOOST_CRYPT_HAS_CUDA)
29+
#elif BOOST_CRYPT_HAS_CUDA
3030

3131
#include <cuda/std/span>
3232
#include <cuda/std/array>
@@ -44,7 +44,7 @@
4444
namespace boost::crypt::compat {
4545

4646
// Fixed width types
47-
#ifdef BOOST_CRYPT_HAS_CUDA
47+
#if BOOST_CRYPT_HAS_CUDA
4848
using size_t = cuda::std::size_t;
4949
using uint32_t = cuda::std::uint32_t;
5050
using uint64_t = cuda::std::uint64_t;
@@ -56,13 +56,13 @@ using uint64_t = std::uint64_t;
5656

5757
// Arrays and spans
5858
template <typename T, compat::size_t N>
59-
#ifdef BOOST_CRYPT_HAS_CUDA
59+
#if BOOST_CRYPT_HAS_CUDA
6060
using array = cuda::std::array<T, N>;
6161
#else
6262
using array = std::array<T, N>;
6363
#endif
6464

65-
#ifdef BOOST_CRYPT_HAS_CUDA
65+
#if BOOST_CRYPT_HAS_CUDA
6666
template<typename T, cuda::std::size_t Extent = cuda::std::dynamic_extent>
6767
using span = cuda::std::span<T, Extent>;
6868
#else
@@ -71,7 +71,7 @@ using span = std::span<T, Extent>;
7171
#endif
7272

7373
// Byte and friends
74-
#ifdef BOOST_CRYPT_HAS_CUDA
74+
#if BOOST_CRYPT_HAS_CUDA
7575
using byte = cuda::std::byte;
7676
#else
7777
using byte = std::byte;
@@ -80,7 +80,7 @@ using byte = std::byte;
8080
template <typename T>
8181
BOOST_CRYPT_GPU_ENABLED constexpr auto as_bytes(span<T> s) noexcept
8282
{
83-
#ifdef BOOST_CRYPT_HAS_CUDA
83+
#if BOOST_CRYPT_HAS_CUDA
8484
return cuda::std::as_bytes(s);
8585
#else
8686
return std::as_bytes(s);
@@ -90,15 +90,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto as_bytes(span<T> s) noexcept
9090
template <typename T>
9191
BOOST_CRYPT_GPU_ENABLED constexpr auto as_writable_bytes(span<T> s) noexcept
9292
{
93-
#ifdef BOOST_CRYPT_HAS_CUDA
93+
#if BOOST_CRYPT_HAS_CUDA
9494
return cuda::std::as_writable_bytes(s);
9595
#else
9696
return std::as_writable_bytes(s);
9797
#endif
9898
}
9999

100100
// Type traits
101-
#ifdef BOOST_CRYPT_HAS_CUDA
101+
#if BOOST_CRYPT_HAS_CUDA
102102
template <typename T, T v>
103103
using integral_constant = cuda::std::integral_constant<T, v>;
104104
template <bool b>
@@ -116,23 +116,23 @@ using false_type = std::false_type;
116116

117117
template <typename T>
118118
inline constexpr bool is_trivially_copyable_v =
119-
#ifdef BOOST_CRYPT_HAS_CUDA
119+
#if BOOST_CRYPT_HAS_CUDA
120120
cuda::std::is_trivially_copyable_v<T>;
121121
#else
122122
std::is_trivially_copyable_v<T>;
123123
#endif
124124

125125
template <typename T>
126126
using remove_reference_t =
127-
#ifdef BOOST_CRYPT_HAS_CUDA
127+
#if BOOST_CRYPT_HAS_CUDA
128128
cuda::std::remove_reference_t<T>;
129129
#else
130130
std::remove_reference_t<T>;
131131
#endif
132132

133133
template <typename T>
134134
using remove_cvref_t =
135-
#ifdef BOOST_CRYPT_HAS_CUDA
135+
#if BOOST_CRYPT_HAS_CUDA
136136
cuda::std::remove_cv_t<cuda::std::remove_reference_t<T>>;
137137
#else
138138
std::remove_cv_t<std::remove_reference_t<T>>;
@@ -141,23 +141,23 @@ using remove_cvref_t =
141141
// Ranges concepts and utilities
142142
template <typename R>
143143
concept sized_range =
144-
#ifdef BOOST_CRYPT_HAS_CUDA
144+
#if BOOST_CRYPT_HAS_CUDA
145145
cuda::std::ranges::sized_range<R>;
146146
#else
147147
std::ranges::sized_range<R>;
148148
#endif
149149

150150
template <typename R, typename T>
151151
concept output_range =
152-
#ifdef BOOST_CRYPT_HAS_CUDA
152+
#if BOOST_CRYPT_HAS_CUDA
153153
cuda::std::ranges::output_range<R, T>;
154154
#else
155155
std::ranges::output_range<R, T>;
156156
#endif
157157

158158
template <typename R>
159159
using range_value_t =
160-
#ifdef BOOST_CRYPT_HAS_CUDA
160+
#if BOOST_CRYPT_HAS_CUDA
161161
cuda::std::ranges::range_value_t<R>;
162162
#else
163163
std::ranges::range_value_t<R>;
@@ -167,7 +167,7 @@ using range_value_t =
167167
template <typename T>
168168
BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>& t) noexcept -> T&&
169169
{
170-
#ifdef BOOST_CRYPT_HAS_CUDA
170+
#if BOOST_CRYPT_HAS_CUDA
171171
return cuda::std::forward<T>(t);
172172
#else
173173
return std::forward<T>(t);
@@ -177,7 +177,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>& t) noexcep
177177
template <typename T>
178178
BOOST_CRYPT_GPU_ENABLED constexpr auto forward(remove_reference_t<T>&& t) noexcept -> T&&
179179
{
180-
#ifdef BOOST_CRYPT_HAS_CUDA
180+
#if BOOST_CRYPT_HAS_CUDA
181181
return cuda::std::forward<T>(cuda::std::move(t));
182182
#else
183183
return std::forward<T>(std::move(t));
@@ -203,15 +203,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto make_span(R&& r)
203203
{
204204
if constexpr (is_span_v<remove_cvref_t<R>>)
205205
{
206-
#ifdef BOOST_CRYPT_HAS_CUDA
206+
#if BOOST_CRYPT_HAS_CUDA
207207
return cuda::std::forward<R>(r);
208208
#else
209209
return std::forward<R>(r);
210210
#endif
211211
}
212212
else
213213
{
214-
#ifdef BOOST_CRYPT_HAS_CUDA
214+
#if BOOST_CRYPT_HAS_CUDA
215215
return cuda::std::span(cuda::std::forward<R>(r));
216216
#else
217217
return std::span(std::forward<R>(r));
@@ -228,7 +228,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto make_span(R& r)
228228
}
229229
else
230230
{
231-
#ifdef BOOST_CRYPT_HAS_CUDA
231+
#if BOOST_CRYPT_HAS_CUDA
232232
return cuda::std::span(r);
233233
#else
234234
return std::span(r);
@@ -247,7 +247,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotl(T val, int shift) noexcept
247247
#pragma clang diagnostic ignored "-Wsign-conversion"
248248
#endif
249249

250-
#ifdef BOOST_CRYPT_HAS_CUDA
250+
#if BOOST_CRYPT_HAS_CUDA
251251
return cuda::std::rotl(val, shift);
252252
#else
253253
return std::rotl(val, shift);
@@ -268,7 +268,7 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotr(T val, int shift) noexcept
268268
#pragma clang diagnostic ignored "-Wsign-conversion"
269269
#endif
270270

271-
#ifdef BOOST_CRYPT_HAS_CUDA
271+
#if BOOST_CRYPT_HAS_CUDA
272272
return cuda::std::rotr(val, shift);
273273
#else
274274
return std::rotr(val, shift);
@@ -282,15 +282,15 @@ BOOST_CRYPT_GPU_ENABLED constexpr auto rotr(T val, int shift) noexcept
282282
// Expected
283283
template <typename T, typename E>
284284
using expected =
285-
#ifdef BOOST_CRYPT_HAS_CUDA
285+
#if BOOST_CRYPT_HAS_CUDA
286286
cuda::std::expected<T, E>;
287287
#else
288288
boost::crypt::detail::expected_impl::expected<T, E>;
289289
#endif
290290

291291
template <typename E>
292292
using unexpected =
293-
#ifdef BOOST_CRYPT_HAS_CUDA
293+
#if BOOST_CRYPT_HAS_CUDA
294294
cuda::std::unexpected<E>;
295295
#else
296296
boost::crypt::detail::expected_impl::unexpected<E>;
@@ -299,7 +299,7 @@ using unexpected =
299299
// Endian
300300
enum class endian : int
301301
{
302-
#ifdef BOOST_CRYPT_HAS_CUDA
302+
#if BOOST_CRYPT_HAS_CUDA
303303
little = static_cast<int>(cuda::std::endian::little),
304304
big = static_cast<int>(cuda::std::endian::big),
305305
native = static_cast<int>(cuda::std::endian::native),

include/boost/crypt2/detail/concepts.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
#include <boost/crypt2/detail/compat.hpp>
99

10-
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !defined(BOOST_CRYPT_HAS_CUDA)
10+
#if !defined(BOOST_CRYPT_BUILD_MODULE) && !BOOST_CRYPT_HAS_CUDA
1111
#include <filesystem>
1212
#include <type_traits>
1313
#endif
1414

1515
namespace boost::crypt::concepts {
1616

17-
#ifndef BOOST_CRYPT_HAS_CUDA
17+
#if !BOOST_CRYPT_HAS_CUDA
1818

1919
template <typename T>
2020
concept file_system_path =

include/boost/crypt2/detail/config.hpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#ifdef __CUDACC__
99
# ifndef BOOST_CRYPT_HAS_CUDA
10-
# define BOOST_CRYPT_HAS_CUDA
10+
# define BOOST_CRYPT_HAS_CUDA 1
1111
# endif
1212
# define BOOST_CRYPT_GPU_ENABLED __host__ __device__
1313
# define BOOST_CRYPT_GPU_HOST_ENABLED __host__
@@ -17,14 +17,18 @@
1717

1818
#ifdef __CUDACC_RTC__
1919
# ifndef BOOST_CRYPT_HAS_CUDA
20-
# define BOOST_CRYPT_HAS_CUDA
20+
# define BOOST_CRYPT_HAS_CUDA 1
2121
# endif
2222
# define BOOST_CRYPT_HAS_NVRTC
2323
# define BOOST_CRYPT_GPU_ENABLED __host__ __device__
2424
# define BOOST_CRYPT_GPU_HOST_ENABLED __host__
2525
# define BOOST_CRYPT_GPU_DEVICE_ENABLED __device__
2626
#endif
2727

28+
#ifndef BOOST_CRYPT_HAS_CUDA
29+
# define BOOST_CRYPT_HAS_CUDA 0
30+
#endif
31+
2832
#ifndef BOOST_CRYPT_GPU_ENABLED
2933
# define BOOST_CRYPT_GPU_ENABLED
3034
#endif
@@ -47,21 +51,4 @@
4751
# define BOOST_CRYPT_EXPORT
4852
#endif
4953

50-
// See: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#hardware-implementation
51-
#if defined(_WIN32) || defined(BOOST_CRYPT_HAS_CUDA)
52-
53-
#define BOOST_CRYPT_ENDIAN_BIG_BYTE 0
54-
#define BOOST_CRYPT_ENDIAN_LITTLE_BYTE 1
55-
56-
#elif defined(__BYTE_ORDER__)
57-
58-
#define BOOST_CRYPT_ENDIAN_BIG_BYTE (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
59-
#define BOOST_CRYPT_ENDIAN_LITTLE_BYTE (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
60-
61-
#else
62-
63-
#error Could not determine endian type. Please file an issue at https://github.com/cppalliance/crypt with your architecture
64-
65-
#endif // Determine endianness
66-
6754
#endif // BOOST_CRYPT_DETAIL_CONFIG_HPP

include/boost/crypt2/detail/file_reader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <boost/crypt2/detail/config.hpp>
99

10-
#ifndef BOOST_CRYPT_HAS_CUDA
10+
#if !BOOST_CRYPT_HAS_CUDA
1111

1212
#ifndef BOOST_CRYPT_BUILD_MODULE
1313
#include <fstream>

include/boost/crypt2/hash/detail/hash_file.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <boost/crypt2/detail/config.hpp>
99

10-
#ifndef BOOST_CRYPT_HAS_CUDA
10+
#if !BOOST_CRYPT_HAS_CUDA
1111

1212
#include <boost/crypt2/detail/file_reader.hpp>
1313
#include <boost/crypt2/detail/concepts.hpp>

include/boost/crypt2/hash/detail/sha224_256_hasher.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace sha256_detail {
4343

4444
// On the host device we prefer this array to be static,
4545
// but in a CUDA environment we move it into the function to make it available to host and device
46-
#ifndef BOOST_CRYPT_HAS_CUDA
46+
#if !BOOST_CRYPT_HAS_CUDA
4747
inline constexpr compat::array<compat::uint32_t, 64U> sha256_k {
4848
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
4949
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,
@@ -102,7 +102,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_maj(const compat::uint32_t x,
102102
template <compat::size_t digest_size>
103103
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_224_256_hasher<digest_size>::process_message_block() noexcept -> void
104104
{
105-
#ifdef BOOST_CRYPT_HAS_CUDA
105+
#if BOOST_CRYPT_HAS_CUDA
106106
constexpr compat::uint32_t sha256_k[64] = {
107107
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b,
108108
0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01,

include/boost/crypt2/hash/detail/sha3_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class sha3_base final {
7676

7777
namespace sha3_detail {
7878

79-
#ifndef BOOST_CRYPT_HAS_CUDA
79+
#if !BOOST_CRYPT_HAS_CUDA
8080

8181
inline constexpr compat::size_t num_rounds {24U};
8282

@@ -108,7 +108,7 @@ inline constexpr compat::array<compat::uint64_t, num_rounds> iota {
108108
template <compat::size_t digest_size, bool is_xof>
109109
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha3_base<digest_size, is_xof>::process_message_block() noexcept -> void
110110
{
111-
#ifdef BOOST_CRYPT_HAS_CUDA
111+
#if BOOST_CRYPT_HAS_CUDA
112112

113113
constexpr compat::size_t num_rounds {24U};
114114

include/boost/crypt2/hash/detail/sha512_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512_base<digest_size>::init() noexcept
301301

302302
namespace sha512_detail {
303303

304-
#ifndef BOOST_CRYPT_HAS_CUDA
304+
#if !BOOST_CRYPT_HAS_CUDA
305305

306306
// On the host device we prefer this array to be static,
307307
// but in a CUDA environment we move it into the function to make it available to host and device
@@ -377,7 +377,7 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha_maj(const compat::uint64_t x,
377377
template <compat::size_t digest_size>
378378
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha512_base<digest_size>::process_message_block() noexcept -> void
379379
{
380-
#ifdef BOOST_CRYPT_HAS_CUDA
380+
#if BOOST_CRYPT_HAS_CUDA
381381

382382
constexpr compat::array<compat::uint64_t, 80U> sha512_k = {
383383
0x428A2F98D728AE22ULL, 0x7137449123EF65CDULL, 0xB5C0FBCFEC4D3B2FULL,

0 commit comments

Comments
 (0)