[flang-commits] [flang] [flang] IEEE_SCALB and SCALE - kind=2, kind=3 (PR #135374)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 11 10:50:32 PDT 2025
================
@@ -7593,12 +7593,46 @@ IntrinsicLibrary::genSameTypeAs(mlir::Type resultType,
mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
+ mlir::FloatType floatTy = mlir::dyn_cast<mlir::FloatType>(resultType);
+ if (!floatTy.isF16() && !floatTy.isBF16()) // kind=4,8,10,16
+ return builder.createConvert(
+ loc, resultType,
+ fir::runtime::genScale(builder, loc, args[0], args[1]));
- mlir::Value realX = fir::getBase(args[0]);
- mlir::Value intI = fir::getBase(args[1]);
-
- return builder.createConvert(
- loc, resultType, fir::runtime::genScale(builder, loc, realX, intI));
+ // Convert kind=2,3 arg X to kind=4. Convert kind=4 result back to kind=2,3.
+ mlir::Type i1Ty = builder.getI1Type();
+ mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext());
+ mlir::Value result = builder.createConvert(
+ loc, resultType,
+ fir::runtime::genScale(
+ builder, loc, builder.createConvert(loc, f32Ty, args[0]), args[1]));
+
+ // kind=4 runtime::genScale call may not signal kind=2,3 exceptions.
+ // If X is finite and result is infinite, signal IEEE_OVERFLOW
+ // If X is finite and scale(result, -I) != X, signal IEEE_UNDERFLOW
----------------
vdonaldson wrote:
I don't believe the core correctness of the results of these new kinds is affected by conversions between kinds 2, 3, and 4. I believe that level of correctness is automatically accounted for. I haven't attempted to look at detailed correctness with respect to rounding modes and very low level details of the implementation for either the existing kinds or the new kinds.
https://github.com/llvm/llvm-project/pull/135374
More information about the flang-commits
mailing list