tmoddiv.pp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondmoddiv() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondtypeconv() }
  9. {****************************************************************}
  10. { DEFINES: }
  11. { FPC = Target is FreePascal compiler }
  12. {****************************************************************}
  13. { REMARKS: }
  14. { }
  15. { }
  16. { }
  17. {****************************************************************}
  18. { CURRENT NODE (result): }
  19. { LOC_REGISTER }
  20. { LEFT NODE (operand) (numerator) }
  21. { LOC_REFERENCE / LOC_MEM }
  22. { LOC_REGISTER / LOC_CREGISTER }
  23. { RIGHT NODE (operand (denominator) }
  24. { ord constant node }
  25. { LOC_REGISTER / LOC_CREGISTER }
  26. { LOC_REFERENCE / LOC_MEM }
  27. {$ifdef VER70}
  28. {$define TP}
  29. {$endif}
  30. function getlongcnt: longint;
  31. begin
  32. getlongcnt := -10;
  33. end;
  34. {$IFNDEF TP}
  35. function getcardinalcnt: cardinal;
  36. begin
  37. getcardinalcnt := 10;
  38. end;
  39. function getint64cnt: int64;
  40. begin
  41. getint64cnt := -10;
  42. end;
  43. {$ENDIF}
  44. procedure test(value, required: longint);
  45. begin
  46. if value <> required then
  47. begin
  48. writeln('Got ',value,' instead of ',required);
  49. halt(1);
  50. end
  51. else
  52. writeln('Passed!');
  53. end;
  54. var
  55. longres : longint;
  56. longcnt : longint;
  57. {$IFNDEF TP}
  58. cardinalres : cardinal;
  59. cardinalcnt : cardinal;
  60. int64res : int64;
  61. int64cnt : int64;
  62. {$ENDIF}
  63. begin
  64. WriteLn('------------------- LONGINT ------------------------');
  65. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  66. { RIGHT : power of 2 ordconstn }
  67. { LEFT : LOC_REFERENCE }
  68. longres := 24;
  69. longres := longres div 4;
  70. Write('Value should be 6...');
  71. test(longres, 6);
  72. { RIGHT : power of 2 ordconstn }
  73. { LEFT : LOC_REFERENCE }
  74. longres := 24;
  75. longres := longres mod 4;
  76. Write('Value should be 0...');
  77. test(longres, 0);
  78. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  79. { RIGHT : LOC_REFERENCE }
  80. { LEFT : LOC_REFERENCE }
  81. longres := 136;
  82. longcnt := -13;
  83. longres := longres div longcnt;
  84. Write('Value should be -10...');
  85. test(longres, -10);
  86. { RIGHT : LOC_REFERENCE }
  87. { LEFT : LOC_REFERENCE }
  88. longres := 10101010;
  89. longcnt := -13;
  90. longres := longres mod longcnt;
  91. Write('Value should be 10...');
  92. test(longres, 10);
  93. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  94. { RIGHT : LOC_REGISTER }
  95. { LEFT : LOC_REFERENCE }
  96. longres := -11111111;
  97. longres := longres div getlongcnt;
  98. Write('Value should be 1111111...');
  99. test(longres, 1111111);
  100. { RIGHT : LOC_REGISTER }
  101. { LEFT : LOC_REFERENCE }
  102. longres := -1111111;
  103. longres := longres mod getlongcnt;
  104. Write('Value should be -1...');
  105. test(longres, -1);
  106. { RIGHT : LOC_REFERENCE }
  107. { LEFT : LOC_REGISTER }
  108. longcnt := 2;
  109. longres := getlongcnt div longcnt;
  110. Write('Value should be -5...');
  111. test(longres, -5);
  112. { RIGHT : LOC_REFERENCE }
  113. { LEFT : LOC_REGISTER }
  114. longcnt := 3;
  115. longres := getlongcnt mod longcnt;
  116. Write('Value should be -1...');
  117. test(longres, -1);
  118. { special tests for results }
  119. Writeln('special numeric values tests...');
  120. longres := $7FFFFFFF;
  121. longcnt := $80000000;
  122. longres := longres div longcnt;
  123. Write('Value should be 0...');
  124. test(longres, 0);
  125. Writeln('special numeric values tests...');
  126. longres := $7FFFFFFF;
  127. longcnt := $80000000;
  128. longres := longcnt div longres;
  129. Write('Value should be -1...');
  130. test(longres, -1);
  131. Writeln('special numeric values tests...');
  132. cardinalcnt := $80000;
  133. cardinalres := $12345;
  134. cardinalres := cardinalcnt div cardinalres;
  135. Write('Value should be 7...');
  136. test(cardinalres, 7);
  137. {$IFNDEF TP}
  138. WriteLn('------------------- CARDINAL -----------------------');
  139. { special tests for results }
  140. Writeln('special numeric values tests...');
  141. cardinalres := $7FFFFFFF;
  142. cardinalcnt := $80000000;
  143. cardinalres := cardinalres div cardinalcnt;
  144. Write('Value should be 0...');
  145. test(cardinalres, 0);
  146. Writeln('special numeric values tests...');
  147. cardinalres := $7FFFFFFF;
  148. cardinalcnt := $80000000;
  149. cardinalres := cardinalcnt div cardinalres;
  150. Write('Value should be 1...');
  151. test(cardinalres, 1);
  152. Writeln('special numeric values tests...');
  153. cardinalcnt := $80000;
  154. cardinalres := $12345;
  155. cardinalres := cardinalcnt div cardinalres;
  156. test(cardinalres, 7);
  157. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  158. { RIGHT : power of 2 ordconstn }
  159. { LEFT : LOC_REFERENCE }
  160. cardinalres := 24;
  161. cardinalres := cardinalres div 4;
  162. Write('Value should be 6...');
  163. test(cardinalres, 6);
  164. { RIGHT : power of 2 ordconstn }
  165. { LEFT : LOC_REFERENCE }
  166. cardinalres := 24;
  167. cardinalres := cardinalres mod 4;
  168. Write('Value should be 0...');
  169. test(cardinalres, 0);
  170. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  171. { RIGHT : LOC_REFERENCE }
  172. { LEFT : LOC_REFERENCE }
  173. cardinalres := 136;
  174. cardinalcnt := 13;
  175. cardinalres := cardinalres div cardinalcnt;
  176. Write('Value should be 10...');
  177. test(cardinalres, 10);
  178. { RIGHT : LOC_REFERENCE }
  179. { LEFT : LOC_REFERENCE }
  180. cardinalres := 10101010;
  181. cardinalcnt := 13;
  182. cardinalres := cardinalres mod cardinalcnt;
  183. Write('Value should be 10...');
  184. test(cardinalres, 10);
  185. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  186. { RIGHT : LOC_REGISTER }
  187. { LEFT : LOC_REFERENCE }
  188. cardinalres := 11111111;
  189. cardinalres := cardinalres div getcardinalcnt;
  190. Write('Value should be 1111111...');
  191. test(cardinalres, 1111111);
  192. { RIGHT : LOC_REGISTER }
  193. { LEFT : LOC_REFERENCE }
  194. cardinalres := 1111111;
  195. cardinalres := cardinalres mod getcardinalcnt;
  196. Write('Value should be 1...');
  197. test(cardinalres, 1);
  198. { RIGHT : LOC_REFERENCE }
  199. { LEFT : LOC_REGISTER }
  200. cardinalcnt := 2;
  201. cardinalres := getcardinalcnt div cardinalcnt;
  202. Write('Value should be 5...');
  203. test(cardinalres, 5);
  204. { RIGHT : LOC_REFERENCE }
  205. { LEFT : LOC_REGISTER }
  206. cardinalcnt := 3;
  207. cardinalres := getcardinalcnt mod cardinalcnt;
  208. Write('Value should be 1...');
  209. test(cardinalres, 1);
  210. WriteLn('--------------------- INT64 ------------------------');
  211. { special tests for results }
  212. Writeln('special numeric values tests...');
  213. int64res := $7FFFFFFF shl 32;
  214. int64cnt := $80000000 shl 32;
  215. int64res := int64res div int64cnt;
  216. Write('Value should be 0...');
  217. test(int64res and $FFFFFFFF, 0);
  218. Writeln('special numeric values tests...');
  219. int64res := $7FFFFFFF shl 32;
  220. int64cnt := $80000000 shl 32;
  221. int64res := int64cnt div int64res;
  222. Write('Value should be -1...');
  223. test(int64res and $FFFFFFFF, -1);
  224. int64res := $7FFFFFFF;
  225. int64cnt := $80000000;
  226. int64res := int64res div int64cnt;
  227. Write('Value should be 0...');
  228. test(int64res and $FFFFFFFF, 0);
  229. Writeln('special numeric values tests...');
  230. int64res := $7FFFFFFF;
  231. int64cnt := $80000000;
  232. int64res := int64cnt div int64res;
  233. Write('Value should be 1...');
  234. test(int64res and $FFFFFFFF, 1);
  235. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  236. { RIGHT : power of 2 ordconstn }
  237. { LEFT : LOC_REFERENCE }
  238. int64res := 24;
  239. int64res := int64res div 4;
  240. Write('Value should be 6...');
  241. test(int64res and $FFFFFFFF, 6);
  242. { RIGHT : power of 2 ordconstn }
  243. { LEFT : LOC_REFERENCE }
  244. int64res := 24;
  245. int64res := int64res mod 4;
  246. Write('Value should be 0...');
  247. test(int64res and $FFFFFFFF, 0);
  248. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  249. { RIGHT : LOC_REFERENCE }
  250. { LEFT : LOC_REFERENCE }
  251. int64res := 136;
  252. int64cnt := -13;
  253. int64res := int64res div int64cnt;
  254. Write('Value should be -10...');
  255. test(int64res and $FFFFFFFF, -10);
  256. { RIGHT : LOC_REFERENCE }
  257. { LEFT : LOC_REFERENCE }
  258. int64res := 10101010;
  259. int64cnt := -13;
  260. int64res := int64res mod int64cnt;
  261. Write('Value should be -10...');
  262. test(int64res and $FFFFFFFF, -10);
  263. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  264. { RIGHT : LOC_REGISTER }
  265. { LEFT : LOC_REFERENCE }
  266. int64res := -11111111;
  267. int64res := int64res div getint64cnt;
  268. Write('Value should be 1111111...');
  269. test(int64res and $FFFFFFFF, 1111111);
  270. { RIGHT : LOC_REGISTER }
  271. { LEFT : LOC_REFERENCE }
  272. int64res := -1111111;
  273. int64res := int64res mod getint64cnt;
  274. Write('Value should be 1...');
  275. test(int64res and $FFFFFFFF, 1);
  276. { RIGHT : LOC_REFERENCE }
  277. { LEFT : LOC_REGISTER }
  278. int64cnt := 2;
  279. int64res := getint64cnt div int64cnt;
  280. Write('Value should be -5...');
  281. test(int64res and $FFFFFFFF, -5);
  282. { RIGHT : LOC_REFERENCE }
  283. { LEFT : LOC_REGISTER }
  284. int64cnt := 3;
  285. int64res := getint64cnt mod int64cnt;
  286. Write('Value should be -1...');
  287. test(int64res and $FFFFFFFF, -1);
  288. {$ENDIF}
  289. end.