@@ -21,6 +21,93 @@ pub const POLY128_OSTREAM_DEF: &str = r#"std::ostream& operator<<(std::ostream&
21
21
return os;
22
22
}"# ;
23
23
24
+ // Format f16 values (and vectors containing them) in a way that is consistent with C.
25
+ pub const F16_FORMATTING_DEF : & str = r#"
26
+ /// Used to continue `Debug`ging SIMD types as `MySimd(1, 2, 3, 4)`, as they
27
+ /// were before moving to array-based simd.
28
+ #[inline]
29
+ fn debug_simd_finish<T: core::fmt::Debug, const N: usize>(
30
+ formatter: &mut core::fmt::Formatter<'_>,
31
+ type_name: &str,
32
+ array: &[T; N],
33
+ ) -> core::fmt::Result {
34
+ core::fmt::Formatter::debug_tuple_fields_finish(
35
+ formatter,
36
+ type_name,
37
+ &core::array::from_fn::<&dyn core::fmt::Debug, N, _>(|i| &array[i]),
38
+ )
39
+ }
40
+
41
+ #[repr(transparent)]
42
+ struct Hex<T>(T);
43
+
44
+ impl<T: DebugHexF16> core::fmt::Debug for Hex<T> {
45
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46
+ <T as DebugHexF16>::fmt(&self.0, f)
47
+ }
48
+ }
49
+
50
+ fn debug_f16<T: DebugHexF16>(x: T) -> impl core::fmt::Debug {
51
+ Hex(x)
52
+ }
53
+
54
+ trait DebugHexF16 {
55
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result;
56
+ }
57
+
58
+ impl DebugHexF16 for f16 {
59
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
60
+ write!(f, "{:#06x?}", self.to_bits())
61
+ }
62
+ }
63
+
64
+ impl DebugHexF16 for float16x4_t {
65
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66
+ let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 4]>(*self) };
67
+ debug_simd_finish(f, "float16x4_t", &array)
68
+ }
69
+ }
70
+
71
+ impl DebugHexF16 for float16x8_t {
72
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73
+ let array = unsafe { core::mem::transmute::<_, [Hex<f16>; 8]>(*self) };
74
+ debug_simd_finish(f, "float16x8_t", &array)
75
+ }
76
+ }
77
+
78
+ impl DebugHexF16 for float16x4x2_t {
79
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80
+ debug_simd_finish(f, "float16x4x2_t", &[Hex(self.0), Hex(self.1)])
81
+ }
82
+ }
83
+ impl DebugHexF16 for float16x4x3_t {
84
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85
+ debug_simd_finish(f, "float16x4x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)])
86
+ }
87
+ }
88
+ impl DebugHexF16 for float16x4x4_t {
89
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
90
+ debug_simd_finish(f, "float16x4x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)])
91
+ }
92
+ }
93
+
94
+ impl DebugHexF16 for float16x8x2_t {
95
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96
+ debug_simd_finish(f, "float16x8x2_t", &[Hex(self.0), Hex(self.1)])
97
+ }
98
+ }
99
+ impl DebugHexF16 for float16x8x3_t {
100
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
101
+ debug_simd_finish(f, "float16x8x3_t", &[Hex(self.0), Hex(self.1), Hex(self.2)])
102
+ }
103
+ }
104
+ impl DebugHexF16 for float16x8x4_t {
105
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
106
+ debug_simd_finish(f, "float16x8x4_t", &[Hex(self.0), Hex(self.1), Hex(self.2), Hex(self.3)])
107
+ }
108
+ }
109
+ "# ;
110
+
24
111
pub const AARCH_CONFIGURATIONS : & str = r#"
25
112
#![cfg_attr(target_arch = "arm", feature(stdarch_arm_neon_intrinsics))]
26
113
#![cfg_attr(target_arch = "arm", feature(stdarch_aarch32_crc32))]
@@ -30,5 +117,6 @@ pub const AARCH_CONFIGURATIONS: &str = r#"
30
117
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_sha3))]
31
118
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_sm4))]
32
119
#![cfg_attr(any(target_arch = "aarch64", target_arch = "arm64ec"), feature(stdarch_neon_ftts))]
120
+ #![feature(fmt_helpers_for_derive)]
33
121
#![feature(stdarch_neon_f16)]
34
122
"# ;
0 commit comments