cpubase.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. procedure inverse_flags(var f: TResFlags);
  256. function flags_to_cond(const f: TResFlags) : TAsmCond;
  257. function findreg_by_number(r:Tregister):tregisterindex;
  258. function std_regnum_search(const s:string):Tregister;
  259. function std_regname(r:Tregister):string;
  260. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  261. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  262. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  263. function condition_in(const Subset, c: TAsmCond): Boolean;
  264. procedure shifterop_reset(var so : tshifterop); {$ifdef USEINLINE}inline;{$endif USEINLINE}
  265. function dwarf_reg(r:tregister):shortint;
  266. function dwarf_reg_no_error(r:tregister):shortint;
  267. function eh_return_data_regno(nr: longint): longint;
  268. function is_shifter_const(d: aint; size: tcgsize): boolean;
  269. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  270. implementation
  271. uses
  272. systems,rgBase,verbose;
  273. const
  274. std_regname_table : TRegNameTable = (
  275. {$i ra64std.inc}
  276. );
  277. regnumber_index : array[tregisterindex] of tregisterindex = (
  278. {$i ra64rni.inc}
  279. );
  280. std_regname_index : array[tregisterindex] of tregisterindex = (
  281. {$i ra64sri.inc}
  282. );
  283. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  284. begin
  285. case regtype of
  286. R_INTREGISTER:
  287. begin
  288. case s of
  289. { there's only Wn and Xn }
  290. OS_64,
  291. OS_S64:
  292. cgsize2subreg:=R_SUBWHOLE;
  293. else
  294. cgsize2subreg:=R_SUBD;
  295. end;
  296. end;
  297. R_MMREGISTER:
  298. begin
  299. case s of
  300. { records }
  301. OS_32,
  302. OS_F32:
  303. cgsize2subreg:=R_SUBMMS;
  304. OS_64,
  305. OS_F64:
  306. cgsize2subreg:=R_SUBMMD;
  307. else
  308. internalerror(2009112701);
  309. end;
  310. end;
  311. else
  312. cgsize2subreg:=R_SUBWHOLE;
  313. end;
  314. end;
  315. function reg_cgsize(const reg: tregister): tcgsize;
  316. begin
  317. case getregtype(reg) of
  318. R_INTREGISTER:
  319. case getsubreg(reg) of
  320. R_SUBD:
  321. result:=OS_32
  322. else
  323. result:=OS_64;
  324. end;
  325. R_MMREGISTER :
  326. begin
  327. case getsubreg(reg) of
  328. R_SUBMMD:
  329. result:=OS_F64;
  330. R_SUBMMS:
  331. result:=OS_F32;
  332. { always use OS_M128, because these could be the top or bottom bytes (or middle in some cases) }
  333. R_SUBMM8B:
  334. result:=OS_M128;
  335. R_SUBMM16B:
  336. result:=OS_M128;
  337. R_SUBMM4H:
  338. result:=OS_M128;
  339. R_SUBMM8H:
  340. result:=OS_M128;
  341. R_SUBMM2S:
  342. result:=OS_M128;
  343. R_SUBMM4S:
  344. result:=OS_M128;
  345. R_SUBMM1D:
  346. result:=OS_M128;
  347. R_SUBMM2D:
  348. result:=OS_M128;
  349. R_SUBMMWHOLE:
  350. result:=OS_M128;
  351. else
  352. internalerror(2009112903);
  353. end;
  354. end;
  355. else
  356. internalerror(200303181);
  357. end;
  358. end;
  359. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  360. begin
  361. is_calljmp:=o in [A_B,A_BL,A_BLR,A_RET,A_CBNZ,A_CBZ,A_TBNZ,A_TBZ];
  362. end;
  363. procedure inverse_flags(var f: TResFlags);
  364. const
  365. inv_flags: array[TResFlags] of TResFlags =
  366. (F_NE,F_EQ,F_CC,F_CS,F_PL,F_MI,F_VC,F_VS,F_LS,F_HI,
  367. F_LT,F_GE,F_LE,F_GT);
  368. begin
  369. f:=inv_flags[f];
  370. end;
  371. function flags_to_cond(const f: TResFlags) : TAsmCond;
  372. const
  373. flag_2_cond: array[TResFlags] of TAsmCond =
  374. (C_EQ,C_NE,C_HS,C_LO,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  375. C_GE,C_LT,C_GT,C_LE);
  376. begin
  377. if f>high(flag_2_cond) then
  378. internalerror(200112301);
  379. result:=flag_2_cond[f];
  380. end;
  381. function findreg_by_number(r:Tregister):tregisterindex;
  382. begin
  383. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  384. end;
  385. function std_regnum_search(const s:string):Tregister;
  386. begin
  387. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  388. end;
  389. function std_regname(r:Tregister):string;
  390. var
  391. p : tregisterindex;
  392. begin
  393. p:=findreg_by_number_table(r,regnumber_index);
  394. if p<>0 then
  395. result:=std_regname_table[p]
  396. else
  397. result:=generic_regname(r);
  398. end;
  399. procedure shifterop_reset(var so : tshifterop);{$ifdef USEINLINE}inline;{$endif USEINLINE}
  400. begin
  401. FillChar(so,sizeof(so),0);
  402. end;
  403. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  404. const
  405. inverse: array[TAsmCond] of TAsmCond=(C_None,
  406. C_NE,C_EQ,C_LO,C_HS,C_PL,C_MI,C_VC,C_VS,C_LS,C_HI,
  407. C_LT,C_GE,C_LE,C_GT,C_None,C_None
  408. );
  409. begin
  410. result := inverse[c];
  411. end;
  412. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  413. begin
  414. result := c1 = c2;
  415. end;
  416. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  417. function condition_in(const Subset, c: TAsmCond): Boolean;
  418. begin
  419. Result := (c = C_None) or conditions_equal(Subset, c);
  420. { Please update as necessary. [Kit] }
  421. if not Result then
  422. case Subset of
  423. C_EQ:
  424. Result := (c in [C_GE, C_LE]);
  425. C_LT:
  426. Result := (c in [C_LE]);
  427. C_GT:
  428. Result := (c in [C_GE]);
  429. else
  430. Result := False;
  431. end;
  432. end;
  433. function dwarf_reg(r:tregister):shortint;
  434. begin
  435. result:=regdwarf_table[findreg_by_number(r)];
  436. if result=-1 then
  437. internalerror(200603251);
  438. end;
  439. function dwarf_reg_no_error(r:tregister):shortint;
  440. begin
  441. result:=regdwarf_table[findreg_by_number(r)];
  442. end;
  443. function is_shifter_const(d: aint; size: tcgsize): boolean;
  444. var
  445. pattern, checkpattern: qword;
  446. patternlen, maxbits, replicatedlen: longint;
  447. rightmostone, rightmostzero, checkbit, secondrightmostbit: longint;
  448. begin
  449. result:=false;
  450. { patterns with all bits 0 or 1 cannot be represented this way }
  451. if (d=0) then
  452. exit;
  453. case size of
  454. OS_64,
  455. OS_S64:
  456. begin
  457. if d=-1 then
  458. exit;
  459. maxbits:=64;
  460. end
  461. else
  462. begin
  463. if longint(d)=-1 then
  464. exit;
  465. { we'll generate a 32 bit pattern -> ignore upper sign bits in
  466. case of negative longint value }
  467. d:=cardinal(d);
  468. maxbits:=32;
  469. end;
  470. end;
  471. { "The Logical (immediate) instructions accept a bitmask immediate value
  472. that is a 32-bit pattern or a 64-bit pattern viewed as a vector of
  473. identical elements of size e = 2, 4, 8, 16, 32 or, 64 bits. Each
  474. element contains the same sub-pattern, that is a single run of
  475. 1 to (e - 1) nonzero bits from bit 0 followed by zero bits, then
  476. rotated by 0 to (e - 1) bits." (ARMv8 ARM)
  477. Rather than generating all possible patterns and checking whether they
  478. match our constant, we check whether the lowest 2/4/8/... bits are
  479. a valid pattern, and if so whether the constant consists of a
  480. replication of this pattern. Such a valid pattern has the form of
  481. either (regexp notation)
  482. * 1+0+1*
  483. * 0+1+0* }
  484. patternlen:=2;
  485. while patternlen<=maxbits do
  486. begin
  487. { try lowest <patternlen> bits of d as pattern }
  488. if patternlen<>64 then
  489. pattern:=qword(d) and ((qword(1) shl patternlen)-1)
  490. else
  491. pattern:=qword(d);
  492. { valid pattern? If it contains too many 1<->0 transitions, larger
  493. parts of d cannot be a valid pattern either }
  494. rightmostone:=BsfQWord(pattern);
  495. rightmostzero:=BsfQWord(not(pattern));
  496. { pattern all ones or zeroes -> not a valid pattern (but larger ones
  497. can still be valid, since we have too few transitions) }
  498. if (rightmostone<patternlen) and
  499. (rightmostzero<patternlen) then
  500. begin
  501. if rightmostone>rightmostzero then
  502. begin
  503. { we have .*1*0* -> check next zero position by shifting
  504. out the existing zeroes (shr rightmostone), inverting and
  505. then again looking for the rightmost one position }
  506. checkpattern:=not(pattern);
  507. checkbit:=rightmostone;
  508. end
  509. else
  510. begin
  511. { same as above, but for .*0*1* }
  512. checkpattern:=pattern;
  513. checkbit:=rightmostzero;
  514. end;
  515. secondrightmostbit:=BsfQWord(checkpattern shr checkbit)+checkbit;
  516. { if this position is >= patternlen -> ok (1 transition),
  517. otherwise we now have 2 transitions and have to check for a
  518. third (if there is one, abort)
  519. bsf returns 255 if no 1 bit is found, so in that case it's
  520. also ok
  521. }
  522. if secondrightmostbit<patternlen then
  523. begin
  524. secondrightmostbit:=BsfQWord(not(checkpattern) shr secondrightmostbit)+secondrightmostbit;
  525. if secondrightmostbit<patternlen then
  526. exit;
  527. end;
  528. { ok, this is a valid pattern, now does d consist of a
  529. repetition of this pattern? }
  530. replicatedlen:=patternlen;
  531. checkpattern:=pattern;
  532. while replicatedlen<maxbits do
  533. begin
  534. { douplicate current pattern }
  535. checkpattern:=checkpattern or (checkpattern shl replicatedlen);
  536. replicatedlen:=replicatedlen*2;
  537. end;
  538. if qword(d)=checkpattern then
  539. begin
  540. { yes! }
  541. result:=true;
  542. exit;
  543. end;
  544. end;
  545. patternlen:=patternlen*2;
  546. end;
  547. end;
  548. function eh_return_data_regno(nr: longint): longint;
  549. begin
  550. if (nr>=0) and (nr<2) then
  551. result:=nr
  552. else
  553. result:=-1;
  554. end;
  555. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  556. var
  557. singlerec : tcompsinglerec;
  558. doublerec : tcompdoublerec;
  559. begin
  560. Result:=false;
  561. case ft of
  562. s32real:
  563. begin
  564. singlerec.value:=value;
  565. singlerec:=tcompsinglerec(NtoLE(DWord(singlerec)));
  566. Result:=(singlerec.bytes[0]=0) and (singlerec.bytes[1]=0) and ((singlerec.bytes[2] and 7)=0) and
  567. (((singlerec.bytes[3] and $7e)=$40) or ((singlerec.bytes[3] and $7e)=$3e));
  568. end;
  569. s64real:
  570. begin
  571. doublerec.value:=value;
  572. doublerec:=tcompdoublerec(NtoLE(QWord(doublerec)));
  573. Result:=(doublerec.bytes[0]=0) and (doublerec.bytes[1]=0) and (doublerec.bytes[2]=0) and
  574. (doublerec.bytes[3]=0) and (doublerec.bytes[4]=0) and (doublerec.bytes[5]=0) and
  575. ((((doublerec.bytes[6] and $c0)=$0) and ((doublerec.bytes[7] and $7f)=$40)) or
  576. (((doublerec.bytes[6] and $c0)=$c0) and ((doublerec.bytes[7] and $7f)=$3f)));
  577. end;
  578. else
  579. ;
  580. end;
  581. end;
  582. end.