Skip to content

Commit 54d9376

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

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

Diff for: src/float/extend.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ intrinsics! {
8686
intrinsics! {
8787
#[avr_skip]
8888
#[aapcs_on_arm]
89-
#[arm_aeabi_alias = __aeabi_h2f]
89+
#[apple_f16_arg_abi, arm_aeabi_alias = __aeabi_h2f]
9090
#[cfg(f16_enabled)]
9191
pub extern "C" fn __extendhfsf2(a: f16) -> f32 {
9292
extend(a)
9393
}
9494

9595
#[avr_skip]
9696
#[aapcs_on_arm]
97+
#[apple_f16_arg_abi]
9798
#[cfg(f16_enabled)]
9899
pub extern "C" fn __gnu_h2f_ieee(a: f16) -> f32 {
99100
extend(a)

Diff for: src/float/trunc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,23 @@ intrinsics! {
134134
intrinsics! {
135135
#[avr_skip]
136136
#[aapcs_on_arm]
137-
#[arm_aeabi_alias = __aeabi_f2h]
137+
#[apple_f16_ret_abi, arm_aeabi_alias = __aeabi_f2h]
138138
#[cfg(f16_enabled)]
139139
pub extern "C" fn __truncsfhf2(a: f32) -> f16 {
140140
trunc(a)
141141
}
142142

143143
#[avr_skip]
144144
#[aapcs_on_arm]
145+
#[apple_f16_ret_abi]
145146
#[cfg(f16_enabled)]
146147
pub extern "C" fn __gnu_f2h_ieee(a: f32) -> f16 {
147148
trunc(a)
148149
}
149150

150151
#[avr_skip]
151152
#[aapcs_on_arm]
152-
#[arm_aeabi_alias = __aeabi_d2h]
153+
#[apple_f16_ret_abi, arm_aeabi_alias = __aeabi_d2h]
153154
#[cfg(f16_enabled)]
154155
pub extern "C" fn __truncdfhf2(a: f64) -> f16 {
155156
trunc(a)

Diff for: src/macros.rs

+77
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,83 @@ 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+
// `arm_aeabi_alias` would conflict if not handled here. Avoid macro ambiguity by combining
283+
// in a single `#[]`.
284+
#[apple_f16_arg_abi $(, arm_aeabi_alias = $alias:ident)?]
285+
$(#[$($attr:tt)*])*
286+
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
287+
$($body:tt)*
288+
}
289+
290+
$($rest:tt)*
291+
) => (
292+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64")))]
293+
$(#[$($attr)*])*
294+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
295+
$($body)*
296+
}
297+
298+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
299+
mod $name {
300+
#[no_mangle]
301+
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
302+
$(#[$($attr)*])*
303+
extern $abi fn $name( $($argname: u16),* ) $(-> $ret)? {
304+
super::$name($(f16::from_bits($argname)),*)
305+
}
306+
}
307+
308+
#[cfg(not(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"))))]
309+
intrinsics! {
310+
$(#[arm_aeabi_alias = $alias])?
311+
$(#[$($attr)*])*
312+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
313+
$($body)*
314+
}
315+
}
316+
317+
intrinsics!($($rest)*);
318+
);
319+
(
320+
#[apple_f16_ret_abi $(, arm_aeabi_alias = $alias:ident)?]
321+
$(#[$($attr:tt)*])*
322+
pub extern $abi:tt fn $name:ident( $($argname:ident: $ty:ty),* ) $(-> $ret:ty)? {
323+
$($body:tt)*
324+
}
325+
326+
$($rest:tt)*
327+
) => (
328+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64")))]
329+
$(#[$($attr)*])*
330+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
331+
$($body)*
332+
}
333+
334+
#[cfg(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"), not(feature = "mangled-names")))]
335+
mod $name {
336+
#[no_mangle]
337+
#[cfg_attr(not(all(windows, target_env = "gnu")), linkage = "weak")]
338+
$(#[$($attr)*])*
339+
extern $abi fn $name( $($argname: $ty),* ) -> u16 {
340+
super::$name($($argname),*).to_bits()
341+
}
342+
}
343+
344+
#[cfg(not(all(target_vendor = "apple", any(target_arch = "x86", target_arch = "x86_64"))))]
345+
intrinsics! {
346+
$(#[arm_aeabi_alias = $alias])?
347+
$(#[$($attr)*])*
348+
pub extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
349+
$($body)*
350+
}
351+
}
352+
353+
intrinsics!($($rest)*);
354+
);
355+
279356
// A bunch of intrinsics on ARM are aliased in the standard compiler-rt
280357
// build under `__aeabi_*` aliases, and LLVM will call these instead of the
281358
// original function. The aliasing here is used to generate these symbols in

0 commit comments

Comments
 (0)