Skip to content

Commit a15736f

Browse files
committed
Add f16 and f128 methods.
1 parent 9a6575d commit a15736f

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

library/core/src/intrinsics/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,7 @@ 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-
/// Stabilized as [`f32::add_algebraic`] and [`f64::add_algebraic`].
2998+
/// Stabilized as [`f16::add_algebraic`], [`f32::add_algebraic`], [`f64::add_algebraic`] and [`f128::add_algebraic`].
29992999
#[rustc_nounwind]
30003000
#[rustc_intrinsic]
30013001
#[rustc_intrinsic_must_be_overridden]
@@ -3005,7 +3005,7 @@ pub fn fadd_algebraic<T: Copy>(_a: T, _b: T) -> T {
30053005

30063006
/// Float subtraction that allows optimizations based on algebraic rules.
30073007
///
3008-
/// Stabilized as [`f32::sub_algebraic`] and [`f64::sub_algebraic`].
3008+
/// Stabilized as [`f16::sub_algebraic`], [`f32::sub_algebraic`], [`f64::sub_algebraic`] and [`f128::sub_algebraic`].
30093009
#[rustc_nounwind]
30103010
#[rustc_intrinsic]
30113011
#[rustc_intrinsic_must_be_overridden]
@@ -3015,7 +3015,7 @@ pub fn fsub_algebraic<T: Copy>(_a: T, _b: T) -> T {
30153015

30163016
/// Float multiplication that allows optimizations based on algebraic rules.
30173017
///
3018-
/// Stabilized as [`f32::mul_algebraic`] and [`f64::mul_algebraic`].
3018+
/// Stabilized as [`f16::mul_algebraic`], [`f32::mul_algebraic`], [`f64::mul_algebraic`] and [`f128::mul_algebraic`].
30193019
#[rustc_nounwind]
30203020
#[rustc_intrinsic]
30213021
#[rustc_intrinsic_must_be_overridden]
@@ -3025,7 +3025,7 @@ pub fn fmul_algebraic<T: Copy>(_a: T, _b: T) -> T {
30253025

30263026
/// Float division that allows optimizations based on algebraic rules.
30273027
///
3028-
/// Stabilized as [`f32::div_algebraic`] and [`f64::div_algebraic`].
3028+
/// Stabilized as [`f16::div_algebraic`], [`f32::div_algebraic`], [`f64::div_algebraic`] and [`f128::div_algebraic`].
30293029
#[rustc_nounwind]
30303030
#[rustc_intrinsic]
30313031
#[rustc_intrinsic_must_be_overridden]
@@ -3035,7 +3035,7 @@ pub fn fdiv_algebraic<T: Copy>(_a: T, _b: T) -> T {
30353035

30363036
/// Float remainder that allows optimizations based on algebraic rules.
30373037
///
3038-
/// Stabilized as [`f32::rem_algebraic`] and [`f64::rem_algebraic`].
3038+
/// Stabilized as [`f16::rem_algebraic`], [`f32::rem_algebraic`], [`f64::rem_algebraic`] and [`f128::rem_algebraic`].
30393039
#[rustc_nounwind]
30403040
#[rustc_intrinsic]
30413041
#[rustc_intrinsic_must_be_overridden]

library/core/src/num/f128.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,4 +1365,44 @@ impl f128 {
13651365
// SAFETY: this is actually a safe intrinsic
13661366
unsafe { intrinsics::copysignf128(self, sign) }
13671367
}
1368+
1369+
/// Float addition that allows optimizations based on algebraic rules.
1370+
#[must_use = "method returns a new number and does not mutate the original value"]
1371+
#[unstable(feature = "float_algebraic", issue = "136469")]
1372+
#[inline]
1373+
pub fn add_algebraic(self, rhs: f128) -> f128 {
1374+
intrinsics::fadd_algebraic(self, rhs)
1375+
}
1376+
1377+
/// Float subtraction that allows optimizations based on algebraic rules.
1378+
#[must_use = "method returns a new number and does not mutate the original value"]
1379+
#[unstable(feature = "float_algebraic", issue = "136469")]
1380+
#[inline]
1381+
pub fn sub_algebraic(self, rhs: f128) -> f128 {
1382+
intrinsics::fsub_algebraic(self, rhs)
1383+
}
1384+
1385+
/// Float multiplication that allows optimizations based on algebraic rules.
1386+
#[must_use = "method returns a new number and does not mutate the original value"]
1387+
#[unstable(feature = "float_algebraic", issue = "136469")]
1388+
#[inline]
1389+
pub fn mul_algebraic(self, rhs: f128) -> f128 {
1390+
intrinsics::fmul_algebraic(self, rhs)
1391+
}
1392+
1393+
/// Float division that allows optimizations based on algebraic rules.
1394+
#[must_use = "method returns a new number and does not mutate the original value"]
1395+
#[unstable(feature = "float_algebraic", issue = "136469")]
1396+
#[inline]
1397+
pub fn div_algebraic(self, rhs: f128) -> f128 {
1398+
intrinsics::fdiv_algebraic(self, rhs)
1399+
}
1400+
1401+
/// Float remainder that allows optimizations based on algebraic rules.
1402+
#[must_use = "method returns a new number and does not mutate the original value"]
1403+
#[unstable(feature = "float_algebraic", issue = "136469")]
1404+
#[inline]
1405+
pub fn rem_algebraic(self, rhs: f128) -> f128 {
1406+
intrinsics::frem_algebraic(self, rhs)
1407+
}
13681408
}

library/core/src/num/f16.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,4 +1341,44 @@ impl f16 {
13411341
// SAFETY: this is actually a safe intrinsic
13421342
unsafe { intrinsics::copysignf16(self, sign) }
13431343
}
1344+
1345+
/// Float addition that allows optimizations based on algebraic rules.
1346+
#[must_use = "method returns a new number and does not mutate the original value"]
1347+
#[unstable(feature = "float_algebraic", issue = "136469")]
1348+
#[inline]
1349+
pub fn add_algebraic(self, rhs: f16) -> f16 {
1350+
intrinsics::fadd_algebraic(self, rhs)
1351+
}
1352+
1353+
/// Float subtraction that allows optimizations based on algebraic rules.
1354+
#[must_use = "method returns a new number and does not mutate the original value"]
1355+
#[unstable(feature = "float_algebraic", issue = "136469")]
1356+
#[inline]
1357+
pub fn sub_algebraic(self, rhs: f16) -> f16 {
1358+
intrinsics::fsub_algebraic(self, rhs)
1359+
}
1360+
1361+
/// Float multiplication that allows optimizations based on algebraic rules.
1362+
#[must_use = "method returns a new number and does not mutate the original value"]
1363+
#[unstable(feature = "float_algebraic", issue = "136469")]
1364+
#[inline]
1365+
pub fn mul_algebraic(self, rhs: f16) -> f16 {
1366+
intrinsics::fmul_algebraic(self, rhs)
1367+
}
1368+
1369+
/// Float division that allows optimizations based on algebraic rules.
1370+
#[must_use = "method returns a new number and does not mutate the original value"]
1371+
#[unstable(feature = "float_algebraic", issue = "136469")]
1372+
#[inline]
1373+
pub fn div_algebraic(self, rhs: f16) -> f16 {
1374+
intrinsics::fdiv_algebraic(self, rhs)
1375+
}
1376+
1377+
/// Float remainder that allows optimizations based on algebraic rules.
1378+
#[must_use = "method returns a new number and does not mutate the original value"]
1379+
#[unstable(feature = "float_algebraic", issue = "136469")]
1380+
#[inline]
1381+
pub fn rem_algebraic(self, rhs: f16) -> f16 {
1382+
intrinsics::frem_algebraic(self, rhs)
1383+
}
13441384
}

0 commit comments

Comments
 (0)