Skip to content

Commit f47e0c7

Browse files
committed
Handle Win64 builtins ABI change in LLVM 14
As of https://reviews.llvm.org/D110413, these no longer use the unadjusted ABI (and use normal C ABI instead, passing i128 indirectly and returning it as <2 x i64>). To support both LLVM 14 and older versions, rustc will expose a "llvm14-builtins-abi" target feature, based on which compiler-builtins can chose the appropriate ABI. This is needed for rust-lang/rust#93577.
1 parent d5e097e commit f47e0c7

File tree

1 file changed

+81
-35
lines changed

1 file changed

+81
-35
lines changed

src/float/conv.rs

+81-35
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,6 @@ intrinsics! {
109109
}
110110
}
111111

112-
#[unadjusted_on_win64]
113-
pub extern "C" fn __floattisf(i: i128) -> f32 {
114-
int_to_float(i)
115-
}
116-
117-
#[unadjusted_on_win64]
118-
pub extern "C" fn __floattidf(i: i128) -> f64 {
119-
int_to_float(i)
120-
}
121-
122112
#[arm_aeabi_alias = __aeabi_ui2f]
123113
pub extern "C" fn __floatunsisf(i: u32) -> f32 {
124114
int_to_float(i)
@@ -140,16 +130,6 @@ intrinsics! {
140130
pub extern "C" fn __floatundidf(i: u64) -> f64 {
141131
int_to_float(i)
142132
}
143-
144-
#[unadjusted_on_win64]
145-
pub extern "C" fn __floatuntisf(i: u128) -> f32 {
146-
int_to_float(i)
147-
}
148-
149-
#[unadjusted_on_win64]
150-
pub extern "C" fn __floatuntidf(i: u128) -> f64 {
151-
int_to_float(i)
152-
}
153133
}
154134

155135
fn float_to_int<F: Float, I: Int>(f: F) -> I
@@ -224,11 +204,6 @@ intrinsics! {
224204
float_to_int(f)
225205
}
226206

227-
#[unadjusted_on_win64]
228-
pub extern "C" fn __fixsfti(f: f32) -> i128 {
229-
float_to_int(f)
230-
}
231-
232207
#[arm_aeabi_alias = __aeabi_d2iz]
233208
pub extern "C" fn __fixdfsi(f: f64) -> i32 {
234209
float_to_int(f)
@@ -239,11 +214,6 @@ intrinsics! {
239214
float_to_int(f)
240215
}
241216

242-
#[unadjusted_on_win64]
243-
pub extern "C" fn __fixdfti(f: f64) -> i128 {
244-
float_to_int(f)
245-
}
246-
247217
#[arm_aeabi_alias = __aeabi_f2uiz]
248218
pub extern "C" fn __fixunssfsi(f: f32) -> u32 {
249219
float_to_int(f)
@@ -254,11 +224,6 @@ intrinsics! {
254224
float_to_int(f)
255225
}
256226

257-
#[unadjusted_on_win64]
258-
pub extern "C" fn __fixunssfti(f: f32) -> u128 {
259-
float_to_int(f)
260-
}
261-
262227
#[arm_aeabi_alias = __aeabi_d2uiz]
263228
pub extern "C" fn __fixunsdfsi(f: f64) -> u32 {
264229
float_to_int(f)
@@ -268,6 +233,87 @@ intrinsics! {
268233
pub extern "C" fn __fixunsdfdi(f: f64) -> u64 {
269234
float_to_int(f)
270235
}
236+
}
237+
238+
// The ABI for the following intrinsics changed in LLVM 14. On Win64, they now
239+
// use Win64 ABI rather than unadjusted ABI. Pick the correct ABI based on the
240+
// llvm14-builtins-abi target feature.
241+
242+
#[cfg(target_feature = "llvm14-builtins-abi")]
243+
intrinsics! {
244+
pub extern "C" fn __floattisf(i: i128) -> f32 {
245+
int_to_float(i)
246+
}
247+
248+
pub extern "C" fn __floattidf(i: i128) -> f64 {
249+
int_to_float(i)
250+
}
251+
252+
pub extern "C" fn __floatuntisf(i: u128) -> f32 {
253+
int_to_float(i)
254+
}
255+
256+
pub extern "C" fn __floatuntidf(i: u128) -> f64 {
257+
int_to_float(i)
258+
}
259+
260+
#[win64_128bit_abi_hack]
261+
pub extern "C" fn __fixsfti(f: f32) -> i128 {
262+
float_to_int(f)
263+
}
264+
265+
#[win64_128bit_abi_hack]
266+
pub extern "C" fn __fixdfti(f: f64) -> i128 {
267+
float_to_int(f)
268+
}
269+
270+
#[win64_128bit_abi_hack]
271+
pub extern "C" fn __fixunssfti(f: f32) -> u128 {
272+
float_to_int(f)
273+
}
274+
275+
#[win64_128bit_abi_hack]
276+
pub extern "C" fn __fixunsdfti(f: f64) -> u128 {
277+
float_to_int(f)
278+
}
279+
}
280+
281+
#[cfg(not(target_feature = "llvm14-builtins-abi"))]
282+
intrinsics! {
283+
#[unadjusted_on_win64]
284+
pub extern "C" fn __floattisf(i: i128) -> f32 {
285+
int_to_float(i)
286+
}
287+
288+
#[unadjusted_on_win64]
289+
pub extern "C" fn __floattidf(i: i128) -> f64 {
290+
int_to_float(i)
291+
}
292+
293+
#[unadjusted_on_win64]
294+
pub extern "C" fn __floatuntisf(i: u128) -> f32 {
295+
int_to_float(i)
296+
}
297+
298+
#[unadjusted_on_win64]
299+
pub extern "C" fn __floatuntidf(i: u128) -> f64 {
300+
int_to_float(i)
301+
}
302+
303+
#[unadjusted_on_win64]
304+
pub extern "C" fn __fixsfti(f: f32) -> i128 {
305+
float_to_int(f)
306+
}
307+
308+
#[unadjusted_on_win64]
309+
pub extern "C" fn __fixdfti(f: f64) -> i128 {
310+
float_to_int(f)
311+
}
312+
313+
#[unadjusted_on_win64]
314+
pub extern "C" fn __fixunssfti(f: f32) -> u128 {
315+
float_to_int(f)
316+
}
271317

272318
#[unadjusted_on_win64]
273319
pub extern "C" fn __fixunsdfti(f: f64) -> u128 {

0 commit comments

Comments
 (0)