@@ -625,7 +625,11 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
625625 mlir::Location loc, mlir::Value x) {
626626 mlir::func::FuncOp func;
627627 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.
629633 if (fltTy.isF32 ())
630634 func = fir::runtime::getRuntimeFunc<mkRTKey (Spacing4)>(loc, builder);
631635 else if (fltTy.isF64 ())
@@ -634,12 +638,17 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
634638 func = fir::runtime::getRuntimeFunc<ForcedSpacing10>(loc, builder);
635639 else if (fltTy.isF128 ())
636640 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);
637645 else
638646 fir::intrinsicTypeTODO (builder, fltTy, loc, " SPACING" );
639647
640648 auto funcTy = func.getFunctionType ();
641649 llvm::SmallVector<mlir::Value> args = {
642650 builder.createConvert (loc, funcTy.getInput (0 ), x)};
643651
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);
645654}
0 commit comments