[flang-commits] [flang] f5ab4bf - [flang] Define IEEE_SCALB, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP

peter klausler via flang-commits flang-commits at lists.llvm.org
Wed Oct 6 12:10:21 PDT 2021


Author: peter klausler
Date: 2021-10-06T12:10:14-07:00
New Revision: f5ab4bfb5bbbc188f53ddfd6765a2418bce0bb8d

URL: https://github.com/llvm/llvm-project/commit/f5ab4bfb5bbbc188f53ddfd6765a2418bce0bb8d
DIFF: https://github.com/llvm/llvm-project/commit/f5ab4bfb5bbbc188f53ddfd6765a2418bce0bb8d.diff

LOG: [flang] Define IEEE_SCALB, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP

These functions were missing from the standard intrinsic module
IEEE_ARITHMETIC.  IEEE_SCALB is an alias for the standard intrinsic
function SCALE(), and the others are defined as new builtin intrinsic
functions.

Differential Revision: https://reviews.llvm.org/D111253

Added: 
    

Modified: 
    flang/lib/Evaluate/fold-real.cpp
    flang/lib/Evaluate/intrinsics.cpp
    flang/module/__fortran_builtins.f90
    flang/module/ieee_arithmetic.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/fold-real.cpp b/flang/lib/Evaluate/fold-real.cpp
index 93b3ce20a75b..f73b733dce6e 100644
--- a/flang/lib/Evaluate/fold-real.cpp
+++ b/flang/lib/Evaluate/fold-real.cpp
@@ -144,6 +144,7 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
   }
   // TODO: dim, dot_product, fraction, matmul,
   // modulo, nearest, norm2, rrspacing, scale,
+  // __builtin_next_after/down/up,
   // set_exponent, spacing, transfer,
   // bessel_jn (transformational) and bessel_yn (transformational)
   return Expr<T>{std::move(funcRef)};

diff  --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 99329ff795fc..2324b780f8e5 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -690,7 +690,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
         {{"a", ExtensibleDerived, Rank::anyOrAssumedRank},
             {"b", ExtensibleDerived, Rank::anyOrAssumedRank}},
         DefaultLogical, Rank::scalar, IntrinsicClass::inquiryFunction},
-    {"scale", {{"x", SameReal}, {"i", AnyInt}}, SameReal},
+    {"scale", {{"x", SameReal}, {"i", AnyInt}}, SameReal}, // == IEEE_SCALB()
     {"scan",
         {{"string", SameChar}, {"set", SameChar},
             {"back", AnyLogical, Rank::elemental, Optionality::optional},
@@ -791,6 +791,9 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
             DefaultingKIND},
         KINDInt},
     {"__builtin_ieee_is_nan", {{"a", AnyFloating}}, DefaultLogical},
+    {"__builtin_ieee_next_after", {{"x", SameReal}, {"y", AnyReal}}, SameReal},
+    {"__builtin_ieee_next_down", {{"x", SameReal}}, SameReal},
+    {"__builtin_ieee_next_up", {{"x", SameReal}}, SameReal},
     {"__builtin_ieee_selected_real_kind", // alias for selected_real_kind
         {{"p", AnyInt, Rank::scalar},
             {"r", AnyInt, Rank::scalar, Optionality::optional},

diff  --git a/flang/module/__fortran_builtins.f90 b/flang/module/__fortran_builtins.f90
index f76e648dc2a8..5d7a0008ec36 100644
--- a/flang/module/__fortran_builtins.f90
+++ b/flang/module/__fortran_builtins.f90
@@ -42,6 +42,9 @@
   procedure(type(__builtin_c_ptr)) :: __builtin_c_loc
 
   intrinsic :: __builtin_ieee_is_nan
+  intrinsic :: __builtin_ieee_next_after, __builtin_ieee_next_down, &
+    __builtin_ieee_next_up
+  intrinsic :: scale ! for ieee_scalb
   intrinsic :: __builtin_ieee_selected_real_kind
   intrinsic :: __builtin_ieee_support_datatype, &
     __builtin_ieee_support_denormal, __builtin_ieee_support_divide, &

diff  --git a/flang/module/ieee_arithmetic.f90 b/flang/module/ieee_arithmetic.f90
index 21fc907ec88b..1d7c32e7e116 100644
--- a/flang/module/ieee_arithmetic.f90
+++ b/flang/module/ieee_arithmetic.f90
@@ -11,6 +11,10 @@ module ieee_arithmetic
 
   use __Fortran_builtins, only: &
     ieee_is_nan => __builtin_ieee_is_nan, &
+    ieee_next_after => __builtin_ieee_next_after, &
+    ieee_next_down => __builtin_ieee_next_down, &
+    ieee_next_up => __builtin_ieee_next_up, &
+    ieee_scalb => scale, &
     ieee_selected_real_kind => __builtin_ieee_selected_real_kind, &
     ieee_support_datatype => __builtin_ieee_support_datatype, &
     ieee_support_denormal => __builtin_ieee_support_denormal, &


        


More information about the flang-commits mailing list