Skip to content

Commit 8cfeb9d

Browse files
committed
Expose algebraic floating point intrinsics
1 parent 4a43094 commit 8cfeb9d

File tree

3 files changed

+110
-5
lines changed

3 files changed

+110
-5
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,8 @@ pub unsafe fn float_to_int_unchecked<Float: Copy, Int: Copy>(_value: Float) -> I
29952995

29962996
/// Float addition that allows optimizations based on algebraic rules.
29972997
///
2998-
/// This intrinsic does not have a stable counterpart.
2998+
/// The stabilized version of this intrinsic is
2999+
/// [`f32::add_algebraic`](../../std/primitive.f32.html#method.add_algebraic)
29993000
#[rustc_nounwind]
30003001
#[rustc_intrinsic]
30013002
#[rustc_intrinsic_must_be_overridden]
@@ -3005,7 +3006,8 @@ pub fn fadd_algebraic<T: Copy>(_a: T, _b: T) -> T {
30053006

30063007
/// Float subtraction that allows optimizations based on algebraic rules.
30073008
///
3008-
/// This intrinsic does not have a stable counterpart.
3009+
/// The stabilized version of this intrinsic is
3010+
/// [`f32::sub_algebraic`](../../std/primitive.f32.html#method.sub_algebraic)
30093011
#[rustc_nounwind]
30103012
#[rustc_intrinsic]
30113013
#[rustc_intrinsic_must_be_overridden]
@@ -3015,7 +3017,8 @@ pub fn fsub_algebraic<T: Copy>(_a: T, _b: T) -> T {
30153017

30163018
/// Float multiplication that allows optimizations based on algebraic rules.
30173019
///
3018-
/// This intrinsic does not have a stable counterpart.
3020+
/// The stabilized version of this intrinsic is
3021+
/// [`f32::mul_algebraic`](../../std/primitive.f32.html#method.mul_algebraic)
30193022
#[rustc_nounwind]
30203023
#[rustc_intrinsic]
30213024
#[rustc_intrinsic_must_be_overridden]
@@ -3025,7 +3028,8 @@ pub fn fmul_algebraic<T: Copy>(_a: T, _b: T) -> T {
30253028

30263029
/// Float division that allows optimizations based on algebraic rules.
30273030
///
3028-
/// This intrinsic does not have a stable counterpart.
3031+
/// The stabilized version of this intrinsic is
3032+
/// [`f32::div_algebraic`](../../std/primitive.f32.html#method.div_algebraic)
30293033
#[rustc_nounwind]
30303034
#[rustc_intrinsic]
30313035
#[rustc_intrinsic_must_be_overridden]
@@ -3035,7 +3039,8 @@ pub fn fdiv_algebraic<T: Copy>(_a: T, _b: T) -> T {
30353039

30363040
/// Float remainder that allows optimizations based on algebraic rules.
30373041
///
3038-
/// This intrinsic does not have a stable counterpart.
3042+
/// The stabilized version of this intrinsic is
3043+
/// [`f32::rem_algebraic`](../../std/primitive.f32.html#method.rem_algebraic)
30393044
#[rustc_nounwind]
30403045
#[rustc_intrinsic]
30413046
#[rustc_intrinsic_must_be_overridden]

library/std/src/f32.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,4 +1154,54 @@ impl f32 {
11541154
let x = unsafe { cmath::lgammaf_r(self, &mut signgamp) };
11551155
(x, signgamp)
11561156
}
1157+
1158+
/// Float addition that allows optimizations based on algebraic rules.
1159+
#[rustc_allow_incoherent_impl]
1160+
#[doc(alias = "fadd_algebraic", alias = "addAlgebraic")]
1161+
#[must_use = "method returns a new number and does not mutate the original value"]
1162+
#[unstable(feature = "float_algebraic", issue = "21690")]
1163+
#[inline]
1164+
pub fn add_algebraic(self, rhs: f32) -> f32 {
1165+
intrinsics::fadd_algebraic(self, rhs)
1166+
}
1167+
1168+
/// Float subtraction that allows optimizations based on algebraic rules.
1169+
#[rustc_allow_incoherent_impl]
1170+
#[doc(alias = "fsub_algebraic", alias = "subAlgebraic")]
1171+
#[must_use = "method returns a new number and does not mutate the original value"]
1172+
#[unstable(feature = "float_algebraic", issue = "21690")]
1173+
#[inline]
1174+
pub fn sub_algebraic(self, rhs: f32) -> f32 {
1175+
intrinsics::fsub_algebraic(self, rhs)
1176+
}
1177+
1178+
/// Float multiplication that allows optimizations based on algebraic rules.
1179+
#[rustc_allow_incoherent_impl]
1180+
#[doc(alias = "fmul_algebraic", alias = "mulAlgebraic")]
1181+
#[must_use = "method returns a new number and does not mutate the original value"]
1182+
#[unstable(feature = "float_algebraic", issue = "21690")]
1183+
#[inline]
1184+
pub fn mul_algebraic(self, rhs: f32) -> f32 {
1185+
intrinsics::fmul_algebraic(self, rhs)
1186+
}
1187+
1188+
/// Float division that allows optimizations based on algebraic rules.
1189+
#[rustc_allow_incoherent_impl]
1190+
#[doc(alias = "fdiv_algebraic", alias = "divAlgebraic")]
1191+
#[must_use = "method returns a new number and does not mutate the original value"]
1192+
#[unstable(feature = "float_algebraic", issue = "21690")]
1193+
#[inline]
1194+
pub fn div_algebraic(self, rhs: f32) -> f32 {
1195+
intrinsics::fdiv_algebraic(self, rhs)
1196+
}
1197+
1198+
/// Float remainder that allows optimizations based on algebraic rules.
1199+
#[rustc_allow_incoherent_impl]
1200+
#[doc(alias = "frem_algebraic", alias = "remAlgebraic")]
1201+
#[must_use = "method returns a new number and does not mutate the original value"]
1202+
#[unstable(feature = "float_algebraic", issue = "21690")]
1203+
#[inline]
1204+
pub fn rem_algebraic(self, rhs: f32) -> f32 {
1205+
intrinsics::frem_algebraic(self, rhs)
1206+
}
11571207
}

library/std/src/f64.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,4 +1154,54 @@ impl f64 {
11541154
let x = unsafe { cmath::lgamma_r(self, &mut signgamp) };
11551155
(x, signgamp)
11561156
}
1157+
1158+
/// Float addition that allows optimizations based on algebraic rules.
1159+
#[rustc_allow_incoherent_impl]
1160+
#[doc(alias = "fadd_algebraic", alias = "addAlgebraic")]
1161+
#[must_use = "method returns a new number and does not mutate the original value"]
1162+
#[unstable(feature = "float_algebraic", issue = "21690")]
1163+
#[inline]
1164+
pub fn add_algebraic(self, rhs: f64) -> f64 {
1165+
intrinsics::fadd_algebraic(self, rhs)
1166+
}
1167+
1168+
/// Float subtraction that allows optimizations based on algebraic rules.
1169+
#[rustc_allow_incoherent_impl]
1170+
#[doc(alias = "fsub_algebraic", alias = "subAlgebraic")]
1171+
#[must_use = "method returns a new number and does not mutate the original value"]
1172+
#[unstable(feature = "float_algebraic", issue = "21690")]
1173+
#[inline]
1174+
pub fn sub_algebraic(self, rhs: f64) -> f64 {
1175+
intrinsics::fsub_algebraic(self, rhs)
1176+
}
1177+
1178+
/// Float multiplication that allows optimizations based on algebraic rules.
1179+
#[rustc_allow_incoherent_impl]
1180+
#[doc(alias = "fmul_algebraic", alias = "mulAlgebraic")]
1181+
#[must_use = "method returns a new number and does not mutate the original value"]
1182+
#[unstable(feature = "float_algebraic", issue = "21690")]
1183+
#[inline]
1184+
pub fn mul_algebraic(self, rhs: f64) -> f64 {
1185+
intrinsics::fmul_algebraic(self, rhs)
1186+
}
1187+
1188+
/// Float division that allows optimizations based on algebraic rules.
1189+
#[rustc_allow_incoherent_impl]
1190+
#[doc(alias = "fdiv_algebraic", alias = "divAlgebraic")]
1191+
#[must_use = "method returns a new number and does not mutate the original value"]
1192+
#[unstable(feature = "float_algebraic", issue = "21690")]
1193+
#[inline]
1194+
pub fn div_algebraic(self, rhs: f64) -> f64 {
1195+
intrinsics::fdiv_algebraic(self, rhs)
1196+
}
1197+
1198+
/// Float remainder that allows optimizations based on algebraic rules.
1199+
#[rustc_allow_incoherent_impl]
1200+
#[doc(alias = "frem_algebraic", alias = "remAlgebraic")]
1201+
#[must_use = "method returns a new number and does not mutate the original value"]
1202+
#[unstable(feature = "float_algebraic", issue = "21690")]
1203+
#[inline]
1204+
pub fn rem_algebraic(self, rhs: f64) -> f64 {
1205+
intrinsics::frem_algebraic(self, rhs)
1206+
}
11571207
}

0 commit comments

Comments
 (0)