@@ -135,6 +135,24 @@ uint64_t opal_common_ucx_load_uint64(const void *ptr, size_t size)
135135 }
136136}
137137
138+ /**
139+ * Cast and store a uint64_t value to a value of \c size bytes pointed to by \c ptr.
140+ */
141+ static inline
142+ void opal_common_ucx_store_uint64 (uint64_t value , void * ptr , size_t size )
143+ {
144+ if (sizeof (uint8_t ) == size ) {
145+ * (uint8_t * )ptr = value ;
146+ } else if (sizeof (uint16_t ) == size ) {
147+ * (uint16_t * )ptr = value ;
148+ } else if (sizeof (uint32_t ) == size ) {
149+ * (uint32_t * )ptr = value ;
150+ } else {
151+ * (uint64_t * )ptr = value ;
152+ }
153+ }
154+
155+
138156static inline
139157ucs_status_t opal_common_ucx_request_status (ucs_status_ptr_t request )
140158{
@@ -226,13 +244,7 @@ int opal_common_ucx_atomic_cswap(ucp_ep_h ep, uint64_t compare,
226244 uint64_t remote_addr , ucp_rkey_h rkey ,
227245 ucp_worker_h worker )
228246{
229- if (op_size == sizeof (uint64_t )) {
230- * (uint64_t * )result = value ;
231- } else {
232- assert (op_size == sizeof (uint32_t ));
233- * (uint32_t * )result = value ;
234- }
235-
247+ opal_common_ucx_store_uint64 (value , result , op_size );
236248 return opal_common_ucx_atomic_fetch (ep , UCP_ATOMIC_FETCH_OP_CSWAP , compare , result ,
237249 op_size , remote_addr , rkey , worker );
238250}
@@ -244,13 +256,7 @@ ucs_status_ptr_t opal_common_ucx_atomic_cswap_nb(ucp_ep_h ep, uint64_t compare,
244256 ucp_send_callback_t req_handler ,
245257 ucp_worker_h worker )
246258{
247- if (op_size == sizeof (uint64_t )) {
248- * (uint64_t * )result = value ;
249- } else {
250- assert (op_size == sizeof (uint32_t ));
251- * (uint32_t * )result = value ;
252- }
253-
259+ opal_common_ucx_store_uint64 (value , result , op_size );
254260 return opal_common_ucx_atomic_fetch_nb (ep , UCP_ATOMIC_FETCH_OP_CSWAP , compare , result ,
255261 op_size , remote_addr , rkey , req_handler , worker );
256262}
0 commit comments