| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::MaybeUninitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/maybe_uninit/MaybeUninit#, ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/}; |
| 2 | use zerocopyrust-analyzer cargo zerocopy 0.8.26 crate/::transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!; |
| 3 | |
| 4 | #[cfg(target_arch = "x86")] |
| 5 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::archrust-analyzer cargo core https://github.com/rust-lang/rust/library/core arch/::x86::{ |
| 6 | __m128, __m128i, __m256, _mm256_cvtph_ps, _mm256_cvtps_ph, _mm_cvtph_ps, |
| 7 | _MM_FROUND_TO_NEAREST_INT, |
| 8 | }; |
| 9 | #[cfg(target_arch = "x86_64")] |
| 10 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::archrust-analyzer cargo core https://github.com/rust-lang/rust/library/core arch/::x86_64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/arch/x86_64/::{ |
| 11 | __m128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128#, __m128irust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128i#, __m256rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m256#, _mm256_cvtph_psrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm256_cvtph_ps()., _mm256_cvtps_phrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm256_cvtps_ph()., _mm_cvtph_psrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtph_ps()., _mm_cvtps_phrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtps_ph()., |
| 12 | _MM_FROUND_TO_NEAREST_INTrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/sse41/_MM_FROUND_TO_NEAREST_INT., |
| 13 | }; |
| 14 | |
| 15 | #[cfg(target_arch = "x86")] |
| 16 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::archrust-analyzer cargo core https://github.com/rust-lang/rust/library/core arch/::x86::_mm_cvtps_ph; |
| 17 | |
| 18 | use superrust-analyzer cargo half 2.7.1 binary16/arch/::convert_chunked_slice_8rust-analyzer cargo half 2.7.1 binary16/arch/convert_chunked_slice_8().; |
| 19 | |
| 20 | /////////////// x86/x86_64 f16c //////////////// |
| 21 | |
| 22 | #[target_feature(enable = "f16c")] |
| 23 | #[inline] |
| 24 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f16_to_f32_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16_to_f32_x86_f16c().(i: u16) -> f32 { |
| 25 | let vec: __m128irust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128i# = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!([i, 0, 0, 0, 0, 0, 0, 0]); |
| 26 | let retval: [f32; 4] = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(_mm_cvtph_psrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtph_ps().(vec)); |
| 27 | retval[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). |
| 28 | } |
| 29 | |
| 30 | #[target_feature(enable = "f16c")] |
| 31 | #[inline] |
| 32 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f32_to_f16_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f32_to_f16_x86_f16c().(f: f32) -> u16 { |
| 33 | let vec: __m128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128# = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!([f, 0.0, 0.0, 0.0]); |
| 34 | let retval = _mm_cvtps_phrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtps_ph().(vec, _MM_FROUND_TO_NEAREST_INTrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/sse41/_MM_FROUND_TO_NEAREST_INT.); |
| 35 | let retval: [u16; 8] = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(retval); |
| 36 | retval[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). |
| 37 | } |
| 38 | |
| 39 | #[target_feature(enable = "f16c")] |
| 40 | #[inline] |
| 41 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f16x4_to_f32x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x4_to_f32x4_x86_f16c().(v: &[u16; 4]) -> [f32; 4] { |
| 42 | let vec: __m128irust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128i# = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!([*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v, [0, 0, 0, 0]]); |
| 43 | transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(_mm_cvtph_psrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtph_ps().(vec)) |
| 44 | } |
| 45 | |
| 46 | #[target_feature(enable = "f16c")] |
| 47 | #[inline] |
| 48 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f32x4_to_f16x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f32x4_to_f16x4_x86_f16c().(v: &[f32; 4]) -> [u16; 4] { |
| 49 | let vec: __m128rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128# = zerocopyrust-analyzer cargo zerocopy 0.8.26 crate/::transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v); |
| 50 | let retval = _mm_cvtps_phrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm_cvtps_ph().(vec, _MM_FROUND_TO_NEAREST_INTrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/sse41/_MM_FROUND_TO_NEAREST_INT.); |
| 51 | let retval: [[u16; 4]; 2] = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(retval); |
| 52 | retval[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). |
| 53 | } |
| 54 | |
| 55 | #[target_feature(enable = "f16c")] |
| 56 | #[inline] |
| 57 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f16x4_to_f64x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x4_to_f64x4_x86_f16c().(v: &[u16; 4]) -> [f64; 4] { |
| 58 | let array = f16x4_to_f32x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x4_to_f32x4_x86_f16c().(v); |
| 59 | // Let compiler vectorize this regular cast for now. |
| 60 | // TODO: investigate auto-detecting sse2/avx convert features |
| 61 | [ |
| 62 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 63 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 64 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 65 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 66 | ] |
| 67 | } |
| 68 | |
| 69 | #[target_feature(enable = "f16c")] |
| 70 | #[inline] |
| 71 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f64x4_to_f16x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f64x4_to_f16x4_x86_f16c().(v: &[f64; 4]) -> [u16; 4] { |
| 72 | // Let compiler vectorize this regular cast for now. |
| 73 | // TODO: investigate auto-detecting sse2/avx convert features |
| 74 | let v = [v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32]; |
| 75 | f32x4_to_f16x4_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f32x4_to_f16x4_x86_f16c().(&v) |
| 76 | } |
| 77 | |
| 78 | #[target_feature(enable = "f16c")] |
| 79 | #[inline] |
| 80 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f16x8_to_f32x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x8_to_f32x8_x86_f16c().(v: &[u16; 8]) -> [f32; 8] { |
| 81 | let vec: __m128irust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m128i# = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v); |
| 82 | transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(_mm256_cvtph_psrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm256_cvtph_ps().(vec)) |
| 83 | } |
| 84 | |
| 85 | #[target_feature(enable = "f16c")] |
| 86 | #[inline] |
| 87 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f32x8_to_f16x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f32x8_to_f16x8_x86_f16c().(v: &[f32; 8]) -> [u16; 8] { |
| 88 | let vec: __m256rust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/__m256# = transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().v); |
| 89 | let retval = _mm256_cvtps_phrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/f16c/_mm256_cvtps_ph().(vec, _MM_FROUND_TO_NEAREST_INTrust-analyzer cargo core https://github.com/rust-lang/rust/library/core core_arch/x86/sse41/_MM_FROUND_TO_NEAREST_INT.); |
| 90 | transmuterust-analyzer cargo zerocopy 0.8.26 macros/transmute!!(retval) |
| 91 | } |
| 92 | |
| 93 | #[target_feature(enable = "f16c")] |
| 94 | #[inline] |
| 95 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f16x8_to_f64x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x8_to_f64x8_x86_f16c().(v: &[u16; 8]) -> [f64; 8] { |
| 96 | let array = f16x8_to_f32x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f16x8_to_f32x8_x86_f16c().(v); |
| 97 | // Let compiler vectorize this regular cast for now. |
| 98 | // TODO: investigate auto-detecting sse2/avx convert features |
| 99 | [ |
| 100 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 101 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 102 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 103 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 104 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 105 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 106 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().6]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 107 | array[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().7]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index(). as f64, |
| 108 | ] |
| 109 | } |
| 110 | |
| 111 | #[target_feature(enable = "f16c")] |
| 112 | #[inline] |
| 113 | pub(superrust-analyzer cargo half 2.7.1 binary16/arch/) unsafe fn f64x8_to_f16x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f64x8_to_f16x8_x86_f16c().(v: &[f64; 8]) -> [u16; 8] { |
| 114 | // Let compiler vectorize this regular cast for now. |
| 115 | // TODO: investigate auto-detecting sse2/avx convert features |
| 116 | let v = [ |
| 117 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 118 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 119 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 120 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 121 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 122 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 123 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().6]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 124 | v[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().7]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). as f32, |
| 125 | ]; |
| 126 | f32x8_to_f16x8_x86_f16crust-analyzer cargo half 2.7.1 binary16/arch/x86/f32x8_to_f16x8_x86_f16c().(&v) |
| 127 | } |