double_cpdo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. union float64_components {
  21. float64 f64;
  22. unsigned int i[2];
  23. };
  24. float64 float64_exp(float64 Fm);
  25. float64 float64_ln(float64 Fm);
  26. float64 float64_sin(float64 rFm);
  27. float64 float64_cos(float64 rFm);
  28. float64 float64_arcsin(float64 rFm);
  29. float64 float64_arctan(float64 rFm);
  30. float64 float64_log(float64 rFm);
  31. float64 float64_tan(float64 rFm);
  32. float64 float64_arccos(float64 rFm);
  33. float64 float64_pow(float64 rFn, float64 rFm);
  34. float64 float64_pol(float64 rFn, float64 rFm);
  35. static float64 float64_rsf(struct roundingData *roundData, float64 rFn, float64 rFm)
  36. {
  37. return float64_sub(roundData, rFm, rFn);
  38. }
  39. static float64 float64_rdv(struct roundingData *roundData, float64 rFn, float64 rFm)
  40. {
  41. return float64_div(roundData, rFm, rFn);
  42. }
  43. static float64 (*const dyadic_double[16])(struct roundingData*, float64 rFn, float64 rFm) = {
  44. [ADF_CODE >> 20] = float64_add,
  45. [MUF_CODE >> 20] = float64_mul,
  46. [SUF_CODE >> 20] = float64_sub,
  47. [RSF_CODE >> 20] = float64_rsf,
  48. [DVF_CODE >> 20] = float64_div,
  49. [RDF_CODE >> 20] = float64_rdv,
  50. [RMF_CODE >> 20] = float64_rem,
  51. /* strictly, these opcodes should not be implemented */
  52. [FML_CODE >> 20] = float64_mul,
  53. [FDV_CODE >> 20] = float64_div,
  54. [FRD_CODE >> 20] = float64_rdv,
  55. };
  56. static float64 float64_mvf(struct roundingData *roundData,float64 rFm)
  57. {
  58. return rFm;
  59. }
  60. static float64 float64_mnf(struct roundingData *roundData,float64 rFm)
  61. {
  62. union float64_components u;
  63. u.f64 = rFm;
  64. #ifdef __ARMEB__
  65. u.i[0] ^= 0x80000000;
  66. #else
  67. u.i[1] ^= 0x80000000;
  68. #endif
  69. return u.f64;
  70. }
  71. static float64 float64_abs(struct roundingData *roundData,float64 rFm)
  72. {
  73. union float64_components u;
  74. u.f64 = rFm;
  75. #ifdef __ARMEB__
  76. u.i[0] &= 0x7fffffff;
  77. #else
  78. u.i[1] &= 0x7fffffff;
  79. #endif
  80. return u.f64;
  81. }
  82. static float64 (*const monadic_double[16])(struct roundingData *, float64 rFm) = {
  83. [MVF_CODE >> 20] = float64_mvf,
  84. [MNF_CODE >> 20] = float64_mnf,
  85. [ABS_CODE >> 20] = float64_abs,
  86. [RND_CODE >> 20] = float64_round_to_int,
  87. [URD_CODE >> 20] = float64_round_to_int,
  88. [SQT_CODE >> 20] = float64_sqrt,
  89. [NRM_CODE >> 20] = float64_mvf,
  90. };
  91. unsigned int DoubleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
  92. {
  93. FPA11 *fpa11 = GET_FPA11();
  94. float64 rFm;
  95. unsigned int Fm, opc_mask_shift;
  96. Fm = getFm(opcode);
  97. if (CONSTANT_FM(opcode)) {
  98. rFm = getDoubleConstant(Fm);
  99. } else {
  100. switch (fpa11->fType[Fm]) {
  101. case typeSingle:
  102. rFm = float32_to_float64(fpa11->fpreg[Fm].fSingle);
  103. break;
  104. case typeDouble:
  105. rFm = fpa11->fpreg[Fm].fDouble;
  106. break;
  107. default:
  108. return 0;
  109. }
  110. }
  111. opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
  112. if (!MONADIC_INSTRUCTION(opcode)) {
  113. unsigned int Fn = getFn(opcode);
  114. float64 rFn;
  115. switch (fpa11->fType[Fn]) {
  116. case typeSingle:
  117. rFn = float32_to_float64(fpa11->fpreg[Fn].fSingle);
  118. break;
  119. case typeDouble:
  120. rFn = fpa11->fpreg[Fn].fDouble;
  121. break;
  122. default:
  123. return 0;
  124. }
  125. if (dyadic_double[opc_mask_shift]) {
  126. rFd->fDouble = dyadic_double[opc_mask_shift](roundData, rFn, rFm);
  127. } else {
  128. return 0;
  129. }
  130. } else {
  131. if (monadic_double[opc_mask_shift]) {
  132. rFd->fDouble = monadic_double[opc_mask_shift](roundData, rFm);
  133. } else {
  134. return 0;
  135. }
  136. }
  137. return 1;
  138. }