From 758279fba7b0cd4a648157ecd52de8b7d8257dfe Mon Sep 17 00:00:00 2001 From: Krisna Pranav <68631244+krishpranav@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:33:19 +0530 Subject: [PATCH] Fix: Update to Support Rust's Unstable Features and Correct Module Imports --- crates/core_arch/src/arm/neon.rs | 33 ++++++++++++++++++++++++++++++++ crates/core_arch/src/x86/mod.rs | 32 +++++++++++++++++++++++++++++++ crates/core_arch/src/x86/test.rs | 14 ++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/crates/core_arch/src/arm/neon.rs b/crates/core_arch/src/arm/neon.rs index ff67812365..8286a4630d 100644 --- a/crates/core_arch/src/arm/neon.rs +++ b/crates/core_arch/src/arm/neon.rs @@ -1425,6 +1425,39 @@ pub unsafe fn vsriq_n_p64(a: poly64x2_t, b: poly64x2_t) -> poly64x )) } +#[cfg(target_arch = "aarch64")] +mod neon_sve { + use std::arch::asm; + + // SIMD operation for f16 - Add 2 f16 values using NEON + pub fn add_f16(a: f16, b: f16) -> f16 { + unsafe { + let result: f16; + asm!( + "fadd {0}, {1}, {2}", // NEON SIMD add for f16 + inout(vreg) a => result, + in(vreg) b, + options(nostack), + ); + result + } + } + + // SIMD operation for f128 - Add 2 f128 values using SVE + pub fn add_f128(a: f128, b: f128) -> f128 { + unsafe { + let result: f128; + asm!( + "fadd {0}, {1}, {2}", // SVE SIMD add for f128 + inout(vreg) a => result, + in(vreg) b, + options(nostack), + ); + result + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/core_arch/src/x86/mod.rs b/crates/core_arch/src/x86/mod.rs index bd0af1cb79..f149d0b8bc 100644 --- a/crates/core_arch/src/x86/mod.rs +++ b/crates/core_arch/src/x86/mod.rs @@ -750,3 +750,35 @@ pub use self::avxneconvert::*; mod avx512fp16; #[unstable(feature = "stdarch_x86_avx512_f16", issue = "127213")] pub use self::avx512fp16::*; + +#[cfg(target_arch = "x86_64")] +mod avx512 { + use std::arch::asm; + + pub fn add_f16(a: f16, b: f16) -> f16 { + unsafe { + let result: f16; + + asm!( + "vaddps {0}, {1}, {2}" + inout(xmm_reg) a => result, + in(xmm_reg) b, + options(nostack), + ); + result + } + } + + pub fn add_f128(a: f128, b: f128) -> f128 { + unsafe { + let result: f128; + asm!{ + "vaddps {0}, {1}, {2}", + inout(ymm_reg) a => result, + in(ymm_reg) b, + options(nostack), + }; + result + } + } +} \ No newline at end of file diff --git a/crates/core_arch/src/x86/test.rs b/crates/core_arch/src/x86/test.rs index dd78321135..68382082b6 100644 --- a/crates/core_arch/src/x86/test.rs +++ b/crates/core_arch/src/x86/test.rs @@ -166,3 +166,17 @@ pub unsafe fn assert_eq_m512h(a: __m512h, b: __m512h) { panic!("{:?} != {:?}", a, b); } } + +#[test] +fn test_add_f16() { + let a: f16 = 1.5; + let b: f16 = 2.5; + assert_eq!(add_f16(a, b), 4.0); +} + +#[test] +fn test_add_f128() { + let a: f128 = 3.5; + let b: f128 = 4.5; + assert_eq!(add_f128(a, b), 8.0); +} \ No newline at end of file