1 /*
2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3  * Copyright (c) 2020, Red Hat Inc. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.
9  *
10  * This code is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * version 2 for more details (a copy is included in the LICENSE file that
14  * accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License version
17  * 2 along with this work; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  */
24 
25 #include "precompiled.hpp"
26 
27 #if defined(AARCH64) && !defined(ZERO)
28 
29 #include "asm/assembler.hpp"
30 #include "asm/assembler.inline.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "unittest.hpp"
34 
35 #define __ _masm.
36 
asm_check(const unsigned int * insns,const unsigned int * insns1,size_t len)37 static void asm_check(const unsigned int *insns, const unsigned int *insns1, size_t len) {
38   bool ok = true;
39   for (unsigned int i = 0; i < len; i++) {
40     if (insns[i] != insns1[i]) {
41       ResourceMark rm;
42       stringStream ss;
43       ss.print_cr("Ours:");
44       Disassembler::decode((address)&insns1[i], (address)&insns1[i+1], &ss);
45       ss.print_cr("Theirs:");
46       Disassembler::decode((address)&insns[i], (address)&insns[i+1], &ss);
47 
48       EXPECT_EQ(insns[i], insns1[i]) << ss.as_string();
49     }
50   }
51 }
52 
TEST_VM(AssemblerAArch64,validate)53 TEST_VM(AssemblerAArch64, validate) {
54   // Smoke test for assembler
55   BufferBlob* b = BufferBlob::create("aarch64Test", 500000);
56   CodeBuffer code(b);
57   Assembler _masm(&code);
58   address entry = __ pc();
59 
60   // python aarch64-asmtest.py | expand > asmtest.out.h
61 #include "asmtest.out.h"
62 
63   asm_check((unsigned int *)entry, insns, sizeof insns / sizeof insns[0]);
64 
65   {
66     address PC = __ pc();
67     __ ld1(v0, __ T16B, Address(r16));      // No offset
68     __ ld1(v0, __ T8H, __ post(r16, 16));   // Post-index
69     __ ld2(v0, v1, __ T8H, __ post(r24, 16 * 2));   // Post-index
70     __ ld1(v0, __ T16B, __ post(r16, r17)); // Register post-index
71     static const unsigned int vector_insns[] = {
72        0x4c407200, // ld1   {v0.16b}, [x16]
73        0x4cdf7600, // ld1   {v0.8h}, [x16], #16
74        0x4cdf8700, // ld2   {v0.8h, v1.8h}, [x24], #32
75        0x4cd17200, // ld1   {v0.16b}, [x16], x17
76       };
77     asm_check((unsigned int *)PC, vector_insns,
78               sizeof vector_insns / sizeof vector_insns[0]);
79   }
80 
81   BufferBlob::free(b);
82 }
83 
84 #endif  // AARCH64
85