ex.rs - source
Description: Source of the Rust file `library/core/src/../../stdarch/crates/core_arch/src/acle/ex.rs`.
Keywords: rust, rustlang, rust-lang

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117

    // Reference: Section 5.4.4 "LDREX / STREX" of ACLE

    /// Removes the exclusive lock created by LDREX
    // Supported: v6, v6K, v7-M, v7-A, v7-R
    // Not supported: v5, v6-M
    // NOTE: there's no dedicated CLREX instruction in v6 (<v6k); to clear the exclusive monitor users
    // have to do a dummy STREX operation
    #[cfg(any(
        all(target_feature = "v6k", not(target_feature = "mclass")), // excludes v6-M
        all(target_feature = "v7", target_feature = "mclass"), // v7-M
    ))]
    pub unsafe fn __clrex() {
        extern "C" {
            #[link_name = "llvm.arm.clrex"]
            fn clrex();
        }

        clrex()
    }

    /// Executes a exclusive LDR instruction for 8 bit value.
    // Supported: v6K, v7-M, v7-A, v7-R
    // Not supported: v5, v6, v6-M
    #[cfg(
        target_feature = "v6k", // includes v7-M but excludes v6-M
    )]
    pub unsafe fn __ldrexb(p: *const u8) -> u8 {
        extern "C" {
            #[link_name = "llvm.arm.ldrex.p0i8"]
            fn ldrex8(p: *const u8) -> u32;
        }

        ldrex8(p) as u8
    }

    /// Executes a exclusive LDR instruction for 16 bit value.
    // Supported: v6K, v7-M, v7-A, v7-R, v8
    // Not supported: v5, v6, v6-M
    #[cfg(
        target_feature = "v6k", // includes v7-M but excludes v6-M
    )]
    pub unsafe fn __ldrexh(p: *const u16) -> u16 {
        extern "C" {
            #[link_name = "llvm.arm.ldrex.p0i16"]
            fn ldrex16(p: *const u16) -> u32;
        }

        ldrex16(p) as u16
    }

    /// Executes a exclusive LDR instruction for 32 bit value.
    // Supported: v6, v7-M, v6K, v7-A, v7-R, v8
    // Not supported: v5, v6-M
    #[cfg(any(
        all(target_feature = "v6", not(target_feature = "mclass")), // excludes v6-M
        all(target_feature = "v7", target_feature = "mclass"), // v7-M
    ))]
    pub unsafe fn __ldrex(p: *const u32) -> u32 {
        extern "C" {
            #[link_name = "llvm.arm.ldrex.p0i32"]
            fn ldrex32(p: *const u32) -> u32;
        }

        ldrex32(p)
    }

    /// Executes a exclusive STR instruction for 8 bit values
    ///
    /// Returns `0` if the operation succeeded, or `1` if it failed
    // supported: v6K, v7-M, v7-A, v7-R
    // Not supported: v5, v6, v6-M
    #[cfg(
        target_feature = "v6k", // includes v7-M but excludes v6-M
    )]
    pub unsafe fn __strexb(value: u32, addr: *mut u8) -> u32 {
        extern "C" {
            #[link_name = "llvm.arm.strex.p0i8"]
            fn strex8(value: u32, addr: *mut u8) -> u32;
        }

        strex8(value, addr)
    }

    /// Executes a exclusive STR instruction for 16 bit values
    ///
    /// Returns `0` if the operation succeeded, or `1` if it failed
    // Supported: v6K, v7-M, v7-A, v7-R, v8
    // Not supported: v5, v6, v6-M
    #[cfg(
        target_feature = "v6k", // includes v7-M but excludes v6-M
    )]
    pub unsafe fn __strexh(value: u16, addr: *mut u16) -> u32 {
        extern "C" {
            #[link_name = "llvm.arm.strex.p0i16"]
            fn strex16(value: u32, addr: *mut u16) -> u32;
        }

        strex16(value as u32, addr)
    }

    /// Executes a exclusive STR instruction for 32 bit values
    ///
    /// Returns `0` if the operation succeeded, or `1` if it failed
    // Supported: v6, v7-M, v6K, v7-A, v7-R, v8
    // Not supported: v5, v6-M
    #[cfg(any(
        all(target_feature = "v6", not(target_feature = "mclass")), // excludes v6-M
        all(target_feature = "v7", target_feature = "mclass"), // v7-M
    ))]
    pub unsafe fn __strex(value: u32, addr: *mut u32) -> u32 {
        extern "C" {
            #[link_name = "llvm.arm.strex.p0i32"]
            fn strex32(value: u32, addr: *mut u32) -> u32;
        }

        strex32(value, addr)
    }