Skip to content

Commit 24fc363

Browse files
committed
Auto merge of #3596 - bend-n:support_fstar_algebraic, r=RalfJung
support `f*_algebraic` supports the [`f*_algebraic`](https://doc.rust-lang.org/std/intrinsics/fn.fadd_algebraic.html) intrinsics.
2 parents 1678334 + 18379e8 commit 24fc363

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/intrinsics/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
256256
let res = this.adjust_nan(res, &[f]);
257257
this.write_scalar(res, dest)?;
258258
}
259+
#[rustfmt::skip]
260+
| "fadd_algebraic"
261+
| "fsub_algebraic"
262+
| "fmul_algebraic"
263+
| "fdiv_algebraic"
264+
| "frem_algebraic"
265+
=> {
266+
let [a, b] = check_arg_count(args)?;
267+
let a = this.read_immediate(a)?;
268+
let b = this.read_immediate(b)?;
269+
let op = match intrinsic_name {
270+
"fadd_algebraic" => mir::BinOp::Add,
271+
"fsub_algebraic" => mir::BinOp::Sub,
272+
"fmul_algebraic" => mir::BinOp::Mul,
273+
"fdiv_algebraic" => mir::BinOp::Div,
274+
"frem_algebraic" => mir::BinOp::Rem,
275+
_ => bug!(),
276+
};
277+
let res = this.wrapping_binary_op(op, &a, &b)?;
278+
// `wrapping_binary_op` already called `generate_nan` if necessary.
279+
this.write_immediate(*res, dest)?;
280+
}
259281

260282
#[rustfmt::skip]
261283
| "fadd_fast"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(core_intrinsics)]
2+
3+
use std::intrinsics::{
4+
fadd_algebraic, fdiv_algebraic, fmul_algebraic, frem_algebraic, fsub_algebraic,
5+
};
6+
7+
#[inline(never)]
8+
pub fn test_operations_f64(a: f64, b: f64) {
9+
// make sure they all map to the correct operation
10+
assert_eq!(fadd_algebraic(a, b), a + b);
11+
assert_eq!(fsub_algebraic(a, b), a - b);
12+
assert_eq!(fmul_algebraic(a, b), a * b);
13+
assert_eq!(fdiv_algebraic(a, b), a / b);
14+
assert_eq!(frem_algebraic(a, b), a % b);
15+
}
16+
17+
#[inline(never)]
18+
pub fn test_operations_f32(a: f32, b: f32) {
19+
// make sure they all map to the correct operation
20+
assert_eq!(fadd_algebraic(a, b), a + b);
21+
assert_eq!(fsub_algebraic(a, b), a - b);
22+
assert_eq!(fmul_algebraic(a, b), a * b);
23+
assert_eq!(fdiv_algebraic(a, b), a / b);
24+
assert_eq!(frem_algebraic(a, b), a % b);
25+
}
26+
27+
fn main() {
28+
test_operations_f64(1., 2.);
29+
test_operations_f64(10., 5.);
30+
test_operations_f32(11., 2.);
31+
test_operations_f32(10., 15.);
32+
}

0 commit comments

Comments
 (0)