diff --git a/src/codegen_f16_f128.rs b/src/codegen_f16_f128.rs index 1e202be1f..c2406197f 100644 --- a/src/codegen_f16_f128.rs +++ b/src/codegen_f16_f128.rs @@ -1,3 +1,4 @@ +use crate::compiler_builtins::CMP_RESULT_TY; use crate::prelude::*; pub(crate) fn f16_to_f32(fx: &mut FunctionCx<'_, '_, '_>, value: Value) -> Value { @@ -70,13 +71,10 @@ pub(crate) fn fcmp(fx: &mut FunctionCx<'_, '_, '_>, cc: FloatCC, lhs: Value, rhs let res = fx.lib_call( name, vec![AbiParam::new(types::F128), AbiParam::new(types::F128)], - // FIXME(rust-lang/compiler-builtins#919): This should be `I64` on non-AArch64 - // architectures, but switching it before compiler-builtins is fixed causes test - // failures. - vec![AbiParam::new(types::I32)], + vec![AbiParam::new(CMP_RESULT_TY)], &[lhs, rhs], )[0]; - let zero = fx.bcx.ins().iconst(types::I32, 0); + let zero = fx.bcx.ins().iconst(CMP_RESULT_TY, 0); let res = fx.bcx.ins().icmp(int_cc, res, zero); res } diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 155bf8668..ca9157daa 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -3,11 +3,34 @@ use std::ffi::c_int; #[cfg(feature = "jit")] use std::ffi::c_void; +use cranelift_codegen::ir::{Type, types}; + // FIXME replace with core::ffi::c_size_t once stabilized #[allow(non_camel_case_types)] #[cfg(feature = "jit")] type size_t = usize; +// Needs to stay in sync with compiler-builtins + +// Aarch64 uses `int` rather than a pointer-sized value. +#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] +#[cfg(feature = "jit")] +type CmpResult = i32; +#[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] +pub(crate) const CMP_RESULT_TY: Type = types::I32; + +// In compiler-rt, LLP64 ABIs use `long long` and everything else uses `long`. In effect, +// this means the return value is always pointer-sized. +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(feature = "jit")] +type CmpResult = isize; +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(target_pointer_width = "32")] +pub(crate) const CMP_RESULT_TY: Type = types::I32; +#[cfg(not(any(target_arch = "aarch64", target_arch = "arm64ec")))] +#[cfg(target_pointer_width = "64")] +pub(crate) const CMP_RESULT_TY: Type = types::I64; + macro_rules! builtin_functions { ( $register:ident; @@ -88,12 +111,12 @@ builtin_functions! { #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fmodf128(a: f128, b: f128) -> f128; // float comparison - fn __eqtf2(a: f128, b: f128) -> i32; - fn __netf2(a: f128, b: f128) -> i32; - fn __lttf2(a: f128, b: f128) -> i32; - fn __letf2(a: f128, b: f128) -> i32; - fn __gttf2(a: f128, b: f128) -> i32; - fn __getf2(a: f128, b: f128) -> i32; + fn __eqtf2(a: f128, b: f128) -> CmpResult; + fn __netf2(a: f128, b: f128) -> CmpResult; + fn __lttf2(a: f128, b: f128) -> CmpResult; + fn __letf2(a: f128, b: f128) -> CmpResult; + fn __gttf2(a: f128, b: f128) -> CmpResult; + fn __getf2(a: f128, b: f128) -> CmpResult; #[cfg(not(all(target_os = "windows", target_env = "gnu")))] fn fminimumf128(a: f128, b: f128) -> f128; #[cfg(not(all(target_os = "windows", target_env = "gnu")))]