math_32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. * arch/sparc/math-emu/math.c
  3. *
  4. * Copyright (C) 1998 Peter Maydell (pmaydell@chiark.greenend.org.uk)
  5. * Copyright (C) 1997, 1999 Jakub Jelinek (jj@ultra.linux.cz)
  6. * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  7. *
  8. * This is a good place to start if you're trying to understand the
  9. * emulation code, because it's pretty simple. What we do is
  10. * essentially analyse the instruction to work out what the operation
  11. * is and which registers are involved. We then execute the appropriate
  12. * FXXXX function. [The floating point queue introduces a minor wrinkle;
  13. * see below...]
  14. * The fxxxxx.c files each emulate a single insn. They look relatively
  15. * simple because the complexity is hidden away in an unholy tangle
  16. * of preprocessor macros.
  17. *
  18. * The first layer of macros is single.h, double.h, quad.h. Generally
  19. * these files define macros for working with floating point numbers
  20. * of the three IEEE formats. FP_ADD_D(R,A,B) is for adding doubles,
  21. * for instance. These macros are usually defined as calls to more
  22. * generic macros (in this case _FP_ADD(D,2,R,X,Y) where the number
  23. * of machine words required to store the given IEEE format is passed
  24. * as a parameter. [double.h and co check the number of bits in a word
  25. * and define FP_ADD_D & co appropriately].
  26. * The generic macros are defined in op-common.h. This is where all
  27. * the grotty stuff like handling NaNs is coded. To handle the possible
  28. * word sizes macros in op-common.h use macros like _FP_FRAC_SLL_##wc()
  29. * where wc is the 'number of machine words' parameter (here 2).
  30. * These are defined in the third layer of macros: op-1.h, op-2.h
  31. * and op-4.h. These handle operations on floating point numbers composed
  32. * of 1,2 and 4 machine words respectively. [For example, on sparc64
  33. * doubles are one machine word so macros in double.h eventually use
  34. * constructs in op-1.h, but on sparc32 they use op-2.h definitions.]
  35. * soft-fp.h is on the same level as op-common.h, and defines some
  36. * macros which are independent of both word size and FP format.
  37. * Finally, sfp-machine.h is the machine dependent part of the
  38. * code: it defines the word size and what type a word is. It also
  39. * defines how _FP_MUL_MEAT_t() maps to _FP_MUL_MEAT_n_* : op-n.h
  40. * provide several possible flavours of multiply algorithm, most
  41. * of which require that you supply some form of asm or C primitive to
  42. * do the actual multiply. (such asm primitives should be defined
  43. * in sfp-machine.h too). udivmodti4.c is the same sort of thing.
  44. *
  45. * There may be some errors here because I'm working from a
  46. * SPARC architecture manual V9, and what I really want is V8...
  47. * Also, the insns which can generate exceptions seem to be a
  48. * greater subset of the FPops than for V9 (for example, FCMPED
  49. * has to be emulated on V8). So I think I'm going to have
  50. * to emulate them all just to be on the safe side...
  51. *
  52. * Emulation routines originate from soft-fp package, which is
  53. * part of glibc and has appropriate copyrights in it (allegedly).
  54. *
  55. * NB: on sparc int == long == 4 bytes, long long == 8 bytes.
  56. * Most bits of the kernel seem to go for long rather than int,
  57. * so we follow that practice...
  58. */
  59. /* TODO:
  60. * fpsave() saves the FP queue but fpload() doesn't reload it.
  61. * Therefore when we context switch or change FPU ownership
  62. * we have to check to see if the queue had anything in it and
  63. * emulate it if it did. This is going to be a pain.
  64. */
  65. #include <linux/types.h>
  66. #include <linux/sched.h>
  67. #include <linux/mm.h>
  68. #include <linux/perf_event.h>
  69. #include <asm/uaccess.h>
  70. #include "sfp-util_32.h"
  71. #include <math-emu/soft-fp.h>
  72. #include <math-emu/single.h>
  73. #include <math-emu/double.h>
  74. #include <math-emu/quad.h>
  75. #define FLOATFUNC(x) extern int x(void *,void *,void *)
  76. /* The Vn labels indicate what version of the SPARC architecture gas thinks
  77. * each insn is. This is from the binutils source :->
  78. */
  79. /* quadword instructions */
  80. #define FSQRTQ 0x02b /* v8 */
  81. #define FADDQ 0x043 /* v8 */
  82. #define FSUBQ 0x047 /* v8 */
  83. #define FMULQ 0x04b /* v8 */
  84. #define FDIVQ 0x04f /* v8 */
  85. #define FDMULQ 0x06e /* v8 */
  86. #define FQTOS 0x0c7 /* v8 */
  87. #define FQTOD 0x0cb /* v8 */
  88. #define FITOQ 0x0cc /* v8 */
  89. #define FSTOQ 0x0cd /* v8 */
  90. #define FDTOQ 0x0ce /* v8 */
  91. #define FQTOI 0x0d3 /* v8 */
  92. #define FCMPQ 0x053 /* v8 */
  93. #define FCMPEQ 0x057 /* v8 */
  94. /* single/double instructions (subnormal): should all work */
  95. #define FSQRTS 0x029 /* v7 */
  96. #define FSQRTD 0x02a /* v7 */
  97. #define FADDS 0x041 /* v6 */
  98. #define FADDD 0x042 /* v6 */
  99. #define FSUBS 0x045 /* v6 */
  100. #define FSUBD 0x046 /* v6 */
  101. #define FMULS 0x049 /* v6 */
  102. #define FMULD 0x04a /* v6 */
  103. #define FDIVS 0x04d /* v6 */
  104. #define FDIVD 0x04e /* v6 */
  105. #define FSMULD 0x069 /* v6 */
  106. #define FDTOS 0x0c6 /* v6 */
  107. #define FSTOD 0x0c9 /* v6 */
  108. #define FSTOI 0x0d1 /* v6 */
  109. #define FDTOI 0x0d2 /* v6 */
  110. #define FABSS 0x009 /* v6 */
  111. #define FCMPS 0x051 /* v6 */
  112. #define FCMPES 0x055 /* v6 */
  113. #define FCMPD 0x052 /* v6 */
  114. #define FCMPED 0x056 /* v6 */
  115. #define FMOVS 0x001 /* v6 */
  116. #define FNEGS 0x005 /* v6 */
  117. #define FITOS 0x0c4 /* v6 */
  118. #define FITOD 0x0c8 /* v6 */
  119. #define FSR_TEM_SHIFT 23UL
  120. #define FSR_TEM_MASK (0x1fUL << FSR_TEM_SHIFT)
  121. #define FSR_AEXC_SHIFT 5UL
  122. #define FSR_AEXC_MASK (0x1fUL << FSR_AEXC_SHIFT)
  123. #define FSR_CEXC_SHIFT 0UL
  124. #define FSR_CEXC_MASK (0x1fUL << FSR_CEXC_SHIFT)
  125. static int do_one_mathemu(u32 insn, unsigned long *fsr, unsigned long *fregs);
  126. /* Unlike the Sparc64 version (which has a struct fpustate), we
  127. * pass the taskstruct corresponding to the task which currently owns the
  128. * FPU. This is partly because we don't have the fpustate struct and
  129. * partly because the task owning the FPU isn't always current (as is
  130. * the case for the Sparc64 port). This is probably SMP-related...
  131. * This function returns 1 if all queued insns were emulated successfully.
  132. * The test for unimplemented FPop in kernel mode has been moved into
  133. * kernel/traps.c for simplicity.
  134. */
  135. int do_mathemu(struct pt_regs *regs, struct task_struct *fpt)
  136. {
  137. /* regs->pc isn't necessarily the PC at which the offending insn is sitting.
  138. * The FPU maintains a queue of FPops which cause traps.
  139. * When it hits an instruction that requires that the trapped op succeeded
  140. * (usually because it reads a reg. that the trapped op wrote) then it
  141. * causes this exception. We need to emulate all the insns on the queue
  142. * and then allow the op to proceed.
  143. * This code should also handle the case where the trap was precise,
  144. * in which case the queue length is zero and regs->pc points at the
  145. * single FPop to be emulated. (this case is untested, though :->)
  146. * You'll need this case if you want to be able to emulate all FPops
  147. * because the FPU either doesn't exist or has been software-disabled.
  148. * [The UltraSPARC makes FP a precise trap; this isn't as stupid as it
  149. * might sound because the Ultra does funky things with a superscalar
  150. * architecture.]
  151. */
  152. /* You wouldn't believe how often I typed 'ftp' when I meant 'fpt' :-> */
  153. int i;
  154. int retcode = 0; /* assume all succeed */
  155. unsigned long insn;
  156. perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
  157. #ifdef DEBUG_MATHEMU
  158. printk("In do_mathemu()... pc is %08lx\n", regs->pc);
  159. printk("fpqdepth is %ld\n", fpt->thread.fpqdepth);
  160. for (i = 0; i < fpt->thread.fpqdepth; i++)
  161. printk("%d: %08lx at %08lx\n", i, fpt->thread.fpqueue[i].insn,
  162. (unsigned long)fpt->thread.fpqueue[i].insn_addr);
  163. #endif
  164. if (fpt->thread.fpqdepth == 0) { /* no queue, guilty insn is at regs->pc */
  165. #ifdef DEBUG_MATHEMU
  166. printk("precise trap at %08lx\n", regs->pc);
  167. #endif
  168. if (!get_user(insn, (u32 __user *) regs->pc)) {
  169. retcode = do_one_mathemu(insn, &fpt->thread.fsr, fpt->thread.float_regs);
  170. if (retcode) {
  171. /* in this case we need to fix up PC & nPC */
  172. regs->pc = regs->npc;
  173. regs->npc += 4;
  174. }
  175. }
  176. return retcode;
  177. }
  178. /* Normal case: need to empty the queue... */
  179. for (i = 0; i < fpt->thread.fpqdepth; i++) {
  180. retcode = do_one_mathemu(fpt->thread.fpqueue[i].insn, &(fpt->thread.fsr), fpt->thread.float_regs);
  181. if (!retcode) /* insn failed, no point doing any more */
  182. break;
  183. }
  184. /* Now empty the queue and clear the queue_not_empty flag */
  185. if (retcode)
  186. fpt->thread.fsr &= ~(0x3000 | FSR_CEXC_MASK);
  187. else
  188. fpt->thread.fsr &= ~0x3000;
  189. fpt->thread.fpqdepth = 0;
  190. return retcode;
  191. }
  192. /* All routines returning an exception to raise should detect
  193. * such exceptions _before_ rounding to be consistent with
  194. * the behavior of the hardware in the implemented cases
  195. * (and thus with the recommendations in the V9 architecture
  196. * manual).
  197. *
  198. * We return 0 if a SIGFPE should be sent, 1 otherwise.
  199. */
  200. static inline int record_exception(unsigned long *pfsr, int eflag)
  201. {
  202. unsigned long fsr = *pfsr;
  203. int would_trap;
  204. /* Determine if this exception would have generated a trap. */
  205. would_trap = (fsr & ((long)eflag << FSR_TEM_SHIFT)) != 0UL;
  206. /* If trapping, we only want to signal one bit. */
  207. if (would_trap != 0) {
  208. eflag &= ((fsr & FSR_TEM_MASK) >> FSR_TEM_SHIFT);
  209. if ((eflag & (eflag - 1)) != 0) {
  210. if (eflag & FP_EX_INVALID)
  211. eflag = FP_EX_INVALID;
  212. else if (eflag & FP_EX_OVERFLOW)
  213. eflag = FP_EX_OVERFLOW;
  214. else if (eflag & FP_EX_UNDERFLOW)
  215. eflag = FP_EX_UNDERFLOW;
  216. else if (eflag & FP_EX_DIVZERO)
  217. eflag = FP_EX_DIVZERO;
  218. else if (eflag & FP_EX_INEXACT)
  219. eflag = FP_EX_INEXACT;
  220. }
  221. }
  222. /* Set CEXC, here is the rule:
  223. *
  224. * In general all FPU ops will set one and only one
  225. * bit in the CEXC field, this is always the case
  226. * when the IEEE exception trap is enabled in TEM.
  227. */
  228. fsr &= ~(FSR_CEXC_MASK);
  229. fsr |= ((long)eflag << FSR_CEXC_SHIFT);
  230. /* Set the AEXC field, rule is:
  231. *
  232. * If a trap would not be generated, the
  233. * CEXC just generated is OR'd into the
  234. * existing value of AEXC.
  235. */
  236. if (would_trap == 0)
  237. fsr |= ((long)eflag << FSR_AEXC_SHIFT);
  238. /* If trapping, indicate fault trap type IEEE. */
  239. if (would_trap != 0)
  240. fsr |= (1UL << 14);
  241. *pfsr = fsr;
  242. return (would_trap ? 0 : 1);
  243. }
  244. typedef union {
  245. u32 s;
  246. u64 d;
  247. u64 q[2];
  248. } *argp;
  249. static int do_one_mathemu(u32 insn, unsigned long *pfsr, unsigned long *fregs)
  250. {
  251. /* Emulate the given insn, updating fsr and fregs appropriately. */
  252. int type = 0;
  253. /* r is rd, b is rs2 and a is rs1. The *u arg tells
  254. whether the argument should be packed/unpacked (0 - do not unpack/pack, 1 - unpack/pack)
  255. non-u args tells the size of the argument (0 - no argument, 1 - single, 2 - double, 3 - quad */
  256. #define TYPE(dummy, r, ru, b, bu, a, au) type = (au << 2) | (a << 0) | (bu << 5) | (b << 3) | (ru << 8) | (r << 6)
  257. int freg;
  258. argp rs1 = NULL, rs2 = NULL, rd = NULL;
  259. FP_DECL_EX;
  260. FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
  261. FP_DECL_D(DA); FP_DECL_D(DB); FP_DECL_D(DR);
  262. FP_DECL_Q(QA); FP_DECL_Q(QB); FP_DECL_Q(QR);
  263. int IR;
  264. long fsr;
  265. #ifdef DEBUG_MATHEMU
  266. printk("In do_mathemu(), emulating %08lx\n", insn);
  267. #endif
  268. if ((insn & 0xc1f80000) == 0x81a00000) /* FPOP1 */ {
  269. switch ((insn >> 5) & 0x1ff) {
  270. case FSQRTQ: TYPE(3,3,1,3,1,0,0); break;
  271. case FADDQ:
  272. case FSUBQ:
  273. case FMULQ:
  274. case FDIVQ: TYPE(3,3,1,3,1,3,1); break;
  275. case FDMULQ: TYPE(3,3,1,2,1,2,1); break;
  276. case FQTOS: TYPE(3,1,1,3,1,0,0); break;
  277. case FQTOD: TYPE(3,2,1,3,1,0,0); break;
  278. case FITOQ: TYPE(3,3,1,1,0,0,0); break;
  279. case FSTOQ: TYPE(3,3,1,1,1,0,0); break;
  280. case FDTOQ: TYPE(3,3,1,2,1,0,0); break;
  281. case FQTOI: TYPE(3,1,0,3,1,0,0); break;
  282. case FSQRTS: TYPE(2,1,1,1,1,0,0); break;
  283. case FSQRTD: TYPE(2,2,1,2,1,0,0); break;
  284. case FADDD:
  285. case FSUBD:
  286. case FMULD:
  287. case FDIVD: TYPE(2,2,1,2,1,2,1); break;
  288. case FADDS:
  289. case FSUBS:
  290. case FMULS:
  291. case FDIVS: TYPE(2,1,1,1,1,1,1); break;
  292. case FSMULD: TYPE(2,2,1,1,1,1,1); break;
  293. case FDTOS: TYPE(2,1,1,2,1,0,0); break;
  294. case FSTOD: TYPE(2,2,1,1,1,0,0); break;
  295. case FSTOI: TYPE(2,1,0,1,1,0,0); break;
  296. case FDTOI: TYPE(2,1,0,2,1,0,0); break;
  297. case FITOS: TYPE(2,1,1,1,0,0,0); break;
  298. case FITOD: TYPE(2,2,1,1,0,0,0); break;
  299. case FMOVS:
  300. case FABSS:
  301. case FNEGS: TYPE(2,1,0,1,0,0,0); break;
  302. }
  303. } else if ((insn & 0xc1f80000) == 0x81a80000) /* FPOP2 */ {
  304. switch ((insn >> 5) & 0x1ff) {
  305. case FCMPS: TYPE(3,0,0,1,1,1,1); break;
  306. case FCMPES: TYPE(3,0,0,1,1,1,1); break;
  307. case FCMPD: TYPE(3,0,0,2,1,2,1); break;
  308. case FCMPED: TYPE(3,0,0,2,1,2,1); break;
  309. case FCMPQ: TYPE(3,0,0,3,1,3,1); break;
  310. case FCMPEQ: TYPE(3,0,0,3,1,3,1); break;
  311. }
  312. }
  313. if (!type) { /* oops, didn't recognise that FPop */
  314. #ifdef DEBUG_MATHEMU
  315. printk("attempt to emulate unrecognised FPop!\n");
  316. #endif
  317. return 0;
  318. }
  319. /* Decode the registers to be used */
  320. freg = (*pfsr >> 14) & 0xf;
  321. *pfsr &= ~0x1c000; /* clear the traptype bits */
  322. freg = ((insn >> 14) & 0x1f);
  323. switch (type & 0x3) { /* is rs1 single, double or quad? */
  324. case 3:
  325. if (freg & 3) { /* quadwords must have bits 4&5 of the */
  326. /* encoded reg. number set to zero. */
  327. *pfsr |= (6 << 14);
  328. return 0; /* simulate invalid_fp_register exception */
  329. }
  330. /* fall through */
  331. case 2:
  332. if (freg & 1) { /* doublewords must have bit 5 zeroed */
  333. *pfsr |= (6 << 14);
  334. return 0;
  335. }
  336. }
  337. rs1 = (argp)&fregs[freg];
  338. switch (type & 0x7) {
  339. case 7: FP_UNPACK_QP (QA, rs1); break;
  340. case 6: FP_UNPACK_DP (DA, rs1); break;
  341. case 5: FP_UNPACK_SP (SA, rs1); break;
  342. }
  343. freg = (insn & 0x1f);
  344. switch ((type >> 3) & 0x3) { /* same again for rs2 */
  345. case 3:
  346. if (freg & 3) { /* quadwords must have bits 4&5 of the */
  347. /* encoded reg. number set to zero. */
  348. *pfsr |= (6 << 14);
  349. return 0; /* simulate invalid_fp_register exception */
  350. }
  351. /* fall through */
  352. case 2:
  353. if (freg & 1) { /* doublewords must have bit 5 zeroed */
  354. *pfsr |= (6 << 14);
  355. return 0;
  356. }
  357. }
  358. rs2 = (argp)&fregs[freg];
  359. switch ((type >> 3) & 0x7) {
  360. case 7: FP_UNPACK_QP (QB, rs2); break;
  361. case 6: FP_UNPACK_DP (DB, rs2); break;
  362. case 5: FP_UNPACK_SP (SB, rs2); break;
  363. }
  364. freg = ((insn >> 25) & 0x1f);
  365. switch ((type >> 6) & 0x3) { /* and finally rd. This one's a bit different */
  366. case 0: /* dest is fcc. (this must be FCMPQ or FCMPEQ) */
  367. if (freg) { /* V8 has only one set of condition codes, so */
  368. /* anything but 0 in the rd field is an error */
  369. *pfsr |= (6 << 14); /* (should probably flag as invalid opcode */
  370. return 0; /* but SIGFPE will do :-> ) */
  371. }
  372. break;
  373. case 3:
  374. if (freg & 3) { /* quadwords must have bits 4&5 of the */
  375. /* encoded reg. number set to zero. */
  376. *pfsr |= (6 << 14);
  377. return 0; /* simulate invalid_fp_register exception */
  378. }
  379. /* fall through */
  380. case 2:
  381. if (freg & 1) { /* doublewords must have bit 5 zeroed */
  382. *pfsr |= (6 << 14);
  383. return 0;
  384. }
  385. /* fall through */
  386. case 1:
  387. rd = (void *)&fregs[freg];
  388. break;
  389. }
  390. #ifdef DEBUG_MATHEMU
  391. printk("executing insn...\n");
  392. #endif
  393. /* do the Right Thing */
  394. switch ((insn >> 5) & 0x1ff) {
  395. /* + */
  396. case FADDS: FP_ADD_S (SR, SA, SB); break;
  397. case FADDD: FP_ADD_D (DR, DA, DB); break;
  398. case FADDQ: FP_ADD_Q (QR, QA, QB); break;
  399. /* - */
  400. case FSUBS: FP_SUB_S (SR, SA, SB); break;
  401. case FSUBD: FP_SUB_D (DR, DA, DB); break;
  402. case FSUBQ: FP_SUB_Q (QR, QA, QB); break;
  403. /* * */
  404. case FMULS: FP_MUL_S (SR, SA, SB); break;
  405. case FSMULD: FP_CONV (D, S, 2, 1, DA, SA);
  406. FP_CONV (D, S, 2, 1, DB, SB);
  407. case FMULD: FP_MUL_D (DR, DA, DB); break;
  408. case FDMULQ: FP_CONV (Q, D, 4, 2, QA, DA);
  409. FP_CONV (Q, D, 4, 2, QB, DB);
  410. case FMULQ: FP_MUL_Q (QR, QA, QB); break;
  411. /* / */
  412. case FDIVS: FP_DIV_S (SR, SA, SB); break;
  413. case FDIVD: FP_DIV_D (DR, DA, DB); break;
  414. case FDIVQ: FP_DIV_Q (QR, QA, QB); break;
  415. /* sqrt */
  416. case FSQRTS: FP_SQRT_S (SR, SB); break;
  417. case FSQRTD: FP_SQRT_D (DR, DB); break;
  418. case FSQRTQ: FP_SQRT_Q (QR, QB); break;
  419. /* mov */
  420. case FMOVS: rd->s = rs2->s; break;
  421. case FABSS: rd->s = rs2->s & 0x7fffffff; break;
  422. case FNEGS: rd->s = rs2->s ^ 0x80000000; break;
  423. /* float to int */
  424. case FSTOI: FP_TO_INT_S (IR, SB, 32, 1); break;
  425. case FDTOI: FP_TO_INT_D (IR, DB, 32, 1); break;
  426. case FQTOI: FP_TO_INT_Q (IR, QB, 32, 1); break;
  427. /* int to float */
  428. case FITOS: IR = rs2->s; FP_FROM_INT_S (SR, IR, 32, int); break;
  429. case FITOD: IR = rs2->s; FP_FROM_INT_D (DR, IR, 32, int); break;
  430. case FITOQ: IR = rs2->s; FP_FROM_INT_Q (QR, IR, 32, int); break;
  431. /* float to float */
  432. case FSTOD: FP_CONV (D, S, 2, 1, DR, SB); break;
  433. case FSTOQ: FP_CONV (Q, S, 4, 1, QR, SB); break;
  434. case FDTOQ: FP_CONV (Q, D, 4, 2, QR, DB); break;
  435. case FDTOS: FP_CONV (S, D, 1, 2, SR, DB); break;
  436. case FQTOS: FP_CONV (S, Q, 1, 4, SR, QB); break;
  437. case FQTOD: FP_CONV (D, Q, 2, 4, DR, QB); break;
  438. /* comparison */
  439. case FCMPS:
  440. case FCMPES:
  441. FP_CMP_S(IR, SB, SA, 3);
  442. if (IR == 3 &&
  443. (((insn >> 5) & 0x1ff) == FCMPES ||
  444. FP_ISSIGNAN_S(SA) ||
  445. FP_ISSIGNAN_S(SB)))
  446. FP_SET_EXCEPTION (FP_EX_INVALID);
  447. break;
  448. case FCMPD:
  449. case FCMPED:
  450. FP_CMP_D(IR, DB, DA, 3);
  451. if (IR == 3 &&
  452. (((insn >> 5) & 0x1ff) == FCMPED ||
  453. FP_ISSIGNAN_D(DA) ||
  454. FP_ISSIGNAN_D(DB)))
  455. FP_SET_EXCEPTION (FP_EX_INVALID);
  456. break;
  457. case FCMPQ:
  458. case FCMPEQ:
  459. FP_CMP_Q(IR, QB, QA, 3);
  460. if (IR == 3 &&
  461. (((insn >> 5) & 0x1ff) == FCMPEQ ||
  462. FP_ISSIGNAN_Q(QA) ||
  463. FP_ISSIGNAN_Q(QB)))
  464. FP_SET_EXCEPTION (FP_EX_INVALID);
  465. }
  466. if (!FP_INHIBIT_RESULTS) {
  467. switch ((type >> 6) & 0x7) {
  468. case 0: fsr = *pfsr;
  469. if (IR == -1) IR = 2;
  470. /* fcc is always fcc0 */
  471. fsr &= ~0xc00; fsr |= (IR << 10);
  472. *pfsr = fsr;
  473. break;
  474. case 1: rd->s = IR; break;
  475. case 5: FP_PACK_SP (rd, SR); break;
  476. case 6: FP_PACK_DP (rd, DR); break;
  477. case 7: FP_PACK_QP (rd, QR); break;
  478. }
  479. }
  480. if (_fex == 0)
  481. return 1; /* success! */
  482. return record_exception(pfsr, _fex);
  483. }