trecreg3.pp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {$mode delphi}
  2. const
  3. RS_CR0 = 1;
  4. RS_CR1 = 2;
  5. RS_CR2 = 3;
  6. RS_CR3 = 4;
  7. RS_CR4 = 5;
  8. RS_CR5 = 6;
  9. RS_CR6 = 7;
  10. RS_CR7 = 8;
  11. type
  12. TResFlagsEnum = (F_EQ, F_NE, F_LT, F_LE, F_GT, F_GE, F_SO, F_FX, F_FEX, F_VX,
  13. F_OX);
  14. TResFlags = record
  15. cr: RS_CR0..RS_CR7;
  16. flag: TResFlagsEnum;
  17. end;
  18. type
  19. TAsmCondFlag = (C_None { unconditional jumps },
  20. { conditions when not using ctr decrement etc }
  21. C_LT, C_LE, C_EQ, C_GE, C_GT, C_NL, C_NE, C_NG, C_SO, C_NS, C_UN, C_NU,
  22. { conditions when using ctr decrement etc }
  23. C_T, C_F, C_DNZ, C_DNZT, C_DNZF, C_DZ, C_DZT, C_DZF);
  24. TDirHint = (DH_None, DH_Minus, DH_Plus);
  25. const
  26. { these are in the XER, but when moved to CR_x they correspond with the }
  27. { bits below }
  28. C_OV = C_GT;
  29. C_CA = C_EQ;
  30. C_NO = C_NG;
  31. C_NC = C_NE;
  32. type
  33. TAsmCond = packed record
  34. dirhint: tdirhint;
  35. case simple: boolean of
  36. false: (BO, BI: byte);
  37. true: (
  38. cond: TAsmCondFlag;
  39. case byte of
  40. 0: ();
  41. { specifies in which part of the cr the bit has to be }
  42. { tested for blt,bgt,beq,..,bnu }
  43. 1: (cr: RS_CR0..RS_CR7);
  44. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  45. 2: (crbit: byte)
  46. );
  47. end;
  48. procedure error(err : int64);
  49. begin
  50. writeln('Error: ', err);
  51. halt(1);
  52. end;
  53. function flags_to_cond(const f: TResFlags): TAsmCond;
  54. const
  55. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  56. (C_EQ, C_NE, C_LT, C_LE, C_GT, C_GE, C_SO);
  57. begin
  58. if f.flag > high(flag_2_cond) then
  59. error(1);
  60. case f.flag of
  61. F_EQ, F_NE, F_LT, F_LE, F_GT, F_GE, F_SO, F_FX, F_FEX, F_VX,
  62. F_OX:
  63. ;
  64. else
  65. error(2);
  66. end;
  67. result.simple := true;
  68. result.cr := f.cr;
  69. result.cond := flag_2_cond[f.flag];
  70. end;
  71. var flags : TResFlags;
  72. begin
  73. flags.cr := RS_CR7;
  74. flags.flag := F_EQ;
  75. flags_to_cond(flags);
  76. writeln('Passed');
  77. end.