Auto merge of #3535 - RalfJung:host-float, r=RalfJung

update host-float comments

Turns out most of these do not have guaranteed precision anyway so it's fine to use host floats (see https://github.com/rust-lang/rust/pull/121793 and https://github.com/rust-lang/rust/pull/118217). The exception are sqrt and mul_add, tracked at https://github.com/rust-lang/miri/issues/3534 and https://github.com/rust-lang/miri/issues/2995.
This commit is contained in:
bors 2024-05-02 17:16:10 +00:00
commit f6c0090064
3 changed files with 16 additions and 16 deletions

View File

@ -730,7 +730,7 @@ fn emulate_foreign_item_inner(
=> {
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let f = this.read_scalar(f)?.to_f32()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host();
let res = match link_name.as_str() {
"cbrtf" => f_host.cbrt(),
@ -761,7 +761,7 @@ fn emulate_foreign_item_inner(
let f2 = this.read_scalar(f2)?.to_f32()?;
// underscore case for windows, here and below
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let res = match link_name.as_str() {
"_hypotf" | "hypotf" => f1.to_host().hypot(f2.to_host()).to_soft(),
"atan2f" => f1.to_host().atan2(f2.to_host()).to_soft(),
@ -787,7 +787,7 @@ fn emulate_foreign_item_inner(
=> {
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let f = this.read_scalar(f)?.to_f64()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host();
let res = match link_name.as_str() {
"cbrt" => f_host.cbrt(),
@ -818,7 +818,7 @@ fn emulate_foreign_item_inner(
let f2 = this.read_scalar(f2)?.to_f64()?;
// underscore case for windows, here and below
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let res = match link_name.as_str() {
"_hypot" | "hypot" => f1.to_host().hypot(f2.to_host()).to_soft(),
"atan2" => f1.to_host().atan2(f2.to_host()).to_soft(),
@ -848,7 +848,7 @@ fn emulate_foreign_item_inner(
let x = this.read_scalar(x)?.to_f32()?;
let signp = this.deref_pointer(signp)?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let (res, sign) = x.to_host().ln_gamma();
this.write_int(sign, &signp)?;
let res = this.adjust_nan(res.to_soft(), &[x]);
@ -859,7 +859,7 @@ fn emulate_foreign_item_inner(
let x = this.read_scalar(x)?.to_f64()?;
let signp = this.deref_pointer(signp)?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let (res, sign) = x.to_host().ln_gamma();
this.write_int(sign, &signp)?;
let res = this.adjust_nan(res.to_soft(), &[x]);

View File

@ -193,12 +193,12 @@ fn emulate_intrinsic_by_name(
=> {
let [f] = check_arg_count(args)?;
let f = this.read_scalar(f)?.to_f32()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host();
let res = match intrinsic_name {
"sinf32" => f_host.sin(),
"cosf32" => f_host.cos(),
"sqrtf32" => f_host.sqrt(),
"sqrtf32" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
"expf32" => f_host.exp(),
"exp2f32" => f_host.exp2(),
"logf32" => f_host.ln(),
@ -238,12 +238,12 @@ fn emulate_intrinsic_by_name(
=> {
let [f] = check_arg_count(args)?;
let f = this.read_scalar(f)?.to_f64()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host();
let res = match intrinsic_name {
"sinf64" => f_host.sin(),
"cosf64" => f_host.cos(),
"sqrtf64" => f_host.sqrt(),
"sqrtf64" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
"expf64" => f_host.exp(),
"exp2f64" => f_host.exp2(),
"logf64" => f_host.ln(),
@ -366,7 +366,7 @@ fn emulate_intrinsic_by_name(
let [f1, f2] = check_arg_count(args)?;
let f1 = this.read_scalar(f1)?.to_f32()?;
let f2 = this.read_scalar(f2)?.to_f32()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, this operation does not have guaranteed precision).
let res = f1.to_host().powf(f2.to_host()).to_soft();
let res = this.adjust_nan(res, &[f1, f2]);
this.write_scalar(res, dest)?;
@ -376,7 +376,7 @@ fn emulate_intrinsic_by_name(
let [f1, f2] = check_arg_count(args)?;
let f1 = this.read_scalar(f1)?.to_f64()?;
let f2 = this.read_scalar(f2)?.to_f64()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, this operation does not have guaranteed precision).
let res = f1.to_host().powf(f2.to_host()).to_soft();
let res = this.adjust_nan(res, &[f1, f2]);
this.write_scalar(res, dest)?;
@ -386,7 +386,7 @@ fn emulate_intrinsic_by_name(
let [f, i] = check_arg_count(args)?;
let f = this.read_scalar(f)?.to_f32()?;
let i = this.read_scalar(i)?.to_i32()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, this operation does not have guaranteed precision).
let res = f.to_host().powi(i).to_soft();
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;
@ -396,7 +396,7 @@ fn emulate_intrinsic_by_name(
let [f, i] = check_arg_count(args)?;
let f = this.read_scalar(f)?.to_f64()?;
let i = this.read_scalar(i)?.to_i32()?;
// FIXME: Using host floats.
// Using host floats (but it's fine, this operation does not have guaranteed precision).
let res = f.to_host().powi(i).to_soft();
let res = this.adjust_nan(res, &[f]);
this.write_scalar(res, dest)?;

View File

@ -99,14 +99,14 @@ enum Op<'a> {
let ty::Float(float_ty) = op.layout.ty.kind() else {
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
};
// FIXME using host floats
// Using host floats (but it's fine, these operations do not have guaranteed precision).
match float_ty {
FloatTy::F16 => unimplemented!("f16_f128"),
FloatTy::F32 => {
let f = op.to_scalar().to_f32()?;
let f_host = f.to_host();
let res = match host_op {
"fsqrt" => f_host.sqrt(),
"fsqrt" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
"fsin" => f_host.sin(),
"fcos" => f_host.cos(),
"fexp" => f_host.exp(),