//! LoongArch64 LASX intrinsics - intrinsics::simd implementation

use super::super::{simd as ls, simd::*, *};
use crate::core_arch::simd::{self as cs, *};
use crate::intrinsics::simd as is;
use crate::mem::transmute;

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickev_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            0, 2, 4, 6, 8, 10, 12, 14, 32, 34, 36, 38, 40, 42, 44, 46,
            16, 18, 20, 22, 24, 26, 28, 30, 48, 50, 52, 54, 56, 58, 60, 62
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickev_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 4, 2, 6])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickev_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 2, 8, 10, 4, 6, 12, 14])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickev_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 2, 4, 6, 16, 18, 20, 22, 8, 10, 12, 14, 24, 26, 28, 30])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickod_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            1, 3, 5, 7, 9, 11, 13, 15, 33, 35, 37, 39, 41, 43, 45, 47,
            17, 19, 21, 23, 25, 27, 29, 31, 49, 51, 53, 55, 57, 59, 61, 63
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickod_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 5, 3, 7])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickod_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 3, 9, 11, 5, 7, 13, 15])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_pickod_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 3, 5, 7, 17, 19, 21, 23, 9, 11, 13, 15, 25, 27, 29, 31])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvh_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            8, 40, 9, 41, 10, 42, 11, 43, 12, 44, 13, 45, 14, 46, 15, 47,
            24, 56, 25, 57, 26, 58, 27, 59, 28, 60, 29, 61, 30, 62, 31, 63
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvh_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [4, 20, 5, 21, 6, 22, 7, 23, 12, 28, 13, 29, 14, 30, 15, 31])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvh_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [2, 10, 3, 11, 6, 14, 7, 15])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvh_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 5, 3, 7])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvl_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            0, 32, 1, 33, 2, 34, 3, 35, 4, 36, 5, 37, 6, 38, 7, 39,
            16, 48, 17, 49, 18, 50, 19, 51, 20, 52, 21, 53, 22, 54, 23, 55
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvl_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 16, 1, 17, 2, 18, 3, 19, 8, 24, 9, 25, 10, 26, 11, 27])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvl_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 8, 1, 9, 4, 12, 5, 13])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_ilvl_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 4, 2, 6])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replvei_b<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
            I + 16, I + 16, I + 16, I + 16, I + 16, I + 16, I + 16, I + 16,
            I + 16, I + 16, I + 16, I + 16, I + 16, I + 16, I + 16, I + 16
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replvei_h<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            I, I, I, I, I, I, I, I,
            I + 8, I + 8, I + 8, I + 8, I + 8, I + 8, I + 8, I + 8
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replvei_w<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [I, I, I, I, I + 4, I + 4, I + 4, I + 4])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replvei_d<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [I, I, I + 2, I + 2])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replve0_b<T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replve0_h<T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replve0_w<T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [0, 0, 0, 0, 0, 0, 0, 0])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replve0_d<T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [0, 0, 0, 0])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_replve0_q<T: Copy>(a: T) -> T {
    simd_shuffle!(a, a, [0, 1, 0, 1])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packev_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            0, 32, 2, 34, 4, 36, 6, 38, 8, 40, 10, 42, 12, 44, 14, 46,
            16, 48, 18, 50, 20, 52, 22, 54, 24, 56, 26, 58, 28, 60, 30, 62
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packev_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packev_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 8, 2, 10, 4, 12, 6, 14])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packev_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [0, 4, 2, 6])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packod_b<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(
        b,
        a,
        [
            1, 33, 3, 35, 5, 37, 7, 39, 9, 41, 11, 43, 13, 45, 15, 47,
            17, 49, 19, 51, 21, 53, 23, 55, 25, 57, 27, 59, 29, 61, 31, 63
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packod_h<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packod_w<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 9, 3, 11, 5, 13, 7, 15])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_packod_d<T: Copy>(a: T, b: T) -> T {
    simd_shuffle!(b, a, [1, 5, 3, 7])
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_shuf4i_b<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            ((I >> 0) & 3) + 0, ((I >> 2) & 3) + 0, ((I >> 4) & 3) + 0, ((I >> 6) & 3) + 0,
            ((I >> 0) & 3) + 4, ((I >> 2) & 3) + 4, ((I >> 4) & 3) + 4, ((I >> 6) & 3) + 4,
            ((I >> 0) & 3) + 8, ((I >> 2) & 3) + 8, ((I >> 4) & 3) + 8, ((I >> 6) & 3) + 8,
            ((I >> 0) & 3) + 12, ((I >> 2) & 3) + 12, ((I >> 4) & 3) + 12, ((I >> 6) & 3) + 12,
            ((I >> 0) & 3) + 16, ((I >> 2) & 3) + 16, ((I >> 4) & 3) + 16, ((I >> 6) & 3) + 16,
            ((I >> 0) & 3) + 20, ((I >> 2) & 3) + 20, ((I >> 4) & 3) + 20, ((I >> 6) & 3) + 20,
            ((I >> 0) & 3) + 24, ((I >> 2) & 3) + 24, ((I >> 4) & 3) + 24, ((I >> 6) & 3) + 24,
            ((I >> 0) & 3) + 28, ((I >> 2) & 3) + 28, ((I >> 4) & 3) + 28, ((I >> 6) & 3) + 28
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_shuf4i_h<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            ((I >> 0) & 3) + 0, ((I >> 2) & 3) + 0, ((I >> 4) & 3) + 0, ((I >> 6) & 3) + 0,
            ((I >> 0) & 3) + 4, ((I >> 2) & 3) + 4, ((I >> 4) & 3) + 4, ((I >> 6) & 3) + 4,
            ((I >> 0) & 3) + 8, ((I >> 2) & 3) + 8, ((I >> 4) & 3) + 8, ((I >> 6) & 3) + 8,
            ((I >> 0) & 3) + 12, ((I >> 2) & 3) + 12, ((I >> 4) & 3) + 12, ((I >> 6) & 3) + 12,
        ]
    )
}

#[inline(always)]
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
const unsafe fn simd_shuf4i_w<const I: u32, T: Copy>(a: T) -> T {
    simd_shuffle!(
        a,
        a,
        [
            ((I >> 0) & 3) + 0, ((I >> 2) & 3) + 0, ((I >> 4) & 3) + 0, ((I >> 6) & 3) + 0,
            ((I >> 0) & 3) + 4, ((I >> 2) & 3) + 4, ((I >> 4) & 3) + 4, ((I >> 6) & 3) + 4
        ]
    )
}

impl_vv!("lasx", lasx_xvpcnt_b, is::simd_ctpop, m256i, i8x32);
impl_vv!("lasx", lasx_xvpcnt_h, is::simd_ctpop, m256i, i16x16);
impl_vv!("lasx", lasx_xvpcnt_w, is::simd_ctpop, m256i, i32x8);
impl_vv!("lasx", lasx_xvpcnt_d, is::simd_ctpop, m256i, i64x4);
impl_vv!("lasx", lasx_xvclz_b, is::simd_ctlz, m256i, i8x32);
impl_vv!("lasx", lasx_xvclz_h, is::simd_ctlz, m256i, i16x16);
impl_vv!("lasx", lasx_xvclz_w, is::simd_ctlz, m256i, i32x8);
impl_vv!("lasx", lasx_xvclz_d, is::simd_ctlz, m256i, i64x4);
impl_vv!("lasx", lasx_xvneg_b, is::simd_neg, m256i, i8x32);
impl_vv!("lasx", lasx_xvneg_h, is::simd_neg, m256i, i16x16);
impl_vv!("lasx", lasx_xvneg_w, is::simd_neg, m256i, i32x8);
impl_vv!("lasx", lasx_xvneg_d, is::simd_neg, m256i, i64x4);
impl_vv!("lasx", lasx_xvfsqrt_s, is::simd_fsqrt, m256, f32x8);
impl_vv!("lasx", lasx_xvfsqrt_d, is::simd_fsqrt, m256d, f64x4);
impl_vv!("lasx", lasx_xvreplve0_b, simd_replve0_b, m256i, i8x32);
impl_vv!("lasx", lasx_xvreplve0_h, simd_replve0_h, m256i, i16x16);
impl_vv!("lasx", lasx_xvreplve0_w, simd_replve0_w, m256i, i32x8);
impl_vv!("lasx", lasx_xvreplve0_d, simd_replve0_d, m256i, i64x4);
impl_vv!("lasx", lasx_xvreplve0_q, simd_replve0_q, m256i, i64x4);

impl_gv!("lasx", lasx_xvreplgr2vr_b, ls::simd_splat, m256i, i8x32, i32);
impl_gv!("lasx", lasx_xvreplgr2vr_h, ls::simd_splat, m256i, i16x16, i32);
impl_gv!("lasx", lasx_xvreplgr2vr_w, ls::simd_splat, m256i, i32x8, i32);
impl_gv!("lasx", lasx_xvreplgr2vr_d, ls::simd_splat, m256i, i64x4, i64);

impl_sv!("lasx", lasx_xvrepli_b, ls::simd_splat, m256i, i8x32, 10);
impl_sv!("lasx", lasx_xvrepli_h, ls::simd_splat, m256i, i16x16, 10);
impl_sv!("lasx", lasx_xvrepli_w, ls::simd_splat, m256i, i32x8, 10);
impl_sv!("lasx", lasx_xvrepli_d, ls::simd_splat, m256i, i64x4, 10);

impl_vvv!("lasx", lasx_xvadd_b, is::simd_add, m256i, i8x32);
impl_vvv!("lasx", lasx_xvadd_h, is::simd_add, m256i, i16x16);
impl_vvv!("lasx", lasx_xvadd_w, is::simd_add, m256i, i32x8);
impl_vvv!("lasx", lasx_xvadd_d, is::simd_add, m256i, i64x4);
impl_vvv!("lasx", lasx_xvsub_b, is::simd_sub, m256i, i8x32);
impl_vvv!("lasx", lasx_xvsub_h, is::simd_sub, m256i, i16x16);
impl_vvv!("lasx", lasx_xvsub_w, is::simd_sub, m256i, i32x8);
impl_vvv!("lasx", lasx_xvsub_d, is::simd_sub, m256i, i64x4);
impl_vvv!("lasx", lasx_xvmax_b, cs::simd_imax, m256i, i8x32);
impl_vvv!("lasx", lasx_xvmax_h, cs::simd_imax, m256i, i16x16);
impl_vvv!("lasx", lasx_xvmax_w, cs::simd_imax, m256i, i32x8);
impl_vvv!("lasx", lasx_xvmax_d, cs::simd_imax, m256i, i64x4);
impl_vvv!("lasx", lasx_xvmax_bu, cs::simd_imax, m256i, u8x32);
impl_vvv!("lasx", lasx_xvmax_hu, cs::simd_imax, m256i, u16x16);
impl_vvv!("lasx", lasx_xvmax_wu, cs::simd_imax, m256i, u32x8);
impl_vvv!("lasx", lasx_xvmax_du, cs::simd_imax, m256i, u64x4);
impl_vvv!("lasx", lasx_xvmin_b, cs::simd_imin, m256i, i8x32);
impl_vvv!("lasx", lasx_xvmin_h, cs::simd_imin, m256i, i16x16);
impl_vvv!("lasx", lasx_xvmin_w, cs::simd_imin, m256i, i32x8);
impl_vvv!("lasx", lasx_xvmin_d, cs::simd_imin, m256i, i64x4);
impl_vvv!("lasx", lasx_xvmin_bu, cs::simd_imin, m256i, u8x32);
impl_vvv!("lasx", lasx_xvmin_hu, cs::simd_imin, m256i, u16x16);
impl_vvv!("lasx", lasx_xvmin_wu, cs::simd_imin, m256i, u32x8);
impl_vvv!("lasx", lasx_xvmin_du, cs::simd_imin, m256i, u64x4);
impl_vvv!("lasx", lasx_xvseq_b, is::simd_eq, m256i, i8x32);
impl_vvv!("lasx", lasx_xvseq_h, is::simd_eq, m256i, i16x16);
impl_vvv!("lasx", lasx_xvseq_w, is::simd_eq, m256i, i32x8);
impl_vvv!("lasx", lasx_xvseq_d, is::simd_eq, m256i, i64x4);
impl_vvv!("lasx", lasx_xvslt_b, is::simd_lt, m256i, i8x32);
impl_vvv!("lasx", lasx_xvslt_h, is::simd_lt, m256i, i16x16);
impl_vvv!("lasx", lasx_xvslt_w, is::simd_lt, m256i, i32x8);
impl_vvv!("lasx", lasx_xvslt_d, is::simd_lt, m256i, i64x4);
impl_vvv!("lasx", lasx_xvslt_bu, is::simd_lt, m256i, u8x32);
impl_vvv!("lasx", lasx_xvslt_hu, is::simd_lt, m256i, u16x16);
impl_vvv!("lasx", lasx_xvslt_wu, is::simd_lt, m256i, u32x8);
impl_vvv!("lasx", lasx_xvslt_du, is::simd_lt, m256i, u64x4);
impl_vvv!("lasx", lasx_xvsle_b, is::simd_le, m256i, i8x32);
impl_vvv!("lasx", lasx_xvsle_h, is::simd_le, m256i, i16x16);
impl_vvv!("lasx", lasx_xvsle_w, is::simd_le, m256i, i32x8);
impl_vvv!("lasx", lasx_xvsle_d, is::simd_le, m256i, i64x4);
impl_vvv!("lasx", lasx_xvsle_bu, is::simd_le, m256i, u8x32);
impl_vvv!("lasx", lasx_xvsle_hu, is::simd_le, m256i, u16x16);
impl_vvv!("lasx", lasx_xvsle_wu, is::simd_le, m256i, u32x8);
impl_vvv!("lasx", lasx_xvsle_du, is::simd_le, m256i, u64x4);
impl_vvv!("lasx", lasx_xvmul_b, is::simd_mul, m256i, i8x32);
impl_vvv!("lasx", lasx_xvmul_h, is::simd_mul, m256i, i16x16);
impl_vvv!("lasx", lasx_xvmul_w, is::simd_mul, m256i, i32x8);
impl_vvv!("lasx", lasx_xvmul_d, is::simd_mul, m256i, i64x4);
impl_vvv!("lasx", lasx_xvdiv_b, is::simd_div, m256i, i8x32);
impl_vvv!("lasx", lasx_xvdiv_h, is::simd_div, m256i, i16x16);
impl_vvv!("lasx", lasx_xvdiv_w, is::simd_div, m256i, i32x8);
impl_vvv!("lasx", lasx_xvdiv_d, is::simd_div, m256i, i64x4);
impl_vvv!("lasx", lasx_xvdiv_bu, is::simd_div, m256i, u8x32);
impl_vvv!("lasx", lasx_xvdiv_hu, is::simd_div, m256i, u16x16);
impl_vvv!("lasx", lasx_xvdiv_wu, is::simd_div, m256i, u32x8);
impl_vvv!("lasx", lasx_xvdiv_du, is::simd_div, m256i, u64x4);
impl_vvv!("lasx", lasx_xvmod_b, is::simd_rem, m256i, i8x32);
impl_vvv!("lasx", lasx_xvmod_h, is::simd_rem, m256i, i16x16);
impl_vvv!("lasx", lasx_xvmod_w, is::simd_rem, m256i, i32x8);
impl_vvv!("lasx", lasx_xvmod_d, is::simd_rem, m256i, i64x4);
impl_vvv!("lasx", lasx_xvmod_bu, is::simd_rem, m256i, u8x32);
impl_vvv!("lasx", lasx_xvmod_hu, is::simd_rem, m256i, u16x16);
impl_vvv!("lasx", lasx_xvmod_wu, is::simd_rem, m256i, u32x8);
impl_vvv!("lasx", lasx_xvmod_du, is::simd_rem, m256i, u64x4);
impl_vvv!("lasx", lasx_xvand_v, is::simd_and, m256i, u8x32);
impl_vvv!("lasx", lasx_xvandn_v, ls::simd_andn, m256i, u8x32);
impl_vvv!("lasx", lasx_xvor_v, is::simd_or, m256i, u8x32);
impl_vvv!("lasx", lasx_xvorn_v, ls::simd_orn, m256i, u8x32);
impl_vvv!("lasx", lasx_xvnor_v, ls::simd_nor, m256i, u8x32);
impl_vvv!("lasx", lasx_xvxor_v, is::simd_xor, m256i, u8x32);
impl_vvv!("lasx", lasx_xvfadd_s, is::simd_add, m256, f32x8);
impl_vvv!("lasx", lasx_xvfadd_d, is::simd_add, m256d, f64x4);
impl_vvv!("lasx", lasx_xvfsub_s, is::simd_sub, m256, f32x8);
impl_vvv!("lasx", lasx_xvfsub_d, is::simd_sub, m256d, f64x4);
impl_vvv!("lasx", lasx_xvfmul_s, is::simd_mul, m256, f32x8);
impl_vvv!("lasx", lasx_xvfmul_d, is::simd_mul, m256d, f64x4);
impl_vvv!("lasx", lasx_xvfdiv_s, is::simd_div, m256, f32x8);
impl_vvv!("lasx", lasx_xvfdiv_d, is::simd_div, m256d, f64x4);
impl_vvv!("lasx", lasx_xvsll_b, ls::simd_shl, m256i, i8x32);
impl_vvv!("lasx", lasx_xvsll_h, ls::simd_shl, m256i, i16x16);
impl_vvv!("lasx", lasx_xvsll_w, ls::simd_shl, m256i, i32x8);
impl_vvv!("lasx", lasx_xvsll_d, ls::simd_shl, m256i, i64x4);
impl_vvv!("lasx", lasx_xvsra_b, ls::simd_shr, m256i, i8x32);
impl_vvv!("lasx", lasx_xvsra_h, ls::simd_shr, m256i, i16x16);
impl_vvv!("lasx", lasx_xvsra_w, ls::simd_shr, m256i, i32x8);
impl_vvv!("lasx", lasx_xvsra_d, ls::simd_shr, m256i, i64x4);
impl_vvv!("lasx", lasx_xvsrl_b, ls::simd_shr, m256i, u8x32);
impl_vvv!("lasx", lasx_xvsrl_h, ls::simd_shr, m256i, u16x16);
impl_vvv!("lasx", lasx_xvsrl_w, ls::simd_shr, m256i, u32x8);
impl_vvv!("lasx", lasx_xvsrl_d, ls::simd_shr, m256i, u64x4);
impl_vvv!("lasx", lasx_xvbitclr_b, ls::simd_bitclr, m256i, u8x32);
impl_vvv!("lasx", lasx_xvbitclr_h, ls::simd_bitclr, m256i, u16x16);
impl_vvv!("lasx", lasx_xvbitclr_w, ls::simd_bitclr, m256i, u32x8);
impl_vvv!("lasx", lasx_xvbitclr_d, ls::simd_bitclr, m256i, u64x4);
impl_vvv!("lasx", lasx_xvbitset_b, ls::simd_bitset, m256i, u8x32);
impl_vvv!("lasx", lasx_xvbitset_h, ls::simd_bitset, m256i, u16x16);
impl_vvv!("lasx", lasx_xvbitset_w, ls::simd_bitset, m256i, u32x8);
impl_vvv!("lasx", lasx_xvbitset_d, ls::simd_bitset, m256i, u64x4);
impl_vvv!("lasx", lasx_xvbitrev_b, ls::simd_bitrev, m256i, u8x32);
impl_vvv!("lasx", lasx_xvbitrev_h, ls::simd_bitrev, m256i, u16x16);
impl_vvv!("lasx", lasx_xvbitrev_w, ls::simd_bitrev, m256i, u32x8);
impl_vvv!("lasx", lasx_xvbitrev_d, ls::simd_bitrev, m256i, u64x4);
impl_vvv!("lasx", lasx_xvsadd_b, is::simd_saturating_add, m256i, i8x32);
impl_vvv!("lasx", lasx_xvsadd_h, is::simd_saturating_add, m256i, i16x16);
impl_vvv!("lasx", lasx_xvsadd_w, is::simd_saturating_add, m256i, i32x8);
impl_vvv!("lasx", lasx_xvsadd_d, is::simd_saturating_add, m256i, i64x4);
impl_vvv!("lasx", lasx_xvsadd_bu, is::simd_saturating_add, m256i, u8x32);
impl_vvv!("lasx", lasx_xvsadd_hu, is::simd_saturating_add, m256i, u16x16);
impl_vvv!("lasx", lasx_xvsadd_wu, is::simd_saturating_add, m256i, u32x8);
impl_vvv!("lasx", lasx_xvsadd_du, is::simd_saturating_add, m256i, u64x4);
impl_vvv!("lasx", lasx_xvssub_b, is::simd_saturating_sub, m256i, i8x32);
impl_vvv!("lasx", lasx_xvssub_h, is::simd_saturating_sub, m256i, i16x16);
impl_vvv!("lasx", lasx_xvssub_w, is::simd_saturating_sub, m256i, i32x8);
impl_vvv!("lasx", lasx_xvssub_d, is::simd_saturating_sub, m256i, i64x4);
impl_vvv!("lasx", lasx_xvssub_bu, is::simd_saturating_sub, m256i, u8x32);
impl_vvv!("lasx", lasx_xvssub_hu, is::simd_saturating_sub, m256i, u16x16);
impl_vvv!("lasx", lasx_xvssub_wu, is::simd_saturating_sub, m256i, u32x8);
impl_vvv!("lasx", lasx_xvssub_du, is::simd_saturating_sub, m256i, u64x4);
impl_vvv!("lasx", lasx_xvadda_b, ls::simd_adda, m256i, i8x32);
impl_vvv!("lasx", lasx_xvadda_h, ls::simd_adda, m256i, i16x16);
impl_vvv!("lasx", lasx_xvadda_w, ls::simd_adda, m256i, i32x8);
impl_vvv!("lasx", lasx_xvadda_d, ls::simd_adda, m256i, i64x4);
impl_vvv!("lasx", lasx_xvabsd_b, ls::simd_absd, m256i, i8x32);
impl_vvv!("lasx", lasx_xvabsd_h, ls::simd_absd, m256i, i16x16);
impl_vvv!("lasx", lasx_xvabsd_w, ls::simd_absd, m256i, i32x8);
impl_vvv!("lasx", lasx_xvabsd_d, ls::simd_absd, m256i, i64x4);
impl_vvv!("lasx", lasx_xvabsd_bu, ls::simd_absd, m256i, u8x32);
impl_vvv!("lasx", lasx_xvabsd_hu, ls::simd_absd, m256i, u16x16);
impl_vvv!("lasx", lasx_xvabsd_wu, ls::simd_absd, m256i, u32x8);
impl_vvv!("lasx", lasx_xvabsd_du, ls::simd_absd, m256i, u64x4);
impl_vvv!("lasx", lasx_xvpickev_b, simd_pickev_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvpickev_h, simd_pickev_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvpickev_w, simd_pickev_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvpickev_d, simd_pickev_d, m256i, i64x4);
impl_vvv!("lasx", lasx_xvpickod_b, simd_pickod_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvpickod_h, simd_pickod_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvpickod_w, simd_pickod_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvpickod_d, simd_pickod_d, m256i, i64x4);
impl_vvv!("lasx", lasx_xvilvh_b, simd_ilvh_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvilvh_h, simd_ilvh_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvilvh_w, simd_ilvh_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvilvh_d, simd_ilvh_d, m256i, i64x4);
impl_vvv!("lasx", lasx_xvilvl_b, simd_ilvl_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvilvl_h, simd_ilvl_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvilvl_w, simd_ilvl_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvilvl_d, simd_ilvl_d, m256i, i64x4);
impl_vvv!("lasx", lasx_xvpackev_b, simd_packev_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvpackev_h, simd_packev_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvpackev_w, simd_packev_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvpackev_d, simd_packev_d, m256i, i64x4);
impl_vvv!("lasx", lasx_xvpackod_b, simd_packod_b, m256i, i8x32);
impl_vvv!("lasx", lasx_xvpackod_h, simd_packod_h, m256i, i16x16);
impl_vvv!("lasx", lasx_xvpackod_w, simd_packod_w, m256i, i32x8);
impl_vvv!("lasx", lasx_xvpackod_d, simd_packod_d, m256i, i64x4);

impl_vuv!("lasx", lasx_xvslli_b, is::simd_shl, m256i, i8x32);
impl_vuv!("lasx", lasx_xvslli_h, is::simd_shl, m256i, i16x16);
impl_vuv!("lasx", lasx_xvslli_w, is::simd_shl, m256i, i32x8);
impl_vuv!("lasx", lasx_xvslli_d, is::simd_shl, m256i, i64x4);
impl_vuv!("lasx", lasx_xvsrai_b, is::simd_shr, m256i, i8x32);
impl_vuv!("lasx", lasx_xvsrai_h, is::simd_shr, m256i, i16x16);
impl_vuv!("lasx", lasx_xvsrai_w, is::simd_shr, m256i, i32x8);
impl_vuv!("lasx", lasx_xvsrai_d, is::simd_shr, m256i, i64x4);
impl_vuv!("lasx", lasx_xvsrli_b, is::simd_shr, m256i, u8x32);
impl_vuv!("lasx", lasx_xvsrli_h, is::simd_shr, m256i, u16x16);
impl_vuv!("lasx", lasx_xvsrli_w, is::simd_shr, m256i, u32x8);
impl_vuv!("lasx", lasx_xvsrli_d, is::simd_shr, m256i, u64x4);
impl_vuv!("lasx", lasx_xvaddi_bu, is::simd_add, m256i, u8x32, 5);
impl_vuv!("lasx", lasx_xvaddi_hu, is::simd_add, m256i, u16x16, 5);
impl_vuv!("lasx", lasx_xvaddi_wu, is::simd_add, m256i, u32x8, 5);
impl_vuv!("lasx", lasx_xvaddi_du, is::simd_add, m256i, u64x4, 5);
impl_vuv!("lasx", lasx_xvslti_bu, is::simd_lt, m256i, u8x32, 5);
impl_vuv!("lasx", lasx_xvslti_hu, is::simd_lt, m256i, u16x16, 5);
impl_vuv!("lasx", lasx_xvslti_wu, is::simd_lt, m256i, u32x8, 5);
impl_vuv!("lasx", lasx_xvslti_du, is::simd_lt, m256i, u64x4, 5);
impl_vuv!("lasx", lasx_xvslei_bu, is::simd_le, m256i, u8x32, 5);
impl_vuv!("lasx", lasx_xvslei_hu, is::simd_le, m256i, u16x16, 5);
impl_vuv!("lasx", lasx_xvslei_wu, is::simd_le, m256i, u32x8, 5);
impl_vuv!("lasx", lasx_xvslei_du, is::simd_le, m256i, u64x4, 5);
impl_vuv!("lasx", lasx_xvmaxi_bu, cs::simd_imax, m256i, u8x32, 5);
impl_vuv!("lasx", lasx_xvmaxi_hu, cs::simd_imax, m256i, u16x16, 5);
impl_vuv!("lasx", lasx_xvmaxi_wu, cs::simd_imax, m256i, u32x8, 5);
impl_vuv!("lasx", lasx_xvmaxi_du, cs::simd_imax, m256i, u64x4, 5);
impl_vuv!("lasx", lasx_xvmini_bu, cs::simd_imin, m256i, u8x32, 5);
impl_vuv!("lasx", lasx_xvmini_hu, cs::simd_imin, m256i, u16x16, 5);
impl_vuv!("lasx", lasx_xvmini_wu, cs::simd_imin, m256i, u32x8, 5);
impl_vuv!("lasx", lasx_xvmini_du, cs::simd_imin, m256i, u64x4, 5);
impl_vuv!("lasx", lasx_xvrepl128vei_b, simd_replvei_b, m256i, i8x32, 4, const);
impl_vuv!("lasx", lasx_xvrepl128vei_h, simd_replvei_h, m256i, i16x16, 3, const);
impl_vuv!("lasx", lasx_xvrepl128vei_w, simd_replvei_w, m256i, i32x8, 2, const);
impl_vuv!("lasx", lasx_xvrepl128vei_d, simd_replvei_d, m256i, i64x4, 1, const);
impl_vuv!("lasx", lasx_xvshuf4i_b, simd_shuf4i_b, m256i, i8x32, 8, const);
impl_vuv!("lasx", lasx_xvshuf4i_h, simd_shuf4i_h, m256i, i16x16, 8, const);
impl_vuv!("lasx", lasx_xvshuf4i_w, simd_shuf4i_w, m256i, i32x8, 8, const);

impl_vug!("lasx", lasx_xvpickve2gr_w, is::simd_extract, m256i, i32x8, i32, 3);
impl_vug!("lasx", lasx_xvpickve2gr_d, is::simd_extract, m256i, i64x4, i64, 2);
impl_vug!("lasx", lasx_xvpickve2gr_wu, is::simd_extract, m256i, u32x8, u32, 3);
impl_vug!("lasx", lasx_xvpickve2gr_du, is::simd_extract, m256i, u64x4, u64, 2);

impl_vsv!("lasx", lasx_xvseqi_b, is::simd_eq, m256i, i8x32, 5);
impl_vsv!("lasx", lasx_xvseqi_h, is::simd_eq, m256i, i16x16, 5);
impl_vsv!("lasx", lasx_xvseqi_w, is::simd_eq, m256i, i32x8, 5);
impl_vsv!("lasx", lasx_xvseqi_d, is::simd_eq, m256i, i64x4, 5);
impl_vsv!("lasx", lasx_xvslti_b, is::simd_lt, m256i, i8x32, 5);
impl_vsv!("lasx", lasx_xvslti_h, is::simd_lt, m256i, i16x16, 5);
impl_vsv!("lasx", lasx_xvslti_w, is::simd_lt, m256i, i32x8, 5);
impl_vsv!("lasx", lasx_xvslti_d, is::simd_lt, m256i, i64x4, 5);
impl_vsv!("lasx", lasx_xvslei_b, is::simd_le, m256i, i8x32, 5);
impl_vsv!("lasx", lasx_xvslei_h, is::simd_le, m256i, i16x16, 5);
impl_vsv!("lasx", lasx_xvslei_w, is::simd_le, m256i, i32x8, 5);
impl_vsv!("lasx", lasx_xvslei_d, is::simd_le, m256i, i64x4, 5);
impl_vsv!("lasx", lasx_xvmaxi_b, cs::simd_imax, m256i, i8x32, 5);
impl_vsv!("lasx", lasx_xvmaxi_h, cs::simd_imax, m256i, i16x16, 5);
impl_vsv!("lasx", lasx_xvmaxi_w, cs::simd_imax, m256i, i32x8, 5);
impl_vsv!("lasx", lasx_xvmaxi_d, cs::simd_imax, m256i, i64x4, 5);
impl_vsv!("lasx", lasx_xvmini_b, cs::simd_imin, m256i, i8x32, 5);
impl_vsv!("lasx", lasx_xvmini_h, cs::simd_imin, m256i, i16x16, 5);
impl_vsv!("lasx", lasx_xvmini_w, cs::simd_imin, m256i, i32x8, 5);
impl_vsv!("lasx", lasx_xvmini_d, cs::simd_imin, m256i, i64x4, 5);

impl_vvvv!("lasx", lasx_xvmadd_b, ls::simd_madd, m256i, i8x32);
impl_vvvv!("lasx", lasx_xvmadd_h, ls::simd_madd, m256i, i16x16);
impl_vvvv!("lasx", lasx_xvmadd_w, ls::simd_madd, m256i, i32x8);
impl_vvvv!("lasx", lasx_xvmadd_d, ls::simd_madd, m256i, i64x4);
impl_vvvv!("lasx", lasx_xvmsub_b, ls::simd_msub, m256i, i8x32);
impl_vvvv!("lasx", lasx_xvmsub_h, ls::simd_msub, m256i, i16x16);
impl_vvvv!("lasx", lasx_xvmsub_w, ls::simd_msub, m256i, i32x8);
impl_vvvv!("lasx", lasx_xvmsub_d, ls::simd_msub, m256i, i64x4);
impl_vvvv!("lasx", lasx_xvfmadd_s, is::simd_fma, m256, f32x8);
impl_vvvv!("lasx", lasx_xvfmadd_d, is::simd_fma, m256d, f64x4);
impl_vvvv!("lasx", lasx_xvfmsub_s, ls::simd_fmsub, m256, f32x8);
impl_vvvv!("lasx", lasx_xvfmsub_d, ls::simd_fmsub, m256d, f64x4);
impl_vvvv!("lasx", lasx_xvfnmadd_s, ls::simd_fnmadd, m256, f32x8);
impl_vvvv!("lasx", lasx_xvfnmadd_d, ls::simd_fnmadd, m256d, f64x4);
impl_vvvv!("lasx", lasx_xvfnmsub_s, ls::simd_fnmsub, m256, f32x8);
impl_vvvv!("lasx", lasx_xvfnmsub_d, ls::simd_fnmsub, m256d, f64x4);

impl_vugv!("lasx", lasx_xvinsgr2vr_w, is::simd_insert, m256i, i32x8, i32, 3);
impl_vugv!("lasx", lasx_xvinsgr2vr_d, is::simd_insert, m256i, i64x4, i64, 2);
