tshlshr.pp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. {***********************************************************}
  2. { CODE GENERATOR TEST SUITE *}
  3. {***********************************************************}
  4. { NODE TESTED : secondshlshr() *}
  5. {***********************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondtypeconv() }
  9. { secondinline() with strings only! }
  10. { secondadd() comparison }
  11. { secondifn() }
  12. {***********************************************************}
  13. { DEFINES : FPC if target is Free Pascal compiler }
  14. {***********************************************************}
  15. { REMARKS: None }
  16. {***********************************************************}
  17. Program tshlshr;
  18. {----------------------------------------------------}
  19. { Cases to test: }
  20. { RIGHT NODE (shift count value) }
  21. { - LOC_CREGISTER }
  22. { - LOC_REFERENCE / LOC_MEM }
  23. { - LOC_REGISTER }
  24. { - numeric constant }
  25. { LEFT NODE (value to shift) }
  26. { - LOC_CREGISTER }
  27. { - LOC_REFERENCE / LOC_MEM }
  28. { - LOC_REGISTER }
  29. {----------------------------------------------------}
  30. procedure test(value, required: longint);
  31. begin
  32. if value <> required then
  33. begin
  34. writeln('Got ',value,' instead of ',required);
  35. halt(1);
  36. end
  37. else
  38. writeln('Passed!');
  39. end;
  40. type
  41. tint64record = packed record
  42. {$ifdef ENDIAN_BIG}
  43. highval : longint;
  44. lowval : longint;
  45. {$else}
  46. lowval : longint;
  47. highval : longint;
  48. {$endif}
  49. end;
  50. var
  51. longres : longint;
  52. longcnt : longint;
  53. bytecnt : shortint;
  54. byteres : shortint;
  55. {$IFDEF FPC}
  56. int64res : int64;
  57. int64cnt : int64;
  58. int64rec : tint64record;
  59. {$ENDIF}
  60. Begin
  61. WriteLn('------------------------------ LONGINT --------------------------------');
  62. { left : LOC_REFERENCE }
  63. { right : numeric constant }
  64. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  65. longres:=1;
  66. longres := longres shl 15;
  67. Write('(SHL) Value should be 32768...');
  68. test(longres, 32768);
  69. longres:=-1;
  70. longres := longres shl 15;
  71. Write('(SHL) Value should be -32768...');
  72. test(longres, -32768);
  73. longres:=1;
  74. longres := longres shl 33;
  75. Write('(SHL) Value should be 2...');
  76. test(longres, 2);
  77. longres:=$8000;
  78. longres := longres shr 15;
  79. Write('(SHR) Value should be 1...');
  80. test(longres, 1);
  81. longres:=-1;
  82. longres := longres shr 15;
  83. Write('(SHR) Value should be 131071...');
  84. test(longres, 131071);
  85. longres:=$FFFF;
  86. longres := longres shr 33;
  87. Write('(SHR) Value should be 32767...');
  88. test(longres, 32767);
  89. { left : LOC_REFERENCE }
  90. { right : LOC_REFERENCE }
  91. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  92. longres := 1;
  93. longcnt := -2;
  94. longres:=longres shl longcnt ;
  95. Write('(SHL) Value should be 1073741824...');
  96. test(longres, 1073741824);
  97. longres:=1;
  98. longcnt:=15;
  99. longres := longres shl longcnt;
  100. Write('(SHL) Value should be 32768...');
  101. test(longres, 32768);
  102. longres:=-1;
  103. longcnt := 15;
  104. longres := longres shl longcnt;
  105. Write('(SHL) Value should be -32768...');
  106. test(longres, -32768);
  107. longres := 1;
  108. longcnt := -2;
  109. longres:=longres shr longcnt ;
  110. Write('(SHR) Value should be 0...');
  111. test(longres, 0);
  112. longres:=32768;
  113. longcnt:=15;
  114. longres := longres shr longcnt;
  115. Write('(SHR) Value should be 1...');
  116. test(longres, 1);
  117. longres:=-1;
  118. longcnt := 15;
  119. longres := longres shl longcnt;
  120. Write('(SHR) Value should be -32768...');
  121. test(longres, -32768);
  122. { left : LOC_REFERENCE }
  123. { right : LOC_REGISRER }
  124. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  125. longres := 1;
  126. bytecnt := -2;
  127. longres:=longres shl bytecnt ;
  128. Write('(SHL) Value should be 1073741824...');
  129. test(longres, 1073741824);
  130. longres:=1;
  131. bytecnt:=15;
  132. longres := longres shl bytecnt;
  133. Write('(SHL) Value should be 32768...');
  134. test(longres, 32768);
  135. longres:=-1;
  136. bytecnt := 15;
  137. longres := longres shl bytecnt;
  138. Write('(SHL) Value should be -32768...');
  139. test(longres, -32768);
  140. longres := 1;
  141. bytecnt := -2;
  142. longres:=longres shr bytecnt ;
  143. Write('(SHR) Value should be 0...');
  144. test(longres, 0);
  145. longres:=32768;
  146. bytecnt:=15;
  147. longres := longres shr bytecnt;
  148. Write('(SHR) Value should be 1...');
  149. test(longres, 1);
  150. longres:=-1;
  151. bytecnt := 15;
  152. longres := longres shr bytecnt;
  153. Write('(SHR) Value should be 131071...');
  154. test(longres, 131071);
  155. WriteLn('(left) : LOC_REGISTER; (right) : LOC_REGISTER');
  156. byteres := 1;
  157. bytecnt := 2;
  158. byteres := byteres shl bytecnt;
  159. Write('(SHL) Value should be 4...');
  160. test(byteres, 4);
  161. byteres := 4;
  162. bytecnt := 2;
  163. byteres := byteres shr bytecnt;
  164. Write('(SHR) Value should be 1...');
  165. test(byteres, 1);
  166. {$IFDEF FPC}
  167. WriteLn('------------------------------ INT64 --------------------------------');
  168. { left : LOC_REFERENCE }
  169. { right : numeric constant }
  170. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  171. int64res:=1;
  172. int64res := int64res shl 15;
  173. Write('(SHL) Value should be 32768...');
  174. test(int64res and $FFFFFFFF, 32768);
  175. int64res:=-1;
  176. int64res := int64res shl 15;
  177. Write('(SHL) Value should be -32768...');
  178. test(int64res and $FFFFFFFF, -32768);
  179. int64res:=1;
  180. int64res := int64res shl 65;
  181. Write('(SHL) Value should be 0...');
  182. test(int64res and $FFFFFFFF, 0);
  183. int64res:=$8000;
  184. int64res := int64res shr 15;
  185. Write('(SHR) Value should be 1...');
  186. test(int64res and $FFFFFFFF, 1);
  187. int64res:=$FFFF;
  188. int64res := int64res shr 65;
  189. Write('(SHR) Value should be 0...');
  190. test(int64res and $FFFFFFFF, 0);
  191. { left : LOC_REFERENCE }
  192. { right : LOC_REFERENCE }
  193. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  194. int64res := 1;
  195. int64cnt := -2;
  196. int64res:=int64res shl int64cnt ;
  197. Write('(SHL) Value should be 1073741824...');
  198. test(int64res and $FFFFFFFF, 1073741824);
  199. int64res:=1;
  200. int64cnt:=15;
  201. int64res := int64res shl int64cnt;
  202. Write('(SHL) Value should be 32768...');
  203. test(int64res and $FFFFFFFF, 32768);
  204. int64res:=-1;
  205. int64cnt := 15;
  206. int64res := int64res shl int64cnt;
  207. Write('(SHL) Value should be -32768...');
  208. test(int64res and $FFFFFFFF, -32768);
  209. int64res := 1;
  210. int64cnt := 33;
  211. int64res := int64res shl int64cnt;
  212. Write('(SHL) Value should be 2 in high longint (85899345)...');
  213. move(int64res,int64rec, sizeof(int64));
  214. test(int64rec.highval, 2);
  215. { test(int64res, 8589934592);}
  216. int64res := 1;
  217. int64cnt := -2;
  218. int64res:=int64res shr int64cnt ;
  219. Write('(SHR) Value should be 0...');
  220. test(int64res and $FFFFFFFF, 0);
  221. int64res:=32768;
  222. int64cnt:=15;
  223. int64res := int64res shr int64cnt;
  224. Write('(SHR) Value should be 1...');
  225. test(int64res and $FFFFFFFF, 1);
  226. int64res:=-1;
  227. int64cnt := 15;
  228. int64res := int64res shl int64cnt;
  229. Write('(SHR) Value should be -32768...');
  230. test(int64res and $FFFFFFFF, -32768);
  231. { left : LOC_REFERENCE }
  232. { right : LOC_REGISRER }
  233. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  234. int64res := 1;
  235. bytecnt := -2;
  236. int64res:=int64res shl bytecnt ;
  237. Write('(SHL) Value should be 1073741824...');
  238. test(int64res and $FFFFFFFF, 1073741824);
  239. int64res:=1;
  240. bytecnt:=15;
  241. int64res := int64res shl bytecnt;
  242. Write('(SHL) Value should be 32768...');
  243. test(int64res and $FFFFFFFF, 32768);
  244. int64res:=-1;
  245. bytecnt := 15;
  246. int64res := int64res shl bytecnt;
  247. Write('(SHL) Value should be -32768...');
  248. test(int64res and $FFFFFFFF, -32768);
  249. int64res := 1;
  250. bytecnt := -2;
  251. int64res:=int64res shr bytecnt ;
  252. Write('(SHR) Value should be 0...');
  253. test(int64res and $FFFFFFFF, 0);
  254. int64res:=32768;
  255. bytecnt:=15;
  256. int64res := int64res shr bytecnt;
  257. Write('(SHR) Value should be 1...');
  258. test(int64res and $FFFFFFFF, 1);
  259. int64res := 1;
  260. bytecnt := 33;
  261. int64res := int64res shl bytecnt;
  262. Write('(SHL) Value should be 2 in high longint (85899345)...');
  263. move(int64res,int64rec, sizeof(int64));
  264. test(int64rec.highval, 2);
  265. { int64res:=-1;
  266. bytecnt := 15;
  267. int64res := int64res shr bytecnt;
  268. WriteLn('(SHR) Value should be 131071...',int64res);}
  269. {$ENDIF}
  270. end.
  271. {
  272. $Log$
  273. Revision 1.6 2002-09-29 14:37:22 carl
  274. * must more 64-bit testing (to detect endian specific problems)
  275. Revision 1.5 2002/09/07 15:40:56 peter
  276. * old logs removed and tabs fixed
  277. Revision 1.4 2002/03/29 18:43:55 peter
  278. * updated int64 tests so kylix passes the tests
  279. Revision 1.3 2002/03/05 21:56:32 carl
  280. * Adapted for automated testing
  281. }