tmoddiv.pp 10 KB

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