#
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 IMM12: i64>(a: i64, b: i64) {
    68    static_assert_simm_bits!(IMM12, 12);
    69    __cacop(a, b, IMM12);
    70}
    71
    72/// Reads the CSR
    73#[inline]
    74#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    75pub unsafe fn csrrd<const IMM14: i32>() -> i64 {
    76    static_assert_uimm_bits!(IMM14, 14);
    77    __csrrd(IMM14)
    78}
    79
    80/// Writes the CSR
    81#[inline]
    82#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    83pub unsafe fn csrwr<const IMM14: i32>(a: i64) -> i64 {
    84    static_assert_uimm_bits!(IMM14, 14);
    85    __csrwr(a, IMM14)
    86}
    87
    88/// Exchanges the CSR
    89#[inline]
    90#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    91pub unsafe fn csrxchg<const IMM14: i32>(a: i64, b: i64) -> i64 {
    92    static_assert_uimm_bits!(IMM14, 14);
    93    __csrxchg(a, b, IMM14)
    94}
    95
    96/// Reads the 64-bit IO-CSR
    97#[inline]
    98#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    99pub unsafe fn iocsrrd_d(a: i32) -> i64 {
    100    __iocsrrd_d(a)
    101}
    102
    103/// Writes the 64-bit IO-CSR
    104#[inline]
    105#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    106pub unsafe fn iocsrwr_d(a: i64, b: i32) {
    107    __iocsrwr_d(a, b)
    108}
    109
    110/// Generates the less-than-or-equal asseration instruction
    111#[inline]
    112#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    113pub unsafe fn asrtle(a: i64, b: i64) {
    114    __asrtle(a, b);
    115}
    116
    117/// Generates the greater-than asseration instruction
    118#[inline]
    119#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    120pub unsafe fn asrtgt(a: i64, b: i64) {
    121    __asrtgt(a, b);
    122}
    123
    124/// Loads the page table directory entry
    125#[inline]
    126#[rustc_legacy_const_generics(1)]
    127#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    128pub unsafe fn lddir<const B: i64>(a: i64) -> i64 {
    129    __lddir(a, B)
    130}
    131
    132/// Loads the page table entry
    133#[inline]
    134#[rustc_legacy_const_generics(1)]
    135#[unstable(feature = "stdarch_loongarch", issue = "117427")]
    136pub unsafe fn ldpte<const B: i64>(a: i64) {
    137    __ldpte(a, B)
    138}