@@ -141,6 +141,24 @@ fn get_simple_function_f128<'gcc, 'tcx>(
141141 )
142142}
143143
144+ fn generic_f16_builtin < ' gcc , ' tcx > (
145+ cx : & CodegenCx < ' gcc , ' tcx > ,
146+ name : Symbol ,
147+ args : & [ OperandRef < ' tcx , RValue < ' gcc > > ] ,
148+ ) -> RValue < ' gcc > {
149+ let f32_type = cx. type_f32 ( ) ;
150+ let builtin_name = match name {
151+ sym:: fabs => "fabsf" ,
152+ _ => unreachable ! ( ) ,
153+ } ;
154+
155+ let func = cx. context . get_builtin_function ( builtin_name) ;
156+ let args: Vec < _ > =
157+ args. iter ( ) . map ( |arg| cx. context . new_cast ( None , arg. immediate ( ) , f32_type) ) . collect ( ) ;
158+ let result = cx. context . new_call ( None , func, & args) ;
159+ cx. context . new_cast ( None , result, cx. type_f16 ( ) )
160+ }
161+
144162fn f16_builtin < ' gcc , ' tcx > (
145163 cx : & CodegenCx < ' gcc , ' tcx > ,
146164 name : Symbol ,
@@ -150,7 +168,6 @@ fn f16_builtin<'gcc, 'tcx>(
150168 let builtin_name = match name {
151169 sym:: ceilf16 => "__builtin_ceilf" ,
152170 sym:: copysignf16 => "__builtin_copysignf" ,
153- sym:: fabs => "fabsf" ,
154171 sym:: expf16 => "expf" ,
155172 sym:: exp2f16 => "exp2f" ,
156173 sym:: floorf16 => "__builtin_floorf" ,
@@ -228,7 +245,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
228245 | sym:: copysignf16
229246 | sym:: expf16
230247 | sym:: exp2f16
231- | sym:: fabs
232248 | sym:: floorf16
233249 | sym:: fmaf16
234250 | sym:: logf16
@@ -448,7 +464,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
448464 span_bug ! ( span, "expected float type for fabs intrinsic: {:?}" , ty) ;
449465 } ;
450466 let func = match float_ty {
451- ty:: FloatTy :: F16 => break ' fabs f16_builtin ( self , name, args) ,
467+ ty:: FloatTy :: F16 => break ' fabs generic_f16_builtin ( self , name, args) ,
452468 ty:: FloatTy :: F32 => self . context . get_builtin_function ( "fabsf" ) ,
453469 ty:: FloatTy :: F64 => self . context . get_builtin_function ( "fabs" ) ,
454470 ty:: FloatTy :: F128 => get_simple_function_f128 ( span, self , name) ,
0 commit comments