#![allow(unsafe_op_in_unsafe_fn, clippy::missing_safety_doc)]
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
use half::bf16;
#[target_feature(enable = "avx512bf16,avx512f,avx512bw")]
#[inline]
pub unsafe fn widen(p: *const bf16) -> __m512 {
let raw: __m256i = core::ptr::read_unaligned(p as *const __m256i);
_mm512_cvtpbh_ps(core::mem::transmute::<__m256i, __m256bh>(raw))
}
#[target_feature(enable = "avx512bf16,avx512f,avx512bw")]
#[inline]
pub unsafe fn narrow(v: __m512, p: *mut bf16) {
let packed: __m256bh = _mm512_cvtneps_pbh(v);
core::ptr::write_unaligned(p as *mut __m256i, core::mem::transmute::<__m256bh, __m256i>(packed));
}
#[target_feature(enable = "avx512bf16,avx512f,avx512bw")]
#[inline]
pub unsafe fn pack_pair(lo: *const bf16, hi: *const bf16) -> __m512i {
let l: __m256i = core::ptr::read_unaligned(lo as *const __m256i);
let h: __m256i = core::ptr::read_unaligned(hi as *const __m256i);
_mm512_or_si512(
_mm512_cvtepu16_epi32(l),
_mm512_slli_epi32::<16>(_mm512_cvtepu16_epi32(h)),
)
}
#[target_feature(enable = "avx512bf16,avx512f,avx512bw")]
#[inline]
pub unsafe fn bcast_pair(a0: bf16, a1: bf16) -> __m512i {
_mm512_set1_epi32((((a1.to_bits() as u32) << 16) | a0.to_bits() as u32) as i32)
}
#[target_feature(enable = "avx512bf16,avx512f,avx512bw")]
#[inline]
pub unsafe fn dp(acc: __m512, a: __m512i, b: __m512i) -> __m512 {
_mm512_dpbf16_ps(
acc,
core::mem::transmute::<__m512i, __m512bh>(a),
core::mem::transmute::<__m512i, __m512bh>(b),
)
}