cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Contains the base types for the m68k
  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 m68k
  18. }
  19. unit cpubase;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,globals,
  24. strings,cutils,cclasses,aasmbase,cpuinfo,cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. tasmop = {$i m68kop.inc}
  30. {# This should define the array of instructions as string }
  31. op2strtable=array[tasmop] of string[11];
  32. Const
  33. {# First value of opcode enumeration }
  34. firstop = low(tasmop);
  35. {# Last value of opcode enumeration }
  36. lastop = high(tasmop);
  37. {*****************************************************************************
  38. Registers
  39. *****************************************************************************}
  40. type
  41. { Number of registers used for indexing in tables }
  42. tregisterindex=0..{$i r68knor.inc}-1;
  43. const
  44. { Available Superregisters }
  45. {$i r68ksup.inc}
  46. RS_SP = RS_A7;
  47. R_SUBWHOLE = R_SUBD;
  48. { Available Registers }
  49. {$i r68kcon.inc}
  50. NR_SP = NR_A7;
  51. { Integer Super registers first and last }
  52. first_int_imreg = 8;
  53. { Float Super register first and last }
  54. first_fpu_imreg = 8;
  55. { Integer Super registers first and last }
  56. first_addr_imreg = 8;
  57. { MM Super register first and last }
  58. first_mm_supreg = 0;
  59. first_mm_imreg = 0;
  60. maxfpuregs = 8;
  61. { include regnumber_count_bsstart }
  62. {$i r68kbss.inc}
  63. regnumber_table : array[tregisterindex] of tregister = (
  64. {$i r68knum.inc}
  65. );
  66. regstabs_table : array[tregisterindex] of shortint = (
  67. {$i r68ksta.inc}
  68. );
  69. regdwarf_table : array[tregisterindex] of shortint = (
  70. { TODO: reused stabs values!}
  71. {$i r68ksta.inc}
  72. );
  73. { registers which may be destroyed by calls }
  74. VOLATILE_INTREGISTERS = [RS_D0,RS_D1];
  75. VOLATILE_FPUREGISTERS = [RS_FP0,RS_FP1];
  76. VOLATILE_ADDRESSREGISTERS = [RS_A0,RS_A1];
  77. {*****************************************************************************
  78. Conditions
  79. *****************************************************************************}
  80. type
  81. TAsmCond=(C_None,
  82. C_CC,C_LS,C_CS,C_LT,C_EQ,C_MI,C_F,C_NE,
  83. C_GE,C_PL,C_GT,C_T,C_HI,C_VC,C_LE,C_VS
  84. );
  85. const
  86. cond2str:array[TAsmCond] of string[3]=('',
  87. 'cc','ls','cs','lt','eq','mi','f','ne',
  88. 'ge','pl','gt','t','hi','vc','le','vs'
  89. );
  90. const
  91. cond2bxx: array[TAsmCond] of tasmop = (A_NONE,
  92. A_BCC, A_BLS, A_BCS, A_BLT, A_BEQ, A_BMI, A_NONE, A_BNE,
  93. A_BGE, A_BPL, A_BGT, A_NONE, A_BHI, A_BVC, A_BLE, A_BVS
  94. );
  95. cond2sxx: array[TAsmCond] of tasmop = (A_NONE,
  96. A_SCC, A_SLS, A_SCS, A_SLT, A_SEQ, A_SMI, A_SF, A_SNE,
  97. A_SGE, A_SPL, A_SGT, A_ST, A_SHI, A_SVC, A_SLE, A_SVS
  98. );
  99. cond2fsxx: array[TAsmCond] of tasmop = (A_NONE,
  100. A_NONE, A_NONE, A_NONE, A_FSLT, A_FSEQ, A_NONE, A_FSF, A_FSNE,
  101. A_FSGE, A_NONE, A_FSGT, A_FST, A_NONE, A_NONE, A_FSLE, A_NONE
  102. );
  103. cond2dbxx: array[TAsmCond] of tasmop = (A_NONE,
  104. A_DBCC, A_DBLS, A_DBCS, A_DBLT, A_DBEQ, A_DBMI, A_DBF, A_DBNE,
  105. A_DBGE, A_DBPL, A_DBGT, A_DBT, A_DBHI, A_DBVC, A_DBLE, A_DBVS
  106. );
  107. cond2jxx: array[TAsmCond] of tasmop = (A_NONE,
  108. A_JCC, A_JLS, A_JCS, A_JLT, A_JEQ, A_JMI, A_NONE, A_JNE,
  109. A_JGE, A_JPL, A_JGT, A_NONE, A_JHI, A_JVC, A_JLE, A_JVS
  110. );
  111. cond2fjxx: array[TAsmCond] of tasmop = (A_NONE,
  112. A_NONE, A_NONE, A_NONE, A_FJLT, A_FJEQ, A_NONE, A_FJF, A_FJNE,
  113. A_FJGE, A_NONE, A_FJGT, A_FJT, A_NONE, A_NONE, A_FJLE, A_NONE
  114. );
  115. {*****************************************************************************
  116. Flags
  117. *****************************************************************************}
  118. type
  119. TResFlags = (
  120. F_E,F_NE,
  121. F_G,F_L,F_GE,F_LE,F_C,F_NC,F_A,F_AE,F_B,F_BE,
  122. F_FE,F_FNE,
  123. F_FG,F_FL,F_FGE,F_FLE
  124. );
  125. const
  126. FloatResFlags = [F_FE..F_FLE];
  127. {*****************************************************************************
  128. Reference
  129. *****************************************************************************}
  130. type
  131. { direction of address register : }
  132. { (An) (An)+ -(An) }
  133. tdirection = (dir_none,dir_inc,dir_dec);
  134. {*****************************************************************************
  135. Operand Sizes
  136. *****************************************************************************}
  137. { S_NO = No Size of operand }
  138. { S_B = 8-bit size operand }
  139. { S_W = 16-bit size operand }
  140. { S_L = 32-bit size operand }
  141. { Floating point types }
  142. { S_FS = single type (32 bit) }
  143. { S_FD = double/64bit integer }
  144. { S_FX = Extended type }
  145. topsize = (S_NO,S_B,S_W,S_L,S_FS,S_FD,S_FX);
  146. TOpSizes = set of topsize;
  147. {*****************************************************************************
  148. Constants
  149. *****************************************************************************}
  150. const
  151. {# maximum number of operands in assembler instruction }
  152. max_operands = 6;
  153. {*****************************************************************************
  154. Default generic sizes
  155. *****************************************************************************}
  156. {# Defines the default address size for a processor, }
  157. OS_ADDR = OS_32;
  158. {# the natural int size for a processor,
  159. has to match osuinttype/ossinttype as initialized in psystem }
  160. OS_INT = OS_32;
  161. OS_SINT = OS_S32;
  162. {# the maximum float size for a processor, }
  163. OS_FLOAT = OS_F64;
  164. {# the size of a vector register for a processor }
  165. OS_VECTOR = OS_M128;
  166. {*****************************************************************************
  167. GDB Information
  168. *****************************************************************************}
  169. {# Register indexes for stabs information, when some
  170. parameters or variables are stored in registers.
  171. Taken from m68kelf.h (DBX_REGISTER_NUMBER)
  172. from GCC 3.x source code.
  173. This is not compatible with the m68k-sun
  174. implementation.
  175. }
  176. stab_regindex : array[tregisterindex] of shortint =
  177. (
  178. {$i r68ksta.inc}
  179. );
  180. {*****************************************************************************
  181. Generic Register names
  182. *****************************************************************************}
  183. {# Stack pointer register }
  184. NR_STACK_POINTER_REG = NR_SP;
  185. RS_STACK_POINTER_REG = RS_SP;
  186. {# Frame pointer register }
  187. { Frame pointer register (initialized in tcpuprocinfo.init_framepointer) }
  188. RS_FRAME_POINTER_REG: tsuperregister = RS_NO;
  189. NR_FRAME_POINTER_REG: tregister = NR_NO;
  190. {# Register for addressing absolute data in a position independant way,
  191. such as in PIC code. The exact meaning is ABI specific. For
  192. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  193. }
  194. RS_PIC_OFFSET_REG: tsuperregister = RS_NO;
  195. NR_PIC_OFFSET_REG: tregister = NR_NO;
  196. { Return address for DWARF }
  197. NR_RETURN_ADDRESS_REG = NR_A0;
  198. RS_RETURN_ADDRESS_REG = RS_A0;
  199. { Results are returned in this register (32-bit values) }
  200. NR_FUNCTION_RETURN_REG = NR_D0;
  201. RS_FUNCTION_RETURN_REG = RS_D0;
  202. { Low part of 64bit return value }
  203. NR_FUNCTION_RETURN64_LOW_REG = NR_D0;
  204. RS_FUNCTION_RETURN64_LOW_REG = RS_D0;
  205. { High part of 64bit return value }
  206. NR_FUNCTION_RETURN64_HIGH_REG = NR_D1;
  207. RS_FUNCTION_RETURN64_HIGH_REG = RS_D1;
  208. { The value returned from a function is available in this register }
  209. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  210. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  211. { The lowh part of 64bit value returned from a function }
  212. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  213. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  214. { The high part of 64bit value returned from a function }
  215. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  216. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  217. {# Floating point results will be placed into this register }
  218. NR_FPU_RESULT_REG = NR_FP0;
  219. {# This is m68k C ABI specific. Some ABIs expect the address of the
  220. return struct result value in this register. Note that it could be
  221. either A0 or A1, so later it must be decided on target/ABI specific
  222. basis. We start with A1 now, because that's what Linux/m68k does
  223. currently. (KB) }
  224. RS_M68K_STRUCT_RESULT_REG: tsuperregister = RS_A1;
  225. NR_M68K_STRUCT_RESULT_REG: tregister = NR_A1;
  226. NR_DEFAULTFLAGS = NR_SR;
  227. RS_DEFAULTFLAGS = RS_SR;
  228. {*****************************************************************************
  229. GCC /ABI linking information
  230. *****************************************************************************}
  231. {# Required parameter alignment when calling a routine declared as
  232. stdcall and cdecl. The alignment value should be the one defined
  233. by GCC or the target ABI.
  234. The value of this constant is equal to the constant
  235. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  236. }
  237. std_param_align = 4; { for 32-bit version only }
  238. {*****************************************************************************
  239. CPU Dependent Constants
  240. *****************************************************************************}
  241. {*****************************************************************************
  242. Helpers
  243. *****************************************************************************}
  244. const
  245. tcgsize2opsize: Array[tcgsize] of topsize =
  246. (S_NO,S_B,S_W,S_L,S_L,S_NO,S_B,S_W,S_L,S_L,S_NO,
  247. S_FS,S_FD,S_FX,S_NO,S_NO,
  248. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  249. function is_calljmp(o:tasmop):boolean;
  250. procedure inverse_flags(var r : TResFlags);
  251. function flags_to_cond(const f: TResFlags) : TAsmCond;
  252. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  253. function reg_cgsize(const reg: tregister): tcgsize;
  254. function findreg_by_number(r:Tregister):tregisterindex;
  255. function std_regnum_search(const s:string):Tregister;
  256. function std_regname(r:Tregister):string;
  257. function isaddressregister(reg : tregister) : boolean;
  258. function isintregister(reg : tregister) : boolean;
  259. function isfpuregister(reg : tregister) : boolean;
  260. function fpuregopsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  261. function fpuregsize: aint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  262. function needs_unaligned(const refalignment: aint; const size: tcgsize): boolean;
  263. function isregoverlap(reg1: tregister; reg2: tregister): boolean;
  264. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  265. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  266. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  267. function condition_in(const Subset, c: TAsmCond): Boolean;
  268. function dwarf_reg(r:tregister):shortint;
  269. function dwarf_reg_no_error(r:tregister):shortint;
  270. function eh_return_data_regno(nr: longint): longint;
  271. function isvalue8bit(val: tcgint): boolean;
  272. function isvalue16bit(val: tcgint): boolean;
  273. function isvalueforaddqsubq(val: tcgint): boolean;
  274. implementation
  275. uses
  276. verbose,
  277. rgbase;
  278. const
  279. std_regname_table : TRegNameTable = (
  280. {$i r68kstd.inc}
  281. );
  282. std_regfullname_table : TRegNameTable = (
  283. {$i r68kstdf.inc}
  284. );
  285. regnumber_index : array[tregisterindex] of tregisterindex = (
  286. {$i r68krni.inc}
  287. );
  288. std_regname_index : array[tregisterindex] of tregisterindex = (
  289. {$i r68ksri.inc}
  290. );
  291. {*****************************************************************************
  292. Helpers
  293. *****************************************************************************}
  294. function is_calljmp(o:tasmop):boolean;
  295. begin
  296. case o of
  297. A_BXX,A_FBXX,A_DBXX,
  298. A_BHS,A_BLO,A_BHI,A_BLS,A_BCC,A_BCS,A_BNE,A_BEQ,A_BVC,A_BVS,
  299. A_BPL,A_BMI,A_BGE,A_BLT,A_BGT,A_BLE,A_BRA,
  300. A_DBT,A_DBF,A_DBHI,A_DBLS,A_DBCC,A_DBHS,A_DBCS,A_DBLO,A_DBNE,
  301. A_DBEQ,A_DBVC,A_DBVS,A_DBPL,A_DBMI,A_DBGE,A_DBLT,A_DBGT,A_DBLE,
  302. A_DBRA,
  303. A_FBF,A_FBEQ,A_FBOGT,A_FBOGE,A_FBOLT,A_FBOLE,A_FBOGL,A_FBOR,A_FBUN,
  304. A_FBUEQ,A_FBUGT,A_FBUGE,A_FBULT,A_FBULE,A_FBNE,A_FBT,A_FBSF,A_FBSEQ,
  305. A_FBGT,A_FBGE,A_FBLT,A_FBLE,A_FBGL,A_FBGLE,A_FBNGLE,A_FBNGL,A_FBNLE,
  306. A_FBNLT,A_FBNGE,A_FBNGT,A_FBSNE,A_FBST,
  307. A_FDBF,A_FDBEQ,A_FDBOGT,A_FDBOGE,A_FDBOLT,A_FDBOLE,A_FDBOGL,A_FDBOR,
  308. A_FDBUN,A_FDBUEQ,A_FDBUGT,A_FDBUGE,A_FDBULT,A_FDBULE,A_FDBNE,A_FDBT,
  309. A_FDBSF,A_FDBSEQ,A_FDBGT,A_FDBGE,A_FDBLT,A_FDBLE,A_FDBGL,A_FDBGLE,
  310. A_FDBNGLE,A_FDBNGL,A_FDBNLE,A_FDBNLT,A_FDBNGE,A_FDBNGT,A_FDBSNE,
  311. A_FDBST,
  312. A_JSR,A_BSR,A_JMP:
  313. is_calljmp:=true;
  314. else
  315. is_calljmp:=false;
  316. end;
  317. end;
  318. procedure inverse_flags(var r: TResFlags);
  319. const flagsinvers : array[F_E..F_FLE] of tresflags =
  320. (F_NE,F_E,
  321. F_LE,F_GE,
  322. F_L,F_G,
  323. F_NC,F_C,
  324. F_BE,F_B,
  325. F_AE,F_A,
  326. F_FNE,F_FE,
  327. F_FLE,F_FGE,
  328. F_FL,F_G);
  329. begin
  330. r:=flagsinvers[r];
  331. end;
  332. function flags_to_cond(const f: TResFlags) : TAsmCond;
  333. const flags2cond: array[tresflags] of tasmcond = (
  334. C_EQ,{F_E equal}
  335. C_NE,{F_NE not equal}
  336. C_GT,{F_G gt signed}
  337. C_LT,{F_L lt signed}
  338. C_GE,{F_GE ge signed}
  339. C_LE,{F_LE le signed}
  340. C_CS,{F_C carry set}
  341. C_CC,{F_NC carry clear}
  342. C_HI,{F_A gt unsigned}
  343. C_CC,{F_AE ge unsigned}
  344. C_CS,{F_B lt unsigned}
  345. C_LS,{F_BE le unsigned}
  346. C_EQ,{F_FEQ }
  347. C_NE,{F_FNE }
  348. C_GT,{F_FG }
  349. C_LT,{F_FL }
  350. C_GE,{F_FGE }
  351. C_LE);{F_FLE }
  352. begin
  353. flags_to_cond := flags2cond[f];
  354. end;
  355. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  356. begin
  357. case regtype of
  358. R_INTREGISTER:
  359. if (CPUM68K_HAS_BYTEWORDMATH in cpu_capabilities[current_settings.cputype]) then
  360. case s of
  361. OS_8,OS_S8:
  362. cgsize2subreg:=R_SUBL;
  363. OS_16,OS_S16:
  364. cgsize2subreg:=R_SUBW;
  365. OS_32,OS_S32:
  366. cgsize2subreg:=R_SUBD;
  367. OS_64,OS_S64:
  368. cgsize2subreg:=R_SUBWHOLE;
  369. OS_NO:
  370. cgsize2subreg:=R_SUBNONE;
  371. else
  372. internalerror(2019090801);
  373. end
  374. else
  375. case s of
  376. OS_8,OS_S8,
  377. OS_16,OS_S16,
  378. OS_32,OS_S32,
  379. OS_64,OS_S64:
  380. cgsize2subreg:=R_SUBWHOLE;
  381. OS_NO:
  382. cgsize2subreg:=R_SUBNONE;
  383. else
  384. internalerror(2019090803);
  385. end;
  386. R_ADDRESSREGISTER:
  387. cgsize2subreg:=R_SUBWHOLE;
  388. R_FPUREGISTER:
  389. cgsize2subreg:=R_SUBNONE;
  390. else
  391. internalerror(2019090802);
  392. end;
  393. end;
  394. function reg_cgsize(const reg: tregister): tcgsize;
  395. { 68881 & compatibles -> 80 bit }
  396. { CF FPU -> 64 bit }
  397. const
  398. fpureg_cgsize: array[boolean] of tcgsize = ( OS_F80, OS_F64 );
  399. begin
  400. case getregtype(reg) of
  401. R_ADDRESSREGISTER,
  402. R_INTREGISTER :
  403. result:=OS_32;
  404. R_FPUREGISTER :
  405. result:=fpureg_cgsize[current_settings.fputype = fpu_coldfire];
  406. else
  407. internalerror(200303181);
  408. end;
  409. end;
  410. function findreg_by_number(r:Tregister):tregisterindex;
  411. begin
  412. result:=findreg_by_number_table(r,regnumber_index);
  413. end;
  414. function std_regnum_search(const s:string):Tregister;
  415. begin
  416. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  417. if result=NR_NO then
  418. begin
  419. result:=regnumber_table[findreg_by_name_table(s,std_regfullname_table,std_regname_index)];
  420. end;
  421. end;
  422. function std_regname(r:Tregister):string;
  423. var
  424. p : tregisterindex;
  425. begin
  426. p:=findreg_by_number_table(r,regnumber_index);
  427. if p<>0 then
  428. result:=std_regname_table[p]
  429. else
  430. result:=generic_regname(r);
  431. end;
  432. function isaddressregister(reg : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  433. begin
  434. result:=getregtype(reg)=R_ADDRESSREGISTER;
  435. end;
  436. function isintregister(reg : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  437. begin
  438. result:=getregtype(reg)=R_INTREGISTER;
  439. end;
  440. function isfpuregister(reg : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  441. begin
  442. result:=getregtype(reg)=R_FPUREGISTER;
  443. end;
  444. function fpuregopsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  445. const
  446. fpu_regopsize: array[boolean] of TOpSize = ( S_FX, S_FD );
  447. begin
  448. result:=fpu_regopsize[current_settings.fputype = fpu_coldfire];
  449. end;
  450. function fpuregsize: aint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  451. const
  452. fpu_regsize: array[boolean] of aint = ( 12, 8 ); { S_FX is 12 bytes on '881 }
  453. begin
  454. result:=fpu_regsize[current_settings.fputype = fpu_coldfire];
  455. end;
  456. function needs_unaligned(const refalignment: aint; const size: tcgsize): boolean;
  457. begin
  458. result:=not(CPUM68K_HAS_UNALIGNED in cpu_capabilities[current_settings.cputype]) and
  459. (refalignment = 1) and
  460. (tcgsize2size[size] > 1);
  461. end;
  462. // the function returns true, if the registers overlap (subreg of the same superregister and same type)
  463. function isregoverlap(reg1: tregister; reg2: tregister): boolean;
  464. begin
  465. tregisterrec(reg1).subreg:=R_SUBNONE;
  466. tregisterrec(reg2).subreg:=R_SUBNONE;
  467. result:=reg1=reg2;
  468. end;
  469. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  470. const
  471. inverse:array[TAsmCond] of TAsmCond=(C_None,
  472. //C_CC,C_LS,C_CS,C_LT,C_EQ,C_MI,C_F,C_NE,
  473. C_CS,C_HI,C_CC,C_GE,C_NE,C_PL,C_T,C_EQ,
  474. //C_GE,C_PL,C_GT,C_T,C_HI,C_VC,C_LE,C_VS
  475. C_LT,C_MI,C_LE,C_F,C_LS,C_VS,C_GT,C_VC
  476. );
  477. begin
  478. result := inverse[c];
  479. end;
  480. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  481. begin
  482. result := c1 = c2;
  483. end;
  484. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  485. function condition_in(const Subset, c: TAsmCond): Boolean;
  486. begin
  487. Result := (c = C_None) or conditions_equal(Subset, c);
  488. { Please update as necessary. [Kit] }
  489. if not Result then
  490. case Subset of
  491. C_EQ:
  492. Result := (c in [C_GE, C_LE]);
  493. C_LT:
  494. Result := (c in [C_LE]);
  495. C_GT:
  496. Result := (c in [C_GE]);
  497. else
  498. Result := False;
  499. end;
  500. end;
  501. function dwarf_reg(r:tregister):shortint;
  502. begin
  503. result:=regdwarf_table[findreg_by_number(r)];
  504. if result=-1 then
  505. internalerror(200603251);
  506. end;
  507. function dwarf_reg_no_error(r:tregister):shortint;
  508. begin
  509. result:=regdwarf_table[findreg_by_number(r)];
  510. end;
  511. function eh_return_data_regno(nr: longint): longint;
  512. begin
  513. result:=-1;
  514. end;
  515. { returns true if given value fits to an 8bit signed integer }
  516. function isvalue8bit(val: tcgint): boolean;
  517. begin
  518. isvalue8bit := (val >= low(shortint)) and (val <= high(shortint));
  519. end;
  520. { returns true if given value fits to a 16bit signed integer }
  521. function isvalue16bit(val: tcgint): boolean;
  522. begin
  523. isvalue16bit := (val >= low(smallint)) and (val <= high(smallint));
  524. end;
  525. { returns true if given value fits addq/subq argument, so in 1 - 8 range }
  526. function isvalueforaddqsubq(val: tcgint): boolean;
  527. begin
  528. isvalueforaddqsubq := (val >= 1) and (val <= 8);
  529. end;
  530. end.