dsp.igen 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071
  1. // -*- C -*-
  2. // Simulator definition for the MIPS DSP ASE.
  3. // Copyright (C) 2005-2015 Free Software Foundation, Inc.
  4. // Contributed by MIPS Technologies, Inc. Written by Chao-ying Fu.
  5. //
  6. // This file is part of the MIPS sim
  7. //
  8. // This program is free software; you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation; either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. // op: 0 = ADD, 1 = SUB, 2 = MUL
  21. // sat: 0 = no saturation, 1 = saturation
  22. :function:::void:do_ph_op:int rd, int rs, int rt, int op, int sat
  23. {
  24. int i;
  25. signed32 h0 = 0;
  26. signed16 h1, h2;
  27. unsigned32 v1 = GPR[rs];
  28. unsigned32 v2 = GPR[rt];
  29. unsigned32 result = 0;
  30. for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
  31. {
  32. h1 = (signed16)(v1 & 0xffff);
  33. h2 = (signed16)(v2 & 0xffff);
  34. if (op == 0) // ADD
  35. h0 = (signed32)h1 + (signed32)h2;
  36. else if (op == 1) // SUB
  37. h0 = (signed32)h1 - (signed32)h2;
  38. else // MUL
  39. h0 = (signed32)h1 * (signed32)h2;
  40. if (h0 > (signed32)0x7fff || h0 < (signed32)0xffff8000)
  41. {
  42. if (op == 0 || op == 1) // ADD, SUB
  43. DSPCR |= DSPCR_OUFLAG4;
  44. else if (op == 2) // MUL
  45. DSPCR |= DSPCR_OUFLAG5;
  46. if (sat == 1)
  47. {
  48. if (h0 > (signed32)0x7fff)
  49. h0 = 0x7fff;
  50. else
  51. h0 = 0x8000;
  52. }
  53. }
  54. result |= ((unsigned32)((unsigned16)h0) << i);
  55. }
  56. GPR[rd] = EXTEND32 (result);
  57. }
  58. // op: 0 = ADD, 1 = SUB
  59. :function:::void:do_w_op:int rd, int rs, int rt, int op
  60. {
  61. signed64 h0;
  62. signed32 h1, h2;
  63. unsigned32 v1 = GPR[rs];
  64. unsigned32 v2 = GPR[rt];
  65. unsigned32 result = 0;
  66. h1 = (signed32)v1;
  67. h2 = (signed32)v2;
  68. if (op == 0) // ADD
  69. h0 = (signed64)h1 + (signed64)h2;
  70. else // SUB
  71. h0 = (signed64)h1 - (signed64)h2;
  72. if (((h0 & 0x100000000LL) >> 1) != (h0 & 0x80000000))
  73. {
  74. DSPCR |= DSPCR_OUFLAG4;
  75. if (h0 & 0x100000000LL)
  76. h0 = 0x80000000;
  77. else
  78. h0 = 0x7fffffff;
  79. }
  80. GPR[rd] = EXTEND32 (h0);
  81. }
  82. // op: 0 = ADD, 1 = SUB
  83. // sat: 0 = no saturation, 1 = saturation
  84. :function:::void:do_qb_op:int rd, int rs, int rt, int op, int sat
  85. {
  86. int i;
  87. unsigned32 h0;
  88. unsigned8 h1, h2;
  89. unsigned32 v1 = GPR[rs];
  90. unsigned32 v2 = GPR[rt];
  91. unsigned32 result = 0;
  92. for (i = 0; i < 32; i += 8, v1 >>= 8, v2 >>= 8)
  93. {
  94. h1 = (unsigned8)(v1 & 0xff);
  95. h2 = (unsigned8)(v2 & 0xff);
  96. if (op == 0) // ADD
  97. h0 = (unsigned32)h1 + (unsigned32)h2;
  98. else // SUB
  99. h0 = (unsigned32)h1 - (unsigned32)h2;
  100. if (h0 & 0x100)
  101. {
  102. DSPCR |= DSPCR_OUFLAG4;
  103. if (sat == 1)
  104. {
  105. if (op == 0) // ADD
  106. h0 = 0xff;
  107. else // SUB
  108. h0 = 0;
  109. }
  110. }
  111. result |= ((unsigned32)((unsigned8)h0) << i);
  112. }
  113. GPR[rd] = EXTEND32 (result);
  114. }
  115. // op: 0 = left, 1 = right
  116. :function:::void:do_qb_shift:int rd, int rt, int shift, int op
  117. {
  118. int i, j;
  119. unsigned8 h0;
  120. unsigned32 v1 = GPR[rt];
  121. unsigned32 result = 0;
  122. for (i = 0; i < 32; i += 8, v1 >>= 8)
  123. {
  124. h0 = (unsigned8)(v1 & 0xff);
  125. if (op == 0) // left
  126. {
  127. for (j = 7; j >= 8 - shift; j--)
  128. {
  129. if (h0 & (1<<j))
  130. {
  131. DSPCR |= DSPCR_OUFLAG6;
  132. break;
  133. }
  134. }
  135. h0 = h0 << shift;
  136. }
  137. else // right
  138. h0 = h0 >> shift;
  139. result |= ((unsigned32)h0 << i);
  140. }
  141. GPR[rd] = EXTEND32 (result);
  142. }
  143. // op: 0 = left, 1 = right
  144. // sat: 0 = no saturation/rounding, 1 = saturation/rounding
  145. :function:::void:do_ph_shift:int rd, int rt, int shift, int op, int sat
  146. {
  147. int i, j;
  148. signed16 h0;
  149. unsigned32 v1 = GPR[rt];
  150. unsigned32 result = 0;
  151. int setcond;
  152. for (i = 0; i < 32; i += 16, v1 >>= 16)
  153. {
  154. h0 = (signed16)(v1 & 0xffff);
  155. if (op == 0) // left
  156. {
  157. setcond = 0;
  158. if (h0 & (1<<15))
  159. {
  160. for (j = 14; j >= 15 - shift; j--)
  161. {
  162. if (!(h0 & (1 << j)))
  163. {
  164. DSPCR |= DSPCR_OUFLAG6;
  165. setcond = 1;
  166. break;
  167. }
  168. }
  169. }
  170. else
  171. {
  172. for (j = 14; j >= 15 - shift; j--)
  173. {
  174. if (h0 & (1 << j))
  175. {
  176. DSPCR |= DSPCR_OUFLAG6;
  177. setcond = 2;
  178. break;
  179. }
  180. }
  181. }
  182. h0 = h0 << shift;
  183. if (sat == 1)
  184. {
  185. if (setcond == 2)
  186. h0 = 0x7fff;
  187. else if (setcond == 1)
  188. h0 = 0x8000;
  189. }
  190. }
  191. else // right
  192. {
  193. if (sat == 1 && shift != 0 && (h0 & (1 << (shift-1))))
  194. h0 = (h0 >> shift) + 1;
  195. else
  196. h0 = h0 >> shift;
  197. }
  198. result |= ((unsigned32)((unsigned16)h0) << i);
  199. }
  200. GPR[rd] = EXTEND32 (result);
  201. }
  202. :function:::void:do_w_shll:int rd, int rt, int shift
  203. {
  204. int i;
  205. unsigned32 v1 = GPR[rt];
  206. unsigned32 result = 0;
  207. int setcond = 0;
  208. if (v1 & (1 << 31))
  209. {
  210. for (i = 30; i >= 31 - shift; i--)
  211. {
  212. if (!(v1 & (1 << i)))
  213. {
  214. DSPCR |= DSPCR_OUFLAG6;
  215. setcond = 1;
  216. break;
  217. }
  218. }
  219. }
  220. else
  221. {
  222. for (i = 30; i >= 31 - shift; i--)
  223. {
  224. if (v1 & (1 << i))
  225. {
  226. DSPCR |= DSPCR_OUFLAG6;
  227. setcond = 2;
  228. break;
  229. }
  230. }
  231. }
  232. if (setcond == 2)
  233. result = 0x7fffffff;
  234. else if (setcond == 1)
  235. result = 0x80000000;
  236. else
  237. result = v1 << shift;
  238. GPR[rd] = EXTEND32 (result);
  239. }
  240. :function:::void:do_ph_s_absq:int rd, int rt
  241. {
  242. int i;
  243. signed16 h0;
  244. unsigned32 v1 = GPR[rt];
  245. unsigned32 result = 0;
  246. for (i = 0; i < 32; i += 16, v1 >>= 16)
  247. {
  248. h0 = (signed16)(v1 & 0xffff);
  249. if (h0 == (signed16)0x8000)
  250. {
  251. DSPCR |= DSPCR_OUFLAG4;
  252. h0 = 0x7fff;
  253. }
  254. else if (h0 & 0x8000)
  255. h0 = -h0;
  256. result |= ((unsigned32)((unsigned16)h0) << i);
  257. }
  258. GPR[rd] = EXTEND32 (result);
  259. }
  260. :function:::void:do_w_s_absq:int rd, int rt
  261. {
  262. unsigned32 v1 = GPR[rt];
  263. signed32 h0 = (signed32)v1;
  264. if (h0 == (signed32)0x80000000)
  265. {
  266. DSPCR |= DSPCR_OUFLAG4;
  267. h0 = 0x7fffffff;
  268. }
  269. else if (h0 & 0x80000000)
  270. h0 = -h0;
  271. GPR[rd] = EXTEND32 (h0);
  272. }
  273. :function:::void:do_qb_s_absq:int rd, int rt
  274. {
  275. int i;
  276. signed8 q0;
  277. unsigned32 v1 = GPR[rt];
  278. unsigned32 result = 0;
  279. for (i = 0; i < 32; i += 8, v1 >>= 8)
  280. {
  281. q0 = (signed8)(v1 & 0xff);
  282. if (q0 == (signed8)0x80)
  283. {
  284. DSPCR |= DSPCR_OUFLAG4;
  285. q0 = 0x7f;
  286. }
  287. else if (q0 & 0x80)
  288. q0 = -q0;
  289. result |= ((unsigned32)((unsigned8)q0) << i);
  290. }
  291. GPR[rd] = EXTEND32 (result);
  292. }
  293. :function:::void:do_addsc:int rd, int rs, int rt
  294. {
  295. unsigned32 v1 = GPR[rs];
  296. unsigned32 v2 = GPR[rt];
  297. unsigned64 h0;
  298. h0 = (unsigned64)v1 + (unsigned64)v2;
  299. if (h0 & 0x100000000LL)
  300. DSPCR |= DSPCR_CARRY;
  301. GPR[rd] = EXTEND32 (h0);
  302. }
  303. :function:::void:do_addwc:int rd, int rs, int rt
  304. {
  305. unsigned32 v1 = GPR[rs];
  306. unsigned32 v2 = GPR[rt];
  307. unsigned64 h0;
  308. signed32 h1 = (signed32) v1;
  309. signed32 h2 = (signed32) v2;
  310. h0 = (signed64)h1 + (signed64)h2
  311. + (signed64)((DSPCR >> DSPCR_CARRY_SHIFT) & DSPCR_CARRY_MASK);
  312. if (((h0 & 0x100000000LL) >> 1) != (h0 & 0x80000000))
  313. DSPCR |= DSPCR_OUFLAG4;
  314. GPR[rd] = EXTEND32 (h0);
  315. }
  316. :function:::void:do_bitrev:int rd, int rt
  317. {
  318. int i;
  319. unsigned32 v1 = GPR[rt];
  320. unsigned32 h1 = 0;
  321. for (i = 0; i < 16; i++)
  322. {
  323. if (v1 & (1 << i))
  324. h1 |= (1 << (15 - i));
  325. }
  326. GPR[rd] = EXTEND32 (h1);
  327. }
  328. // op: 0 = EXTPV, 1 = EXTPDPV
  329. :function:::void:do_extpv:int rt, int ac, int rs, int op
  330. {
  331. unsigned32 size = GPR[rs] & 0x1f;
  332. do_extp (SD_, rt, ac, size, op);
  333. }
  334. // op: 0 = EXTRV, 1 = EXTRV_R, 2 = EXTRV_RS
  335. :function:::void:do_extrv:int rt, int ac, int rs, int op
  336. {
  337. unsigned32 shift = GPR[rs] & 0x1f;
  338. do_w_extr (SD_, rt, ac, shift, op);
  339. }
  340. :function:::void:do_extrv_s_h:int rt, int ac, int rs
  341. {
  342. unsigned32 shift = GPR[rs] & 0x1f;
  343. do_h_extr (SD_, rt, ac, shift);
  344. }
  345. :function:::void:do_insv:int rt, int rs
  346. {
  347. unsigned32 v1 = GPR[rs];
  348. unsigned32 v2 = GPR[rt];
  349. unsigned32 pos = (DSPCR >> DSPCR_POS_SHIFT) & DSPCR_POS_MASK;
  350. unsigned32 size = (DSPCR >> DSPCR_SCOUNT_SHIFT) & DSPCR_SCOUNT_MASK;
  351. unsigned32 mask1, mask2, mask3, result;
  352. if (size < 32)
  353. mask1 = (1 << size) - 1;
  354. else
  355. mask1 = 0xffffffff;
  356. mask2 = (1 << pos) - 1;
  357. if (pos + size < 32)
  358. mask3 = ~((1 << (pos + size)) - 1);
  359. else
  360. mask3 = 0;
  361. result = (v2 & mask3) | ((v1 & mask1) << pos) | (v2 & mask2);
  362. GPR[rt] = EXTEND32 (result);
  363. }
  364. // op: 0 = NORMAL, 1 = EXTEND16, 2 = EXTEND32
  365. :function:::void:do_lxx:int rd, int base, int index, int op
  366. {
  367. if (op == 0)
  368. GPR[rd] = do_load (SD_, AccessLength_BYTE, GPR[base], GPR[index]);
  369. else if (op == 1)
  370. GPR[rd] = EXTEND16 (do_load (SD_, AccessLength_HALFWORD, GPR[base], GPR[index]));
  371. else if (op == 2)
  372. GPR[rd] = EXTEND32 (do_load (SD_, AccessLength_WORD, GPR[base], GPR[index]));
  373. }
  374. :function:::void:do_modsub:int rd, int rs, int rt
  375. {
  376. unsigned32 result = 0;
  377. unsigned32 v1 = GPR[rs];
  378. unsigned32 v2 = GPR[rt];
  379. unsigned32 decr = v2 & 0xff;
  380. unsigned32 lastindex = (v2 & 0xffff00) >> 8;
  381. if (v1 == 0)
  382. result = lastindex;
  383. else
  384. result = v1 - decr;
  385. GPR[rd] = EXTEND32 (result);
  386. }
  387. :function:::void:do_mthlip:int rs, int ac
  388. {
  389. unsigned32 pos = (DSPCR >> DSPCR_POS_SHIFT) & DSPCR_POS_MASK;
  390. DSPHI(ac) = DSPLO(ac);
  391. DSPLO(ac) = GPR[rs];
  392. if (pos >= 32)
  393. Unpredictable ();
  394. else
  395. pos += 32;
  396. DSPCR &= (~DSPCR_POS_SMASK);
  397. DSPCR |= (pos & DSPCR_POS_MASK) << DSPCR_POS_SHIFT;
  398. }
  399. :function:::void:do_mulsaq_s_w_ph:int ac, int rs, int rt
  400. {
  401. int i;
  402. unsigned32 v1 = GPR[rs];
  403. unsigned32 v2 = GPR[rt];
  404. signed16 h1, h2;
  405. signed32 result;
  406. unsigned32 lo = DSPLO(ac);
  407. unsigned32 hi = DSPHI(ac);
  408. signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
  409. for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
  410. {
  411. h1 = (signed16)(v1 & 0xffff);
  412. h2 = (signed16)(v2 & 0xffff);
  413. if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
  414. {
  415. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  416. result = (signed32) 0x7fffffff;
  417. }
  418. else
  419. result = ((signed32)h1 * (signed32)h2) << 1;
  420. if (i == 0)
  421. prod -= (signed64) result;
  422. else
  423. prod += (signed64) result;
  424. }
  425. DSPLO(ac) = EXTEND32 (prod);
  426. DSPHI(ac) = EXTEND32 (prod >> 32);
  427. }
  428. :function:::void:do_ph_packrl:int rd, int rs, int rt
  429. {
  430. unsigned32 v1 = GPR[rs];
  431. unsigned32 v2 = GPR[rt];
  432. GPR[rd] = EXTEND32 ((v1 << 16) + (v2 >> 16));
  433. }
  434. :function:::void:do_qb_pick:int rd, int rs, int rt
  435. {
  436. int i, j;
  437. unsigned32 v1 = GPR[rs];
  438. unsigned32 v2 = GPR[rt];
  439. unsigned8 h1, h2;
  440. unsigned32 result = 0;
  441. for (i = 0, j = 0; i < 32; i += 8, j++, v1 >>= 8, v2 >>= 8)
  442. {
  443. h1 = (unsigned8)(v1 & 0xff);
  444. h2 = (unsigned8)(v2 & 0xff);
  445. if (DSPCR & (1 << (DSPCR_CCOND_SHIFT + j)))
  446. result |= (unsigned32)(h1 << i);
  447. else
  448. result |= (unsigned32)(h2 << i);
  449. }
  450. GPR[rd] = EXTEND32 (result);
  451. }
  452. :function:::void:do_ph_pick:int rd, int rs, int rt
  453. {
  454. int i, j;
  455. unsigned32 v1 = GPR[rs];
  456. unsigned32 v2 = GPR[rt];
  457. unsigned16 h1, h2;
  458. unsigned32 result = 0;
  459. for (i = 0, j = 0; i < 32; i += 16, j++, v1 >>= 16, v2 >>= 16)
  460. {
  461. h1 = (unsigned16)(v1 & 0xffff);
  462. h2 = (unsigned16)(v2 & 0xffff);
  463. if (DSPCR & (1 << (DSPCR_CCOND_SHIFT + j)))
  464. result |= (unsigned32)(h1 << i);
  465. else
  466. result |= (unsigned32)(h2 << i);
  467. }
  468. GPR[rd] = EXTEND32 (result);
  469. }
  470. // op: 0 = QBR, 1 = QBRA, 2 = QBL, 3 = QBLA
  471. :function:::void:do_qb_ph_precequ:int rd, int rt, int op
  472. {
  473. unsigned32 v1 = GPR[rt];
  474. if (op == 0)
  475. GPR[rd] = EXTEND32 ((v1 & 0xff00) << 15) | ((v1 & 0xff) << 7);
  476. else if (op == 1)
  477. GPR[rd] = EXTEND32 ((v1 & 0xff0000) << 7) | ((v1 & 0xff) << 7);
  478. else if (op == 2)
  479. GPR[rd] = EXTEND32 ((v1 & 0xff000000) >> 1) | ((v1 & 0xff0000) >> 9);
  480. else if (op == 3)
  481. GPR[rd] = EXTEND32 ((v1 & 0xff000000) >> 1) | ((v1 & 0xff00) >> 1);
  482. }
  483. // op: 0 = QBR, 1 = QBRA, 2 = QBL, 3 = QBLA
  484. :function:::void:do_qb_ph_preceu:int rd, int rt, int op
  485. {
  486. unsigned32 v1 = GPR[rt];
  487. if (op == 0)
  488. GPR[rd] = EXTEND32 ((v1 & 0xff00) << 8) | (v1 & 0xff);
  489. else if (op == 1)
  490. GPR[rd] = EXTEND32 ((v1 & 0xff0000) | (v1 & 0xff));
  491. else if (op == 2)
  492. GPR[rd] = EXTEND32 ((v1 & 0xff000000) >> 8) | ((v1 & 0xff0000) >> 16);
  493. else if (op == 3)
  494. GPR[rd] = EXTEND32 ((v1 & 0xff000000) >> 8) | ((v1 & 0xff00) >> 8);
  495. }
  496. // op: 0 = .PHL, 1 = PHR
  497. :function:::void:do_w_preceq:int rd, int rt, int op
  498. {
  499. unsigned32 v1 = GPR[rt];
  500. if (op == 0)
  501. GPR[rd] = EXTEND32 (v1 & 0xffff0000);
  502. else if (op == 1)
  503. GPR[rd] = EXTEND32 ((v1 & 0xffff) << 16);
  504. }
  505. :function:::void:do_w_ph_precrq:int rd, int rs, int rt
  506. {
  507. unsigned32 v1 = GPR[rs];
  508. unsigned32 v2 = GPR[rt];
  509. unsigned32 tempu = (v1 & 0xffff0000) >> 16;
  510. unsigned32 tempv = (v2 & 0xffff0000) >> 16;
  511. GPR[rd] = EXTEND32 ((tempu << 16) | tempv);
  512. }
  513. // sat: 0 = PRECRQ.QB.PH, 1 = PRECRQU_S.QB.PH
  514. :function:::void:do_ph_qb_precrq:int rd, int rs, int rt, int sat
  515. {
  516. unsigned32 v1 = GPR[rs];
  517. unsigned32 v2 = GPR[rt];
  518. unsigned32 tempu = 0, tempv = 0, tempw = 0, tempx = 0;
  519. if (sat == 0)
  520. {
  521. tempu = (v1 & 0xff000000) >> 24;
  522. tempv = (v1 & 0xff00) >> 8;
  523. tempw = (v2 & 0xff000000) >> 24;
  524. tempx = (v2 & 0xff00) >> 8;
  525. }
  526. else if (sat == 1)
  527. {
  528. if (v1 & 0x80000000)
  529. {
  530. DSPCR |= DSPCR_OUFLAG6;
  531. tempu = 0;
  532. }
  533. else if (!(v1 & 0x80000000) && ((v1 >> 16) > (unsigned32)0x7f80))
  534. {
  535. DSPCR |= DSPCR_OUFLAG6;
  536. tempu = 0xff;
  537. }
  538. else
  539. tempu = (v1 & 0x7f800000) >> 23;
  540. if (v1 & 0x8000)
  541. {
  542. DSPCR |= DSPCR_OUFLAG6;
  543. tempv = 0;
  544. }
  545. else if (!(v1 & 0x8000) && ((v1 & 0xffff) > (unsigned32)0x7f80))
  546. {
  547. DSPCR |= DSPCR_OUFLAG6;
  548. tempv = 0xff;
  549. }
  550. else
  551. tempv = (v1 & 0x7f80) >> 7;
  552. if (v2 & 0x80000000)
  553. {
  554. DSPCR |= DSPCR_OUFLAG6;
  555. tempw = 0;
  556. }
  557. else if (!(v2 & 0x80000000) && ((v2 >> 16) > (unsigned32)0x7f80))
  558. {
  559. DSPCR |= DSPCR_OUFLAG6;
  560. tempw = 0xff;
  561. }
  562. else
  563. tempw = (v2 & 0x7f800000) >> 23;
  564. if (v2 & 0x8000)
  565. {
  566. DSPCR |= DSPCR_OUFLAG6;
  567. tempx = 0;
  568. }
  569. else if (!(v2 & 0x8000) && ((v2 & 0xffff) > (unsigned32)0x7f80))
  570. {
  571. DSPCR |= DSPCR_OUFLAG6;
  572. tempx = 0xff;
  573. }
  574. else
  575. tempx = (v2 & 0x7f80) >> 7;
  576. }
  577. GPR[rd] = EXTEND32 ((tempu << 24) | (tempv << 16) | (tempw << 8) | tempx);
  578. }
  579. :function:::void:do_w_ph_rs_precrq:int rd, int rs, int rt
  580. {
  581. unsigned32 v1 = GPR[rs];
  582. unsigned32 v2 = GPR[rt];
  583. signed32 h1 = (signed32)v1;
  584. signed32 h2 = (signed32)v2;
  585. signed64 temp1 = (signed64)h1 + (signed64)0x8000;
  586. signed32 temp2;
  587. signed64 temp3 = (signed64)h2 + (signed64)0x8000;
  588. signed32 temp4;
  589. if (((temp1 & 0x100000000LL) >> 1) != (temp1 & 0x80000000))
  590. {
  591. DSPCR |= DSPCR_OUFLAG6;
  592. temp2 = 0x7fff;
  593. }
  594. else
  595. temp2 = (signed32)((temp1 & 0xffff0000) >> 16);
  596. if (((temp3 & 0x100000000LL) >> 1) != (temp3 & 0x80000000))
  597. {
  598. DSPCR |= DSPCR_OUFLAG6;
  599. temp4 = 0x7fff;
  600. }
  601. else
  602. temp4 = (signed32)((temp3 & 0xffff0000) >> 16);
  603. GPR[rd] = EXTEND32 ((temp2 << 16) | temp4);
  604. }
  605. :function:::void:do_qb_w_raddu:int rd, int rs
  606. {
  607. int i;
  608. unsigned8 h0;
  609. unsigned32 v1 = GPR[rs];
  610. unsigned32 result = 0;
  611. for (i = 0; i < 32; i += 8, v1 >>= 8)
  612. {
  613. h0 = (unsigned8)(v1 & 0xff);
  614. result += (unsigned32)h0;
  615. }
  616. GPR[rd] = EXTEND32 (result);
  617. }
  618. :function:::void:do_rddsp:int rd, int mask
  619. {
  620. unsigned32 result = 0;
  621. if (mask & 0x1)
  622. {
  623. result &= (~DSPCR_POS_SMASK);
  624. result |= (DSPCR & DSPCR_POS_SMASK);
  625. }
  626. if (mask & 0x2)
  627. {
  628. result &= (~DSPCR_SCOUNT_SMASK);
  629. result |= (DSPCR & DSPCR_SCOUNT_SMASK);
  630. }
  631. if (mask & 0x4)
  632. {
  633. result &= (~DSPCR_CARRY_SMASK);
  634. result |= (DSPCR & DSPCR_CARRY_SMASK);
  635. }
  636. if (mask & 0x8)
  637. {
  638. result &= (~DSPCR_OUFLAG_SMASK);
  639. result |= (DSPCR & DSPCR_OUFLAG_SMASK);
  640. }
  641. if (mask & 0x10)
  642. {
  643. result &= (~DSPCR_CCOND_SMASK);
  644. result |= (DSPCR & DSPCR_CCOND_SMASK);
  645. }
  646. if (mask & 0x20)
  647. {
  648. result &= (~DSPCR_EFI_SMASK);
  649. result |= (DSPCR & DSPCR_EFI_SMASK);
  650. }
  651. GPR[rd] = EXTEND32 (result);
  652. }
  653. // op: 0 = REPL.QB, 1 = REPLV.QB, 2 = REPL.PH, 3 = REPLV.PH
  654. :function:::void:do_repl:int rd, int p2, int op
  655. {
  656. if (op == 0)
  657. GPR[rd] = EXTEND32 ((p2 << 24) | (p2 << 16) | (p2 << 8) | p2);
  658. else if (op == 1)
  659. {
  660. unsigned32 v1 = GPR[p2] & 0xff;
  661. GPR[rd] = EXTEND32 ((v1 << 24) | (v1 << 16) | (v1 << 8) | v1);
  662. }
  663. else if (op == 2)
  664. {
  665. signed32 v1 = p2;
  666. if (v1 & 0x200)
  667. v1 |= 0xfffffc00;
  668. GPR[rd] = EXTEND32 ((v1 << 16) | (v1 & 0xffff));
  669. }
  670. else if (op == 3)
  671. {
  672. unsigned32 v1 = GPR[p2];
  673. v1 = v1 & 0xffff;
  674. GPR[rd] = EXTEND32 ((v1 << 16) | v1);
  675. }
  676. }
  677. :function:::void:do_shilov:int ac, int rs
  678. {
  679. signed32 shift = GPR[rs] & 0x3f;
  680. do_shilo (SD_, ac, shift);
  681. }
  682. // op: 0 = SHLLV, 1 = SHRAV
  683. // sat: 0 = normal, 1 = saturate/rounding
  684. :function:::void:do_ph_shl:int rd, int rt, int rs, int op, int sat
  685. {
  686. unsigned32 shift = GPR[rs] & 0xf;
  687. do_ph_shift (SD_, rd, rt, shift, op, sat);
  688. }
  689. // op: 0 = SHLLV, 1 = SHRLV
  690. :function:::void:do_qb_shl:int rd, int rt, int rs, int op
  691. {
  692. unsigned32 shift = GPR[rs] & 0x7;
  693. do_qb_shift (SD_, rd, rt, shift, op);
  694. }
  695. :function:::void:do_w_s_shllv:int rd, int rt, int rs
  696. {
  697. unsigned32 shift = GPR[rs] & 0x1f;
  698. do_w_shll (SD_, rd, rt, shift);
  699. }
  700. :function:::void:do_ph_shrlv:int rd, int rt, int rs
  701. {
  702. unsigned32 shift = GPR[rs] & 0xf;
  703. do_ph_shrl (SD_, rd, rt, shift);
  704. }
  705. :function:::void:do_w_r_shrav:int rd, int rt, int rs
  706. {
  707. unsigned32 shift = GPR[rs] & 0x1f;
  708. do_w_shra (SD_, rd, rt, shift);
  709. }
  710. :function:::void:do_wrdsp:int rs, int mask
  711. {
  712. unsigned32 v1 = GPR[rs];
  713. if (mask & 0x1)
  714. {
  715. DSPCR &= (~DSPCR_POS_SMASK);
  716. DSPCR |= (v1 & DSPCR_POS_SMASK);
  717. }
  718. if (mask & 0x2)
  719. {
  720. DSPCR &= (~DSPCR_SCOUNT_SMASK);
  721. DSPCR |= (v1 & DSPCR_SCOUNT_SMASK);
  722. }
  723. if (mask & 0x4)
  724. {
  725. DSPCR &= (~DSPCR_CARRY_SMASK);
  726. DSPCR |= (v1 & DSPCR_CARRY_SMASK);
  727. }
  728. if (mask & 0x8)
  729. {
  730. DSPCR &= (~DSPCR_OUFLAG_SMASK);
  731. DSPCR |= (v1 & DSPCR_OUFLAG_SMASK);
  732. }
  733. if (mask & 0x10)
  734. {
  735. DSPCR &= (~DSPCR_CCOND_SMASK);
  736. DSPCR |= (v1 & DSPCR_CCOND_SMASK);
  737. }
  738. if (mask & 0x20)
  739. {
  740. DSPCR &= (~DSPCR_EFI_SMASK);
  741. DSPCR |= (v1 & DSPCR_EFI_SMASK);
  742. }
  743. }
  744. // round: 0 = no rounding, 1 = rounding
  745. :function:::void:do_qb_shrav:int rd, int rt, int rs, int round
  746. {
  747. unsigned32 shift = GPR[rs] & 0x7;
  748. do_qb_shra (SD_, rd, rt, shift, round);
  749. }
  750. :function:::void:do_append:int rt, int rs, int sa
  751. {
  752. unsigned32 v0 = GPR[rs];
  753. unsigned32 v1 = GPR[rt];
  754. unsigned32 result;
  755. unsigned32 mask = (1 << sa) - 1;
  756. result = (v1 << sa) | (v0 & mask);
  757. GPR[rt] = EXTEND32 (result);
  758. }
  759. :function:::void:do_balign:int rt, int rs, int bp
  760. {
  761. unsigned32 v0 = GPR[rs];
  762. unsigned32 v1 = GPR[rt];
  763. unsigned32 result;
  764. if (bp == 0)
  765. result = v1;
  766. else
  767. result = (v1 << 8 * bp) | (v0 >> 8 * (4 - bp));
  768. GPR[rt] = EXTEND32 (result);
  769. }
  770. :function:::void:do_ph_w_mulsa:int ac, int rs, int rt
  771. {
  772. int i;
  773. unsigned32 v1 = GPR[rs];
  774. unsigned32 v2 = GPR[rt];
  775. signed16 h1, h2;
  776. signed32 result;
  777. unsigned32 lo = DSPLO(ac);
  778. unsigned32 hi = DSPHI(ac);
  779. signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
  780. for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
  781. {
  782. h1 = (signed16)(v1 & 0xffff);
  783. h2 = (signed16)(v2 & 0xffff);
  784. result = (signed32)h1 * (signed32)h2;
  785. if (i == 0)
  786. prod -= (signed64) result;
  787. else
  788. prod += (signed64) result;
  789. }
  790. DSPLO(ac) = EXTEND32 (prod);
  791. DSPHI(ac) = EXTEND32 (prod >> 32);
  792. }
  793. :function:::void:do_ph_qb_precr:int rd, int rs, int rt
  794. {
  795. unsigned32 v1 = GPR[rs];
  796. unsigned32 v2 = GPR[rt];
  797. unsigned32 tempu = (v1 & 0xff0000) >> 16;
  798. unsigned32 tempv = (v1 & 0xff);
  799. unsigned32 tempw = (v2 & 0xff0000) >> 16;
  800. unsigned32 tempx = (v2 & 0xff);
  801. GPR[rd] = EXTEND32 ((tempu << 24) | (tempv << 16) | (tempw << 8) | tempx);
  802. }
  803. :function:::void:do_prepend:int rt, int rs, int sa
  804. {
  805. unsigned32 v0 = GPR[rs];
  806. unsigned32 v1 = GPR[rt];
  807. unsigned32 result;
  808. if (sa == 0)
  809. result = v1;
  810. else
  811. result = (v0 << (32 - sa)) | (v1 >> sa);
  812. GPR[rt] = EXTEND32 (result);
  813. }
  814. :function:::void:do_w_shra:int rd, int rt, int shift
  815. {
  816. unsigned32 result = GPR[rt];
  817. signed32 h0 = (signed32)result;
  818. if (shift != 0 && (h0 & (1 << (shift-1))))
  819. h0 = (h0 >> shift) + 1;
  820. else
  821. h0 = h0 >> shift;
  822. GPR[rd] = EXTEND32 (h0);
  823. }
  824. 011111,5.RS,5.RT,5.RD,01010,010000:SPECIAL3:32::ADDQ.PH
  825. "addq.ph r<RD>, r<RS>, r<RT>"
  826. *dsp:
  827. {
  828. do_ph_op (SD_, RD, RS, RT, 0, 0);
  829. }
  830. 011111,5.RS,5.RT,5.RD,01110,010000:SPECIAL3:32::ADDQ_S.PH
  831. "addq_s.ph r<RD>, r<RS>, r<RT>"
  832. *dsp:
  833. {
  834. do_ph_op (SD_, RD, RS, RT, 0, 1);
  835. }
  836. 011111,5.RS,5.RT,5.RD,10110,010000:SPECIAL3:32::ADDQ_S.W
  837. "addq_s.w r<RD>, r<RS>, r<RT>"
  838. *dsp:
  839. {
  840. do_w_op (SD_, RD, RS, RT, 0);
  841. }
  842. 011111,5.RS,5.RT,5.RD,00000,010000:SPECIAL3:32::ADDU.QB
  843. "addu.qb r<RD>, r<RS>, r<RT>"
  844. *dsp:
  845. {
  846. do_qb_op (SD_, RD, RS, RT, 0, 0);
  847. }
  848. 011111,5.RS,5.RT,5.RD,00100,010000:SPECIAL3:32::ADDU_S.QB
  849. "addu_s.qb r<RD>, r<RS>, r<RT>"
  850. *dsp:
  851. {
  852. do_qb_op (SD_, RD, RS, RT, 0, 1);
  853. }
  854. 011111,5.RS,5.RT,5.RD,01011,010000:SPECIAL3:32::SUBQ.PH
  855. "subq.ph r<RD>, r<RS>, r<RT>"
  856. *dsp:
  857. {
  858. do_ph_op (SD_, RD, RS, RT, 1, 0);
  859. }
  860. 011111,5.RS,5.RT,5.RD,01111,010000:SPECIAL3:32::SUBQ_S.PH
  861. "subq_s.ph r<RD>, r<RS>, r<RT>"
  862. *dsp:
  863. {
  864. do_ph_op (SD_, RD, RS, RT, 1, 1);
  865. }
  866. 011111,5.RS,5.RT,5.RD,10111,010000:SPECIAL3:32::SUBQ_S.W
  867. "subq_s.w r<RD>, r<RS>, r<RT>"
  868. *dsp:
  869. {
  870. do_w_op (SD_, RD, RS, RT, 1);
  871. }
  872. 011111,5.RS,5.RT,5.RD,00001,010000:SPECIAL3:32::SUBU.QB
  873. "subu.qb r<RD>, r<RS>, r<RT>"
  874. *dsp:
  875. {
  876. do_qb_op (SD_, RD, RS, RT, 1, 0);
  877. }
  878. 011111,5.RS,5.RT,5.RD,00101,010000:SPECIAL3:32::SUBU_S.QB
  879. "subu_s.qb r<RD>, r<RS>, r<RT>"
  880. *dsp:
  881. {
  882. do_qb_op (SD_, RD, RS, RT, 1, 1);
  883. }
  884. 011111,5.RS,5.RT,5.RD,10000,010000:SPECIAL3:32::ADDSC
  885. "addsc r<RD>, r<RS>, r<RT>"
  886. *dsp:
  887. {
  888. do_addsc (SD_, RD, RS, RT);
  889. }
  890. 011111,5.RS,5.RT,5.RD,10001,010000:SPECIAL3:32::ADDWC
  891. "addwc r<RD>, r<RS>, r<RT>"
  892. *dsp:
  893. {
  894. do_addwc (SD_, RD, RS, RT);
  895. }
  896. 011111,5.RS,5.RT,5.RD,10010,010000:SPECIAL3:32::MODSUB
  897. "modsub r<RD>, r<RS>, r<RT>"
  898. *dsp:
  899. {
  900. do_modsub (SD_, RD, RS, RT);
  901. }
  902. 011111,5.RS,00000,5.RD,10100,010000:SPECIAL3:32::RADDU.W.QB
  903. "raddu.w.qb r<RD>, r<RS>"
  904. *dsp:
  905. {
  906. do_qb_w_raddu (SD_, RD, RS);
  907. }
  908. 011111,00000,5.RT,5.RD,01001,010010:SPECIAL3:32::ABSQ_S.PH
  909. "absq_s.ph r<RD>, r<RT>"
  910. *dsp:
  911. {
  912. do_ph_s_absq (SD_, RD, RT);
  913. }
  914. 011111,00000,5.RT,5.RD,10001,010010:SPECIAL3:32::ABSQ_S.W
  915. "absq_s.w r<RD>, r<RT>"
  916. *dsp:
  917. {
  918. do_w_s_absq (SD_, RD, RT);
  919. }
  920. 011111,5.RS,5.RT,5.RD,01100,010001:SPECIAL3:32::PRECRQ.QB.PH
  921. "precrq.qb.ph r<RD>, r<RS>, r<RT>"
  922. *dsp:
  923. {
  924. do_ph_qb_precrq (SD_, RD, RS, RT, 0);
  925. }
  926. 011111,5.RS,5.RT,5.RD,10100,010001:SPECIAL3:32::PRECRQ.PH.W
  927. "precrq.ph.w r<RD>, r<RS>, r<RT>"
  928. *dsp:
  929. {
  930. do_w_ph_precrq (SD_, RD, RS, RT);
  931. }
  932. 011111,5.RS,5.RT,5.RD,10101,010001:SPECIAL3:32::PRECRQ_RS.PH.W
  933. "precrq_rs.ph.w r<RD>, r<RS>, r<RT>"
  934. *dsp:
  935. {
  936. do_w_ph_rs_precrq (SD_, RD, RS, RT);
  937. }
  938. 011111,5.RS,5.RT,5.RD,01111,010001:SPECIAL3:32::PRECRQU_S.QB.PH
  939. "precrqu_s.qb.ph r<RD>, r<RS>, r<RT>"
  940. *dsp:
  941. {
  942. do_ph_qb_precrq (SD_, RD, RS, RT, 1);
  943. }
  944. 011111,00000,5.RT,5.RD,01100,010010:SPECIAL3:32::PRECEQ.W.PHL
  945. "preceq.w.phl r<RD>, r<RT>"
  946. *dsp:
  947. {
  948. do_w_preceq (SD_, RD, RT, 0);
  949. }
  950. 011111,00000,5.RT,5.RD,01101,010010:SPECIAL3:32::PRECEQ.W.PHR
  951. "preceq.w.phr r<RD>, r<RT>"
  952. *dsp:
  953. {
  954. do_w_preceq (SD_, RD, RT, 1);
  955. }
  956. 011111,00000,5.RT,5.RD,00100,010010:SPECIAL3:32::PRECEQU.PH.QBL
  957. "precequ.ph.qbl r<RD>, r<RT>"
  958. *dsp:
  959. {
  960. do_qb_ph_precequ (SD_, RD, RT, 2);
  961. }
  962. 011111,00000,5.RT,5.RD,00101,010010:SPECIAL3:32::PRECEQU.PH.QBR
  963. "precequ.ph.qbr r<RD>, r<RT>"
  964. *dsp:
  965. {
  966. do_qb_ph_precequ (SD_, RD, RT, 0);
  967. }
  968. 011111,00000,5.RT,5.RD,00110,010010:SPECIAL3:32::PRECEQU.PH.QBLA
  969. "precequ.ph.qbla r<RD>, r<RT>"
  970. *dsp:
  971. {
  972. do_qb_ph_precequ (SD_, RD, RT, 3);
  973. }
  974. 011111,00000,5.RT,5.RD,00111,010010:SPECIAL3:32::PRECEQU.PH.QBRA
  975. "precequ.ph.qbra r<RD>, r<RT>"
  976. *dsp:
  977. {
  978. do_qb_ph_precequ (SD_, RD, RT, 1);
  979. }
  980. 011111,00000,5.RT,5.RD,11100,010010:SPECIAL3:32::PRECEU.PH.QBL
  981. "preceu.ph.qbl r<RD>, r<RT>"
  982. *dsp:
  983. {
  984. do_qb_ph_preceu (SD_, RD, RT, 2);
  985. }
  986. 011111,00000,5.RT,5.RD,11101,010010:SPECIAL3:32::PRECEU.PH.QBR
  987. "preceu.ph.qbr r<RD>, r<RT>"
  988. *dsp:
  989. {
  990. do_qb_ph_preceu (SD_, RD, RT, 0);
  991. }
  992. 011111,00000,5.RT,5.RD,11110,010010:SPECIAL3:32::PRECEU.PH.QBLA
  993. "preceu.ph.qbla r<RD>, r<RT>"
  994. *dsp:
  995. {
  996. do_qb_ph_preceu (SD_, RD, RT, 3);
  997. }
  998. 011111,00000,5.RT,5.RD,11111,010010:SPECIAL3:32::PRECEU.PH.QBRA
  999. "preceu.ph.qbra r<RD>, r<RT>"
  1000. *dsp:
  1001. {
  1002. do_qb_ph_preceu (SD_, RD, RT, 1);
  1003. }
  1004. 011111,00,3.SHIFT3,5.RT,5.RD,00000,010011:SPECIAL3:32::SHLL.QB
  1005. "shll.qb r<RD>, r<RT>, <SHIFT3>"
  1006. *dsp:
  1007. {
  1008. do_qb_shift (SD_, RD, RT, SHIFT3, 0);
  1009. }
  1010. 011111,5.RS,5.RT,5.RD,00010,010011:SPECIAL3:32::SHLLV.QB
  1011. "shllv.qb r<RD>, r<RT>, r<RS>"
  1012. *dsp:
  1013. {
  1014. do_qb_shl (SD_, RD, RT, RS, 0);
  1015. }
  1016. 011111,0,4.SHIFT4,5.RT,5.RD,01000,010011:SPECIAL3:32::SHLL.PH
  1017. "shll.ph r<RD>, r<RT>, <SHIFT4>"
  1018. *dsp:
  1019. {
  1020. do_ph_shift (SD_, RD, RT, SHIFT4, 0, 0);
  1021. }
  1022. 011111,5.RS,5.RT,5.RD,01010,010011:SPECIAL3:32::SHLLV.PH
  1023. "shllv.ph r<RD>, r<RT>, r<RS>"
  1024. *dsp:
  1025. {
  1026. do_ph_shl (SD_, RD, RT, RS, 0, 0);
  1027. }
  1028. 011111,0,4.SHIFT4,5.RT,5.RD,01100,010011:SPECIAL3:32::SHLL_S.PH
  1029. "shll_s.ph r<RD>, r<RT>, <SHIFT4>"
  1030. *dsp:
  1031. {
  1032. do_ph_shift (SD_, RD, RT, SHIFT4, 0, 1);
  1033. }
  1034. 011111,5.RS,5.RT,5.RD,01110,010011:SPECIAL3:32::SHLLV_S.PH
  1035. "shllv_s.ph r<RD>, r<RT>, r<RS>"
  1036. *dsp:
  1037. {
  1038. do_ph_shl (SD_, RD, RT, RS, 0, 1);
  1039. }
  1040. 011111,5.SHIFT5,5.RT,5.RD,10100,010011:SPECIAL3:32::SHLL_S.W
  1041. "shll_s.w r<RD>, r<RT>, <SHIFT5>"
  1042. *dsp:
  1043. {
  1044. do_w_shll (SD_, RD, RT, SHIFT5);
  1045. }
  1046. 011111,5.RS,5.RT,5.RD,10110,010011:SPECIAL3:32::SHLLV_S.W
  1047. "shllv_s.w r<RD>, r<RT>, r<RS>"
  1048. *dsp:
  1049. {
  1050. do_w_s_shllv (SD_, RD, RT, RS);
  1051. }
  1052. 011111,00,3.SHIFT3,5.RT,5.RD,00001,010011:SPECIAL3:32::SHRL.QB
  1053. "shrl.qb r<RD>, r<RT>, <SHIFT3>"
  1054. *dsp:
  1055. {
  1056. do_qb_shift (SD_, RD, RT, SHIFT3, 1);
  1057. }
  1058. 011111,5.RS,5.RT,5.RD,00011,010011:SPECIAL3:32::SHRLV.QB
  1059. "shrlv.qb r<RD>, r<RT>, r<RS>"
  1060. *dsp:
  1061. {
  1062. do_qb_shl (SD_, RD, RT, RS, 1);
  1063. }
  1064. 011111,0,4.SHIFT4,5.RT,5.RD,01001,010011:SPECIAL3:32::SHRA.PH
  1065. "shra.ph r<RD>, r<RT>, <SHIFT4>"
  1066. *dsp:
  1067. {
  1068. do_ph_shift (SD_, RD, RT, SHIFT4, 1, 0);
  1069. }
  1070. 011111,5.RS,5.RT,5.RD,01011,010011:SPECIAL3:32::SHRAV.PH
  1071. "shrav.ph r<RD>, r<RT>, r<RS>"
  1072. *dsp:
  1073. {
  1074. do_ph_shl (SD_, RD, RT, RS, 1, 0);
  1075. }
  1076. 011111,0,4.SHIFT4,5.RT,5.RD,01101,010011:SPECIAL3:32::SHRA_R.PH
  1077. "shra_r.ph r<RD>, r<RT>, <SHIFT4>"
  1078. *dsp:
  1079. {
  1080. do_ph_shift (SD_, RD, RT, SHIFT4, 1, 1);
  1081. }
  1082. 011111,5.RS,5.RT,5.RD,01111,010011:SPECIAL3:32::SHRAV_R.PH
  1083. "shrav_r.ph r<RD>, r<RT>, r<RS>"
  1084. *dsp:
  1085. {
  1086. do_ph_shl (SD_, RD, RT, RS, 1, 1);
  1087. }
  1088. 011111,5.SHIFT5,5.RT,5.RD,10101,010011:SPECIAL3:32::SHRA_R.W
  1089. "shra_r.w r<RD>, r<RT>, <SHIFT5>"
  1090. *dsp:
  1091. {
  1092. do_w_shra (SD_, RD, RT, SHIFT5);
  1093. }
  1094. 011111,5.RS,5.RT,5.RD,10111,010011:SPECIAL3:32::SHRAV_R.W
  1095. "shrav_r.w r<RD>, r<RT>, r<RS>"
  1096. *dsp:
  1097. {
  1098. do_w_r_shrav (SD_, RD, RT, RS);
  1099. }
  1100. // loc: 0 = qhl, 1 = qhr
  1101. :function:::void:do_qb_muleu:int rd, int rs, int rt, int loc
  1102. {
  1103. int i;
  1104. unsigned32 result = 0;
  1105. unsigned32 v1 = GPR[rs];
  1106. unsigned32 v2 = GPR[rt];
  1107. unsigned16 h1, h2;
  1108. unsigned32 prod;
  1109. if (loc == 0)
  1110. v1 >>= 16;
  1111. for (i = 0; i < 32; i += 16, v1 >>= 8, v2 >>= 16)
  1112. {
  1113. h1 = (unsigned16)(v1 & 0xff);
  1114. h2 = (unsigned16)(v2 & 0xffff);
  1115. prod = (unsigned32)h1 * (unsigned32)h2;
  1116. if (prod > 0xffff)
  1117. {
  1118. DSPCR |= DSPCR_OUFLAG5;
  1119. prod = 0xffff;
  1120. }
  1121. result |= ((unsigned32)prod << i);
  1122. }
  1123. GPR[rd] = EXTEND32 (result);
  1124. }
  1125. 011111,5.RS,5.RT,5.RD,00110,010000:SPECIAL3:32::MULEU_S.PH.QBL
  1126. "muleu_s.ph.qbl r<RD>, r<RS>, r<RT>"
  1127. *dsp:
  1128. {
  1129. do_qb_muleu (SD_, RD, RS, RT, 0);
  1130. }
  1131. 011111,5.RS,5.RT,5.RD,00111,010000:SPECIAL3:32::MULEU_S.PH.QBR
  1132. "muleu_s.ph.qbr r<RD>, r<RS>, r<RT>"
  1133. *dsp:
  1134. {
  1135. do_qb_muleu (SD_, RD, RS, RT, 1);
  1136. }
  1137. // round: 0 = no rounding, 1 = rounding
  1138. :function:::void:do_ph_mulq:int rd, int rs, int rt, int round
  1139. {
  1140. int i;
  1141. unsigned32 result = 0;
  1142. unsigned32 v1 = GPR[rs];
  1143. unsigned32 v2 = GPR[rt];
  1144. signed16 h1, h2;
  1145. signed32 prod;
  1146. for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
  1147. {
  1148. h1 = (signed16)(v1 & 0xffff);
  1149. h2 = (signed16)(v2 & 0xffff);
  1150. if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
  1151. {
  1152. DSPCR |= DSPCR_OUFLAG5;
  1153. prod = 0x7fffffff;
  1154. }
  1155. else
  1156. {
  1157. prod = ((signed32)h1 * (signed32)h2) << 1;
  1158. if (round == 1)
  1159. prod += (signed32)0x8000;
  1160. }
  1161. result |= (((unsigned32)prod >> 16) << i);
  1162. }
  1163. GPR[rd] = EXTEND32 (result);
  1164. }
  1165. 011111,5.RS,5.RT,5.RD,11111,010000:SPECIAL3:32::MULQ_RS.PH
  1166. "mulq_rs.ph r<RD>, r<RS>, r<RT>"
  1167. *dsp:
  1168. {
  1169. do_ph_mulq (SD_, RD, RS, RT, 1);
  1170. }
  1171. // loc: 0 = phl, 1 = phr
  1172. :function:::void:do_ph_muleq:int rd, int rs, int rt, int loc
  1173. {
  1174. unsigned32 v1 = GPR[rs];
  1175. unsigned32 v2 = GPR[rt];
  1176. signed16 h1, h2;
  1177. signed32 prod;
  1178. if (loc == 0)
  1179. {
  1180. h1 = (signed16)(v1 >> 16);
  1181. h2 = (signed16)(v2 >> 16);
  1182. }
  1183. else
  1184. {
  1185. h1 = (signed16)(v1 & 0xffff);
  1186. h2 = (signed16)(v2 & 0xffff);
  1187. }
  1188. if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
  1189. {
  1190. DSPCR |= DSPCR_OUFLAG5;
  1191. prod = 0x7fffffff;
  1192. }
  1193. else
  1194. prod = ((signed32)h1 * (signed32)h2) << 1;
  1195. GPR[rd] = EXTEND32 (prod);
  1196. }
  1197. 011111,5.RS,5.RT,5.RD,11100,010000:SPECIAL3:32::MULEQ_S.W.PHL
  1198. "muleq_s.w.phl r<RD>, r<RS>, r<RT>"
  1199. *dsp:
  1200. {
  1201. do_ph_muleq (SD_, RD, RS, RT, 0);
  1202. }
  1203. 011111,5.RS,5.RT,5.RD,11101,010000:SPECIAL3:32::MULEQ_S.W.PHR
  1204. "muleq_s.w.phr r<RD>, r<RS>, r<RT>"
  1205. *dsp:
  1206. {
  1207. do_ph_muleq (SD_, RD, RS, RT, 1);
  1208. }
  1209. // op: 0 = DPAU 1 = DPSU
  1210. // loc: 0 = qbl, 1 = qbr
  1211. :function:::void:do_qb_dot_product:int ac, int rs, int rt, int op, int loc
  1212. {
  1213. int i;
  1214. unsigned32 v1 = GPR[rs];
  1215. unsigned32 v2 = GPR[rt];
  1216. unsigned8 h1, h2;
  1217. unsigned32 lo = DSPLO(ac);
  1218. unsigned32 hi = DSPHI(ac);
  1219. unsigned64 prod = (((unsigned64)hi) << 32) + (unsigned64)lo;
  1220. if (loc == 0)
  1221. {
  1222. v1 >>= 16;
  1223. v2 >>= 16;
  1224. }
  1225. for (i = 0; i < 16; i += 8, v1 >>= 8, v2 >>= 8)
  1226. {
  1227. h1 = (unsigned8)(v1 & 0xff);
  1228. h2 = (unsigned8)(v2 & 0xff);
  1229. if (op == 0) // DPAU
  1230. prod += (unsigned64)h1 * (unsigned64)h2;
  1231. else // DPSU
  1232. prod -= (unsigned64)h1 * (unsigned64)h2;
  1233. }
  1234. DSPLO(ac) = EXTEND32 (prod);
  1235. DSPHI(ac) = EXTEND32 (prod >> 32);
  1236. }
  1237. 011111,5.RS,5.RT,000,2.AC,00011,110000:SPECIAL3:32::DPAU.H.QBL
  1238. "dpau.h.qbl ac<AC>, r<RS>, r<RT>"
  1239. *dsp:
  1240. {
  1241. do_qb_dot_product (SD_, AC, RS, RT, 0, 0);
  1242. }
  1243. 011111,5.RS,5.RT,000,2.AC,00111,110000:SPECIAL3:32::DPAU.H.QBR
  1244. "dpau.h.qbr ac<AC>, r<RS>, r<RT>"
  1245. *dsp:
  1246. {
  1247. do_qb_dot_product (SD_, AC, RS, RT, 0, 1);
  1248. }
  1249. 011111,5.RS,5.RT,000,2.AC,01011,110000:SPECIAL3:32::DPSU.H.QBL
  1250. "dpsu.h.qbl ac<AC>, r<RS>, r<RT>"
  1251. *dsp:
  1252. {
  1253. do_qb_dot_product (SD_, AC, RS, RT, 1, 0);
  1254. }
  1255. 011111,5.RS,5.RT,000,2.AC,01111,110000:SPECIAL3:32::DPSU.H.QBR
  1256. "dpsu.h.qbr ac<AC>, r<RS>, r<RT>"
  1257. *dsp:
  1258. {
  1259. do_qb_dot_product (SD_, AC, RS, RT, 1, 1);
  1260. }
  1261. // op: 0 = DPAQ 1 = DPSQ
  1262. :function:::void:do_ph_dot_product:int ac, int rs, int rt, int op
  1263. {
  1264. int i;
  1265. unsigned32 v1 = GPR[rs];
  1266. unsigned32 v2 = GPR[rt];
  1267. signed16 h1, h2;
  1268. signed32 result;
  1269. unsigned32 lo = DSPLO(ac);
  1270. unsigned32 hi = DSPHI(ac);
  1271. signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
  1272. for (i = 0; i < 32; i += 16, v1 >>= 16, v2 >>= 16)
  1273. {
  1274. h1 = (signed16)(v1 & 0xffff);
  1275. h2 = (signed16)(v2 & 0xffff);
  1276. if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
  1277. {
  1278. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1279. result = (signed32)0x7fffffff;
  1280. }
  1281. else
  1282. result = ((signed32)h1 * (signed32)h2) << 1;
  1283. if (op == 0) // DPAQ
  1284. prod += (signed64)result;
  1285. else // DPSQ
  1286. prod -= (signed64)result;
  1287. }
  1288. DSPLO(ac) = EXTEND32 (prod);
  1289. DSPHI(ac) = EXTEND32 (prod >> 32);
  1290. }
  1291. 011111,5.RS,5.RT,000,2.AC,00100,110000:SPECIAL3:32::DPAQ_S.W.PH
  1292. "dpaq_s.w.ph ac<AC>, r<RS>, r<RT>"
  1293. *dsp:
  1294. {
  1295. do_ph_dot_product (SD_, AC, RS, RT, 0);
  1296. }
  1297. 011111,5.RS,5.RT,000,2.AC,00101,110000:SPECIAL3:32::DPSQ_S.W.PH
  1298. "dpsq_s.w.ph ac<AC>, r<RS>, r<RT>"
  1299. *dsp:
  1300. {
  1301. do_ph_dot_product (SD_, AC, RS, RT, 1);
  1302. }
  1303. 011111,5.RS,5.RT,000,2.AC,00110,110000:SPECIAL3:32::MULSAQ_S.W.PH
  1304. "mulsaq_s.w.ph ac<AC>, r<RS>, r<RT>"
  1305. *dsp:
  1306. {
  1307. do_mulsaq_s_w_ph (SD_, AC, RS, RT);
  1308. }
  1309. // op: 0 = DPAQ 1 = DPSQ
  1310. :function:::void:do_w_dot_product:int ac, int rs, int rt, int op
  1311. {
  1312. unsigned32 v1 = GPR[rs];
  1313. unsigned32 v2 = GPR[rt];
  1314. signed32 h1, h2;
  1315. signed64 result;
  1316. unsigned32 lo = DSPLO(ac);
  1317. unsigned32 hi = DSPHI(ac);
  1318. unsigned32 resultlo;
  1319. unsigned32 resulthi;
  1320. unsigned32 carry;
  1321. unsigned64 temp1;
  1322. signed64 temp2;
  1323. h1 = (signed32) v1;
  1324. h2 = (signed32) v2;
  1325. if (h1 == 0x80000000 && h2 == 0x80000000)
  1326. {
  1327. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1328. result = (signed64) 0x7fffffffffffffffLL;
  1329. }
  1330. else
  1331. result = ((signed64)h1 * (signed64)h2) << 1;
  1332. resultlo = (unsigned32)(result);
  1333. resulthi = (unsigned32)(result >> 32);
  1334. if (op ==0) // DPAQ
  1335. {
  1336. temp1 = (unsigned64)lo + (unsigned64)resultlo;
  1337. carry = (unsigned32)((temp1 >> 32) & 1);
  1338. temp2 = (signed64)((signed32)hi) + (signed64)((signed32)resulthi) +
  1339. (signed64)((signed32)carry);
  1340. }
  1341. else // DPSQ
  1342. {
  1343. temp1 = (unsigned64)lo - (unsigned64)resultlo;
  1344. carry = (unsigned32)((temp1 >> 32) & 1);
  1345. temp2 = (signed64)((signed32)hi) - (signed64)((signed32)resulthi) -
  1346. (signed64)((signed32)carry);
  1347. }
  1348. if (((temp2 & 0x100000000LL) >> 1) != (temp2 & 0x80000000LL))
  1349. {
  1350. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1351. if (temp2 & 0x100000000LL)
  1352. {
  1353. DSPLO(ac) = EXTEND32 (0x00000000);
  1354. DSPHI(ac) = EXTEND32 (0x80000000);
  1355. }
  1356. else
  1357. {
  1358. DSPLO(ac) = EXTEND32 (0xffffffff);
  1359. DSPHI(ac) = EXTEND32 (0x7fffffff);
  1360. }
  1361. }
  1362. else
  1363. {
  1364. DSPLO(ac) = EXTEND32 (temp1);
  1365. DSPHI(ac) = EXTEND32 (temp2);
  1366. }
  1367. }
  1368. 011111,5.RS,5.RT,000,2.AC,01100,110000:SPECIAL3:32::DPAQ_SA.L.W
  1369. "dpaq_sa.l.w ac<AC>, r<RS>, r<RT>"
  1370. *dsp:
  1371. {
  1372. do_w_dot_product (SD_, AC, RS, RT, 0);
  1373. }
  1374. 011111,5.RS,5.RT,000,2.AC,01101,110000:SPECIAL3:32::DPSQ_SA.L.W
  1375. "dpsq_sa.l.w ac<AC>, r<RS>, r<RT>"
  1376. *dsp:
  1377. {
  1378. do_w_dot_product (SD_, AC, RS, RT, 1);
  1379. }
  1380. // op: 0 = MAQ_S 1 = MAQ_SA
  1381. // loc: 0 = phl, 1 = phr
  1382. :function:::void:do_ph_maq:int ac, int rs, int rt, int op, int loc
  1383. {
  1384. int i;
  1385. unsigned32 v1 = GPR[rs];
  1386. unsigned32 v2 = GPR[rt];
  1387. signed16 h1, h2;
  1388. signed32 result;
  1389. unsigned32 lo = DSPLO(ac);
  1390. unsigned32 hi = DSPHI(ac);
  1391. signed64 prod = (signed64)((((unsigned64)hi) << 32) + (unsigned64)lo);
  1392. if (loc == 0)
  1393. {
  1394. h1 = (signed16)(v1 >> 16);
  1395. h2 = (signed16)(v2 >> 16);
  1396. }
  1397. else
  1398. {
  1399. h1 = (signed16)(v1 & 0xffff);
  1400. h2 = (signed16)(v2 & 0xffff);
  1401. }
  1402. if (h1 == (signed16)0x8000 && h2 == (signed16)0x8000)
  1403. {
  1404. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1405. result = (signed32)0x7fffffff;
  1406. }
  1407. else
  1408. result = ((signed32)h1 * (signed32)h2) << 1;
  1409. prod += (signed64)result;
  1410. if (op == 1) // MAQ_SA
  1411. {
  1412. if (prod & 0x8000000000000000LL)
  1413. {
  1414. for (i = 62; i >= 31; i--)
  1415. {
  1416. if (!(prod & ((signed64)1 << i)))
  1417. {
  1418. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1419. prod = 0xffffffff80000000LL;
  1420. break;
  1421. }
  1422. }
  1423. }
  1424. else
  1425. {
  1426. for (i = 62; i >= 31; i--)
  1427. {
  1428. if (prod & ((signed64)1 << i))
  1429. {
  1430. DSPCR |= (1 << (DSPCR_OUFLAG_SHIFT + ac));
  1431. prod = 0x7fffffff;
  1432. break;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. DSPLO(ac) = EXTEND32 (prod);
  1438. DSPHI(ac) = EXTEND32 (prod >> 32);
  1439. }
  1440. 011111,5.RS,5.RT,000,2.AC,10100,110000:SPECIAL3:32::MAQ_S.W.PHL
  1441. "maq_s.w.phl ac<AC>, r<RS>, r<RT>"
  1442. *dsp:
  1443. {
  1444. do_ph_maq (SD_, AC, RS, RT, 0, 0);
  1445. }
  1446. 011111,5.RS,5.RT,000,2.AC,10110,110000:SPECIAL3:32::MAQ_S.W.PHR
  1447. "maq_s.w.phr ac<AC>, r<RS>, r<RT>"
  1448. *dsp:
  1449. {
  1450. do_ph_maq (SD_, AC, RS, RT, 0, 1);
  1451. }
  1452. 011111,5.RS,5.RT,000,2.AC,10000,110000:SPECIAL3:32::MAQ_SA.W.PHL
  1453. "maq_sa.w.phl ac<AC>, r<RS>, r<RT>"
  1454. *dsp:
  1455. {
  1456. do_ph_maq (SD_, AC, RS, RT, 1, 0);
  1457. }
  1458. 011111,5.RS,5.RT,000,2.AC,10010,110000:SPECIAL3:32::MAQ_SA.W.PHR
  1459. "maq_sa.w.phr ac<AC>, r<RS>, r<RT>"
  1460. *dsp:
  1461. {
  1462. do_ph_maq (SD_, AC, RS, RT, 1, 1);
  1463. }
  1464. 011111,00000,5.RT,5.RD,11011,010010:SPECIAL3:32::BITREV
  1465. "bitrev r<RD>, r<RT>"
  1466. *dsp:
  1467. {
  1468. do_bitrev (SD_, RD, RT);
  1469. }
  1470. 011111,5.RS,5.RT,00000,00000,001100:SPECIAL3:32::INSV
  1471. "insv r<RT>, r<RS>"
  1472. *dsp:
  1473. {
  1474. do_insv (SD_, RT, RS);
  1475. }
  1476. 011111,00,8.IMM8,5.RD,00010,010010:SPECIAL3:32::REPL.QB
  1477. "repl.qb r<RD>, <IMM8>"
  1478. *dsp:
  1479. {
  1480. do_repl (SD_, RD, IMM8, 0);
  1481. }
  1482. 011111,00000,5.RT,5.RD,00011,010010:SPECIAL3:32::REPLV.QB
  1483. "replv.qb r<RD>, r<RT>"
  1484. *dsp:
  1485. {
  1486. do_repl (SD_, RD, RT, 1);
  1487. }
  1488. 011111,10.IMM10,5.RD,01010,010010:SPECIAL3:32::REPL.PH
  1489. "repl.ph r<RD>, <IMM10>"
  1490. *dsp:
  1491. {
  1492. do_repl (SD_, RD, IMM10, 2);
  1493. }
  1494. 011111,00000,5.RT,5.RD,01011,010010:SPECIAL3:32::REPLV.PH
  1495. "replv.ph r<RD>, r<RT>"
  1496. *dsp:
  1497. {
  1498. do_repl (SD_, RD, RT, 3);
  1499. }
  1500. // op: 0 = EQ, 1 = LT, 2 = LE
  1501. :function:::void:do_qb_cmpu:int rs, int rt, int op
  1502. {
  1503. int i, j;
  1504. unsigned32 v1 = GPR[rs];
  1505. unsigned32 v2 = GPR[rt];
  1506. unsigned8 h1, h2;
  1507. unsigned32 mask;
  1508. for (i = 0, j = 0; i < 32; i += 8, j++, v1 >>= 8, v2 >>= 8)
  1509. {
  1510. h1 = (unsigned8)(v1 & 0xff);
  1511. h2 = (unsigned8)(v2 & 0xff);
  1512. mask = ~(1 << (DSPCR_CCOND_SHIFT + j));
  1513. DSPCR &= mask;
  1514. if (op == 0) // EQ
  1515. DSPCR |= ((h1 == h2) << (DSPCR_CCOND_SHIFT + j));
  1516. else if (op == 1) // LT
  1517. DSPCR |= ((h1 < h2) << (DSPCR_CCOND_SHIFT + j));
  1518. else // LE
  1519. DSPCR |= ((h1 <= h2) << (DSPCR_CCOND_SHIFT + j));
  1520. }
  1521. }
  1522. 011111,5.RS,5.RT,00000,00000,010001:SPECIAL3:32::CMPU.EQ.QB
  1523. "cmpu.eq.qb r<RS>, r<RT>"
  1524. *dsp:
  1525. {
  1526. do_qb_cmpu (SD_, RS, RT, 0);
  1527. }
  1528. 011111,5.RS,5.RT,00000,00001,010001:SPECIAL3:32::CMPU.LT.QB
  1529. "cmpu.lt.qb r<RS>, r<RT>"
  1530. *dsp:
  1531. {
  1532. do_qb_cmpu (SD_, RS, RT, 1);
  1533. }
  1534. 011111,5.RS,5.RT,00000,00010,010001:SPECIAL3:32::CMPU.LE.QB
  1535. "cmpu.le.qb r<RS>, r<RT>"
  1536. *dsp:
  1537. {
  1538. do_qb_cmpu (SD_, RS, RT, 2);
  1539. }
  1540. // op: 0 = EQ, 1 = LT, 2 = LE
  1541. :function:::void:do_qb_cmpgu:int rd, int rs, int rt, int op
  1542. {
  1543. int i, j;
  1544. unsigned32 v1 = GPR[rs];
  1545. unsigned32 v2 = GPR[rt];
  1546. unsigned8 h1, h2;
  1547. unsigned32 result = 0;
  1548. for (i = 0, j = 0; i < 32; i += 8, j++, v1 >>= 8, v2 >>= 8)
  1549. {
  1550. h1 = (unsigned8)(v1 & 0xff);
  1551. h2 = (unsigned8)(v2 & 0xff);
  1552. if (op == 0) // EQ
  1553. result |= ((h1 == h2) << j);
  1554. else if (op == 1) // LT
  1555. result |= ((h1 < h2) << j);
  1556. else // LE
  1557. result |= ((h1 <= h2) << j);
  1558. }
  1559. GPR[rd] = EXTEND32 (result);
  1560. }
  1561. 011111,5.RS,5.RT,5.RD,00100,010001:SPECIAL3:32::CMPGU.EQ.QB
  1562. "cmpgu.eq.qb r<RD>, r<RS>, r<RT>"
  1563. *dsp:
  1564. {
  1565. do_qb_cmpgu (SD_, RD, RS, RT, 0);
  1566. }
  1567. 011111,5.RS,5.RT,5.RD,00101,010001:SPECIAL3:32::CMPGU.LT.QB
  1568. "cmpgu.lt.qb r<RD>, r<RS>, r<RT>"
  1569. *dsp:
  1570. {
  1571. do_qb_cmpgu (SD_, RD, RS, RT, 1);
  1572. }
  1573. 011111,5.RS,5.RT,5.RD,00110,010001:SPECIAL3:32::CMPGU.LE.QB
  1574. "cmpgu.le.qb r<RD>, r<RS>, r<RT>"
  1575. *dsp:
  1576. {
  1577. do_qb_cmpgu (SD_, RD, RS, RT, 2);
  1578. }
  1579. // op: 0 = EQ, 1 = LT, 2 = LE
  1580. :function:::void:do_ph_cmpu:int rs, int rt, int op
  1581. {
  1582. int i, j;
  1583. unsigned32 v1 = GPR[rs];
  1584. unsigned32 v2 = GPR[rt];
  1585. signed16 h1, h2;
  1586. unsigned32 mask;
  1587. for (i = 0, j = 0; i < 32; i += 16, j++, v1 >>= 16, v2 >>= 16)
  1588. {
  1589. h1 = (signed16)(v1 & 0xffff);
  1590. h2 = (signed16)(v2 & 0xffff);
  1591. mask = ~(1 << (DSPCR_CCOND_SHIFT + j));
  1592. DSPCR &= mask;
  1593. if (op == 0) // EQ
  1594. DSPCR |= ((h1 == h2) << (DSPCR_CCOND_SHIFT + j));
  1595. else if (op == 1) // LT
  1596. DSPCR |= ((h1 < h2) << (DSPCR_CCOND_SHIFT + j));
  1597. else // LE
  1598. DSPCR |= ((h1 <= h2) << (DSPCR_CCOND_SHIFT + j));
  1599. }
  1600. }
  1601. 011111,5.RS,5.RT,00000,01000,010001:SPECIAL3:32::CMP.EQ.PH
  1602. "cmp.eq.ph r<RS>, r<RT>"
  1603. *dsp:
  1604. {
  1605. do_ph_cmpu (SD_, RS, RT, 0);
  1606. }
  1607. 011111,5.RS,5.RT,00000,01001,010001:SPECIAL3:32::CMP.LT.PH
  1608. "cmp.lt.ph r<RS>, r<RT>"
  1609. *dsp:
  1610. {
  1611. do_ph_cmpu (SD_, RS, RT, 1);
  1612. }
  1613. 011111,5.RS,5.RT,00000,01010,010001:SPECIAL3:32::CMP.LE.PH
  1614. "cmp.le.ph r<RS>, r<RT>"
  1615. *dsp:
  1616. {
  1617. do_ph_cmpu (SD_, RS, RT, 2);
  1618. }
  1619. 011111,5.RS,5.RT,5.RD,00011,010001:SPECIAL3:32::PICK.QB
  1620. "pick.qb r<RD>, r<RS>, r<RT>"
  1621. *dsp:
  1622. {
  1623. do_qb_pick (SD_, RD, RS, RT);
  1624. }
  1625. 011111,5.RS,5.RT,5.RD,01011,010001:SPECIAL3:32::PICK.PH
  1626. "pick.ph r<RD>, r<RS>, r<RT>"
  1627. *dsp:
  1628. {
  1629. do_ph_pick (SD_, RD, RS, RT);
  1630. }
  1631. 011111,5.RS,5.RT,5.RD,01110,010001:SPECIAL3:32::PACKRL.PH
  1632. "packrl.ph r<RD>, r<RS>, r<RT>"
  1633. *dsp:
  1634. {
  1635. do_ph_packrl (SD_, RD, RS, RT);
  1636. }
  1637. // op: 0 = EXTR, 1 = EXTR_R, 2 = EXTR_RS
  1638. :function:::void:do_w_extr:int rt, int ac, int shift, int op
  1639. {
  1640. int i;
  1641. unsigned32 lo = DSPLO(ac);
  1642. unsigned32 hi = DSPHI(ac);
  1643. unsigned64 prod = (((unsigned64)hi) << 32) + (unsigned64)lo;
  1644. signed64 result = (signed64)prod;
  1645. int setcond = 0;
  1646. if (!(prod & 0x8000000000000000LL))
  1647. {
  1648. for (i = 62; i >= (shift + 31); i--)
  1649. {
  1650. if (prod & ((unsigned64)1 << i))
  1651. {
  1652. DSPCR |= DSPCR_OUFLAG7;
  1653. setcond = 1;
  1654. break;
  1655. }
  1656. }
  1657. if (((prod >> (shift - 1)) & 0xffffffffLL) == 0xffffffffLL)
  1658. {
  1659. DSPCR |= DSPCR_OUFLAG7;
  1660. setcond = 1;
  1661. }
  1662. }
  1663. else
  1664. {
  1665. for (i = 62; i >= (shift + 31); i--)
  1666. {
  1667. if (!(prod & ((unsigned64)1 << i)))
  1668. {
  1669. DSPCR |= DSPCR_OUFLAG7;
  1670. setcond = 2;
  1671. break;
  1672. }
  1673. }
  1674. }
  1675. if (op == 0) // EXTR
  1676. result = result >> shift;
  1677. else if (op == 1) // EXTR_R
  1678. {
  1679. if (shift != 0)
  1680. result = ((result >> (shift - 1)) + 1) >> 1;
  1681. else
  1682. result = result >> shift;
  1683. }
  1684. else // EXTR_RS
  1685. {
  1686. if (setcond == 1)
  1687. result = 0x7fffffff;
  1688. else if (setcond == 2)
  1689. result = 0x80000000;
  1690. else
  1691. {
  1692. if (shift != 0)
  1693. result = ((result >> (shift - 1)) + 1) >> 1;
  1694. else
  1695. result = result >> shift;
  1696. }
  1697. }
  1698. GPR[rt] = EXTEND32 (result);
  1699. }
  1700. 011111,5.SHIFT,5.RT,000,2.AC,00000,111000:SPECIAL3:32::EXTR.W
  1701. "extr.w r<RT>, ac<AC>, <SHIFT>"
  1702. *dsp:
  1703. {
  1704. do_w_extr (SD_, RT, AC, SHIFT, 0);
  1705. }
  1706. 011111,5.RS,5.RT,000,2.AC,00001,111000:SPECIAL3:32::EXTRV.W
  1707. "extrv.w r<RT>, ac<AC>, r<RS>"
  1708. *dsp:
  1709. {
  1710. do_extrv (SD_, RT, AC, RS, 0);
  1711. }
  1712. 011111,5.SHIFT,5.RT,000,2.AC,00100,111000:SPECIAL3:32::EXTR_R.W
  1713. "extr_r.w r<RT>, ac<AC>, <SHIFT>"
  1714. *dsp:
  1715. {
  1716. do_w_extr (SD_, RT, AC, SHIFT, 1);
  1717. }
  1718. 011111,5.RS,5.RT,000,2.AC,00101,111000:SPECIAL3:32::EXTRV_R.W
  1719. "extrv_r.w r<RT>, ac<AC>, r<RS>"
  1720. *dsp:
  1721. {
  1722. do_extrv (SD_, RT, AC, RS, 1);
  1723. }
  1724. 011111,5.SHIFT,5.RT,000,2.AC,00110,111000:SPECIAL3:32::EXTR_RS.W
  1725. "extr_rs.w r<RT>, ac<AC>, <SHIFT>"
  1726. *dsp:
  1727. {
  1728. do_w_extr (SD_, RT, AC, SHIFT, 2);
  1729. }
  1730. 011111,5.RS,5.RT,000,2.AC,00111,111000:SPECIAL3:32::EXTRV_RS.W
  1731. "extrv_rs.w r<RT>, ac<AC>, r<RS>"
  1732. *dsp:
  1733. {
  1734. do_extrv (SD_, RT, AC, RS, 2);
  1735. }
  1736. :function:::void:do_h_extr:int rt, int ac, int shift
  1737. {
  1738. int i;
  1739. unsigned32 lo = DSPLO(ac);
  1740. unsigned32 hi = DSPHI(ac);
  1741. unsigned64 prod = (((unsigned64)hi) << 32) + (unsigned64)lo;
  1742. signed64 result = (signed64)prod;
  1743. signed64 value = 0xffffffffffff8000LL;
  1744. result >>= shift;
  1745. if (result > 0x7fff)
  1746. {
  1747. result = 0x7fff;
  1748. DSPCR |= DSPCR_OUFLAG7;
  1749. }
  1750. else if (result < value)
  1751. {
  1752. result = value;
  1753. DSPCR |= DSPCR_OUFLAG7;
  1754. }
  1755. GPR[rt] = EXTEND32 (result);
  1756. }
  1757. 011111,5.SHIFT,5.RT,000,2.AC,01110,111000:SPECIAL3:32::EXTR_S.H
  1758. "extr_s.h r<RT>, ac<AC>, <SHIFT>"
  1759. *dsp:
  1760. {
  1761. do_h_extr (SD_, RT, AC, SHIFT);
  1762. }
  1763. 011111,5.RS,5.RT,000,2.AC,01111,111000:SPECIAL3:32::EXTRV_S.H
  1764. "extrv_s.h r<RT>, ac<AC>, r<RS>"
  1765. *dsp:
  1766. {
  1767. do_extrv_s_h (SD_, RT, AC, RS);
  1768. }
  1769. // op: 0 = EXTP, 1 = EXTPDP
  1770. :function:::void:do_extp:int rt, int ac, int size, int op
  1771. {
  1772. signed32 pos = (DSPCR >> DSPCR_POS_SHIFT) & DSPCR_POS_MASK;
  1773. unsigned32 lo = DSPLO(ac);
  1774. unsigned32 hi = DSPHI(ac);
  1775. unsigned64 prod = (((unsigned64)hi) << 32) + (unsigned64)lo;
  1776. unsigned64 result = 0;
  1777. if (pos - (size + 1) >= -1)
  1778. {
  1779. prod >>= (pos - size);
  1780. result = prod & (((unsigned64)1 << (size + 1)) - 1);
  1781. DSPCR &= (~DSPCR_EFI_SMASK);
  1782. if (op == 1) // EXTPDP
  1783. {
  1784. if (pos - (size + 1) >= 0)
  1785. {
  1786. DSPCR &= (~DSPCR_POS_SMASK);
  1787. DSPCR |= ((pos - (size + 1)) & DSPCR_POS_MASK) << DSPCR_POS_SHIFT;
  1788. }
  1789. else if (pos - (size + 1) == -1)
  1790. {
  1791. DSPCR |= DSPCR_POS_SMASK;
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. DSPCR |= DSPCR_EFI;
  1798. Unpredictable ();
  1799. }
  1800. GPR[rt] = EXTEND32 (result);
  1801. }
  1802. 011111,5.SIZE,5.RT,000,2.AC,00010,111000:SPECIAL3:32::EXTP
  1803. "extp r<RT>, ac<AC>, <SIZE>"
  1804. *dsp:
  1805. {
  1806. do_extp (SD_, RT, AC, SIZE, 0);
  1807. }
  1808. 011111,5.RS,5.RT,000,2.AC,00011,111000:SPECIAL3:32::EXTPV
  1809. "extpv r<RT>, ac<AC>, r<RS>"
  1810. *dsp:
  1811. {
  1812. do_extpv (SD_, RT, AC, RS, 0);
  1813. }
  1814. 011111,5.SIZE,5.RT,000,2.AC,01010,111000:SPECIAL3:32::EXTPDP
  1815. "extpdp r<RT>, ac<AC>, <SIZE>"
  1816. *dsp:
  1817. {
  1818. do_extp (SD_, RT, AC, SIZE, 1);
  1819. }
  1820. 011111,5.RS,5.RT,000,2.AC,01011,111000:SPECIAL3:32::EXTPDPV
  1821. "extpdpv r<RT>, ac<AC>, r<RS>"
  1822. *dsp:
  1823. {
  1824. do_extpv (SD_, RT, AC, RS, 1);
  1825. }
  1826. :function:::void:do_shilo:int ac, int shift
  1827. {
  1828. unsigned32 lo = DSPLO(ac);
  1829. unsigned32 hi = DSPHI(ac);
  1830. unsigned64 prod = (((unsigned64)hi) << 32) + (unsigned64)lo;
  1831. if (shift > 31)
  1832. shift = shift - 64;
  1833. if (shift >= 0)
  1834. prod >>= shift;
  1835. else
  1836. prod <<= (-shift);
  1837. DSPLO(ac) = EXTEND32 (prod);
  1838. DSPHI(ac) = EXTEND32 (prod >> 32);
  1839. }
  1840. 011111,6.SHIFT6,0000,000,2.AC,11010,111000:SPECIAL3:32::SHILO
  1841. "shilo ac<AC>, <SHIFT6>"
  1842. *dsp:
  1843. {
  1844. do_shilo (SD_, AC, SHIFT6);
  1845. }
  1846. 011111,5.RS,00000,000,2.AC,11011,111000:SPECIAL3:32::SHILOV
  1847. "shilov ac<AC>, r<RS>"
  1848. *dsp:
  1849. {
  1850. do_shilov (SD_, AC, RS);
  1851. }
  1852. 011111,5.RS,00000,000,2.AC,11111,111000:SPECIAL3:32::MTHLIP
  1853. "mthlip r<RS>, ac<AC>"
  1854. *dsp:
  1855. {
  1856. do_mthlip (SD_, RS, AC);
  1857. }
  1858. 011111,5.RS,10.MASK10,10011,111000:SPECIAL3:32::WRDSP
  1859. "wrdsp r<RS>":MASK10 == 1111111111
  1860. "wrdsp r<RS>, <MASK10>"
  1861. *dsp:
  1862. {
  1863. do_wrdsp (SD_, RS, MASK10);
  1864. }
  1865. 011111,10.MASK10,5.RD,10010,111000:SPECIAL3:32::RDDSP
  1866. "rddsp r<RD>":MASK10 == 1111111111
  1867. "rddsp r<RD>, <MASK10>"
  1868. *dsp:
  1869. {
  1870. do_rddsp (SD_, RD, MASK10);
  1871. }
  1872. 011111,5.BASE,5.INDEX,5.RD,00110,001010:SPECIAL3:32::LBUX
  1873. "lbux r<RD>, r<INDEX>(r<BASE>)"
  1874. *dsp:
  1875. {
  1876. do_lxx (SD_, RD, BASE, INDEX, 0);
  1877. }
  1878. 011111,5.BASE,5.INDEX,5.RD,00100,001010:SPECIAL3:32::LHX
  1879. "lhx r<RD>, r<INDEX>(r<BASE>)"
  1880. *dsp:
  1881. {
  1882. do_lxx (SD_, RD, BASE, INDEX, 1);
  1883. }
  1884. 011111,5.BASE,5.INDEX,5.RD,00000,001010:SPECIAL3:32::LWX
  1885. "lwx r<RD>, r<INDEX>(r<BASE>)"
  1886. *dsp:
  1887. {
  1888. do_lxx (SD_, RD, BASE, INDEX, 2);
  1889. }
  1890. 000001,00000,11100,16.OFFSET:REGIMM:32::BPOSGE32
  1891. "bposge32 <OFFSET>"
  1892. *dsp:
  1893. {
  1894. unsigned32 pos = (DSPCR >> DSPCR_POS_SHIFT) & DSPCR_POS_MASK;
  1895. address_word offset = EXTEND16 (OFFSET) << 2;
  1896. if (pos >= 32)
  1897. {
  1898. DELAY_SLOT (NIA + offset);
  1899. }
  1900. }