cpubase.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Peter Vreman
  3. Contains the base types for the ARM
  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. {# Base unit for processor information. This unit contains
  18. enumerations of registers, opcodes, sizes, and other
  19. such things which are processor specific.
  20. }
  21. unit cpubase;
  22. {$define USEINLINE}
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. globtype,globals,
  27. cpuinfo,
  28. cgbase
  29. ;
  30. {*****************************************************************************
  31. Assembler Opcodes
  32. *****************************************************************************}
  33. type
  34. TAsmOp= {$i armop.inc}
  35. {This is a bit of a hack, because there are more than 256 ARM Assembly Ops
  36. But FPC currently can't handle more than 256 elements in a set.}
  37. TCommonAsmOps = Set of A_None .. A_UADD16;
  38. { This should define the array of instructions as string }
  39. op2strtable=array[tasmop] of string[11];
  40. const
  41. { First value of opcode enumeration }
  42. firstop = low(tasmop);
  43. { Last value of opcode enumeration }
  44. lastop = high(tasmop);
  45. {*****************************************************************************
  46. Registers
  47. *****************************************************************************}
  48. type
  49. { Number of registers used for indexing in tables }
  50. tregisterindex=0..{$i rarmnor.inc}-1;
  51. const
  52. { Available Superregisters }
  53. {$i rarmsup.inc}
  54. RS_PC = RS_R15;
  55. { No Subregisters }
  56. R_SUBWHOLE = R_SUBNONE;
  57. { Available Registers }
  58. {$i rarmcon.inc}
  59. { aliases }
  60. NR_PC = NR_R15;
  61. { Integer Super registers first and last }
  62. first_int_supreg = RS_R0;
  63. first_int_imreg = $10;
  64. { Float Super register first and last }
  65. first_fpu_supreg = RS_F0;
  66. first_fpu_imreg = $08;
  67. { MM Super register first and last }
  68. first_mm_supreg = RS_S0;
  69. first_mm_imreg = $30;
  70. { TODO: Calculate bsstart}
  71. regnumber_count_bsstart = 128;
  72. regnumber_table : array[tregisterindex] of tregister = (
  73. {$i rarmnum.inc}
  74. );
  75. regstabs_table : array[tregisterindex] of shortint = (
  76. {$i rarmsta.inc}
  77. );
  78. regdwarf_table : array[tregisterindex] of shortint = (
  79. {$i rarmdwa.inc}
  80. );
  81. { registers which may be destroyed by calls }
  82. VOLATILE_INTREGISTERS = [RS_R0..RS_R3,RS_R12..RS_R14];
  83. VOLATILE_FPUREGISTERS = [RS_F0..RS_F3];
  84. VOLATILE_MMREGISTERS = [RS_D0..RS_D7,RS_D16..RS_D31];
  85. VOLATILE_INTREGISTERS_DARWIN = [RS_R0..RS_R3,RS_R9,RS_R12..RS_R14];
  86. type
  87. totherregisterset = set of tregisterindex;
  88. {*****************************************************************************
  89. Instruction post fixes
  90. *****************************************************************************}
  91. type
  92. { ARM instructions load/store and arithmetic instructions
  93. can have several instruction post fixes which are collected
  94. in this enumeration
  95. }
  96. TOpPostfix = (PF_None,
  97. { update condition flags
  98. or floating point single }
  99. PF_S,
  100. { floating point size }
  101. PF_D,PF_E,PF_P,PF_EP,
  102. { exchange }
  103. PF_X,
  104. { rounding }
  105. PF_R,
  106. { load/store }
  107. PF_B,PF_SB,PF_BT,PF_H,PF_SH,PF_T,
  108. { multiple load/store address modes }
  109. PF_IA,PF_IB,PF_DA,PF_DB,PF_FD,PF_FA,PF_ED,PF_EA,
  110. { multiple load/store vfp address modes }
  111. PF_IAD,PF_DBD,PF_FDD,PF_EAD,
  112. PF_IAS,PF_DBS,PF_FDS,PF_EAS,
  113. PF_IAX,PF_DBX,PF_FDX,PF_EAX,
  114. { VFP postfixes }
  115. PF_8,PF_16,PF_32,PF_64,
  116. PF_I8,PF_I16,PF_I32,PF_I64,
  117. PF_S8,PF_S16,PF_S32,PF_S64,
  118. PF_U8,PF_U16,PF_U32,PF_U64,
  119. PF_P8, // polynomial
  120. PF_F32,PF_F64,
  121. PF_F32F64,PF_F64F32,
  122. PF_F32S16,PF_F32U16,PF_S16F32,PF_U16F32,
  123. PF_F64S16,PF_F64U16,PF_S16F64,PF_U16F64,
  124. PF_F32S32,PF_F32U32,PF_S32F32,PF_U32F32,
  125. PF_F64S32,PF_F64U32,PF_S32F64,PF_U32F64
  126. );
  127. TOpPostfixes = set of TOpPostfix;
  128. TRoundingMode = (RM_None,RM_P,RM_M,RM_Z);
  129. const
  130. cgsize2fpuoppostfix : array[OS_NO..OS_F128] of toppostfix = (
  131. PF_None,
  132. PF_None,PF_None,PF_None,PF_None,PF_None,PF_None,PF_None,PF_None,PF_None,PF_None,
  133. PF_S,PF_D,PF_E,PF_None,PF_None);
  134. oppostfix2str : array[TOpPostfix] of string[8] = ('',
  135. 's',
  136. 'd','e','p','ep',
  137. 'x',
  138. 'r',
  139. 'b','sb','bt','h','sh','t',
  140. 'ia','ib','da','db','fd','fa','ed','ea',
  141. 'iad','dbd','fdd','ead',
  142. 'ias','dbs','fds','eas',
  143. 'iax','dbx','fdx','eax',
  144. '.8','.16','.32','.64',
  145. '.i8','.i16','.i32','.i64',
  146. '.s8','.s16','.s32','.s64',
  147. '.u8','.u16','.u32','.u64',
  148. '.p8',
  149. '.f32','.f64',
  150. '.f32.f64','.f64.f32',
  151. '.f32.s16','.f32.u16','.s16.f32','.u16.f32',
  152. '.f64.s16','.f64.u16','.s16.f64','.u16.f64',
  153. '.f32.s32','.f32.u32','.s32.f32','.u32.f32',
  154. '.f64.s32','.f64.u32','.s32.f64','.u32.f64');
  155. roundingmode2str : array[TRoundingMode] of string[1] = ('',
  156. 'p','m','z');
  157. {*****************************************************************************
  158. Conditions
  159. *****************************************************************************}
  160. type
  161. TAsmCond=(C_None,
  162. C_EQ,C_NE,C_CS,C_CC,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  163. C_GE,C_LT,C_GT,C_LE,C_AL,C_NV
  164. );
  165. TAsmConds = set of TAsmCond;
  166. const
  167. cond2str : array[TAsmCond] of string[2]=('',
  168. 'eq','ne','cs','cc','mi','pl','vs','vc','hi','ls',
  169. 'ge','lt','gt','le','al','nv'
  170. );
  171. uppercond2str : array[TAsmCond] of string[2]=('',
  172. 'EQ','NE','CS','CC','MI','PL','VS','VC','HI','LS',
  173. 'GE','LT','GT','LE','AL','NV'
  174. );
  175. {*****************************************************************************
  176. Flags
  177. *****************************************************************************}
  178. type
  179. TResFlags = (F_EQ,F_NE,F_CS,F_CC,F_MI,F_PL,F_VS,F_VC,F_HI,F_LS,
  180. F_GE,F_LT,F_GT,F_LE);
  181. {*****************************************************************************
  182. Operands
  183. *****************************************************************************}
  184. taddressmode = (AM_OFFSET,AM_PREINDEXED,AM_POSTINDEXED);
  185. tshiftmode = (SM_None,SM_LSL,SM_LSR,SM_ASR,SM_ROR,SM_RRX);
  186. tupdatereg = (UR_None,UR_Update);
  187. pshifterop = ^tshifterop;
  188. tshifterop = record
  189. shiftmode : tshiftmode;
  190. rs : tregister;
  191. shiftimm : byte;
  192. end;
  193. tcpumodeflag = (mfA, mfI, mfF);
  194. tcpumodeflags = set of tcpumodeflag;
  195. tspecialregflag = (srC, srX, srS, srF);
  196. tspecialregflags = set of tspecialregflag;
  197. {*****************************************************************************
  198. Constants
  199. *****************************************************************************}
  200. const
  201. max_operands = 6;
  202. maxintregs = 15;
  203. maxfpuregs = 8;
  204. maxaddrregs = 0;
  205. {*****************************************************************************
  206. Operand Sizes
  207. *****************************************************************************}
  208. type
  209. topsize = (S_NO,
  210. S_B,S_W,S_L,S_BW,S_BL,S_WL,
  211. S_IS,S_IL,S_IQ,
  212. S_FS,S_FL,S_FX,S_D,S_Q,S_FV,S_FXX
  213. );
  214. {*****************************************************************************
  215. Constants
  216. *****************************************************************************}
  217. const
  218. maxvarregs = 7;
  219. varregs : Array [1..maxvarregs] of tsuperregister =
  220. (RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,RS_R9,RS_R10);
  221. maxfpuvarregs = 4;
  222. fpuvarregs : Array [1..maxfpuvarregs] of tsuperregister =
  223. (RS_F4,RS_F5,RS_F6,RS_F7);
  224. {*****************************************************************************
  225. Default generic sizes
  226. *****************************************************************************}
  227. { Defines the default address size for a processor, }
  228. OS_ADDR = OS_32;
  229. { the natural int size for a processor,
  230. has to match osuinttype/ossinttype as initialized in psystem }
  231. OS_INT = OS_32;
  232. OS_SINT = OS_S32;
  233. { the maximum float size for a processor, }
  234. OS_FLOAT = OS_F64;
  235. { the size of a vector register for a processor }
  236. OS_VECTOR = OS_M32;
  237. {*****************************************************************************
  238. Generic Register names
  239. *****************************************************************************}
  240. { Stack pointer register }
  241. NR_STACK_POINTER_REG = NR_R13;
  242. RS_STACK_POINTER_REG = RS_R13;
  243. { Frame pointer register (initialized in tcpuprocinfo.init_framepointer) }
  244. RS_FRAME_POINTER_REG: tsuperregister = RS_NO;
  245. NR_FRAME_POINTER_REG: tregister = NR_NO;
  246. { Register for addressing absolute data in a position independant way,
  247. such as in PIC code. The exact meaning is ABI specific. For
  248. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  249. }
  250. NR_PIC_OFFSET_REG = NR_R9;
  251. { Results are returned in this register (32-bit values) }
  252. NR_FUNCTION_RETURN_REG = NR_R0;
  253. RS_FUNCTION_RETURN_REG = RS_R0;
  254. { The value returned from a function is available in this register }
  255. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  256. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  257. NR_FPU_RESULT_REG = NR_F0;
  258. NR_MM_RESULT_REG = NR_D0;
  259. NR_RETURN_ADDRESS_REG = NR_FUNCTION_RETURN_REG;
  260. { Offset where the parent framepointer is pushed }
  261. PARENT_FRAMEPOINTER_OFFSET = 0;
  262. NR_DEFAULTFLAGS = NR_CPSR;
  263. RS_DEFAULTFLAGS = RS_CPSR;
  264. { Low part of 64bit return value }
  265. function NR_FUNCTION_RESULT64_LOW_REG: tregister;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  266. function RS_FUNCTION_RESULT64_LOW_REG: shortint;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  267. { High part of 64bit return value }
  268. function NR_FUNCTION_RESULT64_HIGH_REG: tregister;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  269. function RS_FUNCTION_RESULT64_HIGH_REG: shortint;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  270. {*****************************************************************************
  271. GCC /ABI linking information
  272. *****************************************************************************}
  273. const
  274. { Required parameter alignment when calling a routine declared as
  275. stdcall and cdecl. The alignment value should be the one defined
  276. by GCC or the target ABI.
  277. The value of this constant is equal to the constant
  278. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  279. }
  280. std_param_align = 4;
  281. {*****************************************************************************
  282. Helpers
  283. *****************************************************************************}
  284. { Returns the tcgsize corresponding with the size of reg.}
  285. function reg_cgsize(const reg: tregister) : tcgsize;
  286. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  287. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  288. procedure inverse_flags(var f: TResFlags);
  289. function flags_to_cond(const f: TResFlags) : TAsmCond;
  290. function findreg_by_number(r:Tregister):tregisterindex;
  291. function std_regnum_search(const s:string):Tregister;
  292. function std_regname(r:Tregister):string;
  293. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  294. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  295. procedure shifterop_reset(var so : tshifterop); {$ifdef USEINLINE}inline;{$endif USEINLINE}
  296. function is_pc(const r : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  297. function is_shifter_const(d : aint;var imm_shift : byte) : boolean;
  298. function is_thumb_imm(d: aint): boolean;
  299. { Returns true if d is a valid constant for thumb 32 bit,
  300. doesn't handle ROR_C detection }
  301. function is_thumb32_imm(d : aint) : boolean;
  302. function split_into_shifter_const(value : aint;var imm1: dword; var imm2: dword):boolean;
  303. function is_continuous_mask(d : aword;var lsb, width: byte) : boolean;
  304. function dwarf_reg(r:tregister):shortint;
  305. function dwarf_reg_no_error(r:tregister):shortint;
  306. function eh_return_data_regno(nr: longint): longint;
  307. function IsIT(op: TAsmOp) : boolean;
  308. function GetITLevels(op: TAsmOp) : longint;
  309. function GenerateARMCode : boolean;
  310. function GenerateThumbCode : boolean;
  311. function GenerateThumb2Code : boolean;
  312. function IsVFPFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  313. implementation
  314. uses
  315. systems,rgBase,verbose;
  316. const
  317. std_regname_table : TRegNameTable = (
  318. {$i rarmstd.inc}
  319. );
  320. regnumber_index : array[tregisterindex] of tregisterindex = (
  321. {$i rarmrni.inc}
  322. );
  323. std_regname_index : array[tregisterindex] of tregisterindex = (
  324. {$i rarmsri.inc}
  325. );
  326. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  327. begin
  328. case regtype of
  329. R_MMREGISTER:
  330. begin
  331. case s of
  332. OS_F32:
  333. cgsize2subreg:=R_SUBFS;
  334. OS_F64:
  335. cgsize2subreg:=R_SUBFD;
  336. else
  337. internalerror(2009112701);
  338. end;
  339. end;
  340. else
  341. cgsize2subreg:=R_SUBWHOLE;
  342. end;
  343. end;
  344. function reg_cgsize(const reg: tregister): tcgsize;
  345. begin
  346. case getregtype(reg) of
  347. R_INTREGISTER :
  348. reg_cgsize:=OS_32;
  349. R_FPUREGISTER :
  350. reg_cgsize:=OS_F80;
  351. R_MMREGISTER :
  352. begin
  353. case getsubreg(reg) of
  354. R_SUBFD,
  355. R_SUBWHOLE:
  356. result:=OS_F64;
  357. R_SUBFS:
  358. result:=OS_F32;
  359. else
  360. internalerror(2009112903);
  361. end;
  362. end;
  363. else
  364. internalerror(200303181);
  365. end;
  366. end;
  367. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  368. begin
  369. { This isn't 100% perfect because the arm allows jumps also by writing to PC=R15.
  370. To overcome this problem we simply forbid that FPC generates jumps by loading R15 }
  371. is_calljmp:= o in [A_B,A_BL,A_BX,A_BLX];
  372. end;
  373. procedure inverse_flags(var f: TResFlags);
  374. const
  375. inv_flags: array[TResFlags] of TResFlags =
  376. (F_NE,F_EQ,F_CC,F_CS,F_PL,F_MI,F_VC,F_VS,F_LS,F_HI,
  377. F_LT,F_GE,F_LE,F_GT);
  378. begin
  379. f:=inv_flags[f];
  380. end;
  381. function flags_to_cond(const f: TResFlags) : TAsmCond;
  382. const
  383. flag_2_cond: array[F_EQ..F_LE] of TAsmCond =
  384. (C_EQ,C_NE,C_CS,C_CC,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  385. C_GE,C_LT,C_GT,C_LE);
  386. begin
  387. if f>high(flag_2_cond) then
  388. internalerror(200112301);
  389. result:=flag_2_cond[f];
  390. end;
  391. function findreg_by_number(r:Tregister):tregisterindex;
  392. begin
  393. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  394. end;
  395. function std_regnum_search(const s:string):Tregister;
  396. begin
  397. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  398. end;
  399. function std_regname(r:Tregister):string;
  400. var
  401. p : tregisterindex;
  402. begin
  403. p:=findreg_by_number_table(r,regnumber_index);
  404. if p<>0 then
  405. result:=std_regname_table[p]
  406. else
  407. result:=generic_regname(r);
  408. end;
  409. procedure shifterop_reset(var so : tshifterop);{$ifdef USEINLINE}inline;{$endif USEINLINE}
  410. begin
  411. FillChar(so,sizeof(so),0);
  412. end;
  413. function is_pc(const r : tregister) : boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  414. begin
  415. is_pc:=(r=NR_R15);
  416. end;
  417. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  418. const
  419. inverse: array[TAsmCond] of TAsmCond=(C_None,
  420. C_NE,C_EQ,C_CC,C_CS,C_PL,C_MI,C_VC,C_VS,C_LS,C_HI,
  421. C_LT,C_GE,C_LE,C_GT,C_None,C_None
  422. );
  423. begin
  424. result := inverse[c];
  425. end;
  426. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  427. begin
  428. result := c1 = c2;
  429. end;
  430. function is_shifter_const(d : aint;var imm_shift : byte) : boolean;
  431. var
  432. i : longint;
  433. begin
  434. if GenerateThumb2Code then
  435. begin
  436. for i:=0 to 24 do
  437. begin
  438. if (dword(d) and not($ff shl i))=0 then
  439. begin
  440. imm_shift:=i;
  441. result:=true;
  442. exit;
  443. end;
  444. end;
  445. end
  446. else
  447. begin
  448. for i:=0 to 15 do
  449. begin
  450. if (dword(d) and not(roldword($ff,i*2)))=0 then
  451. begin
  452. imm_shift:=i*2;
  453. result:=true;
  454. exit;
  455. end;
  456. end;
  457. end;
  458. result:=false;
  459. end;
  460. function is_thumb_imm(d: aint): boolean;
  461. begin
  462. result:=(d and $FF) = d;
  463. end;
  464. function is_thumb32_imm(d: aint): boolean;
  465. var
  466. t : aint;
  467. i : longint;
  468. begin
  469. {Loading 0-255 is simple}
  470. if (d and $FF) = d then
  471. result:=true
  472. { If top and bottom are equal, check if either all 4 bytes are equal
  473. or byte 0 and 2 or byte 1 and 3 are equal }
  474. else if ((d shr 16)=(d and $FFFF)) and
  475. (
  476. ((d and $FF00FF00) = 0) or
  477. ((d and $00FF00FF) = 0) or
  478. ((d shr 8)=(d and $FF))
  479. ) then
  480. result:=true
  481. {Can an 8-bit value be shifted accordingly?}
  482. else
  483. begin
  484. result:=false;
  485. for i:=8 to 31 do
  486. begin
  487. t:=RolDWord(d,i);
  488. if ((t and $FF)=t) and
  489. ((t and $80)=$80) then
  490. begin
  491. result:=true;
  492. exit;
  493. end;
  494. end;
  495. end;
  496. end;
  497. function is_continuous_mask(d : aword;var lsb, width: byte) : boolean;
  498. var
  499. msb : byte;
  500. begin
  501. lsb:=BsfDword(d);
  502. msb:=BsrDword(d);
  503. width:=msb-lsb+1;
  504. result:=(lsb<>255) and (msb<>255) and (aword(((1 shl (msb-lsb+1))-1) shl lsb) = d);
  505. end;
  506. function split_into_shifter_const(value : aint;var imm1: dword; var imm2: dword) : boolean;
  507. var
  508. d, i, i2: Dword;
  509. begin
  510. Result:=false;
  511. {Thumb2 is not supported (YET?)}
  512. if GenerateThumb2Code then exit;
  513. d:=DWord(value);
  514. for i:=0 to 15 do
  515. begin
  516. imm1:=d and rordword($FF, I*2);
  517. imm2:=d and not (imm1); {remove already found bits}
  518. {is the remainder a shifterconst? YAY! we've done it!}
  519. {Could we start from i instead of 0?}
  520. for i2:=0 to 15 do
  521. begin
  522. if (imm2 and not(rordword($FF,i2*2)))=0 then
  523. begin
  524. result:=true;
  525. exit;
  526. end;
  527. end;
  528. end;
  529. end;
  530. function dwarf_reg(r:tregister):shortint;
  531. begin
  532. result:=regdwarf_table[findreg_by_number(r)];
  533. if result=-1 then
  534. internalerror(200603251);
  535. end;
  536. function dwarf_reg_no_error(r:tregister):shortint;
  537. begin
  538. result:=regdwarf_table[findreg_by_number(r)];
  539. end;
  540. function eh_return_data_regno(nr: longint): longint;
  541. begin
  542. if (nr>=0) and (nr<2) then
  543. result:=nr
  544. else
  545. result:=-1;
  546. end;
  547. { Low part of 64bit return value }
  548. function NR_FUNCTION_RESULT64_LOW_REG: tregister; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  549. begin
  550. if target_info.endian=endian_little then
  551. result:=NR_R0
  552. else
  553. result:=NR_R1;
  554. end;
  555. function RS_FUNCTION_RESULT64_LOW_REG: shortint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  556. begin
  557. if target_info.endian=endian_little then
  558. result:=RS_R0
  559. else
  560. result:=RS_R1;
  561. end;
  562. { High part of 64bit return value }
  563. function NR_FUNCTION_RESULT64_HIGH_REG: tregister; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  564. begin
  565. if target_info.endian=endian_little then
  566. result:=NR_R1
  567. else
  568. result:=NR_R0;
  569. end;
  570. function RS_FUNCTION_RESULT64_HIGH_REG: shortint; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  571. begin
  572. if target_info.endian=endian_little then
  573. result:=RS_R1
  574. else
  575. result:=RS_R0;
  576. end;
  577. function IsIT(op: TAsmOp) : boolean;
  578. begin
  579. case op of
  580. A_IT,
  581. A_ITE, A_ITT,
  582. A_ITEE, A_ITTE, A_ITET, A_ITTT,
  583. A_ITEEE, A_ITTEE, A_ITETE, A_ITTTE,
  584. A_ITEET, A_ITTET, A_ITETT, A_ITTTT:
  585. result:=true;
  586. else
  587. result:=false;
  588. end;
  589. end;
  590. function GetITLevels(op: TAsmOp) : longint;
  591. begin
  592. case op of
  593. A_IT:
  594. result:=1;
  595. A_ITE, A_ITT:
  596. result:=2;
  597. A_ITEE, A_ITTE, A_ITET, A_ITTT:
  598. result:=3;
  599. A_ITEEE, A_ITTEE, A_ITETE, A_ITTTE,
  600. A_ITEET, A_ITTET, A_ITETT, A_ITTTT:
  601. result:=4;
  602. else
  603. result:=0;
  604. end;
  605. end;
  606. function GenerateARMCode : boolean;
  607. begin
  608. Result:=current_settings.instructionset=is_arm;
  609. end;
  610. function GenerateThumbCode : boolean;
  611. begin
  612. Result:=(current_settings.instructionset=is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[current_settings.cputype]);
  613. end;
  614. function GenerateThumb2Code : boolean;
  615. begin
  616. Result:=(current_settings.instructionset=is_thumb) and (CPUARM_HAS_THUMB2 in cpu_capabilities[current_settings.cputype]);
  617. end;
  618. function IsVFPFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  619. var
  620. singlerec : tcompsinglerec;
  621. doublerec : tcompdoublerec;
  622. begin
  623. Result:=false;
  624. case ft of
  625. s32real:
  626. begin
  627. singlerec.value:=value;
  628. singlerec:=tcompsinglerec(NtoLE(DWord(singlerec)));
  629. Result:=(singlerec.bytes[0]=0) and (singlerec.bytes[1]=0) and ((singlerec.bytes[2] and 7)=0) and
  630. (((singlerec.bytes[3] and $7e)=$40) or ((singlerec.bytes[3] and $7e)=$3e));
  631. end;
  632. s64real:
  633. begin
  634. doublerec.value:=value;
  635. doublerec:=tcompdoublerec(NtoLE(QWord(doublerec)));
  636. Result:=(doublerec.bytes[0]=0) and (doublerec.bytes[1]=0) and (doublerec.bytes[2]=0) and
  637. (doublerec.bytes[3]=0) and (doublerec.bytes[4]=0) and (doublerec.bytes[5]=0) and
  638. ((((doublerec.bytes[6] and $7f)=$40) and ((doublerec.bytes[7] and $c0)=0)) or
  639. (((doublerec.bytes[6] and $7f)=$3f) and ((doublerec.bytes[7] and $c0)=$c0)));
  640. end;
  641. end;
  642. end;
  643. end.