Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update to Support Rust's Unstable Features and Correct Module Imports #1701

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions crates/core_arch/src/arm/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,39 @@ pub unsafe fn vsriq_n_p64<const N: i32>(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::*;
Expand Down
32 changes: 32 additions & 0 deletions crates/core_arch/src/x86/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
14 changes: 14 additions & 0 deletions crates/core_arch/src/x86/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading