1b8021494Sopenharmony_ci// Copyright 2016, VIXL authors
2b8021494Sopenharmony_ci// All rights reserved.
3b8021494Sopenharmony_ci//
4b8021494Sopenharmony_ci// Redistribution and use in source and binary forms, with or without
5b8021494Sopenharmony_ci// modification, are permitted provided that the following conditions are met:
6b8021494Sopenharmony_ci//
7b8021494Sopenharmony_ci//   * Redistributions of source code must retain the above copyright notice,
8b8021494Sopenharmony_ci//     this list of conditions and the following disclaimer.
9b8021494Sopenharmony_ci//   * Redistributions in binary form must reproduce the above copyright notice,
10b8021494Sopenharmony_ci//     this list of conditions and the following disclaimer in the documentation
11b8021494Sopenharmony_ci//     and/or other materials provided with the distribution.
12b8021494Sopenharmony_ci//   * Neither the name of ARM Limited nor the names of its contributors may be
13b8021494Sopenharmony_ci//     used to endorse or promote products derived from this software without
14b8021494Sopenharmony_ci//     specific prior written permission.
15b8021494Sopenharmony_ci//
16b8021494Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17b8021494Sopenharmony_ci// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18b8021494Sopenharmony_ci// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19b8021494Sopenharmony_ci// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20b8021494Sopenharmony_ci// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b8021494Sopenharmony_ci// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22b8021494Sopenharmony_ci// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23b8021494Sopenharmony_ci// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24b8021494Sopenharmony_ci// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25b8021494Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26b8021494Sopenharmony_ci
27b8021494Sopenharmony_ci#include "test-runner.h"
28b8021494Sopenharmony_ci
29b8021494Sopenharmony_ci#include "aarch64/abi-aarch64.h"
30b8021494Sopenharmony_ci#include "test-utils-aarch64.h"
31b8021494Sopenharmony_ci
32b8021494Sopenharmony_ci#if (__cplusplus >= 201103L) && !defined(VIXL_HAS_ABI_SUPPORT)
33b8021494Sopenharmony_ci#error "C++11 should be sufficient to provide ABI support."
34b8021494Sopenharmony_ci#endif  // #if (__cplusplus >= 201103L) && !defined(VIXL_HAS_ABI_SUPPORT)
35b8021494Sopenharmony_ci
36b8021494Sopenharmony_ci#ifdef VIXL_HAS_ABI_SUPPORT
37b8021494Sopenharmony_ci
38b8021494Sopenharmony_ci#define TEST(name) TEST_(AARCH64_ABI_##name)
39b8021494Sopenharmony_ci
40b8021494Sopenharmony_cinamespace vixl {
41b8021494Sopenharmony_cinamespace aarch64 {
42b8021494Sopenharmony_ci
43b8021494Sopenharmony_ci
44b8021494Sopenharmony_ciTEST(abi) {
45b8021494Sopenharmony_ci  ABI abi;
46b8021494Sopenharmony_ci
47b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetStackSpaceRequired() == 0);
48b8021494Sopenharmony_ci  VIXL_CHECK(!abi.GetReturnGenericOperand<void>().IsValid());
49b8021494Sopenharmony_ci
50b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<bool>().Equals(GenericOperand(w0)));
51b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<char>().Equals(GenericOperand(w0)));
52b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<int8_t>().Equals(GenericOperand(w0)));
53b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<uint8_t>().Equals(GenericOperand(w0)));
54b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<short>()
55b8021494Sopenharmony_ci                 .Equals(  // NOLINT(google-runtime-int)
56b8021494Sopenharmony_ci                     GenericOperand(w0)));
57b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<int16_t>().Equals(GenericOperand(w0)));
58b8021494Sopenharmony_ci  VIXL_CHECK(
59b8021494Sopenharmony_ci      abi.GetReturnGenericOperand<uint16_t>().Equals(GenericOperand(w0)));
60b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<int>().Equals(GenericOperand(w0)));
61b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<int32_t>().Equals(GenericOperand(w0)));
62b8021494Sopenharmony_ci  VIXL_CHECK(
63b8021494Sopenharmony_ci      abi.GetReturnGenericOperand<uint32_t>().Equals(GenericOperand(w0)));
64b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<int64_t>().Equals(GenericOperand(x0)));
65b8021494Sopenharmony_ci  VIXL_CHECK(
66b8021494Sopenharmony_ci      abi.GetReturnGenericOperand<uint64_t>().Equals(GenericOperand(x0)));
67b8021494Sopenharmony_ci
68b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<float>().Equals(GenericOperand(s0)));
69b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetReturnGenericOperand<double>().Equals(GenericOperand(d0)));
70b8021494Sopenharmony_ci
71b8021494Sopenharmony_ci  GenericOperand found(NoReg);
72b8021494Sopenharmony_ci  GenericOperand expected(NoReg);
73b8021494Sopenharmony_ci#define CHECK_NEXT_PARAMETER_REG(type, reg)           \
74b8021494Sopenharmony_ci  found = abi.GetNextParameterGenericOperand<type>(); \
75b8021494Sopenharmony_ci  expected = GenericOperand(reg);                     \
76b8021494Sopenharmony_ci  VIXL_CHECK(found.Equals(expected))
77b8021494Sopenharmony_ci// Slots on the stack are always 8 bytes.
78b8021494Sopenharmony_ci#define CHECK_NEXT_PARAMETER_MEM(type, mem_op, size)  \
79b8021494Sopenharmony_ci  found = abi.GetNextParameterGenericOperand<type>(); \
80b8021494Sopenharmony_ci  expected = GenericOperand(mem_op, size);            \
81b8021494Sopenharmony_ci  VIXL_CHECK(found.Equals(expected))
82b8021494Sopenharmony_ci
83b8021494Sopenharmony_ci  abi.Reset();
84b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(int, w0);
85b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(char, w1);
86b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(bool, w2);
87b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(float, s0);
88b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d1);
89b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d2);
90b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(float, s3);
91b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(int64_t, x3);
92b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(uint64_t, x4);
93b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(void*, x5);
94b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(uint32_t, w6);
95b8021494Sopenharmony_ci  typedef short my_type;  // NOLINT(google-runtime-int)
96b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(my_type, w7);
97b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(int, MemOperand(sp, 0), kWRegSizeInBytes);
98b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(int, MemOperand(sp, 8), kWRegSizeInBytes);
99b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d4);
100b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d5);
101b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d6);
102b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_REG(double, d7);
103b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(double, MemOperand(sp, 16), kDRegSizeInBytes);
104b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(bool, MemOperand(sp, 24), kWRegSizeInBytes);
105b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(short,  // NOLINT(google-runtime-int)
106b8021494Sopenharmony_ci                           MemOperand(sp, 32),
107b8021494Sopenharmony_ci                           kWRegSizeInBytes);
108b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(float, MemOperand(sp, 40), kSRegSizeInBytes);
109b8021494Sopenharmony_ci  CHECK_NEXT_PARAMETER_MEM(float, MemOperand(sp, 48), kSRegSizeInBytes);
110b8021494Sopenharmony_ci  VIXL_CHECK(abi.GetStackSpaceRequired() == 56);
111b8021494Sopenharmony_ci}
112b8021494Sopenharmony_ci}  // namespace aarch64
113b8021494Sopenharmony_ci}  // namespace vixl
114b8021494Sopenharmony_ci
115b8021494Sopenharmony_ci#endif  // VIXL_HAS_ABI_SUPPORT
116