Skip to content

Commit abdd350

Browse files
committed
go back to portable LLVM intrinsic to avoid fallback trouble
1 parent bfc3662 commit abdd350

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,19 @@ unsafe extern "unadjusted" {
336336
#[link_name = "llvm.s390.vcnf"] fn vcnf(a: vector_signed_short, immarg: i32) -> vector_signed_short;
337337
#[link_name = "llvm.s390.vcrnfs"] fn vcrnfs(a: vector_float, b: vector_float, immarg: i32) -> vector_signed_short;
338338

339-
#[link_name = "llvm.s390.vfmaxsb"] fn vfmaxsb(a: vector_float, b: vector_float, mode: i32) -> vector_float;
340-
#[link_name = "llvm.s390.vfmaxdb"] fn vfmaxdb(a: vector_double, b: vector_double, mode: i32) -> vector_double;
341-
#[link_name = "llvm.s390.vfminsb"] fn vfminsb(a: vector_float, b: vector_float, mode: i32) -> vector_float;
342-
#[link_name = "llvm.s390.vfmindb"] fn vfmindb(a: vector_double, b: vector_double, mode: i32) -> vector_double;
339+
// These are the intrinsics we'd like to use (with mode 0). However, they require
340+
// "vector-enhancements-1" and don't have a fallback, whereas `vec_min`/`vec_max` should be
341+
// available with just "vector". Therefore, we cannot use them.
342+
// #[link_name = "llvm.s390.vfmaxsb"] fn vfmaxsb(a: vector_float, b: vector_float, mode: i32) -> vector_float;
343+
// #[link_name = "llvm.s390.vfmaxdb"] fn vfmaxdb(a: vector_double, b: vector_double, mode: i32) -> vector_double;
344+
// #[link_name = "llvm.s390.vfminsb"] fn vfminsb(a: vector_float, b: vector_float, mode: i32) -> vector_float;
345+
// #[link_name = "llvm.s390.vfmindb"] fn vfmindb(a: vector_double, b: vector_double, mode: i32) -> vector_double;
346+
// Instead, we use "portable" LLVM intrinsics -- even though those have the wrong semantics
347+
// (https://github.com/rust-lang/stdarch/issues/2060), they usually do the right thing.
348+
#[link_name = "llvm.minnum.v4f32"] fn minnum_v4f32(a: f32x4, b: f32x4) -> f32x4;
349+
#[link_name = "llvm.minnum.v2f64"] fn minnum_v2f64(a: f64x2, b: f64x2) -> f64x2;
350+
#[link_name = "llvm.maxnum.v4f32"] fn maxnum_v4f32(a: f32x4, b: f32x4) -> f32x4;
351+
#[link_name = "llvm.maxnum.v2f64"] fn maxnum_v2f64(a: f64x2, b: f64x2) -> f64x2;
343352
}
344353

345354
#[repr(simd)]
@@ -797,8 +806,8 @@ mod sealed {
797806
vfmaxdb(a, b, const { 0 })
798807
}
799808

800-
test_impl! { vec_vfmaxsb (a: vector_float, b: vector_float) -> vector_float [vfmaxsb_m0, "vector-enhancements-1" vfmaxsb ] }
801-
test_impl! { vec_vfmaxdb (a: vector_double, b: vector_double) -> vector_double [vfmaxdb_m0, "vector-enhancements-1" vfmaxdb] }
809+
test_impl! { vec_vfmaxsb (a: vector_float, b: vector_float) -> vector_float [maxnum_v4f32, "vector-enhancements-1" vfmaxsb] }
810+
test_impl! { vec_vfmaxdb (a: vector_double, b: vector_double) -> vector_double [maxnum_v2f64, "vector-enhancements-1" vfmaxdb] }
802811

803812
impl_vec_trait!([VectorMax vec_max] vec_vfmaxsb (vector_float, vector_float) -> vector_float);
804813
impl_vec_trait!([VectorMax vec_max] vec_vfmaxdb (vector_double, vector_double) -> vector_double);
@@ -844,20 +853,8 @@ mod sealed {
844853
impl_min!(vec_vmnslg, vector_unsigned_long_long, vmnlg);
845854
}
846855

847-
#[inline]
848-
#[target_feature(enable = "vector")]
849-
unsafe fn vfminsb_m0(a: vector_float, b: vector_float) -> vector_float {
850-
// clang uses mode 0 for `vec_min`, so we do the same.
851-
vfminsb(a, b, const { 0 })
852-
}
853-
#[inline]
854-
#[target_feature(enable = "vector")]
855-
unsafe fn vfmindb_m0(a: vector_double, b: vector_double) -> vector_double {
856-
vfmindb(a, b, const { 0 })
857-
}
858-
859-
test_impl! { vec_vfminsb (a: vector_float, b: vector_float) -> vector_float [vfminsb_m0, "vector-enhancements-1" vfminsb] }
860-
test_impl! { vec_vfmindb (a: vector_double, b: vector_double) -> vector_double [vfmindb_m0, "vector-enhancements-1" vfmindb] }
856+
test_impl! { vec_vfminsb (a: vector_float, b: vector_float) -> vector_float [minnum_v4f32, "vector-enhancements-1" vfminsb] }
857+
test_impl! { vec_vfmindb (a: vector_double, b: vector_double) -> vector_double [minnum_v2f64, "vector-enhancements-1" vfmindb] }
861858

862859
impl_vec_trait!([VectorMin vec_min] vec_vfminsb (vector_float, vector_float) -> vector_float);
863860
impl_vec_trait!([VectorMin vec_min] vec_vfmindb (vector_double, vector_double) -> vector_double);

0 commit comments

Comments
 (0)