1 // Copyright 2016, 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 #include "test-runner.h"
28 #include "test-utils-aarch64.h"
29
30 #include "aarch64/abi-aarch64.h"
31
32 #if (__cplusplus >= 201103L) && !defined(VIXL_HAS_ABI_SUPPORT)
33 #error "C++11 should be sufficient to provide ABI support."
34 #endif // #if (__cplusplus >= 201103L) && !defined(VIXL_HAS_ABI_SUPPORT)
35
36 #ifdef VIXL_HAS_ABI_SUPPORT
37
38 #define TEST(name) TEST_(AARCH64_ABI_##name)
39
40 namespace vixl {
41 namespace aarch64 {
42
43
TEST(abi)44 TEST(abi) {
45 ABI abi;
46
47 VIXL_CHECK(abi.GetStackSpaceRequired() == 0);
48 VIXL_CHECK(!abi.GetReturnGenericOperand<void>().IsValid());
49
50 VIXL_CHECK(abi.GetReturnGenericOperand<bool>().Equals(GenericOperand(w0)));
51 VIXL_CHECK(abi.GetReturnGenericOperand<char>().Equals(GenericOperand(w0)));
52 VIXL_CHECK(abi.GetReturnGenericOperand<int8_t>().Equals(GenericOperand(w0)));
53 VIXL_CHECK(abi.GetReturnGenericOperand<uint8_t>().Equals(GenericOperand(w0)));
54 VIXL_CHECK(
55 abi.GetReturnGenericOperand<short>().Equals( // NOLINT(runtime/int)
56 GenericOperand(w0)));
57 VIXL_CHECK(abi.GetReturnGenericOperand<int16_t>().Equals(GenericOperand(w0)));
58 VIXL_CHECK(
59 abi.GetReturnGenericOperand<uint16_t>().Equals(GenericOperand(w0)));
60 VIXL_CHECK(abi.GetReturnGenericOperand<int>().Equals(GenericOperand(w0)));
61 VIXL_CHECK(abi.GetReturnGenericOperand<int32_t>().Equals(GenericOperand(w0)));
62 VIXL_CHECK(
63 abi.GetReturnGenericOperand<uint32_t>().Equals(GenericOperand(w0)));
64 VIXL_CHECK(abi.GetReturnGenericOperand<int64_t>().Equals(GenericOperand(x0)));
65 VIXL_CHECK(
66 abi.GetReturnGenericOperand<uint64_t>().Equals(GenericOperand(x0)));
67
68 VIXL_CHECK(abi.GetReturnGenericOperand<float>().Equals(GenericOperand(s0)));
69 VIXL_CHECK(abi.GetReturnGenericOperand<double>().Equals(GenericOperand(d0)));
70
71 GenericOperand found(NoReg);
72 GenericOperand expected(NoReg);
73 #define CHECK_NEXT_PARAMETER_REG(type, reg) \
74 found = abi.GetNextParameterGenericOperand<type>(); \
75 expected = GenericOperand(reg); \
76 VIXL_CHECK(found.Equals(expected))
77 // Slots on the stack are always 8 bytes.
78 #define CHECK_NEXT_PARAMETER_MEM(type, mem_op, size) \
79 found = abi.GetNextParameterGenericOperand<type>(); \
80 expected = GenericOperand(mem_op, size); \
81 VIXL_CHECK(found.Equals(expected))
82
83 abi.Reset();
84 CHECK_NEXT_PARAMETER_REG(int, w0);
85 CHECK_NEXT_PARAMETER_REG(char, w1);
86 CHECK_NEXT_PARAMETER_REG(bool, w2);
87 CHECK_NEXT_PARAMETER_REG(float, s0);
88 CHECK_NEXT_PARAMETER_REG(double, d1);
89 CHECK_NEXT_PARAMETER_REG(double, d2);
90 CHECK_NEXT_PARAMETER_REG(float, s3);
91 CHECK_NEXT_PARAMETER_REG(int64_t, x3);
92 CHECK_NEXT_PARAMETER_REG(uint64_t, x4);
93 CHECK_NEXT_PARAMETER_REG(void*, x5);
94 CHECK_NEXT_PARAMETER_REG(uint32_t, w6);
95 typedef short my_type; // NOLINT(runtime/int)
96 CHECK_NEXT_PARAMETER_REG(my_type, w7);
97 CHECK_NEXT_PARAMETER_MEM(int, MemOperand(sp, 0), kWRegSizeInBytes);
98 CHECK_NEXT_PARAMETER_MEM(int, MemOperand(sp, 8), kWRegSizeInBytes);
99 CHECK_NEXT_PARAMETER_REG(double, d4);
100 CHECK_NEXT_PARAMETER_REG(double, d5);
101 CHECK_NEXT_PARAMETER_REG(double, d6);
102 CHECK_NEXT_PARAMETER_REG(double, d7);
103 CHECK_NEXT_PARAMETER_MEM(double, MemOperand(sp, 16), kDRegSizeInBytes);
104 CHECK_NEXT_PARAMETER_MEM(bool, MemOperand(sp, 24), kWRegSizeInBytes);
105 CHECK_NEXT_PARAMETER_MEM(short, // NOLINT(runtime/int)
106 MemOperand(sp, 32),
107 kWRegSizeInBytes);
108 CHECK_NEXT_PARAMETER_MEM(float, MemOperand(sp, 40), kSRegSizeInBytes);
109 CHECK_NEXT_PARAMETER_MEM(float, MemOperand(sp, 48), kSRegSizeInBytes);
110 VIXL_CHECK(abi.GetStackSpaceRequired() == 56);
111 }
112 }
113 } // namespace vixl::aarch64
114
115 #endif // VIXL_ABI_SUPORT
116