Index: flang/include/flang/Runtime/numeric.h =================================================================== --- flang/include/flang/Runtime/numeric.h +++ flang/include/flang/Runtime/numeric.h @@ -18,90 +18,6 @@ namespace Fortran::runtime { extern "C" { -// AINT -CppTypeFor RTNAME(Aint4_4)( - CppTypeFor); -CppTypeFor RTNAME(Aint4_8)( - CppTypeFor); -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Aint4_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -CppTypeFor RTNAME(Aint4_16)( - CppTypeFor); -#endif -CppTypeFor RTNAME(Aint8_4)( - CppTypeFor); -CppTypeFor RTNAME(Aint8_8)( - CppTypeFor); -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Aint8_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -CppTypeFor RTNAME(Aint8_16)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Aint10_4)( - CppTypeFor); -CppTypeFor RTNAME(Aint10_8)( - CppTypeFor); -CppTypeFor RTNAME(Aint10_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -CppTypeFor RTNAME(Aint16_4)( - CppTypeFor); -CppTypeFor RTNAME(Aint16_8)( - CppTypeFor); -CppTypeFor RTNAME(Aint16_16)( - CppTypeFor); -#endif - -// ANINT -CppTypeFor RTNAME(Anint4_4)( - CppTypeFor); -CppTypeFor RTNAME(Anint4_8)( - CppTypeFor); -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Anint4_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -CppTypeFor RTNAME(Anint4_16)( - CppTypeFor); -#endif -CppTypeFor RTNAME(Anint8_4)( - CppTypeFor); -CppTypeFor RTNAME(Anint8_8)( - CppTypeFor); -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Anint8_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 -CppTypeFor RTNAME(Anint8_16)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Anint10_4)( - CppTypeFor); -CppTypeFor RTNAME(Anint10_8)( - CppTypeFor); -CppTypeFor RTNAME(Anint10_10)( - CppTypeFor); -#endif -#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 -CppTypeFor RTNAME(Anint16_4)( - CppTypeFor); -CppTypeFor RTNAME(Anint16_8)( - CppTypeFor); -CppTypeFor RTNAME(Anint16_16)( - CppTypeFor); -#endif - // CEILING CppTypeFor RTNAME(Ceiling4_1)( CppTypeFor); Index: flang/lib/Lower/IntrinsicCall.cpp =================================================================== --- flang/lib/Lower/IntrinsicCall.cpp +++ flang/lib/Lower/IntrinsicCall.cpp @@ -1034,6 +1034,16 @@ return mlir::FunctionType::get(context, {t}, {t}); } +static mlir::FunctionType genF80F80FuncType(mlir::MLIRContext *context) { + mlir::Type t = mlir::FloatType::getF80(context); + return mlir::FunctionType::get(context, {t}, {t}); +} + +static mlir::FunctionType genF128F128FuncType(mlir::MLIRContext *context) { + mlir::Type t = mlir::FloatType::getF128(context); + return mlir::FunctionType::get(context, {t}, {t}); +} + static mlir::FunctionType genF32F32F32FuncType(mlir::MLIRContext *context) { auto t = mlir::FloatType::getF32(context); return mlir::FunctionType::get(context, {t, t}, {t}); @@ -1235,8 +1245,12 @@ {"abs", "llvm.fabs.f64", genF64F64FuncType}, {"aint", "llvm.trunc.f32", genF32F32FuncType}, {"aint", "llvm.trunc.f64", genF64F64FuncType}, + {"aint", "llvm.trunc.f80", genF80F80FuncType}, + {"aint", "llvm.trunc.f128", genF128F128FuncType}, {"anint", "llvm.round.f32", genF32F32FuncType}, {"anint", "llvm.round.f64", genF64F64FuncType}, + {"anint", "llvm.round.f80", genF80F80FuncType}, + {"anint", "llvm.round.f128", genF128F128FuncType}, {"atan", "atanf", genF32F32FuncType}, {"atan", "atan", genF64F64FuncType}, // ceil is used for CEILING but is different, it returns a real. Index: flang/runtime/numeric.cpp =================================================================== --- flang/runtime/numeric.cpp +++ flang/runtime/numeric.cpp @@ -16,13 +16,8 @@ namespace Fortran::runtime { -// AINT -template inline RESULT Aint(ARG x) { - return std::trunc(x); -} - -// ANINT & NINT -template inline RESULT Anint(ARG x) { +// NINT (16.9.141) +template inline RESULT Nint(ARG x) { if (x >= 0) { return std::trunc(x + ARG{0.5}); } else { @@ -163,126 +158,6 @@ extern "C" { -CppTypeFor RTNAME(Aint4_4)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint4_8)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint8_4)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint8_8)( - CppTypeFor x) { - return Aint>(x); -} -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Aint4_10)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint8_10)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint10_4)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint10_8)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint10_10)( - CppTypeFor x) { - return Aint>(x); -} -#elif LDBL_MANT_DIG == 113 -CppTypeFor RTNAME(Aint4_16)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint8_16)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint16_4)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint16_8)( - CppTypeFor x) { - return Aint>(x); -} -CppTypeFor RTNAME(Aint16_16)( - CppTypeFor x) { - return Aint>(x); -} -#endif - -CppTypeFor RTNAME(Anint4_4)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint4_8)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint8_4)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint8_8)( - CppTypeFor x) { - return Anint>(x); -} -#if LDBL_MANT_DIG == 64 -CppTypeFor RTNAME(Anint4_10)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint8_10)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint10_4)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint10_8)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint10_10)( - CppTypeFor x) { - return Anint>(x); -} -#elif LDBL_MANT_DIG == 113 -CppTypeFor RTNAME(Anint4_16)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint8_16)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint16_4)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint16_8)( - CppTypeFor x) { - return Anint>(x); -} -CppTypeFor RTNAME(Anint16_16)( - CppTypeFor x) { - return Anint>(x); -} -#endif - CppTypeFor RTNAME(Ceiling4_1)( CppTypeFor x) { return Ceiling>(x); @@ -689,92 +564,92 @@ CppTypeFor RTNAME(Nint4_1)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint4_2)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint4_4)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint4_8)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #ifdef __SIZEOF_INT128__ CppTypeFor RTNAME(Nint4_16)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #endif CppTypeFor RTNAME(Nint8_1)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint8_2)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint8_4)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint8_8)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #ifdef __SIZEOF_INT128__ CppTypeFor RTNAME(Nint8_16)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #endif #if LDBL_MANT_DIG == 64 CppTypeFor RTNAME(Nint10_1)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint10_2)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint10_4)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint10_8)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #ifdef __SIZEOF_INT128__ CppTypeFor RTNAME(Nint10_16)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #endif #elif LDBL_MANT_DIG == 113 CppTypeFor RTNAME(Nint16_1)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint16_2)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint16_4)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } CppTypeFor RTNAME(Nint16_8)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #ifdef __SIZEOF_INT128__ CppTypeFor RTNAME(Nint16_16)( CppTypeFor x) { - return Anint>(x); + return Nint>(x); } #endif #endif Index: flang/test/Lower/Intrinsics/numeric-128bit.f90 =================================================================== --- /dev/null +++ flang/test/Lower/Intrinsics/numeric-128bit.f90 @@ -0,0 +1,30 @@ +! REQUIRES: shell +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: func.func @_QPaint_test( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "a"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "b"}) { +! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref +! CHECK: %[[VAL_3:.*]] = fir.call @llvm.trunc.f128(%[[VAL_2]]) : (f128) -> f128 +! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref +! CHECK: return +! CHECK: } + +subroutine aint_test(a, b) + real(16) :: a, b + b = aint(a) +end subroutine + +! CHECK-LABEL: func.func @_QPanint_test( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "a"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "b"}) { +! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref +! CHECK: %[[VAL_3:.*]] = fir.call @llvm.round.f128(%[[VAL_2]]) : (f128) -> f128 +! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref +! CHECK: return +! CHECK: } + +subroutine anint_test(a, b) + real(16) :: a, b + b = anint(a) +end subroutine Index: flang/unittests/Runtime/Numeric.cpp =================================================================== --- flang/unittests/Runtime/Numeric.cpp +++ flang/unittests/Runtime/Numeric.cpp @@ -18,28 +18,6 @@ // Simple tests of numeric intrinsic functions using examples from Fortran 2018 -TEST(Numeric, Aint) { - EXPECT_EQ(RTNAME(Aint4_4)(Real<4>{3.7}), 3.0); - EXPECT_EQ(RTNAME(Aint8_4)(Real<8>{-3.7}), -3.0); - EXPECT_EQ(RTNAME(Aint8_8)(Real<8>{0}), 0.0); - EXPECT_EQ(RTNAME(Aint4_4)(std::numeric_limits>::infinity()), - std::numeric_limits>::infinity()); - EXPECT_TRUE( - std::isnan(RTNAME(Aint8_8)(std::numeric_limits>::quiet_NaN()))); -} - -TEST(Numeric, Anint) { - EXPECT_EQ(RTNAME(Anint4_4)(Real<4>{2.783}), 3.0); - EXPECT_EQ(RTNAME(Anint8_4)(Real<8>{-2.783}), -3.0); - EXPECT_EQ(RTNAME(Anint4_4)(Real<4>{2.5}), 3.0); - EXPECT_EQ(RTNAME(Anint8_4)(Real<8>{-2.5}), -3.0); - EXPECT_EQ(RTNAME(Anint8_8)(Real<8>{0}), 0.0); - EXPECT_EQ(RTNAME(Anint4_4)(std::numeric_limits>::infinity()), - std::numeric_limits>::infinity()); - EXPECT_TRUE( - std::isnan(RTNAME(Aint8_8)(std::numeric_limits>::quiet_NaN()))); -} - TEST(Numeric, Ceiling) { EXPECT_EQ(RTNAME(Ceiling4_4)(Real<4>{3.7}), 4); EXPECT_EQ(RTNAME(Ceiling8_8)(Real<8>{-3.7}), -3);