| 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 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 23 | |
| 24 | static inline void __check32(int line, uint32_t val, uint32_t expect) |
| 25 | { |
| 26 | if (val != expect) { |
| 27 | printf("ERROR at line %d: 0x%08x != 0x%08x\n", line, val, expect); |
| 28 | err++; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | #define check32(RES, EXP) __check32(__LINE__, RES, EXP) |
| 33 | |
| 34 | static inline void __check64(int line, uint64_t val, uint64_t expect) |
| 35 | { |
| 36 | if (val != expect) { |
| 37 | printf("ERROR at line %d: 0x%016llx != 0x%016llx\n", line, val, expect); |
| 38 | err++; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | #define check64(RES, EXP) __check64(__LINE__, RES, EXP) |
| 43 | |
| 44 | static inline void __chk_error(const char *filename, int line, int ret) |
| 45 | { |
| 46 | if (ret < 0) { |
| 47 | printf("ERROR %s:%d - %d\n", filename, line, ret); |
| 48 | err++; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | #define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret)) |
| 53 | |
| 54 | static inline void __checkp(int line, void *p, void *expect) |
| 55 | { |
| 56 | if (p != expect) { |
| 57 | printf("ERROR at line %d: 0x%p != 0x%p\n", line, p, expect); |
| 58 | err++; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | #define checkp(RES, EXP) __checkp(__LINE__, RES, EXP) |
| 63 | |
| 64 | static inline void __check32_ne(int line, uint32_t val, uint32_t expect) |
| 65 | { |
| 66 | if (val == expect) { |
| 67 | printf("ERROR at line %d: 0x%08x == 0x%08x\n", line, val, expect); |
| 68 | err++; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #define check32_ne(RES, EXP) __check32_ne(__LINE__, RES, EXP) |
| 73 | |
| 74 | static inline void __check64_ne(int line, uint64_t val, uint64_t expect) |
| 75 | { |
| 76 | if (val == expect) { |
| 77 | printf("ERROR at line %d: 0x%016llx == 0x%016llx\n", line, val, expect); |
| 78 | err++; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | #define check64_ne(RES, EXP) __check64_ne(__LINE__, RES, EXP) |
| 83 | |
| 84 | /* Define the bits in Hexagon USR register */ |
| 85 | #define USR_OVF_BIT 0 /* Sticky saturation overflow */ |
| 86 | #define USR_FPINVF_BIT 1 /* IEEE FP invalid sticky flag */ |
| 87 | #define USR_FPDBZF_BIT 2 /* IEEE FP divide-by-zero sticky flag */ |
| 88 | #define USR_FPOVFF_BIT 3 /* IEEE FP overflow sticky flag */ |
| 89 | #define USR_FPUNFF_BIT 4 /* IEEE FP underflow sticky flag */ |
| 90 | #define USR_FPINPF_BIT 5 /* IEEE FP inexact sticky flag */ |
| 91 | |
| 92 | /* Corresponding values in USR */ |
| 93 | #define USR_CLEAR 0 |
| 94 | #define USR_OVF (1 << USR_OVF_BIT) |
| 95 | #define USR_FPINVF (1 << USR_FPINVF_BIT) |
| 96 | #define USR_FPDBZF (1 << USR_FPDBZF_BIT) |
| 97 | #define USR_FPOVFF (1 << USR_FPOVFF_BIT) |
| 98 | #define USR_FPUNFF (1 << USR_FPUNFF_BIT) |
| 99 | #define USR_FPINPF (1 << USR_FPINPF_BIT) |
| 100 | |
| 101 | /* Clear bits 0-5 in USR */ |
| 102 | #define CLEAR_USRBITS \ |
| 103 | "r2 = usr\n\t" \ |
| 104 | "r2 = and(r2, #0xffffffc0)\n\t" \ |
| 105 | "usr = r2\n\t" |
| 106 | |
| 107 | /* Clear bits 1-5 in USR */ |
| 108 | #define CLEAR_FPSTATUS \ |
| 109 | "r2 = usr\n\t" \ |
| 110 | "r2 = and(r2, #0xffffffc1)\n\t" \ |
| 111 | "usr = r2\n\t" |
| 112 | |
| 113 | /* Some useful floating point values */ |
| 114 | const uint16_t HF_INF = 0x7c00; |
| 115 | const uint16_t HF_INF_neg = 0xfc00; |
| 116 | const uint16_t HF_QNaN = 0x7e00; |
| 117 | const uint16_t HF_SNaN = 0x7d00; |
| 118 | const uint16_t HF_SNaN_neg = 0xfd00; |
| 119 | const uint16_t HF_QNaN_neg = 0xfe00; |
| 120 | const uint16_t HF_zero = 0x0000; |
| 121 | const uint16_t HF_zero_neg = 0x8000; |
| 122 | const uint16_t HF_one = 0x3c00; |
| 123 | const uint16_t HF_one_recip = 0x3bf9; |
| 124 | const uint16_t HF_two = 0x4000; |
| 125 | const uint16_t HF_small_neg = 0x8010; |
| 126 | const uint16_t HF_any = 0x3c00; |
| 127 | const uint16_t HF_neg_two = 0xc000; |
| 128 | |
| 129 | const uint16_t BF_INF = 0x7f80; |
| 130 | const uint16_t BF_INF_neg = 0xff80; |
| 131 | const uint16_t BF_QNaN = 0x7fc0; |
| 132 | const uint16_t BF_SNaN = 0x7f81; |
| 133 | const uint16_t BF_QNaN_neg = 0xffc0; |
| 134 | const uint16_t BF_SNaN_neg = 0xff81; |
| 135 | const uint16_t BF_HEX_NaN = 0x7fff; |
| 136 | const uint16_t BF_zero = 0x0000; |
| 137 | const uint16_t BF_zero_neg = 0x8000; |
| 138 | const uint16_t BF_one = 0x3f80; |
| 139 | const uint16_t BF_two = 0x4000; |
| 140 | const uint16_t BF_four = 0x4080; |
| 141 | |
| 142 | const uint32_t SF_INF = 0x7f800000; |
| 143 | const uint32_t SF_INF_neg = 0xff800000; |
| 144 | const uint32_t SF_QNaN = 0x7fc00000; |
| 145 | const uint32_t SF_QNaN_special = 0x7f800001; |
| 146 | const uint32_t SF_SNaN = 0x7fb00000; |
| 147 | const uint32_t SF_QNaN_neg = 0xffc00000; |
| 148 | const uint32_t SF_SNaN_neg = 0xffb00000; |
| 149 | const uint32_t SF_HEX_NaN = 0xffffffff; |
| 150 | const uint32_t SF_zero = 0x00000000; |
| 151 | const uint32_t SF_zero_neg = 0x80000000; |
| 152 | const uint32_t SF_one = 0x3f800000; |
| 153 | const uint32_t SF_one_recip = 0x3f7f0001; /* 0.9960... */ |
| 154 | const uint32_t SF_one_invsqrta = 0x3f7f0000; /* 0.99609375 */ |
| 155 | const uint32_t SF_two = 0x40000000; |
| 156 | const uint32_t SF_four = 0x40800000; |
| 157 | const uint32_t SF_small_neg = 0xab98fba8; |
| 158 | const uint32_t SF_large_pos = 0x5afa572e; |
| 159 | const uint32_t SF_any = 0x3f800000; |
| 160 | const uint32_t SF_denorm = 0x00000001; |
| 161 | const uint32_t SF_random = 0x346001d6; |
| 162 | const uint32_t SF_neg_two = 0xc0000000; |
| 163 | |
| 164 | const uint64_t DF_QNaN = 0x7ff8000000000000ULL; |
| 165 | const uint64_t DF_SNaN = 0x7ff7000000000000ULL; |
| 166 | const uint64_t DF_QNaN_neg = 0xfff8000000000000ULL; |
| 167 | const uint64_t DF_SNaN_neg = 0xfff7000000000000ULL; |
| 168 | const uint64_t DF_HEX_NaN = 0xffffffffffffffffULL; |
| 169 | const uint64_t DF_zero = 0x0000000000000000ULL; |
| 170 | const uint64_t DF_zero_neg = 0x8000000000000000ULL; |
| 171 | const uint64_t DF_any = 0x3f80000000000000ULL; |
| 172 | const uint64_t DF_one = 0x3ff0000000000000ULL; |
| 173 | const uint64_t DF_one_hh = 0x3ff001ff80000000ULL; /* 1.00048... */ |
| 174 | const uint64_t DF_small_neg = 0xbd731f7500000000ULL; |
| 175 | const uint64_t DF_large_pos = 0x7f80000000000001ULL; |
| 176 | |
| 177 | #endif |