1
1
//! Various operations on integer and floating-point numbers
2
2
3
+ use crate :: codegen_f16_f128;
3
4
use crate :: prelude:: * ;
4
5
5
6
fn bin_op_to_intcc ( bin_op : BinOp , signed : bool ) -> IntCC {
@@ -350,25 +351,60 @@ pub(crate) fn codegen_float_binop<'tcx>(
350
351
let lhs = in_lhs. load_scalar ( fx) ;
351
352
let rhs = in_rhs. load_scalar ( fx) ;
352
353
354
+ // FIXME(bytecodealliance/wasmtime#8312): Remove once backend lowerings have
355
+ // been added to Cranelift.
356
+ let ( lhs, rhs) = if * in_lhs. layout ( ) . ty . kind ( ) == ty:: Float ( FloatTy :: F16 ) {
357
+ ( codegen_f16_f128:: f16_to_f32 ( fx, lhs) , codegen_f16_f128:: f16_to_f32 ( fx, rhs) )
358
+ } else {
359
+ ( lhs, rhs)
360
+ } ;
353
361
let b = fx. bcx . ins ( ) ;
354
362
let res = match bin_op {
363
+ // FIXME(bytecodealliance/wasmtime#8312): Remove once backend lowerings
364
+ // have been added to Cranelift.
365
+ BinOp :: Add | BinOp :: Sub | BinOp :: Mul | BinOp :: Div
366
+ if * in_lhs. layout ( ) . ty . kind ( ) == ty:: Float ( FloatTy :: F128 ) =>
367
+ {
368
+ codegen_f16_f128:: codegen_f128_binop ( fx, bin_op, lhs, rhs)
369
+ }
355
370
BinOp :: Add => b. fadd ( lhs, rhs) ,
356
371
BinOp :: Sub => b. fsub ( lhs, rhs) ,
357
372
BinOp :: Mul => b. fmul ( lhs, rhs) ,
358
373
BinOp :: Div => b. fdiv ( lhs, rhs) ,
359
374
BinOp :: Rem => {
360
- let ( name, ty) = match in_lhs. layout ( ) . ty . kind ( ) {
361
- ty:: Float ( FloatTy :: F32 ) => ( "fmodf" , types:: F32 ) ,
362
- ty:: Float ( FloatTy :: F64 ) => ( "fmod" , types:: F64 ) ,
375
+ let ( name, ty, lhs, rhs) = match in_lhs. layout ( ) . ty . kind ( ) {
376
+ ty:: Float ( FloatTy :: F16 ) => (
377
+ "fmodf" ,
378
+ types:: F32 ,
379
+ // FIXME(bytecodealliance/wasmtime#8312): Already converted
380
+ // by the FIXME above.
381
+ // fx.bcx.ins().fpromote(types::F32, lhs),
382
+ // fx.bcx.ins().fpromote(types::F32, rhs),
383
+ lhs,
384
+ rhs,
385
+ ) ,
386
+ ty:: Float ( FloatTy :: F32 ) => ( "fmodf" , types:: F32 , lhs, rhs) ,
387
+ ty:: Float ( FloatTy :: F64 ) => ( "fmod" , types:: F64 , lhs, rhs) ,
388
+ ty:: Float ( FloatTy :: F128 ) => ( "fmodf128" , types:: F128 , lhs, rhs) ,
363
389
_ => bug ! ( ) ,
364
390
} ;
365
391
366
- fx. lib_call (
392
+ let ret_val = fx. lib_call (
367
393
name,
368
394
vec ! [ AbiParam :: new( ty) , AbiParam :: new( ty) ] ,
369
395
vec ! [ AbiParam :: new( ty) ] ,
370
396
& [ lhs, rhs] ,
371
- ) [ 0 ]
397
+ ) [ 0 ] ;
398
+
399
+ let ret_val = if * in_lhs. layout ( ) . ty . kind ( ) == ty:: Float ( FloatTy :: F16 ) {
400
+ // FIXME(bytecodealliance/wasmtime#8312): Use native Cranelift
401
+ // operation once Cranelift backend lowerings have been
402
+ // implemented.
403
+ codegen_f16_f128:: f32_to_f16 ( fx, ret_val)
404
+ } else {
405
+ ret_val
406
+ } ;
407
+ return CValue :: by_val ( ret_val, in_lhs. layout ( ) ) ;
372
408
}
373
409
BinOp :: Eq | BinOp :: Lt | BinOp :: Le | BinOp :: Ne | BinOp :: Ge | BinOp :: Gt => {
374
410
let fltcc = match bin_op {
@@ -386,6 +422,13 @@ pub(crate) fn codegen_float_binop<'tcx>(
386
422
_ => unreachable ! ( "{:?}({:?}, {:?})" , bin_op, in_lhs, in_rhs) ,
387
423
} ;
388
424
425
+ // FIXME(bytecodealliance/wasmtime#8312): Remove once backend lowerings have
426
+ // been added to Cranelift.
427
+ let res = if * in_lhs. layout ( ) . ty . kind ( ) == ty:: Float ( FloatTy :: F16 ) {
428
+ codegen_f16_f128:: f32_to_f16 ( fx, res)
429
+ } else {
430
+ res
431
+ } ;
389
432
CValue :: by_val ( res, in_lhs. layout ( ) )
390
433
}
391
434
0 commit comments