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