@@ -207,45 +207,45 @@ impl DebugHexF16 for __m512i {
207207 }
208208}
209209
210- trait DebugI16 {
210+ trait DebugAs<T> {
211211 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;
212212}
213213
214- impl DebugI16 for i16 {
214+ impl<T: core::fmt::Display> DebugAs<T> for T {
215215 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
216216 write!(f, "{}", self)
217217 }
218218}
219219
220- impl DebugI16 for __m128i {
221- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
222- let array = unsafe { core::mem::transmute::<_, [i16; 8]>(*self) };
223- debug_simd_finish(f, "__m128i", &array)
224- }
225- }
226-
227- impl DebugI16 for __m256i {
228- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
229- let array = unsafe { core::mem::transmute::<_, [i16; 16]>(*self) };
230- debug_simd_finish(f, "__m256i", &array)
231- }
232- }
233-
234- impl DebugI16 for __m512i {
235- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
236- let array = unsafe { core::mem::transmute::<_, [i16; 32]>(*self) } ;
237- debug_simd_finish(f, "__m512i", &array)
238- }
239- }
240-
241- fn debug_i16<T: DebugI16>(x: T) -> impl core::fmt::Debug {
242- struct DebugWrapper<T>(T );
243- impl<T: DebugI16> core::fmt::Debug for DebugWrapper<T> {
220+ macro_rules! impl_debug_as {
221+ ($simd:ty, $name:expr, $bits:expr, [$($type:ty),+]) => {
222+ $(
223+ impl DebugAs<$type> for $simd {
224+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
225+ const ELEMENT_BITS: usize = core::mem::size_of::<$type>() * 8;
226+ const NUM_ELEMENTS: usize = $bits / ELEMENT_BITS;
227+ let array = unsafe { core::mem::transmute::<_, [$type; NUM_ELEMENTS]>(*self) };
228+ debug_simd_finish(f, $name, &array)
229+ }
230+ }
231+ )+
232+ };
233+ }
234+
235+ impl_debug_as!(__m128i, "__m128i", 128, [u8, i8, u16, i16, u32, i32, u64, i64]);
236+ impl_debug_as!(__m256i, "__m256i", 256, [u8, i8, u16, i16, u32, i32, u64, i64]) ;
237+ impl_debug_as!(__m512i, "__m512i", 512, [u8, i8, u16, i16, u32, i32, u64, i64]);
238+
239+ fn debug_as<V, T>(x: V) -> impl core::fmt::Debug
240+ where V: DebugAs<T>
241+ {
242+ struct DebugWrapper<V, T>(V, core::marker::PhantomData<T> );
243+ impl<V: DebugAs<T>, T> core::fmt::Debug for DebugWrapper<V, T> {
244244 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
245245 self.0.fmt(f)
246246 }
247247 }
248- DebugWrapper(x)
248+ DebugWrapper(x, core::marker::PhantomData )
249249}
250250
251251"# ;
0 commit comments