Skip to content

Commit 7def335

Browse files
committed
Fix ABI for f16 builtins on Intel Apple targets
1 parent 41d37b4 commit 7def335

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/float/extend.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ intrinsics! {
8787
#[avr_skip]
8888
#[aapcs_on_arm]
8989
#[arm_aeabi_alias = __aeabi_h2f]
90+
#[apple_f16_arg_abi]
9091
#[cfg(f16_enabled)]
9192
pub extern "C" fn __extendhfsf2(a: f16) -> f32 {
9293
extend(a)
9394
}
9495

9596
#[avr_skip]
9697
#[aapcs_on_arm]
98+
#[apple_f16_arg_abi]
9799
#[cfg(f16_enabled)]
98100
pub extern "C" fn __gnu_h2f_ieee(a: f16) -> f32 {
99101
extend(a)

src/float/trunc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@ intrinsics! {
135135
#[avr_skip]
136136
#[aapcs_on_arm]
137137
#[arm_aeabi_alias = __aeabi_f2h]
138+
#[apple_f16_ret_abi]
138139
#[cfg(f16_enabled)]
139140
pub extern "C" fn __truncsfhf2(a: f32) -> f16 {
140141
trunc(a)
141142
}
142143

143144
#[avr_skip]
144145
#[aapcs_on_arm]
146+
#[apple_f16_ret_abi]
145147
#[cfg(f16_enabled)]
146148
pub extern "C" fn __gnu_f2h_ieee(a: f32) -> f16 {
147149
trunc(a)
@@ -150,6 +152,7 @@ intrinsics! {
150152
#[avr_skip]
151153
#[aapcs_on_arm]
152154
#[arm_aeabi_alias = __aeabi_d2h]
155+
#[apple_f16_ret_abi]
153156
#[cfg(f16_enabled)]
154157
pub extern "C" fn __truncdfhf2(a: f64) -> f16 {
155158
trunc(a)

src/macros.rs

+71
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,77 @@ macro_rules! intrinsics {
276276
intrinsics!($($rest)*);
277277
);
278278

279+
// On x86 (32-bit and 64-bit) Apple platforms, `f16` is passed and returned like a `u16` unless
280+
// the builtin involves `f128`.
281+
(
282+
#[apple_f16_arg_abi]
283+
$(#[$($attr:tt)*])*
284+
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
285+
$($body:tt)*
286+
}
287+
288+
$($rest:tt)*
289+
) => (
290+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64")))]
291+
$(#[$($attr)*])*
292+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
293+
$($body)*
294+
}
295+
296+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
297+
mod $name {
298+
#[no_mangle]
299+
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
300+
extern $abi fn $name( $($argname: u16),* ) $(-> $ret)? {
301+
super::$name($(f16::from_bits($argname)),*)
302+
}
303+
}
304+
305+
#[cfg(not(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"))))]
306+
intrinsics! {
307+
$(#[$($attr)*])*
308+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
309+
$($body)*
310+
}
311+
}
312+
313+
intrinsics!($($rest)*);
314+
);
315+
(
316+
#[apple_f16_ret_abi]
317+
$(#[$($attr:tt)*])*
318+
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
319+
$($body:tt)*
320+
}
321+
322+
$($rest:tt)*
323+
) => (
324+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64")))]
325+
$(#[$($attr)*])*
326+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
327+
$($body)*
328+
}
329+
330+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
331+
mod $name {
332+
#[no_mangle]
333+
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
334+
extern $abi fn $name( $($argname: $ty),* ) -> u16 {
335+
super::$name($($argname),*).to_bits()
336+
}
337+
}
338+
339+
#[cfg(not(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"))))]
340+
intrinsics! {
341+
$(#[$($attr)*])*
342+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
343+
$($body)*
344+
}
345+
}
346+
347+
intrinsics!($($rest)*);
348+
);
349+
279350
// A bunch of intrinsics on ARM are aliased in the standard compiler-rt
280351
// build under `__aeabi_*` aliases, and LLVM will call these instead of the
281352
// original function. The aliasing here is used to generate these symbols in

0 commit comments

Comments
 (0)