tw39178.pp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. { %cpu=x86_64,i386 }
  2. { %opt=-Cpcoreavx2 -O3 }
  3. {$mode objfpc} {$h+} {$modeswitch advancedrecords} {$modeswitch duplicatelocals}
  4. uses
  5. cpu;
  6. type
  7. UintVec3 = record
  8. x, y, z: uint32;
  9. class function Make(x, y, z: uint32): UintVec3; static;
  10. function ToString: string;
  11. class operator shr(const a: UintVec3; b: uint32): UintVec3;
  12. class operator div(const a: UintVec3; b: uint32): UintVec3;
  13. class operator =(const a,b: UintVec3): Boolean;
  14. end;
  15. class function UintVec3.Make(x, y, z: uint32): UintVec3;
  16. begin
  17. result.x := x;
  18. result.y := y;
  19. result.z := z;
  20. end;
  21. function UintVec3.ToString: string;
  22. begin
  23. WriteStr(result, x, ', ', y, ', ', z);
  24. end;
  25. class operator UintVec3.shr(const a: UintVec3; b: uint32): UintVec3;
  26. begin
  27. result.x := a.x shr b;
  28. result.y := a.y shr b;
  29. result.z := a.z shr b;
  30. end;
  31. class operator UintVec3.div(const a: UintVec3; b: uint32): UintVec3;
  32. begin
  33. result.x := a.x div b;
  34. result.y := a.y div b;
  35. result.z := a.z div b;
  36. end;
  37. class operator UintVec3.=(const a,b: UintVec3): Boolean;
  38. begin
  39. result := (a.x = b.x) and
  40. (a.y = b.y) and
  41. (a.z = b.z);
  42. end;
  43. begin
  44. if BMI2Support then
  45. begin
  46. writeln('div 2: ', (UintVec3.Make(100, 50, 30) div 2).ToString);
  47. writeln('shr 1: ', (UintVec3.Make(100, 50, 30) shr 1).ToString);
  48. if not((UintVec3.Make(100, 50, 30) div 2)=(UintVec3.Make(100, 50, 30) shr 1)) then
  49. halt(1);
  50. writeln('ok');
  51. end;
  52. end.