1// Copyright 2013, ARM Limited 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 "a64/simulator-a64.h" 31#include "a64/debugger-a64.h" 32#include "a64/macro-assembler-a64.h" 33 34using namespace vixl; 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// double add3_double(double x, double y, double z) 50// 51// This example is intended to show the calling convention with double 52// floating point arguments. 53void GenerateAdd3Double(MacroAssembler* masm); 54 55// Generate a function with the following prototype: 56// double add4_double(uint64_t a, double b, uint64_t c, double d) 57// 58// The generated function pictures the calling convention for functions 59// mixing integer and floating point arguments. 60void GenerateAdd4Double(MacroAssembler* masm); 61 62// Generate a function with the following prototype: 63// uint32_t sum_array(uint8_t* array, uint32_t size) 64// 65// The generated function computes the sum of all the elements in 66// the given array. 67void GenerateSumArray(MacroAssembler* masm); 68 69// Generate a function with the following prototype: 70// int64_t abs(int64_t x) 71// 72// The generated function computes the absolute value of an integer. 73void GenerateAbs(MacroAssembler* masm); 74 75// Generate a function with the following prototype: 76// uint64_t check_bounds(uint64_t value, uint64_t low, uint64_t high) 77// 78// The goal of this example is to illustrate the use of conditional 79// instructions. The generated function will check that the given value is 80// contained within the given boundaries. It returns 1 if 'value' is between 81// 'low' and 'high' (ie. low <= value <= high). 82void GenerateCheckBounds(MacroAssembler* masm); 83 84// Generate a function which uses the stack to swap the content of the x0, x1, 85// x2 and x3 registers. 86void GenerateSwap4(MacroAssembler* masm); 87 88// Generate a function which swaps the content of w0 and w1. 89// This example demonstrates some interesting features of VIXL's stack 90// operations. 91void GenerateSwapInt32(MacroAssembler* masm); 92 93// Generate a function with the following prototype: 94// uint64_t demo_function(uint64_t x) 95// 96// This is the example used in doc/getting-started.txt 97void GenerateDemoFunction(MacroAssembler *masm); 98 99 100#endif /* !VIXL_EXAMPLE_EXAMPLES_H_ */ 101