armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 1 | // Copyright 2015, ARM Limited |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are met: |
| 6 | // |
| 7 | // * Redistributions of source code must retain the above copyright notice, |
| 8 | // this list of conditions and the following disclaimer. |
| 9 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // * Neither the name of ARM Limited nor the names of its contributors may be |
| 13 | // used to endorse or promote products derived from this software without |
| 14 | // specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND |
| 17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 20 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | |
| 27 | #ifndef VIXL_EXAMPLE_EXAMPLES_H_ |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 28 | #define VIXL_EXAMPLE_EXAMPLES_H_ |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 29 | |
Alexandre Rames | 39c32a6 | 2016-05-23 15:47:22 +0100 | [diff] [blame] | 30 | #include "a64/debugger-a64.h" |
| 31 | #include "a64/macro-assembler-a64.h" |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 32 | |
| 33 | using namespace vixl; |
| 34 | |
| 35 | // Generate a function with the following prototype: |
| 36 | // uint64_t factorial(uint64_t n) |
| 37 | // |
| 38 | // It provides an iterative implementation of the factorial computation. |
| 39 | void GenerateFactorial(MacroAssembler* masm); |
| 40 | |
| 41 | // Generate a function with the following prototype: |
| 42 | // uint64_t factorial_rec(uint64_t n) |
| 43 | // |
| 44 | // It provides a recursive implementation of the factorial computation. |
| 45 | void GenerateFactorialRec(MacroAssembler* masm); |
| 46 | |
| 47 | // Generate a function with the following prototype: |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 48 | // void neon_matrix_multiply(float* dst, float* mat1, float* mat2) |
| 49 | // |
| 50 | // It provides an implementation of a column-major 4x4 matrix multiplication. |
| 51 | void GenerateNEONMatrixMultiply(MacroAssembler* masm); |
| 52 | |
| 53 | // Generate a function with the following prototype: |
| 54 | // void add2_vectors(int8_t *vecA, const int8_t *vecB, unsigned size) |
| 55 | // |
| 56 | // Demonstrate how to add two vectors using NEON. The result is stored in vecA. |
| 57 | void GenerateAdd2Vectors(MacroAssembler* masm); |
| 58 | |
| 59 | // Generate a function with the following prototype: |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 60 | // double add3_double(double x, double y, double z) |
| 61 | // |
| 62 | // This example is intended to show the calling convention with double |
| 63 | // floating point arguments. |
| 64 | void GenerateAdd3Double(MacroAssembler* masm); |
| 65 | |
| 66 | // Generate a function with the following prototype: |
| 67 | // double add4_double(uint64_t a, double b, uint64_t c, double d) |
| 68 | // |
| 69 | // The generated function pictures the calling convention for functions |
| 70 | // mixing integer and floating point arguments. |
| 71 | void GenerateAdd4Double(MacroAssembler* masm); |
| 72 | |
| 73 | // Generate a function with the following prototype: |
| 74 | // uint32_t sum_array(uint8_t* array, uint32_t size) |
| 75 | // |
| 76 | // The generated function computes the sum of all the elements in |
| 77 | // the given array. |
| 78 | void GenerateSumArray(MacroAssembler* masm); |
| 79 | |
| 80 | // Generate a function with the following prototype: |
| 81 | // int64_t abs(int64_t x) |
| 82 | // |
| 83 | // The generated function computes the absolute value of an integer. |
| 84 | void GenerateAbs(MacroAssembler* masm); |
| 85 | |
| 86 | // Generate a function with the following prototype: |
| 87 | // uint64_t check_bounds(uint64_t value, uint64_t low, uint64_t high) |
| 88 | // |
| 89 | // The goal of this example is to illustrate the use of conditional |
| 90 | // instructions. The generated function will check that the given value is |
| 91 | // contained within the given boundaries. It returns 1 if 'value' is between |
| 92 | // 'low' and 'high' (ie. low <= value <= high). |
| 93 | void GenerateCheckBounds(MacroAssembler* masm); |
| 94 | |
armvixl | 5289c59 | 2015-03-02 13:52:04 +0000 | [diff] [blame] | 95 | // Generate a function with the following prototype: |
| 96 | // uint32_t crc32(const char *msg, size_t msg_length) |
| 97 | // |
| 98 | // The generated function computes the CRC-32 checksum on the input msg |
| 99 | // with specified length, and returns the result. |
| 100 | void GenerateCrc32(MacroAssembler* masm); |
| 101 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 102 | // Generate a function which uses the stack to swap the content of the x0, x1, |
| 103 | // x2 and x3 registers. |
| 104 | void GenerateSwap4(MacroAssembler* masm); |
| 105 | |
| 106 | // Generate a function which swaps the content of w0 and w1. |
| 107 | // This example demonstrates some interesting features of VIXL's stack |
| 108 | // operations. |
| 109 | void GenerateSwapInt32(MacroAssembler* masm); |
| 110 | |
| 111 | // Generate a function with the following prototype: |
| 112 | // uint64_t demo_function(uint64_t x) |
| 113 | // |
| 114 | // This is the example used in doc/getting-started.txt |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 115 | void GenerateDemoFunction(MacroAssembler* masm); |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 116 | |
armvixl | db64434 | 2015-07-21 11:37:10 +0100 | [diff] [blame] | 117 | // This function generates and runs code that uses literals to sum the `a` and |
| 118 | // `b` inputs. |
| 119 | int64_t LiteralExample(int64_t a, int64_t b); |
| 120 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 121 | |
| 122 | #endif /* !VIXL_EXAMPLE_EXAMPLES_H_ */ |