1b8021494Sopenharmony_ci// Copyright 2017, 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#ifdef VIXL_INCLUDE_TARGET_AARCH32
30b8021494Sopenharmony_ci#include "aarch32/macro-assembler-aarch32.h"
31b8021494Sopenharmony_ci#include "aarch32/test-utils-aarch32.h"
32b8021494Sopenharmony_ci#endif
33b8021494Sopenharmony_ci
34b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
35b8021494Sopenharmony_ci#include "aarch64/macro-assembler-aarch64.h"
36b8021494Sopenharmony_ci#endif
37b8021494Sopenharmony_ci
38b8021494Sopenharmony_ci#define TEST(name) TEST_(SCOPES_##name)
39b8021494Sopenharmony_ci
40b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_A32
41b8021494Sopenharmony_ci#define TEST_A32(name) TEST(name)
42b8021494Sopenharmony_ci#else
43b8021494Sopenharmony_ci// Do not add this test to the harness.
44b8021494Sopenharmony_ci#define TEST_A32(name) void Test##name()
45b8021494Sopenharmony_ci#endif
46b8021494Sopenharmony_ci
47b8021494Sopenharmony_ci#define __ masm.
48b8021494Sopenharmony_ci
49b8021494Sopenharmony_cinamespace vixl {
50b8021494Sopenharmony_ci
51b8021494Sopenharmony_ci// This file contains tests for code generation scopes.
52b8021494Sopenharmony_ci
53b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
54b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_basic_32) {
55b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
56b8021494Sopenharmony_ci
57b8021494Sopenharmony_ci  {
58b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
59b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
60b8021494Sopenharmony_ci  }
61b8021494Sopenharmony_ci
62b8021494Sopenharmony_ci  masm.FinalizeCode();
63b8021494Sopenharmony_ci}
64b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
65b8021494Sopenharmony_ci
66b8021494Sopenharmony_ci
67b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
68b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_basic_64) {
69b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
70b8021494Sopenharmony_ci
71b8021494Sopenharmony_ci  {
72b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, aarch64::kInstructionSize);
73b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
74b8021494Sopenharmony_ci  }
75b8021494Sopenharmony_ci
76b8021494Sopenharmony_ci  masm.FinalizeCode();
77b8021494Sopenharmony_ci}
78b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
79b8021494Sopenharmony_ci
80b8021494Sopenharmony_ci
81b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
82b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_assembler_use_32) {
83b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
84b8021494Sopenharmony_ci
85b8021494Sopenharmony_ci  {
86b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, 2 * aarch32::kA32InstructionSizeInBytes);
87b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
88b8021494Sopenharmony_ci    __ mov(aarch32::r1, 1);
89b8021494Sopenharmony_ci  }
90b8021494Sopenharmony_ci
91b8021494Sopenharmony_ci  masm.FinalizeCode();
92b8021494Sopenharmony_ci}
93b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
94b8021494Sopenharmony_ci
95b8021494Sopenharmony_ci
96b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
97b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_assembler_use_64) {
98b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
99b8021494Sopenharmony_ci
100b8021494Sopenharmony_ci  {
101b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, 2 * aarch64::kInstructionSize);
102b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
103b8021494Sopenharmony_ci    __ movz(aarch64::x1, 1);
104b8021494Sopenharmony_ci  }
105b8021494Sopenharmony_ci
106b8021494Sopenharmony_ci  masm.FinalizeCode();
107b8021494Sopenharmony_ci}
108b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
109b8021494Sopenharmony_ci
110b8021494Sopenharmony_ci
111b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
112b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Open_32) {
113b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
114b8021494Sopenharmony_ci
115b8021494Sopenharmony_ci  {
116b8021494Sopenharmony_ci    CodeBufferCheckScope scope;
117b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
118b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
119b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
120b8021494Sopenharmony_ci  }
121b8021494Sopenharmony_ci
122b8021494Sopenharmony_ci  masm.FinalizeCode();
123b8021494Sopenharmony_ci}
124b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
125b8021494Sopenharmony_ci
126b8021494Sopenharmony_ci
127b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
128b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Open_64) {
129b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
130b8021494Sopenharmony_ci
131b8021494Sopenharmony_ci  {
132b8021494Sopenharmony_ci    CodeBufferCheckScope scope;
133b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
134b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
135b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
136b8021494Sopenharmony_ci  }
137b8021494Sopenharmony_ci
138b8021494Sopenharmony_ci  masm.FinalizeCode();
139b8021494Sopenharmony_ci}
140b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
141b8021494Sopenharmony_ci
142b8021494Sopenharmony_ci
143b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
144b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Close_32) {
145b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
146b8021494Sopenharmony_ci
147b8021494Sopenharmony_ci  {
148b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
149b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
150b8021494Sopenharmony_ci    scope.Close();
151b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
152b8021494Sopenharmony_ci  }
153b8021494Sopenharmony_ci
154b8021494Sopenharmony_ci  masm.FinalizeCode();
155b8021494Sopenharmony_ci}
156b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
157b8021494Sopenharmony_ci
158b8021494Sopenharmony_ci
159b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
160b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Close_64) {
161b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
162b8021494Sopenharmony_ci
163b8021494Sopenharmony_ci  {
164b8021494Sopenharmony_ci    CodeBufferCheckScope scope(&masm, aarch64::kInstructionSize);
165b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
166b8021494Sopenharmony_ci    scope.Close();
167b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
168b8021494Sopenharmony_ci  }
169b8021494Sopenharmony_ci
170b8021494Sopenharmony_ci  masm.FinalizeCode();
171b8021494Sopenharmony_ci}
172b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
173b8021494Sopenharmony_ci
174b8021494Sopenharmony_ci
175b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
176b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Open_Close_32) {
177b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
178b8021494Sopenharmony_ci
179b8021494Sopenharmony_ci  {
180b8021494Sopenharmony_ci    CodeBufferCheckScope scope;
181b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
182b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
183b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
184b8021494Sopenharmony_ci    scope.Close();
185b8021494Sopenharmony_ci    __ Mov(aarch32::r2, 2);
186b8021494Sopenharmony_ci  }
187b8021494Sopenharmony_ci
188b8021494Sopenharmony_ci  masm.FinalizeCode();
189b8021494Sopenharmony_ci}
190b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
191b8021494Sopenharmony_ci
192b8021494Sopenharmony_ci
193b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
194b8021494Sopenharmony_ciTEST(CodeBufferCheckScope_Open_Close_64) {
195b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
196b8021494Sopenharmony_ci
197b8021494Sopenharmony_ci  {
198b8021494Sopenharmony_ci    CodeBufferCheckScope scope;
199b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
200b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
201b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
202b8021494Sopenharmony_ci    scope.Close();
203b8021494Sopenharmony_ci    __ Mov(aarch64::x2, 2);
204b8021494Sopenharmony_ci  }
205b8021494Sopenharmony_ci
206b8021494Sopenharmony_ci  masm.FinalizeCode();
207b8021494Sopenharmony_ci}
208b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
209b8021494Sopenharmony_ci
210b8021494Sopenharmony_ci
211b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
212b8021494Sopenharmony_ciTEST(EmissionCheckScope_basic_32) {
213b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
214b8021494Sopenharmony_ci
215b8021494Sopenharmony_ci  {
216b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
217b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
218b8021494Sopenharmony_ci  }
219b8021494Sopenharmony_ci
220b8021494Sopenharmony_ci  masm.FinalizeCode();
221b8021494Sopenharmony_ci}
222b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
223b8021494Sopenharmony_ci
224b8021494Sopenharmony_ci
225b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
226b8021494Sopenharmony_ciTEST(EmissionCheckScope_basic_64) {
227b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
228b8021494Sopenharmony_ci
229b8021494Sopenharmony_ci  {
230b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm, aarch64::kInstructionSize);
231b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
232b8021494Sopenharmony_ci  }
233b8021494Sopenharmony_ci
234b8021494Sopenharmony_ci  masm.FinalizeCode();
235b8021494Sopenharmony_ci}
236b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
237b8021494Sopenharmony_ci
238b8021494Sopenharmony_ci
239b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
240b8021494Sopenharmony_ciTEST(EmissionCheckScope_Open_32) {
241b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
242b8021494Sopenharmony_ci
243b8021494Sopenharmony_ci  {
244b8021494Sopenharmony_ci    EmissionCheckScope scope;
245b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
246b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
247b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
248b8021494Sopenharmony_ci  }
249b8021494Sopenharmony_ci
250b8021494Sopenharmony_ci  masm.FinalizeCode();
251b8021494Sopenharmony_ci}
252b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
253b8021494Sopenharmony_ci
254b8021494Sopenharmony_ci
255b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
256b8021494Sopenharmony_ciTEST(EmissionCheckScope_Open_64) {
257b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
258b8021494Sopenharmony_ci
259b8021494Sopenharmony_ci  {
260b8021494Sopenharmony_ci    EmissionCheckScope scope;
261b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
262b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
263b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
264b8021494Sopenharmony_ci  }
265b8021494Sopenharmony_ci
266b8021494Sopenharmony_ci  masm.FinalizeCode();
267b8021494Sopenharmony_ci}
268b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
269b8021494Sopenharmony_ci
270b8021494Sopenharmony_ci
271b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
272b8021494Sopenharmony_ciTEST(EmissionCheckScope_Close_32) {
273b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
274b8021494Sopenharmony_ci
275b8021494Sopenharmony_ci  {
276b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
277b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
278b8021494Sopenharmony_ci    scope.Close();
279b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
280b8021494Sopenharmony_ci  }
281b8021494Sopenharmony_ci
282b8021494Sopenharmony_ci  masm.FinalizeCode();
283b8021494Sopenharmony_ci}
284b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
285b8021494Sopenharmony_ci
286b8021494Sopenharmony_ci
287b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
288b8021494Sopenharmony_ciTEST(EmissionCheckScope_Close_64) {
289b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
290b8021494Sopenharmony_ci
291b8021494Sopenharmony_ci  {
292b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm, aarch64::kInstructionSize);
293b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
294b8021494Sopenharmony_ci    scope.Close();
295b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
296b8021494Sopenharmony_ci  }
297b8021494Sopenharmony_ci
298b8021494Sopenharmony_ci  masm.FinalizeCode();
299b8021494Sopenharmony_ci}
300b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
301b8021494Sopenharmony_ci
302b8021494Sopenharmony_ci
303b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
304b8021494Sopenharmony_ciTEST(EmissionCheckScope_Open_Close_32) {
305b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
306b8021494Sopenharmony_ci
307b8021494Sopenharmony_ci  {
308b8021494Sopenharmony_ci    EmissionCheckScope scope;
309b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
310b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
311b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
312b8021494Sopenharmony_ci    scope.Close();
313b8021494Sopenharmony_ci    __ Mov(aarch32::r2, 2);
314b8021494Sopenharmony_ci  }
315b8021494Sopenharmony_ci
316b8021494Sopenharmony_ci  masm.FinalizeCode();
317b8021494Sopenharmony_ci}
318b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
319b8021494Sopenharmony_ci
320b8021494Sopenharmony_ci
321b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
322b8021494Sopenharmony_ciTEST(EmissionCheckScope_Open_Close_64) {
323b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
324b8021494Sopenharmony_ci
325b8021494Sopenharmony_ci  {
326b8021494Sopenharmony_ci    EmissionCheckScope scope;
327b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
328b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
329b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
330b8021494Sopenharmony_ci    scope.Close();
331b8021494Sopenharmony_ci    __ Mov(aarch64::x2, 2);
332b8021494Sopenharmony_ci  }
333b8021494Sopenharmony_ci
334b8021494Sopenharmony_ci  masm.FinalizeCode();
335b8021494Sopenharmony_ci}
336b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
337b8021494Sopenharmony_ci
338b8021494Sopenharmony_ci
339b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
340b8021494Sopenharmony_ci
341b8021494Sopenharmony_ci#define ASSERT_LITERAL_POOL_SIZE_32(expected)     \
342b8021494Sopenharmony_ci  {                                               \
343b8021494Sopenharmony_ci    aarch32::TestMacroAssembler test(&masm);      \
344b8021494Sopenharmony_ci    VIXL_CHECK((expected) == test.GetPoolSize()); \
345b8021494Sopenharmony_ci  }
346b8021494Sopenharmony_ci
347b8021494Sopenharmony_ciTEST_A32(EmissionCheckScope_emit_pool_32) {
348b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
349b8021494Sopenharmony_ci
350b8021494Sopenharmony_ci  // Make sure the pool is empty;
351b8021494Sopenharmony_ci  masm.EmitLiteralPool(PoolManager<int32_t>::kBranchRequired);
352b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(0);
353b8021494Sopenharmony_ci
354b8021494Sopenharmony_ci  __ Ldrd(aarch32::r0, aarch32::r1, 0x1234567890abcdef);
355b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(8);
356b8021494Sopenharmony_ci
357b8021494Sopenharmony_ci  const int kLdrdRange = 255;
358b8021494Sopenharmony_ci  const int kLessThanLdrdRange = 100;
359b8021494Sopenharmony_ci
360b8021494Sopenharmony_ci  {
361b8021494Sopenharmony_ci    // Check that opening the scope with a reserved space well below the limit
362b8021494Sopenharmony_ci    // at which can generate the literal pool does not force the emission of
363b8021494Sopenharmony_ci    // the pool.
364b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
365b8021494Sopenharmony_ci                             kLessThanLdrdRange,
366b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
367b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_32(8);
368b8021494Sopenharmony_ci  }
369b8021494Sopenharmony_ci
370b8021494Sopenharmony_ci  {
371b8021494Sopenharmony_ci    // Check that the scope forces emission of the pool if necessary.
372b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
373b8021494Sopenharmony_ci                             kLdrdRange + 1,
374b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
375b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_32(0);
376b8021494Sopenharmony_ci  }
377b8021494Sopenharmony_ci
378b8021494Sopenharmony_ci  masm.FinalizeCode();
379b8021494Sopenharmony_ci}
380b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
381b8021494Sopenharmony_ci
382b8021494Sopenharmony_ci
383b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
384b8021494Sopenharmony_ci
385b8021494Sopenharmony_ci#define ASSERT_LITERAL_POOL_SIZE_64(expected)          \
386b8021494Sopenharmony_ci  VIXL_CHECK((expected + aarch64::kInstructionSize) == \
387b8021494Sopenharmony_ci             masm.GetLiteralPoolSize())
388b8021494Sopenharmony_ci
389b8021494Sopenharmony_ciTEST(EmissionCheckScope_emit_pool_64) {
390b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
391b8021494Sopenharmony_ci
392b8021494Sopenharmony_ci  // Make sure the pool is empty;
393b8021494Sopenharmony_ci  masm.EmitLiteralPool(aarch64::LiteralPool::kBranchRequired);
394b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(0);
395b8021494Sopenharmony_ci
396b8021494Sopenharmony_ci  __ Ldr(aarch64::x0, 0x1234567890abcdef);
397b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(8);
398b8021494Sopenharmony_ci
399b8021494Sopenharmony_ci  {
400b8021494Sopenharmony_ci    // Check that opening the scope with a reserved space well below the limit
401b8021494Sopenharmony_ci    // at which can generate the literal pool does not force the emission of
402b8021494Sopenharmony_ci    // the pool.
403b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
404b8021494Sopenharmony_ci                             10 * aarch64::kInstructionSize,
405b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
406b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_64(8);
407b8021494Sopenharmony_ci  }
408b8021494Sopenharmony_ci
409b8021494Sopenharmony_ci  {
410b8021494Sopenharmony_ci    // Check that the scope forces emission of the pool if necessary.
411b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
412b8021494Sopenharmony_ci                             aarch64::kMaxLoadLiteralRange + 1,
413b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
414b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_64(0);
415b8021494Sopenharmony_ci  }
416b8021494Sopenharmony_ci
417b8021494Sopenharmony_ci  masm.FinalizeCode();
418b8021494Sopenharmony_ci}
419b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
420b8021494Sopenharmony_ci
421b8021494Sopenharmony_ci
422b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
423b8021494Sopenharmony_ciTEST_A32(EmissionCheckScope_emit_pool_on_Open_32) {
424b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
425b8021494Sopenharmony_ci
426b8021494Sopenharmony_ci  // Make sure the pool is empty;
427b8021494Sopenharmony_ci  masm.EmitLiteralPool(PoolManager<int32_t>::kBranchRequired);
428b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(0);
429b8021494Sopenharmony_ci
430b8021494Sopenharmony_ci  __ Ldrd(aarch32::r0, aarch32::r1, 0x1234567890abcdef);
431b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(8);
432b8021494Sopenharmony_ci
433b8021494Sopenharmony_ci  const int kLdrdRange = 255;
434b8021494Sopenharmony_ci  const int kLessThanLdrdRange = 100;
435b8021494Sopenharmony_ci
436b8021494Sopenharmony_ci  {
437b8021494Sopenharmony_ci    // Check that opening the scope with a reserved space well below the limit
438b8021494Sopenharmony_ci    // at which can generate the literal pool does not force the emission of
439b8021494Sopenharmony_ci    // the pool.
440b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
441b8021494Sopenharmony_ci                             kLessThanLdrdRange,
442b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
443b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_32(8);
444b8021494Sopenharmony_ci  }
445b8021494Sopenharmony_ci
446b8021494Sopenharmony_ci  {
447b8021494Sopenharmony_ci    // Check that the scope forces emission of the pool if necessary.
448b8021494Sopenharmony_ci    EmissionCheckScope scope(&masm,
449b8021494Sopenharmony_ci                             kLdrdRange + 1,
450b8021494Sopenharmony_ci                             EmissionCheckScope::kMaximumSize);
451b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_32(0);
452b8021494Sopenharmony_ci  }
453b8021494Sopenharmony_ci
454b8021494Sopenharmony_ci  masm.FinalizeCode();
455b8021494Sopenharmony_ci}
456b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
457b8021494Sopenharmony_ci
458b8021494Sopenharmony_ci
459b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
460b8021494Sopenharmony_ciTEST(EmissionCheckScope_emit_pool_on_Open_64) {
461b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
462b8021494Sopenharmony_ci
463b8021494Sopenharmony_ci  // Make sure the pool is empty;
464b8021494Sopenharmony_ci  masm.EmitLiteralPool(aarch64::LiteralPool::kBranchRequired);
465b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(0);
466b8021494Sopenharmony_ci
467b8021494Sopenharmony_ci  __ Ldr(aarch64::x0, 0x1234567890abcdef);
468b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(8);
469b8021494Sopenharmony_ci
470b8021494Sopenharmony_ci  {
471b8021494Sopenharmony_ci    // Check that opening the scope with a reserved space well below the limit
472b8021494Sopenharmony_ci    // at which can generate the literal pool does not force the emission of
473b8021494Sopenharmony_ci    // the pool.
474b8021494Sopenharmony_ci    EmissionCheckScope scope;
475b8021494Sopenharmony_ci    scope.Open(&masm,
476b8021494Sopenharmony_ci               10 * aarch64::kInstructionSize,
477b8021494Sopenharmony_ci               EmissionCheckScope::kMaximumSize);
478b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_64(8);
479b8021494Sopenharmony_ci  }
480b8021494Sopenharmony_ci
481b8021494Sopenharmony_ci  {
482b8021494Sopenharmony_ci    // Check that the scope forces emission of the pool if necessary.
483b8021494Sopenharmony_ci    EmissionCheckScope scope;
484b8021494Sopenharmony_ci    scope.Open(&masm,
485b8021494Sopenharmony_ci               aarch64::kMaxLoadLiteralRange + 1,
486b8021494Sopenharmony_ci               EmissionCheckScope::kMaximumSize);
487b8021494Sopenharmony_ci    ASSERT_LITERAL_POOL_SIZE_64(0);
488b8021494Sopenharmony_ci  }
489b8021494Sopenharmony_ci
490b8021494Sopenharmony_ci  masm.FinalizeCode();
491b8021494Sopenharmony_ci}
492b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
493b8021494Sopenharmony_ci
494b8021494Sopenharmony_ci
495b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
496b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_basic_32) {
497b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
498b8021494Sopenharmony_ci
499b8021494Sopenharmony_ci  {
500b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
501b8021494Sopenharmony_ci    __ nop();
502b8021494Sopenharmony_ci  }
503b8021494Sopenharmony_ci
504b8021494Sopenharmony_ci  masm.FinalizeCode();
505b8021494Sopenharmony_ci}
506b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
507b8021494Sopenharmony_ci
508b8021494Sopenharmony_ci
509b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
510b8021494Sopenharmony_ciTEST(ExactAssemblyScope_basic_64) {
511b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
512b8021494Sopenharmony_ci
513b8021494Sopenharmony_ci  {
514b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, aarch64::kInstructionSize);
515b8021494Sopenharmony_ci    __ nop();
516b8021494Sopenharmony_ci  }
517b8021494Sopenharmony_ci
518b8021494Sopenharmony_ci  masm.FinalizeCode();
519b8021494Sopenharmony_ci}
520b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
521b8021494Sopenharmony_ci
522b8021494Sopenharmony_ci
523b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
524b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_Open_32) {
525b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
526b8021494Sopenharmony_ci
527b8021494Sopenharmony_ci  {
528b8021494Sopenharmony_ci    ExactAssemblyScope scope;
529b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
530b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
531b8021494Sopenharmony_ci    __ mov(aarch32::r1, 1);
532b8021494Sopenharmony_ci  }
533b8021494Sopenharmony_ci
534b8021494Sopenharmony_ci  masm.FinalizeCode();
535b8021494Sopenharmony_ci}
536b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
537b8021494Sopenharmony_ci
538b8021494Sopenharmony_ci
539b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
540b8021494Sopenharmony_ciTEST(ExactAssemblyScope_Open_64) {
541b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
542b8021494Sopenharmony_ci
543b8021494Sopenharmony_ci  {
544b8021494Sopenharmony_ci    ExactAssemblyScope scope;
545b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
546b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
547b8021494Sopenharmony_ci    __ movz(aarch64::x1, 1);
548b8021494Sopenharmony_ci  }
549b8021494Sopenharmony_ci
550b8021494Sopenharmony_ci  masm.FinalizeCode();
551b8021494Sopenharmony_ci}
552b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
553b8021494Sopenharmony_ci
554b8021494Sopenharmony_ci
555b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
556b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_Close_32) {
557b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
558b8021494Sopenharmony_ci
559b8021494Sopenharmony_ci  {
560b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, aarch32::kA32InstructionSizeInBytes);
561b8021494Sopenharmony_ci    __ mov(aarch32::r0, 0);
562b8021494Sopenharmony_ci    scope.Close();
563b8021494Sopenharmony_ci    __ Mov(aarch32::r1, 1);
564b8021494Sopenharmony_ci  }
565b8021494Sopenharmony_ci
566b8021494Sopenharmony_ci  masm.FinalizeCode();
567b8021494Sopenharmony_ci}
568b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
569b8021494Sopenharmony_ci
570b8021494Sopenharmony_ci
571b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
572b8021494Sopenharmony_ciTEST(ExactAssemblyScope_Close_64) {
573b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
574b8021494Sopenharmony_ci
575b8021494Sopenharmony_ci  {
576b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, aarch64::kInstructionSize);
577b8021494Sopenharmony_ci    __ movz(aarch64::x0, 0);
578b8021494Sopenharmony_ci    scope.Close();
579b8021494Sopenharmony_ci    __ Mov(aarch64::x1, 1);
580b8021494Sopenharmony_ci  }
581b8021494Sopenharmony_ci
582b8021494Sopenharmony_ci  masm.FinalizeCode();
583b8021494Sopenharmony_ci}
584b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
585b8021494Sopenharmony_ci
586b8021494Sopenharmony_ci
587b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
588b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_Open_Close_32) {
589b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
590b8021494Sopenharmony_ci
591b8021494Sopenharmony_ci  {
592b8021494Sopenharmony_ci    ExactAssemblyScope scope;
593b8021494Sopenharmony_ci    __ Mov(aarch32::r0, 0);
594b8021494Sopenharmony_ci    scope.Open(&masm, aarch32::kA32InstructionSizeInBytes);
595b8021494Sopenharmony_ci    __ mov(aarch32::r1, 1);
596b8021494Sopenharmony_ci    scope.Close();
597b8021494Sopenharmony_ci    __ Mov(aarch32::r2, 2);
598b8021494Sopenharmony_ci  }
599b8021494Sopenharmony_ci
600b8021494Sopenharmony_ci  masm.FinalizeCode();
601b8021494Sopenharmony_ci}
602b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
603b8021494Sopenharmony_ci
604b8021494Sopenharmony_ci
605b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
606b8021494Sopenharmony_ciTEST(ExactAssemblyScope_Open_Close_64) {
607b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
608b8021494Sopenharmony_ci
609b8021494Sopenharmony_ci  {
610b8021494Sopenharmony_ci    ExactAssemblyScope scope;
611b8021494Sopenharmony_ci    __ Mov(aarch64::x0, 0);
612b8021494Sopenharmony_ci    scope.Open(&masm, aarch64::kInstructionSize);
613b8021494Sopenharmony_ci    __ movz(aarch64::x1, 1);
614b8021494Sopenharmony_ci    scope.Close();
615b8021494Sopenharmony_ci    __ Mov(aarch64::x2, 2);
616b8021494Sopenharmony_ci  }
617b8021494Sopenharmony_ci
618b8021494Sopenharmony_ci  masm.FinalizeCode();
619b8021494Sopenharmony_ci}
620b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
621b8021494Sopenharmony_ci
622b8021494Sopenharmony_ci
623b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
624b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_32) {
625b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
626b8021494Sopenharmony_ci
627b8021494Sopenharmony_ci  // By default macro instructions are allowed.
628b8021494Sopenharmony_ci  VIXL_CHECK(!masm.ArePoolsBlocked());
629b8021494Sopenharmony_ci  VIXL_ASSERT(!masm.AllowAssembler());
630b8021494Sopenharmony_ci  VIXL_ASSERT(masm.AllowMacroInstructions());
631b8021494Sopenharmony_ci  {
632b8021494Sopenharmony_ci    ExactAssemblyScope scope1(&masm, 2 * aarch32::kA32InstructionSizeInBytes);
633b8021494Sopenharmony_ci    VIXL_CHECK(masm.ArePoolsBlocked());
634b8021494Sopenharmony_ci    VIXL_ASSERT(masm.AllowAssembler());
635b8021494Sopenharmony_ci    VIXL_ASSERT(!masm.AllowMacroInstructions());
636b8021494Sopenharmony_ci    __ nop();
637b8021494Sopenharmony_ci    {
638b8021494Sopenharmony_ci      ExactAssemblyScope scope2(&masm, 1 * aarch32::kA32InstructionSizeInBytes);
639b8021494Sopenharmony_ci      VIXL_CHECK(masm.ArePoolsBlocked());
640b8021494Sopenharmony_ci      VIXL_ASSERT(masm.AllowAssembler());
641b8021494Sopenharmony_ci      VIXL_ASSERT(!masm.AllowMacroInstructions());
642b8021494Sopenharmony_ci      __ nop();
643b8021494Sopenharmony_ci    }
644b8021494Sopenharmony_ci    VIXL_CHECK(masm.ArePoolsBlocked());
645b8021494Sopenharmony_ci    VIXL_ASSERT(masm.AllowAssembler());
646b8021494Sopenharmony_ci    VIXL_ASSERT(!masm.AllowMacroInstructions());
647b8021494Sopenharmony_ci  }
648b8021494Sopenharmony_ci  VIXL_CHECK(!masm.ArePoolsBlocked());
649b8021494Sopenharmony_ci  VIXL_ASSERT(!masm.AllowAssembler());
650b8021494Sopenharmony_ci  VIXL_ASSERT(masm.AllowMacroInstructions());
651b8021494Sopenharmony_ci
652b8021494Sopenharmony_ci  {
653b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, 2 * aarch32::kA32InstructionSizeInBytes);
654b8021494Sopenharmony_ci    __ add(aarch32::r0, aarch32::r0, aarch32::r0);
655b8021494Sopenharmony_ci    __ sub(aarch32::r0, aarch32::r0, aarch32::r0);
656b8021494Sopenharmony_ci  }
657b8021494Sopenharmony_ci
658b8021494Sopenharmony_ci  masm.FinalizeCode();
659b8021494Sopenharmony_ci}
660b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
661b8021494Sopenharmony_ci
662b8021494Sopenharmony_ci
663b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
664b8021494Sopenharmony_ciTEST(ExactAssemblyScope_64) {
665b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
666b8021494Sopenharmony_ci
667b8021494Sopenharmony_ci  // By default macro instructions are allowed.
668b8021494Sopenharmony_ci  VIXL_CHECK(!masm.ArePoolsBlocked());
669b8021494Sopenharmony_ci  VIXL_ASSERT(!masm.AllowAssembler());
670b8021494Sopenharmony_ci  VIXL_ASSERT(masm.AllowMacroInstructions());
671b8021494Sopenharmony_ci  {
672b8021494Sopenharmony_ci    ExactAssemblyScope scope1(&masm, 2 * aarch64::kInstructionSize);
673b8021494Sopenharmony_ci    VIXL_CHECK(masm.ArePoolsBlocked());
674b8021494Sopenharmony_ci    VIXL_ASSERT(masm.AllowAssembler());
675b8021494Sopenharmony_ci    VIXL_ASSERT(!masm.AllowMacroInstructions());
676b8021494Sopenharmony_ci    __ nop();
677b8021494Sopenharmony_ci    {
678b8021494Sopenharmony_ci      ExactAssemblyScope scope2(&masm, 1 * aarch64::kInstructionSize);
679b8021494Sopenharmony_ci      VIXL_CHECK(masm.ArePoolsBlocked());
680b8021494Sopenharmony_ci      VIXL_ASSERT(masm.AllowAssembler());
681b8021494Sopenharmony_ci      VIXL_ASSERT(!masm.AllowMacroInstructions());
682b8021494Sopenharmony_ci      __ nop();
683b8021494Sopenharmony_ci    }
684b8021494Sopenharmony_ci    VIXL_CHECK(masm.ArePoolsBlocked());
685b8021494Sopenharmony_ci    VIXL_ASSERT(masm.AllowAssembler());
686b8021494Sopenharmony_ci    VIXL_ASSERT(!masm.AllowMacroInstructions());
687b8021494Sopenharmony_ci  }
688b8021494Sopenharmony_ci  VIXL_CHECK(!masm.ArePoolsBlocked());
689b8021494Sopenharmony_ci  VIXL_ASSERT(!masm.AllowAssembler());
690b8021494Sopenharmony_ci  VIXL_ASSERT(masm.AllowMacroInstructions());
691b8021494Sopenharmony_ci
692b8021494Sopenharmony_ci  {
693b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, 2 * aarch64::kInstructionSize);
694b8021494Sopenharmony_ci    __ add(aarch64::x0, aarch64::x0, aarch64::x0);
695b8021494Sopenharmony_ci    __ sub(aarch64::x0, aarch64::x0, aarch64::x0);
696b8021494Sopenharmony_ci  }
697b8021494Sopenharmony_ci
698b8021494Sopenharmony_ci  masm.FinalizeCode();
699b8021494Sopenharmony_ci}
700b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
701b8021494Sopenharmony_ci
702b8021494Sopenharmony_ci
703b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH32
704b8021494Sopenharmony_ciTEST_A32(ExactAssemblyScope_scope_with_pools_32) {
705b8021494Sopenharmony_ci  aarch32::MacroAssembler masm;
706b8021494Sopenharmony_ci
707b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(0);
708b8021494Sopenharmony_ci
709b8021494Sopenharmony_ci  __ Ldrd(aarch32::r0, aarch32::r1, 0x1234567890abcdef);
710b8021494Sopenharmony_ci
711b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(8);
712b8021494Sopenharmony_ci
713b8021494Sopenharmony_ci  const int32_t kLdrdRange = 255;
714b8021494Sopenharmony_ci  const int32_t n_nops = (kLdrdRange / aarch32::kA32InstructionSizeInBytes) + 1;
715b8021494Sopenharmony_ci  {
716b8021494Sopenharmony_ci    // The literal pool should be generated when opening this scope, as
717b8021494Sopenharmony_ci    // otherwise the `Ldrd` will run out of range when we generate the `nop`
718b8021494Sopenharmony_ci    // instructions below.
719b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm,
720b8021494Sopenharmony_ci                             n_nops * aarch32::kA32InstructionSizeInBytes);
721b8021494Sopenharmony_ci
722b8021494Sopenharmony_ci    // Although it must be, we do not check that the literal pool size is zero
723b8021494Sopenharmony_ci    // here, because we want this regression test to fail while or after we
724b8021494Sopenharmony_ci    // generate the nops.
725b8021494Sopenharmony_ci
726b8021494Sopenharmony_ci    for (int32_t i = 0; i < n_nops; ++i) {
727b8021494Sopenharmony_ci      __ nop();
728b8021494Sopenharmony_ci    }
729b8021494Sopenharmony_ci  }
730b8021494Sopenharmony_ci
731b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_32(0);
732b8021494Sopenharmony_ci
733b8021494Sopenharmony_ci  masm.FinalizeCode();
734b8021494Sopenharmony_ci}
735b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH32
736b8021494Sopenharmony_ci
737b8021494Sopenharmony_ci
738b8021494Sopenharmony_ci#ifdef VIXL_INCLUDE_TARGET_AARCH64
739b8021494Sopenharmony_ciTEST(ExactAssemblyScope_scope_with_pools_64) {
740b8021494Sopenharmony_ci  aarch64::MacroAssembler masm;
741b8021494Sopenharmony_ci
742b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(0);
743b8021494Sopenharmony_ci
744b8021494Sopenharmony_ci  __ Ldr(aarch64::x10, 0x1234567890abcdef);
745b8021494Sopenharmony_ci
746b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(8);
747b8021494Sopenharmony_ci
748b8021494Sopenharmony_ci  const int64_t n_nops =
749b8021494Sopenharmony_ci      aarch64::kMaxLoadLiteralRange / aarch64::kInstructionSize;
750b8021494Sopenharmony_ci  {
751b8021494Sopenharmony_ci    // The literal pool should be generated when opening this scope, as
752b8021494Sopenharmony_ci    // otherwise the `Ldr` will run out of range when we generate the `nop`
753b8021494Sopenharmony_ci    // instructions below.
754b8021494Sopenharmony_ci    ExactAssemblyScope scope(&masm, n_nops * aarch64::kInstructionSize);
755b8021494Sopenharmony_ci
756b8021494Sopenharmony_ci    // Although it must be, we do not check that the literal pool size is zero
757b8021494Sopenharmony_ci    // here, because we want this regression test to fail while or after we
758b8021494Sopenharmony_ci    // generate the nops.
759b8021494Sopenharmony_ci
760b8021494Sopenharmony_ci    for (int64_t i = 0; i < n_nops; ++i) {
761b8021494Sopenharmony_ci      __ nop();
762b8021494Sopenharmony_ci    }
763b8021494Sopenharmony_ci  }
764b8021494Sopenharmony_ci
765b8021494Sopenharmony_ci  ASSERT_LITERAL_POOL_SIZE_64(0);
766b8021494Sopenharmony_ci
767b8021494Sopenharmony_ci  masm.FinalizeCode();
768b8021494Sopenharmony_ci}
769b8021494Sopenharmony_ci#endif  // VIXL_INCLUDE_TARGET_AARCH64
770b8021494Sopenharmony_ci
771b8021494Sopenharmony_ci
772b8021494Sopenharmony_ci}  // namespace vixl
773