extended_cpdo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include "fpa11.h"
  18. #include "softfloat.h"
  19. #include "fpopcode.h"
  20. floatx80 floatx80_exp(floatx80 Fm);
  21. floatx80 floatx80_ln(floatx80 Fm);
  22. floatx80 floatx80_sin(floatx80 rFm);
  23. floatx80 floatx80_cos(floatx80 rFm);
  24. floatx80 floatx80_arcsin(floatx80 rFm);
  25. floatx80 floatx80_arctan(floatx80 rFm);
  26. floatx80 floatx80_log(floatx80 rFm);
  27. floatx80 floatx80_tan(floatx80 rFm);
  28. floatx80 floatx80_arccos(floatx80 rFm);
  29. floatx80 floatx80_pow(floatx80 rFn, floatx80 rFm);
  30. floatx80 floatx80_pol(floatx80 rFn, floatx80 rFm);
  31. static floatx80 floatx80_rsf(struct roundingData *roundData, floatx80 rFn, floatx80 rFm)
  32. {
  33. return floatx80_sub(roundData, rFm, rFn);
  34. }
  35. static floatx80 floatx80_rdv(struct roundingData *roundData, floatx80 rFn, floatx80 rFm)
  36. {
  37. return floatx80_div(roundData, rFm, rFn);
  38. }
  39. static floatx80 (*const dyadic_extended[16])(struct roundingData*, floatx80 rFn, floatx80 rFm) = {
  40. [ADF_CODE >> 20] = floatx80_add,
  41. [MUF_CODE >> 20] = floatx80_mul,
  42. [SUF_CODE >> 20] = floatx80_sub,
  43. [RSF_CODE >> 20] = floatx80_rsf,
  44. [DVF_CODE >> 20] = floatx80_div,
  45. [RDF_CODE >> 20] = floatx80_rdv,
  46. [RMF_CODE >> 20] = floatx80_rem,
  47. /* strictly, these opcodes should not be implemented */
  48. [FML_CODE >> 20] = floatx80_mul,
  49. [FDV_CODE >> 20] = floatx80_div,
  50. [FRD_CODE >> 20] = floatx80_rdv,
  51. };
  52. static floatx80 floatx80_mvf(struct roundingData *roundData, floatx80 rFm)
  53. {
  54. return rFm;
  55. }
  56. static floatx80 floatx80_mnf(struct roundingData *roundData, floatx80 rFm)
  57. {
  58. rFm.high ^= 0x8000;
  59. return rFm;
  60. }
  61. static floatx80 floatx80_abs(struct roundingData *roundData, floatx80 rFm)
  62. {
  63. rFm.high &= 0x7fff;
  64. return rFm;
  65. }
  66. static floatx80 (*const monadic_extended[16])(struct roundingData*, floatx80 rFm) = {
  67. [MVF_CODE >> 20] = floatx80_mvf,
  68. [MNF_CODE >> 20] = floatx80_mnf,
  69. [ABS_CODE >> 20] = floatx80_abs,
  70. [RND_CODE >> 20] = floatx80_round_to_int,
  71. [URD_CODE >> 20] = floatx80_round_to_int,
  72. [SQT_CODE >> 20] = floatx80_sqrt,
  73. [NRM_CODE >> 20] = floatx80_mvf,
  74. };
  75. unsigned int ExtendedCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
  76. {
  77. FPA11 *fpa11 = GET_FPA11();
  78. floatx80 rFm;
  79. unsigned int Fm, opc_mask_shift;
  80. Fm = getFm(opcode);
  81. if (CONSTANT_FM(opcode)) {
  82. rFm = getExtendedConstant(Fm);
  83. } else {
  84. switch (fpa11->fType[Fm]) {
  85. case typeSingle:
  86. rFm = float32_to_floatx80(fpa11->fpreg[Fm].fSingle);
  87. break;
  88. case typeDouble:
  89. rFm = float64_to_floatx80(fpa11->fpreg[Fm].fDouble);
  90. break;
  91. case typeExtended:
  92. rFm = fpa11->fpreg[Fm].fExtended;
  93. break;
  94. default:
  95. return 0;
  96. }
  97. }
  98. opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
  99. if (!MONADIC_INSTRUCTION(opcode)) {
  100. unsigned int Fn = getFn(opcode);
  101. floatx80 rFn;
  102. switch (fpa11->fType[Fn]) {
  103. case typeSingle:
  104. rFn = float32_to_floatx80(fpa11->fpreg[Fn].fSingle);
  105. break;
  106. case typeDouble:
  107. rFn = float64_to_floatx80(fpa11->fpreg[Fn].fDouble);
  108. break;
  109. case typeExtended:
  110. rFn = fpa11->fpreg[Fn].fExtended;
  111. break;
  112. default:
  113. return 0;
  114. }
  115. if (dyadic_extended[opc_mask_shift]) {
  116. rFd->fExtended = dyadic_extended[opc_mask_shift](roundData, rFn, rFm);
  117. } else {
  118. return 0;
  119. }
  120. } else {
  121. if (monadic_extended[opc_mask_shift]) {
  122. rFd->fExtended = monadic_extended[opc_mask_shift](roundData, rFm);
  123. } else {
  124. return 0;
  125. }
  126. }
  127. return 1;
  128. }