diff options
| author | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2025-04-22 16:39:32 +0200 |
|---|---|---|
| committer | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2025-04-23 08:54:52 +0200 |
| commit | 0296f05ce568e644363daa2f37b3a4d245d13951 (patch) | |
| tree | be80853b33be6010ca1ee71bfd965ce036b82a50 /compiler/rustc_const_eval/src | |
| parent | 6bc57c6bf7d0024ad9ea5a2c112f3fc9c383c8a4 (diff) | |
| download | rust-0296f05ce568e644363daa2f37b3a4d245d13951.tar.gz rust-0296f05ce568e644363daa2f37b3a4d245d13951.zip | |
Make algebraic intrinsics into 'const fn' items; Make algebraic functions of 'f16', 'f32', 'f64', and 'f128' into 'const fn' items;
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 4ca317e3a1e..40c63f2b250 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -158,6 +158,31 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { self.copy_op(&val, dest)?; } + sym::fadd_algebraic + | sym::fsub_algebraic + | sym::fmul_algebraic + | sym::fdiv_algebraic + | sym::frem_algebraic => { + let a = self.read_immediate(&args[0])?; + let b = self.read_immediate(&args[1])?; + + let op = match intrinsic_name { + sym::fadd_algebraic => BinOp::Add, + sym::fsub_algebraic => BinOp::Sub, + sym::fmul_algebraic => BinOp::Mul, + sym::fdiv_algebraic => BinOp::Div, + sym::frem_algebraic => BinOp::Rem, + + _ => bug!(), + }; + + let res = self.binary_op(op, &a, &b)?; + // `binary_op` already called `generate_nan` if needed. + + // FIXME: Miri should add some non-determinism to the result here to catch any dependences on exact computations. This has previously been done, but the behaviour was removed as part of constification. + self.write_immediate(*res, dest)?; + } + sym::ctpop | sym::cttz | sym::cttz_nonzero |
