@@ -4,9 +4,7 @@ mod simd;
44#[ cfg( feature = "master" ) ]
55use std:: iter;
66
7- #[ cfg( feature = "master" ) ]
8- use gccjit:: Type ;
9- use gccjit:: { ComparisonOp , Function , FunctionType , RValue , ToRValue , UnaryOp } ;
7+ use gccjit:: { ComparisonOp , Function , FunctionType , RValue , ToRValue , Type , UnaryOp } ;
108#[ cfg( feature = "master" ) ]
119use rustc_abi:: ExternAbi ;
1210use rustc_abi:: { BackendRepr , HasDataLayout , WrappingRange } ;
@@ -40,6 +38,22 @@ use crate::context::CodegenCx;
4038use crate :: intrinsic:: simd:: generic_simd_intrinsic;
4139use crate :: type_of:: LayoutGccExt ;
4240
41+ fn float_intrinsic < ' gcc , ' tcx > (
42+ cx : & CodegenCx < ' gcc , ' tcx > ,
43+ typ : Type < ' gcc > ,
44+ name : & str ,
45+ ) -> Option < Function < ' gcc > > {
46+ // GCC doesn't have the intrinsic we want so we use the compiler-builtins one
47+ Some ( cx. context . new_function (
48+ None ,
49+ FunctionType :: Extern ,
50+ typ,
51+ & [ cx. context . new_parameter ( None , typ, "a" ) , cx. context . new_parameter ( None , typ, "b" ) ] ,
52+ name,
53+ false ,
54+ ) )
55+ }
56+
4357fn get_simple_intrinsic < ' gcc , ' tcx > (
4458 cx : & CodegenCx < ' gcc , ' tcx > ,
4559 name : Symbol ,
@@ -70,65 +84,19 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
7084 // FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7185 sym:: fmuladdf32 => "fmaf" , // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f32
7286 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- }
87+ sym:: minimumf32 => return float_intrinsic ( cx, cx. type_f32 ( ) , "fminimumf" ) ,
88+ sym:: minimumf64 => return float_intrinsic ( cx, cx. type_f64 ( ) , "fminimum" ) ,
89+ sym:: minimumf128 => return float_intrinsic ( cx, cx. type_f128 ( ) , "fminimumf128" ) ,
90+ sym:: maximumf32 => return float_intrinsic ( cx, cx. type_f32 ( ) , "fmaximumf" ) ,
91+ sym:: maximumf64 => return float_intrinsic ( cx, cx. type_f64 ( ) , "fmaximum" ) ,
92+ sym:: maximumf128 => return float_intrinsic ( cx, cx. type_f128 ( ) , "fmaximumf128" ) ,
10993 sym:: copysignf32 => "copysignf" ,
11094 sym:: copysignf64 => "copysign" ,
11195 sym:: floorf32 => "floorf" ,
11296 sym:: floorf64 => "floor" ,
11397 sym:: ceilf32 => "ceilf" ,
11498 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- }
99+ sym:: powf128 => return float_intrinsic ( cx, cx. type_f128 ( ) , "powf128" ) ,
132100 sym:: truncf32 => "truncf" ,
133101 sym:: truncf64 => "trunc" ,
134102 // We match the LLVM backend and lower this to `rint`.
0 commit comments