66//
77// ===----------------------------------------------------------------------===//
88
9- #ifndef LLVM_LIBC_SRC___SUPPORT_RPC_RPC_UTIL_H
10- #define LLVM_LIBC_SRC___SUPPORT_RPC_RPC_UTIL_H
11-
12- #include " src/__support/macros/attributes.h"
13- #include " src/__support/macros/config.h"
9+ #ifndef LLVM_LIBC_SHARED_RPC_UTIL_H
10+ #define LLVM_LIBC_SHARED_RPC_UTIL_H
1411
1512#include < stddef.h>
1613#include < stdint.h>
2017#define RPC_TARGET_IS_GPU
2118#endif
2219
23- namespace LIBC_NAMESPACE_DECL {
20+ #ifndef RPC_INLINE
21+ #define RPC_INLINE inline
22+ #endif
23+
2424namespace rpc {
2525
2626template <typename T> struct type_identity {
@@ -40,26 +40,26 @@ template <class T> struct is_const<const T> : type_constant<bool, true> {};
4040
4141// / Freestanding implementation of std::move.
4242template <class T >
43- LIBC_INLINE constexpr typename remove_reference<T>::type &&move(T &&t) {
43+ RPC_INLINE constexpr typename remove_reference<T>::type &&move(T &&t) {
4444 return static_cast <typename remove_reference<T>::type &&>(t);
4545}
4646
4747// / Freestanding implementation of std::forward.
4848template <typename T>
49- LIBC_INLINE constexpr T &&forward(typename remove_reference<T>::type &value) {
49+ RPC_INLINE constexpr T &&forward(typename remove_reference<T>::type &value) {
5050 return static_cast <T &&>(value);
5151}
5252template <typename T>
53- LIBC_INLINE constexpr T &&forward(typename remove_reference<T>::type &&value) {
53+ RPC_INLINE constexpr T &&forward(typename remove_reference<T>::type &&value) {
5454 return static_cast <T &&>(value);
5555}
5656
5757struct in_place_t {
58- LIBC_INLINE explicit in_place_t () = default;
58+ RPC_INLINE explicit in_place_t () = default;
5959};
6060
6161struct nullopt_t {
62- LIBC_INLINE constexpr explicit nullopt_t () = default;
62+ RPC_INLINE constexpr explicit nullopt_t () = default;
6363};
6464
6565constexpr inline in_place_t in_place{};
@@ -75,15 +75,15 @@ template <typename T> class optional {
7575
7676 bool in_use = false ;
7777
78- LIBC_INLINE ~OptionalStorage () { reset (); }
78+ RPC_INLINE ~OptionalStorage () { reset (); }
7979
80- LIBC_INLINE constexpr OptionalStorage () : empty() {}
80+ RPC_INLINE constexpr OptionalStorage () : empty() {}
8181
8282 template <typename ... Args>
83- LIBC_INLINE constexpr explicit OptionalStorage (in_place_t , Args &&...args)
83+ RPC_INLINE constexpr explicit OptionalStorage (in_place_t , Args &&...args)
8484 : stored_value(forward<Args>(args)...) {}
8585
86- LIBC_INLINE constexpr void reset () {
86+ RPC_INLINE constexpr void reset () {
8787 if (in_use)
8888 stored_value.~U ();
8989 in_use = false ;
@@ -93,60 +93,54 @@ template <typename T> class optional {
9393 OptionalStorage<T> storage;
9494
9595public:
96- LIBC_INLINE constexpr optional () = default;
97- LIBC_INLINE constexpr optional (nullopt_t ) {}
96+ RPC_INLINE constexpr optional () = default;
97+ RPC_INLINE constexpr optional (nullopt_t ) {}
9898
99- LIBC_INLINE constexpr optional (const T &t) : storage(in_place, t) {
99+ RPC_INLINE constexpr optional (const T &t) : storage(in_place, t) {
100100 storage.in_use = true ;
101101 }
102- LIBC_INLINE constexpr optional (const optional &) = default;
102+ RPC_INLINE constexpr optional (const optional &) = default;
103103
104- LIBC_INLINE constexpr optional (T &&t) : storage(in_place, move(t)) {
104+ RPC_INLINE constexpr optional (T &&t) : storage(in_place, move(t)) {
105105 storage.in_use = true ;
106106 }
107- LIBC_INLINE constexpr optional (optional &&O) = default;
107+ RPC_INLINE constexpr optional (optional &&O) = default;
108108
109- LIBC_INLINE constexpr optional &operator =(T &&t) {
109+ RPC_INLINE constexpr optional &operator =(T &&t) {
110110 storage = move (t);
111111 return *this ;
112112 }
113- LIBC_INLINE constexpr optional &operator =(optional &&) = default ;
113+ RPC_INLINE constexpr optional &operator =(optional &&) = default ;
114114
115- LIBC_INLINE constexpr optional &operator =(const T &t) {
115+ RPC_INLINE constexpr optional &operator =(const T &t) {
116116 storage = t;
117117 return *this ;
118118 }
119- LIBC_INLINE constexpr optional &operator =(const optional &) = default ;
119+ RPC_INLINE constexpr optional &operator =(const optional &) = default ;
120120
121- LIBC_INLINE constexpr void reset () { storage.reset (); }
121+ RPC_INLINE constexpr void reset () { storage.reset (); }
122122
123- LIBC_INLINE constexpr const T &value () const & {
124- return storage.stored_value ;
125- }
123+ RPC_INLINE constexpr const T &value () const & { return storage.stored_value ; }
126124
127- LIBC_INLINE constexpr T &value () & { return storage.stored_value ; }
125+ RPC_INLINE constexpr T &value () & { return storage.stored_value ; }
128126
129- LIBC_INLINE constexpr explicit operator bool () const {
130- return storage.in_use ;
131- }
132- LIBC_INLINE constexpr bool has_value () const { return storage.in_use ; }
133- LIBC_INLINE constexpr const T *operator ->() const {
127+ RPC_INLINE constexpr explicit operator bool () const { return storage.in_use ; }
128+ RPC_INLINE constexpr bool has_value () const { return storage.in_use ; }
129+ RPC_INLINE constexpr const T *operator ->() const {
134130 return &storage.stored_value ;
135131 }
136- LIBC_INLINE constexpr T *operator ->() { return &storage.stored_value ; }
137- LIBC_INLINE constexpr const T &operator *() const & {
132+ RPC_INLINE constexpr T *operator ->() { return &storage.stored_value ; }
133+ RPC_INLINE constexpr const T &operator *() const & {
138134 return storage.stored_value ;
139135 }
140- LIBC_INLINE constexpr T &operator *() & { return storage.stored_value ; }
136+ RPC_INLINE constexpr T &operator *() & { return storage.stored_value ; }
141137
142- LIBC_INLINE constexpr T &&value() && { return move (storage.stored_value ); }
143- LIBC_INLINE constexpr T &&operator *() && {
144- return move (storage.stored_value );
145- }
138+ RPC_INLINE constexpr T &&value() && { return move (storage.stored_value ); }
139+ RPC_INLINE constexpr T &&operator *() && { return move (storage.stored_value ); }
146140};
147141
148142// / Suspend the thread briefly to assist the thread scheduler during busy loops.
149- LIBC_INLINE void sleep_briefly () {
143+ RPC_INLINE void sleep_briefly () {
150144#if defined(LIBC_TARGET_ARCH_IS_NVPTX)
151145 if (__nvvm_reflect (" __CUDA_ARCH" ) >= 700 )
152146 asm (" nanosleep.u32 64;" ::: " memory" );
@@ -164,7 +158,7 @@ LIBC_INLINE void sleep_briefly() {
164158}
165159
166160// / Conditional to indicate if this process is running on the GPU.
167- LIBC_INLINE constexpr bool is_process_gpu () {
161+ RPC_INLINE constexpr bool is_process_gpu () {
168162#ifdef RPC_TARGET_IS_GPU
169163 return true ;
170164#else
@@ -173,14 +167,14 @@ LIBC_INLINE constexpr bool is_process_gpu() {
173167}
174168
175169// / Wait for all lanes in the group to complete.
176- LIBC_INLINE void sync_lane (uint64_t lane_mask) {
170+ RPC_INLINE void sync_lane (uint64_t lane_mask) {
177171#ifdef RPC_TARGET_IS_GPU
178172 return __gpu_sync_lane (lane_mask);
179173#endif
180174}
181175
182176// / Copies the value from the first active thread to the rest.
183- LIBC_INLINE uint32_t broadcast_value (uint64_t lane_mask, uint32_t x) {
177+ RPC_INLINE uint32_t broadcast_value (uint64_t lane_mask, uint32_t x) {
184178#ifdef RPC_TARGET_IS_GPU
185179 return __gpu_read_first_lane_u32 (lane_mask, x);
186180#else
@@ -189,7 +183,7 @@ LIBC_INLINE uint32_t broadcast_value(uint64_t lane_mask, uint32_t x) {
189183}
190184
191185// / Returns the number lanes that participate in the RPC interface.
192- LIBC_INLINE uint32_t get_num_lanes () {
186+ RPC_INLINE uint32_t get_num_lanes () {
193187#ifdef RPC_TARGET_IS_GPU
194188 return __gpu_num_lanes ();
195189#else
@@ -198,7 +192,7 @@ LIBC_INLINE uint32_t get_num_lanes() {
198192}
199193
200194// / Returns the id of the thread inside of an AMD wavefront executing together.
201- LIBC_INLINE uint64_t get_lane_mask () {
195+ RPC_INLINE uint64_t get_lane_mask () {
202196#ifdef RPC_TARGET_IS_GPU
203197 return __gpu_lane_mask ();
204198#else
@@ -207,7 +201,7 @@ LIBC_INLINE uint64_t get_lane_mask() {
207201}
208202
209203// / Returns the id of the thread inside of an AMD wavefront executing together.
210- LIBC_INLINE uint32_t get_lane_id () {
204+ RPC_INLINE uint32_t get_lane_id () {
211205#ifdef RPC_TARGET_IS_GPU
212206 return __gpu_lane_id ();
213207#else
@@ -216,7 +210,7 @@ LIBC_INLINE uint32_t get_lane_id() {
216210}
217211
218212// / Conditional that is only true for a single thread in a lane.
219- LIBC_INLINE bool is_first_lane (uint64_t lane_mask) {
213+ RPC_INLINE bool is_first_lane (uint64_t lane_mask) {
220214#ifdef RPC_TARGET_IS_GPU
221215 return __gpu_is_first_in_lane (lane_mask);
222216#else
@@ -225,7 +219,7 @@ LIBC_INLINE bool is_first_lane(uint64_t lane_mask) {
225219}
226220
227221// / Returns a bitmask of threads in the current lane for which \p x is true.
228- LIBC_INLINE uint64_t ballot (uint64_t lane_mask, bool x) {
222+ RPC_INLINE uint64_t ballot (uint64_t lane_mask, bool x) {
229223#ifdef RPC_TARGET_IS_GPU
230224 return __gpu_ballot (lane_mask, x);
231225#else
@@ -235,22 +229,22 @@ LIBC_INLINE uint64_t ballot(uint64_t lane_mask, bool x) {
235229
236230// / Return \p val aligned "upwards" according to \p align.
237231template <typename V, typename A>
238- LIBC_INLINE constexpr V align_up (V val, A align) {
232+ RPC_INLINE constexpr V align_up (V val, A align) {
239233 return ((val + V (align) - 1 ) / V (align)) * V (align);
240234}
241235
242236// / Utility to provide a unified interface between the CPU and GPU's memory
243237// / model. On the GPU stack variables are always private to a lane so we can
244238// / simply use the variable passed in. On the CPU we need to allocate enough
245239// / space for the whole lane and index into it.
246- template <typename V> LIBC_INLINE V &lane_value (V *val, uint32_t id) {
240+ template <typename V> RPC_INLINE V &lane_value (V *val, uint32_t id) {
247241 if constexpr (is_process_gpu ())
248242 return *val;
249243 return val[id];
250244}
251245
252246// / Advance the \p p by \p bytes.
253- template <typename T, typename U> LIBC_INLINE T *advance (T *ptr, U bytes) {
247+ template <typename T, typename U> RPC_INLINE T *advance (T *ptr, U bytes) {
254248 if constexpr (is_const<T>::value)
255249 return reinterpret_cast <T *>(reinterpret_cast <const uint8_t *>(ptr) +
256250 bytes);
@@ -259,15 +253,14 @@ template <typename T, typename U> LIBC_INLINE T *advance(T *ptr, U bytes) {
259253}
260254
261255// / Wrapper around the optimal memory copy implementation for the target.
262- LIBC_INLINE void rpc_memcpy (void *dst, const void *src, size_t count) {
256+ RPC_INLINE void rpc_memcpy (void *dst, const void *src, size_t count) {
263257 __builtin_memcpy (dst, src, count);
264258}
265259
266- template <class T > LIBC_INLINE constexpr const T &max (const T &a, const T &b) {
260+ template <class T > RPC_INLINE constexpr const T &max (const T &a, const T &b) {
267261 return (a < b) ? b : a;
268262}
269263
270264} // namespace rpc
271- } // namespace LIBC_NAMESPACE_DECL
272265
273- #endif // LLVM_LIBC_SRC___SUPPORT_RPC_RPC_UTIL_H
266+ #endif // LLVM_LIBC_SHARED_RPC_UTIL_H
0 commit comments