cpubase.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. {
  2. Copyright (c) 1998-2012 by Florian Klaempfl and Peter Vreman
  3. Copyright (c) 2014 by Jonas Maebe and Florian Klaempfl
  4. Contains the base types for Aarch64
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { Base unit for processor information. This unit contains
  19. enumerations of registers, opcodes, sizes, and other
  20. such things which are processor specific.
  21. }
  22. unit cpubase;
  23. {$define USEINLINE}
  24. {$i fpcdefs.inc}
  25. interface
  26. uses
  27. cutils,cclasses,
  28. globtype,globals,
  29. cpuinfo,
  30. aasmbase,
  31. cgbase
  32. ;
  33. {*****************************************************************************
  34. Assembler Opcodes
  35. *****************************************************************************}
  36. type
  37. TAsmOp= {$i a64op.inc}
  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. { Last value of opcode for TCommonAsmOps set below }
  46. LastCommonAsmOp = A_MOV;
  47. type
  48. { See comment for this type in arm/cpubase.pas }
  49. TCommonAsmOps = Set of A_None .. LastCommonAsmOp;
  50. {*****************************************************************************
  51. Registers
  52. *****************************************************************************}
  53. type
  54. { Number of registers used for indexing in tables }
  55. tregisterindex=0..{$i ra64nor.inc}-1;
  56. const
  57. { Available Superregisters }
  58. {$i ra64sup.inc}
  59. RS_IP0 = RS_X16;
  60. RS_IP1 = RS_X17;
  61. RS_XR = RS_X8;
  62. R_SUBWHOLE = R_SUBQ;
  63. { Available Registers }
  64. {$i ra64con.inc}
  65. NR_IP0 = NR_X16;
  66. NR_IP1 = NR_X17;
  67. NR_XR = NR_X8;
  68. { Integer Super registers first and last }
  69. first_int_supreg = RS_X0;
  70. { xzr and sp take up a separate super register because some instructions
  71. are ambiguous otherwise }
  72. first_int_imreg = $21;
  73. { Integer Super registers first and last }
  74. first_fpu_supreg = RS_S0;
  75. first_fpu_imreg = $20;
  76. { MM Super register first and last }
  77. first_mm_supreg = RS_S0;
  78. first_mm_imreg = $20;
  79. { Required parameter alignment when calling a routine declared as
  80. stdcall and cdecl. The alignment value should be the one defined
  81. by GCC or the target ABI.
  82. The value of this constant is equal to the constant
  83. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  84. }
  85. std_param_align = 8;
  86. { TODO: Calculate bsstart}
  87. regnumber_count_bsstart = 512;
  88. regnumber_table : array[tregisterindex] of tregister = (
  89. {$i ra64num.inc}
  90. );
  91. regstabs_table : array[tregisterindex] of shortint = (
  92. {$i ra64sta.inc}
  93. );
  94. regdwarf_table : array[tregisterindex] of shortint = (
  95. {$i ra64dwa.inc}
  96. );
  97. { registers which may be destroyed by calls }
  98. VOLATILE_INTREGISTERS = [RS_X0..RS_X17,RS_X30];
  99. VOLATILE_MMREGISTERS = [RS_D0..RS_D7,RS_D16..RS_D31];
  100. {*****************************************************************************
  101. Instruction post fixes
  102. *****************************************************************************}
  103. type
  104. { ARM instructions load/store and arithmetic instructions
  105. can have several instruction post fixes which are collected
  106. in this enumeration
  107. }
  108. TOpPostfix = (PF_None,
  109. { update condition flags }
  110. PF_S,
  111. { load/store sizes }
  112. PF_B,PF_SB,PF_H,PF_SH,PF_W,PF_SW
  113. );
  114. TOpPostfixes = set of TOpPostfix;
  115. const
  116. tcgsizep2size: array[tcgsize] of byte =
  117. {OS_NO }
  118. (0,
  119. {OS_8,OS_16,OS_32,OS_64,OS_128,OS_S8,OS_S16,OS_S32,OS_S64,OS_S128}
  120. 0, 1, 2, 3, 4, 0, 1, 2, 3, 4,
  121. {OS_F32,OS_F64,OS_F80,OS_C64,OS_F128,}
  122. 2, 3, 0, 3, 4,
  123. {OS_M8, OS_M16, OS_M32, OS_M64, OS_M128, OS_M256, OS_M512}
  124. 0, 1, 2, 3, 4, 5, 6);
  125. oppostfix2str: array[TOpPostfix] of string[2] = ('',
  126. 's',
  127. 'b','sb','h','sh','w','sw');
  128. {*****************************************************************************
  129. Conditions
  130. *****************************************************************************}
  131. type
  132. TAsmCond=(C_None,
  133. C_EQ,C_NE,C_HS,C_LO,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  134. C_GE,C_LT,C_GT,C_LE,C_AL,C_NV
  135. );
  136. TAsmConds = set of TAsmCond;
  137. const
  138. C_CS = C_HS;
  139. C_CC = C_LO;
  140. cond2str : array[TAsmCond] of string[2]=('',
  141. 'eq','ne','hs','lo','mi','pl','vs','vc','hi','ls',
  142. 'ge','lt','gt','le','al','nv'
  143. );
  144. uppercond2str : array[TAsmCond] of string[2]=('',
  145. 'EQ','NE','HS','LO','MI','PL','VS','VC','HI','LS',
  146. 'GE','LT','GT','LE','AL','NV'
  147. );
  148. {*****************************************************************************
  149. Flags
  150. *****************************************************************************}
  151. type
  152. TResFlags = (F_EQ,F_NE,F_CS,F_CC,F_MI,F_PL,F_VS,F_VC,F_HI,F_LS,
  153. F_GE,F_LT,F_GT,F_LE);
  154. const
  155. F_HS = F_CS;
  156. F_LO = F_CC;
  157. {*****************************************************************************
  158. Operands
  159. *****************************************************************************}
  160. type
  161. taddressmode = (AM_OFFSET,AM_PREINDEXED,AM_POSTINDEXED);
  162. tshiftmode = (SM_None,
  163. { shifted register instructions. LSL can also be used for
  164. the index register of certain loads/stores }
  165. SM_LSL,SM_LSR,SM_ASR,SM_ROR,
  166. { extended register instructions: zero/sign extension +
  167. optional shift (interpreted as LSL after extension)
  168. -- the index register of certain loads/stores can be
  169. extended via (s|u)xtw with a shiftval of either 0 or
  170. log2(transfer size of the load/store)
  171. }
  172. SM_UXTB,SM_UXTH,SM_UXTW,SM_UXTX,SM_SXTB,SM_SXTH,SM_SXTW,SM_SXTX);
  173. tupdatereg = (UR_None,UR_Update);
  174. pshifterop = ^tshifterop;
  175. tshifterop = record
  176. shiftmode : tshiftmode;
  177. shiftimm : byte;
  178. end;
  179. {*****************************************************************************
  180. Constants
  181. *****************************************************************************}
  182. const
  183. max_operands = 6;
  184. maxintregs = 32;
  185. maxfpuregs = 32;
  186. maxaddrregs = 0;
  187. shiftedregmodes = [SM_LSL,SM_UXTB,SM_UXTH,SM_UXTW,SM_UXTX,SM_SXTB,SM_SXTH,SM_SXTW,SM_SXTX];
  188. extendedregmodes = [SM_LSL,SM_LSR,SM_ASR];
  189. logicalshiftedregmodes = [SM_LSL,SM_LSR,SM_ASR,SM_ROR];
  190. {*****************************************************************************
  191. Operand Sizes
  192. *****************************************************************************}
  193. type
  194. topsize = (S_NO,
  195. S_B,S_W,S_L,S_BW,S_BL,S_WL,
  196. S_IS,S_IL,S_IQ,
  197. S_FS,S_FL,S_FX,S_D,S_Q,S_FV,S_FXX
  198. );
  199. {*****************************************************************************
  200. Default generic sizes
  201. *****************************************************************************}
  202. const
  203. { Defines the default address size for a processor, }
  204. OS_ADDR = OS_64;
  205. { the natural int size for a processor,
  206. has to match osuinttype/ossinttype as initialized in psystem }
  207. OS_INT = OS_64;
  208. OS_SINT = OS_S64;
  209. { the maximum float size for a processor, }
  210. OS_FLOAT = OS_F64;
  211. { the size of a vector register for a processor }
  212. OS_VECTOR = OS_M128;
  213. {*****************************************************************************
  214. Generic Register names
  215. *****************************************************************************}
  216. NR_FP = NR_X29;
  217. RS_FP = RS_X29;
  218. NR_WFP = NR_W29;
  219. RS_WFP = RS_W29;
  220. NR_LR = NR_X30;
  221. RS_LR = RS_X30;
  222. NR_WLR = NR_W30;
  223. RS_WLR = RS_W30;
  224. { Stack pointer register }
  225. NR_STACK_POINTER_REG = NR_SP;
  226. RS_STACK_POINTER_REG = RS_SP;
  227. { Frame pointer register }
  228. NR_FRAME_POINTER_REG = NR_X29;
  229. RS_FRAME_POINTER_REG = RS_X29;
  230. { Register for addressing absolute data in a position independant way,
  231. such as in PIC code. The exact meaning is ABI specific. For
  232. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  233. }
  234. NR_PIC_OFFSET_REG = NR_X18;
  235. { Results are returned in this register (32-bit values) }
  236. NR_FUNCTION_RETURN_REG = NR_X0;
  237. RS_FUNCTION_RETURN_REG = RS_X0;
  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. NR_FPU_RESULT_REG = NR_NO;
  242. NR_MM_RESULT_REG = NR_D0;
  243. NR_RETURN_ADDRESS_REG = NR_LR;
  244. { Offset where the parent framepointer is pushed }
  245. PARENT_FRAMEPOINTER_OFFSET = 0;
  246. NR_DEFAULTFLAGS = NR_NZCV;
  247. RS_DEFAULTFLAGS = RS_NZCV;
  248. {*****************************************************************************
  249. Helpers
  250. *****************************************************************************}
  251. { Returns the tcgsize corresponding with the size of reg.}
  252. function reg_cgsize(const reg: tregister) : tcgsize;
  253. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  254. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  255. function is_calljmpmaybeuncondret(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  256. procedure inverse_flags(var f: TResFlags);
  257. function flags_to_cond(const f: TResFlags) : TAsmCond;
  258. function findreg_by_number(r:Tregister):tregisterindex;
  259. function std_regnum_search(const s:string):Tregister;
  260. function std_regname(r:Tregister):string;
  261. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  262. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  263. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  264. function condition_in(const Subset, c: TAsmCond): Boolean;
  265. procedure shifterop_reset(var so : tshifterop); {$ifdef USEINLINE}inline;{$endif USEINLINE}
  266. function dwarf_reg(r:tregister):shortint;
  267. function dwarf_reg_no_error(r:tregister):shortint;
  268. function eh_return_data_regno(nr: longint): longint;
  269. function is_shifter_const(d: aint; size: tcgsize): boolean;
  270. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  271. implementation
  272. uses
  273. systems,rgBase,verbose;
  274. const
  275. std_regname_table : TRegNameTable = (
  276. {$i ra64std.inc}
  277. );
  278. regnumber_index : array[tregisterindex] of tregisterindex = (
  279. {$i ra64rni.inc}
  280. );
  281. std_regname_index : array[tregisterindex] of tregisterindex = (
  282. {$i ra64sri.inc}
  283. );
  284. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  285. begin
  286. case regtype of
  287. R_INTREGISTER:
  288. begin
  289. case s of
  290. { there's only Wn and Xn }
  291. OS_64,
  292. OS_S64:
  293. cgsize2subreg:=R_SUBWHOLE;
  294. else
  295. cgsize2subreg:=R_SUBD;
  296. end;
  297. end;
  298. R_MMREGISTER:
  299. begin
  300. case s of
  301. { records }
  302. OS_32,
  303. OS_F32:
  304. cgsize2subreg:=R_SUBMMS;
  305. OS_64,
  306. OS_F64:
  307. cgsize2subreg:=R_SUBMMD;
  308. else
  309. internalerror(2009112701);
  310. end;
  311. end;
  312. else
  313. cgsize2subreg:=R_SUBWHOLE;
  314. end;
  315. end;
  316. function reg_cgsize(const reg: tregister): tcgsize;
  317. begin
  318. case getregtype(reg) of
  319. R_INTREGISTER:
  320. case getsubreg(reg) of
  321. R_SUBD:
  322. result:=OS_32
  323. else
  324. result:=OS_64;
  325. end;
  326. R_MMREGISTER :
  327. begin
  328. case getsubreg(reg) of
  329. R_SUBMMD:
  330. result:=OS_F64;
  331. R_SUBMMS:
  332. result:=OS_F32;
  333. { always use OS_M128, because these could be the top or bottom bytes (or middle in some cases) }
  334. R_SUBMM8B:
  335. result:=OS_M128;
  336. R_SUBMM16B:
  337. result:=OS_M128;
  338. R_SUBMM4H:
  339. result:=OS_M128;
  340. R_SUBMM8H:
  341. result:=OS_M128;
  342. R_SUBMM2S:
  343. result:=OS_M128;
  344. R_SUBMM4S:
  345. result:=OS_M128;
  346. R_SUBMM1D:
  347. result:=OS_M128;
  348. R_SUBMM2D:
  349. result:=OS_M128;
  350. R_SUBMMWHOLE:
  351. result:=OS_M128;
  352. else
  353. internalerror(2009112903);
  354. end;
  355. end;
  356. else
  357. internalerror(200303181);
  358. end;
  359. end;
  360. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  361. begin
  362. is_calljmp:=o in [A_B,A_BL,A_BLR,A_RET,A_CBNZ,A_CBZ,A_TBNZ,A_TBZ];
  363. end;
  364. function is_calljmpmaybeuncondret(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  365. begin
  366. { Note that the caller still has to check the instruction's condition }
  367. is_calljmpmaybeuncondret:=(o in [A_B,A_BL,A_BLR,A_RET]);
  368. end;
  369. procedure inverse_flags(var f: TResFlags);
  370. const
  371. inv_flags: array[TResFlags] of TResFlags =
  372. (F_NE,F_EQ,F_CC,F_CS,F_PL,F_MI,F_VC,F_VS,F_LS,F_HI,
  373. F_LT,F_GE,F_LE,F_GT);
  374. begin
  375. f:=inv_flags[f];
  376. end;
  377. function flags_to_cond(const f: TResFlags) : TAsmCond;
  378. const
  379. flag_2_cond: array[TResFlags] of TAsmCond =
  380. (C_EQ,C_NE,C_HS,C_LO,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  381. C_GE,C_LT,C_GT,C_LE);
  382. begin
  383. if f>high(flag_2_cond) then
  384. internalerror(200112301);
  385. result:=flag_2_cond[f];
  386. end;
  387. function findreg_by_number(r:Tregister):tregisterindex;
  388. begin
  389. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  390. end;
  391. function std_regnum_search(const s:string):Tregister;
  392. begin
  393. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  394. end;
  395. function std_regname(r:Tregister):string;
  396. var
  397. p : tregisterindex;
  398. begin
  399. p:=findreg_by_number_table(r,regnumber_index);
  400. if p<>0 then
  401. result:=std_regname_table[p]
  402. else
  403. result:=generic_regname(r);
  404. end;
  405. procedure shifterop_reset(var so : tshifterop);{$ifdef USEINLINE}inline;{$endif USEINLINE}
  406. begin
  407. FillChar(so,sizeof(so),0);
  408. end;
  409. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  410. const
  411. inverse: array[TAsmCond] of TAsmCond=(C_None,
  412. C_NE,C_EQ,C_LO,C_HS,C_PL,C_MI,C_VC,C_VS,C_LS,C_HI,
  413. C_LT,C_GE,C_LE,C_GT,C_None,C_None
  414. );
  415. begin
  416. result := inverse[c];
  417. end;
  418. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  419. begin
  420. result := c1 = c2;
  421. end;
  422. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  423. function condition_in(const Subset, c: TAsmCond): Boolean;
  424. begin
  425. Result := (c = C_None) or conditions_equal(Subset, c);
  426. { Please update as necessary. [Kit] }
  427. if not Result then
  428. case Subset of
  429. C_EQ:
  430. Result := (c in [C_GE, C_LE]);
  431. C_LT:
  432. Result := (c in [C_LE]);
  433. C_GT:
  434. Result := (c in [C_GE]);
  435. else
  436. Result := False;
  437. end;
  438. end;
  439. function dwarf_reg(r:tregister):shortint;
  440. begin
  441. result:=regdwarf_table[findreg_by_number(r)];
  442. if result=-1 then
  443. internalerror(200603251);
  444. end;
  445. function dwarf_reg_no_error(r:tregister):shortint;
  446. begin
  447. result:=regdwarf_table[findreg_by_number(r)];
  448. end;
  449. function is_shifter_const(d: aint; size: tcgsize): boolean;
  450. var
  451. pattern, checkpattern: qword;
  452. patternlen, maxbits, replicatedlen: longint;
  453. rightmostone, rightmostzero, checkbit, secondrightmostbit: longint;
  454. begin
  455. result:=false;
  456. { patterns with all bits 0 or 1 cannot be represented this way }
  457. if (d=0) then
  458. exit;
  459. case size of
  460. OS_64,
  461. OS_S64:
  462. begin
  463. if d=-1 then
  464. exit;
  465. maxbits:=64;
  466. end
  467. else
  468. begin
  469. if longint(d)=-1 then
  470. exit;
  471. { we'll generate a 32 bit pattern -> ignore upper sign bits in
  472. case of negative longint value }
  473. d:=cardinal(d);
  474. maxbits:=32;
  475. end;
  476. end;
  477. { "The Logical (immediate) instructions accept a bitmask immediate value
  478. that is a 32-bit pattern or a 64-bit pattern viewed as a vector of
  479. identical elements of size e = 2, 4, 8, 16, 32 or, 64 bits. Each
  480. element contains the same sub-pattern, that is a single run of
  481. 1 to (e - 1) nonzero bits from bit 0 followed by zero bits, then
  482. rotated by 0 to (e - 1) bits." (ARMv8 ARM)
  483. Rather than generating all possible patterns and checking whether they
  484. match our constant, we check whether the lowest 2/4/8/... bits are
  485. a valid pattern, and if so whether the constant consists of a
  486. replication of this pattern. Such a valid pattern has the form of
  487. either (regexp notation)
  488. * 1+0+1*
  489. * 0+1+0* }
  490. patternlen:=2;
  491. while patternlen<=maxbits do
  492. begin
  493. { try lowest <patternlen> bits of d as pattern }
  494. if patternlen<>64 then
  495. pattern:=qword(d) and ((qword(1) shl patternlen)-1)
  496. else
  497. pattern:=qword(d);
  498. { valid pattern? If it contains too many 1<->0 transitions, larger
  499. parts of d cannot be a valid pattern either }
  500. rightmostone:=BsfQWord(pattern);
  501. rightmostzero:=BsfQWord(not(pattern));
  502. { pattern all ones or zeroes -> not a valid pattern (but larger ones
  503. can still be valid, since we have too few transitions) }
  504. if (rightmostone<patternlen) and
  505. (rightmostzero<patternlen) then
  506. begin
  507. if rightmostone>rightmostzero then
  508. begin
  509. { we have .*1*0* -> check next zero position by shifting
  510. out the existing zeroes (shr rightmostone), inverting and
  511. then again looking for the rightmost one position }
  512. checkpattern:=not(pattern);
  513. checkbit:=rightmostone;
  514. end
  515. else
  516. begin
  517. { same as above, but for .*0*1* }
  518. checkpattern:=pattern;
  519. checkbit:=rightmostzero;
  520. end;
  521. secondrightmostbit:=BsfQWord(checkpattern shr checkbit)+checkbit;
  522. { if this position is >= patternlen -> ok (1 transition),
  523. otherwise we now have 2 transitions and have to check for a
  524. third (if there is one, abort)
  525. bsf returns 255 if no 1 bit is found, so in that case it's
  526. also ok
  527. }
  528. if secondrightmostbit<patternlen then
  529. begin
  530. secondrightmostbit:=BsfQWord(not(checkpattern) shr secondrightmostbit)+secondrightmostbit;
  531. if secondrightmostbit<patternlen then
  532. exit;
  533. end;
  534. { ok, this is a valid pattern, now does d consist of a
  535. repetition of this pattern? }
  536. replicatedlen:=patternlen;
  537. checkpattern:=pattern;
  538. while replicatedlen<maxbits do
  539. begin
  540. { douplicate current pattern }
  541. checkpattern:=checkpattern or (checkpattern shl replicatedlen);
  542. replicatedlen:=replicatedlen*2;
  543. end;
  544. if qword(d)=checkpattern then
  545. begin
  546. { yes! }
  547. result:=true;
  548. exit;
  549. end;
  550. end;
  551. patternlen:=patternlen*2;
  552. end;
  553. end;
  554. function eh_return_data_regno(nr: longint): longint;
  555. begin
  556. if (nr>=0) and (nr<2) then
  557. result:=nr
  558. else
  559. result:=-1;
  560. end;
  561. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  562. var
  563. singlerec : tcompsinglerec;
  564. doublerec : tcompdoublerec;
  565. begin
  566. Result:=false;
  567. case ft of
  568. s32real:
  569. begin
  570. singlerec.value:=value;
  571. singlerec:=tcompsinglerec(NtoLE(DWord(singlerec)));
  572. Result:=(singlerec.bytes[0]=0) and (singlerec.bytes[1]=0) and ((singlerec.bytes[2] and 7)=0) and
  573. (((singlerec.bytes[3] and $7e)=$40) or ((singlerec.bytes[3] and $7e)=$3e));
  574. end;
  575. s64real:
  576. begin
  577. doublerec.value:=value;
  578. doublerec:=tcompdoublerec(NtoLE(QWord(doublerec)));
  579. Result:=(doublerec.bytes[0]=0) and (doublerec.bytes[1]=0) and (doublerec.bytes[2]=0) and
  580. (doublerec.bytes[3]=0) and (doublerec.bytes[4]=0) and (doublerec.bytes[5]=0) and
  581. ((((doublerec.bytes[6] and $c0)=$0) and ((doublerec.bytes[7] and $7f)=$40)) or
  582. (((doublerec.bytes[6] and $c0)=$c0) and ((doublerec.bytes[7] and $7f)=$3f)));
  583. end;
  584. else
  585. ;
  586. end;
  587. end;
  588. end.