cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. { warning: CPU32 opcodes are not fully compatible with the MC68020. }
  30. { 68000 only opcodes }
  31. tasmop = (a_none,
  32. a_abcd,a_add,a_adda,a_addi,a_addq,a_addx,a_and,a_andi,
  33. a_asl,a_asr,a_bcc,a_bcs,a_beq,a_bge,a_bgt,a_bhi,
  34. a_ble,a_bls,a_blt,a_bmi,a_bne,a_bpl,a_bvc,a_bvs,
  35. a_bchg,a_bclr,a_bra,a_bset,a_bsr,a_btst,a_chk,
  36. a_clr,a_cmp,a_cmpa,a_cmpi,a_cmpm,a_dbcc,a_dbcs,a_dbeq,a_dbge,
  37. a_dbgt,a_dbhi,a_dble,a_dbls,a_dblt,a_dbmi,a_dbne,a_dbra,
  38. a_dbpl,a_dbt,a_dbvc,a_dbvs,a_dbf,a_divs,a_divu,
  39. a_eor,a_eori,a_exg,a_illegal,a_ext,a_jmp,a_jsr,
  40. a_lea,a_link,a_lsl,a_lsr,a_move,a_movea,a_movei,a_moveq,
  41. a_movem,a_movep,a_muls,a_mulu,a_nbcd,a_neg,a_negx,
  42. a_nop,a_not,a_or,a_ori,a_pea,a_rol,a_ror,a_roxl,
  43. a_roxr,a_rtr,a_rts,a_sbcd,a_scc,a_scs,a_seq,a_sge,
  44. a_sgt,a_shi,a_sle,a_sls,a_slt,a_smi,a_sne,
  45. a_spl,a_st,a_svc,a_svs,a_sf,a_sub,a_suba,a_subi,a_subq,
  46. a_subx,a_swap,a_tas,a_trap,a_trapv,a_tst,a_unlk,
  47. a_rte,a_reset,a_stop,
  48. { mc68010 instructions }
  49. a_bkpt,a_movec,a_moves,a_rtd,
  50. { mc68020 instructions }
  51. a_bfchg,a_bfclr,a_bfexts,a_bfextu,a_bfffo,
  52. a_bfins,a_bfset,a_bftst,a_callm,a_cas,a_cas2,
  53. a_chk2,a_cmp2,a_divsl,a_divul,a_extb,a_pack,a_rtm,
  54. a_trapcc,a_tracs,a_trapeq,a_trapf,a_trapge,a_trapgt,
  55. a_traphi,a_traple,a_trapls,a_traplt,a_trapmi,a_trapne,
  56. a_trappl,a_trapt,a_trapvc,a_trapvs,a_unpk,
  57. { mc64040 instructions }
  58. a_move16,
  59. { coldfire v4 instructions }
  60. a_mov3q,a_mvz,a_mvs,a_sats,a_byterev,a_ff1,a_remu,a_rems,
  61. { fpu processor instructions - directly supported }
  62. { ieee aware and misc. condition codes not supported }
  63. a_fabs,a_fsabs,a_fdabs,a_fadd,a_fsadd,a_fdadd,
  64. a_fbeq,a_fbne,a_fbngt,a_fbgt,a_fbge,a_fbnge,
  65. a_fblt,a_fbnlt,a_fble,a_fbgl,a_fbngl,a_fbgle,a_fbngle,
  66. a_fdbeq,a_fdbne,a_fdbgt,a_fdbngt,a_fdbge,a_fdbnge,
  67. a_fdblt,a_fdbnlt,a_fdble,a_fdbgl,a_fdbngl,a_fdbgle,a_fdbngle,
  68. a_fseq,a_fsne,a_fsgt,a_fsngt,a_fsge,a_fsnge,
  69. a_fslt,a_fsnlt,a_fsle,a_fsgl,a_fsngl,a_fsgle,a_fsngle,
  70. a_fcmp,a_fdiv,a_fsdiv,a_fddiv,a_fmove,a_fsmove,a_fdmove,a_fmovem,
  71. a_fmul,a_fsmul,a_fdmul,a_fneg,a_fsneg,a_fdneg,a_fnop,a_fsqrt,a_fssqrt,a_fdsqrt,
  72. a_fsub,a_fssub,a_fdsub,a_fsgldiv,a_fsglmul,a_ftst,
  73. a_ftrapeq,a_ftrapne,a_ftrapgt,a_ftrapngt,a_ftrapge,a_ftrapnge,
  74. a_ftraplt,a_ftrapnlt,a_ftraple,a_ftrapgl,a_ftrapngl,a_ftrapgle,a_ftrapngle,
  75. a_fint,a_fintrz,
  76. { fpu instructions - indirectly supported }
  77. a_fsin,a_fcos,
  78. { protected instructions }
  79. a_cprestore,a_cpsave,
  80. { fpu unit protected instructions }
  81. { and 68030/68851 common mmu instructions }
  82. { (this may include 68040 mmu instructions) }
  83. a_frestore,a_fsave,a_pflush,a_pflusha,a_pload,a_pmove,a_ptest,
  84. { useful for assembly language output }
  85. a_label,a_dbxx,a_sxx,a_bxx,a_fsxx,a_fbxx);
  86. {# This should define the array of instructions as string }
  87. op2strtable=array[tasmop] of string[11];
  88. Const
  89. {# First value of opcode enumeration }
  90. firstop = low(tasmop);
  91. {# Last value of opcode enumeration }
  92. lastop = high(tasmop);
  93. {*****************************************************************************
  94. Registers
  95. *****************************************************************************}
  96. type
  97. { Number of registers used for indexing in tables }
  98. tregisterindex=0..{$i r68knor.inc}-1;
  99. const
  100. { Available Superregisters }
  101. {$i r68ksup.inc}
  102. RS_SP = RS_A7;
  103. R_SUBWHOLE = R_SUBD;
  104. { Available Registers }
  105. {$i r68kcon.inc}
  106. NR_SP = NR_A7;
  107. { Integer Super registers first and last }
  108. first_int_imreg = RS_D7+1;
  109. { Float Super register first and last }
  110. first_fpu_imreg = RS_FP7+1;
  111. { Integer Super registers first and last }
  112. first_addr_imreg = RS_SP+1;
  113. { MM Super register first and last }
  114. first_mm_supreg = 0;
  115. first_mm_imreg = 0;
  116. maxfpuregs = 8;
  117. { include regnumber_count_bsstart }
  118. {$i r68kbss.inc}
  119. regnumber_table : array[tregisterindex] of tregister = (
  120. {$i r68knum.inc}
  121. );
  122. regstabs_table : array[tregisterindex] of shortint = (
  123. {$i r68ksta.inc}
  124. );
  125. regdwarf_table : array[tregisterindex] of shortint = (
  126. { TODO: reused stabs values!}
  127. {$i r68ksta.inc}
  128. );
  129. { registers which may be destroyed by calls }
  130. VOLATILE_INTREGISTERS = [RS_D0,RS_D1];
  131. VOLATILE_FPUREGISTERS = [RS_FP0,RS_FP1];
  132. VOLATILE_ADDRESSREGISTERS = [RS_A0,RS_A1];
  133. {*****************************************************************************
  134. Conditions
  135. *****************************************************************************}
  136. type
  137. TAsmCond=(C_None,
  138. C_CC,C_LS,C_CS,C_LT,C_EQ,C_MI,C_F,C_NE,
  139. C_GE,C_PL,C_GT,C_T,C_HI,C_VC,C_LE,C_VS
  140. );
  141. const
  142. cond2str:array[TAsmCond] of string[3]=('',
  143. 'cc','ls','cs','lt','eq','mi','f','ne',
  144. 'ge','pl','gt','t','hi','vc','le','vs'
  145. );
  146. {*****************************************************************************
  147. Flags
  148. *****************************************************************************}
  149. type
  150. TResFlags = (
  151. F_E,F_NE,
  152. F_G,F_L,F_GE,F_LE,F_C,F_NC,F_A,F_AE,F_B,F_BE,
  153. F_FE,F_FNE,
  154. F_FG,F_FL,F_FGE,F_FLE
  155. );
  156. const
  157. FloatResFlags = [F_FE..F_FLE];
  158. {*****************************************************************************
  159. Reference
  160. *****************************************************************************}
  161. type
  162. { direction of address register : }
  163. { (An) (An)+ -(An) }
  164. tdirection = (dir_none,dir_inc,dir_dec);
  165. {*****************************************************************************
  166. Operand Sizes
  167. *****************************************************************************}
  168. { S_NO = No Size of operand }
  169. { S_B = 8-bit size operand }
  170. { S_W = 16-bit size operand }
  171. { S_L = 32-bit size operand }
  172. { Floating point types }
  173. { S_FS = single type (32 bit) }
  174. { S_FD = double/64bit integer }
  175. { S_FX = Extended type }
  176. topsize = (S_NO,S_B,S_W,S_L,S_FS,S_FD,S_FX,S_IQ);
  177. {*****************************************************************************
  178. Constants
  179. *****************************************************************************}
  180. const
  181. {# maximum number of operands in assembler instruction }
  182. max_operands = 4;
  183. {*****************************************************************************
  184. Default generic sizes
  185. *****************************************************************************}
  186. {# Defines the default address size for a processor, }
  187. OS_ADDR = OS_32;
  188. {# the natural int size for a processor,
  189. has to match osuinttype/ossinttype as initialized in psystem }
  190. OS_INT = OS_32;
  191. OS_SINT = OS_S32;
  192. {# the maximum float size for a processor, }
  193. OS_FLOAT = OS_F64;
  194. {# the size of a vector register for a processor }
  195. OS_VECTOR = OS_M128;
  196. {*****************************************************************************
  197. GDB Information
  198. *****************************************************************************}
  199. {# Register indexes for stabs information, when some
  200. parameters or variables are stored in registers.
  201. Taken from m68kelf.h (DBX_REGISTER_NUMBER)
  202. from GCC 3.x source code.
  203. This is not compatible with the m68k-sun
  204. implementation.
  205. }
  206. stab_regindex : array[tregisterindex] of shortint =
  207. (
  208. {$i r68ksta.inc}
  209. );
  210. {*****************************************************************************
  211. Generic Register names
  212. *****************************************************************************}
  213. {# Stack pointer register }
  214. NR_STACK_POINTER_REG = NR_SP;
  215. RS_STACK_POINTER_REG = RS_SP;
  216. {# Frame pointer register }
  217. { Frame pointer register (initialized in tcpuprocinfo.init_framepointer) }
  218. RS_FRAME_POINTER_REG: tsuperregister = RS_NO;
  219. NR_FRAME_POINTER_REG: tregister = NR_NO;
  220. {# Register for addressing absolute data in a position independant way,
  221. such as in PIC code. The exact meaning is ABI specific. For
  222. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  223. }
  224. RS_PIC_OFFSET_REG: tsuperregister = RS_NO;
  225. NR_PIC_OFFSET_REG: tregister = NR_NO;
  226. { Return address for DWARF }
  227. NR_RETURN_ADDRESS_REG = NR_A0;
  228. RS_RETURN_ADDRESS_REG = RS_A0;
  229. { Results are returned in this register (32-bit values) }
  230. NR_FUNCTION_RETURN_REG = NR_D0;
  231. RS_FUNCTION_RETURN_REG = RS_D0;
  232. { Low part of 64bit return value }
  233. NR_FUNCTION_RETURN64_LOW_REG = NR_D0;
  234. RS_FUNCTION_RETURN64_LOW_REG = RS_D0;
  235. { High part of 64bit return value }
  236. NR_FUNCTION_RETURN64_HIGH_REG = NR_D1;
  237. RS_FUNCTION_RETURN64_HIGH_REG = RS_D1;
  238. { The value returned from a function is available in this register }
  239. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  240. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  241. { The lowh part of 64bit value returned from a function }
  242. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  243. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  244. { The high part of 64bit value returned from a function }
  245. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  246. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  247. {# Floating point results will be placed into this register }
  248. NR_FPU_RESULT_REG = NR_FP0;
  249. {# This is m68k C ABI specific. Some ABIs expect the address of the
  250. return struct result value in this register. Note that it could be
  251. either A0 or A1, so later it must be decided on target/ABI specific
  252. basis. We start with A1 now, because that's what Linux/m68k does
  253. currently. (KB) }
  254. RS_M68K_STRUCT_RESULT_REG: tsuperregister = RS_A1;
  255. NR_M68K_STRUCT_RESULT_REG: tregister = NR_A1;
  256. NR_DEFAULTFLAGS = NR_SR;
  257. RS_DEFAULTFLAGS = RS_SR;
  258. {*****************************************************************************
  259. GCC /ABI linking information
  260. *****************************************************************************}
  261. {# Required parameter alignment when calling a routine declared as
  262. stdcall and cdecl. The alignment value should be the one defined
  263. by GCC or the target ABI.
  264. The value of this constant is equal to the constant
  265. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  266. }
  267. std_param_align = 4; { for 32-bit version only }
  268. {*****************************************************************************
  269. CPU Dependent Constants
  270. *****************************************************************************}
  271. {*****************************************************************************
  272. Helpers
  273. *****************************************************************************}
  274. const
  275. tcgsize2opsize: Array[tcgsize] of topsize =
  276. (S_NO,S_B,S_W,S_L,S_L,S_NO,S_B,S_W,S_L,S_L,S_NO,
  277. S_FS,S_FD,S_FX,S_NO,S_NO,
  278. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,
  279. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,
  280. S_NO,S_NO,S_NO,S_NO,S_NO,
  281. S_NO,S_NO,S_NO,S_NO,S_NO);
  282. function is_calljmp(o:tasmop):boolean;
  283. procedure inverse_flags(var r : TResFlags);
  284. function flags_to_cond(const f: TResFlags) : TAsmCond;
  285. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  286. function reg_cgsize(const reg: tregister): tcgsize;
  287. function findreg_by_number(r:Tregister):tregisterindex;
  288. function std_regnum_search(const s:string):Tregister;
  289. function std_regname(r:Tregister):string;
  290. function isaddressregister(reg : tregister) : boolean;
  291. function isintregister(reg : tregister) : boolean;
  292. function fpuregopsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  293. function fpuregsize: aint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  294. function needs_unaligned(const refalignment: aint; const size: tcgsize): boolean;
  295. function isregoverlap(reg1: tregister; reg2: tregister): boolean;
  296. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  297. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  298. function dwarf_reg(r:tregister):shortint;
  299. function dwarf_reg_no_error(r:tregister):shortint;
  300. function eh_return_data_regno(nr: longint): longint;
  301. function isvalue8bit(val: tcgint): boolean;
  302. function isvalue16bit(val: tcgint): boolean;
  303. function isvalueforaddqsubq(val: tcgint): boolean;
  304. implementation
  305. uses
  306. verbose,
  307. rgbase;
  308. const
  309. std_regname_table : TRegNameTable = (
  310. {$i r68kstd.inc}
  311. );
  312. regnumber_index : array[tregisterindex] of tregisterindex = (
  313. {$i r68krni.inc}
  314. );
  315. std_regname_index : array[tregisterindex] of tregisterindex = (
  316. {$i r68ksri.inc}
  317. );
  318. {*****************************************************************************
  319. Helpers
  320. *****************************************************************************}
  321. function is_calljmp(o:tasmop):boolean;
  322. begin
  323. case o of
  324. A_BXX,A_FBXX,A_DBXX,
  325. A_BCC..A_BVS,
  326. A_DBCC..A_DBVS,
  327. A_FBEQ..A_FSNGLE,
  328. A_JSR,A_BSR,A_JMP:
  329. is_calljmp:=true;
  330. else
  331. is_calljmp:=false;
  332. end;
  333. end;
  334. procedure inverse_flags(var r: TResFlags);
  335. const flagsinvers : array[F_E..F_FLE] of tresflags =
  336. (F_NE,F_E,
  337. F_LE,F_GE,
  338. F_L,F_G,
  339. F_NC,F_C,
  340. F_BE,F_B,
  341. F_AE,F_A,
  342. F_FNE,F_FE,
  343. F_FLE,F_FGE,
  344. F_FL,F_G);
  345. begin
  346. r:=flagsinvers[r];
  347. end;
  348. function flags_to_cond(const f: TResFlags) : TAsmCond;
  349. const flags2cond: array[tresflags] of tasmcond = (
  350. C_EQ,{F_E equal}
  351. C_NE,{F_NE not equal}
  352. C_GT,{F_G gt signed}
  353. C_LT,{F_L lt signed}
  354. C_GE,{F_GE ge signed}
  355. C_LE,{F_LE le signed}
  356. C_CS,{F_C carry set}
  357. C_CC,{F_NC carry clear}
  358. C_HI,{F_A gt unsigned}
  359. C_CC,{F_AE ge unsigned}
  360. C_CS,{F_B lt unsigned}
  361. C_LS,{F_BE le unsigned}
  362. C_EQ,{F_FEQ }
  363. C_NE,{F_FNE }
  364. C_GT,{F_FG }
  365. C_LT,{F_FL }
  366. C_GE,{F_FGE }
  367. C_LE);{F_FLE }
  368. begin
  369. flags_to_cond := flags2cond[f];
  370. end;
  371. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  372. begin
  373. case regtype of
  374. R_INTREGISTER:
  375. if (CPUM68K_HAS_BYTEWORDMATH in cpu_capabilities[current_settings.cputype]) then
  376. case s of
  377. OS_8,OS_S8:
  378. cgsize2subreg:=R_SUBL;
  379. OS_16,OS_S16:
  380. cgsize2subreg:=R_SUBW;
  381. OS_32,OS_S32:
  382. cgsize2subreg:=R_SUBD;
  383. OS_64,OS_S64:
  384. cgsize2subreg:=R_SUBWHOLE;
  385. OS_NO:
  386. cgsize2subreg:=R_SUBNONE;
  387. else
  388. internalerror(2019090801);
  389. end
  390. else
  391. case s of
  392. OS_8,OS_S8,
  393. OS_16,OS_S16,
  394. OS_32,OS_S32,
  395. OS_64,OS_S64:
  396. cgsize2subreg:=R_SUBWHOLE;
  397. OS_NO:
  398. cgsize2subreg:=R_SUBNONE;
  399. else
  400. internalerror(2019090803);
  401. end;
  402. R_ADDRESSREGISTER:
  403. cgsize2subreg:=R_SUBWHOLE;
  404. R_FPUREGISTER:
  405. cgsize2subreg:=R_SUBNONE;
  406. else
  407. internalerror(2019090802);
  408. end;
  409. end;
  410. function reg_cgsize(const reg: tregister): tcgsize;
  411. { 68881 & compatibles -> 80 bit }
  412. { CF FPU -> 64 bit }
  413. const
  414. fpureg_cgsize: array[boolean] of tcgsize = ( OS_F80, OS_F64 );
  415. begin
  416. case getregtype(reg) of
  417. R_ADDRESSREGISTER,
  418. R_INTREGISTER :
  419. result:=OS_32;
  420. R_FPUREGISTER :
  421. result:=fpureg_cgsize[current_settings.fputype = fpu_coldfire];
  422. else
  423. internalerror(200303181);
  424. end;
  425. end;
  426. function findreg_by_number(r:Tregister):tregisterindex;
  427. begin
  428. result:=findreg_by_number_table(r,regnumber_index);
  429. end;
  430. function std_regnum_search(const s:string):Tregister;
  431. begin
  432. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  433. end;
  434. function std_regname(r:Tregister):string;
  435. var
  436. p : tregisterindex;
  437. begin
  438. p:=findreg_by_number_table(r,regnumber_index);
  439. if p<>0 then
  440. result:=std_regname_table[p]
  441. else
  442. result:=generic_regname(r);
  443. end;
  444. function isaddressregister(reg : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  445. begin
  446. result:=getregtype(reg)=R_ADDRESSREGISTER;
  447. end;
  448. function isintregister(reg : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  449. begin
  450. result:=getregtype(reg)=R_INTREGISTER;
  451. end;
  452. function fpuregopsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  453. const
  454. fpu_regopsize: array[boolean] of TOpSize = ( S_FX, S_FD );
  455. begin
  456. result:=fpu_regopsize[current_settings.fputype = fpu_coldfire];
  457. end;
  458. function fpuregsize: aint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  459. const
  460. fpu_regsize: array[boolean] of aint = ( 12, 8 ); { S_FX is 12 bytes on '881 }
  461. begin
  462. result:=fpu_regsize[current_settings.fputype = fpu_coldfire];
  463. end;
  464. function needs_unaligned(const refalignment: aint; const size: tcgsize): boolean;
  465. begin
  466. result:=not(CPUM68K_HAS_UNALIGNED in cpu_capabilities[current_settings.cputype]) and
  467. (refalignment = 1) and
  468. (tcgsize2size[size] > 1);
  469. end;
  470. // the function returns true, if the registers overlap (subreg of the same superregister and same type)
  471. function isregoverlap(reg1: tregister; reg2: tregister): boolean;
  472. begin
  473. tregisterrec(reg1).subreg:=R_SUBNONE;
  474. tregisterrec(reg2).subreg:=R_SUBNONE;
  475. result:=reg1=reg2;
  476. end;
  477. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  478. const
  479. inverse:array[TAsmCond] of TAsmCond=(C_None,
  480. //C_CC,C_LS,C_CS,C_LT,C_EQ,C_MI,C_F,C_NE,
  481. C_CS,C_HI,C_CC,C_GE,C_NE,C_PL,C_T,C_EQ,
  482. //C_GE,C_PL,C_GT,C_T,C_HI,C_VC,C_LE,C_VS
  483. C_LT,C_MI,C_LE,C_F,C_LS,C_VS,C_GT,C_VC
  484. );
  485. begin
  486. result := inverse[c];
  487. end;
  488. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  489. begin
  490. result := c1 = c2;
  491. end;
  492. function dwarf_reg(r:tregister):shortint;
  493. begin
  494. result:=regdwarf_table[findreg_by_number(r)];
  495. if result=-1 then
  496. internalerror(200603251);
  497. end;
  498. function dwarf_reg_no_error(r:tregister):shortint;
  499. begin
  500. result:=regdwarf_table[findreg_by_number(r)];
  501. end;
  502. function eh_return_data_regno(nr: longint): longint;
  503. begin
  504. result:=-1;
  505. end;
  506. { returns true if given value fits to an 8bit signed integer }
  507. function isvalue8bit(val: tcgint): boolean;
  508. begin
  509. isvalue8bit := (val >= low(shortint)) and (val <= high(shortint));
  510. end;
  511. { returns true if given value fits to a 16bit signed integer }
  512. function isvalue16bit(val: tcgint): boolean;
  513. begin
  514. isvalue16bit := (val >= low(smallint)) and (val <= high(smallint));
  515. end;
  516. { returns true if given value fits addq/subq argument, so in 1 - 8 range }
  517. function isvalueforaddqsubq(val: tcgint): boolean;
  518. begin
  519. isvalueforaddqsubq := (val >= 1) and (val <= 8);
  520. end;
  521. end.