[PATCH] D106292: [flang] Implement the runtime portion of the CSHIFT intrinsic

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 21 12:03:28 PDT 2021


PeteSteinfeld updated this revision to Diff 360545.
PeteSteinfeld added a comment.

Responding to Jean's comments by reverting my change to the vector version of
CSHIFT.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106292/new/

https://reviews.llvm.org/D106292

Files:
  flang/runtime/transformational.cpp
  flang/unittests/RuntimeGTest/Transformational.cpp


Index: flang/unittests/RuntimeGTest/Transformational.cpp
===================================================================
--- flang/unittests/RuntimeGTest/Transformational.cpp
+++ flang/unittests/RuntimeGTest/Transformational.cpp
@@ -60,6 +60,44 @@
   }
   result.Destroy();
 
+  // VECTOR  1 3 5 2 4 6
+  auto vector{MakeArray<TypeCategory::Integer, 4>(
+      std::vector<int>{6}, std::vector<std::int32_t>{1, 2, 3, 4, 5, 6})};
+  vector->GetDimension(0).SetLowerBound(0);
+  StaticDescriptor<1, true> vectorDesc;
+  Descriptor &vectorResult{vectorDesc.descriptor()};
+
+  auto shiftVector{MakeArray<TypeCategory::Integer, 8>(
+      std::vector<int>{1}, std::vector<std::int64_t>{2})};
+  RTNAME(CshiftVector)(vectorResult, *vector, *shiftVector, __FILE__, __LINE__);
+  EXPECT_EQ(vectorResult.type(), array->type());
+  EXPECT_EQ(vectorResult.rank(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).LowerBound(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).Extent(), 6);
+  EXPECT_EQ(vectorResult.type(), (TypeCode{TypeCategory::Integer, 4}));
+  static std::int32_t cshiftExpect3[6]{3, 4, 5, 6, 1, 2};
+  for (int j{0}; j < 6; ++j) {
+    EXPECT_EQ(*vectorResult.ZeroBasedIndexedElement<std::int32_t>(j),
+        cshiftExpect3[j]);
+  }
+  vectorResult.Destroy();
+
+  auto shiftVector1{MakeArray<TypeCategory::Integer, 8>(
+      std::vector<int>{1}, std::vector<std::int64_t>{-2})};
+  RTNAME(CshiftVector)
+  (vectorResult, *vector, *shiftVector1, __FILE__, __LINE__);
+  EXPECT_EQ(vectorResult.type(), array->type());
+  EXPECT_EQ(vectorResult.rank(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).LowerBound(), 1);
+  EXPECT_EQ(vectorResult.GetDimension(0).Extent(), 6);
+  EXPECT_EQ(vectorResult.type(), (TypeCode{TypeCategory::Integer, 4}));
+  static std::int32_t cshiftExpect4[6]{5, 6, 1, 2, 3, 4};
+  for (int j{0}; j < 6; ++j) {
+    EXPECT_EQ(*vectorResult.ZeroBasedIndexedElement<std::int32_t>(j),
+        cshiftExpect4[j]);
+  }
+  vectorResult.Destroy();
+
   auto boundary{MakeArray<TypeCategory::Integer, 4>(
       std::vector<int>{3}, std::vector<std::int32_t>{-1, -2, -3})};
   boundary->GetDimension(0).SetLowerBound(9); // shouldn't matter
Index: flang/runtime/transformational.cpp
===================================================================
--- flang/runtime/transformational.cpp
+++ flang/runtime/transformational.cpp
@@ -130,7 +130,7 @@
 
 extern "C" {
 
-// CSHIFT of rank > 1
+// CSHIFT where rank of ARRAY argument > 1
 void RTNAME(Cshift)(Descriptor &result, const Descriptor &source,
     const Descriptor &shift, int dim, const char *sourceFile, int line) {
   Terminator terminator{sourceFile, line};
@@ -172,7 +172,7 @@
   }
 }
 
-// CSHIFT of vector
+// CSHIFT where rank of ARRAY argument == 1
 void RTNAME(CshiftVector)(Descriptor &result, const Descriptor &source,
     std::int64_t shift, const char *sourceFile, int line) {
   Terminator terminator{sourceFile, line};
@@ -184,6 +184,9 @@
   for (SubscriptValue j{0}; j < extent; ++j) {
     SubscriptValue resultAt{1 + j};
     SubscriptValue sourceAt{lb + (j + shift) % extent};
+    if (sourceAt < 0) {
+      sourceAt += extent;
+    }
     CopyElement(result, &resultAt, source, &sourceAt, terminator);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106292.360545.patch
Type: text/x-patch
Size: 3222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210721/81e0759b/attachment.bin>


More information about the llvm-commits mailing list