cpubase.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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 PowerPC
  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, a_divwo_,
  39. a_divwu, a_divwu_, a_divwuo, a_divwuo_, a_eciwx, a_ecowx, a_eieio, a_eqv,
  40. a_eqv_, a_extsb, a_extsb_, a_extsh, a_extsh_, a_fabs, a_fabs_, a_fadd,
  41. a_fadd_, a_fadds, a_fadds_, a_fcmpo, a_fcmpu, a_fctid, a_fctid_,
  42. a_fctidz, a_fctidz_, a_fctiw, a_fctiw_, a_fctiwz, a_fctiwz_,
  43. 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_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_blr, a_bctr, a_blrl, a_bctrl, a_crset, a_crclr, a_crmove,
  75. a_crnot, a_mt {move to special purpose reg}, a_mf {move from special purpose reg},
  76. a_nop, a_li, a_lis, a_la, a_mr, a_mr_, a_not, a_not_, a_mtcr, a_mtlr, a_mflr,
  77. a_mtctr, a_mfctr, a_mftbu, a_mfxer,
  78. a_mfpvr, a_mfdcr, a_mtdcr, a_mfdec, mtdec);
  79. {# This should define the array of instructions as string }
  80. op2strtable=array[tasmop] of string[8];
  81. Const
  82. {# First value of opcode enumeration }
  83. firstop = low(tasmop);
  84. {# Last value of opcode enumeration }
  85. lastop = high(tasmop);
  86. {*****************************************************************************
  87. Registers
  88. *****************************************************************************}
  89. type
  90. { Number of registers used for indexing in tables }
  91. tregisterindex=0..{$i rppcnor.inc}-1;
  92. totherregisterset = set of tregisterindex;
  93. const
  94. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  95. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  96. { Available Superregisters }
  97. {$i rppcsup.inc}
  98. { No Subregisters }
  99. R_SUBWHOLE=R_SUBNONE;
  100. { Available Registers }
  101. {$i rppccon.inc}
  102. { Integer Super registers first and last }
  103. first_int_imreg = $20;
  104. { Float Super register first and last }
  105. first_fpu_imreg = $20;
  106. { MM Super register first and last }
  107. first_mm_imreg = $20;
  108. { TODO: Calculate bsstart}
  109. regnumber_count_bsstart = 64;
  110. regnumber_table : array[tregisterindex] of tregister = (
  111. {$i rppcnum.inc}
  112. );
  113. regstabs_table : array[tregisterindex] of shortint = (
  114. {$i rppcstab.inc}
  115. );
  116. regdwarf_table : array[tregisterindex] of shortint = (
  117. {$i rppcdwrf.inc}
  118. );
  119. {*****************************************************************************
  120. Conditions
  121. *****************************************************************************}
  122. type
  123. TAsmCondFlag = (C_None { unconditional jumps },
  124. { conditions when not using ctr decrement etc }
  125. C_LT,C_LE,C_EQ,C_GE,C_GT,C_NL,C_NE,C_NG,C_SO,C_NS,C_UN,C_NU,
  126. { conditions when using ctr decrement etc }
  127. C_T,C_F,C_DNZ,C_DNZT,C_DNZF,C_DZ,C_DZT,C_DZF);
  128. TDirHint = (DH_None,DH_Minus,DH_Plus);
  129. const
  130. { these are in the XER, but when moved to CR_x they correspond with the }
  131. { bits below }
  132. C_OV = C_GT;
  133. C_CA = C_EQ;
  134. C_NO = C_NG;
  135. C_NC = C_NE;
  136. type
  137. TAsmCond = packed record
  138. dirhint : tdirhint;
  139. case simple: boolean of
  140. false: (BO, BI: byte);
  141. true: (
  142. cond: TAsmCondFlag;
  143. case byte of
  144. 0: ();
  145. { specifies in which part of the cr the bit has to be }
  146. { tested for blt,bgt,beq,..,bnu }
  147. 1: (cr: RS_CR0..RS_CR7);
  148. { specifies the bit to test for bt,bf,bdz,..,bdzf }
  149. 2: (crbit: byte)
  150. );
  151. end;
  152. const
  153. AsmCondFlag2BO: Array[C_T..C_DZF] of Byte =
  154. (12,4,16,8,0,18,10,2);
  155. AsmCondFlag2BOLT_NU: Array[C_LT..C_NU] of Byte =
  156. (12,4,12,4,12,4,4,4,12,4,12,4);
  157. AsmCondFlag2BI: Array[C_LT..C_NU] of Byte =
  158. (0,1,2,0,1,0,2,1,3,3,3,3);
  159. AsmCondFlagTF: Array[TAsmCondFlag] of Boolean =
  160. (false,true,false,true,false,true,false,false,false,true,false,true,false,
  161. true,false,false,true,false,false,true,false);
  162. AsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  163. { conditions when not using ctr decrement etc}
  164. 'lt','le','eq','ge','gt','nl','ne','ng','so','ns','un','nu',
  165. 't','f','dnz','dnzt','dnzf','dz','dzt','dzf');
  166. UpperAsmCondFlag2Str: Array[TAsmCondFlag] of string[4] = ({cf_none}'',
  167. { conditions when not using ctr decrement etc}
  168. 'LT','LE','EQ','GE','GT','NL','NE','NG','SO','NS','UN','NU',
  169. 'T','F','DNZ','DNZT','DNZF','DZ','DZT','DZF');
  170. const
  171. CondAsmOps=3;
  172. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  173. A_BC, A_TW, A_TWI
  174. );
  175. CondAsmOpStr:array[0..CondAsmOps-1] of string[7]=(
  176. 'BC','TW','TWI'
  177. );
  178. {*****************************************************************************
  179. Flags
  180. *****************************************************************************}
  181. type
  182. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LE,F_GT,F_GE,F_SO,F_FX,F_FEX,F_VX,F_OX);
  183. TResFlags = record
  184. cr: RS_CR0..RS_CR7;
  185. flag: TResFlagsEnum;
  186. end;
  187. (*
  188. const
  189. { arrays for boolean location conversions }
  190. flag_2_cond : array[TResFlags] of TAsmCond =
  191. (C_E,C_NE,C_LT,C_LE,C_GT,C_GE,???????????????);
  192. *)
  193. {*****************************************************************************
  194. Reference
  195. *****************************************************************************}
  196. const
  197. { MacOS only. Whether the direct data area (TOC) directly contain
  198. global variables. Otherwise it contains pointers to global variables. }
  199. macos_direct_globals = false;
  200. {*****************************************************************************
  201. Operand Sizes
  202. *****************************************************************************}
  203. {*****************************************************************************
  204. Constants
  205. *****************************************************************************}
  206. const
  207. max_operands = 5;
  208. {*****************************************************************************
  209. Default generic sizes
  210. *****************************************************************************}
  211. {# Defines the default address size for a processor, }
  212. OS_ADDR = OS_32;
  213. {# the natural int size for a processor,
  214. has to match osuinttype/ossinttype as initialized in psystem }
  215. OS_INT = OS_32;
  216. OS_SINT = OS_S32;
  217. {# the maximum float size for a processor, }
  218. OS_FLOAT = OS_F64;
  219. {# the size of a vector register for a processor }
  220. OS_VECTOR = OS_M128;
  221. {*****************************************************************************
  222. GDB Information
  223. *****************************************************************************}
  224. {# Register indexes for stabs information, when some
  225. parameters or variables are stored in registers.
  226. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  227. from GCC 3.x source code. PowerPC has 1:1 mapping
  228. according to the order of the registers defined
  229. in GCC
  230. }
  231. stab_regindex : array[tregisterindex] of shortint = (
  232. {$i rppcstab.inc}
  233. );
  234. {*****************************************************************************
  235. Generic Register names
  236. *****************************************************************************}
  237. {# Stack pointer register }
  238. NR_STACK_POINTER_REG = NR_R1;
  239. RS_STACK_POINTER_REG = RS_R1;
  240. {# Frame pointer register }
  241. NR_FRAME_POINTER_REG = NR_STACK_POINTER_REG;
  242. RS_FRAME_POINTER_REG = RS_STACK_POINTER_REG;
  243. {# Register for addressing absolute data in a position independant way,
  244. such as in PIC code. The exact meaning is ABI specific. For
  245. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  246. Taken from GCC rs6000.h
  247. }
  248. { TODO: As indicated in rs6000.h, but can't find it anywhere else!}
  249. NR_PIC_OFFSET_REG = NR_R30;
  250. { Return address of a function }
  251. NR_RETURN_ADDRESS_REG = NR_R0;
  252. { Results are returned in this register (32-bit values) }
  253. NR_FUNCTION_RETURN_REG = NR_R3;
  254. RS_FUNCTION_RETURN_REG = RS_R3;
  255. { Low part of 64bit return value }
  256. NR_FUNCTION_RETURN64_LOW_REG = NR_R4;
  257. RS_FUNCTION_RETURN64_LOW_REG = RS_R4;
  258. { High part of 64bit return value }
  259. NR_FUNCTION_RETURN64_HIGH_REG = NR_R3;
  260. RS_FUNCTION_RETURN64_HIGH_REG = RS_R3;
  261. { The value returned from a function is available in this register }
  262. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  263. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  264. { The lowh part of 64bit value returned from a function }
  265. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  266. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  267. { The high part of 64bit value returned from a function }
  268. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  269. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  270. NR_FPU_RESULT_REG = NR_F1;
  271. NR_MM_RESULT_REG = NR_M0;
  272. NR_DEFAULTFLAGS = NR_CR;
  273. RS_DEFAULTFLAGS = RS_CR;
  274. {*****************************************************************************
  275. GCC /ABI linking information
  276. *****************************************************************************}
  277. {# Registers which must be saved when calling a routine declared as
  278. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  279. saved should be the ones as defined in the target ABI and / or GCC.
  280. This value can be deduced from CALLED_USED_REGISTERS array in the
  281. GCC source.
  282. }
  283. saved_standard_registers : array[0..18] of tsuperregister = (
  284. RS_R13,RS_R14,RS_R15,RS_R16,RS_R17,RS_R18,RS_R19,
  285. RS_R20,RS_R21,RS_R22,RS_R23,RS_R24,RS_R25,RS_R26,RS_R27,RS_R28,RS_R29,
  286. RS_R30,RS_R31
  287. );
  288. { this is only for the generic code which is not used for this architecture }
  289. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  290. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  291. {# Required parameter alignment when calling a routine declared as
  292. stdcall and cdecl. The alignment value should be the one defined
  293. by GCC or the target ABI.
  294. The value of this constant is equal to the constant
  295. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  296. }
  297. std_param_align = 4; { for 32-bit version only }
  298. {*****************************************************************************
  299. CPU Dependent Constants
  300. *****************************************************************************}
  301. LinkageAreaSizeAIX = 24;
  302. LinkageAreaSizeSYSV = 8;
  303. { offset in the linkage area for the saved stack pointer }
  304. LA_SP = 0;
  305. { offset in the linkage area for the saved conditional register}
  306. LA_CR_AIX = 4;
  307. { offset in the linkage area for the saved link register}
  308. LA_LR_AIX = 8;
  309. LA_LR_SYSV = 4;
  310. { offset in the linkage area for the saved RTOC register}
  311. LA_RTOC_AIX = 20;
  312. PARENT_FRAMEPOINTER_OFFSET = 12;
  313. NR_RTOC = NR_R2;
  314. maxfpuregs = 8;
  315. { minimum size of the stack frame if one exists }
  316. MINIMUM_STACKFRAME_SIZE = 56;
  317. {*****************************************************************************
  318. Helpers
  319. *****************************************************************************}
  320. function is_calljmp(o:tasmop):boolean;
  321. procedure inverse_flags(var r : TResFlags);
  322. function flags_to_cond(const f: TResFlags) : TAsmCond;
  323. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  324. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  325. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  326. { Returns the tcgsize corresponding with the size of reg.}
  327. function reg_cgsize(const reg: tregister) : tcgsize;
  328. function findreg_by_number(r:Tregister):tregisterindex;
  329. function std_regnum_search(const s:string):Tregister;
  330. function std_regname(r:Tregister):string;
  331. function is_condreg(r : tregister):boolean;
  332. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  333. function conditions_equal(const c1, c2: TAsmCond): boolean;
  334. function dwarf_reg(r:tregister):shortint;
  335. implementation
  336. uses
  337. rgbase,verbose;
  338. const
  339. std_regname_table : TRegNameTable = (
  340. {$i rppcstd.inc}
  341. );
  342. regnumber_index : array[tregisterindex] of tregisterindex = (
  343. {$i rppcrni.inc}
  344. );
  345. std_regname_index : array[tregisterindex] of tregisterindex = (
  346. {$i rppcsri.inc}
  347. );
  348. {*****************************************************************************
  349. Helpers
  350. *****************************************************************************}
  351. function is_calljmp(o:tasmop):boolean;
  352. begin
  353. is_calljmp:=false;
  354. case o of
  355. A_B,A_BA,A_BL,A_BLA,A_BC,A_BCA,A_BCL,A_BCLA,A_BCCTR,A_BCCTRL,A_BCLR,
  356. A_BCLRL,A_TW,A_TWI: is_calljmp:=true;
  357. end;
  358. end;
  359. procedure inverse_flags(var r: TResFlags);
  360. const
  361. inv_flags: array[F_EQ..F_GE] of TResFlagsEnum =
  362. (F_NE,F_EQ,F_GE,F_GE,F_LE,F_LT);
  363. begin
  364. r.flag := inv_flags[r.flag];
  365. end;
  366. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  367. const
  368. inv_condflags:array[TAsmCondFlag] of TAsmCondFlag=(C_None,
  369. C_GE,C_GT,C_NE,C_LT,C_LE,C_LT,C_EQ,C_GT,C_NS,C_SO,C_NU,C_UN,
  370. C_F,C_T,C_DNZ,C_DNZF,C_DNZT,C_DZ,C_DZF,C_DZT);
  371. begin
  372. if (c.cond in [C_DNZ,C_DZ]) then
  373. internalerror(2005022501);
  374. result := c;
  375. result.cond := inv_condflags[c.cond];
  376. end;
  377. function conditions_equal(const c1, c2: TAsmCond): boolean;
  378. begin
  379. result :=
  380. (c1.simple and c2.simple) and
  381. (c1.cond = c2.cond) and
  382. ((not(c1.cond in [C_T..C_DZF]) and
  383. (c1.cr = c2.cr)) or
  384. (c1.crbit = c2.crbit));
  385. end;
  386. function flags_to_cond(const f: TResFlags) : TAsmCond;
  387. const
  388. flag_2_cond: array[F_EQ..F_SO] of TAsmCondFlag =
  389. (C_EQ,C_NE,C_LT,C_LE,C_GT,C_GE,C_SO);
  390. begin
  391. if f.flag > high(flag_2_cond) then
  392. internalerror(200112301);
  393. result.simple := true;
  394. result.cr := f.cr;
  395. result.cond := flag_2_cond[f.flag];
  396. end;
  397. procedure create_cond_imm(BO,BI:byte;var r : TAsmCond);
  398. begin
  399. r.simple := false;
  400. r.bo := bo;
  401. r.bi := bi;
  402. end;
  403. procedure create_cond_norm(cond: TAsmCondFlag; cr: byte;var r : TasmCond);
  404. begin
  405. r.dirhint := DH_None;
  406. r.simple := true;
  407. r.cond := cond;
  408. case cond of
  409. C_NONE:;
  410. C_T..C_DZF: r.crbit := cr
  411. else r.cr := RS_CR0+cr;
  412. end;
  413. end;
  414. function is_condreg(r : tregister):boolean;
  415. var
  416. supreg: tsuperregister;
  417. begin
  418. result := false;
  419. if (getregtype(r) = R_SPECIALREGISTER) then
  420. begin
  421. supreg := getsupreg(r);
  422. result := (supreg >= RS_CR0) and (supreg <= RS_CR7);
  423. end;
  424. end;
  425. function reg_cgsize(const reg: tregister): tcgsize;
  426. begin
  427. case getregtype(reg) of
  428. R_INTREGISTER :
  429. result:=OS_32;
  430. R_MMREGISTER:
  431. result:=OS_M128;
  432. R_FPUREGISTER:
  433. result:=OS_F64;
  434. else
  435. internalerror(200303181);
  436. end;
  437. end;
  438. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  439. begin
  440. cgsize2subreg:=R_SUBWHOLE;
  441. end;
  442. function findreg_by_number(r:Tregister):tregisterindex;
  443. begin
  444. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  445. end;
  446. function std_regnum_search(const s:string):Tregister;
  447. begin
  448. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  449. end;
  450. function std_regname(r:Tregister):string;
  451. var
  452. p : tregisterindex;
  453. begin
  454. p:=findreg_by_number_table(r,regnumber_index);
  455. if p<>0 then
  456. result:=std_regname_table[p]
  457. else
  458. result:=generic_regname(r);
  459. end;
  460. function dwarf_reg(r:tregister):shortint;
  461. begin
  462. result:=regdwarf_table[findreg_by_number(r)];
  463. if result=-1 then
  464. internalerror(200603251);
  465. end;
  466. end.