tint643.pp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {$q+}
  2. {$mode objfpc}
  3. uses
  4. sysutils;
  5. type
  6. tqwordrec = packed record
  7. {$ifndef ENDIAN_BIG}
  8. low,high : dword;
  9. {$else}
  10. high, low : dword;
  11. {$endif}
  12. end;
  13. procedure assignqword(h,l : dword;var q : qword);
  14. begin
  15. tqwordrec(q).high:=h;
  16. tqwordrec(q).low:=l;
  17. end;
  18. procedure testmulqword;
  19. var
  20. q1, q2, q3, q4: qword;
  21. c: cardinal;
  22. loops: longint;
  23. begin
  24. assignqword(0,$1000,q1);
  25. assignqword(0,$7fff,q2);
  26. c := $1000 * $7fff;
  27. q4 := c;
  28. loops := 0;
  29. try
  30. repeat
  31. q3 := q1 * q2;
  32. if q3 <> q4 then
  33. begin
  34. writeln('qword multiplication of shift error');
  35. halt(1);
  36. end;
  37. inc(loops);
  38. if (loops >= 39) then
  39. begin
  40. writeln('qword multiplication overflow detection failed');
  41. halt(1);
  42. end;
  43. q1 := q1 shl 1;
  44. q4 := q4 shl 1;
  45. writeln(loops,': ',q3);
  46. until false;
  47. except
  48. on eintoverflow do
  49. begin
  50. if loops < 38 then
  51. begin
  52. writeln('false qword multiplication overflow detected');
  53. halt(1);
  54. end;
  55. end;
  56. end;
  57. end;
  58. begin
  59. testmulqword;
  60. end.