cmpaxh_test.ds 6.5 KB

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