xref: /openbmc/qemu/tests/tcg/hexagon/hex_test.h (revision 7d87775f)
1 /*
2  *  Copyright(c) 2022-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 
19 #ifndef HEX_TEST_H
20 #define HEX_TEST_H
21 
22 static inline void __check32(int line, uint32_t val, uint32_t expect)
23 {
24     if (val != expect) {
25         printf("ERROR at line %d: 0x%08x != 0x%08x\n", line, val, expect);
26         err++;
27     }
28 }
29 
30 #define check32(RES, EXP) __check32(__LINE__, RES, EXP)
31 
32 static inline void __check64(int line, uint64_t val, uint64_t expect)
33 {
34     if (val != expect) {
35         printf("ERROR at line %d: 0x%016llx != 0x%016llx\n", line, val, expect);
36         err++;
37     }
38 }
39 
40 #define check64(RES, EXP) __check64(__LINE__, RES, EXP)
41 
42 static inline void __chk_error(const char *filename, int line, int ret)
43 {
44     if (ret < 0) {
45         printf("ERROR %s:%d - %d\n", filename, line, ret);
46         err++;
47     }
48 }
49 
50 #define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret))
51 
52 static inline void __checkp(int line, void *p, void *expect)
53 {
54     if (p != expect) {
55         printf("ERROR at line %d: 0x%p != 0x%p\n", line, p, expect);
56         err++;
57     }
58 }
59 
60 #define checkp(RES, EXP) __checkp(__LINE__, RES, EXP)
61 
62 static inline void __check32_ne(int line, uint32_t val, uint32_t expect)
63 {
64     if (val == expect) {
65         printf("ERROR at line %d: 0x%08x == 0x%08x\n", line, val, expect);
66         err++;
67     }
68 }
69 
70 #define check32_ne(RES, EXP) __check32_ne(__LINE__, RES, EXP)
71 
72 static inline void __check64_ne(int line, uint64_t val, uint64_t expect)
73 {
74     if (val == expect) {
75         printf("ERROR at line %d: 0x%016llx == 0x%016llx\n", line, val, expect);
76         err++;
77     }
78 }
79 
80 #define check64_ne(RES, EXP) __check64_ne(__LINE__, RES, EXP)
81 
82 /* Define the bits in Hexagon USR register */
83 #define USR_OVF_BIT          0        /* Sticky saturation overflow */
84 #define USR_FPINVF_BIT       1        /* IEEE FP invalid sticky flag */
85 #define USR_FPDBZF_BIT       2        /* IEEE FP divide-by-zero sticky flag */
86 #define USR_FPOVFF_BIT       3        /* IEEE FP overflow sticky flag */
87 #define USR_FPUNFF_BIT       4        /* IEEE FP underflow sticky flag */
88 #define USR_FPINPF_BIT       5        /* IEEE FP inexact sticky flag */
89 
90 /* Corresponding values in USR */
91 #define USR_CLEAR            0
92 #define USR_OVF              (1 << USR_OVF_BIT)
93 #define USR_FPINVF           (1 << USR_FPINVF_BIT)
94 #define USR_FPDBZF           (1 << USR_FPDBZF_BIT)
95 #define USR_FPOVFF           (1 << USR_FPOVFF_BIT)
96 #define USR_FPUNFF           (1 << USR_FPUNFF_BIT)
97 #define USR_FPINPF           (1 << USR_FPINPF_BIT)
98 
99 /* Clear bits 0-5 in USR */
100 #define CLEAR_USRBITS \
101     "r2 = usr\n\t" \
102     "r2 = and(r2, #0xffffffc0)\n\t" \
103     "usr = r2\n\t"
104 
105 /* Clear bits 1-5 in USR */
106 #define CLEAR_FPSTATUS \
107     "r2 = usr\n\t" \
108     "r2 = and(r2, #0xffffffc1)\n\t" \
109     "usr = r2\n\t"
110 
111 /* Some useful floating point values */
112 const uint32_t SF_INF =              0x7f800000;
113 const uint32_t SF_QNaN =             0x7fc00000;
114 const uint32_t SF_QNaN_special =     0x7f800001;
115 const uint32_t SF_SNaN =             0x7fb00000;
116 const uint32_t SF_QNaN_neg =         0xffc00000;
117 const uint32_t SF_SNaN_neg =         0xffb00000;
118 const uint32_t SF_HEX_NaN =          0xffffffff;
119 const uint32_t SF_zero =             0x00000000;
120 const uint32_t SF_zero_neg =         0x80000000;
121 const uint32_t SF_one =              0x3f800000;
122 const uint32_t SF_one_recip =        0x3f7f0001;         /* 0.9960...  */
123 const uint32_t SF_one_invsqrta =     0x3f7f0000;         /* 0.99609375 */
124 const uint32_t SF_two =              0x40000000;
125 const uint32_t SF_four =             0x40800000;
126 const uint32_t SF_small_neg =        0xab98fba8;
127 const uint32_t SF_large_pos =        0x5afa572e;
128 const uint32_t SF_any =              0x3f800000;
129 const uint32_t SF_denorm =           0x00000001;
130 const uint32_t SF_random =           0x346001d6;
131 
132 const uint64_t DF_QNaN =             0x7ff8000000000000ULL;
133 const uint64_t DF_SNaN =             0x7ff7000000000000ULL;
134 const uint64_t DF_QNaN_neg =         0xfff8000000000000ULL;
135 const uint64_t DF_SNaN_neg =         0xfff7000000000000ULL;
136 const uint64_t DF_HEX_NaN =          0xffffffffffffffffULL;
137 const uint64_t DF_zero =             0x0000000000000000ULL;
138 const uint64_t DF_zero_neg =         0x8000000000000000ULL;
139 const uint64_t DF_any =              0x3f80000000000000ULL;
140 const uint64_t DF_one =              0x3ff0000000000000ULL;
141 const uint64_t DF_one_hh =           0x3ff001ff80000000ULL;     /* 1.00048... */
142 const uint64_t DF_small_neg =        0xbd731f7500000000ULL;
143 const uint64_t DF_large_pos =        0x7f80000000000001ULL;
144 
145 #endif
146