Skip to content

Commit 658b5c8

Browse files
sayantnAmanieu
authored andcommitted
Use simd_funnel_sh{l,r} and simd_round_ties_even to remove uses of LLVM intrinsics
1 parent fddd05b commit 658b5c8

File tree

5 files changed

+47
-163
lines changed

5 files changed

+47
-163
lines changed

library/stdarch/crates/core_arch/src/aarch64/neon/generated.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23785,14 +23785,7 @@ pub fn vrndph_f16(a: f16) -> f16 {
2378523785
#[unstable(feature = "stdarch_neon_f16", issue = "136306")]
2378623786
#[cfg_attr(test, assert_instr(frintx))]
2378723787
pub fn vrndx_f16(a: float16x4_t) -> float16x4_t {
23788-
unsafe extern "unadjusted" {
23789-
#[cfg_attr(
23790-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23791-
link_name = "llvm.rint.v4f16"
23792-
)]
23793-
fn _vrndx_f16(a: float16x4_t) -> float16x4_t;
23794-
}
23795-
unsafe { _vrndx_f16(a) }
23788+
unsafe { simd_round_ties_even(a) }
2379623789
}
2379723790
#[doc = "Floating-point round to integral exact, using current rounding mode"]
2379823791
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndxq_f16)"]
@@ -23801,14 +23794,7 @@ pub fn vrndx_f16(a: float16x4_t) -> float16x4_t {
2380123794
#[unstable(feature = "stdarch_neon_f16", issue = "136306")]
2380223795
#[cfg_attr(test, assert_instr(frintx))]
2380323796
pub fn vrndxq_f16(a: float16x8_t) -> float16x8_t {
23804-
unsafe extern "unadjusted" {
23805-
#[cfg_attr(
23806-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23807-
link_name = "llvm.rint.v8f16"
23808-
)]
23809-
fn _vrndxq_f16(a: float16x8_t) -> float16x8_t;
23810-
}
23811-
unsafe { _vrndxq_f16(a) }
23797+
unsafe { simd_round_ties_even(a) }
2381223798
}
2381323799
#[doc = "Floating-point round to integral exact, using current rounding mode"]
2381423800
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndx_f32)"]
@@ -23817,14 +23803,7 @@ pub fn vrndxq_f16(a: float16x8_t) -> float16x8_t {
2381723803
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
2381823804
#[cfg_attr(test, assert_instr(frintx))]
2381923805
pub fn vrndx_f32(a: float32x2_t) -> float32x2_t {
23820-
unsafe extern "unadjusted" {
23821-
#[cfg_attr(
23822-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23823-
link_name = "llvm.rint.v2f32"
23824-
)]
23825-
fn _vrndx_f32(a: float32x2_t) -> float32x2_t;
23826-
}
23827-
unsafe { _vrndx_f32(a) }
23806+
unsafe { simd_round_ties_even(a) }
2382823807
}
2382923808
#[doc = "Floating-point round to integral exact, using current rounding mode"]
2383023809
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndxq_f32)"]
@@ -23833,14 +23812,7 @@ pub fn vrndx_f32(a: float32x2_t) -> float32x2_t {
2383323812
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
2383423813
#[cfg_attr(test, assert_instr(frintx))]
2383523814
pub fn vrndxq_f32(a: float32x4_t) -> float32x4_t {
23836-
unsafe extern "unadjusted" {
23837-
#[cfg_attr(
23838-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23839-
link_name = "llvm.rint.v4f32"
23840-
)]
23841-
fn _vrndxq_f32(a: float32x4_t) -> float32x4_t;
23842-
}
23843-
unsafe { _vrndxq_f32(a) }
23815+
unsafe { simd_round_ties_even(a) }
2384423816
}
2384523817
#[doc = "Floating-point round to integral exact, using current rounding mode"]
2384623818
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndx_f64)"]
@@ -23849,14 +23821,7 @@ pub fn vrndxq_f32(a: float32x4_t) -> float32x4_t {
2384923821
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
2385023822
#[cfg_attr(test, assert_instr(frintx))]
2385123823
pub fn vrndx_f64(a: float64x1_t) -> float64x1_t {
23852-
unsafe extern "unadjusted" {
23853-
#[cfg_attr(
23854-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23855-
link_name = "llvm.rint.v1f64"
23856-
)]
23857-
fn _vrndx_f64(a: float64x1_t) -> float64x1_t;
23858-
}
23859-
unsafe { _vrndx_f64(a) }
23824+
unsafe { simd_round_ties_even(a) }
2386023825
}
2386123826
#[doc = "Floating-point round to integral exact, using current rounding mode"]
2386223827
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndxq_f64)"]
@@ -23865,14 +23830,7 @@ pub fn vrndx_f64(a: float64x1_t) -> float64x1_t {
2386523830
#[stable(feature = "neon_intrinsics", since = "1.59.0")]
2386623831
#[cfg_attr(test, assert_instr(frintx))]
2386723832
pub fn vrndxq_f64(a: float64x2_t) -> float64x2_t {
23868-
unsafe extern "unadjusted" {
23869-
#[cfg_attr(
23870-
any(target_arch = "aarch64", target_arch = "arm64ec"),
23871-
link_name = "llvm.rint.v2f64"
23872-
)]
23873-
fn _vrndxq_f64(a: float64x2_t) -> float64x2_t;
23874-
}
23875-
unsafe { _vrndxq_f64(a) }
23833+
unsafe { simd_round_ties_even(a) }
2387623834
}
2387723835
#[doc = "Floating-point round to integral, using current rounding mode"]
2387823836
#[doc = "[Arm's documentation](https://developer.arm.com/architectures/instruction-sets/intrinsics/vrndxh_f16)"]

library/stdarch/crates/core_arch/src/powerpc/altivec.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,6 @@ unsafe extern "C" {
360360
#[link_name = "llvm.ppc.altivec.vsrv"]
361361
fn vsrv(a: vector_unsigned_char, b: vector_unsigned_char) -> vector_unsigned_char;
362362

363-
#[link_name = "llvm.fshl.v16i8"]
364-
fn fshlb(
365-
a: vector_unsigned_char,
366-
b: vector_unsigned_char,
367-
c: vector_unsigned_char,
368-
) -> vector_unsigned_char;
369-
#[link_name = "llvm.fshl.v8i16"]
370-
fn fshlh(
371-
a: vector_unsigned_short,
372-
b: vector_unsigned_short,
373-
c: vector_unsigned_short,
374-
) -> vector_unsigned_short;
375-
#[link_name = "llvm.fshl.v4i32"]
376-
fn fshlw(
377-
a: vector_unsigned_int,
378-
b: vector_unsigned_int,
379-
c: vector_unsigned_int,
380-
) -> vector_unsigned_int;
381-
382363
#[link_name = "llvm.nearbyint.v4f32"]
383364
fn vrfin(a: vector_float) -> vector_float;
384365
}
@@ -3193,19 +3174,19 @@ mod sealed {
31933174
impl_vec_cntlz! { vec_vcntlzw(vector_unsigned_int) }
31943175

31953176
macro_rules! impl_vrl {
3196-
($fun:ident $intr:ident $ty:ident) => {
3177+
($fun:ident $ty:ident) => {
31973178
#[inline]
31983179
#[target_feature(enable = "altivec")]
31993180
#[cfg_attr(test, assert_instr($fun))]
32003181
unsafe fn $fun(a: t_t_l!($ty), b: t_t_l!($ty)) -> t_t_l!($ty) {
3201-
transmute($intr(transmute(a), transmute(a), transmute(b)))
3182+
simd_funnel_shl(a, a, b)
32023183
}
32033184
};
32043185
}
32053186

3206-
impl_vrl! { vrlb fshlb u8 }
3207-
impl_vrl! { vrlh fshlh u16 }
3208-
impl_vrl! { vrlw fshlw u32 }
3187+
impl_vrl! { vrlb u8 }
3188+
impl_vrl! { vrlh u16 }
3189+
impl_vrl! { vrlw u32 }
32093190

32103191
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
32113192
pub trait VectorRl {

library/stdarch/crates/core_arch/src/s390x/vector.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ unsafe extern "unadjusted" {
8383
#[link_name = "llvm.nearbyint.v4f32"] fn nearbyint_v4f32(a: vector_float) -> vector_float;
8484
#[link_name = "llvm.nearbyint.v2f64"] fn nearbyint_v2f64(a: vector_double) -> vector_double;
8585

86-
#[link_name = "llvm.rint.v4f32"] fn rint_v4f32(a: vector_float) -> vector_float;
87-
#[link_name = "llvm.rint.v2f64"] fn rint_v2f64(a: vector_double) -> vector_double;
88-
8986
#[link_name = "llvm.roundeven.v4f32"] fn roundeven_v4f32(a: vector_float) -> vector_float;
9087
#[link_name = "llvm.roundeven.v2f64"] fn roundeven_v2f64(a: vector_double) -> vector_double;
9188

@@ -101,11 +98,6 @@ unsafe extern "unadjusted" {
10198
#[link_name = "llvm.s390.vsld"] fn vsld(a: i8x16, b: i8x16, c: u32) -> i8x16;
10299
#[link_name = "llvm.s390.vsrd"] fn vsrd(a: i8x16, b: i8x16, c: u32) -> i8x16;
103100

104-
#[link_name = "llvm.fshl.v16i8"] fn fshlb(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char) -> vector_unsigned_char;
105-
#[link_name = "llvm.fshl.v8i16"] fn fshlh(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_short) -> vector_unsigned_short;
106-
#[link_name = "llvm.fshl.v4i32"] fn fshlf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_int) -> vector_unsigned_int;
107-
#[link_name = "llvm.fshl.v2i64"] fn fshlg(a: vector_unsigned_long_long, b: vector_unsigned_long_long, c: vector_unsigned_long_long) -> vector_unsigned_long_long;
108-
109101
#[link_name = "llvm.s390.verimb"] fn verimb(a: vector_signed_char, b: vector_signed_char, c: vector_signed_char, d: i32) -> vector_signed_char;
110102
#[link_name = "llvm.s390.verimh"] fn verimh(a: vector_signed_short, b: vector_signed_short, c: vector_signed_short, d: i32) -> vector_signed_short;
111103
#[link_name = "llvm.s390.verimf"] fn verimf(a: vector_signed_int, b: vector_signed_int, c: vector_signed_int, d: i32) -> vector_signed_int;
@@ -1197,8 +1189,8 @@ mod sealed {
11971189
test_impl! { vec_round_f32 (a: vector_float) -> vector_float [roundeven_v4f32, _] }
11981190
test_impl! { vec_round_f64 (a: vector_double) -> vector_double [roundeven_v2f64, _] }
11991191

1200-
test_impl! { vec_rint_f32 (a: vector_float) -> vector_float [rint_v4f32, "vector-enhancements-1" vfisb] }
1201-
test_impl! { vec_rint_f64 (a: vector_double) -> vector_double [rint_v2f64, vfidb] }
1192+
test_impl! { vec_rint_f32 (a: vector_float) -> vector_float [simd_round_ties_even, "vector-enhancements-1" vfisb] }
1193+
test_impl! { vec_rint_f64 (a: vector_double) -> vector_double [simd_round_ties_even, vfidb] }
12021194

12031195
#[unstable(feature = "stdarch_s390x", issue = "135681")]
12041196
pub trait VectorRoundc {
@@ -1221,8 +1213,8 @@ mod sealed {
12211213
impl_vec_trait! { [VectorRound vec_round] vec_round_f32 (vector_float) }
12221214
impl_vec_trait! { [VectorRound vec_round] vec_round_f64 (vector_double) }
12231215

1224-
impl_vec_trait! { [VectorRint vec_rint] vec_rint_f32 (vector_float) }
1225-
impl_vec_trait! { [VectorRint vec_rint] vec_rint_f64 (vector_double) }
1216+
impl_vec_trait! { [VectorRint vec_rint] simd_round_ties_even (vector_float) }
1217+
impl_vec_trait! { [VectorRint vec_rint] simd_round_ties_even (vector_double) }
12261218

12271219
#[unstable(feature = "stdarch_s390x", issue = "135681")]
12281220
pub trait VectorTrunc {
@@ -1411,43 +1403,42 @@ mod sealed {
14111403
}
14121404

14131405
macro_rules! impl_rot {
1414-
($fun:ident $intr:ident $ty:ident) => {
1406+
($fun:ident $ty:ident) => {
14151407
#[inline]
14161408
#[target_feature(enable = "vector")]
14171409
#[cfg_attr(test, assert_instr($fun))]
14181410
unsafe fn $fun(a: t_t_l!($ty), b: t_t_l!($ty)) -> t_t_l!($ty) {
1419-
transmute($intr(transmute(a), transmute(a), transmute(b)))
1411+
simd_funnel_shl(a, a, b)
14201412
}
14211413
};
14221414
}
14231415

1424-
impl_rot! { verllvb fshlb u8 }
1425-
impl_rot! { verllvh fshlh u16 }
1426-
impl_rot! { verllvf fshlf u32 }
1427-
impl_rot! { verllvg fshlg u64 }
1416+
impl_rot! { verllvb u8 }
1417+
impl_rot! { verllvh u16 }
1418+
impl_rot! { verllvf u32 }
1419+
impl_rot! { verllvg u64 }
14281420

14291421
impl_vec_shift! { [VectorRl vec_rl] (verllvb, verllvh, verllvf, verllvg) }
14301422

14311423
macro_rules! test_rot_imm {
1432-
($fun:ident $instr:ident $intr:ident $ty:ident) => {
1424+
($fun:ident $instr:ident $ty:ident) => {
14331425
#[inline]
14341426
#[target_feature(enable = "vector")]
14351427
#[cfg_attr(test, assert_instr($instr))]
14361428
unsafe fn $fun(a: t_t_l!($ty), bits: core::ffi::c_ulong) -> t_t_l!($ty) {
14371429
// mod by the number of bits in a's element type to prevent UB
14381430
let bits = (bits % $ty::BITS as core::ffi::c_ulong) as $ty;
1439-
let a = transmute(a);
14401431
let b = <t_t_s!($ty)>::splat(bits);
14411432

1442-
transmute($intr(a, a, transmute(b)))
1433+
simd_funnel_shl(a, a, transmute(b))
14431434
}
14441435
};
14451436
}
14461437

1447-
test_rot_imm! { verllvb_imm verllb fshlb u8 }
1448-
test_rot_imm! { verllvh_imm verllh fshlh u16 }
1449-
test_rot_imm! { verllvf_imm verllf fshlf u32 }
1450-
test_rot_imm! { verllvg_imm verllg fshlg u64 }
1438+
test_rot_imm! { verllvb_imm verllb u8 }
1439+
test_rot_imm! { verllvh_imm verllh u16 }
1440+
test_rot_imm! { verllvf_imm verllf u32 }
1441+
test_rot_imm! { verllvg_imm verllg u64 }
14511442

14521443
#[unstable(feature = "stdarch_s390x", issue = "135681")]
14531444
pub trait VectorRli {

0 commit comments

Comments
 (0)