Author: Saurabh Jha Date: 2021-06-24T15:50:58+01:00 New Revision: cd256c8bcc9723f0ce7a32957f26600c966fa07c
URL: https://github.com/llvm/llvm-project/commit/cd256c8bcc9723f0ce7a32957f26600c966fa07c DIFF: https://github.com/llvm/llvm-project/commit/cd256c8bcc9723f0ce7a32957f26600c966fa07c.diff LOG: Add documentation for compound assignment and type conversion of matrix types Added: Modified: clang/docs/LanguageExtensions.rst Removed: ################################################################################ diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index c60b8b39e1c9e..f9e1208634b91 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -523,6 +523,63 @@ float matrices and add the result to a third 4x4 matrix. return a + b * c; } +The matrix type extension also supports operations on 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 on a matrix and a scalar but not on 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. 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 ============================= _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits