Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
| sym::contract_check_ensures
| sym::contract_check_requires
| sym::contract_checks
| sym::copysignf16
| sym::copysignf32
| sym::copysignf64
| sym::copysignf128
| sym::cosf16
| sym::cosf32
| sym::cosf64
Expand All @@ -106,6 +110,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
| sym::expf32
| sym::expf64
| sym::expf128
| sym::fabsf16
| sym::fabsf32
| sym::fabsf64
| sym::fabsf128
| sym::fadd_algebraic
| sym::fdiv_algebraic
| sym::floorf16
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,7 +3170,7 @@ pub const fn maximumf128(x: f128, y: f128) -> f128 {
/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn fabsf16(x: f16) -> f16;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side remark: fabsf16 and fabsf128 aren't used in their corresponding fn abs definitions, so, I'm assuming they're "not ready yet" in that sense. However, they can still be marked safe for consistency.

pub const fn fabsf16(x: f16) -> f16;

/// Returns the absolute value of an `f32`.
///
Expand All @@ -3179,7 +3179,7 @@ pub const unsafe fn fabsf16(x: f16) -> f16;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn fabsf32(x: f32) -> f32;
pub const fn fabsf32(x: f32) -> f32;

/// Returns the absolute value of an `f64`.
///
Expand All @@ -3188,23 +3188,23 @@ pub const unsafe fn fabsf32(x: f32) -> f32;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn fabsf64(x: f64) -> f64;
pub const fn fabsf64(x: f64) -> f64;

/// Returns the absolute value of an `f128`.
///
/// The stabilized version of this intrinsic is
/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn fabsf128(x: f128) -> f128;
pub const fn fabsf128(x: f128) -> f128;

/// Copies the sign from `y` to `x` for `f16` values.
///
/// The stabilized version of this intrinsic is
/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
pub const fn copysignf16(x: f16, y: f16) -> f16;

/// Copies the sign from `y` to `x` for `f32` values.
///
Expand All @@ -3213,23 +3213,23 @@ pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
pub const fn copysignf32(x: f32, y: f32) -> f32;
/// Copies the sign from `y` to `x` for `f64` values.
///
/// The stabilized version of this intrinsic is
/// [`f64::copysign`](../../std/primitive.f64.html#method.copysign)
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
pub const fn copysignf64(x: f64, y: f64) -> f64;

/// Copies the sign from `y` to `x` for `f128` values.
///
/// The stabilized version of this intrinsic is
/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
pub const fn copysignf128(x: f128, y: f128) -> f128;

/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
/// with `df` as the derivative function and `args` as its arguments.
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,7 @@ impl f128 {
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn copysign(self, sign: f128) -> f128 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf128(self, sign) }
intrinsics::copysignf128(self, sign)
}

/// Float addition that allows optimizations based on algebraic rules.
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,7 @@ impl f16 {
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn copysign(self, sign: f16) -> f16 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf16(self, sign) }
intrinsics::copysignf16(self, sign)
}

/// Float addition that allows optimizations based on algebraic rules.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,7 @@ impl f32 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn abs(self) -> f32 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::fabsf32(self) }
intrinsics::fabsf32(self)
}

/// Returns a number that represents the sign of `self`.
Expand Down Expand Up @@ -1508,8 +1507,7 @@ impl f32 {
#[stable(feature = "copysign", since = "1.35.0")]
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
pub const fn copysign(self, sign: f32) -> f32 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf32(self, sign) }
intrinsics::copysignf32(self, sign)
}

/// Float addition that allows optimizations based on algebraic rules.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,7 @@ impl f64 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn abs(self) -> f64 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::fabsf64(self) }
intrinsics::fabsf64(self)
}

/// Returns a number that represents the sign of `self`.
Expand Down Expand Up @@ -1506,8 +1505,7 @@ impl f64 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn copysign(self, sign: f64) -> f64 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf64(self, sign) }
intrinsics::copysignf64(self, sign)
}

/// Float addition that allows optimizations based on algebraic rules.
Expand Down
Loading