extended_cpdo.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. NetWinder Floating Point Emulator
  4. (c) Rebel.COM, 1998,1999
  5. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  6. */
  7. #include "fpa11.h"
  8. #include "softfloat.h"
  9. #include "fpopcode.h"
  10. floatx80 floatx80_exp(floatx80 Fm);
  11. floatx80 floatx80_ln(floatx80 Fm);
  12. floatx80 floatx80_sin(floatx80 rFm);
  13. floatx80 floatx80_cos(floatx80 rFm);
  14. floatx80 floatx80_arcsin(floatx80 rFm);
  15. floatx80 floatx80_arctan(floatx80 rFm);
  16. floatx80 floatx80_log(floatx80 rFm);
  17. floatx80 floatx80_tan(floatx80 rFm);
  18. floatx80 floatx80_arccos(floatx80 rFm);
  19. floatx80 floatx80_pow(floatx80 rFn, floatx80 rFm);
  20. floatx80 floatx80_pol(floatx80 rFn, floatx80 rFm);
  21. static floatx80 floatx80_rsf(struct roundingData *roundData, floatx80 rFn, floatx80 rFm)
  22. {
  23. return floatx80_sub(roundData, rFm, rFn);
  24. }
  25. static floatx80 floatx80_rdv(struct roundingData *roundData, floatx80 rFn, floatx80 rFm)
  26. {
  27. return floatx80_div(roundData, rFm, rFn);
  28. }
  29. static floatx80 (*const dyadic_extended[16])(struct roundingData*, floatx80 rFn, floatx80 rFm) = {
  30. [ADF_CODE >> 20] = floatx80_add,
  31. [MUF_CODE >> 20] = floatx80_mul,
  32. [SUF_CODE >> 20] = floatx80_sub,
  33. [RSF_CODE >> 20] = floatx80_rsf,
  34. [DVF_CODE >> 20] = floatx80_div,
  35. [RDF_CODE >> 20] = floatx80_rdv,
  36. [RMF_CODE >> 20] = floatx80_rem,
  37. /* strictly, these opcodes should not be implemented */
  38. [FML_CODE >> 20] = floatx80_mul,
  39. [FDV_CODE >> 20] = floatx80_div,
  40. [FRD_CODE >> 20] = floatx80_rdv,
  41. };
  42. static floatx80 floatx80_mvf(struct roundingData *roundData, floatx80 rFm)
  43. {
  44. return rFm;
  45. }
  46. static floatx80 floatx80_mnf(struct roundingData *roundData, floatx80 rFm)
  47. {
  48. rFm.high ^= 0x8000;
  49. return rFm;
  50. }
  51. static floatx80 floatx80_abs(struct roundingData *roundData, floatx80 rFm)
  52. {
  53. rFm.high &= 0x7fff;
  54. return rFm;
  55. }
  56. static floatx80 (*const monadic_extended[16])(struct roundingData*, floatx80 rFm) = {
  57. [MVF_CODE >> 20] = floatx80_mvf,
  58. [MNF_CODE >> 20] = floatx80_mnf,
  59. [ABS_CODE >> 20] = floatx80_abs,
  60. [RND_CODE >> 20] = floatx80_round_to_int,
  61. [URD_CODE >> 20] = floatx80_round_to_int,
  62. [SQT_CODE >> 20] = floatx80_sqrt,
  63. [NRM_CODE >> 20] = floatx80_mvf,
  64. };
  65. unsigned int ExtendedCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
  66. {
  67. FPA11 *fpa11 = GET_FPA11();
  68. floatx80 rFm;
  69. unsigned int Fm, opc_mask_shift;
  70. Fm = getFm(opcode);
  71. if (CONSTANT_FM(opcode)) {
  72. rFm = getExtendedConstant(Fm);
  73. } else {
  74. switch (fpa11->fType[Fm]) {
  75. case typeSingle:
  76. rFm = float32_to_floatx80(fpa11->fpreg[Fm].fSingle);
  77. break;
  78. case typeDouble:
  79. rFm = float64_to_floatx80(fpa11->fpreg[Fm].fDouble);
  80. break;
  81. case typeExtended:
  82. rFm = fpa11->fpreg[Fm].fExtended;
  83. break;
  84. default:
  85. return 0;
  86. }
  87. }
  88. opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
  89. if (!MONADIC_INSTRUCTION(opcode)) {
  90. unsigned int Fn = getFn(opcode);
  91. floatx80 rFn;
  92. switch (fpa11->fType[Fn]) {
  93. case typeSingle:
  94. rFn = float32_to_floatx80(fpa11->fpreg[Fn].fSingle);
  95. break;
  96. case typeDouble:
  97. rFn = float64_to_floatx80(fpa11->fpreg[Fn].fDouble);
  98. break;
  99. case typeExtended:
  100. rFn = fpa11->fpreg[Fn].fExtended;
  101. break;
  102. default:
  103. return 0;
  104. }
  105. if (dyadic_extended[opc_mask_shift]) {
  106. rFd->fExtended = dyadic_extended[opc_mask_shift](roundData, rFn, rFm);
  107. } else {
  108. return 0;
  109. }
  110. } else {
  111. if (monadic_extended[opc_mask_shift]) {
  112. rFd->fExtended = monadic_extended[opc_mask_shift](roundData, rFm);
  113. } else {
  114. return 0;
  115. }
  116. }
  117. return 1;
  118. }