mod.rs - source
Description: Source of the Rust file `library/core/src/../../stdarch/crates/core_arch/src/loongarch64/mod.rs`.

#
core/stdarch/crates/core_arch/src/loongarch64/
mod.rs

    1//! `LoongArch64` intrinsics
    2
    3mod lasx;
    4mod lsx;
    5
    6#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    7pub use self::lasx::*;
    8#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    9pub use self::lsx::*;
    10
    11use crate::arch::asm;
    12
    13/// Reads the 64-bit stable counter value and the counter ID
    14#[inline]
    15#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    16pub fn rdtime_d() -> (i64, isize) {
    17    let (val, tid): (i64, isize);
    18    unsafe { asm!("rdtime.d {}, {}", out(reg) val, out(reg) tid, options(readonly, nostack)) };
    19    (val, tid)
    20}
    21
    22#[allow(improper_ctypes)]
    23unsafe extern "unadjusted" {
    24    #[link_name = "llvm.loongarch.crc.w.d.w"]
    25    fn __crc_w_d_w(a: i64, b: i32) -> i32;
    26    #[link_name = "llvm.loongarch.crcc.w.d.w"]
    27    fn __crcc_w_d_w(a: i64, b: i32) -> i32;
    28    #[link_name = "llvm.loongarch.cacop.d"]
    29    fn __cacop(a: i64, b: i64, c: i64);
    30    #[link_name = "llvm.loongarch.csrrd.d"]
    31    fn __csrrd(a: i32) -> i64;
    32    #[link_name = "llvm.loongarch.csrwr.d"]
    33    fn __csrwr(a: i64, b: i32) -> i64;
    34    #[link_name = "llvm.loongarch.csrxchg.d"]
    35    fn __csrxchg(a: i64, b: i64, c: i32) -> i64;
    36    #[link_name = "llvm.loongarch.iocsrrd.d"]
    37    fn __iocsrrd_d(a: i32) -> i64;
    38    #[link_name = "llvm.loongarch.iocsrwr.d"]
    39    fn __iocsrwr_d(a: i64, b: i32);
    40    #[link_name = "llvm.loongarch.asrtle.d"]
    41    fn __asrtle(a: i64, b: i64);
    42    #[link_name = "llvm.loongarch.asrtgt.d"]
    43    fn __asrtgt(a: i64, b: i64);
    44    #[link_name = "llvm.loongarch.lddir.d"]
    45    fn __lddir(a: i64, b: i64) -> i64;
    46    #[link_name = "llvm.loongarch.ldpte.d"]
    47    fn __ldpte(a: i64, b: i64);
    48}
    49
    50/// Calculate the CRC value using the IEEE 802.3 polynomial (0xEDB88320)
    51#[inline]
    52#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    53pub fn crc_w_d_w(a: i64, b: i32) -> i32 {
    54    unsafe { __crc_w_d_w(a, b) }
    55}
    56
    57/// Calculate the CRC value using the Castagnoli polynomial (0x82F63B78)
    58#[inline]
    59#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    60pub fn crcc_w_d_w(a: i64, b: i32) -> i32 {
    61    unsafe { __crcc_w_d_w(a, b) }
    62}
    63
    64/// Generates the cache operation instruction
    65#[inline]
    66#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    67pub unsafe fn cacop<const IMM5: i64, const IMM_S12: i64>(b: i64) {
    68    static_assert_uimm_bits!(IMM5, 5);
    69    static_assert_simm_bits!(IMM_S12, 12);
    70    __cacop(IMM5, b, IMM_S12);
    71}
    72
    73/// Reads the CSR
    74#[inline]
    75#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    76pub unsafe fn csrrd<const IMM14: i32>() -> i64 {
    77    static_assert_uimm_bits!(IMM14, 14);
    78    __csrrd(IMM14)
    79}
    80
    81/// Writes the CSR
    82#[inline]
    83#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    84pub unsafe fn csrwr<const IMM14: i32>(a: i64) -> i64 {
    85    static_assert_uimm_bits!(IMM14, 14);
    86    __csrwr(a, IMM14)
    87}
    88
    89/// Exchanges the CSR
    90#[inline]
    91#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    92pub unsafe fn csrxchg<const IMM14: i32>(a: i64, b: i64) -> i64 {
    93    static_assert_uimm_bits!(IMM14, 14);
    94    __csrxchg(a, b, IMM14)
    95}
    96
    97/// Reads the 64-bit IO-CSR
    98#[inline]
    99#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    100pub unsafe fn iocsrrd_d(a: i32) -> i64 {
    101    __iocsrrd_d(a)
    102}
    103
    104/// Writes the 64-bit IO-CSR
    105#[inline]
    106#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    107pub unsafe fn iocsrwr_d(a: i64, b: i32) {
    108    __iocsrwr_d(a, b)
    109}
    110
    111/// Generates the less-than-or-equal asseration instruction
    112#[inline]
    113#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    114pub unsafe fn asrtle(a: i64, b: i64) {
    115    __asrtle(a, b);
    116}
    117
    118/// Generates the greater-than asseration instruction
    119#[inline]
    120#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    121pub unsafe fn asrtgt(a: i64, b: i64) {
    122    __asrtgt(a, b);
    123}
    124
    125/// Loads the page table directory entry
    126#[inline]
    127#[rustc_legacy_const_generics(1)]
    128#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    129pub unsafe fn lddir<const IMM8: i64>(a: i64) -> i64 {
    130    static_assert_uimm_bits!(IMM8, 8);
    131    __lddir(a, IMM8)
    132}
    133
    134/// Loads the page table entry
    135#[inline]
    136#[rustc_legacy_const_generics(1)]
    137#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    138pub unsafe fn ldpte<const IMM8: i64>(a: i64) {
    139    static_assert_uimm_bits!(IMM8, 8);
    140    __ldpte(a, IMM8)
    141}