xref: /openbmc/qemu/tests/tcg/hexagon/v73_scalar.c (revision 06831001)
1 /*
2  *  Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdio.h>
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 /*
23  *  Test the scalar core instructions that are new in v73
24  */
25 
26 int err;
27 
28 static void __check32(int line, uint32_t result, uint32_t expect)
29 {
30     if (result != expect) {
31         printf("ERROR at line %d: 0x%08x != 0x%08x\n",
32                line, result, expect);
33         err++;
34     }
35 }
36 
37 #define check32(RES, EXP) __check32(__LINE__, RES, EXP)
38 
39 static void __check64(int line, uint64_t result, uint64_t expect)
40 {
41     if (result != expect) {
42         printf("ERROR at line %d: 0x%016llx != 0x%016llx\n",
43                line, result, expect);
44         err++;
45     }
46 }
47 
48 #define check64(RES, EXP) __check64(__LINE__, RES, EXP)
49 
50 static bool my_func_called;
51 
52 static void my_func(void)
53 {
54     my_func_called = true;
55 }
56 
57 static inline void callrh(void *func)
58 {
59     asm volatile("callrh %0\n\t"
60                  : : "r"(func)
61                  /* Mark the caller-save registers as clobbered */
62                  : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
63                    "r10", "r11", "r12", "r13", "r14", "r15", "r28",
64                    "p0", "p1", "p2", "p3");
65 }
66 
67 static void test_callrh(void)
68 {
69     my_func_called = false;
70     callrh(&my_func);
71     check32(my_func_called, true);
72 }
73 
74 static void test_jumprh(void)
75 {
76     uint32_t res;
77     asm ("%0 = #5\n\t"
78          "r0 = ##1f\n\t"
79          "jumprh r0\n\t"
80          "%0 = #3\n\t"
81          "jump 2f\n\t"
82          "1:\n\t"
83          "%0 = #1\n\t"
84          "2:\n\t"
85          : "=r"(res) : : "r0");
86     check32(res, 1);
87 }
88 
89 int main()
90 {
91     test_callrh();
92     test_jumprh();
93 
94     puts(err ? "FAIL" : "PASS");
95     return err ? 1 : 0;
96 }
97