blob: ff25c04da162d4bca95f0b1c667efaa29a4d8dad [file] [log] [blame]
armvixl5289c592015-03-02 13:52:04 +00001// Copyright 2015, ARM Limited
armvixlad96eda2013-06-14 11:42:37 +01002// 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_
armvixl0f35e362016-05-10 13:57:58 +010028#define VIXL_EXAMPLE_EXAMPLES_H_
armvixlad96eda2013-06-14 11:42:37 +010029
Alexandre Rames39c32a62016-05-23 15:47:22 +010030#include "a64/debugger-a64.h"
31#include "a64/macro-assembler-a64.h"
armvixlad96eda2013-06-14 11:42:37 +010032
33using 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.
39void 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.
45void GenerateFactorialRec(MacroAssembler* masm);
46
47// Generate a function with the following prototype:
armvixl5289c592015-03-02 13:52:04 +000048// void neon_matrix_multiply(float* dst, float* mat1, float* mat2)
49//
50// It provides an implementation of a column-major 4x4 matrix multiplication.
51void 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.
57void GenerateAdd2Vectors(MacroAssembler* masm);
58
59// Generate a function with the following prototype:
armvixlad96eda2013-06-14 11:42:37 +010060// 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.
64void 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.
71void 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.
78void 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.
84void 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).
93void GenerateCheckBounds(MacroAssembler* masm);
94
armvixl5289c592015-03-02 13:52:04 +000095// 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.
100void GenerateCrc32(MacroAssembler* masm);
101
armvixlad96eda2013-06-14 11:42:37 +0100102// Generate a function which uses the stack to swap the content of the x0, x1,
103// x2 and x3 registers.
104void 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.
109void 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
armvixl0f35e362016-05-10 13:57:58 +0100115void GenerateDemoFunction(MacroAssembler* masm);
armvixlad96eda2013-06-14 11:42:37 +0100116
armvixldb644342015-07-21 11:37:10 +0100117// This function generates and runs code that uses literals to sum the `a` and
118// `b` inputs.
119int64_t LiteralExample(int64_t a, int64_t b);
120
armvixlad96eda2013-06-14 11:42:37 +0100121
122#endif /* !VIXL_EXAMPLE_EXAMPLES_H_ */