2
0

tbopr.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. {$mode macpas}
  2. {$r-}
  3. {$q-}
  4. procedure testlongintrot;
  5. const
  6. haltoffset = 0;
  7. var
  8. l : longint;
  9. begin
  10. l := 1;
  11. l := brotl(l,1);
  12. if (l <> 2) then
  13. halt(1+haltoffset);
  14. l := brotr(l,1);
  15. if (l <> 1) then
  16. halt(2+haltoffset);
  17. l := longint($80000001);
  18. l := brotl(l,2);
  19. if (l <> 6) then
  20. halt(3+haltoffset);
  21. l := brotr(l,3);
  22. if (l <> longint($c0000000)) then
  23. halt(4+haltoffset);
  24. l := brotr(l,2);
  25. // "longint($c0000000) shr 2" is evaluated using 64 bit :/
  26. if (l <> (longint(cardinal($c0000000) shr 2))) then
  27. halt(5+haltoffset);
  28. end;
  29. procedure testcardinalrot;
  30. const
  31. haltoffset = 5;
  32. var
  33. l : cardinal;
  34. begin
  35. l := 1;
  36. l := brotl(l,1);
  37. if (l <> 2) then
  38. halt(1+haltoffset);
  39. l := brotr(l,1);
  40. if (l <> 1) then
  41. halt(2+haltoffset);
  42. l := $80000001;
  43. l := brotl(l,2);
  44. if (l <> 6) then
  45. halt(3+haltoffset);
  46. l := brotr(l,3);
  47. if (l <> $c0000000) then
  48. halt(4+haltoffset);
  49. l := brotr(l,2);
  50. if (l <> (cardinal($c0000000) shr 2)) then
  51. halt(5+haltoffset);
  52. end;
  53. procedure testint64rot;
  54. const
  55. haltoffset = 10;
  56. var
  57. l : int64;
  58. begin
  59. l := 1;
  60. l := brotl(l,1);
  61. if (l <> 2) then
  62. halt(1+haltoffset);
  63. l := brotr(l,1);
  64. if (l <> 1) then
  65. halt(2+haltoffset);
  66. l := $80000001;
  67. l := brotl(l,2);
  68. if (l <> $200000004) then
  69. halt(3+haltoffset);
  70. l := brotr(l,3);
  71. if (l <> int64($8000000040000000)) then
  72. halt(4+haltoffset);
  73. l := brotr(l,2);
  74. if (l <> (int64($8000000040000000) shr 2)) then
  75. halt(5+haltoffset);
  76. end;
  77. procedure testqwordrot;
  78. const
  79. haltoffset = 15;
  80. var
  81. l : qword;
  82. begin
  83. l := 1;
  84. l := brotl(l,1);
  85. if (l <> 2) then
  86. halt(1+haltoffset);
  87. l := brotr(l,1);
  88. if (l <> 1) then
  89. halt(2+haltoffset);
  90. l := $80000001;
  91. l := brotl(l,2);
  92. if (l <> $200000004) then
  93. halt(3+haltoffset);
  94. l := brotr(l,3);
  95. if (l <> qword($8000000040000000)) then
  96. halt(4+haltoffset);
  97. l := brotr(l,2);
  98. if (l <> (qword($8000000040000000) shr 2)) then
  99. halt(5+haltoffset);
  100. end;
  101. procedure testlongintnot;
  102. const
  103. haltoffset = 20;
  104. var
  105. l, j : longint;
  106. begin
  107. l := low(longint);
  108. for j := 1 to (maxlongint div 13579) do
  109. begin
  110. if not(l) <> bnot(l) then
  111. halt(haltoffset+1);
  112. inc(l,13579*2);
  113. end;
  114. end;
  115. procedure testcardinalnot;
  116. const
  117. haltoffset = 21;
  118. var
  119. l, j : cardinal;
  120. begin
  121. l := 0;
  122. for j := 1 to (maxlongint div 13579) do
  123. begin
  124. if not(l) <> bnot(l) then
  125. halt(haltoffset+1);
  126. inc(l,13579*2);
  127. end;
  128. end;
  129. procedure testint64not;
  130. const
  131. haltoffset = 22;
  132. var
  133. l, j : int64;
  134. begin
  135. l := low(int64);
  136. j := 1;
  137. repeat
  138. if not(l) <> bnot(l) then
  139. halt(haltoffset+1);
  140. inc(l,int64(13579)*high(longint)*2);
  141. inc(j);
  142. until (j = (high(int64) div (int64(13579) * high(longint))));
  143. end;
  144. procedure testqwordnot;
  145. const
  146. haltoffset = 22;
  147. var
  148. l, j : qword;
  149. begin
  150. l := 0;
  151. j := 1;
  152. repeat
  153. if not(l) <> bnot(l) then
  154. halt(haltoffset+1);
  155. inc(l,int64(13579)*high(longint)*2);
  156. inc(j);
  157. until (j = (high(int64) div (int64(13579) * high(longint))));
  158. end;
  159. begin
  160. testlongintrot;
  161. testcardinalrot;
  162. testint64rot;
  163. testqwordrot;
  164. testlongintnot;
  165. testcardinalnot;
  166. testint64not;
  167. testqwordnot;
  168. end.