| 1 |
incdir "tests" |
| 2 |
include "dsp_base.inc" |
| 3 |
|
| 4 |
input_ax: |
| 5 |
; [0] - 0x0000'0000 - 0 |
| 6 |
CW 0 |
| 7 |
CW 0 |
| 8 |
; [1] - 0x0000'0001 - 1 in $ax0.l |
| 9 |
CW 0 |
| 10 |
CW 1 |
| 11 |
; [2] - 0x0000'ffff - -1 in $ax0.l |
| 12 |
CW 0 |
| 13 |
CW 0xffff |
| 14 |
; [3] - 0x0001'0000 - 1 in $ax0.h |
| 15 |
CW 1 |
| 16 |
CW 0 |
| 17 |
; [4] - 0x7fff'0000 - INT_MAX in $ax0.h |
| 18 |
CW 0x7fff |
| 19 |
CW 0 |
| 20 |
; [5] - 0x8000'0000 - INT_MIN in $ax0.h |
| 21 |
CW 0x8000 |
| 22 |
CW 0 |
| 23 |
; [6] - 0xffff'0000 - -1 in $ax0.h |
| 24 |
CW 0xffff |
| 25 |
CW 0 |
| 26 |
input_ax_end: |
| 27 |
|
| 28 |
input_acc: |
| 29 |
; [0] - 0x00'0000'0000 - 0 |
| 30 |
CW 0 |
| 31 |
CW 0 |
| 32 |
CW 0 |
| 33 |
; [1] - 0x00'0000'0001 - 1 in $ac0.l |
| 34 |
CW 0 |
| 35 |
CW 0 |
| 36 |
CW 1 |
| 37 |
; [2] - 0x00'0000'ffff - -1 in $ac0.l |
| 38 |
CW 0 |
| 39 |
CW 0 |
| 40 |
CW 1 |
| 41 |
; [3] - 0x00'0001'0000 - 1 in $ac0.m |
| 42 |
CW 0 |
| 43 |
CW 1 |
| 44 |
CW 0 |
| 45 |
; [4] - 0x00'7fff'0000 - INT_MAX in $ac0.m |
| 46 |
CW 0 |
| 47 |
CW 0x7fff |
| 48 |
CW 0 |
| 49 |
; [5] - 0x00'8000'0000 - INT_MIN in $ac0.m, but not sign extended |
| 50 |
CW 0 |
| 51 |
CW 0x8000 |
| 52 |
CW 0 |
| 53 |
; [6] - 0x00'ffff'0000 - -1 in $ac0.m, but not sign extended |
| 54 |
CW 0 |
| 55 |
CW 0xffff |
| 56 |
CW 0 |
| 57 |
; [7] - 0x01'0000'0000 - 1 in $ac0.l |
| 58 |
CW 1 |
| 59 |
CW 0 |
| 60 |
CW 0 |
| 61 |
; [8] - 0x7f'ffff'0000 - true INT_MAX |
| 62 |
CW 0x7f |
| 63 |
CW 0xffff |
| 64 |
CW 0 |
| 65 |
; [9] - 0x80'0000'0000 - true INT_MIN |
| 66 |
CW 0x80 |
| 67 |
CW 0 |
| 68 |
CW 0 |
| 69 |
; [10] - 0xff'8000'0000 - INT_MIN in $ac0.m, sign-extended |
| 70 |
CW 0xff |
| 71 |
CW 0x8000 |
| 72 |
CW 0 |
| 73 |
; [11] - 0xff'ffff'0000 - -1 |
| 74 |
CW 0xff |
| 75 |
CW 0xffff |
| 76 |
CW 0 |
| 77 |
input_acc_end: |
| 78 |
|
| 79 |
/* Python script to generate the following result tables from a DSP dump: |
| 80 |
import struct |
| 81 |
def gen_tables(name, num_ax, num_acc): |
| 82 |
with open(name, "rb") as fin: |
| 83 |
data = fin.read() |
| 84 |
reg_values = list(struct.iter_unpack(">" + "H"*0x20, data)) |
| 85 |
# Initial register values (there is no corresponding send_back call for these), then our two |
| 86 |
# default value checks, then the TSTAXH test, then the CMPAXH test, then the test results |
| 87 |
assert len(reg_values) == 1 + 2 + num_ax + num_ax * num_acc + 1 |
| 88 |
print("result_table_tstaxh:") |
| 89 |
for ax in range(num_ax): |
| 90 |
# SR is register 0x13 |
| 91 |
print("CW {:#04x}".format(reg_values[3 + ax][0x13])) |
| 92 |
print("result_table_tstaxh_end:") |
| 93 |
print() |
| 94 |
print("result_table_cmpaxh:") |
| 95 |
for ax in range(num_ax): |
| 96 |
print("; ax [{}]".format(ax)) |
| 97 |
for acc in range(num_acc): |
| 98 |
print("CW {:#04x}".format(reg_values[3 + num_ax + ax * num_acc + acc][0x13])) |
| 99 |
print("result_table_cmpaxh_end:") |
| 100 |
|
| 101 |
gen_tables("dsp_dump0.bin", 7, 12) |
| 102 |
*/ |
| 103 |
|
| 104 |
result_table_tstaxh: |
| 105 |
CW 0x22a4 |
| 106 |
CW 0x22a4 |
| 107 |
CW 0x22a4 |
| 108 |
CW 0x22a0 |
| 109 |
CW 0x2280 |
| 110 |
CW 0x2288 |
| 111 |
CW 0x22a8 |
| 112 |
result_table_tstaxh_end: |
| 113 |
|
| 114 |
result_table_cmpaxh: |
| 115 |
; ax [0] |
| 116 |
CW 0x22a5 |
| 117 |
CW 0x22a1 |
| 118 |
CW 0x22a1 |
| 119 |
CW 0x22a1 |
| 120 |
CW 0x2281 |
| 121 |
CW 0x2291 |
| 122 |
CW 0x22b1 |
| 123 |
CW 0x22b1 |
| 124 |
CW 0x22b1 |
| 125 |
CW 0x22b9 |
| 126 |
CW 0x2289 |
| 127 |
CW 0x22a9 |
| 128 |
; ax [1] |
| 129 |
CW 0x22a5 |
| 130 |
CW 0x22a1 |
| 131 |
CW 0x22a1 |
| 132 |
CW 0x22a1 |
| 133 |
CW 0x2281 |
| 134 |
CW 0x2291 |
| 135 |
CW 0x22b1 |
| 136 |
CW 0x22b1 |
| 137 |
CW 0x22b1 |
| 138 |
CW 0x22b9 |
| 139 |
CW 0x2289 |
| 140 |
CW 0x22a9 |
| 141 |
; ax [2] |
| 142 |
CW 0x22a5 |
| 143 |
CW 0x22a1 |
| 144 |
CW 0x22a1 |
| 145 |
CW 0x22a1 |
| 146 |
CW 0x2281 |
| 147 |
CW 0x2291 |
| 148 |
CW 0x22b1 |
| 149 |
CW 0x22b1 |
| 150 |
CW 0x22b1 |
| 151 |
CW 0x22b9 |
| 152 |
CW 0x2289 |
| 153 |
CW 0x22a9 |
| 154 |
; ax [3] |
| 155 |
CW 0x22a8 |
| 156 |
CW 0x22a8 |
| 157 |
CW 0x22a8 |
| 158 |
CW 0x22a5 |
| 159 |
CW 0x2281 |
| 160 |
CW 0x2281 |
| 161 |
CW 0x22b1 |
| 162 |
CW 0x22b1 |
| 163 |
CW 0x22b1 |
| 164 |
CW 0x22b3 |
| 165 |
CW 0x2299 |
| 166 |
CW 0x22a9 |
| 167 |
; ax [4] |
| 168 |
CW 0x2288 |
| 169 |
CW 0x2288 |
| 170 |
CW 0x2288 |
| 171 |
CW 0x2288 |
| 172 |
CW 0x22a5 |
| 173 |
CW 0x22a1 |
| 174 |
CW 0x2291 |
| 175 |
CW 0x2291 |
| 176 |
CW 0x2291 |
| 177 |
CW 0x2293 |
| 178 |
CW 0x22b9 |
| 179 |
CW 0x2289 |
| 180 |
; ax [5] |
| 181 |
CW 0x2290 |
| 182 |
CW 0x2290 |
| 183 |
CW 0x2290 |
| 184 |
CW 0x2290 |
| 185 |
CW 0x22b0 |
| 186 |
CW 0x22b0 |
| 187 |
CW 0x2290 |
| 188 |
CW 0x2290 |
| 189 |
CW 0x229a |
| 190 |
CW 0x2298 |
| 191 |
CW 0x22a5 |
| 192 |
CW 0x2281 |
| 193 |
; ax [6] |
| 194 |
CW 0x22a0 |
| 195 |
CW 0x22a0 |
| 196 |
CW 0x22a0 |
| 197 |
CW 0x22a0 |
| 198 |
CW 0x2290 |
| 199 |
CW 0x2290 |
| 200 |
CW 0x22b0 |
| 201 |
CW 0x22b0 |
| 202 |
CW 0x22ba |
| 203 |
CW 0x22b8 |
| 204 |
CW 0x2288 |
| 205 |
CW 0x22a5 |
| 206 |
result_table_cmpaxh_end: |
| 207 |
|
| 208 |
test_main: |
| 209 |
; Perform one test using the default values |
| 210 |
; ($acc0 is 14 0009 0007 and $ax0 is 8000 0003, but this can be changed in the DSPSpy UI) |
| 211 |
; Also, as a sanity check, record the computed sizes of the result tables |
| 212 |
LRI $ar0, #input_ax |
| 213 |
LRI $ix0, #(input_ax_end - input_ax) |
| 214 |
LRI $ar1, #input_acc |
| 215 |
LRI $ix1, #(input_acc_end - input_acc) |
| 216 |
LRI $ar2, #result_table_tstaxh |
| 217 |
LRI $ix2, #(input_ax_end - input_ax)/2 |
| 218 |
LRI $ar3, #result_table_cmpaxh |
| 219 |
LRI $ix3, #((input_ax_end - input_ax)/2)*((input_acc_end - input_acc)/3) |
| 220 |
; Set the sticky overflow bit just so that we get consistent $sr values |
| 221 |
; before and after an overflow occurs |
| 222 |
SBSET #1 |
| 223 |
CMPAXH $acc0, $ax0.h |
| 224 |
CALL send_back ; Expected $sr: 2290 |
| 225 |
; $ar0 should match $ix0, etc |
| 226 |
ADDARN $ar0, $ix0 |
| 227 |
LRI $ix0, #input_ax_end |
| 228 |
ADDARN $ar1, $ix1 |
| 229 |
LRI $ix1, #input_acc_end |
| 230 |
ADDARN $ar2, $ix2 |
| 231 |
LRI $ix2, #result_table_tstaxh_end |
| 232 |
ADDARN $ar3, $ix3 |
| 233 |
LRI $ix3, #result_table_cmpaxh_end |
| 234 |
TSTAXH $ax0.h |
| 235 |
CALL send_back ; Expected $sr: 2288 |
| 236 |
|
| 237 |
CLR $acc0 |
| 238 |
CLR $acc1 |
| 239 |
LRI $ax0.h, #0 |
| 240 |
LRI $ax0.l, #0 |
| 241 |
LRI $ax1.h, #0 |
| 242 |
LRI $ax1.l, #0 |
| 243 |
|
| 244 |
; Check TSTAXH... |
| 245 |
LRI $ar0, #input_ax |
| 246 |
LRI $ar2, #result_table_tstaxh |
| 247 |
|
| 248 |
; for (int ctr = input_ax.size(); ctr > 0; ctr--) { |
| 249 |
BLOOPI #(input_ax_end - input_ax)/2, check_tstaxh_last_ins |
| 250 |
; Note: if DSPSpy supported populating DMEM as well as IMEM, then there are several |
| 251 |
; instructions that could make this faster and cleaner... but it doesn't currently, |
| 252 |
; so we're stuck with ILRRI. |
| 253 |
|
| 254 |
; Load the test value into $ax0.h/$ax0.l via $ac0.m |
| 255 |
ILRRI $ac0.m, $ar0 ; $ac0.m = IMEM[$ar0++] |
| 256 |
MRR $ax0.h, $ac0.m |
| 257 |
ILRRI $ac0.m, $ar0 |
| 258 |
MRR $ax0.l, $ac0.m |
| 259 |
; Load the expected value into $ac1.m |
| 260 |
ILRRI $ac1.m, $ar2 ; $ac1.m = IMEM[$ar2++] |
| 261 |
; Reduce noise in the results |
| 262 |
LRI $ac0.m, #0 |
| 263 |
|
| 264 |
; Do the test |
| 265 |
TSTAXH $ax0.h |
| 266 |
CALL send_back |
| 267 |
|
| 268 |
; Check if $sr matches the value we expected. If there is any difference, |
| 269 |
; note it via a nonzero $ax1.l. (send_back saves the value of $sr) |
| 270 |
MRR $ac0.m, $sr |
| 271 |
CMP |
| 272 |
IFNZ |
| 273 |
LRIS $ax1.l, #1 |
| 274 |
check_tstaxh_last_ins: |
| 275 |
NOP |
| 276 |
; } |
| 277 |
|
| 278 |
; Check CMPAXH... |
| 279 |
CLR $acc0 |
| 280 |
CLR $acc1 |
| 281 |
LRI $ar0, #input_ax |
| 282 |
LRI $ar3, #result_table_cmpaxh |
| 283 |
|
| 284 |
; for (int ctr_ax = input_ax.size(); ctr_ax > 0; ctr_ax--) { |
| 285 |
BLOOPI #(input_ax_end - input_ax)/2, check_cmpaxh_last_ins_outer |
| 286 |
; Load the test value into $ax0.h/$ax0.l via $ac1.m |
| 287 |
ILRRI $ac1.m, $ar0 |
| 288 |
MRR $ax0.h, $ac1.m |
| 289 |
ILRRI $ac1.m, $ar0 |
| 290 |
MRR $ax0.l, $ac1.m |
| 291 |
|
| 292 |
LRI $ar1, #input_acc |
| 293 |
|
| 294 |
; for (int ctr_acc = input_acc.size(); ctr_acc > 0; ctr_acc--) { |
| 295 |
BLOOPI #(input_acc_end - input_acc)/3, check_cmpaxh_last_ins_inner |
| 296 |
|
| 297 |
; Load the test value into $ac0.h/$ac0.m/$ac0.l via $ac1.m |
| 298 |
ILRRI $ac1.m, $ar1 |
| 299 |
MRR $ac0.h, $ac1.m |
| 300 |
ILRRI $ac0.m, $ar1 ; we can load it directly here |
| 301 |
ILRRI $ac1.m, $ar1 |
| 302 |
MRR $ac0.l, $ac1.m |
| 303 |
|
| 304 |
; Load the expected value into $ac1.m |
| 305 |
ILRRI $ac1.m, $ar3 |
| 306 |
|
| 307 |
; Do the test |
| 308 |
CMPAXH $acc0, $ax0.h |
| 309 |
CALL send_back |
| 310 |
|
| 311 |
; Check if $sr matches the value we expected. If there is any difference, |
| 312 |
; note it via a nonzero $ax1.h. (send_back saves the value of $sr) |
| 313 |
; We can overwrite $ac0.m here because we load it on the next iteration. |
| 314 |
MRR $ac0.m, $sr |
| 315 |
LRIS $ac0.l, #0 |
| 316 |
LRI $ac0.h, #0 |
| 317 |
CMP |
| 318 |
IFNZ |
| 319 |
LRIS $ax1.h, #1 |
| 320 |
check_cmpaxh_last_ins_inner: |
| 321 |
NOP |
| 322 |
; } |
| 323 |
check_cmpaxh_last_ins_outer: |
| 324 |
NOP |
| 325 |
; } |
| 326 |
|
| 327 |
; We're done testing. In the final send_back call, if $ax1.l or $ax1.h |
| 328 |
; is nonzero, the test failed. |
| 329 |
CALL send_back |
| 330 |
|
| 331 |
; We're done, DO NOT DELETE THIS LINE |
| 332 |
JMP end_of_test |