cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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_X18,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[OS_NO..OS_F128] 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. oppostfix2str: array[TOpPostfix] of string[2] = ('',
  124. 's',
  125. 'b','sb','h','sh','w','sw');
  126. {*****************************************************************************
  127. Conditions
  128. *****************************************************************************}
  129. type
  130. TAsmCond=(C_None,
  131. C_EQ,C_NE,C_HS,C_LO,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  132. C_GE,C_LT,C_GT,C_LE,C_AL,C_NV
  133. );
  134. TAsmConds = set of TAsmCond;
  135. const
  136. C_CS = C_HS;
  137. C_CC = C_LO;
  138. cond2str : array[TAsmCond] of string[2]=('',
  139. 'eq','ne','hs','lo','mi','pl','vs','vc','hi','ls',
  140. 'ge','lt','gt','le','al','nv'
  141. );
  142. uppercond2str : array[TAsmCond] of string[2]=('',
  143. 'EQ','NE','HS','LO','MI','PL','VS','VC','HI','LS',
  144. 'GE','LT','GT','LE','AL','NV'
  145. );
  146. {*****************************************************************************
  147. Flags
  148. *****************************************************************************}
  149. type
  150. TResFlags = (F_EQ,F_NE,F_CS,F_CC,F_MI,F_PL,F_VS,F_VC,F_HI,F_LS,
  151. F_GE,F_LT,F_GT,F_LE);
  152. const
  153. F_HS = F_CS;
  154. F_LO = F_CC;
  155. {*****************************************************************************
  156. Operands
  157. *****************************************************************************}
  158. type
  159. taddressmode = (AM_OFFSET,AM_PREINDEXED,AM_POSTINDEXED);
  160. tshiftmode = (SM_None,
  161. { shifted register instructions. LSL can also be used for
  162. the index register of certain loads/stores }
  163. SM_LSL,SM_LSR,SM_ASR,SM_ROR,
  164. { extended register instructions: zero/sign extension +
  165. optional shift (interpreted as LSL after extension)
  166. -- the index register of certain loads/stores can be
  167. extended via (s|u)xtw with a shiftval of either 0 or
  168. log2(transfer size of the load/store)
  169. }
  170. SM_UXTB,SM_UXTH,SM_UXTW,SM_UXTX,SM_SXTB,SM_SXTH,SM_SXTW,SM_SXTX);
  171. tupdatereg = (UR_None,UR_Update);
  172. pshifterop = ^tshifterop;
  173. tshifterop = record
  174. shiftmode : tshiftmode;
  175. shiftimm : byte;
  176. end;
  177. {*****************************************************************************
  178. Constants
  179. *****************************************************************************}
  180. const
  181. max_operands = 6;
  182. maxintregs = 32;
  183. maxfpuregs = 32;
  184. maxaddrregs = 0;
  185. shiftedregmodes = [SM_LSL,SM_UXTB,SM_UXTH,SM_UXTW,SM_UXTX,SM_SXTB,SM_SXTH,SM_SXTW,SM_SXTX];
  186. extendedregmodes = [SM_LSL,SM_LSR,SM_ASR];
  187. {*****************************************************************************
  188. Operand Sizes
  189. *****************************************************************************}
  190. type
  191. topsize = (S_NO,
  192. S_B,S_W,S_L,S_BW,S_BL,S_WL,
  193. S_IS,S_IL,S_IQ,
  194. S_FS,S_FL,S_FX,S_D,S_Q,S_FV,S_FXX
  195. );
  196. {*****************************************************************************
  197. Default generic sizes
  198. *****************************************************************************}
  199. const
  200. { Defines the default address size for a processor, }
  201. OS_ADDR = OS_64;
  202. { the natural int size for a processor,
  203. has to match osuinttype/ossinttype as initialized in psystem }
  204. OS_INT = OS_64;
  205. OS_SINT = OS_S64;
  206. { the maximum float size for a processor, }
  207. OS_FLOAT = OS_F64;
  208. { the size of a vector register for a processor }
  209. OS_VECTOR = OS_M128;
  210. {*****************************************************************************
  211. Generic Register names
  212. *****************************************************************************}
  213. NR_FP = NR_X29;
  214. RS_FP = RS_X29;
  215. NR_WFP = NR_W29;
  216. RS_WFP = RS_W29;
  217. NR_LR = NR_X30;
  218. RS_LR = RS_X30;
  219. NR_WLR = NR_W30;
  220. RS_WLR = RS_W30;
  221. { Stack pointer register }
  222. NR_STACK_POINTER_REG = NR_SP;
  223. RS_STACK_POINTER_REG = RS_SP;
  224. { Frame pointer register }
  225. NR_FRAME_POINTER_REG = NR_X29;
  226. RS_FRAME_POINTER_REG = RS_X29;
  227. { Register for addressing absolute data in a position independant way,
  228. such as in PIC code. The exact meaning is ABI specific. For
  229. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  230. }
  231. NR_PIC_OFFSET_REG = NR_X18;
  232. { Results are returned in this register (32-bit values) }
  233. NR_FUNCTION_RETURN_REG = NR_X0;
  234. RS_FUNCTION_RETURN_REG = RS_X0;
  235. { The value returned from a function is available in this register }
  236. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  237. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  238. NR_FPU_RESULT_REG = NR_NO;
  239. NR_MM_RESULT_REG = NR_D0;
  240. NR_RETURN_ADDRESS_REG = NR_FUNCTION_RETURN_REG;
  241. { Offset where the parent framepointer is pushed }
  242. PARENT_FRAMEPOINTER_OFFSET = 0;
  243. NR_DEFAULTFLAGS = NR_NZCV;
  244. RS_DEFAULTFLAGS = RS_NZCV;
  245. {*****************************************************************************
  246. Helpers
  247. *****************************************************************************}
  248. { Returns the tcgsize corresponding with the size of reg.}
  249. function reg_cgsize(const reg: tregister) : tcgsize;
  250. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  251. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  252. procedure inverse_flags(var f: TResFlags);
  253. function flags_to_cond(const f: TResFlags) : TAsmCond;
  254. function findreg_by_number(r:Tregister):tregisterindex;
  255. function std_regnum_search(const s:string):Tregister;
  256. function std_regname(r:Tregister):string;
  257. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  258. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  259. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  260. function condition_in(const Subset, c: TAsmCond): Boolean;
  261. procedure shifterop_reset(var so : tshifterop); {$ifdef USEINLINE}inline;{$endif USEINLINE}
  262. function dwarf_reg(r:tregister):shortint;
  263. function dwarf_reg_no_error(r:tregister):shortint;
  264. function eh_return_data_regno(nr: longint): longint;
  265. function is_shifter_const(d: aint; size: tcgsize): boolean;
  266. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  267. implementation
  268. uses
  269. systems,rgBase,verbose;
  270. const
  271. std_regname_table : TRegNameTable = (
  272. {$i ra64std.inc}
  273. );
  274. regnumber_index : array[tregisterindex] of tregisterindex = (
  275. {$i ra64rni.inc}
  276. );
  277. std_regname_index : array[tregisterindex] of tregisterindex = (
  278. {$i ra64sri.inc}
  279. );
  280. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  281. begin
  282. case regtype of
  283. R_INTREGISTER:
  284. begin
  285. case s of
  286. { there's only Wn and Xn }
  287. OS_64,
  288. OS_S64:
  289. cgsize2subreg:=R_SUBWHOLE;
  290. else
  291. cgsize2subreg:=R_SUBD;
  292. end;
  293. end;
  294. R_MMREGISTER:
  295. begin
  296. case s of
  297. { records }
  298. OS_32,
  299. OS_F32:
  300. cgsize2subreg:=R_SUBMMS;
  301. OS_64,
  302. OS_F64:
  303. cgsize2subreg:=R_SUBMMD;
  304. else
  305. internalerror(2009112701);
  306. end;
  307. end;
  308. else
  309. cgsize2subreg:=R_SUBWHOLE;
  310. end;
  311. end;
  312. function reg_cgsize(const reg: tregister): tcgsize;
  313. begin
  314. case getregtype(reg) of
  315. R_INTREGISTER:
  316. case getsubreg(reg) of
  317. R_SUBD:
  318. result:=OS_32
  319. else
  320. result:=OS_64;
  321. end;
  322. R_MMREGISTER :
  323. begin
  324. case getsubreg(reg) of
  325. R_SUBMMD:
  326. result:=OS_F64;
  327. R_SUBMMS:
  328. result:=OS_F32;
  329. { always use OS_M128, because these could be the top or bottom bytes (or middle in some cases) }
  330. R_SUBMM8B:
  331. result:=OS_M128;
  332. R_SUBMM16B:
  333. result:=OS_M128;
  334. R_SUBMM4H:
  335. result:=OS_M128;
  336. R_SUBMM8H:
  337. result:=OS_M128;
  338. R_SUBMM2S:
  339. result:=OS_M128;
  340. R_SUBMM4S:
  341. result:=OS_M128;
  342. R_SUBMM1D:
  343. result:=OS_M128;
  344. R_SUBMM2D:
  345. result:=OS_M128;
  346. R_SUBMMWHOLE:
  347. result:=OS_M128;
  348. else
  349. internalerror(2009112903);
  350. end;
  351. end;
  352. else
  353. internalerror(200303181);
  354. end;
  355. end;
  356. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  357. begin
  358. is_calljmp:=o in [A_B,A_BL,A_BLR,A_RET,A_CBNZ,A_CBZ,A_TBNZ,A_TBZ];
  359. end;
  360. procedure inverse_flags(var f: TResFlags);
  361. const
  362. inv_flags: array[TResFlags] of TResFlags =
  363. (F_NE,F_EQ,F_CC,F_CS,F_PL,F_MI,F_VC,F_VS,F_LS,F_HI,
  364. F_LT,F_GE,F_LE,F_GT);
  365. begin
  366. f:=inv_flags[f];
  367. end;
  368. function flags_to_cond(const f: TResFlags) : TAsmCond;
  369. const
  370. flag_2_cond: array[TResFlags] of TAsmCond =
  371. (C_EQ,C_NE,C_HS,C_LO,C_MI,C_PL,C_VS,C_VC,C_HI,C_LS,
  372. C_GE,C_LT,C_GT,C_LE);
  373. begin
  374. if f>high(flag_2_cond) then
  375. internalerror(200112301);
  376. result:=flag_2_cond[f];
  377. end;
  378. function findreg_by_number(r:Tregister):tregisterindex;
  379. begin
  380. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  381. end;
  382. function std_regnum_search(const s:string):Tregister;
  383. begin
  384. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  385. end;
  386. function std_regname(r:Tregister):string;
  387. var
  388. p : tregisterindex;
  389. begin
  390. p:=findreg_by_number_table(r,regnumber_index);
  391. if p<>0 then
  392. result:=std_regname_table[p]
  393. else
  394. result:=generic_regname(r);
  395. end;
  396. procedure shifterop_reset(var so : tshifterop);{$ifdef USEINLINE}inline;{$endif USEINLINE}
  397. begin
  398. FillChar(so,sizeof(so),0);
  399. end;
  400. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  401. const
  402. inverse: array[TAsmCond] of TAsmCond=(C_None,
  403. C_NE,C_EQ,C_LO,C_HS,C_PL,C_MI,C_VC,C_VS,C_LS,C_HI,
  404. C_LT,C_GE,C_LE,C_GT,C_None,C_None
  405. );
  406. begin
  407. result := inverse[c];
  408. end;
  409. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  410. begin
  411. result := c1 = c2;
  412. end;
  413. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  414. function condition_in(const Subset, c: TAsmCond): Boolean;
  415. begin
  416. Result := (c = C_None) or conditions_equal(Subset, c);
  417. { Please update as necessary. [Kit] }
  418. if not Result then
  419. case Subset of
  420. C_EQ:
  421. Result := (c in [C_GE, C_LE]);
  422. C_LT:
  423. Result := (c in [C_LE]);
  424. C_GT:
  425. Result := (c in [C_GE]);
  426. else
  427. Result := False;
  428. end;
  429. end;
  430. function dwarf_reg(r:tregister):shortint;
  431. begin
  432. result:=regdwarf_table[findreg_by_number(r)];
  433. if result=-1 then
  434. internalerror(200603251);
  435. end;
  436. function dwarf_reg_no_error(r:tregister):shortint;
  437. begin
  438. result:=regdwarf_table[findreg_by_number(r)];
  439. end;
  440. function is_shifter_const(d: aint; size: tcgsize): boolean;
  441. var
  442. pattern, checkpattern: qword;
  443. patternlen, maxbits, replicatedlen: longint;
  444. rightmostone, rightmostzero, checkbit, secondrightmostbit: longint;
  445. begin
  446. result:=false;
  447. { patterns with all bits 0 or 1 cannot be represented this way }
  448. if (d=0) then
  449. exit;
  450. case size of
  451. OS_64,
  452. OS_S64:
  453. begin
  454. if d=-1 then
  455. exit;
  456. maxbits:=64;
  457. end
  458. else
  459. begin
  460. if longint(d)=-1 then
  461. exit;
  462. { we'll generate a 32 bit pattern -> ignore upper sign bits in
  463. case of negative longint value }
  464. d:=cardinal(d);
  465. maxbits:=32;
  466. end;
  467. end;
  468. { "The Logical (immediate) instructions accept a bitmask immediate value
  469. that is a 32-bit pattern or a 64-bit pattern viewed as a vector of
  470. identical elements of size e = 2, 4, 8, 16, 32 or, 64 bits. Each
  471. element contains the same sub-pattern, that is a single run of
  472. 1 to (e - 1) nonzero bits from bit 0 followed by zero bits, then
  473. rotated by 0 to (e - 1) bits." (ARMv8 ARM)
  474. Rather than generating all possible patterns and checking whether they
  475. match our constant, we check whether the lowest 2/4/8/... bits are
  476. a valid pattern, and if so whether the constant consists of a
  477. replication of this pattern. Such a valid pattern has the form of
  478. either (regexp notation)
  479. * 1+0+1*
  480. * 0+1+0* }
  481. patternlen:=2;
  482. while patternlen<=maxbits do
  483. begin
  484. { try lowest <patternlen> bits of d as pattern }
  485. if patternlen<>64 then
  486. pattern:=qword(d) and ((qword(1) shl patternlen)-1)
  487. else
  488. pattern:=qword(d);
  489. { valid pattern? If it contains too many 1<->0 transitions, larger
  490. parts of d cannot be a valid pattern either }
  491. rightmostone:=BsfQWord(pattern);
  492. rightmostzero:=BsfQWord(not(pattern));
  493. { pattern all ones or zeroes -> not a valid pattern (but larger ones
  494. can still be valid, since we have too few transitions) }
  495. if (rightmostone<patternlen) and
  496. (rightmostzero<patternlen) then
  497. begin
  498. if rightmostone>rightmostzero then
  499. begin
  500. { we have .*1*0* -> check next zero position by shifting
  501. out the existing zeroes (shr rightmostone), inverting and
  502. then again looking for the rightmost one position }
  503. checkpattern:=not(pattern);
  504. checkbit:=rightmostone;
  505. end
  506. else
  507. begin
  508. { same as above, but for .*0*1* }
  509. checkpattern:=pattern;
  510. checkbit:=rightmostzero;
  511. end;
  512. secondrightmostbit:=BsfQWord(checkpattern shr checkbit)+checkbit;
  513. { if this position is >= patternlen -> ok (1 transition),
  514. otherwise we now have 2 transitions and have to check for a
  515. third (if there is one, abort)
  516. bsf returns 255 if no 1 bit is found, so in that case it's
  517. also ok
  518. }
  519. if secondrightmostbit<patternlen then
  520. begin
  521. secondrightmostbit:=BsfQWord(not(checkpattern) shr secondrightmostbit)+secondrightmostbit;
  522. if secondrightmostbit<patternlen then
  523. exit;
  524. end;
  525. { ok, this is a valid pattern, now does d consist of a
  526. repetition of this pattern? }
  527. replicatedlen:=patternlen;
  528. checkpattern:=pattern;
  529. while replicatedlen<maxbits do
  530. begin
  531. { douplicate current pattern }
  532. checkpattern:=checkpattern or (checkpattern shl replicatedlen);
  533. replicatedlen:=replicatedlen*2;
  534. end;
  535. if qword(d)=checkpattern then
  536. begin
  537. { yes! }
  538. result:=true;
  539. exit;
  540. end;
  541. end;
  542. patternlen:=patternlen*2;
  543. end;
  544. end;
  545. function eh_return_data_regno(nr: longint): longint;
  546. begin
  547. if (nr>=0) and (nr<2) then
  548. result:=nr
  549. else
  550. result:=-1;
  551. end;
  552. function IsFloatImmediate(ft : tfloattype;value : bestreal) : boolean;
  553. var
  554. singlerec : tcompsinglerec;
  555. doublerec : tcompdoublerec;
  556. begin
  557. Result:=false;
  558. case ft of
  559. s32real:
  560. begin
  561. singlerec.value:=value;
  562. singlerec:=tcompsinglerec(NtoLE(DWord(singlerec)));
  563. Result:=(singlerec.bytes[0]=0) and (singlerec.bytes[1]=0) and ((singlerec.bytes[2] and 7)=0) and
  564. (((singlerec.bytes[3] and $7e)=$40) or ((singlerec.bytes[3] and $7e)=$3e));
  565. end;
  566. s64real:
  567. begin
  568. doublerec.value:=value;
  569. doublerec:=tcompdoublerec(NtoLE(QWord(doublerec)));
  570. Result:=(doublerec.bytes[0]=0) and (doublerec.bytes[1]=0) and (doublerec.bytes[2]=0) and
  571. (doublerec.bytes[3]=0) and (doublerec.bytes[4]=0) and (doublerec.bytes[5]=0) and
  572. ((((doublerec.bytes[6] and $c0)=$0) and ((doublerec.bytes[7] and $7f)=$40)) or
  573. (((doublerec.bytes[6] and $c0)=$c0) and ((doublerec.bytes[7] and $7f)=$3f)));
  574. end;
  575. else
  576. ;
  577. end;
  578. end;
  579. end.