Skip to content

Commit fe1424a

Browse files
committed
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 rust-lang/rust#121793 and rust-lang/rust#118217). The exception are sqrt and mul_add, tracked at #3534 and #2995.
2 parents 4723bed + 79a157a commit fe1424a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/shims/foreign_items.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
730730
=> {
731731
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
732732
let f = this.read_scalar(f)?.to_f32()?;
733-
// FIXME: Using host floats.
733+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
734734
let f_host = f.to_host();
735735
let res = match link_name.as_str() {
736736
"cbrtf" => f_host.cbrt(),
@@ -761,7 +761,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
761761
let f2 = this.read_scalar(f2)?.to_f32()?;
762762
// underscore case for windows, here and below
763763
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
764-
// FIXME: Using host floats.
764+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
765765
let res = match link_name.as_str() {
766766
"_hypotf" | "hypotf" => f1.to_host().hypot(f2.to_host()).to_soft(),
767767
"atan2f" => f1.to_host().atan2(f2.to_host()).to_soft(),
@@ -787,7 +787,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
787787
=> {
788788
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
789789
let f = this.read_scalar(f)?.to_f64()?;
790-
// FIXME: Using host floats.
790+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
791791
let f_host = f.to_host();
792792
let res = match link_name.as_str() {
793793
"cbrt" => f_host.cbrt(),
@@ -818,7 +818,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
818818
let f2 = this.read_scalar(f2)?.to_f64()?;
819819
// underscore case for windows, here and below
820820
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
821-
// FIXME: Using host floats.
821+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
822822
let res = match link_name.as_str() {
823823
"_hypot" | "hypot" => f1.to_host().hypot(f2.to_host()).to_soft(),
824824
"atan2" => f1.to_host().atan2(f2.to_host()).to_soft(),
@@ -848,7 +848,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
848848
let x = this.read_scalar(x)?.to_f32()?;
849849
let signp = this.deref_pointer(signp)?;
850850

851-
// FIXME: Using host floats.
851+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
852852
let (res, sign) = x.to_host().ln_gamma();
853853
this.write_int(sign, &signp)?;
854854
let res = this.adjust_nan(res.to_soft(), &[x]);
@@ -859,7 +859,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
859859
let x = this.read_scalar(x)?.to_f64()?;
860860
let signp = this.deref_pointer(signp)?;
861861

862-
// FIXME: Using host floats.
862+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
863863
let (res, sign) = x.to_host().ln_gamma();
864864
this.write_int(sign, &signp)?;
865865
let res = this.adjust_nan(res.to_soft(), &[x]);

src/shims/intrinsics/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
193193
=> {
194194
let [f] = check_arg_count(args)?;
195195
let f = this.read_scalar(f)?.to_f32()?;
196-
// FIXME: Using host floats.
196+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
197197
let f_host = f.to_host();
198198
let res = match intrinsic_name {
199199
"sinf32" => f_host.sin(),
200200
"cosf32" => f_host.cos(),
201-
"sqrtf32" => f_host.sqrt(),
201+
"sqrtf32" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
202202
"expf32" => f_host.exp(),
203203
"exp2f32" => f_host.exp2(),
204204
"logf32" => f_host.ln(),
@@ -238,12 +238,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
238238
=> {
239239
let [f] = check_arg_count(args)?;
240240
let f = this.read_scalar(f)?.to_f64()?;
241-
// FIXME: Using host floats.
241+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
242242
let f_host = f.to_host();
243243
let res = match intrinsic_name {
244244
"sinf64" => f_host.sin(),
245245
"cosf64" => f_host.cos(),
246-
"sqrtf64" => f_host.sqrt(),
246+
"sqrtf64" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
247247
"expf64" => f_host.exp(),
248248
"exp2f64" => f_host.exp2(),
249249
"logf64" => f_host.ln(),
@@ -366,7 +366,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
366366
let [f1, f2] = check_arg_count(args)?;
367367
let f1 = this.read_scalar(f1)?.to_f32()?;
368368
let f2 = this.read_scalar(f2)?.to_f32()?;
369-
// FIXME: Using host floats.
369+
// Using host floats (but it's fine, this operation does not have guaranteed precision).
370370
let res = f1.to_host().powf(f2.to_host()).to_soft();
371371
let res = this.adjust_nan(res, &[f1, f2]);
372372
this.write_scalar(res, dest)?;
@@ -376,7 +376,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
376376
let [f1, f2] = check_arg_count(args)?;
377377
let f1 = this.read_scalar(f1)?.to_f64()?;
378378
let f2 = this.read_scalar(f2)?.to_f64()?;
379-
// FIXME: Using host floats.
379+
// Using host floats (but it's fine, this operation does not have guaranteed precision).
380380
let res = f1.to_host().powf(f2.to_host()).to_soft();
381381
let res = this.adjust_nan(res, &[f1, f2]);
382382
this.write_scalar(res, dest)?;
@@ -386,7 +386,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
386386
let [f, i] = check_arg_count(args)?;
387387
let f = this.read_scalar(f)?.to_f32()?;
388388
let i = this.read_scalar(i)?.to_i32()?;
389-
// FIXME: Using host floats.
389+
// Using host floats (but it's fine, this operation does not have guaranteed precision).
390390
let res = f.to_host().powi(i).to_soft();
391391
let res = this.adjust_nan(res, &[f]);
392392
this.write_scalar(res, dest)?;
@@ -396,7 +396,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
396396
let [f, i] = check_arg_count(args)?;
397397
let f = this.read_scalar(f)?.to_f64()?;
398398
let i = this.read_scalar(i)?.to_i32()?;
399-
// FIXME: Using host floats.
399+
// Using host floats (but it's fine, this operation does not have guaranteed precision).
400400
let res = f.to_host().powi(i).to_soft();
401401
let res = this.adjust_nan(res, &[f]);
402402
this.write_scalar(res, dest)?;

src/shims/intrinsics/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9999
let ty::Float(float_ty) = op.layout.ty.kind() else {
100100
span_bug!(this.cur_span(), "{} operand is not a float", intrinsic_name)
101101
};
102-
// FIXME using host floats
102+
// Using host floats (but it's fine, these operations do not have guaranteed precision).
103103
match float_ty {
104104
FloatTy::F16 => unimplemented!("f16_f128"),
105105
FloatTy::F32 => {
106106
let f = op.to_scalar().to_f32()?;
107107
let f_host = f.to_host();
108108
let res = match host_op {
109-
"fsqrt" => f_host.sqrt(),
109+
"fsqrt" => f_host.sqrt(), // FIXME Using host floats, this should use full-precision soft-floats
110110
"fsin" => f_host.sin(),
111111
"fcos" => f_host.cos(),
112112
"fexp" => f_host.exp(),

0 commit comments

Comments
 (0)