single_cpdo.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "fpa11.h"
  19. #include "softfloat.h"
  20. #include "fpopcode.h"
  21. float32 float32_exp(float32 Fm);
  22. float32 float32_ln(float32 Fm);
  23. float32 float32_sin(float32 rFm);
  24. float32 float32_cos(float32 rFm);
  25. float32 float32_arcsin(float32 rFm);
  26. float32 float32_arctan(float32 rFm);
  27. float32 float32_log(float32 rFm);
  28. float32 float32_tan(float32 rFm);
  29. float32 float32_arccos(float32 rFm);
  30. float32 float32_pow(float32 rFn, float32 rFm);
  31. float32 float32_pol(float32 rFn, float32 rFm);
  32. static float32 float32_rsf(struct roundingData *roundData, float32 rFn, float32 rFm)
  33. {
  34. return float32_sub(roundData, rFm, rFn);
  35. }
  36. static float32 float32_rdv(struct roundingData *roundData, float32 rFn, float32 rFm)
  37. {
  38. return float32_div(roundData, rFm, rFn);
  39. }
  40. static float32 (*const dyadic_single[16])(struct roundingData *, float32 rFn, float32 rFm) = {
  41. [ADF_CODE >> 20] = float32_add,
  42. [MUF_CODE >> 20] = float32_mul,
  43. [SUF_CODE >> 20] = float32_sub,
  44. [RSF_CODE >> 20] = float32_rsf,
  45. [DVF_CODE >> 20] = float32_div,
  46. [RDF_CODE >> 20] = float32_rdv,
  47. [RMF_CODE >> 20] = float32_rem,
  48. [FML_CODE >> 20] = float32_mul,
  49. [FDV_CODE >> 20] = float32_div,
  50. [FRD_CODE >> 20] = float32_rdv,
  51. };
  52. static float32 float32_mvf(struct roundingData *roundData, float32 rFm)
  53. {
  54. return rFm;
  55. }
  56. static float32 float32_mnf(struct roundingData *roundData, float32 rFm)
  57. {
  58. return rFm ^ 0x80000000;
  59. }
  60. static float32 float32_abs(struct roundingData *roundData, float32 rFm)
  61. {
  62. return rFm & 0x7fffffff;
  63. }
  64. static float32 (*const monadic_single[16])(struct roundingData*, float32 rFm) = {
  65. [MVF_CODE >> 20] = float32_mvf,
  66. [MNF_CODE >> 20] = float32_mnf,
  67. [ABS_CODE >> 20] = float32_abs,
  68. [RND_CODE >> 20] = float32_round_to_int,
  69. [URD_CODE >> 20] = float32_round_to_int,
  70. [SQT_CODE >> 20] = float32_sqrt,
  71. [NRM_CODE >> 20] = float32_mvf,
  72. };
  73. unsigned int SingleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd)
  74. {
  75. FPA11 *fpa11 = GET_FPA11();
  76. float32 rFm;
  77. unsigned int Fm, opc_mask_shift;
  78. Fm = getFm(opcode);
  79. if (CONSTANT_FM(opcode)) {
  80. rFm = getSingleConstant(Fm);
  81. } else if (fpa11->fType[Fm] == typeSingle) {
  82. rFm = fpa11->fpreg[Fm].fSingle;
  83. } else {
  84. return 0;
  85. }
  86. opc_mask_shift = (opcode & MASK_ARITHMETIC_OPCODE) >> 20;
  87. if (!MONADIC_INSTRUCTION(opcode)) {
  88. unsigned int Fn = getFn(opcode);
  89. float32 rFn;
  90. if (fpa11->fType[Fn] == typeSingle &&
  91. dyadic_single[opc_mask_shift]) {
  92. rFn = fpa11->fpreg[Fn].fSingle;
  93. rFd->fSingle = dyadic_single[opc_mask_shift](roundData, rFn, rFm);
  94. } else {
  95. return 0;
  96. }
  97. } else {
  98. if (monadic_single[opc_mask_shift]) {
  99. rFd->fSingle = monadic_single[opc_mask_shift](roundData, rFm);
  100. } else {
  101. return 0;
  102. }
  103. }
  104. return 1;
  105. }