fpa11_cpdo.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. NetWinder Floating Point Emulator
  4. (c) Rebel.COM, 1998,1999
  5. (c) Philip Blundell, 2001
  6. Direct questions, comments to Scott Bambrough <[email protected]>
  7. */
  8. #include "fpa11.h"
  9. #include "fpopcode.h"
  10. unsigned int SingleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
  11. unsigned int DoubleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
  12. unsigned int ExtendedCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
  13. unsigned int EmulateCPDO(const unsigned int opcode)
  14. {
  15. FPA11 *fpa11 = GET_FPA11();
  16. FPREG *rFd;
  17. unsigned int nType, nDest, nRc;
  18. struct roundingData roundData;
  19. /* Get the destination size. If not valid let Linux perform
  20. an invalid instruction trap. */
  21. nDest = getDestinationSize(opcode);
  22. if (typeNone == nDest)
  23. return 0;
  24. roundData.mode = SetRoundingMode(opcode);
  25. roundData.precision = SetRoundingPrecision(opcode);
  26. roundData.exception = 0;
  27. /* Compare the size of the operands in Fn and Fm.
  28. Choose the largest size and perform operations in that size,
  29. in order to make use of all the precision of the operands.
  30. If Fm is a constant, we just grab a constant of a size
  31. matching the size of the operand in Fn. */
  32. if (MONADIC_INSTRUCTION(opcode))
  33. nType = nDest;
  34. else
  35. nType = fpa11->fType[getFn(opcode)];
  36. if (!CONSTANT_FM(opcode)) {
  37. register unsigned int Fm = getFm(opcode);
  38. if (nType < fpa11->fType[Fm]) {
  39. nType = fpa11->fType[Fm];
  40. }
  41. }
  42. rFd = &fpa11->fpreg[getFd(opcode)];
  43. switch (nType) {
  44. case typeSingle:
  45. nRc = SingleCPDO(&roundData, opcode, rFd);
  46. break;
  47. case typeDouble:
  48. nRc = DoubleCPDO(&roundData, opcode, rFd);
  49. break;
  50. #ifdef CONFIG_FPE_NWFPE_XP
  51. case typeExtended:
  52. nRc = ExtendedCPDO(&roundData, opcode, rFd);
  53. break;
  54. #endif
  55. default:
  56. nRc = 0;
  57. }
  58. /* The CPDO functions used to always set the destination type
  59. to be the same as their working size. */
  60. if (nRc != 0) {
  61. /* If the operation succeeded, check to see if the result in the
  62. destination register is the correct size. If not force it
  63. to be. */
  64. fpa11->fType[getFd(opcode)] = nDest;
  65. #ifdef CONFIG_FPE_NWFPE_XP
  66. if (nDest != nType) {
  67. switch (nDest) {
  68. case typeSingle:
  69. {
  70. if (typeDouble == nType)
  71. rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
  72. else
  73. rFd->fSingle = floatx80_to_float32(&roundData, rFd->fExtended);
  74. }
  75. break;
  76. case typeDouble:
  77. {
  78. if (typeSingle == nType)
  79. rFd->fDouble = float32_to_float64(rFd->fSingle);
  80. else
  81. rFd->fDouble = floatx80_to_float64(&roundData, rFd->fExtended);
  82. }
  83. break;
  84. case typeExtended:
  85. {
  86. if (typeSingle == nType)
  87. rFd->fExtended = float32_to_floatx80(rFd->fSingle);
  88. else
  89. rFd->fExtended = float64_to_floatx80(rFd->fDouble);
  90. }
  91. break;
  92. }
  93. }
  94. #else
  95. if (nDest != nType) {
  96. if (nDest == typeSingle)
  97. rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
  98. else
  99. rFd->fDouble = float32_to_float64(rFd->fSingle);
  100. }
  101. #endif
  102. }
  103. if (roundData.exception)
  104. float_raise(roundData.exception);
  105. return nRc;
  106. }