[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
Sun Jun 13 09:45:53 PDT 2021


SaurabhJha created this revision.
Herald added a subscriber: tschuett.
SaurabhJha requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds examples of compound assignment and type conversions for matrix types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104198

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===================================================================
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -523,6 +523,41 @@
     return a + b * c;
   }
 
+The matrix type extension supports compound assignments for addition, subtraction, and multiplication, provided
+their types are consistent.
+
+.. code-block:: c++
+
+  typedef float m4x4_t __attribute__((matrix_type(4, 4)));
+
+  void f(m4x4_t a, m4x4_t b) {
+    a += b;
+    a -= b;
+    a *= b;
+  }
+
+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)));
+
+  void f1(ix5x5 i, fx5x5 f) {
+    f = (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
 =============================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104198.351727.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210613/fc6022f2/attachment.bin>


More information about the cfe-commits mailing list