@@ -2337,10 +2337,7 @@ fn strongest_failure_ordering(order: Ordering) -> Ordering {
23372337}
23382338
23392339#[ inline]
2340- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2341- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
23422340unsafe fn atomic_store < T : Copy > ( dst : * mut T , val : T , order : Ordering ) {
2343- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
23442341 // SAFETY: the caller must uphold the safety contract for `atomic_store`.
23452342 unsafe {
23462343 match order {
@@ -2351,18 +2348,10 @@ unsafe fn atomic_store<T: Copy>(dst: *mut T, val: T, order: Ordering) {
23512348 AcqRel => panic ! ( "there is no such thing as an acquire/release store" ) ,
23522349 }
23532350 }
2354- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2355- // SAFETY: the caller must uphold the safety contract for `atomic_store`.
2356- unsafe {
2357- * dst = val;
2358- }
23592351}
23602352
23612353#[ inline]
2362- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2363- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
23642354unsafe fn atomic_load < T : Copy > ( dst : * const T , order : Ordering ) -> T {
2365- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
23662355 // SAFETY: the caller must uphold the safety contract for `atomic_load`.
23672356 unsafe {
23682357 match order {
@@ -2373,19 +2362,11 @@ unsafe fn atomic_load<T: Copy>(dst: *const T, order: Ordering) -> T {
23732362 AcqRel => panic ! ( "there is no such thing as an acquire/release load" ) ,
23742363 }
23752364 }
2376- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2377- // SAFETY: the caller must uphold the safety contract for `atomic_load`.
2378- unsafe {
2379- * dst
2380- }
23812365}
23822366
23832367#[ inline]
23842368#[ cfg( target_has_atomic = "8" ) ]
2385- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2386- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
23872369unsafe fn atomic_swap < T : Copy > ( dst : * mut T , val : T , order : Ordering ) -> T {
2388- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
23892370 // SAFETY: the caller must uphold the safety contract for `atomic_swap`.
23902371 unsafe {
23912372 match order {
@@ -2396,22 +2377,12 @@ unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
23962377 SeqCst => intrinsics:: atomic_xchg ( dst, val) ,
23972378 }
23982379 }
2399- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2400- // SAFETY: the caller must uphold the safety contract for `atomic_swap`.
2401- unsafe {
2402- let old = * dst;
2403- * dst = val;
2404- old
2405- }
24062380}
24072381
24082382/// Returns the previous value (like __sync_fetch_and_add).
24092383#[ inline]
24102384#[ cfg( target_has_atomic = "8" ) ]
2411- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2412- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
24132385unsafe fn atomic_add < T : Copy + crate :: ops:: Add < Output = T > > ( dst : * mut T , val : T , order : Ordering ) -> T {
2414- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
24152386 // SAFETY: the caller must uphold the safety contract for `atomic_add`.
24162387 unsafe {
24172388 match order {
@@ -2422,22 +2393,12 @@ unsafe fn atomic_add<T: Copy + crate::ops::Add<Output = T>>(dst: *mut T, val: T,
24222393 SeqCst => intrinsics:: atomic_xadd ( dst, val) ,
24232394 }
24242395 }
2425- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2426- // SAFETY: the caller must uphold the safety contract for `atomic_add`.
2427- unsafe {
2428- let old = * dst;
2429- * dst = old + val;
2430- old
2431- }
24322396}
24332397
24342398/// Returns the previous value (like __sync_fetch_and_sub).
24352399#[ inline]
24362400#[ cfg( target_has_atomic = "8" ) ]
2437- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2438- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
24392401unsafe fn atomic_sub < T : Copy + crate :: ops:: Sub < Output = T > > ( dst : * mut T , val : T , order : Ordering ) -> T {
2440- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
24412402 // SAFETY: the caller must uphold the safety contract for `atomic_sub`.
24422403 unsafe {
24432404 match order {
@@ -2448,58 +2409,35 @@ unsafe fn atomic_sub<T: Copy + crate::ops::Sub<Output = T>>(dst: *mut T, val: T,
24482409 SeqCst => intrinsics:: atomic_xsub ( dst, val) ,
24492410 }
24502411 }
2451- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2452- // SAFETY: the caller must uphold the safety contract for `atomic_sub`.
2453- unsafe {
2454- let old = * dst;
2455- * dst = old - val;
2456- old
2457- }
24582412}
24592413
24602414#[ inline]
24612415#[ cfg( target_has_atomic = "8" ) ]
2462- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2463- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
24642416unsafe fn atomic_compare_exchange < T : Copy + crate :: cmp:: PartialEq > (
24652417 dst : * mut T ,
24662418 old : T ,
24672419 new : T ,
24682420 success : Ordering ,
24692421 failure : Ordering ,
24702422) -> Result < T , T > {
2471- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2472- {
2473- // SAFETY: the caller must uphold the safety contract for `atomic_compare_exchange`.
2474- let ( val, ok) = unsafe {
2475- match ( success, failure) {
2476- ( Acquire , Acquire ) => intrinsics:: atomic_cxchg_acq ( dst, old, new) ,
2477- ( Release , Relaxed ) => intrinsics:: atomic_cxchg_rel ( dst, old, new) ,
2478- ( AcqRel , Acquire ) => intrinsics:: atomic_cxchg_acqrel ( dst, old, new) ,
2479- ( Relaxed , Relaxed ) => intrinsics:: atomic_cxchg_relaxed ( dst, old, new) ,
2480- ( SeqCst , SeqCst ) => intrinsics:: atomic_cxchg ( dst, old, new) ,
2481- ( Acquire , Relaxed ) => intrinsics:: atomic_cxchg_acq_failrelaxed ( dst, old, new) ,
2482- ( AcqRel , Relaxed ) => intrinsics:: atomic_cxchg_acqrel_failrelaxed ( dst, old, new) ,
2483- ( SeqCst , Relaxed ) => intrinsics:: atomic_cxchg_failrelaxed ( dst, old, new) ,
2484- ( SeqCst , Acquire ) => intrinsics:: atomic_cxchg_failacq ( dst, old, new) ,
2485- ( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
2486- ( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
2487- _ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
2488- }
2489- } ;
2490- if ok { Ok ( val) } else { Err ( val) }
2491- }
2492- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
24932423 // SAFETY: the caller must uphold the safety contract for `atomic_compare_exchange`.
2494- unsafe {
2495- let current = * dst;
2496- if current == old {
2497- * dst = new;
2498- Ok ( current)
2499- } else {
2500- Err ( current)
2424+ let ( val, ok) = unsafe {
2425+ match ( success, failure) {
2426+ ( Acquire , Acquire ) => intrinsics:: atomic_cxchg_acq ( dst, old, new) ,
2427+ ( Release , Relaxed ) => intrinsics:: atomic_cxchg_rel ( dst, old, new) ,
2428+ ( AcqRel , Acquire ) => intrinsics:: atomic_cxchg_acqrel ( dst, old, new) ,
2429+ ( Relaxed , Relaxed ) => intrinsics:: atomic_cxchg_relaxed ( dst, old, new) ,
2430+ ( SeqCst , SeqCst ) => intrinsics:: atomic_cxchg ( dst, old, new) ,
2431+ ( Acquire , Relaxed ) => intrinsics:: atomic_cxchg_acq_failrelaxed ( dst, old, new) ,
2432+ ( AcqRel , Relaxed ) => intrinsics:: atomic_cxchg_acqrel_failrelaxed ( dst, old, new) ,
2433+ ( SeqCst , Relaxed ) => intrinsics:: atomic_cxchg_failrelaxed ( dst, old, new) ,
2434+ ( SeqCst , Acquire ) => intrinsics:: atomic_cxchg_failacq ( dst, old, new) ,
2435+ ( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
2436+ ( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
2437+ _ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
25012438 }
2502- }
2439+ } ;
2440+ if ok { Ok ( val) } else { Err ( val) }
25032441}
25042442
25052443#[ inline]
@@ -2511,38 +2449,24 @@ unsafe fn atomic_compare_exchange_weak<T: Copy + crate::cmp::PartialEq>(
25112449 _success : Ordering ,
25122450 _failure : Ordering ,
25132451) -> Result < T , T > {
2514- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2515- {
2516- // SAFETY: the caller must uphold the safety contract for `atomic_compare_exchange_weak`.
2517- let ( val, ok) = unsafe {
2518- match ( _success, _failure) {
2519- ( Acquire , Acquire ) => intrinsics:: atomic_cxchgweak_acq ( dst, old, new) ,
2520- ( Release , Relaxed ) => intrinsics:: atomic_cxchgweak_rel ( dst, old, new) ,
2521- ( AcqRel , Acquire ) => intrinsics:: atomic_cxchgweak_acqrel ( dst, old, new) ,
2522- ( Relaxed , Relaxed ) => intrinsics:: atomic_cxchgweak_relaxed ( dst, old, new) ,
2523- ( SeqCst , SeqCst ) => intrinsics:: atomic_cxchgweak ( dst, old, new) ,
2524- ( Acquire , Relaxed ) => intrinsics:: atomic_cxchgweak_acq_failrelaxed ( dst, old, new) ,
2525- ( AcqRel , Relaxed ) => intrinsics:: atomic_cxchgweak_acqrel_failrelaxed ( dst, old, new) ,
2526- ( SeqCst , Relaxed ) => intrinsics:: atomic_cxchgweak_failrelaxed ( dst, old, new) ,
2527- ( SeqCst , Acquire ) => intrinsics:: atomic_cxchgweak_failacq ( dst, old, new) ,
2528- ( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
2529- ( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
2530- _ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
2531- }
2532- } ;
2533- if ok { Ok ( val) } else { Err ( val) }
2534- }
2535- #[ cfg( any( target_arch = "sbf" , target_arch = "bpf" ) ) ]
25362452 // SAFETY: the caller must uphold the safety contract for `atomic_compare_exchange_weak`.
2537- unsafe {
2538- let current = * dst;
2539- if current == old {
2540- * dst = new;
2541- Ok ( current)
2542- } else {
2543- Err ( current)
2453+ let ( val, ok) = unsafe {
2454+ match ( _success, _failure) {
2455+ ( Acquire , Acquire ) => intrinsics:: atomic_cxchgweak_acq ( dst, old, new) ,
2456+ ( Release , Relaxed ) => intrinsics:: atomic_cxchgweak_rel ( dst, old, new) ,
2457+ ( AcqRel , Acquire ) => intrinsics:: atomic_cxchgweak_acqrel ( dst, old, new) ,
2458+ ( Relaxed , Relaxed ) => intrinsics:: atomic_cxchgweak_relaxed ( dst, old, new) ,
2459+ ( SeqCst , SeqCst ) => intrinsics:: atomic_cxchgweak ( dst, old, new) ,
2460+ ( Acquire , Relaxed ) => intrinsics:: atomic_cxchgweak_acq_failrelaxed ( dst, old, new) ,
2461+ ( AcqRel , Relaxed ) => intrinsics:: atomic_cxchgweak_acqrel_failrelaxed ( dst, old, new) ,
2462+ ( SeqCst , Relaxed ) => intrinsics:: atomic_cxchgweak_failrelaxed ( dst, old, new) ,
2463+ ( SeqCst , Acquire ) => intrinsics:: atomic_cxchgweak_failacq ( dst, old, new) ,
2464+ ( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
2465+ ( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
2466+ _ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
25442467 }
2545- }
2468+ } ;
2469+ if ok { Ok ( val) } else { Err ( val) }
25462470}
25472471
25482472#[ inline]
@@ -2609,7 +2533,6 @@ unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
26092533#[ inline]
26102534#[ cfg( target_has_atomic = "8" ) ]
26112535unsafe fn atomic_max < T : Copy + crate :: cmp:: Ord > ( dst : * mut T , val : T , _order : Ordering ) -> T {
2612- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
26132536 // SAFETY: the caller must uphold the safety contract for `atomic_max`
26142537 unsafe {
26152538 match _order {
@@ -2620,18 +2543,12 @@ unsafe fn atomic_max<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Ord
26202543 SeqCst => intrinsics:: atomic_max ( dst, val) ,
26212544 }
26222545 }
2623- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2624- // SAFETY: the caller must uphold the safety contract for `atomic_max`
2625- unsafe {
2626- crate :: cmp:: max ( * dst, val)
2627- }
26282546}
26292547
26302548/// returns the min value (signed comparison)
26312549#[ inline]
26322550#[ cfg( target_has_atomic = "8" ) ]
26332551unsafe fn atomic_min < T : Copy + crate :: cmp:: Ord > ( dst : * mut T , val : T , _order : Ordering ) -> T {
2634- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
26352552 // SAFETY: the caller must uphold the safety contract for `atomic_min`
26362553 unsafe {
26372554 match _order {
@@ -2642,18 +2559,12 @@ unsafe fn atomic_min<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Ord
26422559 SeqCst => intrinsics:: atomic_min ( dst, val) ,
26432560 }
26442561 }
2645- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2646- // SAFETY: the caller must uphold the safety contract for `atomic_min`
2647- unsafe {
2648- crate :: cmp:: min ( * dst, val)
2649- }
26502562}
26512563
26522564/// returns the max value (unsigned comparison)
26532565#[ inline]
26542566#[ cfg( target_has_atomic = "8" ) ]
26552567unsafe fn atomic_umax < T : Copy + crate :: cmp:: Ord > ( dst : * mut T , val : T , _order : Ordering ) -> T {
2656- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
26572568 // SAFETY: the caller must uphold the safety contract for `atomic_umax`
26582569 unsafe {
26592570 match _order {
@@ -2664,18 +2575,12 @@ unsafe fn atomic_umax<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
26642575 SeqCst => intrinsics:: atomic_umax ( dst, val) ,
26652576 }
26662577 }
2667- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2668- // SAFETY: the caller must uphold the safety contract for `atomic_umax`
2669- unsafe {
2670- crate :: cmp:: max ( * dst, val)
2671- }
26722578}
26732579
26742580/// returns the min value (unsigned comparison)
26752581#[ inline]
26762582#[ cfg( target_has_atomic = "8" ) ]
26772583unsafe fn atomic_umin < T : Copy + crate :: cmp:: Ord > ( dst : * mut T , val : T , _order : Ordering ) -> T {
2678- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
26792584 // SAFETY: the caller must uphold the safety contract for `atomic_umin`
26802585 unsafe {
26812586 match _order {
@@ -2686,11 +2591,6 @@ unsafe fn atomic_umin<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
26862591 SeqCst => intrinsics:: atomic_umin ( dst, val) ,
26872592 }
26882593 }
2689- #[ cfg( any( target_arch = "bpf" , target_arch = "sbf" ) ) ]
2690- // SAFETY: the caller must uphold the safety contract for `atomic_umin`
2691- unsafe {
2692- crate :: cmp:: min ( * dst, val)
2693- }
26942594}
26952595
26962596/// An atomic fence.
@@ -2770,16 +2670,8 @@ unsafe fn atomic_umin<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
27702670#[ inline]
27712671#[ stable( feature = "rust1" , since = "1.0.0" ) ]
27722672#[ rustc_diagnostic_item = "fence" ]
2773- #[ cfg_attr( any( target_arch = "bpf" , target_arch = "sbf" , target_arch = "wasm32" ) , allow( unused_variables) ) ]
27742673pub fn fence ( order : Ordering ) {
2775- #[ cfg( not( any( target_arch = "wasm32" , target_arch = "bpf" , target_arch = "sbf" ) ) ) ]
27762674 // SAFETY: using an atomic fence is safe.
2777- // On wasm32 and SBF it looks like fences aren't implemented in LLVM yet in that
2778- // they will cause LLVM to abort. The wasm instruction set doesn't have
2779- // fences right now. There's discussion online about the best way for tools
2780- // to conventionally implement fences at
2781- // https://github.com/WebAssembly/tool-conventions/issues/59. We should
2782- // follow that discussion and implement a solution when one comes about!
27832675 unsafe {
27842676 match order {
27852677 Acquire => intrinsics:: atomic_fence_acq ( ) ,
@@ -2860,10 +2752,7 @@ pub fn fence(order: Ordering) {
28602752#[ inline]
28612753#[ stable( feature = "compiler_fences" , since = "1.21.0" ) ]
28622754#[ rustc_diagnostic_item = "compiler_fence" ]
2863- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2864- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
28652755pub fn compiler_fence ( order : Ordering ) {
2866- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
28672756 // SAFETY: using an atomic fence is safe.
28682757 unsafe {
28692758 match order {
0 commit comments