@@ -251,3 +251,67 @@ fetch_ops_1_param! {
251
251
max => ( u32 , u64 , i32 , i64 ) ,
252
252
exch => ( u32 , u64 , i32 , i64 , f32 , f64 ) ,
253
253
}
254
+
255
+ macro_rules! inner_cas {
256
+ ( $( $type: ty, $scope: ident) ,* $( , ) ?) => {
257
+ $(
258
+ paste! {
259
+ #[ $crate:: gpu_only]
260
+ #[ allow( clippy:: missing_safety_doc) ]
261
+ pub unsafe fn [ <atomic_compare_and_swap_ $type _ $scope>] ( ptr: * mut $type, current: $type, new: $type, ordering: Ordering ) -> $type {
262
+ if ge_sm70( ) {
263
+ match ordering {
264
+ SeqCst => {
265
+ intrinsics:: [ <fence_sc_ $scope>] ( ) ;
266
+ intrinsics:: [ <atomic_fetch_cas_acquire_ $type _ $scope>] ( ptr, current, new)
267
+ } ,
268
+ Acquire => intrinsics:: [ <atomic_fetch_cas_acquire_ $type _ $scope>] ( ptr, current, new) ,
269
+ AcqRel => intrinsics:: [ <atomic_fetch_cas_acqrel_ $type _ $scope>] ( ptr, current, new) ,
270
+ Release => intrinsics:: [ <atomic_fetch_cas_release_ $type _ $scope>] ( ptr, current, new) ,
271
+ Relaxed => intrinsics:: [ <atomic_fetch_cas_relaxed_ $type _ $scope>] ( ptr, current, new) ,
272
+ _ => unimplemented!( "Weird ordering added by core" )
273
+ }
274
+ } else {
275
+ match ordering {
276
+ SeqCst | AcqRel => {
277
+ intrinsics:: [ <membar_ $scope>] ( ) ;
278
+ let val = intrinsics:: [ <atomic_fetch_cas_volatile_ $type _ $scope>] ( ptr, current, new) ;
279
+ intrinsics:: [ <membar_ $scope>] ( ) ;
280
+ val
281
+ } ,
282
+ Acquire => {
283
+ let val = intrinsics:: [ <atomic_fetch_cas_volatile_ $type _ $scope>] ( ptr, current, new) ;
284
+ intrinsics:: [ <membar_ $scope>] ( ) ;
285
+ val
286
+ } ,
287
+ Release => {
288
+ intrinsics:: [ <membar_ $scope>] ( ) ;
289
+ intrinsics:: [ <atomic_fetch_cas_volatile_ $type _ $scope>] ( ptr, current, new)
290
+ } ,
291
+ Relaxed => {
292
+ intrinsics:: [ <atomic_fetch_cas_volatile_ $type _ $scope>] ( ptr, current, new)
293
+ } ,
294
+ _ => unimplemented!( "Weird ordering added by core" )
295
+ }
296
+ }
297
+ }
298
+ }
299
+ ) *
300
+ }
301
+ }
302
+
303
+ macro_rules! impl_cas {
304
+ ( $( $type: ident) ,* $( , ) ?) => {
305
+ $(
306
+ inner_cas!(
307
+ $type, block,
308
+ $type, device,
309
+ $type, system,
310
+ ) ;
311
+ ) *
312
+ } ;
313
+ }
314
+
315
+ impl_cas ! {
316
+ u32 , u64 , i32 , i64 , f32 , f64
317
+ }
0 commit comments