1// Copyright 2015, VIXL authors 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_ 28#define VIXL_EXAMPLE_EXAMPLES_H_ 29 30#include "aarch64/debugger-aarch64.h" 31#include "aarch64/macro-assembler-aarch64.h" 32 33using namespace vixl; 34using namespace vixl::aarch64; 35 36// Generate a function with the following prototype: 37// uint64_t factorial(uint64_t n) 38// 39// It provides an iterative implementation of the factorial computation. 40void GenerateFactorial(MacroAssembler* masm); 41 42// Generate a function with the following prototype: 43// uint64_t factorial_rec(uint64_t n) 44// 45// It provides a recursive implementation of the factorial computation. 46void GenerateFactorialRec(MacroAssembler* masm); 47 48// Generate a function with the following prototype: 49// void neon_matrix_multiply(float* dst, float* mat1, float* mat2) 50// 51// It provides an implementation of a column-major 4x4 matrix multiplication. 52void GenerateNEONMatrixMultiply(MacroAssembler* masm); 53 54// Generate a function with the following prototype: 55// void add2_vectors(int8_t *vecA, const int8_t *vecB, unsigned size) 56// 57// Demonstrate how to add two vectors using NEON. The result is stored in vecA. 58void GenerateAdd2Vectors(MacroAssembler* masm); 59 60// Generate a function with the following prototype: 61// double add3_double(double x, double y, double z) 62// 63// This example is intended to show the calling convention with double 64// floating point arguments. 65void GenerateAdd3Double(MacroAssembler* masm); 66 67// Generate a function with the following prototype: 68// double add4_double(uint64_t a, double b, uint64_t c, double d) 69// 70// The generated function pictures the calling convention for functions 71// mixing integer and floating point arguments. 72void GenerateAdd4Double(MacroAssembler* masm); 73 74// Generate a function with the following prototype: 75// uint32_t sum_array(uint8_t* array, uint32_t size) 76// 77// The generated function computes the sum of all the elements in 78// the given array. 79void GenerateSumArray(MacroAssembler* masm); 80 81// Generate a function with the following prototype: 82// int64_t abs(int64_t x) 83// 84// The generated function computes the absolute value of an integer. 85void GenerateAbs(MacroAssembler* masm); 86 87// Generate a function with the following prototype: 88// uint64_t check_bounds(uint64_t value, uint64_t low, uint64_t high) 89// 90// The goal of this example is to illustrate the use of conditional 91// instructions. The generated function will check that the given value is 92// contained within the given boundaries. It returns 1 if 'value' is between 93// 'low' and 'high' (ie. low <= value <= high). 94void GenerateCheckBounds(MacroAssembler* masm); 95 96// Generate a function with the following prototype: 97// uint32_t crc32(const char *msg, size_t msg_length) 98// 99// The generated function computes the CRC-32 checksum on the input msg 100// with specified length, and returns the result. 101void GenerateCrc32(MacroAssembler* masm); 102 103// Generate a function which uses the stack to swap the content of the x0, x1, 104// x2 and x3 registers. 105void GenerateSwap4(MacroAssembler* masm); 106 107// Generate a function which swaps the content of w0 and w1. 108// This example demonstrates some interesting features of VIXL's stack 109// operations. 110void GenerateSwapInt32(MacroAssembler* masm); 111 112// Generate a function with the following prototype: 113// uint64_t demo_function(uint64_t x) 114// 115// This is the example used in doc/getting-started-aarch64.txt 116void GenerateDemoFunction(MacroAssembler* masm); 117 118// This function generates and runs code that uses literals to sum the `a` and 119// `b` inputs. 120int64_t LiteralExample(int64_t a, int64_t b); 121 122// Generate a few examples of runtime calls. 123void GenerateRuntimeCallExamples(MacroAssembler* masm); 124 125#endif // VIXL_EXAMPLE_EXAMPLES_H_ 126