Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Formatting and naming fixes, add NV_IF_ELSE_TARGET for non-optional f…
Browse files Browse the repository at this point in the history
…alse statements
  • Loading branch information
wmaxey committed Sep 30, 2021
1 parent dfc5a5f commit 6c4f357
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions include/nv/detail/__preprocessor
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
// _NV_REMOVE_PAREN

#if defined(__cplusplus) && __cplusplus >= 201103L
#define _NV_EVAL2(...) __VA_ARGS__
#define _NV_EVAL(...) _NV_EVAL2(__VA_ARGS__)
# define _NV_EVAL1(...) __VA_ARGS__
# define _NV_EVAL(...) _NV_EVAL1(__VA_ARGS__)
#else
#define _NV_EVAL2(x) x
#define _NV_EVAL(x) _NV_EVAL2(x)
#endif
# define _NV_EVAL1(x) x
# define _NV_EVAL(x) _NV_EVAL1(x)
#endif // defined(__cplusplus) && __cplusplus >= 201103L

#define _NV_CONCAT_EVAL1(l, r) _NV_EVAL(l ## r)
#define _NV_CONCAT_EVAL2(l, r) _NV_CONCAT_EVAL2(l, r)
#define _NV_CONCAT_EVAL(l, r) _NV_CONCAT_EVAL1(l, r)

#define _NV_IF_0(t, f) f
Expand Down
19 changes: 13 additions & 6 deletions include/nv/detail/__target_macros
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,19 @@
# define _NV_ARCH_COND_CAT1(cond) _NV_TARGET_BOOL_##cond
# define _NV_ARCH_COND_CAT(cond) _NV_EVAL(_NV_ARCH_COND_CAT1(cond))

# define _NV_TARGET_EMPTY_PARAM ;

# if defined(__cplusplus) && __cplusplus >= 201103L

# define _NV_BLOCK_EXPAND(...) { _NV_REMOVE_PAREN(__VA_ARGS__) }
# define _NV_TARGET_IF(cond, t, ...) _NV_IF(_NV_ARCH_COND_CAT(cond), t, __VA_ARGS__)
# define _NV_TARGET_IF(cond, t, ...) _NV_IF( _NV_ARCH_COND_CAT(cond), t, __VA_ARGS__)

# else // <C++11 fallback

# define _NV_BLOCK_EXPAND(x) { x }
# define _NV_TARGET_IF(cond, t, f) _NV_IF(_NV_ARCH_COND_CAT(cond), t, f)

# define _NV_TARGET_IF(cond, t) _NV_IF(_NV_ARCH_COND_CAT(cond), t, _NV_TARGET_EMPTY_PARAM)
# define _NV_TARGET_IF_ELSE(cond, t, f) _NV_IF(_NV_ARCH_COND_CAT(cond), t, f)

# endif

Expand All @@ -425,13 +429,16 @@

# define _NV_TARGET_DISPATCH(...) _NV_BLOCK_EXPAND(_NV_DISPATCH_N_ARY(_NV_TARGET_DISPATCH_HANDLE, __VA_ARGS__))

# define NV_IF_TARGET(cond, t, ...) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t, __VA_ARGS__))
# define NV_DISPATCH_TARGET(...) _NV_TARGET_DISPATCH(__VA_ARGS__)
// NV_IF_TARGET supports a false statement provided as a variadic macro
# define NV_IF_TARGET(cond, t, ...) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t, __VA_ARGS__))
# define NV_IF_ELSE_TARGET(cond, t, f) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t, f))
# define NV_DISPATCH_TARGET(...) _NV_TARGET_DISPATCH(__VA_ARGS__)

#else // <C++11 fallback

// We can't support variadics, C++03 TUs must specify an empty false argument for the macro
# define NV_IF_TARGET(cond, t, f) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t, f))
// NV_IF_TARGET does not support a fallback false statement in C++03 or C dialects
# define NV_IF_TARGET(cond, t) _NV_BLOCK_EXPAND(_NV_TARGET_IF(cond, t))
# define NV_IF_ELSE_TARGET(cond, t, f) _NV_BLOCK_EXPAND(_NV_TARGET_IF_ELSE(cond, t, f))

#endif

Expand Down

0 comments on commit 6c4f357

Please sign in to comment.