Use the correct return type for compiler-builtins float compares

This commit is contained in:
bjorn3
2025-10-01 11:40:02 +00:00
parent 160c1091fb
commit 992c2c6b01
2 changed files with 32 additions and 11 deletions
+3 -5
View File
@@ -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
}
+29 -6
View File
@@ -3,11 +3,34 @@
#[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 @@ pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) {
#[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")))]