[PATCH] D104198: [Matrix] Add documentation for compound assignment and type conversion of matrix types

Saurabh Jha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 23 07:45:43 PDT 2021


SaurabhJha updated this revision to Diff 353970.
SaurabhJha added a comment.
Herald added a project: clang-tools-extra.

Did a --amend to rebuild


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104198

Files:
  clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===================================================================
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,64 @@
     return a + b * c;
   }
 
+The matrix type extension also supports operations between a matrix and a scalar.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+      return (a + 23) * 12;
+  }
+
+The matrix type extension supports division between a matrix and a scalar but not between a matrix and a matrix.
+
+.. code-block:: c++
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a) {
+    a = a / 3.0;
+    return a;
+  }
+
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication between matrices
+and between a matrix and a scalar, provided their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  m4x4_t f(m4x4_t a, m4x4_t b) {
+    a += b;
+    a -= b;
+    a *= b;
+    a += 23;
+    a -= 12;
+    return a;
+  }
+
+The matrix type extension supports explicit casts. The casts we support are C-style casts in C and C++ and
+static casts. Implicit type conversion between matrix types is not allowed.
+
+.. code-block:: c++
+
+  typedef int ix5x5 __attribute__((matrix_type(5, 5)));
+  typedef float fx5x5 __attribute__((matrix_type(5, 5)));
+
+  fx5x5 f1(ix5x5 i, fx5x5 f) {
+    return (fx5x5) i;
+  }
+
+
+  template <typename X>
+  using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
+
+  void f2() {
+    matrix_5_5<double> d;
+    matrix_5_5<int> i;
+    i = (matrix_5_5<int>)d;
+    i = static_cast<matrix_5_5<int>>(d);
+  }
 
 Half-Precision Floating Point
 =============================
Index: clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
===================================================================
--- clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
+++ clang-tools-extra/clang-reorder-fields/tool/ClangReorderFields.cpp
@@ -80,7 +80,7 @@
 
   auto &FileMgr = Tool.getFiles();
   SourceManager Sources(Diagnostics, FileMgr);
-  Rewriter Rewrite(Sources, DefaultLangOptions);
+  Rewriter Rewrite(Sources, DefaultLangOptions); // TODO: Ally Donaldson
   Tool.applyAllReplacements(Rewrite);
 
   for (const auto &File : Files) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104198.353970.patch
Type: text/x-patch
Size: 2406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210623/4d4cf14b/attachment-0001.bin>


More information about the cfe-commits mailing list