do_unsar.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Sources of the "UNSIGNED ARITHMETIC" group instructions
  3. */
  4. /* $Id$ */
  5. #include <em_abs.h>
  6. #include "logging.h"
  7. #include "global.h"
  8. #include "log.h"
  9. #include "mem.h"
  10. #include "trap.h"
  11. #include "warn.h"
  12. #include "text.h"
  13. #include "fra.h"
  14. /************************************************************************
  15. * No checking is performed, except for division by zero. *
  16. * The operands popped from the stack are put in unsigned *
  17. * longs. Now the required operation can be performed *
  18. * immediately. Whether the wordsize is two or four bytes *
  19. * doesn't matter. Alas, arithmetic is performed modulo *
  20. * the highest unsigned number for the given size plus 1. *
  21. ************************************************************************/
  22. #ifdef LOGGING
  23. extern int must_test;
  24. #endif /* LOGGING */
  25. #define adu(w1,w2) (unsigned long)(w1 + w2)
  26. #define sbu(w1,w2) (unsigned long)(w1 - w2)
  27. #define mlu(w1,w2) (unsigned long)(w1 * w2)
  28. PRIVATE unsigned long dvu(), rmu(), slu(), sru();
  29. DoADU(l)
  30. register size l;
  31. {
  32. /* ADU w: Addition */
  33. register unsigned long t = upop(arg_wi(l));
  34. LOG(("@U6 DoADU(%ld)", l));
  35. spoilFRA();
  36. npush((long) adu(upop(l), t), l);
  37. }
  38. DoSBU(l)
  39. register size l;
  40. {
  41. /* SBU w: Subtraction */
  42. register unsigned long t = upop(arg_wi(l));
  43. LOG(("@U6 DoSBU(%ld)", l));
  44. spoilFRA();
  45. npush((long) sbu(upop(l), t), l);
  46. }
  47. DoMLU(l)
  48. register size l;
  49. {
  50. /* MLU w: Multiplication */
  51. register unsigned long t = upop(arg_wi(l));
  52. LOG(("@U6 DoMLU(%ld)", l));
  53. spoilFRA();
  54. npush((long) mlu(upop(l), t), l);
  55. }
  56. DoDVU(l)
  57. register size l;
  58. {
  59. /* DVU w: Division */
  60. register unsigned long t = upop(arg_wi(l));
  61. LOG(("@U6 DoDVU(%ld)", l));
  62. spoilFRA();
  63. npush((long) dvu(upop(l), t), l);
  64. }
  65. DoRMU(l)
  66. register size l;
  67. {
  68. /* RMU w: Remainder */
  69. register unsigned long t = upop(arg_wi(l));
  70. LOG(("@U6 DoRMU(%ld)", l));
  71. spoilFRA();
  72. npush((long) rmu(upop(l), t), l);
  73. }
  74. DoSLU(l)
  75. register size l;
  76. {
  77. /* SLU w: Shift left */
  78. register unsigned long t = uwpop();
  79. LOG(("@U6 DoSLU(%ld)", l));
  80. spoilFRA();
  81. l = arg_wi(l);
  82. npush((long) slu(upop(l), t, l), l);
  83. }
  84. DoSRU(l)
  85. register size l;
  86. {
  87. /* SRU w: Shift right */
  88. register unsigned long t = uwpop();
  89. LOG(("@U6 DoSRU(%ld)", l));
  90. spoilFRA();
  91. l = arg_wi(l);
  92. npush((long) sru(upop(l), t, l), l);
  93. }
  94. PRIVATE unsigned long dvu(w1, w2)
  95. unsigned long w1, w2;
  96. {
  97. if (w2 == 0) {
  98. if (!(IgnMask&BIT(EIDIVZ))) {
  99. trap(EIDIVZ);
  100. }
  101. else return (0L);
  102. }
  103. return (w1 / w2);
  104. }
  105. PRIVATE unsigned long rmu(w1, w2)
  106. unsigned long w1, w2;
  107. {
  108. if (w2 == 0) {
  109. if (!(IgnMask&BIT(EIDIVZ))) {
  110. trap(EIDIVZ);
  111. }
  112. else return (0L);
  113. }
  114. return (w1 % w2);
  115. }
  116. /*ARGSUSED*/
  117. PRIVATE unsigned long slu(w1, w2, nbytes) /* w1 << w2 */
  118. unsigned long w1, w2;
  119. size nbytes;
  120. {
  121. #ifdef LOGGING
  122. if (must_test) {
  123. /* check shift distance */
  124. if (w2 >= nbytes*8) {
  125. warning(WSHLARGE);
  126. w2 = nbytes*8 - 1;
  127. }
  128. }
  129. #endif /* LOGGING */
  130. /* calculate result */
  131. return (w1 << w2);
  132. }
  133. /*ARGSUSED*/
  134. PRIVATE unsigned long sru(w1, w2, nbytes) /* w1 >> w2 */
  135. unsigned long w1, w2;
  136. size nbytes;
  137. {
  138. #ifdef LOGGING
  139. if (must_test) {
  140. /* check shift distance */
  141. if (w2 >= nbytes*8) {
  142. warning(WSHLARGE);
  143. w2 = nbytes*8 - 1;
  144. }
  145. }
  146. #endif /* LOGGING */
  147. /* calculate result */
  148. return (w1 >> w2);
  149. }