|
5 | 5 |
|
6 | 6 | #![feature(f16)]
|
7 | 7 | #![feature(f128)]
|
| 8 | +#![feature(cfg_target_has_reliable_f16_f128)] |
8 | 9 | #![allow(unused_macro_rules)]
|
| 10 | +// expect the unexpected (`target_has_reliable_*` are not "known" configs since they are unstable) |
| 11 | +#![expect(unexpected_cfgs)] |
9 | 12 |
|
10 | 13 | use std::hint::black_box;
|
11 | 14 |
|
12 | 15 | macro_rules! both_assert {
|
13 |
| - ($a:expr) => { |
14 |
| - { |
15 |
| - const _: () = assert!($a); |
16 |
| - // `black_box` prevents promotion, and MIR opts are disabled above, so this is truly |
17 |
| - // going through LLVM. |
18 |
| - assert!(black_box($a)); |
19 |
| - } |
20 |
| - }; |
21 |
| - ($a:expr, $b:expr) => { |
22 |
| - { |
23 |
| - const _: () = assert!($a == $b); |
24 |
| - assert_eq!(black_box($a), black_box($b)); |
25 |
| - } |
26 |
| - }; |
| 16 | + ($a:expr) => {{ |
| 17 | + const _: () = assert!($a); |
| 18 | + // `black_box` prevents promotion, and MIR opts are disabled above, so this is truly |
| 19 | + // going through LLVM. |
| 20 | + assert!(black_box($a)); |
| 21 | + }}; |
| 22 | + ($a:expr, $b:expr) => {{ |
| 23 | + const _: () = assert!($a == $b); |
| 24 | + assert_eq!(black_box($a), black_box($b)); |
| 25 | + }}; |
27 | 26 | }
|
28 | 27 |
|
29 | 28 | fn has_broken_floats() -> bool {
|
30 | 29 | // i586 targets are broken due to <https://github.com/rust-lang/rust/issues/114479>.
|
31 | 30 | cfg!(all(target_arch = "x86", not(target_feature = "sse2")))
|
32 | 31 | }
|
33 | 32 |
|
34 |
| -#[cfg(target_arch = "x86_64")] |
35 |
| -fn f16(){ |
| 33 | +#[cfg(target_has_reliable_f16)] |
| 34 | +fn f16() { |
36 | 35 | both_assert!((1f16).to_bits(), 0x3c00);
|
37 | 36 | both_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00);
|
38 | 37 | both_assert!((12.5f16).to_bits(), 0x4a40);
|
@@ -122,7 +121,7 @@ fn f64() {
|
122 | 121 | }
|
123 | 122 | }
|
124 | 123 |
|
125 |
| -#[cfg(target_arch = "x86_64")] |
| 124 | +#[cfg(target_has_reliable_f128)] |
126 | 125 | fn f128() {
|
127 | 126 | both_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
|
128 | 127 | both_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
|
@@ -154,12 +153,10 @@ fn f128() {
|
154 | 153 | }
|
155 | 154 |
|
156 | 155 | fn main() {
|
| 156 | + #[cfg(target_has_reliable_f16)] |
| 157 | + f16(); |
157 | 158 | f32();
|
158 | 159 | f64();
|
159 |
| - |
160 |
| - #[cfg(target_arch = "x86_64")] |
161 |
| - { |
162 |
| - f16(); |
163 |
| - f128(); |
164 |
| - } |
| 160 | + #[cfg(target_has_reliable_f128)] |
| 161 | + f128(); |
165 | 162 | }
|
0 commit comments