diff --git a/library/stdarch/crates/core_arch/src/lib.rs b/library/stdarch/crates/core_arch/src/lib.rs index 2b7fb159130..0c5daffaf05 100644 --- a/library/stdarch/crates/core_arch/src/lib.rs +++ b/library/stdarch/crates/core_arch/src/lib.rs @@ -39,7 +39,8 @@ maybe_uninit_as_bytes, movrs_target_feature, clflushopt_target_feature, - min_adt_const_params + min_adt_const_params, + lang_items, )] #![cfg_attr( test, diff --git a/library/stdarch/crates/core_arch/src/powerpc/mod.rs b/library/stdarch/crates/core_arch/src/powerpc/mod.rs index 9bb1bf22434..e98a738e65f 100644 --- a/library/stdarch/crates/core_arch/src/powerpc/mod.rs +++ b/library/stdarch/crates/core_arch/src/powerpc/mod.rs @@ -2,6 +2,47 @@ pub(crate) mod macros; +/// The IBM extended-precision (double-double) floating-point type. +// FIXME(ppcf128) improve the docs. +#[lang = "ppcf128"] +#[doc(alias = "__ibm128")] +#[doc(alias = "doubledouble")] +#[doc(alias = "f64f64")] +#[unstable(feature = "powerpc_ppcf128", issue = "163323")] +#[allow(non_camel_case_types)] +#[doc(cfg(any(target_arch = "powerpc", target_arch = "powerpc64")))] +#[derive(Clone, Copy)] +pub struct ppcf128(u128); + +#[unstable(feature = "powerpc_ppcf128", issue = "163323")] +impl crate::fmt::Debug for ppcf128 { + fn fmt(&self, f: &mut crate::fmt::Formatter<'_>) -> crate::fmt::Result { + let (hi, lo) = self.to_components(); + write!(f, "ppcf128({hi:?}, {lo:?})") + } +} + +impl ppcf128 { + /// Returns the memory representation of this floating point number as a byte array in + /// native byte order. + #[unstable(feature = "powerpc_ppcf128", issue = "163323")] + #[inline] + pub const fn to_ne_bytes(self) -> [u8; 16] { + // SAFETY: every bit pattern of a `ppcf128` is a valid `[u8; 16]`. + unsafe { crate::mem::transmute::(self) } + } + + /// Returns the large and small component of this floating point number. + #[unstable(feature = "powerpc_ppcf128", issue = "163323")] + #[rustc_const_unstable(feature = "powerpc_ppcf128", issue = "163323")] + #[inline] + pub const fn to_components(self) -> (f64, f64) { + // SAFETY: every bit pattern of a `ppcf128` is a valid `[f64; 2]`. + let [large, small] = unsafe { crate::mem::transmute::(self) }; + (large, small) + } +} + mod altivec; #[unstable(feature = "stdarch_powerpc", issue = "111145")] pub use self::altivec::*; diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 2262c293af6..e7e924f9ebc 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -115,6 +115,24 @@ impl Copy for *const T {} impl Copy for *mut T {} impl Copy for [T; N] {} +pub mod arch { + #[cfg(target_arch = "powerpc")] + pub mod powerpc { + #[lang = "ppcf128"] + pub struct ppcf128(u128); + + impl crate::Copy for ppcf128 {} + } + + #[cfg(any(target_arch = "powerpc64"))] + pub mod powerpc64 { + #[lang = "ppcf128"] + pub struct ppcf128(u128); + + impl crate::Copy for ppcf128 {} + } +} + #[lang = "phantom_data"] pub struct PhantomData; impl Copy for PhantomData {}