Skip to content

Commit 681750b

Browse files
committed
add fixmes for f128
also implement sqrt for f128 (using softfloat) and test sqrt for f16 and f128
1 parent f9ed8c2 commit 681750b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/tools/miri/src/intrinsics/math.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
192192
"powf16" => pow_intrinsic::<HalfS>(this, args, dest)?,
193193
"powf32" => pow_intrinsic::<SingleS>(this, args, dest)?,
194194
"powf64" => pow_intrinsic::<DoubleS>(this, args, dest)?,
195+
"powf128" => todo!("f128"), // FIXME(f128)
195196

196197
"powif16" => powi_intrinsic::<HalfS>(this, args, dest)?,
197198
"powif32" => powi_intrinsic::<SingleS>(this, args, dest)?,
198199
"powif64" => powi_intrinsic::<DoubleS>(this, args, dest)?,
200+
"powif128" => todo!("f128"), // FIXME(f128)
199201

200202
_ => return interp_ok(EmulateItemResult::NotSupported),
201203
}

src/tools/miri/src/intrinsics/simd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, SingleS};
1+
use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, QuadS, SingleS};
22
use rustc_middle::ty;
33
use rustc_middle::ty::FloatTy;
44

@@ -36,7 +36,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3636
FloatTy::F16 => math::sqrt_op::<IeeeFloat<HalfS>>(this, &op, &dest)?,
3737
FloatTy::F32 => math::sqrt_op::<IeeeFloat<SingleS>>(this, &op, &dest)?,
3838
FloatTy::F64 => math::sqrt_op::<IeeeFloat<DoubleS>>(this, &op, &dest)?,
39-
FloatTy::F128 => unimplemented!("f128"),
39+
FloatTy::F128 => math::sqrt_op::<IeeeFloat<QuadS>>(this, &op, &dest)?,
4040
};
4141
}
4242
}
@@ -72,7 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7272
FloatTy::F16 => host_unary_float_op::<HalfS>(this, &op, host_op, &dest)?,
7373
FloatTy::F32 => host_unary_float_op::<SingleS>(this, &op, host_op, &dest)?,
7474
FloatTy::F64 => host_unary_float_op::<DoubleS>(this, &op, host_op, &dest)?,
75-
FloatTy::F128 => unimplemented!("f128"),
75+
FloatTy::F128 => unimplemented!("f128"), // FIXME(f128)
7676
}
7777
}
7878
}

src/tools/miri/tests/pass/intrinsics/portable-simd.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::ptr;
1717
use std::simd::StdFloat;
1818
use std::simd::prelude::*;
1919

20+
// The `portable_simd` crate currently does not support f16 or f128 vectors, so we define our own.
2021
#[repr(simd, packed)]
2122
#[derive(Copy)]
2223
struct PackedSimd<T, const N: usize>([T; N]);
@@ -113,6 +114,9 @@ fn simd_ops_f16() {
113114
f16x4::splat(f16::NEG_INFINITY)
114115
);
115116

117+
assert_eq!(simd_fsqrt(simd_mul(a, a)), a);
118+
assert_eq!(simd_fsqrt(simd_mul(b, b)), simd_fabs(b));
119+
116120
assert_eq!(simd_eq(a, simd_mul(f16x4::splat(5.0), b)), i32x4::from_array([0, !0, 0, 0]));
117121
assert_eq!(simd_ne(a, simd_mul(f16x4::splat(5.0), b)), i32x4::from_array([!0, 0, !0, !0]));
118122
assert_eq!(simd_le(a, simd_mul(f16x4::splat(5.0), b)), i32x4::from_array([0, !0, !0, 0]));
@@ -324,6 +328,9 @@ fn simd_ops_f128() {
324328
f128x4::splat(f128::NEG_INFINITY)
325329
);
326330

331+
assert_eq!(simd_fsqrt(simd_mul(a, a)), a);
332+
assert_eq!(simd_fsqrt(simd_mul(b, b)), simd_fabs(b));
333+
327334
assert_eq!(simd_eq(a, simd_mul(f128x4::splat(5.0), b)), i32x4::from_array([0, !0, 0, 0]));
328335
assert_eq!(simd_ne(a, simd_mul(f128x4::splat(5.0), b)), i32x4::from_array([!0, 0, !0, !0]));
329336
assert_eq!(simd_le(a, simd_mul(f128x4::splat(5.0), b)), i32x4::from_array([0, !0, !0, 0]));
@@ -970,6 +977,11 @@ fn simd_float_intrinsics() {
970977
simd_flog2(a);
971978
simd_flog10(a);
972979
}
980+
981+
unsafe {
982+
let a = f128x2::splat(10.0);
983+
simd_fsqrt(a);
984+
}
973985
}
974986

975987
fn simd_masked_loadstore() {

0 commit comments

Comments
 (0)