2020-09-24 23:44:48 -05:00
|
|
|
macro_rules! debug_wrapper {
|
|
|
|
{ $($trait:ident => $name:ident,)* } => {
|
|
|
|
$(
|
|
|
|
pub(crate) fn $name<T: core::fmt::$trait>(slice: &[T], f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
|
|
#[repr(transparent)]
|
|
|
|
struct Wrapper<'a, T: core::fmt::$trait>(&'a T);
|
|
|
|
|
|
|
|
impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f.debug_list()
|
|
|
|
.entries(slice.iter().map(|x| Wrapper(x)))
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_wrapper! {
|
|
|
|
Debug => format,
|
|
|
|
Binary => format_binary,
|
|
|
|
LowerExp => format_lower_exp,
|
|
|
|
UpperExp => format_upper_exp,
|
|
|
|
Octal => format_octal,
|
|
|
|
LowerHex => format_lower_hex,
|
|
|
|
UpperHex => format_upper_hex,
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_fmt_trait {
|
2020-12-04 23:03:20 -06:00
|
|
|
{ $($type:ident => $(($trait:ident, $format:ident)),*;)* } => {
|
2020-09-24 23:44:48 -05:00
|
|
|
$( // repeat type
|
|
|
|
$( // repeat trait
|
2021-02-09 21:13:27 -06:00
|
|
|
impl<const LANES: usize> core::fmt::$trait for crate::$type<LANES>
|
|
|
|
where
|
2021-07-23 21:54:19 -05:00
|
|
|
crate::LaneCount<LANES>: crate::SupportedLaneCount,
|
2021-02-09 21:13:27 -06:00
|
|
|
{
|
2020-09-24 23:44:48 -05:00
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
|
|
|
$format(self.as_ref(), f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
)*
|
|
|
|
};
|
2020-12-04 23:03:20 -06:00
|
|
|
{ integers: $($type:ident,)* } => {
|
2020-09-24 23:44:48 -05:00
|
|
|
impl_fmt_trait! {
|
|
|
|
$($type =>
|
|
|
|
(Debug, format),
|
|
|
|
(Binary, format_binary),
|
|
|
|
(LowerExp, format_lower_exp),
|
|
|
|
(UpperExp, format_upper_exp),
|
|
|
|
(Octal, format_octal),
|
|
|
|
(LowerHex, format_lower_hex),
|
|
|
|
(UpperHex, format_upper_hex);
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
};
|
2020-12-04 23:03:20 -06:00
|
|
|
{ floats: $($type:ident,)* } => {
|
2020-09-24 23:44:48 -05:00
|
|
|
impl_fmt_trait! {
|
|
|
|
$($type =>
|
|
|
|
(Debug, format),
|
|
|
|
(LowerExp, format_lower_exp),
|
|
|
|
(UpperExp, format_upper_exp);
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
};
|
2020-12-04 23:03:20 -06:00
|
|
|
{ masks: $($type:ident,)* } => {
|
2020-09-24 23:44:48 -05:00
|
|
|
impl_fmt_trait! {
|
|
|
|
$($type =>
|
|
|
|
(Debug, format);
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_fmt_trait! {
|
|
|
|
integers:
|
2021-04-25 18:40:35 -05:00
|
|
|
SimdU8, SimdU16, SimdU32, SimdU64,
|
|
|
|
SimdI8, SimdI16, SimdI32, SimdI64,
|
2020-12-04 23:03:20 -06:00
|
|
|
SimdUsize, SimdIsize,
|
2020-09-24 23:44:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl_fmt_trait! {
|
|
|
|
floats:
|
2020-12-04 23:03:20 -06:00
|
|
|
SimdF32, SimdF64,
|
2020-09-24 23:44:48 -05:00
|
|
|
}
|