math_64.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * arch/sparc64/math-emu/math.c
  3. *
  4. * Copyright (C) 1997,1999 Jakub Jelinek (jj@ultra.linux.cz)
  5. * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  6. *
  7. * Emulation routines originate from soft-fp package, which is part
  8. * of glibc and has appropriate copyrights in it.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/perf_event.h>
  14. #include <asm/fpumacro.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/uaccess.h>
  17. #include <asm/cacheflush.h>
  18. #include "sfp-util_64.h"
  19. #include <math-emu/soft-fp.h>
  20. #include <math-emu/single.h>
  21. #include <math-emu/double.h>
  22. #include <math-emu/quad.h>
  23. /* QUAD - ftt == 3 */
  24. #define FMOVQ 0x003
  25. #define FNEGQ 0x007
  26. #define FABSQ 0x00b
  27. #define FSQRTQ 0x02b
  28. #define FADDQ 0x043
  29. #define FSUBQ 0x047
  30. #define FMULQ 0x04b
  31. #define FDIVQ 0x04f
  32. #define FDMULQ 0x06e
  33. #define FQTOX 0x083
  34. #define FXTOQ 0x08c
  35. #define FQTOS 0x0c7
  36. #define FQTOD 0x0cb
  37. #define FITOQ 0x0cc
  38. #define FSTOQ 0x0cd
  39. #define FDTOQ 0x0ce
  40. #define FQTOI 0x0d3
  41. /* SUBNORMAL - ftt == 2 */
  42. #define FSQRTS 0x029
  43. #define FSQRTD 0x02a
  44. #define FADDS 0x041
  45. #define FADDD 0x042
  46. #define FSUBS 0x045
  47. #define FSUBD 0x046
  48. #define FMULS 0x049
  49. #define FMULD 0x04a
  50. #define FDIVS 0x04d
  51. #define FDIVD 0x04e
  52. #define FSMULD 0x069
  53. #define FSTOX 0x081
  54. #define FDTOX 0x082
  55. #define FDTOS 0x0c6
  56. #define FSTOD 0x0c9
  57. #define FSTOI 0x0d1
  58. #define FDTOI 0x0d2
  59. #define FXTOS 0x084 /* Only Ultra-III generates this. */
  60. #define FXTOD 0x088 /* Only Ultra-III generates this. */
  61. #if 0 /* Optimized inline in sparc64/kernel/entry.S */
  62. #define FITOS 0x0c4 /* Only Ultra-III generates this. */
  63. #endif
  64. #define FITOD 0x0c8 /* Only Ultra-III generates this. */
  65. /* FPOP2 */
  66. #define FCMPQ 0x053
  67. #define FCMPEQ 0x057
  68. #define FMOVQ0 0x003
  69. #define FMOVQ1 0x043
  70. #define FMOVQ2 0x083
  71. #define FMOVQ3 0x0c3
  72. #define FMOVQI 0x103
  73. #define FMOVQX 0x183
  74. #define FMOVQZ 0x027
  75. #define FMOVQLE 0x047
  76. #define FMOVQLZ 0x067
  77. #define FMOVQNZ 0x0a7
  78. #define FMOVQGZ 0x0c7
  79. #define FMOVQGE 0x0e7
  80. #define FSR_TEM_SHIFT 23UL
  81. #define FSR_TEM_MASK (0x1fUL << FSR_TEM_SHIFT)
  82. #define FSR_AEXC_SHIFT 5UL
  83. #define FSR_AEXC_MASK (0x1fUL << FSR_AEXC_SHIFT)
  84. #define FSR_CEXC_SHIFT 0UL
  85. #define FSR_CEXC_MASK (0x1fUL << FSR_CEXC_SHIFT)
  86. /* All routines returning an exception to raise should detect
  87. * such exceptions _before_ rounding to be consistent with
  88. * the behavior of the hardware in the implemented cases
  89. * (and thus with the recommendations in the V9 architecture
  90. * manual).
  91. *
  92. * We return 0 if a SIGFPE should be sent, 1 otherwise.
  93. */
  94. static inline int record_exception(struct pt_regs *regs, int eflag)
  95. {
  96. u64 fsr = current_thread_info()->xfsr[0];
  97. int would_trap;
  98. /* Determine if this exception would have generated a trap. */
  99. would_trap = (fsr & ((long)eflag << FSR_TEM_SHIFT)) != 0UL;
  100. /* If trapping, we only want to signal one bit. */
  101. if(would_trap != 0) {
  102. eflag &= ((fsr & FSR_TEM_MASK) >> FSR_TEM_SHIFT);
  103. if((eflag & (eflag - 1)) != 0) {
  104. if(eflag & FP_EX_INVALID)
  105. eflag = FP_EX_INVALID;
  106. else if(eflag & FP_EX_OVERFLOW)
  107. eflag = FP_EX_OVERFLOW;
  108. else if(eflag & FP_EX_UNDERFLOW)
  109. eflag = FP_EX_UNDERFLOW;
  110. else if(eflag & FP_EX_DIVZERO)
  111. eflag = FP_EX_DIVZERO;
  112. else if(eflag & FP_EX_INEXACT)
  113. eflag = FP_EX_INEXACT;
  114. }
  115. }
  116. /* Set CEXC, here is the rule:
  117. *
  118. * In general all FPU ops will set one and only one
  119. * bit in the CEXC field, this is always the case
  120. * when the IEEE exception trap is enabled in TEM.
  121. */
  122. fsr &= ~(FSR_CEXC_MASK);
  123. fsr |= ((long)eflag << FSR_CEXC_SHIFT);
  124. /* Set the AEXC field, rule is:
  125. *
  126. * If a trap would not be generated, the
  127. * CEXC just generated is OR'd into the
  128. * existing value of AEXC.
  129. */
  130. if(would_trap == 0)
  131. fsr |= ((long)eflag << FSR_AEXC_SHIFT);
  132. /* If trapping, indicate fault trap type IEEE. */
  133. if(would_trap != 0)
  134. fsr |= (1UL << 14);
  135. current_thread_info()->xfsr[0] = fsr;
  136. /* If we will not trap, advance the program counter over
  137. * the instruction being handled.
  138. */
  139. if(would_trap == 0) {
  140. regs->tpc = regs->tnpc;
  141. regs->tnpc += 4;
  142. }
  143. return (would_trap ? 0 : 1);
  144. }
  145. typedef union {
  146. u32 s;
  147. u64 d;
  148. u64 q[2];
  149. } *argp;
  150. int do_mathemu(struct pt_regs *regs, struct fpustate *f, bool illegal_insn_trap)
  151. {
  152. unsigned long pc = regs->tpc;
  153. unsigned long tstate = regs->tstate;
  154. u32 insn = 0;
  155. int type = 0;
  156. /* ftt tells which ftt it may happen in, r is rd, b is rs2 and a is rs1. The *u arg tells
  157. whether the argument should be packed/unpacked (0 - do not unpack/pack, 1 - unpack/pack)
  158. non-u args tells the size of the argument (0 - no argument, 1 - single, 2 - double, 3 - quad */
  159. #define TYPE(ftt, r, ru, b, bu, a, au) type = (au << 2) | (a << 0) | (bu << 5) | (b << 3) | (ru << 8) | (r << 6) | (ftt << 9)
  160. int freg;
  161. static u64 zero[2] = { 0L, 0L };
  162. int flags;
  163. FP_DECL_EX;
  164. FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
  165. FP_DECL_D(DA); FP_DECL_D(DB); FP_DECL_D(DR);
  166. FP_DECL_Q(QA); FP_DECL_Q(QB); FP_DECL_Q(QR);
  167. int IR;
  168. long XR, xfsr;
  169. if (tstate & TSTATE_PRIV)
  170. die_if_kernel("unfinished/unimplemented FPop from kernel", regs);
  171. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
  172. if (test_thread_flag(TIF_32BIT))
  173. pc = (u32)pc;
  174. if (get_user(insn, (u32 __user *) pc) != -EFAULT) {
  175. if ((insn & 0xc1f80000) == 0x81a00000) /* FPOP1 */ {
  176. switch ((insn >> 5) & 0x1ff) {
  177. /* QUAD - ftt == 3 */
  178. case FMOVQ:
  179. case FNEGQ:
  180. case FABSQ: TYPE(3,3,0,3,0,0,0); break;
  181. case FSQRTQ: TYPE(3,3,1,3,1,0,0); break;
  182. case FADDQ:
  183. case FSUBQ:
  184. case FMULQ:
  185. case FDIVQ: TYPE(3,3,1,3,1,3,1); break;
  186. case FDMULQ: TYPE(3,3,1,2,1,2,1); break;
  187. case FQTOX: TYPE(3,2,0,3,1,0,0); break;
  188. case FXTOQ: TYPE(3,3,1,2,0,0,0); break;
  189. case FQTOS: TYPE(3,1,1,3,1,0,0); break;
  190. case FQTOD: TYPE(3,2,1,3,1,0,0); break;
  191. case FITOQ: TYPE(3,3,1,1,0,0,0); break;
  192. case FSTOQ: TYPE(3,3,1,1,1,0,0); break;
  193. case FDTOQ: TYPE(3,3,1,2,1,0,0); break;
  194. case FQTOI: TYPE(3,1,0,3,1,0,0); break;
  195. /* We can get either unimplemented or unfinished
  196. * for these cases. Pre-Niagara systems generate
  197. * unfinished fpop for SUBNORMAL cases, and Niagara
  198. * always gives unimplemented fpop for fsqrt{s,d}.
  199. */
  200. case FSQRTS: {
  201. unsigned long x = current_thread_info()->xfsr[0];
  202. x = (x >> 14) & 0x7;
  203. TYPE(x,1,1,1,1,0,0);
  204. break;
  205. }
  206. case FSQRTD: {
  207. unsigned long x = current_thread_info()->xfsr[0];
  208. x = (x >> 14) & 0x7;
  209. TYPE(x,2,1,2,1,0,0);
  210. break;
  211. }
  212. /* SUBNORMAL - ftt == 2 */
  213. case FADDD:
  214. case FSUBD:
  215. case FMULD:
  216. case FDIVD: TYPE(2,2,1,2,1,2,1); break;
  217. case FADDS:
  218. case FSUBS:
  219. case FMULS:
  220. case FDIVS: TYPE(2,1,1,1,1,1,1); break;
  221. case FSMULD: TYPE(2,2,1,1,1,1,1); break;
  222. case FSTOX: TYPE(2,2,0,1,1,0,0); break;
  223. case FDTOX: TYPE(2,2,0,2,1,0,0); break;
  224. case FDTOS: TYPE(2,1,1,2,1,0,0); break;
  225. case FSTOD: TYPE(2,2,1,1,1,0,0); break;
  226. case FSTOI: TYPE(2,1,0,1,1,0,0); break;
  227. case FDTOI: TYPE(2,1,0,2,1,0,0); break;
  228. /* Only Ultra-III generates these */
  229. case FXTOS: TYPE(2,1,1,2,0,0,0); break;
  230. case FXTOD: TYPE(2,2,1,2,0,0,0); break;
  231. #if 0 /* Optimized inline in sparc64/kernel/entry.S */
  232. case FITOS: TYPE(2,1,1,1,0,0,0); break;
  233. #endif
  234. case FITOD: TYPE(2,2,1,1,0,0,0); break;
  235. }
  236. }
  237. else if ((insn & 0xc1f80000) == 0x81a80000) /* FPOP2 */ {
  238. IR = 2;
  239. switch ((insn >> 5) & 0x1ff) {
  240. case FCMPQ: TYPE(3,0,0,3,1,3,1); break;
  241. case FCMPEQ: TYPE(3,0,0,3,1,3,1); break;
  242. /* Now the conditional fmovq support */
  243. case FMOVQ0:
  244. case FMOVQ1:
  245. case FMOVQ2:
  246. case FMOVQ3:
  247. /* fmovq %fccX, %fY, %fZ */
  248. if (!((insn >> 11) & 3))
  249. XR = current_thread_info()->xfsr[0] >> 10;
  250. else
  251. XR = current_thread_info()->xfsr[0] >> (30 + ((insn >> 10) & 0x6));
  252. XR &= 3;
  253. IR = 0;
  254. switch ((insn >> 14) & 0x7) {
  255. /* case 0: IR = 0; break; */ /* Never */
  256. case 1: if (XR) IR = 1; break; /* Not Equal */
  257. case 2: if (XR == 1 || XR == 2) IR = 1; break; /* Less or Greater */
  258. case 3: if (XR & 1) IR = 1; break; /* Unordered or Less */
  259. case 4: if (XR == 1) IR = 1; break; /* Less */
  260. case 5: if (XR & 2) IR = 1; break; /* Unordered or Greater */
  261. case 6: if (XR == 2) IR = 1; break; /* Greater */
  262. case 7: if (XR == 3) IR = 1; break; /* Unordered */
  263. }
  264. if ((insn >> 14) & 8)
  265. IR ^= 1;
  266. break;
  267. case FMOVQI:
  268. case FMOVQX:
  269. /* fmovq %[ix]cc, %fY, %fZ */
  270. XR = regs->tstate >> 32;
  271. if ((insn >> 5) & 0x80)
  272. XR >>= 4;
  273. XR &= 0xf;
  274. IR = 0;
  275. freg = ((XR >> 2) ^ XR) & 2;
  276. switch ((insn >> 14) & 0x7) {
  277. /* case 0: IR = 0; break; */ /* Never */
  278. case 1: if (XR & 4) IR = 1; break; /* Equal */
  279. case 2: if ((XR & 4) || freg) IR = 1; break; /* Less or Equal */
  280. case 3: if (freg) IR = 1; break; /* Less */
  281. case 4: if (XR & 5) IR = 1; break; /* Less or Equal Unsigned */
  282. case 5: if (XR & 1) IR = 1; break; /* Carry Set */
  283. case 6: if (XR & 8) IR = 1; break; /* Negative */
  284. case 7: if (XR & 2) IR = 1; break; /* Overflow Set */
  285. }
  286. if ((insn >> 14) & 8)
  287. IR ^= 1;
  288. break;
  289. case FMOVQZ:
  290. case FMOVQLE:
  291. case FMOVQLZ:
  292. case FMOVQNZ:
  293. case FMOVQGZ:
  294. case FMOVQGE:
  295. freg = (insn >> 14) & 0x1f;
  296. if (!freg)
  297. XR = 0;
  298. else if (freg < 16)
  299. XR = regs->u_regs[freg];
  300. else if (!test_thread_64bit_stack(regs->u_regs[UREG_FP])) {
  301. struct reg_window32 __user *win32;
  302. flushw_user ();
  303. win32 = (struct reg_window32 __user *)((unsigned long)((u32)regs->u_regs[UREG_FP]));
  304. get_user(XR, &win32->locals[freg - 16]);
  305. } else {
  306. struct reg_window __user *win;
  307. flushw_user ();
  308. win = (struct reg_window __user *)(regs->u_regs[UREG_FP] + STACK_BIAS);
  309. get_user(XR, &win->locals[freg - 16]);
  310. }
  311. IR = 0;
  312. switch ((insn >> 10) & 3) {
  313. case 1: if (!XR) IR = 1; break; /* Register Zero */
  314. case 2: if (XR <= 0) IR = 1; break; /* Register Less Than or Equal to Zero */
  315. case 3: if (XR < 0) IR = 1; break; /* Register Less Than Zero */
  316. }
  317. if ((insn >> 10) & 4)
  318. IR ^= 1;
  319. break;
  320. }
  321. if (IR == 0) {
  322. /* The fmov test was false. Do a nop instead */
  323. current_thread_info()->xfsr[0] &= ~(FSR_CEXC_MASK);
  324. regs->tpc = regs->tnpc;
  325. regs->tnpc += 4;
  326. return 1;
  327. } else if (IR == 1) {
  328. /* Change the instruction into plain fmovq */
  329. insn = (insn & 0x3e00001f) | 0x81a00060;
  330. TYPE(3,3,0,3,0,0,0);
  331. }
  332. }
  333. }
  334. if (type) {
  335. argp rs1 = NULL, rs2 = NULL, rd = NULL;
  336. /* Starting with UltraSPARC-T2, the cpu does not set the FP Trap
  337. * Type field in the %fsr to unimplemented_FPop. Nor does it
  338. * use the fp_exception_other trap. Instead it signals an
  339. * illegal instruction and leaves the FP trap type field of
  340. * the %fsr unchanged.
  341. */
  342. if (!illegal_insn_trap) {
  343. int ftt = (current_thread_info()->xfsr[0] >> 14) & 0x7;
  344. if (ftt != (type >> 9))
  345. goto err;
  346. }
  347. current_thread_info()->xfsr[0] &= ~0x1c000;
  348. freg = ((insn >> 14) & 0x1f);
  349. switch (type & 0x3) {
  350. case 3: if (freg & 2) {
  351. current_thread_info()->xfsr[0] |= (6 << 14) /* invalid_fp_register */;
  352. goto err;
  353. }
  354. case 2: freg = ((freg & 1) << 5) | (freg & 0x1e);
  355. case 1: rs1 = (argp)&f->regs[freg];
  356. flags = (freg < 32) ? FPRS_DL : FPRS_DU;
  357. if (!(current_thread_info()->fpsaved[0] & flags))
  358. rs1 = (argp)&zero;
  359. break;
  360. }
  361. switch (type & 0x7) {
  362. case 7: FP_UNPACK_QP (QA, rs1); break;
  363. case 6: FP_UNPACK_DP (DA, rs1); break;
  364. case 5: FP_UNPACK_SP (SA, rs1); break;
  365. }
  366. freg = (insn & 0x1f);
  367. switch ((type >> 3) & 0x3) {
  368. case 3: if (freg & 2) {
  369. current_thread_info()->xfsr[0] |= (6 << 14) /* invalid_fp_register */;
  370. goto err;
  371. }
  372. case 2: freg = ((freg & 1) << 5) | (freg & 0x1e);
  373. case 1: rs2 = (argp)&f->regs[freg];
  374. flags = (freg < 32) ? FPRS_DL : FPRS_DU;
  375. if (!(current_thread_info()->fpsaved[0] & flags))
  376. rs2 = (argp)&zero;
  377. break;
  378. }
  379. switch ((type >> 3) & 0x7) {
  380. case 7: FP_UNPACK_QP (QB, rs2); break;
  381. case 6: FP_UNPACK_DP (DB, rs2); break;
  382. case 5: FP_UNPACK_SP (SB, rs2); break;
  383. }
  384. freg = ((insn >> 25) & 0x1f);
  385. switch ((type >> 6) & 0x3) {
  386. case 3: if (freg & 2) {
  387. current_thread_info()->xfsr[0] |= (6 << 14) /* invalid_fp_register */;
  388. goto err;
  389. }
  390. case 2: freg = ((freg & 1) << 5) | (freg & 0x1e);
  391. case 1: rd = (argp)&f->regs[freg];
  392. flags = (freg < 32) ? FPRS_DL : FPRS_DU;
  393. if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) {
  394. current_thread_info()->fpsaved[0] = FPRS_FEF;
  395. current_thread_info()->gsr[0] = 0;
  396. }
  397. if (!(current_thread_info()->fpsaved[0] & flags)) {
  398. if (freg < 32)
  399. memset(f->regs, 0, 32*sizeof(u32));
  400. else
  401. memset(f->regs+32, 0, 32*sizeof(u32));
  402. }
  403. current_thread_info()->fpsaved[0] |= flags;
  404. break;
  405. }
  406. switch ((insn >> 5) & 0x1ff) {
  407. /* + */
  408. case FADDS: FP_ADD_S (SR, SA, SB); break;
  409. case FADDD: FP_ADD_D (DR, DA, DB); break;
  410. case FADDQ: FP_ADD_Q (QR, QA, QB); break;
  411. /* - */
  412. case FSUBS: FP_SUB_S (SR, SA, SB); break;
  413. case FSUBD: FP_SUB_D (DR, DA, DB); break;
  414. case FSUBQ: FP_SUB_Q (QR, QA, QB); break;
  415. /* * */
  416. case FMULS: FP_MUL_S (SR, SA, SB); break;
  417. case FSMULD: FP_CONV (D, S, 1, 1, DA, SA);
  418. FP_CONV (D, S, 1, 1, DB, SB);
  419. case FMULD: FP_MUL_D (DR, DA, DB); break;
  420. case FDMULQ: FP_CONV (Q, D, 2, 1, QA, DA);
  421. FP_CONV (Q, D, 2, 1, QB, DB);
  422. case FMULQ: FP_MUL_Q (QR, QA, QB); break;
  423. /* / */
  424. case FDIVS: FP_DIV_S (SR, SA, SB); break;
  425. case FDIVD: FP_DIV_D (DR, DA, DB); break;
  426. case FDIVQ: FP_DIV_Q (QR, QA, QB); break;
  427. /* sqrt */
  428. case FSQRTS: FP_SQRT_S (SR, SB); break;
  429. case FSQRTD: FP_SQRT_D (DR, DB); break;
  430. case FSQRTQ: FP_SQRT_Q (QR, QB); break;
  431. /* mov */
  432. case FMOVQ: rd->q[0] = rs2->q[0]; rd->q[1] = rs2->q[1]; break;
  433. case FABSQ: rd->q[0] = rs2->q[0] & 0x7fffffffffffffffUL; rd->q[1] = rs2->q[1]; break;
  434. case FNEGQ: rd->q[0] = rs2->q[0] ^ 0x8000000000000000UL; rd->q[1] = rs2->q[1]; break;
  435. /* float to int */
  436. case FSTOI: FP_TO_INT_S (IR, SB, 32, 1); break;
  437. case FDTOI: FP_TO_INT_D (IR, DB, 32, 1); break;
  438. case FQTOI: FP_TO_INT_Q (IR, QB, 32, 1); break;
  439. case FSTOX: FP_TO_INT_S (XR, SB, 64, 1); break;
  440. case FDTOX: FP_TO_INT_D (XR, DB, 64, 1); break;
  441. case FQTOX: FP_TO_INT_Q (XR, QB, 64, 1); break;
  442. /* int to float */
  443. case FITOQ: IR = rs2->s; FP_FROM_INT_Q (QR, IR, 32, int); break;
  444. case FXTOQ: XR = rs2->d; FP_FROM_INT_Q (QR, XR, 64, long); break;
  445. /* Only Ultra-III generates these */
  446. case FXTOS: XR = rs2->d; FP_FROM_INT_S (SR, XR, 64, long); break;
  447. case FXTOD: XR = rs2->d; FP_FROM_INT_D (DR, XR, 64, long); break;
  448. #if 0 /* Optimized inline in sparc64/kernel/entry.S */
  449. case FITOS: IR = rs2->s; FP_FROM_INT_S (SR, IR, 32, int); break;
  450. #endif
  451. case FITOD: IR = rs2->s; FP_FROM_INT_D (DR, IR, 32, int); break;
  452. /* float to float */
  453. case FSTOD: FP_CONV (D, S, 1, 1, DR, SB); break;
  454. case FSTOQ: FP_CONV (Q, S, 2, 1, QR, SB); break;
  455. case FDTOQ: FP_CONV (Q, D, 2, 1, QR, DB); break;
  456. case FDTOS: FP_CONV (S, D, 1, 1, SR, DB); break;
  457. case FQTOS: FP_CONV (S, Q, 1, 2, SR, QB); break;
  458. case FQTOD: FP_CONV (D, Q, 1, 2, DR, QB); break;
  459. /* comparison */
  460. case FCMPQ:
  461. case FCMPEQ:
  462. FP_CMP_Q(XR, QB, QA, 3);
  463. if (XR == 3 &&
  464. (((insn >> 5) & 0x1ff) == FCMPEQ ||
  465. FP_ISSIGNAN_Q(QA) ||
  466. FP_ISSIGNAN_Q(QB)))
  467. FP_SET_EXCEPTION (FP_EX_INVALID);
  468. }
  469. if (!FP_INHIBIT_RESULTS) {
  470. switch ((type >> 6) & 0x7) {
  471. case 0: xfsr = current_thread_info()->xfsr[0];
  472. if (XR == -1) XR = 2;
  473. switch (freg & 3) {
  474. /* fcc0, 1, 2, 3 */
  475. case 0: xfsr &= ~0xc00; xfsr |= (XR << 10); break;
  476. case 1: xfsr &= ~0x300000000UL; xfsr |= (XR << 32); break;
  477. case 2: xfsr &= ~0xc00000000UL; xfsr |= (XR << 34); break;
  478. case 3: xfsr &= ~0x3000000000UL; xfsr |= (XR << 36); break;
  479. }
  480. current_thread_info()->xfsr[0] = xfsr;
  481. break;
  482. case 1: rd->s = IR; break;
  483. case 2: rd->d = XR; break;
  484. case 5: FP_PACK_SP (rd, SR); break;
  485. case 6: FP_PACK_DP (rd, DR); break;
  486. case 7: FP_PACK_QP (rd, QR); break;
  487. }
  488. }
  489. if(_fex != 0)
  490. return record_exception(regs, _fex);
  491. /* Success and no exceptions detected. */
  492. current_thread_info()->xfsr[0] &= ~(FSR_CEXC_MASK);
  493. regs->tpc = regs->tnpc;
  494. regs->tnpc += 4;
  495. return 1;
  496. }
  497. err: return 0;
  498. }