utils-dsp.inc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. # MIPS DSP ASE simulator testsuite utility functions.
  2. # Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. # Contributed by MIPS Technologies, Inc. Written by Chao-ying Fu.
  4. #
  5. # This file is part of the GNU simulators.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>. */
  19. # $4, $5, $6, $7, $ac0, $ac1, $ac2, $ac3 are used as temps by the macros
  20. # defined here.
  21. # If a != b, jump to _fail.
  22. # Otherwise, fall through.
  23. .macro dsp_assert a, b
  24. beq \a, \b, 1f
  25. nop
  26. j _fail
  27. nop
  28. 1:
  29. .endm
  30. # Set dsp control register <= crin
  31. # Check if d == (inst ?, s, t)
  32. # Check if crout == dsp control register
  33. .macro dspck_dstio inst, d, s, t, crin, crout
  34. li $4, \crin
  35. wrdsp $4
  36. li $4, \s
  37. li $5, \t
  38. \inst $6, $4, $5
  39. li $7, \d
  40. dsp_assert $6, $7
  41. li $4, \crout
  42. rddsp $5
  43. dsp_assert $4, $5
  44. .endm
  45. # Set dsp control register <= crin
  46. # (inst s, t)
  47. # Check if crout == dsp control register
  48. .macro dspck_stio inst, s, t, crin, crout
  49. li $4, \crin
  50. wrdsp $4
  51. li $4, \s
  52. li $5, \t
  53. \inst $4, $5
  54. li $4, \crout
  55. rddsp $5
  56. dsp_assert $4, $5
  57. .endm
  58. # Set dsp control register <= crin
  59. # Check if d == (inst ?, s, t)
  60. .macro dspck_dsti inst, d, s, t, crin
  61. li $4, \crin
  62. wrdsp $4
  63. li $4, \s
  64. li $5, \t
  65. \inst $6, $4, $5
  66. li $7, \d
  67. dsp_assert $6, $7
  68. .endm
  69. # Set dsp control register <= crin
  70. # Check if tou == (inst tin, s)
  71. .macro dspck_tsi inst, tou, tin, s, crin
  72. li $4, \crin
  73. wrdsp $4
  74. li $4, \s
  75. li $5, \tin
  76. \inst $5, $4
  77. li $6, \tou
  78. dsp_assert $5, $6
  79. .endm
  80. # Set dsp control register <= crin
  81. # Check if d == (inst ?, imm)
  82. # Check if crout == dsp control register
  83. .macro dspck_dIio inst, d, imm, crin, crout
  84. li $4, \crin
  85. wrdsp $4
  86. \inst $5, \imm
  87. li $6, \d
  88. dsp_assert $5, $6
  89. li $4, \crout
  90. rddsp $5
  91. dsp_assert $4, $5
  92. .endm
  93. # Set dsp control register <= crin
  94. # Check if d == (inst ?, s)
  95. # Check if crout == dsp control register
  96. .macro dspck_dsio inst, d, s, crin, crout
  97. li $4, \crin
  98. wrdsp $4
  99. li $4, \s
  100. \inst $6, $4
  101. li $7, \d
  102. dsp_assert $6, $7
  103. li $4, \crout
  104. rddsp $5
  105. dsp_assert $4, $5
  106. .endm
  107. # Set dsp control register <= crin
  108. # Check if d == (inst ?, t, sa)
  109. # Check if crout == dsp control register
  110. .macro dspck_dtsaio inst, d, t, sa, crin, crout
  111. li $4, \crin
  112. wrdsp $4
  113. li $4, \t
  114. \inst $6, $4, \sa
  115. li $7, \d
  116. dsp_assert $6, $7
  117. li $4, \crout
  118. rddsp $5
  119. dsp_assert $4, $5
  120. .endm
  121. # Set dsp control register <= crin
  122. # Check if d == (inst ?, t, sa)
  123. .macro dspck_dtsai inst, d, t, sa, crin
  124. li $4, \crin
  125. wrdsp $4
  126. li $4, \t
  127. \inst $6, $4, \sa
  128. li $7, \d
  129. dsp_assert $6, $7
  130. .endm
  131. # Set dsp control register <= crin
  132. # Set $ac3 <= {hiin, loin}
  133. # (inst $ac3, s, t)
  134. # Check if {hiou, loou} == $ac3
  135. # Check if (crout & 0x80000) == (dsp control register & 0x80000)
  136. .macro dspck_astio inst, hiin, loin, hiou, loou, s, t, crin, crout
  137. li $4, \crin
  138. wrdsp $4
  139. li $4, \hiin
  140. mthi $4, $ac3
  141. li $4, \loin
  142. mtlo $4, $ac3
  143. li $4, \s
  144. li $5, \t
  145. \inst $ac3, $4, $5
  146. li $4, \hiou
  147. mfhi $5, $ac3
  148. dsp_assert $4, $5
  149. li $4, \loou
  150. mflo $5, $ac3
  151. dsp_assert $4, $5
  152. li $4, \crout
  153. and $4, $4, 0x80000
  154. rddsp $5
  155. and $5, $5, 0x80000
  156. dsp_assert $4, $5
  157. .endm
  158. # Set dsp control register <= crin
  159. # Set $ac1 <= {hi, lo}
  160. # Check if t == (inst ? $ac1, sa)
  161. # Check if crout == dsp control register
  162. .macro dspck_atsaio inst, hi, lo, t, sa, crin, crout
  163. li $4, \crin
  164. wrdsp $4
  165. li $4, \hi
  166. mthi $4, $ac1
  167. li $4, \lo
  168. mtlo $4, $ac1
  169. \inst $5, $ac1, \sa
  170. li $6, \t
  171. dsp_assert $5, $6
  172. li $4, \crout
  173. rddsp $5
  174. dsp_assert $4, $5
  175. .endm
  176. # Set dsp control register <= crin
  177. # Set acc <= {hiin, loin}
  178. # (inst acc, s, t)
  179. # Check if {hiou, loou} == acc
  180. # Check if (crout & 0x80000) == (dsp control register & 0x80000)
  181. .macro dspckacc_astio inst, acc, hiin, loin, hiou, loou, s, t, crin, crout
  182. li $4, \crin
  183. wrdsp $4
  184. li $4, \hiin
  185. mthi $4, \acc
  186. li $4, \loin
  187. mtlo $4, \acc
  188. li $4, \s
  189. li $5, \t
  190. \inst \acc, $4, $5
  191. li $4, \hiou
  192. mfhi $5, \acc
  193. dsp_assert $4, $5
  194. li $4, \loou
  195. mflo $5, \acc
  196. dsp_assert $4, $5
  197. li $4, \crout
  198. and $4, $4, 0x80000
  199. rddsp $5
  200. and $5, $5, 0x80000
  201. dsp_assert $4, $5
  202. .endm
  203. # Set dsp control register <= crin
  204. # Set $ac1 <= {hi, lo}
  205. # Check if t == (inst ? $ac1, s)
  206. # Check if crout == dsp control register
  207. .macro dspck_atsio inst, hi, lo, t, s, crin, crout
  208. li $4, \crin
  209. wrdsp $4
  210. li $4, \hi
  211. mthi $4, $ac1
  212. li $4, \lo
  213. mtlo $4, $ac1
  214. li $4, \s
  215. \inst $5, $ac1, $4
  216. li $6, \t
  217. dsp_assert $5, $6
  218. li $4, \crout
  219. rddsp $5
  220. dsp_assert $4, $5
  221. .endm
  222. # Set dsp control register <= (crin & crinmask)
  223. # Set $ac2 <= {hi, lo}
  224. # Check if t == (inst ? $ac2, size)
  225. # Check if (crout & croutmask) == (dsp control register & croutmask)
  226. .macro dspck_tasiimom inst, hi, lo, t, size, crin, crinmask, crout, croutmask
  227. li $4, \crin
  228. and $4, \crinmask
  229. wrdsp $4
  230. li $4, \hi
  231. mthi $4, $ac2
  232. li $4, \lo
  233. mtlo $4, $ac2
  234. \inst $5, $ac2, \size
  235. li $6, \t
  236. dsp_assert $5, $6
  237. li $4, \crout
  238. and $4, \croutmask
  239. rddsp $5
  240. and $5, \croutmask
  241. dsp_assert $4, $5
  242. .endm
  243. # Set dsp control register <= (crin & crinmask)
  244. # Set $ac2 <= {hi, lo}
  245. # Check if t == (inst ? $ac2, size)
  246. .macro dspck_tasiim inst, hi, lo, t, size, crin, crinmask
  247. li $4, \crin
  248. and $4, \crinmask
  249. wrdsp $4
  250. li $4, \hi
  251. mthi $4, $ac2
  252. li $4, \lo
  253. mtlo $4, $ac2
  254. \inst $5, $ac2, \size
  255. li $6, \t
  256. dsp_assert $5, $6
  257. .endm
  258. # Set dsp control register <= (crin & crinmask)
  259. # Set $ac2 <= {hi, lo}
  260. # Check if t == (inst ? $ac2, s)
  261. # Check if (crout & croutmask) == (dsp control register & croutmask)
  262. .macro dspck_tasimom inst, hi, lo, t, s, crin, crinmask, crout, croutmask
  263. li $4, \crin
  264. and $4, \crinmask
  265. wrdsp $4
  266. li $4, \hi
  267. mthi $4, $ac2
  268. li $4, \lo
  269. mtlo $4, $ac2
  270. li $4, \s
  271. \inst $5, $ac2, $4
  272. li $6, \t
  273. dsp_assert $5, $6
  274. li $4, \crout
  275. and $4, \croutmask
  276. rddsp $5
  277. and $5, \croutmask
  278. dsp_assert $4, $5
  279. .endm
  280. # Set dsp control register <= (crin & crinmask)
  281. # Set $ac2 <= {hi, lo}
  282. # Check if t == (inst ? $ac2, s)
  283. .macro dspck_tasim inst, hi, lo, t, s, crin, crinmask
  284. li $4, \crin
  285. and $4, \crinmask
  286. wrdsp $4
  287. li $4, \hi
  288. mthi $4, $ac2
  289. li $4, \lo
  290. mtlo $4, $ac2
  291. li $4, \s
  292. \inst $5, $ac2, $4
  293. li $6, \t
  294. dsp_assert $5, $6
  295. .endm
  296. # Set dsp control register <= crin
  297. # Set $ac0 <= {hi, lo}
  298. # (inst $ac0, shift)
  299. # Check if $ac0 == {hio, loo}
  300. # Check if crout == dsp control register
  301. .macro dspck_asaio inst, hi, lo, hio, loo, shift, crin, crout
  302. li $4, \crin
  303. wrdsp $4
  304. li $4, \hi
  305. mthi $4, $ac0
  306. li $4, \lo
  307. mtlo $4, $ac0
  308. \inst $ac0, \shift
  309. mfhi $5, $ac0
  310. li $6, \hio
  311. dsp_assert $5, $6
  312. mflo $5, $ac0
  313. li $6, \loo
  314. dsp_assert $5, $6
  315. li $4, \crout
  316. rddsp $5
  317. dsp_assert $4, $5
  318. .endm
  319. # Set dsp control register <= crin
  320. # Set $ac0 <= {hi, lo}
  321. # (inst $ac0, s)
  322. # Check if $ac0 == {hio, loo}
  323. # Check if crout == dsp control register
  324. .macro dspck_asio inst, hi, lo, hio, loo, s, crin, crout
  325. li $4, \crin
  326. wrdsp $4
  327. li $4, \hi
  328. mthi $4, $ac0
  329. li $4, \lo
  330. mtlo $4, $ac0
  331. li $4, \s
  332. \inst $ac0, $4
  333. mfhi $5, $ac0
  334. li $6, \hio
  335. dsp_assert $5, $6
  336. mflo $5, $ac0
  337. li $6, \loo
  338. dsp_assert $5, $6
  339. li $4, \crout
  340. rddsp $5
  341. dsp_assert $4, $5
  342. .endm
  343. # Set dsp control register <= crin
  344. # Set $ac3 <= {hi, lo}
  345. # Check if s == (inst ? $ac3)
  346. # Check if $ac3 == {hio, loo}
  347. # Check if crout == dsp control register
  348. .macro dspck_saio inst, hi, lo, hio, loo, s, crin, crout
  349. li $4, \crin
  350. wrdsp $4
  351. li $4, \hi
  352. mthi $4, $ac3
  353. li $4, \lo
  354. mtlo $4, $ac3
  355. li $5, \s
  356. \inst $5, $ac3
  357. mfhi $5, $ac3
  358. li $6, \hio
  359. dsp_assert $5, $6
  360. mflo $5, $ac3
  361. li $6, \loo
  362. dsp_assert $5, $6
  363. li $4, \crout
  364. rddsp $5
  365. dsp_assert $4, $5
  366. .endm
  367. # Set dsp control register <= crin
  368. # (wrdsp s, m)
  369. # Check if crout == dsp control register
  370. .macro dspck_wrdsp s, m, crin, crout
  371. li $4, \crin
  372. wrdsp $4
  373. li $5, \s
  374. wrdsp $5, \m
  375. li $6, \crout
  376. rddsp $7
  377. dsp_assert $6, $7
  378. .endm
  379. # Set dsp control register <= crin
  380. # Check if d == (rddsp ?, m)
  381. .macro dspck_rddsp d, m, crin
  382. li $4, \crin
  383. wrdsp $4
  384. rddsp $5, \m
  385. li $6, \d
  386. dsp_assert $5, $6
  387. .endm
  388. # Check if d == (inst i(b))
  389. .macro dspck_load inst, d, i, b
  390. li $4, \i
  391. la $5, \b
  392. \inst $6, $4($5)
  393. li $7, \d
  394. dsp_assert $6, $7
  395. .endm
  396. # Set dsp control register <= crin
  397. # Check if bposge32 is taken or not as expected in r
  398. # (1 => taken, 0 => not taken)
  399. .macro dspck_bposge32 crin, r
  400. li $4, \crin
  401. wrdsp $4
  402. li $5, 1
  403. bposge32 1f
  404. nop
  405. li $5, 0
  406. 1:
  407. li $6, \r
  408. dsp_assert $5, $6
  409. .endm
  410. # Check if tou == (inst tin, s)
  411. .macro dspck_tsimm inst, tou, tin, s, sa
  412. li $4, \s
  413. li $5, \tin
  414. \inst $5, $4, \sa
  415. li $6, \tou
  416. dsp_assert $5, $6
  417. .endm