do_conv.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * Sources of the "CONVERT" group instructions
  3. */
  4. /* $Id$ */
  5. #include <em_abs.h>
  6. #include "nofloat.h"
  7. #include "global.h"
  8. #include "log.h"
  9. #include "mem.h"
  10. #include "trap.h"
  11. #include "text.h"
  12. #include "fra.h"
  13. #include "warn.h"
  14. #ifndef NOFLOAT
  15. extern double fpop();
  16. #endif /* NOFLOAT */
  17. DoCII()
  18. {
  19. /* CII -: Convert integer to integer (*) */
  20. register int newsize = swpop();
  21. register long s;
  22. LOG(("@C6 DoCII()"));
  23. spoilFRA();
  24. switch ((int)(10 * swpop() + newsize)) {
  25. case 12:
  26. if (wsize == 4) {
  27. wtrap(WILLCONV, EILLINS);
  28. }
  29. npush(spop(1L), 2L);
  30. return;
  31. case 14:
  32. npush(spop(1L), 4L);
  33. return;
  34. case 22:
  35. if (wsize == 4) {
  36. wtrap(WILLCONV, EILLINS);
  37. }
  38. return;
  39. case 24:
  40. npush(spop(2L), 4L);
  41. return;
  42. case 42:
  43. if (wsize == 4) {
  44. wtrap(WILLCONV, EILLINS);
  45. }
  46. s = spop(4L);
  47. if (must_test && !(IgnMask&BIT(ECONV))) {
  48. if (s < I_MINS2 || s > I_MAXS2)
  49. trap(ECONV);
  50. }
  51. npush(s, 2L);
  52. return;
  53. case 44:
  54. return;
  55. default:
  56. wtrap(WILLCONV, EILLINS);
  57. }
  58. }
  59. DoCUI()
  60. {
  61. /* CUI -: Convert unsigned to integer (*) */
  62. register int newsize = swpop();
  63. register unsigned long u;
  64. LOG(("@C6 DoCUI()"));
  65. spoilFRA();
  66. switch ((int)(10 * swpop() + newsize)) {
  67. case 22:
  68. if (wsize == 4) {
  69. wtrap(WILLCONV, EILLINS);
  70. }
  71. u = upop(2L);
  72. if (must_test && !(IgnMask&BIT(ECONV))) {
  73. if (u > I_MAXS2)
  74. trap(ECONV);
  75. }
  76. npush((long) u, 2L);
  77. return;
  78. case 24:
  79. if (wsize == 4) {
  80. wtrap(WILLCONV, EILLINS);
  81. }
  82. npush((long) upop(2L), 4L);
  83. return;
  84. case 42:
  85. if (wsize == 4) {
  86. wtrap(WILLCONV, EILLINS);
  87. }
  88. u = upop(4L);
  89. if (must_test && !(IgnMask&BIT(ECONV))) {
  90. if (u > I_MAXS2)
  91. trap(ECONV);
  92. }
  93. npush((long) u, 2L);
  94. return;
  95. case 44:
  96. u = upop(4L);
  97. if (must_test && !(IgnMask&BIT(ECONV))) {
  98. if (u > I_MAXS4)
  99. trap(ECONV);
  100. }
  101. npush((long) u, 4L);
  102. return;
  103. default:
  104. wtrap(WILLCONV, EILLINS);
  105. }
  106. }
  107. DoCFI()
  108. {
  109. /* CFI -: Convert floating to integer (*) */
  110. #ifndef NOFLOAT
  111. register int newsize = swpop();
  112. double f;
  113. LOG(("@C6 DoCFI()"));
  114. spoilFRA();
  115. switch ((int)(10 * swpop() + newsize)) {
  116. case 42:
  117. if (wsize == 4) {
  118. wtrap(WILLCONV, EILLINS);
  119. }
  120. f = fpop(4L);
  121. if (must_test && !(IgnMask&BIT(ECONV))) {
  122. if (f <= (FL_MINS2 - 1.0) || f > FL_MAXS2)
  123. trap(ECONV);
  124. }
  125. npush((long) f, 2L);
  126. return;
  127. case 44:
  128. f = fpop(4L);
  129. if (must_test && !(IgnMask&BIT(ECONV))) {
  130. if (f <= (FL_MINS4 - 1.0) || f > FL_MAXS4)
  131. trap(ECONV);
  132. }
  133. npush((long) f, 4L);
  134. return;
  135. case 82:
  136. if (wsize == 4) {
  137. wtrap(WILLCONV, EILLINS);
  138. }
  139. f = fpop(8L);
  140. if (must_test && !(IgnMask&BIT(ECONV))) {
  141. if (f <= (FL_MINS2 - 1.0) || f > FL_MAXS2)
  142. trap(ECONV);
  143. }
  144. npush((long) f, 2L);
  145. return;
  146. case 84:
  147. f = fpop(8L);
  148. if (must_test && !(IgnMask&BIT(ECONV))) {
  149. if (f <= (FL_MINS4 - 1.0) || f > FL_MAXS4)
  150. trap(ECONV);
  151. }
  152. npush((long) f, 4L);
  153. return;
  154. default:
  155. wtrap(WILLCONV, EILLINS);
  156. }
  157. #else /* NOFLOAT */
  158. nofloat();
  159. #endif /* NOFLOAT */
  160. }
  161. DoCIF()
  162. {
  163. /* CIF -: Convert integer to floating (*) */
  164. #ifndef NOFLOAT
  165. register int newsize = swpop();
  166. LOG(("@C6 DoCIF()"));
  167. spoilFRA();
  168. switch ((int)(10 * swpop() + newsize)) {
  169. case 24:
  170. if (wsize == 4) {
  171. wtrap(WILLCONV, EILLINS);
  172. }
  173. fpush((double) spop(2L), 4L);
  174. return;
  175. case 28:
  176. if (wsize == 4) {
  177. wtrap(WILLCONV, EILLINS);
  178. }
  179. fpush((double) spop(2L), 8L);
  180. return;
  181. case 44:
  182. fpush((double) spop(4L), 4L);
  183. return;
  184. case 48:
  185. fpush((double) spop(4L), 8L);
  186. return;
  187. default:
  188. wtrap(WILLCONV, EILLINS);
  189. }
  190. #else /* NOFLOAT */
  191. nofloat();
  192. #endif /* NOFLOAT */
  193. }
  194. DoCUF()
  195. {
  196. /* CUF -: Convert unsigned to floating (*) */
  197. #ifndef NOFLOAT
  198. register int newsize = swpop();
  199. register unsigned long u;
  200. LOG(("@C6 DoCUF()"));
  201. spoilFRA();
  202. switch ((int)(10 * swpop() + newsize)) {
  203. case 24:
  204. if (wsize == 4) {
  205. wtrap(WILLCONV, EILLINS);
  206. }
  207. fpush((double) upop(2L), 4L);
  208. return;
  209. case 28:
  210. if (wsize == 4) {
  211. wtrap(WILLCONV, EILLINS);
  212. }
  213. fpush((double) upop(2L), 8L);
  214. return;
  215. case 44:
  216. if ((u = upop(4L)) > I_MAXS4) {
  217. u -= I_MAXS4;
  218. u -= 1;
  219. fpush(((double) u) - (double)(-I_MAXS4-1), 4L);
  220. }
  221. else fpush((double) u, 4L);
  222. return;
  223. case 48:
  224. if ((u = upop(4L)) > I_MAXS4) {
  225. u -= I_MAXS4;
  226. u -= 1;
  227. fpush(((double) u) - (double)(-I_MAXS4-1), 8L);
  228. }
  229. else fpush((double) u, 8L);
  230. return;
  231. default:
  232. wtrap(WILLCONV, EILLINS);
  233. }
  234. #else /* NOFLOAT */
  235. nofloat();
  236. #endif /* NOFLOAT */
  237. }
  238. DoCFF()
  239. {
  240. /* CFF -: Convert floating to floating (*) */
  241. #ifndef NOFLOAT
  242. register int newsize = swpop();
  243. LOG(("@C6 DoCFF()"));
  244. spoilFRA();
  245. switch ((int)(10 * swpop() + newsize)) {
  246. case 44:
  247. return;
  248. case 48:
  249. fpush(fpop(4L), 8L);
  250. return;
  251. case 88:
  252. return;
  253. case 84:
  254. fpush(fpop(8L), 4L);
  255. return;
  256. default:
  257. wtrap(WILLCONV, EILLINS);
  258. }
  259. #else /* NOFLOAT */
  260. nofloat();
  261. #endif /* NOFLOAT */
  262. }
  263. DoCIU()
  264. {
  265. /* CIU -: Convert integer to unsigned */
  266. register int newsize = swpop();
  267. register long u;
  268. LOG(("@C6 DoCIU()"));
  269. spoilFRA();
  270. switch ((int)(10 * swpop() + newsize)) {
  271. case 22:
  272. if (wsize == 4) {
  273. wtrap(WILLCONV, EILLINS);
  274. }
  275. return;
  276. case 24:
  277. if (wsize == 4) {
  278. wtrap(WILLCONV, EILLINS);
  279. }
  280. npush((long) upop(2L), 4L);
  281. return;
  282. case 42:
  283. if (wsize == 4) {
  284. wtrap(WILLCONV, EILLINS);
  285. }
  286. u = upop(4L);
  287. npush(u, 2L);
  288. return;
  289. case 44:
  290. return;
  291. default:
  292. wtrap(WILLCONV, EILLINS);
  293. }
  294. }
  295. DoCUU()
  296. {
  297. /* CUU -: Convert unsigned to unsigned */
  298. register int newsize = swpop();
  299. LOG(("@C6 DoCUU()"));
  300. spoilFRA();
  301. switch ((int)(10 * swpop() + newsize)) {
  302. case 22:
  303. if (wsize == 4) {
  304. wtrap(WILLCONV, EILLINS);
  305. }
  306. return;
  307. case 24:
  308. if (wsize == 4) {
  309. wtrap(WILLCONV, EILLINS);
  310. }
  311. npush((long) upop(2L), 4L);
  312. return;
  313. case 42:
  314. if (wsize == 4) {
  315. wtrap(WILLCONV, EILLINS);
  316. }
  317. npush((long) upop(4L), 2L);
  318. return;
  319. case 44:
  320. return;
  321. default:
  322. wtrap(WILLCONV, EILLINS);
  323. }
  324. }
  325. DoCFU()
  326. {
  327. /* CFU -: Convert floating to unsigned */
  328. #ifndef NOFLOAT
  329. register int newsize = swpop();
  330. double f;
  331. LOG(("@C6 DoCFU()"));
  332. spoilFRA();
  333. switch ((int)(10 * swpop() + newsize)) {
  334. case 42:
  335. if (wsize == 4) {
  336. wtrap(WILLCONV, EILLINS);
  337. }
  338. f = fpop(4L);
  339. npush((unsigned long) f, 2L);
  340. return;
  341. case 44:
  342. f = fpop(4L);
  343. npush((unsigned long) f, 4L);
  344. return;
  345. case 82:
  346. if (wsize == 4) {
  347. wtrap(WILLCONV, EILLINS);
  348. }
  349. f = fpop(8L);
  350. npush((unsigned long) f, 2L);
  351. return;
  352. case 84:
  353. f = fpop(8L);
  354. npush((unsigned long) f, 4L);
  355. return;
  356. default:
  357. wtrap(WILLCONV, EILLINS);
  358. }
  359. #else /* NOFLOAT */
  360. nofloat();
  361. #endif /* NOFLOAT */
  362. }