cpubase.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Contains the base types for the PowerPC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This Unit contains the base types for the PowerPC64
  18. }
  19. unit cpubase;
  20. {$I fpcdefs.inc}
  21. interface
  22. uses
  23. strings, globtype,
  24. cutils, cclasses, aasmbase, cpuinfo, cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. TAsmOp = (A_None,
  30. { normal opcodes }
  31. a_add, a_add_, a_addo, a_addo_, a_addc, a_addc_, a_addco, a_addco_,
  32. a_adde, a_adde_, a_addeo, a_addeo_, a_addi, a_addic, a_addic_, a_addis,
  33. a_addme, a_addme_, a_addmeo, a_addmeo_, a_addze, a_addze_, a_addzeo,
  34. a_addzeo_, a_and, a_and_, a_andc, a_andc_, a_andi_, a_andis_, a_b,
  35. a_ba, a_bl, a_bla, a_bc, a_bca, a_bcl, a_bcla, a_bcctr, a_bcctrl, a_bclr,
  36. a_bclrl, a_cmp, a_cmpi, a_cmpl, a_cmpli, a_cntlzw, a_cntlzw_, a_crand,
  37. a_crandc, a_creqv, a_crnand, a_crnor, a_cror, a_crorc, a_crxor, a_dcba,
  38. a_dcbf, a_dcbi, a_dcbst, a_dcbt, a_dcbtst, a_dcbz, a_divw, a_divw_, a_divwo,
  39. a_divwo_,
  40. a_divwu, a_divwu_, a_divwuo, a_divwuo_, a_eciwx, a_ecowx, a_eieio, a_eqv,
  41. a_eqv_, a_extsb, a_extsb_, a_extsh, a_extsh_, a_fabs, a_fabs_, a_fadd,
  42. a_fadd_, a_fadds, a_fadds_, a_fcmpo, a_fcmpu, a_fctiw, a_fctiw_, a_fctiwz,
  43. a_fctwz_, a_fdiv, a_fdiv_, a_fdivs, a_fdivs_, a_fmadd, a_fmadd_, a_fmadds,
  44. a_fmadds_, a_fmr, a_fmsub, a_fmsub_, a_fmsubs, a_fmsubs_, a_fmul, a_fmul_,
  45. a_fmuls, a_fmuls_, a_fnabs, a_fnabs_, a_fneg, a_fneg_, a_fnmadd,
  46. a_fnmadd_, a_fnmadds, a_fnmadds_, a_fnmsub, a_fnmsub_, a_fnmsubs,
  47. a_fnmsubs_, a_fres, a_fres_, a_frsp, a_frsp_, a_frsqrte, a_frsqrte_,
  48. a_fsel, a_fsel_, a_fsqrt, a_fsqrt_, a_fsqrts, a_fsqrts_, a_fsub, a_fsub_,
  49. a_fsubs, a_fsubs_, a_icbi, a_isync, a_lbz, a_lbzu, a_lbzux, a_lbzx,
  50. a_lfd, a_lfdu, a_lfdux, a_lfdx, a_lfs, a_lfsu, a_lfsux, a_lfsx, a_lha,
  51. a_lhau, a_lhaux, a_lhax, a_lhbrx, a_lhz, a_lhzu, a_lhzux, a_lhzx, a_lmw,
  52. a_lswi, a_lswx, a_lwarx, a_lwbrx, a_lwz, a_lwzu, a_lwzux, a_lwzx, a_mcrf,
  53. a_mcrfs, a_mcrxr, a_mfcr, a_mffs, a_mffs_, a_mfmsr, a_mfspr, a_mfsr,
  54. a_mfsrin, a_mftb, a_mtcrf, a_mtfsb0, a_mtfsb1, a_mtfsf, a_mtfsf_,
  55. a_mtfsfi, a_mtfsfi_, a_mtmsr, a_mtspr, a_mtsr, a_mtsrin, a_mulhw,
  56. a_mulhw_, a_mulhwu, a_mulhwu_, a_mulli, a_mullw, a_mullw_, a_mullwo,
  57. a_mullwo_, a_nand, a_nand_, a_neg, a_neg_, a_nego, a_nego_, a_nor, a_nor_,
  58. a_or, a_or_, a_orc, a_orc_, a_ori, a_oris, a_rfi, a_rlwimi, a_rlwimi_,
  59. a_rlwinm, a_rlwinm_, a_rlwnm, a_sc, a_slw, a_slw_, a_sraw, a_sraw_,
  60. a_srawi, a_srawi_, a_srw, a_srw_, a_stb, a_stbu, a_stbux, a_stbx, a_stfd,
  61. a_stfdu, a_stfdux, a_stfdx, a_stfiwx, a_stfs, a_stfsu, a_stfsux, a_stfsx,
  62. a_sth, a_sthbrx, a_sthu, a_sthux, a_sthx, a_stmw, a_stswi, a_stswx, a_stw,
  63. a_stwbrx, a_stwcx_, a_stwu, a_stwux, a_stwx, a_subf, a_subf_, a_subfo,
  64. a_subfo_, a_subfc, a_subfc_, a_subfco, a_subfco_, a_subfe, a_subfe_,
  65. a_subfeo, a_subfeo_, a_subfic, a_subfme, a_subfme_, a_subfmeo, a_subfmeo_,
  66. a_subfze, a_subfze_, a_subfzeo, a_subfzeo_, a_sync, a_tlbia, a_tlbie,
  67. a_tlbsync, a_tw, a_twi, a_xor, a_xor_, a_xori, a_xoris,
  68. { simplified mnemonics }
  69. a_subi, a_subis, a_subic, a_subic_, a_sub, a_sub_, a_subo, a_subo_,
  70. a_subc, a_subc_, a_subco, a_subco_, a_cmpwi, a_cmpw, a_cmplwi, a_cmplw,
  71. a_extlwi, a_extlwi_, a_extrwi, a_extrwi_, a_inslwi, a_inslwi_, a_insrwi,
  72. a_insrwi_, a_rotlwi, a_rotlwi_, a_rotlw, a_rotlw_, a_slwi, a_slwi_,
  73. a_srwi, a_srwi_, a_clrlwi, a_clrlwi_, a_clrrwi, a_clrrwi_, a_clrslwi,
  74. a_clrslwi_, a_bf, a_bt, a_blr, a_bctr, a_blrl, a_bctrl, a_crset, a_crclr, a_crmove,
  75. a_crnot, a_mt {move to special prupose reg}, a_mf
  76. {move from special purpose reg},
  77. a_nop, a_li, a_lis, a_la, a_mr, a_mr_, a_not, a_mtcr, a_mtlr, a_mflr,
  78. a_mtctr, a_mfctr,
  79. A_EXTSW,
  80. A_RLDIMI,
  81. A_STD, A_STDU, A_STDX, A_STDUX,
  82. A_LD, A_LDU, A_LDX, A_LDUX,
  83. A_CMPD, A_CMPDI, A_CMPLD, A_CMPLDI,
  84. A_SRDI, A_SRADI,
  85. A_SLDI,
  86. A_RLDCL, A_RLDCL_, A_RLDICL, A_RLDICL_, A_RLDCR, A_RLDCR_, A_RLDICR, A_RLDICR_,
  87. A_DIVDU, A_DIVDU_, A_DIVD, A_DIVD_, A_MULLD, A_MULLD_, A_MULHD, A_MULHD_, A_SRAD, A_SLD, A_SRD,
  88. A_DIVDUO_, A_DIVDO_,
  89. A_LWA, A_LWAX, A_LWAUX,
  90. A_FCFID,
  91. A_LDARX, A_STDCX_, A_CNTLZD,
  92. A_LVX, A_STVX,
  93. A_MULLDO, A_MULLDO_, A_MULHDU, A_MULHDU_,
  94. A_MFXER,
  95. A_FCTID, A_FCTID_, A_FCTIDZ, A_FCTIDZ_,
  96. A_EXTRDI, A_EXTRDI_, A_INSRDI, A_INSRDI_,
  97. A_LWSYNC);
  98. {# This should define the array of instructions as string }
  99. op2strtable = array[tasmop] of string[8];
  100. const
  101. {# First value of opcode enumeration }
  102. firstop = low(tasmop);
  103. {# Last value of opcode enumeration }
  104. lastop = high(tasmop);
  105. {*****************************************************************************
  106. Registers
  107. *****************************************************************************}
  108. type
  109. { Number of registers used for indexing in tables }
  110. tregisterindex = 0..{$I rppcnor.inc} - 1;
  111. totherregisterset = set of tregisterindex;
  112. const
  113. maxvarregs = 32 - 6;
  114. { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  115. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  116. { Available Superregisters }
  117. {$I rppcsup.inc}
  118. { No Subregisters }
  119. R_SUBWHOLE = R_SUBNONE;
  120. { Available Registers }
  121. {$I rppccon.inc}
  122. { Integer Super registers first and last }
  123. first_int_imreg = $20;
  124. { Float Super register first and last }
  125. first_fpu_imreg = $20;
  126. { MM Super register first and last }
  127. first_mm_imreg = $20;
  128. { TODO: Calculate bsstart}
  129. regnumber_count_bsstart = 64;
  130. regnumber_table: array[tregisterindex] of tregister = (
  131. {$I rppcnum.inc}
  132. );
  133. regstabs_table: array[tregisterindex] of shortint = (
  134. {$I rppcstab.inc}
  135. );
  136. regdwarf_table: array[tregisterindex] of shortint = (
  137. {$I rppcdwrf.inc}
  138. );
  139. {*****************************************************************************
  140. Conditions
  141. *****************************************************************************}
  142. type
  143. TAsmCondFlag = (C_None { unconditional jumps },
  144. { conditions when not using ctr decrement etc }
  145. C_LT, C_LE, C_EQ, C_GE, C_GT, C_NL, C_NE, C_NG, C_SO, C_NS, C_UN, C_NU,
  146. { conditions when using ctr decrement etc }
  147. C_T, C_F, C_DNZ, C_DNZT, C_DNZF, C_DZ, C_DZT, C_DZF);
  148. TDirHint = (DH_None, DH_Minus, DH_Plus);
  149. const
  150. { these are in the XER, but when moved to CR_x they correspond with the }
  151. { bits below }
  152. C_OV = C_GT;
  153. C_CA = C_EQ;
  154. C_NO = C_NG;
  155. C_NC = C_NE;
  156. type
  157. TAsmCond = packed record
  158. dirhint: tdirhint;
  159. case simple: boolean of
  160. false: (BO, BI: byte);
  161. true: (
  162. cond: TAsmCondFlag;
  163. case byte of
  164. 0: ();
  165. { specifies in which part of the cr the bit has to be }
  166. { tested for blt,bgt,beq,..,bnu }
  167. 1: (cr: RS_CR0..RS_CR7);
  168. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  169. 2: (crbit: byte)
  170. );
  171. end;
  172. const
  173. AsmCondFlag2BO: array[C_T..C_DZF] of Byte =
  174. (12, 4, 16, 8, 0, 18, 10, 2);
  175. AsmCondFlag2BOLT_NU: array[C_LT..C_NU] of Byte =
  176. (12, 4, 12, 4, 12, 4, 4, 4, 12, 4, 12, 4);
  177. AsmCondFlag2BI: array[C_LT..C_NU] of Byte =
  178. (0, 1, 2, 0, 1, 0, 2, 1, 3, 3, 3, 3);
  179. AsmCondFlagTF: array[TAsmCondFlag] of Boolean =
  180. (false, true, false, true, false, true, false, false, false, true, false,
  181. true, false,
  182. true, false, false, true, false, false, true, false);
  183. AsmCondFlag2Str : array[TAsmCondFlag] of string[4] = ({cf_none}'',
  184. { conditions when not using ctr decrement etc}
  185. 'lt', 'le', 'eq', 'ge', 'gt', 'nl', 'ne', 'ng', 'so', 'ns', 'un', 'nu',
  186. 't', 'f', 'dnz', 'dnzt', 'dnzf', 'dz', 'dzt', 'dzf');
  187. UpperAsmCondFlag2Str: array[TAsmCondFlag] of string[4] = ({cf_none}'',
  188. { conditions when not using ctr decrement etc}
  189. 'LT', 'LE', 'EQ', 'GE', 'GT', 'NL', 'NE', 'NG', 'SO', 'NS', 'UN', 'NU',
  190. 'T', 'F', 'DNZ', 'DNZT', 'DNZF', 'DZ', 'DZT', 'DZF');
  191. {*****************************************************************************
  192. Flags
  193. *****************************************************************************}
  194. type
  195. TResFlagsEnum = (F_EQ, F_NE, F_LT, F_LE, F_GT, F_GE, F_SO, F_FX, F_FEX, F_VX,F_OX,
  196. { For IEEE-compliant floating-point compares, only <= and >=
  197. are actually needed but the other two are for inverse. }
  198. F_FA,F_FAE,F_FB,F_FBE);
  199. TResFlags = record
  200. cr: RS_CR0..RS_CR7;
  201. flag: TResFlagsEnum;
  202. end;
  203. {*****************************************************************************
  204. Reference
  205. *****************************************************************************}
  206. const
  207. { MacOS only. Whether the direct data area (TOC) directly contain
  208. global variables. Otherwise it contains pointers to global variables. }
  209. macos_direct_globals = false;
  210. {*****************************************************************************
  211. Operand Sizes
  212. *****************************************************************************}
  213. {*****************************************************************************
  214. Constants
  215. *****************************************************************************}
  216. const
  217. max_operands = 5;
  218. {*****************************************************************************
  219. Default generic sizes
  220. *****************************************************************************}
  221. {# Defines the default address size for a processor, }
  222. OS_ADDR = OS_64;
  223. {# the natural int size for a processor,
  224. has to match osuinttype/ossinttype as initialized in psystem }
  225. OS_INT = OS_64;
  226. OS_SINT = OS_S64;
  227. {# the maximum float size for a processor, }
  228. OS_FLOAT = OS_F64;
  229. {# the size of a vector register for a processor }
  230. OS_VECTOR = OS_M128;
  231. {*****************************************************************************
  232. GDB Information
  233. *****************************************************************************}
  234. {# Register indexes for stabs information, when some
  235. parameters or variables are stored in registers.
  236. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  237. from GCC 3.x source code. PowerPC has 1:1 mapping
  238. according to the order of the registers defined
  239. in GCC
  240. }
  241. stab_regindex: array[tregisterindex] of shortint = (
  242. {$I rppcstab.inc}
  243. );
  244. {*****************************************************************************
  245. Generic Register names
  246. *****************************************************************************}
  247. // Stack pointer register
  248. NR_STACK_POINTER_REG = NR_R1;
  249. RS_STACK_POINTER_REG = RS_R1;
  250. // old stack pointer register used during copying variables from the caller
  251. // stack frame
  252. NR_OLD_STACK_POINTER_REG = NR_R12;
  253. // Frame pointer register
  254. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  255. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  256. {# Register for addressing absolute data in a position independant way,
  257. such as in PIC code. The exact meaning is ABI specific. For
  258. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  259. Taken from GCC rs6000.h
  260. }
  261. { TODO: As indicated in rs6000.h, but can't find it anywhere else!}
  262. NR_PIC_OFFSET_REG = NR_R30;
  263. { Return address of a function }
  264. NR_RETURN_ADDRESS_REG = NR_R0;
  265. { Results are returned in this register (64-bit values) }
  266. NR_FUNCTION_RETURN_REG = NR_R3;
  267. RS_FUNCTION_RETURN_REG = RS_R3;
  268. { The value returned from a function is available in this register }
  269. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  270. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  271. NR_FPU_RESULT_REG = NR_F1;
  272. NR_MM_RESULT_REG = NR_M0;
  273. NR_DEFAULTFLAGS = NR_CR;
  274. RS_DEFAULTFLAGS = RS_CR;
  275. {*****************************************************************************
  276. GCC /ABI linking information
  277. *****************************************************************************}
  278. {# Required parameter alignment when calling a routine declared as
  279. stdcall and cdecl. The alignment value should be the one defined
  280. by GCC or the target ABI.
  281. }
  282. std_param_align = 8;
  283. vmx_std_param_align = 16;
  284. {*****************************************************************************
  285. CPU Dependent Constants
  286. *****************************************************************************}
  287. LinkageAreaSizeELF = 48;
  288. LinkageAreaSizeELFv2 = 32;
  289. { offset in the linkage area for the saved stack pointer }
  290. LA_SP = 0;
  291. { offset in the linkage area for the saved conditional register}
  292. LA_CR_SYSV = 8;
  293. { offset in the linkage area for the saved link register}
  294. LA_LR_AIX = 16;
  295. LA_LR_SYSV = 16;
  296. { offset in the linkage area for the saved RTOC register}
  297. LA_RTOC_SYSV = 40;
  298. LA_RTOC_AIX = 40;
  299. LA_RTOC_ELFV2 = 24;
  300. PARENT_FRAMEPOINTER_OFFSET = 24;
  301. NR_RTOC = NR_R2;
  302. ELF_STACK_ALIGN = 16;
  303. { the size of the "red zone" which must not be changed by asynchronous calls
  304. in the stack frame and can be used for storing temps }
  305. RED_ZONE_SIZE = 288;
  306. { minimum size of the stack frame if one exists }
  307. MINIMUM_STACKFRAME_SIZE = 112;
  308. MINIMUM_STACKFRAME_SIZE_ELFV2 = 112 - 16;
  309. maxfpuregs = 8;
  310. {*****************************************************************************
  311. Helpers
  312. *****************************************************************************}
  313. function is_calljmp(o: tasmop): boolean;
  314. procedure inverse_flags(var r: TResFlags);
  315. function flags_to_cond(const f: TResFlags): TAsmCond;
  316. procedure create_cond_imm(BO, BI: byte; var r: TAsmCond);
  317. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte; var r: TasmCond);
  318. function cgsize2subreg(regtype: tregistertype; s: Tcgsize): Tsubregister;
  319. { Returns the tcgsize corresponding with the size of reg.}
  320. function reg_cgsize(const reg: tregister): tcgsize;
  321. function findreg_by_number(r: Tregister): tregisterindex;
  322. function std_regnum_search(const s: string): Tregister;
  323. function std_regname(r: Tregister): string;
  324. function is_condreg(r: tregister): boolean;
  325. function inverse_cond(const c: TAsmCond): Tasmcond;
  326. {$IFDEF USEINLINE}inline;{$ENDIF USEINLINE}
  327. function conditions_equal(const c1, c2: TAsmCond): boolean;
  328. function dwarf_reg(r:tregister):shortint;
  329. function dwarf_reg_no_error(r:tregister):shortint;
  330. implementation
  331. uses
  332. rgBase, verbose, itcpugas;
  333. const
  334. std_regname_table: TRegNameTable = (
  335. {$I rppcstd.inc}
  336. );
  337. regnumber_index: array[tregisterindex] of tregisterindex = (
  338. {$I rppcrni.inc}
  339. );
  340. std_regname_index: array[tregisterindex] of tregisterindex = (
  341. {$I rppcsri.inc}
  342. );
  343. {*****************************************************************************
  344. Helpers
  345. ***************** ************************************************************}
  346. function is_calljmp(o: tasmop): boolean;
  347. begin
  348. is_calljmp := false;
  349. case o of
  350. A_B, A_BA, A_BL, A_BLA, A_BC, A_BCA, A_BCL, A_BCLA, A_BCCTR, A_BCCTRL,
  351. A_BCLR, A_BF, A_BT,
  352. A_BCLRL, A_TW, A_TWI: is_calljmp := true;
  353. end;
  354. end;
  355. procedure inverse_flags(var r: TResFlags);
  356. const
  357. inv_flags: array[F_EQ..F_GE] of TResFlagsEnum =
  358. (F_NE, F_EQ, F_GE, F_GE, F_LE, F_LT);
  359. inv_fpuflags: array[F_FA..F_FBE] of TResFlagsEnum =
  360. (F_FBE,F_FB,F_FAE,F_FA);
  361. begin
  362. if r.flag in [F_EQ..F_GE] then
  363. r.flag := inv_flags[r.flag]
  364. else if r.flag in [F_FA..F_FBE] then
  365. r.flag := inv_fpuflags[r.flag]
  366. else
  367. internalerror(2014041901);
  368. end;
  369. function inverse_cond(const c: TAsmCond): Tasmcond;
  370. {$IFDEF USEINLINE}inline;
  371. {$ENDIF USEINLINE}
  372. const
  373. inv_condflags: array[TAsmCondFlag] of TAsmCondFlag = (C_None,
  374. C_GE, C_GT, C_NE, C_LT, C_LE, C_LT, C_EQ, C_GT, C_NS, C_SO, C_NU, C_UN,
  375. C_F, C_T, C_DNZ, C_DNZF, C_DNZT, C_DZ, C_DZF, C_DZT);
  376. begin
  377. if (c.cond in [C_DNZ, C_DZ]) then
  378. internalerror(2005022501);
  379. result := c;
  380. result.cond := inv_condflags[c.cond];
  381. end;
  382. function conditions_equal(const c1, c2: TAsmCond): boolean;
  383. begin
  384. result :=
  385. (c1.simple and c2.simple) and
  386. (c1.cond = c2.cond) and
  387. ((not (c1.cond in [C_T..C_DZF]) and
  388. (c1.cr = c2.cr)) or
  389. (c1.crbit = c2.crbit));
  390. end;
  391. function flags_to_cond(const f: TResFlags): TAsmCond;
  392. const
  393. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  394. (C_EQ, C_NE, C_LT, C_LE, C_GT, C_GE, C_SO);
  395. begin
  396. if f.flag > high(flag_2_cond) then
  397. internalerror(200112301);
  398. result.simple := true;
  399. result.cr := f.cr;
  400. if byte(f.cr)=0 then
  401. Comment(V_error,'Wrong use of whole CR register in falgs_to_cond');
  402. result.cond := flag_2_cond[f.flag];
  403. end;
  404. procedure create_cond_imm(BO, BI: byte; var r: TAsmCond);
  405. begin
  406. r.simple := false;
  407. r.bo := bo;
  408. r.bi := bi;
  409. end;
  410. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte; var r: TasmCond);
  411. begin
  412. r.dirhint := DH_None;
  413. r.simple := true;
  414. r.cond := cond;
  415. case cond of
  416. C_NONE: ;
  417. C_T..C_DZF: r.crbit := cr
  418. else
  419. r.cr := RS_CR0 + cr;
  420. end;
  421. end;
  422. function is_condreg(r: tregister): boolean;
  423. var
  424. supreg: tsuperregister;
  425. begin
  426. result := false;
  427. if (getregtype(r) = R_SPECIALREGISTER) then
  428. begin
  429. supreg := getsupreg(r);
  430. result := (supreg >= RS_CR0) and (supreg <= RS_CR7);
  431. end;
  432. end;
  433. function reg_cgsize(const reg: tregister): tcgsize;
  434. begin
  435. case getregtype(reg) of
  436. R_INTREGISTER:
  437. result := OS_64;
  438. R_MMREGISTER:
  439. result := OS_M128;
  440. R_FPUREGISTER:
  441. result := OS_F64;
  442. else
  443. internalerror(200303181);
  444. end;
  445. end;
  446. function cgsize2subreg(regtype: tregistertype; s: Tcgsize): Tsubregister;
  447. begin
  448. cgsize2subreg := R_SUBWHOLE;
  449. end;
  450. function findreg_by_number(r: Tregister): tregisterindex;
  451. begin
  452. result := rgBase.findreg_by_number_table(r, regnumber_index);
  453. end;
  454. function std_regnum_search(const s: string): Tregister;
  455. begin
  456. result := regnumber_table[findreg_by_name_table(s, std_regname_table,
  457. std_regname_index)];
  458. end;
  459. function std_regname(r: Tregister): string;
  460. var
  461. p: tregisterindex;
  462. begin
  463. p := findreg_by_number_table(r, regnumber_index);
  464. if p <> 0 then
  465. result := std_regname_table[p]
  466. else
  467. result := generic_regname(r);
  468. end;
  469. function dwarf_reg(r:tregister):shortint;
  470. begin
  471. result:=regdwarf_table[findreg_by_number(r)];
  472. if result=-1 then
  473. internalerror(200603251);
  474. end;
  475. function dwarf_reg_no_error(r:tregister):shortint;
  476. begin
  477. result:=regdwarf_table[findreg_by_number(r)];
  478. end;
  479. end.