cpubase.pas 24 KB

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