3939 *********************************************************************/
4040#if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32
4141
42+ #if !defined(OPAL_HAVE_ATOMIC_MIN_32 )
43+ static inline int32_t opal_atomic_fetch_min_32 (volatile int32_t * addr , int32_t value )
44+ {
45+ int32_t old = * addr ;
46+ do {
47+ if (old <= value ) {
48+ break ;
49+ }
50+ } while (!opal_atomic_compare_exchange_strong_32 (addr , & old , value ));
51+
52+ return old ;
53+ }
54+
55+ #define OPAL_HAVE_ATOMIC_MIN_32 1
56+
57+ #endif /* OPAL_HAVE_ATOMIC_MIN_32 */
58+
59+ #if !defined(OPAL_HAVE_ATOMIC_MAX_32 )
60+ static inline int32_t opal_atomic_fetch_max_32 (volatile int32_t * addr , int32_t value )
61+ {
62+ int32_t old = * addr ;
63+ do {
64+ if (old >= value ) {
65+ break ;
66+ }
67+ } while (!opal_atomic_compare_exchange_strong_32 (addr , & old , value ));
68+
69+ return old ;
70+ }
71+
72+ #define OPAL_HAVE_ATOMIC_MAX_32 1
73+ #endif /* OPAL_HAVE_ATOMIC_MAX_32 */
74+
4275#define OPAL_ATOMIC_DEFINE_CMPXCG_OP (type , bits , operation , name ) \
4376 static inline type opal_atomic_fetch_ ## name ## _ ## bits (volatile type *addr, type value) \
4477 { \
@@ -104,6 +137,39 @@ OPAL_ATOMIC_DEFINE_CMPXCG_OP(int32_t, 32, -, sub)
104137
105138#if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64
106139
140+ #if !defined(OPAL_HAVE_ATOMIC_MIN_64 )
141+ static inline int64_t opal_atomic_fetch_min_64 (volatile int64_t * addr , int64_t value )
142+ {
143+ int64_t old = * addr ;
144+ do {
145+ if (old <= value ) {
146+ break ;
147+ }
148+ } while (!opal_atomic_compare_exchange_strong_64 (addr , & old , value ));
149+
150+ return old ;
151+ }
152+
153+ #define OPAL_HAVE_ATOMIC_MIN_64 1
154+
155+ #endif /* OPAL_HAVE_ATOMIC_MIN_64 */
156+
157+ #if !defined(OPAL_HAVE_ATOMIC_MAX_64 )
158+ static inline int64_t opal_atomic_fetch_max_64 (volatile int64_t * addr , int64_t value )
159+ {
160+ int64_t old = * addr ;
161+ do {
162+ if (old >= value ) {
163+ break ;
164+ }
165+ } while (!opal_atomic_compare_exchange_strong_64 (addr , & old , value ));
166+
167+ return old ;
168+ }
169+
170+ #define OPAL_HAVE_ATOMIC_MAX_64 1
171+ #endif /* OPAL_HAVE_ATOMIC_MAX_64 */
172+
107173#if !defined(OPAL_HAVE_ATOMIC_SWAP_64 )
108174#define OPAL_HAVE_ATOMIC_SWAP_64 1
109175static inline int64_t opal_atomic_swap_64 (volatile int64_t * addr ,
@@ -115,7 +181,7 @@ static inline int64_t opal_atomic_swap_64(volatile int64_t *addr,
115181
116182 return old ;
117183}
118- #endif /* OPAL_HAVE_ATOMIC_SWAP_32 */
184+ #endif /* OPAL_HAVE_ATOMIC_SWAP_64 */
119185
120186#if !defined(OPAL_HAVE_ATOMIC_ADD_64 )
121187#define OPAL_HAVE_ATOMIC_ADD_64 1
@@ -321,12 +387,37 @@ OPAL_ATOMIC_DEFINE_OP_FETCH(or, |, int32_t, int32_t, 32)
321387OPAL_ATOMIC_DEFINE_OP_FETCH (xor , ^, int32_t , int32_t , 32 )
322388OPAL_ATOMIC_DEFINE_OP_FETCH (sub , - , int32_t , int32_t , 32 )
323389
390+ static inline int32_t opal_atomic_min_fetch_32 (volatile int32_t * addr , int32_t value )
391+ {
392+ int32_t old = opal_atomic_fetch_min_32 (addr , value );
393+ return old <= value ? old : value ;
394+ }
395+
396+ static inline int32_t opal_atomic_max_fetch_32 (volatile int32_t * addr , int32_t value )
397+ {
398+ int32_t old = opal_atomic_fetch_max_32 (addr , value );
399+ return old >= value ? old : value ;
400+ }
401+
324402#if OPAL_HAVE_ATOMIC_MATH_64
325403OPAL_ATOMIC_DEFINE_OP_FETCH (add , + , int64_t , int64_t , 64 )
326404OPAL_ATOMIC_DEFINE_OP_FETCH (and , & , int64_t , int64_t , 64 )
327405OPAL_ATOMIC_DEFINE_OP_FETCH (or , |, int64_t , int64_t , 64 )
328406OPAL_ATOMIC_DEFINE_OP_FETCH (xor , ^, int64_t , int64_t , 64 )
329407OPAL_ATOMIC_DEFINE_OP_FETCH (sub , - , int64_t , int64_t , 64 )
408+
409+ static inline int64_t opal_atomic_min_fetch_64 (volatile int64_t * addr , int64_t value )
410+ {
411+ int64_t old = opal_atomic_fetch_min_64 (addr , value );
412+ return old <= value ? old : value ;
413+ }
414+
415+ static inline int64_t opal_atomic_max_fetch_64 (volatile int64_t * addr , int64_t value )
416+ {
417+ int64_t old = opal_atomic_fetch_max_64 (addr , value );
418+ return old >= value ? old : value ;
419+ }
420+
330421#endif
331422
332423static inline intptr_t opal_atomic_fetch_add_ptr ( volatile void * addr ,
0 commit comments