@@ -625,7 +625,11 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
625
625
mlir::Location loc, mlir::Value x) {
626
626
mlir::func::FuncOp func;
627
627
mlir::Type fltTy = x.getType ();
628
-
628
+ // TODO: for f16/bf16, there are better alternatives that do not require
629
+ // casting the argument (resp. result) to (resp. from) f32, but this requires
630
+ // knowing that the target runtime has been compiled with std::float16_t or
631
+ // std::bfloat16_t support, which is not an information available here for
632
+ // now.
629
633
if (fltTy.isF32 ())
630
634
func = fir::runtime::getRuntimeFunc<mkRTKey (Spacing4)>(loc, builder);
631
635
else if (fltTy.isF64 ())
@@ -634,12 +638,17 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
634
638
func = fir::runtime::getRuntimeFunc<ForcedSpacing10>(loc, builder);
635
639
else if (fltTy.isF128 ())
636
640
func = fir::runtime::getRuntimeFunc<ForcedSpacing16>(loc, builder);
641
+ else if (fltTy.isF16 ())
642
+ func = fir::runtime::getRuntimeFunc<mkRTKey (Spacing2By4)>(loc, builder);
643
+ else if (fltTy.isBF16 ())
644
+ func = fir::runtime::getRuntimeFunc<mkRTKey (Spacing3By4)>(loc, builder);
637
645
else
638
646
fir::intrinsicTypeTODO (builder, fltTy, loc, " SPACING" );
639
647
640
648
auto funcTy = func.getFunctionType ();
641
649
llvm::SmallVector<mlir::Value> args = {
642
650
builder.createConvert (loc, funcTy.getInput (0 ), x)};
643
651
644
- return builder.create <fir::CallOp>(loc, func, args).getResult (0 );
652
+ mlir::Value res = builder.create <fir::CallOp>(loc, func, args).getResult (0 );
653
+ return builder.createConvert (loc, fltTy, res);
645
654
}
0 commit comments