Skip to content

Commit a826695

Browse files
committed
Fix maximum/minimum float intrinsics
1 parent 7db7c9b commit a826695

1 file changed

Lines changed: 23 additions & 53 deletions

File tree

src/intrinsic/mod.rs

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ use crate::context::CodegenCx;
4040
use crate::intrinsic::simd::generic_simd_intrinsic;
4141
use crate::type_of::LayoutGccExt;
4242

43+
fn float_intrinsic<'gcc, 'tcx>(
44+
cx: &CodegenCx<'gcc, 'tcx>,
45+
typ: Type<'gcc>,
46+
name: &str,
47+
) -> Option<Function<'gcc>> {
48+
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
49+
Some(cx.context.new_function(
50+
None,
51+
FunctionType::Extern,
52+
typ,
53+
&[cx.context.new_parameter(None, typ, "a"), cx.context.new_parameter(None, typ, "b")],
54+
name,
55+
false,
56+
))
57+
}
58+
4359
fn get_simple_intrinsic<'gcc, 'tcx>(
4460
cx: &CodegenCx<'gcc, 'tcx>,
4561
name: Symbol,
@@ -70,65 +86,19 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
7086
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7187
sym::fmuladdf32 => "fmaf", // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f32
7288
sym::fmuladdf64 => "fma", // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f64
73-
sym::minimumf32 => "fminimumf",
74-
sym::minimumf64 => "fminimum",
75-
sym::minimumf128 => {
76-
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
77-
// https://docs.rs/compiler_builtins/latest/compiler_builtins/math/full_availability/fn.fminimumf128.html
78-
let f128_type = cx.type_f128();
79-
return Some(cx.context.new_function(
80-
None,
81-
FunctionType::Extern,
82-
f128_type,
83-
&[
84-
cx.context.new_parameter(None, f128_type, "a"),
85-
cx.context.new_parameter(None, f128_type, "b"),
86-
],
87-
"fminimumf128",
88-
false,
89-
));
90-
}
91-
sym::maximumf32 => "fmaximumf",
92-
sym::maximumf64 => "fmaximum",
93-
sym::maximumf128 => {
94-
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
95-
// https://docs.rs/compiler_builtins/latest/compiler_builtins/math/full_availability/fn.fmaximumf128.html
96-
let f128_type = cx.type_f128();
97-
return Some(cx.context.new_function(
98-
None,
99-
FunctionType::Extern,
100-
f128_type,
101-
&[
102-
cx.context.new_parameter(None, f128_type, "a"),
103-
cx.context.new_parameter(None, f128_type, "b"),
104-
],
105-
"fmaximumf128",
106-
false,
107-
));
108-
}
89+
sym::minimumf32 => return float_intrinsic(cx, cx.type_f32(), "fminimumf"),
90+
sym::minimumf64 => return float_intrinsic(cx, cx.type_f64(), "fminimum"),
91+
sym::minimumf128 => return float_intrinsic(cx, cx.type_f128(), "fminimumf128"),
92+
sym::maximumf32 => return float_intrinsic(cx, cx.type_f32(), "fmaximumf"),
93+
sym::maximumf64 => return float_intrinsic(cx, cx.type_f64(), "fmaximum"),
94+
sym::maximumf128 => return float_intrinsic(cx, cx.type_f128(), "fmaximumf128"),
10995
sym::copysignf32 => "copysignf",
11096
sym::copysignf64 => "copysign",
11197
sym::floorf32 => "floorf",
11298
sym::floorf64 => "floor",
11399
sym::ceilf32 => "ceilf",
114100
sym::ceilf64 => "ceil",
115-
sym::powf128 => {
116-
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one.
117-
// FIXME(antoyo): there's some duplication here with functions like minimumf128,
118-
// copysignf128 and maximumf128.
119-
let f128_type = cx.type_f128();
120-
return Some(cx.context.new_function(
121-
None,
122-
FunctionType::Extern,
123-
f128_type,
124-
&[
125-
cx.context.new_parameter(None, f128_type, "a"),
126-
cx.context.new_parameter(None, f128_type, "b"),
127-
],
128-
"powf128",
129-
false,
130-
));
131-
}
101+
sym::powf128 => return float_intrinsic(cx, cx.type_f128(), "powf128"),
132102
sym::truncf32 => "truncf",
133103
sym::truncf64 => "trunc",
134104
// We match the LLVM backend and lower this to `rint`.

0 commit comments

Comments
 (0)