@@ -207,45 +207,45 @@ impl DebugHexF16 for __m512i {
207
207
}
208
208
}
209
209
210
- trait DebugI16 {
210
+ trait DebugAs<T> {
211
211
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;
212
212
}
213
213
214
- impl DebugI16 for i16 {
214
+ impl<T: core::fmt::Display> DebugAs<T> for T {
215
215
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
216
216
write!(f, "{}", self)
217
217
}
218
218
}
219
219
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> {
244
244
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
245
245
self.0.fmt(f)
246
246
}
247
247
}
248
- DebugWrapper(x)
248
+ DebugWrapper(x, core::marker::PhantomData )
249
249
}
250
250
251
251
"# ;
0 commit comments