fpa11_cpdo.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. (c) Philip Blundell, 2001
  5. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/config.h>
  19. #include "fpa11.h"
  20. #include "fpopcode.h"
  21. unsigned int SingleCPDO(const unsigned int opcode, FPREG * rFd);
  22. unsigned int DoubleCPDO(const unsigned int opcode, FPREG * rFd);
  23. unsigned int ExtendedCPDO(const unsigned int opcode, FPREG * rFd);
  24. unsigned int EmulateCPDO(const unsigned int opcode)
  25. {
  26. FPA11 *fpa11 = GET_FPA11();
  27. FPREG *rFd;
  28. unsigned int nType, nDest, nRc;
  29. /* Get the destination size. If not valid let Linux perform
  30. an invalid instruction trap. */
  31. nDest = getDestinationSize(opcode);
  32. if (typeNone == nDest)
  33. return 0;
  34. SetRoundingMode(opcode);
  35. /* Compare the size of the operands in Fn and Fm.
  36. Choose the largest size and perform operations in that size,
  37. in order to make use of all the precision of the operands.
  38. If Fm is a constant, we just grab a constant of a size
  39. matching the size of the operand in Fn. */
  40. if (MONADIC_INSTRUCTION(opcode))
  41. nType = nDest;
  42. else
  43. nType = fpa11->fType[getFn(opcode)];
  44. if (!CONSTANT_FM(opcode)) {
  45. register unsigned int Fm = getFm(opcode);
  46. if (nType < fpa11->fType[Fm]) {
  47. nType = fpa11->fType[Fm];
  48. }
  49. }
  50. rFd = &fpa11->fpreg[getFd(opcode)];
  51. switch (nType) {
  52. case typeSingle:
  53. nRc = SingleCPDO(opcode, rFd);
  54. break;
  55. case typeDouble:
  56. nRc = DoubleCPDO(opcode, rFd);
  57. break;
  58. #ifdef CONFIG_FPE_NWFPE_XP
  59. case typeExtended:
  60. nRc = ExtendedCPDO(opcode, rFd);
  61. break;
  62. #endif
  63. default:
  64. nRc = 0;
  65. }
  66. /* The CPDO functions used to always set the destination type
  67. to be the same as their working size. */
  68. if (nRc != 0) {
  69. /* If the operation succeeded, check to see if the result in the
  70. destination register is the correct size. If not force it
  71. to be. */
  72. fpa11->fType[getFd(opcode)] = nDest;
  73. #ifdef CONFIG_FPE_NWFPE_XP
  74. if (nDest != nType) {
  75. switch (nDest) {
  76. case typeSingle:
  77. {
  78. if (typeDouble == nType)
  79. rFd->fSingle = float64_to_float32(rFd->fDouble);
  80. else
  81. rFd->fSingle = floatx80_to_float32(rFd->fExtended);
  82. }
  83. break;
  84. case typeDouble:
  85. {
  86. if (typeSingle == nType)
  87. rFd->fDouble = float32_to_float64(rFd->fSingle);
  88. else
  89. rFd->fDouble = floatx80_to_float64(rFd->fExtended);
  90. }
  91. break;
  92. case typeExtended:
  93. {
  94. if (typeSingle == nType)
  95. rFd->fExtended = float32_to_floatx80(rFd->fSingle);
  96. else
  97. rFd->fExtended = float64_to_floatx80(rFd->fDouble);
  98. }
  99. break;
  100. }
  101. }
  102. #else
  103. if (nDest != nType) {
  104. if (nDest == typeSingle)
  105. rFd->fSingle = float64_to_float32(rFd->fDouble);
  106. else
  107. rFd->fDouble = float32_to_float64(rFd->fSingle);
  108. }
  109. #endif
  110. }
  111. return nRc;
  112. }