tshlshr.pp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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: {$ifndef fpc}longint{$else fpc}int64{$endif fpc});
  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. {
  93. longres := 1;
  94. longcnt := -2;
  95. longres:=longres shl longcnt ;
  96. Write('(SHL) Value should be 1073741824...');
  97. test(longres, 1073741824);
  98. }
  99. longres:=1;
  100. longcnt:=15;
  101. longres := longres shl longcnt;
  102. Write('(SHL) Value should be 32768...');
  103. test(longres, 32768);
  104. longres:=-1;
  105. longcnt := 15;
  106. longres := longres shl longcnt;
  107. Write('(SHL) Value should be -32768...');
  108. test(longres, -32768);
  109. {
  110. longres := 1;
  111. longcnt := -2;
  112. longres:=longres shr longcnt ;
  113. Write('(SHR) Value should be 0...');
  114. test(longres, 0);
  115. }
  116. longres:=32768;
  117. longcnt:=15;
  118. longres := longres shr longcnt;
  119. Write('(SHR) Value should be 1...');
  120. test(longres, 1);
  121. longres:=-1;
  122. longcnt := 15;
  123. longres := longres shl longcnt;
  124. Write('(SHR) Value should be -32768...');
  125. test(longres, -32768);
  126. { left : LOC_REFERENCE }
  127. { right : LOC_REGISRER }
  128. {
  129. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  130. longres := 1;
  131. bytecnt := -2;
  132. longres:=longres shl bytecnt ;
  133. Write('(SHL) Value should be 1073741824...');
  134. test(longres, 1073741824);
  135. }
  136. longres:=1;
  137. bytecnt:=15;
  138. longres := longres shl bytecnt;
  139. Write('(SHL) Value should be 32768...');
  140. test(longres, 32768);
  141. longres:=-1;
  142. bytecnt := 15;
  143. longres := longres shl bytecnt;
  144. Write('(SHL) Value should be -32768...');
  145. test(longres, -32768);
  146. {
  147. longres := 1;
  148. bytecnt := -2;
  149. longres:=longres shr bytecnt ;
  150. Write('(SHR) Value should be 0...');
  151. test(longres, 0);
  152. }
  153. longres:=32768;
  154. bytecnt:=15;
  155. longres := longres shr bytecnt;
  156. Write('(SHR) Value should be 1...');
  157. test(longres, 1);
  158. longres:=-1;
  159. bytecnt := 15;
  160. longres := longres shr bytecnt;
  161. Write('(SHR) Value should be 131071...');
  162. test(longres, 131071);
  163. WriteLn('(left) : LOC_REGISTER; (right) : LOC_REGISTER');
  164. byteres := 1;
  165. bytecnt := 2;
  166. byteres := byteres shl bytecnt;
  167. Write('(SHL) Value should be 4...');
  168. test(byteres, 4);
  169. byteres := 4;
  170. bytecnt := 2;
  171. byteres := byteres shr bytecnt;
  172. Write('(SHR) Value should be 1...');
  173. test(byteres, 1);
  174. {$IFDEF FPC}
  175. WriteLn('------------------------------ INT64 --------------------------------');
  176. { left : LOC_REFERENCE }
  177. { right : numeric constant }
  178. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  179. int64res:=1;
  180. int64res := int64res shl 15;
  181. Write('(SHL) Value should be 32768...');
  182. test(int64res, 32768);
  183. int64res:=-1;
  184. int64res := int64res shl 15;
  185. Write('(SHL) Value should be -32768...');
  186. test(int64res, -32768);
  187. int64res:=1;
  188. int64res := int64res shl 65;
  189. Write('(SHL) Value should be 2...');
  190. test(int64res, 2);
  191. int64res:=$8000;
  192. int64res := int64res shr 15;
  193. Write('(SHR) Value should be 1...');
  194. test(int64res, 1);
  195. int64res:=$FFFF;
  196. int64res := int64res shr 65;
  197. Write('(SHR) Value should be 32767...');
  198. test(int64res, 32767);
  199. { left : LOC_REFERENCE }
  200. { right : LOC_REFERENCE }
  201. {
  202. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  203. int64res := 1;
  204. int64cnt := -2;
  205. int64res:=int64res shl int64cnt ;
  206. Write('(SHL) Value should be 1073741824...');
  207. test(int64res, 1073741824);
  208. }
  209. int64res:=1;
  210. int64cnt:=15;
  211. int64res := int64res shl int64cnt;
  212. Write('(SHL) Value should be 32768...');
  213. test(int64res, 32768);
  214. int64res:=-1;
  215. int64cnt := 15;
  216. int64res := int64res shl int64cnt;
  217. Write('(SHL) Value should be -32768...');
  218. test(int64res, -32768);
  219. int64res := 1;
  220. int64cnt := 33;
  221. int64res := int64res shl int64cnt;
  222. Write('(SHL) Value should be 2 in high longint (85899345)...');
  223. move(int64res,int64rec, sizeof(int64));
  224. test(int64rec.highval, 2);
  225. { test(int64res, 8589934592);}
  226. {
  227. int64res := 1;
  228. int64cnt := -2;
  229. int64res:=int64res shr int64cnt ;
  230. Write('(SHR) Value should be 0...');
  231. test(int64res and $FFFFFFFF, 0);
  232. }
  233. int64res:=32768;
  234. int64cnt:=15;
  235. int64res := int64res shr int64cnt;
  236. Write('(SHR) Value should be 1...');
  237. test(int64res, 1);
  238. int64res:=-1;
  239. int64cnt := 15;
  240. int64res := int64res shl int64cnt;
  241. Write('(SHR) Value should be -32768...');
  242. test(int64res, -32768);
  243. { left : LOC_REFERENCE }
  244. { right : LOC_REGISRER }
  245. {
  246. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  247. int64res := 1;
  248. bytecnt := -2;
  249. int64res:=int64res shl bytecnt ;
  250. Write('(SHL) Value should be 1073741824...');
  251. test(int64res, 1073741824);
  252. }
  253. int64res:=1;
  254. bytecnt:=15;
  255. int64res := int64res shl bytecnt;
  256. Write('(SHL) Value should be 32768...');
  257. test(int64res, 32768);
  258. int64res:=-1;
  259. bytecnt := 15;
  260. int64res := int64res shl bytecnt;
  261. Write('(SHL) Value should be -32768...');
  262. test(int64res, -32768);
  263. {
  264. int64res := 1;
  265. bytecnt := -2;
  266. int64res:=int64res shr bytecnt ;
  267. Write('(SHR) Value should be 0...');
  268. test(int64res and $FFFFFFFF, 0);
  269. }
  270. int64res:=32768;
  271. bytecnt:=15;
  272. int64res := int64res shr bytecnt;
  273. Write('(SHR) Value should be 1...');
  274. test(int64res, 1);
  275. int64res := 1;
  276. bytecnt := 33;
  277. int64res := int64res shl bytecnt;
  278. Write('(SHL) Value should be 2 in high longint (85899345)...');
  279. move(int64res,int64rec, sizeof(int64));
  280. test(int64rec.highval, 2);
  281. { int64res:=-1;
  282. bytecnt := 15;
  283. int64res := int64res shr bytecnt;
  284. WriteLn('(SHR) Value should be 131071...',int64res);}
  285. {$ENDIF}
  286. end.