From c5d842b7913483bccbb87d9f6578fdf4d292eab8 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sat, 14 Mar 2026 16:35:00 +0100 Subject: [PATCH] add fixmes for f128 also implement sqrt for f128 (using softfloat) and test sqrt for f16 and f128 --- src/intrinsics/math.rs | 2 ++ src/intrinsics/simd.rs | 6 +++--- tests/pass/intrinsics/portable-simd.rs | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/intrinsics/math.rs b/src/intrinsics/math.rs index fbd2aff4b5..fc7101df9e 100644 --- a/src/intrinsics/math.rs +++ b/src/intrinsics/math.rs @@ -192,10 +192,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "powf16" => pow_intrinsic::(this, args, dest)?, "powf32" => pow_intrinsic::(this, args, dest)?, "powf64" => pow_intrinsic::(this, args, dest)?, + "powf128" => todo!("f128"), // FIXME(f128) "powif16" => powi_intrinsic::(this, args, dest)?, "powif32" => powi_intrinsic::(this, args, dest)?, "powif64" => powi_intrinsic::(this, args, dest)?, + "powif128" => todo!("f128"), // FIXME(f128) _ => return interp_ok(EmulateItemResult::NotSupported), } diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 235f815ba2..74582bc589 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -1,4 +1,4 @@ -use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, SingleS}; +use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, QuadS, SingleS}; use rustc_middle::ty; use rustc_middle::ty::FloatTy; @@ -36,7 +36,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { FloatTy::F16 => math::sqrt_op::>(this, &op, &dest)?, FloatTy::F32 => math::sqrt_op::>(this, &op, &dest)?, FloatTy::F64 => math::sqrt_op::>(this, &op, &dest)?, - FloatTy::F128 => unimplemented!("f128"), + FloatTy::F128 => math::sqrt_op::>(this, &op, &dest)?, }; } } @@ -72,7 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { FloatTy::F16 => host_unary_float_op::(this, &op, host_op, &dest)?, FloatTy::F32 => host_unary_float_op::(this, &op, host_op, &dest)?, FloatTy::F64 => host_unary_float_op::(this, &op, host_op, &dest)?, - FloatTy::F128 => unimplemented!("f128"), + FloatTy::F128 => unimplemented!("f128"), // FIXME(f128) } } } diff --git a/tests/pass/intrinsics/portable-simd.rs b/tests/pass/intrinsics/portable-simd.rs index 554011dd02..b4fd8e2165 100644 --- a/tests/pass/intrinsics/portable-simd.rs +++ b/tests/pass/intrinsics/portable-simd.rs @@ -17,6 +17,7 @@ use std::ptr; use std::simd::StdFloat; use std::simd::prelude::*; +// The `portable_simd` crate currently does not support f16 or f128 vectors, so we define our own. #[repr(simd, packed)] #[derive(Copy)] struct PackedSimd([T; N]); @@ -113,6 +114,9 @@ fn simd_ops_f16() { f16x4::splat(f16::NEG_INFINITY) ); + assert_eq!(simd_fsqrt(simd_mul(a, a)), a); + assert_eq!(simd_fsqrt(simd_mul(b, b)), simd_fabs(b)); + assert_eq!(simd_eq(a, simd_mul(f16x4::splat(5.0), b)), i32x4::from_array([0, !0, 0, 0])); assert_eq!(simd_ne(a, simd_mul(f16x4::splat(5.0), b)), i32x4::from_array([!0, 0, !0, !0])); 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() { f128x4::splat(f128::NEG_INFINITY) ); + assert_eq!(simd_fsqrt(simd_mul(a, a)), a); + assert_eq!(simd_fsqrt(simd_mul(b, b)), simd_fabs(b)); + assert_eq!(simd_eq(a, simd_mul(f128x4::splat(5.0), b)), i32x4::from_array([0, !0, 0, 0])); assert_eq!(simd_ne(a, simd_mul(f128x4::splat(5.0), b)), i32x4::from_array([!0, 0, !0, !0])); 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() { simd_flog2(a); simd_flog10(a); } + + unsafe { + let a = f128x2::splat(10.0); + simd_fsqrt(a); + } } fn simd_masked_loadstore() {