@@ -2337,10 +2337,7 @@ fn strongest_failure_ordering(order: Ordering) -> Ordering {
2337
2337
}
2338
2338
2339
2339
#[ inline]
2340
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2341
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2342
2340
unsafe fn atomic_store < T : Copy > ( dst : * mut T , val : T , order : Ordering ) {
2343
- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2344
2341
// SAFETY: the caller must uphold the safety contract for `atomic_store`.
2345
2342
unsafe {
2346
2343
match order {
@@ -2351,18 +2348,10 @@ unsafe fn atomic_store<T: Copy>(dst: *mut T, val: T, order: Ordering) {
2351
2348
AcqRel => panic ! ( "there is no such thing as an acquire/release store" ) ,
2352
2349
}
2353
2350
}
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
- }
2359
2351
}
2360
2352
2361
2353
#[ inline]
2362
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2363
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2364
2354
unsafe fn atomic_load < T : Copy > ( dst : * const T , order : Ordering ) -> T {
2365
- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2366
2355
// SAFETY: the caller must uphold the safety contract for `atomic_load`.
2367
2356
unsafe {
2368
2357
match order {
@@ -2373,19 +2362,11 @@ unsafe fn atomic_load<T: Copy>(dst: *const T, order: Ordering) -> T {
2373
2362
AcqRel => panic ! ( "there is no such thing as an acquire/release load" ) ,
2374
2363
}
2375
2364
}
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
- }
2381
2365
}
2382
2366
2383
2367
#[ inline]
2384
2368
#[ cfg( target_has_atomic = "8" ) ]
2385
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2386
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2387
2369
unsafe fn atomic_swap < T : Copy > ( dst : * mut T , val : T , order : Ordering ) -> T {
2388
- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2389
2370
// SAFETY: the caller must uphold the safety contract for `atomic_swap`.
2390
2371
unsafe {
2391
2372
match order {
@@ -2396,22 +2377,12 @@ unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
2396
2377
SeqCst => intrinsics:: atomic_xchg ( dst, val) ,
2397
2378
}
2398
2379
}
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
- }
2406
2380
}
2407
2381
2408
2382
/// Returns the previous value (like __sync_fetch_and_add).
2409
2383
#[ inline]
2410
2384
#[ cfg( target_has_atomic = "8" ) ]
2411
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2412
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2413
2385
unsafe 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" ) ) ) ]
2415
2386
// SAFETY: the caller must uphold the safety contract for `atomic_add`.
2416
2387
unsafe {
2417
2388
match order {
@@ -2422,22 +2393,12 @@ unsafe fn atomic_add<T: Copy + crate::ops::Add<Output = T>>(dst: *mut T, val: T,
2422
2393
SeqCst => intrinsics:: atomic_xadd ( dst, val) ,
2423
2394
}
2424
2395
}
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
- }
2432
2396
}
2433
2397
2434
2398
/// Returns the previous value (like __sync_fetch_and_sub).
2435
2399
#[ inline]
2436
2400
#[ cfg( target_has_atomic = "8" ) ]
2437
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2438
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2439
2401
unsafe 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" ) ) ) ]
2441
2402
// SAFETY: the caller must uphold the safety contract for `atomic_sub`.
2442
2403
unsafe {
2443
2404
match order {
@@ -2448,58 +2409,35 @@ unsafe fn atomic_sub<T: Copy + crate::ops::Sub<Output = T>>(dst: *mut T, val: T,
2448
2409
SeqCst => intrinsics:: atomic_xsub ( dst, val) ,
2449
2410
}
2450
2411
}
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
- }
2458
2412
}
2459
2413
2460
2414
#[ inline]
2461
2415
#[ cfg( target_has_atomic = "8" ) ]
2462
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2463
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2464
2416
unsafe fn atomic_compare_exchange < T : Copy + crate :: cmp:: PartialEq > (
2465
2417
dst : * mut T ,
2466
2418
old : T ,
2467
2419
new : T ,
2468
2420
success : Ordering ,
2469
2421
failure : Ordering ,
2470
2422
) -> 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" ) ) ]
2493
2423
// 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" ) ,
2501
2438
}
2502
- }
2439
+ } ;
2440
+ if ok { Ok ( val) } else { Err ( val) }
2503
2441
}
2504
2442
2505
2443
#[ inline]
@@ -2511,38 +2449,24 @@ unsafe fn atomic_compare_exchange_weak<T: Copy + crate::cmp::PartialEq>(
2511
2449
_success : Ordering ,
2512
2450
_failure : Ordering ,
2513
2451
) -> 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" ) ) ]
2536
2452
// 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" ) ,
2544
2467
}
2545
- }
2468
+ } ;
2469
+ if ok { Ok ( val) } else { Err ( val) }
2546
2470
}
2547
2471
2548
2472
#[ inline]
@@ -2609,7 +2533,6 @@ unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
2609
2533
#[ inline]
2610
2534
#[ cfg( target_has_atomic = "8" ) ]
2611
2535
unsafe 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" ) ) ) ]
2613
2536
// SAFETY: the caller must uphold the safety contract for `atomic_max`
2614
2537
unsafe {
2615
2538
match _order {
@@ -2620,18 +2543,12 @@ unsafe fn atomic_max<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Ord
2620
2543
SeqCst => intrinsics:: atomic_max ( dst, val) ,
2621
2544
}
2622
2545
}
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
- }
2628
2546
}
2629
2547
2630
2548
/// returns the min value (signed comparison)
2631
2549
#[ inline]
2632
2550
#[ cfg( target_has_atomic = "8" ) ]
2633
2551
unsafe 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" ) ) ) ]
2635
2552
// SAFETY: the caller must uphold the safety contract for `atomic_min`
2636
2553
unsafe {
2637
2554
match _order {
@@ -2642,18 +2559,12 @@ unsafe fn atomic_min<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Ord
2642
2559
SeqCst => intrinsics:: atomic_min ( dst, val) ,
2643
2560
}
2644
2561
}
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
- }
2650
2562
}
2651
2563
2652
2564
/// returns the max value (unsigned comparison)
2653
2565
#[ inline]
2654
2566
#[ cfg( target_has_atomic = "8" ) ]
2655
2567
unsafe 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" ) ) ) ]
2657
2568
// SAFETY: the caller must uphold the safety contract for `atomic_umax`
2658
2569
unsafe {
2659
2570
match _order {
@@ -2664,18 +2575,12 @@ unsafe fn atomic_umax<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
2664
2575
SeqCst => intrinsics:: atomic_umax ( dst, val) ,
2665
2576
}
2666
2577
}
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
- }
2672
2578
}
2673
2579
2674
2580
/// returns the min value (unsigned comparison)
2675
2581
#[ inline]
2676
2582
#[ cfg( target_has_atomic = "8" ) ]
2677
2583
unsafe 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" ) ) ) ]
2679
2584
// SAFETY: the caller must uphold the safety contract for `atomic_umin`
2680
2585
unsafe {
2681
2586
match _order {
@@ -2686,11 +2591,6 @@ unsafe fn atomic_umin<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
2686
2591
SeqCst => intrinsics:: atomic_umin ( dst, val) ,
2687
2592
}
2688
2593
}
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
- }
2694
2594
}
2695
2595
2696
2596
/// An atomic fence.
@@ -2770,16 +2670,8 @@ unsafe fn atomic_umin<T: Copy + crate::cmp::Ord>(dst: *mut T, val: T, _order: Or
2770
2670
#[ inline]
2771
2671
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2772
2672
#[ rustc_diagnostic_item = "fence" ]
2773
- #[ cfg_attr( any( target_arch = "bpf" , target_arch = "sbf" , target_arch = "wasm32" ) , allow( unused_variables) ) ]
2774
2673
pub fn fence ( order : Ordering ) {
2775
- #[ cfg( not( any( target_arch = "wasm32" , target_arch = "bpf" , target_arch = "sbf" ) ) ) ]
2776
2674
// 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!
2783
2675
unsafe {
2784
2676
match order {
2785
2677
Acquire => intrinsics:: atomic_fence_acq ( ) ,
@@ -2860,10 +2752,7 @@ pub fn fence(order: Ordering) {
2860
2752
#[ inline]
2861
2753
#[ stable( feature = "compiler_fences" , since = "1.21.0" ) ]
2862
2754
#[ rustc_diagnostic_item = "compiler_fence" ]
2863
- #[ cfg_attr( target_arch = "bpf" , allow( unused_variables) ) ]
2864
- #[ cfg_attr( target_arch = "sbf" , allow( unused_variables) ) ]
2865
2755
pub fn compiler_fence ( order : Ordering ) {
2866
- #[ cfg( all( not( target_arch = "bpf" ) , not( target_arch = "sbf" ) ) ) ]
2867
2756
// SAFETY: using an atomic fence is safe.
2868
2757
unsafe {
2869
2758
match order {
0 commit comments