@@ -23,11 +23,11 @@ use rustc_codegen_ssa::traits::{
2323 IntrinsicCallBuilderMethods , LayoutTypeCodegenMethods ,
2424} ;
2525use rustc_data_structures:: fx:: FxHashSet ;
26- use rustc_middle:: bug;
2726#[ cfg( feature = "master" ) ]
2827use rustc_middle:: ty:: layout:: FnAbiOf ;
2928use rustc_middle:: ty:: layout:: LayoutOf ;
3029use rustc_middle:: ty:: { self , Instance , Ty } ;
30+ use rustc_middle:: { bug, span_bug} ;
3131use rustc_span:: { Span , Symbol , sym} ;
3232use rustc_target:: callconv:: { ArgAbi , PassMode } ;
3333
@@ -70,8 +70,6 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
7070 // FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7171 sym:: fmuladdf32 => "fmaf" , // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f32
7272 sym:: fmuladdf64 => "fma" , // FIXME: use gcc intrinsic analogous to llvm.fmuladd.f64
73- sym:: fabsf32 => "fabsf" ,
74- sym:: fabsf64 => "fabs" ,
7573 sym:: minimumf32 => "fminimumf" ,
7674 sym:: minimumf64 => "fminimum" ,
7775 sym:: minimumf128 => {
@@ -194,58 +192,29 @@ fn get_simple_function<'gcc, 'tcx>(
194192}
195193
196194fn get_simple_function_f128 < ' gcc , ' tcx > (
195+ span : Span ,
197196 cx : & CodegenCx < ' gcc , ' tcx > ,
198197 name : Symbol ,
199- ) -> Option < Function < ' gcc > > {
200- if !cx. supports_f128_type {
201- return None ;
202- }
203-
198+ ) -> Function < ' gcc > {
204199 let f128_type = cx. type_f128 ( ) ;
205200 let func_name = match name {
206201 sym:: ceilf128 => "ceilf128" ,
207- sym:: fabsf128 => "fabsf128" ,
202+ sym:: fabs => "fabsf128" ,
208203 sym:: floorf128 => "floorf128" ,
209204 sym:: truncf128 => "truncf128" ,
210205 sym:: roundf128 => "roundf128" ,
211206 sym:: round_ties_even_f128 => "roundevenf128" ,
212207 sym:: sqrtf128 => "sqrtf128" ,
213- _ => return None ,
208+ _ => span_bug ! ( span , "used get_simple_function_f128 for non-unary f128 intrinsic" ) ,
214209 } ;
215- Some ( cx. context . new_function (
210+ cx. context . new_function (
216211 None ,
217212 FunctionType :: Extern ,
218213 f128_type,
219214 & [ cx. context . new_parameter ( None , f128_type, "a" ) ] ,
220215 func_name,
221216 false ,
222- ) )
223- }
224-
225- fn get_simple_function_f128_2args < ' gcc , ' tcx > (
226- cx : & CodegenCx < ' gcc , ' tcx > ,
227- name : Symbol ,
228- ) -> Option < Function < ' gcc > > {
229- if !cx. supports_f128_type {
230- return None ;
231- }
232-
233- let f128_type = cx. type_f128 ( ) ;
234- let func_name = match name {
235- sym:: copysignf128 => "copysignf128" ,
236- _ => return None ,
237- } ;
238- Some ( cx. context . new_function (
239- None ,
240- FunctionType :: Extern ,
241- f128_type,
242- & [
243- cx. context . new_parameter ( None , f128_type, "a" ) ,
244- cx. context . new_parameter ( None , f128_type, "b" ) ,
245- ] ,
246- func_name,
247- false ,
248- ) )
217+ )
249218}
250219
251220fn f16_builtin < ' gcc , ' tcx > (
@@ -257,7 +226,7 @@ fn f16_builtin<'gcc, 'tcx>(
257226 let builtin_name = match name {
258227 sym:: ceilf16 => "__builtin_ceilf" ,
259228 sym:: copysignf16 => "__builtin_copysignf" ,
260- sym:: fabsf16 => "fabsf" ,
229+ sym:: fabs => "fabsf" ,
261230 sym:: floorf16 => "__builtin_floorf" ,
262231 sym:: fmaf16 => "fmaf" ,
263232 sym:: powf16 => "__builtin_powf" ,
@@ -297,11 +266,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
297266 let fn_args = instance. args ;
298267
299268 let simple = get_simple_intrinsic ( self , name) ;
300- // FIXME(antoyo): Only call get_simple_function_f128 and get_simple_function_f128_2args when
301- // it is the symbols for the supported f128 builtins.
302- let simple_func = get_simple_function ( self , name)
303- . or_else ( || get_simple_function_f128 ( self , name) )
304- . or_else ( || get_simple_function_f128_2args ( self , name) ) ;
269+ let simple_func = get_simple_function ( self , name) ;
305270
306271 let value = match name {
307272 _ if simple. is_some ( ) => {
@@ -322,7 +287,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
322287 }
323288 sym:: ceilf16
324289 | sym:: copysignf16
325- | sym:: fabsf16
326290 | sym:: floorf16
327291 | sym:: fmaf16
328292 | sym:: powf16
@@ -331,6 +295,40 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
331295 | sym:: round_ties_even_f16
332296 | sym:: sqrtf16
333297 | sym:: truncf16 => f16_builtin ( self , name, args) ,
298+ sym:: ceilf128
299+ | sym:: floorf128
300+ | sym:: truncf128
301+ | sym:: roundf128
302+ | sym:: round_ties_even_f128
303+ | sym:: sqrtf128
304+ if self . cx . supports_f128_type =>
305+ {
306+ let func = get_simple_function_f128 ( span, self , name) ;
307+ self . cx . context . new_call (
308+ self . location ,
309+ func,
310+ & args. iter ( ) . map ( |arg| arg. immediate ( ) ) . collect :: < Vec < _ > > ( ) ,
311+ )
312+ }
313+ sym:: copysignf128 if self . cx . supports_f128_type => {
314+ let f128_type = self . cx . type_f128 ( ) ;
315+ let func = self . cx . context . new_function (
316+ None ,
317+ FunctionType :: Extern ,
318+ f128_type,
319+ & [
320+ self . cx . context . new_parameter ( None , f128_type, "a" ) ,
321+ self . cx . context . new_parameter ( None , f128_type, "b" ) ,
322+ ] ,
323+ "copysignf128" ,
324+ false ,
325+ ) ;
326+ self . cx . context . new_call (
327+ self . location ,
328+ func,
329+ & args. iter ( ) . map ( |arg| arg. immediate ( ) ) . collect :: < Vec < _ > > ( ) ,
330+ )
331+ }
334332 sym:: fmaf128 => {
335333 let f128_type = self . cx . type_f128 ( ) ;
336334 let func = self . cx . context . new_function (
@@ -488,6 +486,23 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
488486 }
489487 }
490488 }
489+ sym:: fabs => ' fabs: {
490+ let ty = args[ 0 ] . layout . ty ;
491+ let ty:: Float ( float_ty) = * ty. kind ( ) else {
492+ span_bug ! ( span, "expected float type for fabs intrinsic: {:?}" , ty) ;
493+ } ;
494+ let func = match float_ty {
495+ ty:: FloatTy :: F16 => break ' fabs f16_builtin ( self , name, args) ,
496+ ty:: FloatTy :: F32 => self . context . get_builtin_function ( "fabsf" ) ,
497+ ty:: FloatTy :: F64 => self . context . get_builtin_function ( "fabs" ) ,
498+ ty:: FloatTy :: F128 => get_simple_function_f128 ( span, self , name) ,
499+ } ;
500+ self . cx . context . new_call (
501+ self . location ,
502+ func,
503+ & args. iter ( ) . map ( |arg| arg. immediate ( ) ) . collect :: < Vec < _ > > ( ) ,
504+ )
505+ }
491506
492507 sym:: raw_eq => {
493508 use rustc_abi:: BackendRepr :: * ;
0 commit comments