cgx86.pas 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the common parts of the code generator for the i386 and the x86-64.
  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. { This unit implements the common parts of the code generator for the i386 and the x86-64.
  19. }
  20. unit cgx86;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cginfo,cgbase,cgobj,
  25. aasmbase,aasmtai,aasmcpu,
  26. cpubase,cpuinfo,cpupara,
  27. node,symconst;
  28. type
  29. tcgx86 = class(tcg)
  30. { passing parameters, per default the parameter is pushed }
  31. { nr gives the number of the parameter (enumerated from }
  32. { left to right), this allows to move the parameter to }
  33. { register, if the cpu supports register calling }
  34. { conventions }
  35. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);override;
  36. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  37. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  38. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  39. procedure a_call_name(list : taasmoutput;const s : string);override;
  40. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  41. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  42. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); override;
  43. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  44. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  45. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  46. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  47. size: tcgsize; a: aword; src, dst: tregister); override;
  48. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  49. size: tcgsize; src1, src2, dst: tregister); override;
  50. { move instructions }
  51. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  52. procedure a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);override;
  53. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  54. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;reg : tregister);override;
  55. procedure a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);override;
  56. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  57. { fpu move instructions }
  58. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  59. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  60. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  61. { vector register move instructions }
  62. procedure a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  63. procedure a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister); override;
  64. procedure a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference); override;
  65. procedure a_parammm_reg(list: taasmoutput; reg: tregister); override;
  66. { comparison operations }
  67. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  68. l : tasmlabel);override;
  69. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  70. l : tasmlabel);override;
  71. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  72. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  73. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  74. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  75. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  76. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference); override;
  77. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  78. procedure g_exception_reason_save(list : taasmoutput; const href : treference);override;
  79. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);override;
  80. procedure g_exception_reason_load(list : taasmoutput; const href : treference);override;
  81. class function reg_cgsize(const reg: tregister): tcgsize; override;
  82. { entry/exit code helpers }
  83. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);override;
  84. procedure g_interrupt_stackframe_entry(list : taasmoutput);override;
  85. procedure g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  86. procedure g_profilecode(list : taasmoutput);override;
  87. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  88. procedure g_restore_frame_pointer(list : taasmoutput);override;
  89. procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
  90. {$ifndef TEST_GENERIC}
  91. procedure g_call_constructor_helper(list : taasmoutput);override;
  92. procedure g_call_destructor_helper(list : taasmoutput);override;
  93. procedure g_call_fail_helper(list : taasmoutput);override;
  94. {$endif}
  95. procedure g_save_standard_registers(list : taasmoutput);override;
  96. procedure g_restore_standard_registers(list : taasmoutput);override;
  97. procedure g_save_all_registers(list : taasmoutput);override;
  98. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  99. procedure g_overflowcheck(list: taasmoutput; const p: tnode);override;
  100. private
  101. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  102. procedure sizes2load(s1 : tcgsize;s2 : topsize; var op: tasmop; var s3: topsize);
  103. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  104. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  105. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  106. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  107. end;
  108. implementation
  109. uses
  110. globtype,globals,verbose,systems,cutils,
  111. symdef,symsym,defbase,paramgr,
  112. rgobj,tgobj,rgcpu;
  113. {$ifndef NOTARGETWIN32}
  114. const
  115. winstackpagesize = 4096;
  116. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  117. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  118. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  119. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  120. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  121. TCGSize2OpSize: Array[tcgsize] of topsize =
  122. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  123. S_FS,S_FL,S_FX,S_IQ,
  124. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  125. {$endif NOTARGETWIN32}
  126. {****************************************************************************
  127. This is private property, keep out! :)
  128. ****************************************************************************}
  129. procedure tcgx86.sizes2load(s1 : tcgsize;s2: topsize; var op: tasmop; var s3: topsize);
  130. begin
  131. case s2 of
  132. S_B:
  133. if S1 in [OS_8,OS_S8] then
  134. s3 := S_B
  135. else internalerror(200109221);
  136. S_W:
  137. case s1 of
  138. OS_8,OS_S8:
  139. s3 := S_BW;
  140. OS_16,OS_S16:
  141. s3 := S_W;
  142. else internalerror(200109222);
  143. end;
  144. S_L:
  145. case s1 of
  146. OS_8,OS_S8:
  147. s3 := S_BL;
  148. OS_16,OS_S16:
  149. s3 := S_WL;
  150. OS_32,OS_S32:
  151. s3 := S_L;
  152. else internalerror(200109223);
  153. end;
  154. else internalerror(200109227);
  155. end;
  156. if s3 in [S_B,S_W,S_L] then
  157. op := A_MOV
  158. else if s1 in [OS_8,OS_16,OS_32] then
  159. op := A_MOVZX
  160. else
  161. op := A_MOVSX;
  162. end;
  163. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  164. begin
  165. case t of
  166. OS_F32 :
  167. begin
  168. op:=A_FLD;
  169. s:=S_FS;
  170. end;
  171. OS_F64 :
  172. begin
  173. op:=A_FLD;
  174. { ???? }
  175. s:=S_FL;
  176. end;
  177. OS_F80 :
  178. begin
  179. op:=A_FLD;
  180. s:=S_FX;
  181. end;
  182. OS_C64 :
  183. begin
  184. op:=A_FILD;
  185. s:=S_IQ;
  186. end;
  187. else
  188. internalerror(200204041);
  189. end;
  190. end;
  191. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  192. var
  193. op : tasmop;
  194. s : topsize;
  195. begin
  196. floatloadops(t,op,s);
  197. list.concat(Taicpu.Op_ref(op,s,ref));
  198. inc(trgcpu(rg).fpuvaroffset);
  199. end;
  200. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  201. begin
  202. case t of
  203. OS_F32 :
  204. begin
  205. op:=A_FSTP;
  206. s:=S_FS;
  207. end;
  208. OS_F64 :
  209. begin
  210. op:=A_FSTP;
  211. s:=S_FL;
  212. end;
  213. OS_F80 :
  214. begin
  215. op:=A_FSTP;
  216. s:=S_FX;
  217. end;
  218. OS_C64 :
  219. begin
  220. op:=A_FISTP;
  221. s:=S_IQ;
  222. end;
  223. else
  224. internalerror(200204042);
  225. end;
  226. end;
  227. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  228. var
  229. op : tasmop;
  230. s : topsize;
  231. begin
  232. floatstoreops(t,op,s);
  233. list.concat(Taicpu.Op_ref(op,s,ref));
  234. dec(trgcpu(rg).fpuvaroffset);
  235. end;
  236. {****************************************************************************
  237. Assembler code
  238. ****************************************************************************}
  239. function tcgx86.reg_cgsize(const reg: tregister): tcgsize;
  240. const
  241. regsize_2_cgsize: array[S_B..S_L] of tcgsize = (OS_8,OS_16,OS_32);
  242. begin
  243. result := regsize_2_cgsize[reg2opsize[reg]];
  244. end;
  245. { currently does nothing }
  246. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  247. begin
  248. a_jmp_cond(list, OC_NONE, l);
  249. end;
  250. { we implement the following routines because otherwise we can't }
  251. { instantiate the class since it's abstract }
  252. procedure tcgx86.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  253. begin
  254. case size of
  255. OS_8,OS_S8,
  256. OS_16,OS_S16:
  257. begin
  258. if target_info.alignment.paraalign = 2 then
  259. list.concat(taicpu.op_reg(A_PUSH,S_W,rg.makeregsize(r,OS_16)))
  260. else
  261. list.concat(taicpu.op_reg(A_PUSH,S_L,rg.makeregsize(r,OS_32)));
  262. end;
  263. OS_32,OS_S32:
  264. list.concat(taicpu.op_reg(A_PUSH,S_L,r));
  265. else
  266. internalerror(2002032212);
  267. end;
  268. end;
  269. procedure tcgx86.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  270. begin
  271. case size of
  272. OS_8,OS_S8,OS_16,OS_S16:
  273. begin
  274. if target_info.alignment.paraalign = 2 then
  275. list.concat(taicpu.op_const(A_PUSH,S_W,a))
  276. else
  277. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  278. end;
  279. OS_32,OS_S32:
  280. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  281. else
  282. internalerror(2002032213);
  283. end;
  284. end;
  285. procedure tcgx86.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  286. var
  287. tmpreg: tregister;
  288. begin
  289. case size of
  290. OS_8,OS_S8,
  291. OS_16,OS_S16:
  292. begin
  293. tmpreg := get_scratch_reg_address(list);
  294. a_load_ref_reg(list,size,r,tmpreg);
  295. if target_info.alignment.paraalign = 2 then
  296. list.concat(taicpu.op_reg(A_PUSH,S_W,rg.makeregsize(tmpreg,OS_16)))
  297. else
  298. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  299. free_scratch_reg(list,tmpreg);
  300. end;
  301. OS_32,OS_S32:
  302. list.concat(taicpu.op_ref(A_PUSH,S_L,r));
  303. else
  304. internalerror(2002032214);
  305. end;
  306. end;
  307. procedure tcgx86.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  308. var
  309. tmpreg: tregister;
  310. begin
  311. if r.segment<>R_NO then
  312. CGMessage(cg_e_cant_use_far_pointer_there);
  313. if (r.base=R_NO) and (r.index=R_NO) then
  314. list.concat(Taicpu.Op_sym_ofs(A_PUSH,S_L,r.symbol,r.offset))
  315. else if (r.base=R_NO) and (r.index<>R_NO) and
  316. (r.offset=0) and (r.scalefactor=0) and (r.symbol=nil) then
  317. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.index))
  318. else if (r.base<>R_NO) and (r.index=R_NO) and
  319. (r.offset=0) and (r.symbol=nil) then
  320. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.base))
  321. else
  322. begin
  323. tmpreg := get_scratch_reg_address(list);
  324. a_loadaddr_ref_reg(list,r,tmpreg);
  325. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  326. free_scratch_reg(list,tmpreg);
  327. end;
  328. end;
  329. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  330. begin
  331. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s)));
  332. end;
  333. procedure tcgx86.a_call_ref(list : taasmoutput;const ref : treference);
  334. begin
  335. list.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  336. end;
  337. {********************** load instructions ********************}
  338. procedure tcgx86.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  339. begin
  340. { the optimizer will change it to "xor reg,reg" when loading zero, }
  341. { no need to do it here too (JM) }
  342. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[size],a,reg))
  343. end;
  344. procedure tcgx86.a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);
  345. begin
  346. {$ifdef OPTLOAD0}
  347. { zero is often used several times in succession -> load it in a }
  348. { register and then store it to memory, so the optimizer can then }
  349. { remove the unnecessary loads of registers and you get smaller }
  350. { (and faster) code }
  351. if (a = 0) and
  352. (size in [OS_32,OS_S32]) then
  353. inherited a_load_const_ref(list,size,a,ref)
  354. else
  355. {$endif OPTLOAD0}
  356. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[size],a,ref));
  357. end;
  358. procedure tcgx86.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  359. begin
  360. list.concat(taicpu.op_reg_ref(A_MOV,TCGSize2OpSize[size],reg,
  361. ref));
  362. End;
  363. procedure tcgx86.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  364. var
  365. op: tasmop;
  366. s: topsize;
  367. begin
  368. sizes2load(size,reg2opsize[reg],op,s);
  369. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  370. end;
  371. procedure tcgx86.a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);
  372. var
  373. op: tasmop;
  374. s: topsize;
  375. begin
  376. sizes2load(size,reg2opsize[reg2],op,s);
  377. if (rg.makeregsize(reg1,OS_INT) = rg.makeregsize(reg2,OS_INT)) then
  378. begin
  379. { "mov reg1, reg1" doesn't make sense }
  380. if op = A_MOV then
  381. exit;
  382. { optimize movzx with "and ffff,<reg>" operation }
  383. if (op = A_MOVZX) then
  384. begin
  385. case size of
  386. OS_8:
  387. begin
  388. list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2],255,reg2));
  389. exit;
  390. end;
  391. OS_16:
  392. begin
  393. list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2],65535,reg2));
  394. exit;
  395. end;
  396. end;
  397. end;
  398. end;
  399. list.concat(taicpu.op_reg_reg(op,s,reg1,reg2));
  400. end;
  401. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  402. begin
  403. if assigned(ref.symbol) and
  404. (ref.base=R_NO) and
  405. (ref.index=R_NO) then
  406. list.concat(taicpu.op_sym_ofs_reg(A_MOV,S_L,ref.symbol,ref.offset,r))
  407. else
  408. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  409. end;
  410. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  411. { R_ST means "the current value at the top of the fpu stack" (JM) }
  412. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  413. begin
  414. if (reg1 <> R_ST) then
  415. begin
  416. list.concat(taicpu.op_reg(A_FLD,S_NO,
  417. trgcpu(rg).correct_fpuregister(reg1,trgcpu(rg).fpuvaroffset)));
  418. inc(trgcpu(rg).fpuvaroffset);
  419. end;
  420. if (reg2 <> R_ST) then
  421. begin
  422. list.concat(taicpu.op_reg(A_FSTP,S_NO,
  423. trgcpu(rg).correct_fpuregister(reg2,trgcpu(rg).fpuvaroffset)));
  424. dec(trgcpu(rg).fpuvaroffset);
  425. end;
  426. end;
  427. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  428. begin
  429. floatload(list,size,ref);
  430. if (reg <> R_ST) then
  431. a_loadfpu_reg_reg(list,R_ST,reg);
  432. end;
  433. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  434. begin
  435. if reg <> R_ST then
  436. a_loadfpu_reg_reg(list,reg,R_ST);
  437. floatstore(list,size,ref);
  438. end;
  439. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  440. begin
  441. list.concat(taicpu.op_reg_reg(A_MOVQ,S_NO,reg1,reg2));
  442. end;
  443. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister);
  444. begin
  445. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  446. end;
  447. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference);
  448. begin
  449. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  450. end;
  451. procedure tcgx86.a_parammm_reg(list: taasmoutput; reg: tregister);
  452. var
  453. href : treference;
  454. begin
  455. list.concat(taicpu.op_const_reg(A_SUB,S_L,8,R_ESP));
  456. reference_reset_base(href,R_ESP,0);
  457. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,href));
  458. end;
  459. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  460. var
  461. opcode: tasmop;
  462. power: longint;
  463. begin
  464. Case Op of
  465. OP_DIV, OP_IDIV:
  466. Begin
  467. if ispowerof2(a,power) then
  468. begin
  469. case op of
  470. OP_DIV:
  471. opcode := A_SHR;
  472. OP_IDIV:
  473. opcode := A_SAR;
  474. end;
  475. list.concat(taicpu.op_const_reg(opcode,reg2opsize[reg],power,
  476. reg));
  477. exit;
  478. end;
  479. { the rest should be handled specifically in the code }
  480. { generator because of the silly register usage restraints }
  481. internalerror(200109224);
  482. End;
  483. OP_MUL,OP_IMUL:
  484. begin
  485. if not(cs_check_overflow in aktlocalswitches) and
  486. ispowerof2(a,power) then
  487. begin
  488. list.concat(taicpu.op_const_reg(A_SHL,reg2opsize[reg],power,
  489. reg));
  490. exit;
  491. end;
  492. if op = OP_IMUL then
  493. list.concat(taicpu.op_const_reg(A_IMUL,reg2opsize[reg],
  494. a,reg))
  495. else
  496. { OP_MUL should be handled specifically in the code }
  497. { generator because of the silly register usage restraints }
  498. internalerror(200109225);
  499. end;
  500. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  501. if not(cs_check_overflow in aktlocalswitches) and
  502. (a = 1) and
  503. (op in [OP_ADD,OP_SUB]) then
  504. if op = OP_ADD then
  505. list.concat(taicpu.op_reg(A_INC,reg2opsize[reg],reg))
  506. else
  507. list.concat(taicpu.op_reg(A_DEC,reg2opsize[reg],reg))
  508. else if (a = 0) then
  509. if (op <> OP_AND) then
  510. exit
  511. else
  512. list.concat(taicpu.op_const_reg(A_MOV,reg2opsize[reg],0,reg))
  513. else if (a = high(aword)) and
  514. (op in [OP_AND,OP_OR,OP_XOR]) then
  515. begin
  516. case op of
  517. OP_AND:
  518. exit;
  519. OP_OR:
  520. list.concat(taicpu.op_const_reg(A_MOV,reg2opsize[reg],high(aword),reg));
  521. OP_XOR:
  522. list.concat(taicpu.op_reg(A_NOT,reg2opsize[reg],reg));
  523. end
  524. end
  525. else
  526. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],reg2opsize[reg],
  527. a,reg));
  528. OP_SHL,OP_SHR,OP_SAR:
  529. begin
  530. if (a and 31) <> 0 Then
  531. list.concat(taicpu.op_const_reg(
  532. TOpCG2AsmOp[op],reg2opsize[reg],a and 31,reg));
  533. if (a shr 5) <> 0 Then
  534. internalerror(68991);
  535. end
  536. else internalerror(68992);
  537. end;
  538. end;
  539. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  540. var
  541. opcode: tasmop;
  542. power: longint;
  543. begin
  544. Case Op of
  545. OP_DIV, OP_IDIV:
  546. Begin
  547. if ispowerof2(a,power) then
  548. begin
  549. case op of
  550. OP_DIV:
  551. opcode := A_SHR;
  552. OP_IDIV:
  553. opcode := A_SAR;
  554. end;
  555. list.concat(taicpu.op_const_ref(opcode,
  556. TCgSize2OpSize[size],power,ref));
  557. exit;
  558. end;
  559. { the rest should be handled specifically in the code }
  560. { generator because of the silly register usage restraints }
  561. internalerror(200109231);
  562. End;
  563. OP_MUL,OP_IMUL:
  564. begin
  565. if not(cs_check_overflow in aktlocalswitches) and
  566. ispowerof2(a,power) then
  567. begin
  568. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  569. power,ref));
  570. exit;
  571. end;
  572. { can't multiply a memory location directly with a constant }
  573. if op = OP_IMUL then
  574. inherited a_op_const_ref(list,op,size,a,ref)
  575. else
  576. { OP_MUL should be handled specifically in the code }
  577. { generator because of the silly register usage restraints }
  578. internalerror(200109232);
  579. end;
  580. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  581. if not(cs_check_overflow in aktlocalswitches) and
  582. (a = 1) and
  583. (op in [OP_ADD,OP_SUB]) then
  584. if op = OP_ADD then
  585. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  586. else
  587. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  588. else if (a = 0) then
  589. if (op <> OP_AND) then
  590. exit
  591. else
  592. a_load_const_ref(list,size,0,ref)
  593. else if (a = high(aword)) and
  594. (op in [OP_AND,OP_OR,OP_XOR]) then
  595. begin
  596. case op of
  597. OP_AND:
  598. exit;
  599. OP_OR:
  600. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],high(aword),ref));
  601. OP_XOR:
  602. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  603. end
  604. end
  605. else
  606. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  607. TCgSize2OpSize[size],a,ref));
  608. OP_SHL,OP_SHR,OP_SAR:
  609. begin
  610. if (a and 31) <> 0 Then
  611. list.concat(taicpu.op_const_ref(
  612. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  613. if (a shr 5) <> 0 Then
  614. internalerror(68991);
  615. end
  616. else internalerror(68992);
  617. end;
  618. end;
  619. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  620. var
  621. regloadsize: tcgsize;
  622. dstsize: topsize;
  623. tmpreg : tregister;
  624. popecx : boolean;
  625. begin
  626. dstsize := tcgsize2opsize[size];
  627. dst := rg.makeregsize(dst,size);
  628. case op of
  629. OP_NEG,OP_NOT:
  630. begin
  631. if src <> R_NO then
  632. internalerror(200112291);
  633. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  634. end;
  635. OP_MUL,OP_DIV,OP_IDIV:
  636. { special stuff, needs separate handling inside code }
  637. { generator }
  638. internalerror(200109233);
  639. OP_SHR,OP_SHL,OP_SAR:
  640. begin
  641. tmpreg := R_NO;
  642. popecx := false;
  643. { we need cl to hold the shift count, so if the destination }
  644. { is ecx, save it to a temp for now }
  645. if dst in [R_ECX,R_CX,R_CL] then
  646. begin
  647. case reg2opsize[dst] of
  648. S_B: regloadsize := OS_8;
  649. S_W: regloadsize := OS_16;
  650. else regloadsize := OS_32;
  651. end;
  652. tmpreg := get_scratch_reg_int(list);
  653. a_load_reg_reg(list,regloadsize,src,tmpreg);
  654. end;
  655. if not(src in [R_ECX,R_CX,R_CL]) then
  656. begin
  657. { is ecx still free (it's also free if it was allocated }
  658. { to dst, since we've moved dst somewhere else already) }
  659. if not((dst = R_ECX) or
  660. ((R_ECX in rg.unusedregsint) and
  661. { this will always be true, it's just here to }
  662. { allocate ecx }
  663. (rg.getexplicitregisterint(list,R_ECX) = R_ECX))) then
  664. begin
  665. list.concat(taicpu.op_reg(A_PUSH,S_L,R_ECX));
  666. popecx := true;
  667. end;
  668. a_load_reg_reg(list,OS_32,rg.makeregsize(src,OS_32),R_ECX);
  669. end
  670. else
  671. src := R_CL;
  672. { do the shift }
  673. if tmpreg = R_NO then
  674. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  675. R_CL,dst))
  676. else
  677. begin
  678. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],S_L,
  679. R_CL,tmpreg));
  680. { move result back to the destination }
  681. a_load_reg_reg(list,OS_32,tmpreg,R_ECX);
  682. free_scratch_reg(list,tmpreg);
  683. end;
  684. if popecx then
  685. list.concat(taicpu.op_reg(A_POP,S_L,R_ECX))
  686. else if not (dst in [R_ECX,R_CX,R_CL]) then
  687. rg.ungetregisterint(list,R_ECX);
  688. end;
  689. else
  690. begin
  691. if reg2opsize[src] <> dstsize then
  692. internalerror(200109226);
  693. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  694. src,dst));
  695. end;
  696. end;
  697. end;
  698. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  699. begin
  700. case op of
  701. OP_NEG,OP_NOT,OP_IMUL:
  702. begin
  703. inherited a_op_ref_reg(list,op,size,ref,reg);
  704. end;
  705. OP_MUL,OP_DIV,OP_IDIV:
  706. { special stuff, needs separate handling inside code }
  707. { generator }
  708. internalerror(200109239);
  709. else
  710. begin
  711. reg := rg.makeregsize(reg,size);
  712. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  713. end;
  714. end;
  715. end;
  716. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  717. var
  718. opsize: topsize;
  719. begin
  720. case op of
  721. OP_NEG,OP_NOT:
  722. begin
  723. if reg <> R_NO then
  724. internalerror(200109237);
  725. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  726. end;
  727. OP_IMUL:
  728. begin
  729. { this one needs a load/imul/store, which is the default }
  730. inherited a_op_ref_reg(list,op,size,ref,reg);
  731. end;
  732. OP_MUL,OP_DIV,OP_IDIV:
  733. { special stuff, needs separate handling inside code }
  734. { generator }
  735. internalerror(200109238);
  736. else
  737. begin
  738. opsize := tcgsize2opsize[size];
  739. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],opsize,reg,ref));
  740. end;
  741. end;
  742. end;
  743. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  744. size: tcgsize; a: aword; src, dst: tregister);
  745. var
  746. tmpref: treference;
  747. power: longint;
  748. opsize: topsize;
  749. begin
  750. opsize := reg2opsize[src];
  751. if (opsize <> S_L) or
  752. not (size in [OS_32,OS_S32]) then
  753. begin
  754. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  755. exit;
  756. end;
  757. { if we get here, we have to do a 32 bit calculation, guaranteed }
  758. Case Op of
  759. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  760. OP_SAR:
  761. { can't do anything special for these }
  762. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  763. OP_IMUL:
  764. begin
  765. if not(cs_check_overflow in aktlocalswitches) and
  766. ispowerof2(a,power) then
  767. { can be done with a shift }
  768. begin
  769. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  770. exit;
  771. end;
  772. list.concat(taicpu.op_const_reg_reg(A_IMUL,S_L,a,src,dst));
  773. end;
  774. OP_ADD, OP_SUB:
  775. if (a = 0) then
  776. a_load_reg_reg(list,size,src,dst)
  777. else
  778. begin
  779. reference_reset(tmpref);
  780. tmpref.base := src;
  781. tmpref.offset := longint(a);
  782. if op = OP_SUB then
  783. tmpref.offset := -tmpref.offset;
  784. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  785. end
  786. else internalerror(200112302);
  787. end;
  788. end;
  789. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  790. size: tcgsize; src1, src2, dst: tregister);
  791. var
  792. tmpref: treference;
  793. opsize: topsize;
  794. begin
  795. opsize := reg2opsize[src1];
  796. if (opsize <> S_L) or
  797. (reg2opsize[src2] <> S_L) or
  798. not (size in [OS_32,OS_S32]) then
  799. begin
  800. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  801. exit;
  802. end;
  803. { if we get here, we have to do a 32 bit calculation, guaranteed }
  804. Case Op of
  805. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  806. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  807. { can't do anything special for these }
  808. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  809. OP_IMUL:
  810. list.concat(taicpu.op_reg_reg_reg(A_IMUL,S_L,src1,src2,dst));
  811. OP_ADD:
  812. begin
  813. reference_reset(tmpref);
  814. tmpref.base := src1;
  815. tmpref.index := src2;
  816. tmpref.scalefactor := 1;
  817. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  818. end
  819. else internalerror(200112303);
  820. end;
  821. end;
  822. {*************** compare instructructions ****************}
  823. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  824. l : tasmlabel);
  825. begin
  826. if (a = 0) then
  827. list.concat(taicpu.op_reg_reg(A_TEST,reg2opsize[reg],reg,reg))
  828. else
  829. list.concat(taicpu.op_const_reg(A_CMP,reg2opsize[reg],a,reg));
  830. a_jmp_cond(list,cmp_op,l);
  831. end;
  832. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  833. l : tasmlabel);
  834. begin
  835. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  836. a_jmp_cond(list,cmp_op,l);
  837. end;
  838. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  839. reg1,reg2 : tregister;l : tasmlabel);
  840. begin
  841. if reg2opsize[reg1] <> reg2opsize[reg2] then
  842. internalerror(200109226);
  843. list.concat(taicpu.op_reg_reg(A_CMP,reg2opsize[reg1],reg1,reg2));
  844. a_jmp_cond(list,cmp_op,l);
  845. end;
  846. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  847. begin
  848. reg := rg.makeregsize(reg,size);
  849. list.concat(taicpu.op_ref_reg(A_CMP,tcgsize2opsize[size],ref,reg));
  850. a_jmp_cond(list,cmp_op,l);
  851. end;
  852. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  853. var
  854. ai : taicpu;
  855. begin
  856. if cond=OC_None then
  857. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  858. else
  859. begin
  860. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  861. ai.SetCondition(TOpCmp2AsmCond[cond]);
  862. end;
  863. ai.is_jmp:=true;
  864. list.concat(ai);
  865. end;
  866. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  867. var
  868. ai : taicpu;
  869. begin
  870. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  871. ai.SetCondition(flags_to_cond(f));
  872. ai.is_jmp := true;
  873. list.concat(ai);
  874. end;
  875. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  876. var
  877. ai : taicpu;
  878. hreg : tregister;
  879. begin
  880. hreg := rg.makeregsize(reg,OS_8);
  881. ai:=Taicpu.Op_reg(A_Setcc,S_B,hreg);
  882. ai.SetCondition(flags_to_cond(f));
  883. list.concat(ai);
  884. if (reg <> hreg) then
  885. a_load_reg_reg(list,OS_8,hreg,reg);
  886. end;
  887. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  888. var
  889. ai : taicpu;
  890. begin
  891. if not(size in [OS_8,OS_S8]) then
  892. a_load_const_ref(list,size,0,ref);
  893. ai:=Taicpu.Op_ref(A_Setcc,S_B,ref);
  894. ai.SetCondition(flags_to_cond(f));
  895. list.concat(ai);
  896. end;
  897. { ************* concatcopy ************ }
  898. procedure tcgx86.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  899. var
  900. ecxpushed : boolean;
  901. helpsize : longint;
  902. i : byte;
  903. reg8,reg32 : tregister;
  904. srcref,dstref : treference;
  905. swap : boolean;
  906. procedure maybepushecx;
  907. begin
  908. if not(R_ECX in rg.unusedregsint) then
  909. begin
  910. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ECX));
  911. ecxpushed:=true;
  912. end
  913. else rg.getexplicitregisterint(list,R_ECX);
  914. end;
  915. begin
  916. if (not loadref) and
  917. ((len<=8) or
  918. (not(cs_littlesize in aktglobalswitches ) and (len<=12))) then
  919. begin
  920. helpsize:=len shr 2;
  921. rg.getexplicitregisterint(list,R_EDI);
  922. dstref:=dest;
  923. srcref:=source;
  924. for i:=1 to helpsize do
  925. begin
  926. a_load_ref_reg(list,OS_32,srcref,R_EDI);
  927. If (len = 4) and delsource then
  928. reference_release(list,source);
  929. a_load_reg_ref(list,OS_32,R_EDI,dstref);
  930. inc(srcref.offset,4);
  931. inc(dstref.offset,4);
  932. dec(len,4);
  933. end;
  934. if len>1 then
  935. begin
  936. a_load_ref_reg(list,OS_16,srcref,R_DI);
  937. If (len = 2) and delsource then
  938. reference_release(list,source);
  939. a_load_reg_ref(list,OS_16,R_DI,dstref);
  940. inc(srcref.offset,2);
  941. inc(dstref.offset,2);
  942. dec(len,2);
  943. end;
  944. rg.ungetregisterint(list,R_EDI);
  945. if len>0 then
  946. begin
  947. { and now look for an 8 bit register }
  948. swap:=false;
  949. if R_EAX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EAX),OS_8)
  950. else if R_EDX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EDX),OS_8)
  951. else if R_EBX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EBX),OS_8)
  952. else if R_ECX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_ECX),OS_8)
  953. else
  954. begin
  955. swap:=true;
  956. { we need only to check 3 registers, because }
  957. { one is always not index or base }
  958. if (dest.base<>R_EAX) and (dest.index<>R_EAX) then
  959. begin
  960. reg8:=R_AL;
  961. reg32:=R_EAX;
  962. end
  963. else if (dest.base<>R_EBX) and (dest.index<>R_EBX) then
  964. begin
  965. reg8:=R_BL;
  966. reg32:=R_EBX;
  967. end
  968. else if (dest.base<>R_ECX) and (dest.index<>R_ECX) then
  969. begin
  970. reg8:=R_CL;
  971. reg32:=R_ECX;
  972. end;
  973. end;
  974. if swap then
  975. { was earlier XCHG, of course nonsense }
  976. begin
  977. rg.getexplicitregisterint(list,R_EDI);
  978. a_load_reg_reg(list,OS_32,reg32,R_EDI);
  979. end;
  980. a_load_ref_reg(list,OS_8,srcref,reg8);
  981. If delsource and (len=1) then
  982. reference_release(list,source);
  983. a_load_reg_ref(list,OS_8,reg8,dstref);
  984. if swap then
  985. begin
  986. a_load_reg_reg(list,OS_32,R_EDI,reg32);
  987. rg.ungetregisterint(list,R_EDI);
  988. end
  989. else
  990. rg.ungetregister(list,reg8);
  991. end;
  992. end
  993. else
  994. begin
  995. rg.getexplicitregisterint(list,R_EDI);
  996. a_loadaddr_ref_reg(list,dest,R_EDI);
  997. list.concat(tai_regalloc.Alloc(R_ESI));
  998. if loadref then
  999. a_load_ref_reg(list,OS_ADDR,source,R_ESI)
  1000. else
  1001. begin
  1002. a_loadaddr_ref_reg(list,source,R_ESI);
  1003. if delsource then
  1004. reference_release(list,source);
  1005. end;
  1006. list.concat(Taicpu.Op_none(A_CLD,S_NO));
  1007. ecxpushed:=false;
  1008. if cs_littlesize in aktglobalswitches then
  1009. begin
  1010. maybepushecx;
  1011. a_load_const_reg(list,OS_INT,len,R_ECX);
  1012. list.concat(Taicpu.Op_none(A_REP,S_NO));
  1013. list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1014. end
  1015. else
  1016. begin
  1017. helpsize:=len shr 2;
  1018. len:=len and 3;
  1019. if helpsize>1 then
  1020. begin
  1021. maybepushecx;
  1022. a_load_const_reg(list,OS_INT,helpsize,R_ECX);
  1023. list.concat(Taicpu.Op_none(A_REP,S_NO));
  1024. end;
  1025. if helpsize>0 then
  1026. list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1027. if len>1 then
  1028. begin
  1029. dec(len,2);
  1030. list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1031. end;
  1032. if len=1 then
  1033. list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1034. end;
  1035. rg.ungetregisterint(list,R_EDI);
  1036. list.concat(tai_regalloc.DeAlloc(R_ESI));
  1037. if ecxpushed then
  1038. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ECX))
  1039. else
  1040. rg.ungetregisterint(list,R_ECX);
  1041. { loading SELF-reference again }
  1042. g_maybe_loadself(list);
  1043. end;
  1044. if delsource then
  1045. tg.ungetiftemp(list,source);
  1046. end;
  1047. procedure tcgx86.g_exception_reason_save(list : taasmoutput; const href : treference);
  1048. begin
  1049. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1050. end;
  1051. procedure tcgx86.g_exception_reason_save_const(list : taasmoutput;const href : treference; a: aword);
  1052. begin
  1053. list.concat(Taicpu.op_const(A_PUSH,S_L,a));
  1054. end;
  1055. procedure tcgx86.g_exception_reason_load(list : taasmoutput; const href : treference);
  1056. begin
  1057. list.concat(Taicpu.op_reg(A_POP,S_L,R_EAX));
  1058. end;
  1059. {****************************************************************************
  1060. Entry/Exit Code Helpers
  1061. ****************************************************************************}
  1062. procedure tcgx86.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);
  1063. var
  1064. lenref : treference;
  1065. power,len : longint;
  1066. opsize : topsize;
  1067. {$ifndef __NOWINPECOFF__}
  1068. again,ok : tasmlabel;
  1069. {$endif}
  1070. begin
  1071. lenref:=ref;
  1072. inc(lenref.offset,4);
  1073. { get stack space }
  1074. rg.getexplicitregisterint(list,R_EDI);
  1075. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_EDI));
  1076. list.concat(Taicpu.op_reg(A_INC,S_L,R_EDI));
  1077. if (elesize<>1) then
  1078. begin
  1079. if ispowerof2(elesize, power) then
  1080. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_EDI))
  1081. else
  1082. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,R_EDI));
  1083. end;
  1084. {$ifndef __NOWINPECOFF__}
  1085. { windows guards only a few pages for stack growing, }
  1086. { so we have to access every page first }
  1087. if target_info.system=system_i386_win32 then
  1088. begin
  1089. objectlibrary.getlabel(again);
  1090. objectlibrary.getlabel(ok);
  1091. a_label(list,again);
  1092. list.concat(Taicpu.op_const_reg(A_CMP,S_L,winstackpagesize,R_EDI));
  1093. a_jmp_cond(list,OC_B,ok);
  1094. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,R_ESP));
  1095. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1096. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize,R_EDI));
  1097. a_jmp_always(list,again);
  1098. a_label(list,ok);
  1099. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,R_EDI,R_ESP));
  1100. rg.ungetregisterint(list,R_EDI);
  1101. { now reload EDI }
  1102. rg.getexplicitregisterint(list,R_EDI);
  1103. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_EDI));
  1104. list.concat(Taicpu.op_reg(A_INC,S_L,R_EDI));
  1105. if (elesize<>1) then
  1106. begin
  1107. if ispowerof2(elesize, power) then
  1108. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_EDI))
  1109. else
  1110. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,R_EDI));
  1111. end;
  1112. end
  1113. else
  1114. {$endif __NOWINPECOFF__}
  1115. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,R_EDI,R_ESP));
  1116. { load destination }
  1117. list.concat(Taicpu.op_reg_reg(A_MOV,S_L,R_ESP,R_EDI));
  1118. { don't destroy the registers! }
  1119. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_ECX));
  1120. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_ESI));
  1121. { load count }
  1122. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_ECX));
  1123. { load source }
  1124. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,ref,R_ESI));
  1125. { scheduled .... }
  1126. list.concat(Taicpu.op_reg(A_INC,S_L,R_ECX));
  1127. { calculate size }
  1128. len:=elesize;
  1129. opsize:=S_B;
  1130. if (len and 3)=0 then
  1131. begin
  1132. opsize:=S_L;
  1133. len:=len shr 2;
  1134. end
  1135. else
  1136. if (len and 1)=0 then
  1137. begin
  1138. opsize:=S_W;
  1139. len:=len shr 1;
  1140. end;
  1141. if ispowerof2(len, power) then
  1142. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_ECX))
  1143. else
  1144. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,R_ECX));
  1145. list.concat(Taicpu.op_none(A_REP,S_NO));
  1146. case opsize of
  1147. S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1148. S_W : list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1149. S_L : list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1150. end;
  1151. rg.ungetregisterint(list,R_EDI);
  1152. list.concat(Taicpu.op_reg(A_POP,S_L,R_ESI));
  1153. list.concat(Taicpu.op_reg(A_POP,S_L,R_ECX));
  1154. { patch the new address }
  1155. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,R_ESP,ref));
  1156. end;
  1157. procedure tcgx86.g_interrupt_stackframe_entry(list : taasmoutput);
  1158. begin
  1159. { .... also the segment registers }
  1160. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_GS));
  1161. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_FS));
  1162. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_ES));
  1163. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_DS));
  1164. { save the registers of an interrupt procedure }
  1165. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDI));
  1166. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ESI));
  1167. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDX));
  1168. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ECX));
  1169. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBX));
  1170. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EAX));
  1171. end;
  1172. procedure tcgx86.g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);
  1173. begin
  1174. if accused then
  1175. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1176. else
  1177. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EAX));
  1178. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EBX));
  1179. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ECX));
  1180. if acchiused then
  1181. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1182. else
  1183. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDX));
  1184. if selfused then
  1185. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1186. else
  1187. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ESI));
  1188. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDI));
  1189. { .... also the segment registers }
  1190. list.concat(Taicpu.Op_reg(A_POP,S_W,R_DS));
  1191. list.concat(Taicpu.Op_reg(A_POP,S_W,R_ES));
  1192. list.concat(Taicpu.Op_reg(A_POP,S_W,R_FS));
  1193. list.concat(Taicpu.Op_reg(A_POP,S_W,R_GS));
  1194. { this restores the flags }
  1195. list.concat(Taicpu.Op_none(A_IRET,S_NO));
  1196. end;
  1197. procedure tcgx86.g_profilecode(list : taasmoutput);
  1198. var
  1199. pl : tasmlabel;
  1200. begin
  1201. case target_info.system of
  1202. system_i386_win32,
  1203. system_i386_freebsd,
  1204. system_i386_wdosx,
  1205. system_i386_linux:
  1206. begin
  1207. objectlibrary.getaddrlabel(pl);
  1208. list.concat(Tai_section.Create(sec_data));
  1209. list.concat(Tai_align.Create(4));
  1210. list.concat(Tai_label.Create(pl));
  1211. list.concat(Tai_const.Create_32bit(0));
  1212. list.concat(Tai_section.Create(sec_code));
  1213. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,R_EDX));
  1214. a_call_name(list,target_info.Cprefix+'mcount');
  1215. include(rg.usedinproc,R_EDX);
  1216. end;
  1217. system_i386_go32v2:
  1218. begin
  1219. a_call_name(list,'MCOUNT');
  1220. end;
  1221. end;
  1222. end;
  1223. procedure tcgx86.g_stackframe_entry(list : taasmoutput;localsize : longint);
  1224. var
  1225. href : treference;
  1226. i : integer;
  1227. again : tasmlabel;
  1228. begin
  1229. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBP));
  1230. list.concat(Taicpu.Op_reg_reg(A_MOV,S_L,R_ESP,R_EBP));
  1231. if localsize>0 then
  1232. begin
  1233. {$ifndef NOTARGETWIN32}
  1234. { windows guards only a few pages for stack growing, }
  1235. { so we have to access every page first }
  1236. if (target_info.system=system_i386_win32) and
  1237. (localsize>=winstackpagesize) then
  1238. begin
  1239. if localsize div winstackpagesize<=5 then
  1240. begin
  1241. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,R_ESP));
  1242. for i:=1 to localsize div winstackpagesize do
  1243. begin
  1244. reference_reset_base(href,R_ESP,localsize-i*winstackpagesize);
  1245. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1246. end;
  1247. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1248. end
  1249. else
  1250. begin
  1251. objectlibrary.getlabel(again);
  1252. rg.getexplicitregisterint(list,R_EDI);
  1253. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,R_EDI));
  1254. a_label(list,again);
  1255. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,R_ESP));
  1256. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1257. list.concat(Taicpu.op_reg(A_DEC,S_L,R_EDI));
  1258. a_jmp_cond(list,OC_NE,again);
  1259. rg.ungetregisterint(list,R_EDI);
  1260. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,R_ESP));
  1261. end
  1262. end
  1263. else
  1264. {$endif NOTARGETWIN32}
  1265. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize,R_ESP));
  1266. end;
  1267. end;
  1268. procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
  1269. begin
  1270. list.concat(Taicpu.Op_none(A_LEAVE,S_NO));
  1271. end;
  1272. procedure tcgx86.g_return_from_proc(list : taasmoutput;parasize : aword);
  1273. begin
  1274. { Routines with the poclearstack flag set use only a ret }
  1275. { also routines with parasize=0 }
  1276. if (po_clearstack in aktprocdef.procoptions) then
  1277. begin
  1278. { complex return values are removed from stack in C code PM }
  1279. if paramanager.ret_in_param(aktprocdef.rettype.def) then
  1280. list.concat(Taicpu.Op_const(A_RET,S_NO,4))
  1281. else
  1282. list.concat(Taicpu.Op_none(A_RET,S_NO));
  1283. end
  1284. else if (parasize=0) then
  1285. list.concat(Taicpu.Op_none(A_RET,S_NO))
  1286. else
  1287. begin
  1288. { parameters are limited to 65535 bytes because }
  1289. { ret allows only imm16 }
  1290. if (parasize>65535) then
  1291. CGMessage(cg_e_parasize_too_big);
  1292. list.concat(Taicpu.Op_const(A_RET,S_NO,parasize));
  1293. end;
  1294. end;
  1295. {$ifndef TEST_GENERIC}
  1296. procedure tcgx86.g_call_constructor_helper(list : taasmoutput);
  1297. begin
  1298. if is_class(procinfo^._class) then
  1299. begin
  1300. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  1301. a_call_name(list,'FPC_NEW_CLASS');
  1302. list.concat(Taicpu.Op_cond_sym(A_Jcc,C_Z,S_NO,faillabel));
  1303. end
  1304. else if is_object(procinfo^._class) then
  1305. begin
  1306. rg.getexplicitregisterint(list,R_EDI);
  1307. a_load_const_reg(list,OS_ADDR,procinfo^._class.vmt_offset,R_EDI);
  1308. a_call_name(list,'FPC_HELP_CONSTRUCTOR');
  1309. list.concat(Taicpu.Op_cond_sym(A_Jcc,C_Z,S_NO,faillabel));
  1310. end
  1311. else
  1312. internalerror(200006161);
  1313. end;
  1314. procedure tcgx86.g_call_destructor_helper(list : taasmoutput);
  1315. var
  1316. nofinal : tasmlabel;
  1317. href : treference;
  1318. begin
  1319. if is_class(procinfo^._class) then
  1320. begin
  1321. a_call_name(list,'FPC_DISPOSE_CLASS')
  1322. end
  1323. else if is_object(procinfo^._class) then
  1324. begin
  1325. { must the object be finalized ? }
  1326. if procinfo^._class.needs_inittable then
  1327. begin
  1328. objectlibrary.getlabel(nofinal);
  1329. reference_reset_base(href,R_EBP,8);
  1330. a_cmp_const_ref_label(list,OS_ADDR,OC_EQ,0,href,nofinal);
  1331. reference_reset_base(href,R_ESI,0);
  1332. g_finalize(list,procinfo^._class,href,false);
  1333. a_label(list,nofinal);
  1334. end;
  1335. rg.getexplicitregisterint(list,R_EDI);
  1336. a_load_const_reg(list,OS_ADDR,procinfo^._class.vmt_offset,R_EDI);
  1337. rg.ungetregisterint(list,R_EDI);
  1338. a_call_name(list,'FPC_HELP_DESTRUCTOR')
  1339. end
  1340. else
  1341. internalerror(200006162);
  1342. end;
  1343. procedure tcgx86.g_call_fail_helper(list : taasmoutput);
  1344. var
  1345. href : treference;
  1346. begin
  1347. if is_class(procinfo^._class) then
  1348. begin
  1349. reference_reset_base(href,procinfo^.framepointer,8);
  1350. a_load_ref_reg(list,OS_ADDR,href,R_ESI);
  1351. a_call_name(list,'FPC_HELP_FAIL_CLASS');
  1352. end
  1353. else if is_object(procinfo^._class) then
  1354. begin
  1355. reference_reset_base(href,procinfo^.framepointer,12);
  1356. a_load_ref_reg(list,OS_ADDR,href,R_ESI);
  1357. rg.getexplicitregisterint(list,R_EDI);
  1358. a_load_const_reg(list,OS_ADDR,procinfo^._class.vmt_offset,R_EDI);
  1359. a_call_name(list,'FPC_HELP_FAIL');
  1360. rg.ungetregisterint(list,R_EDI);
  1361. end
  1362. else
  1363. internalerror(200006163);
  1364. end;
  1365. {$endif}
  1366. procedure tcgx86.g_save_standard_registers(list : taasmoutput);
  1367. begin
  1368. if (R_EBX in aktprocdef.usedregisters) then
  1369. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBX));
  1370. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ESI));
  1371. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDI));
  1372. end;
  1373. procedure tcgx86.g_restore_standard_registers(list : taasmoutput);
  1374. begin
  1375. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDI));
  1376. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ESI));
  1377. if (R_EBX in aktprocdef.usedregisters) then
  1378. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EBX));
  1379. end;
  1380. procedure tcgx86.g_save_all_registers(list : taasmoutput);
  1381. begin
  1382. list.concat(Taicpu.Op_none(A_PUSHA,S_L));
  1383. end;
  1384. procedure tcgx86.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  1385. var
  1386. href : treference;
  1387. begin
  1388. if selfused then
  1389. begin
  1390. reference_reset_base(href,R_ESP,4);
  1391. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_ESI,href));
  1392. end;
  1393. if acchiused then
  1394. begin
  1395. reference_reset_base(href,R_ESP,20);
  1396. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_EDX,href));
  1397. end;
  1398. if accused then
  1399. begin
  1400. reference_reset_base(href,R_ESP,28);
  1401. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_EAX,href));
  1402. end;
  1403. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1404. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1405. list.concat(taicpu.op_none(A_NOP,S_L));
  1406. end;
  1407. { produces if necessary overflowcode }
  1408. procedure tcgx86.g_overflowcheck(list: taasmoutput; const p: tnode);
  1409. var
  1410. hl : tasmlabel;
  1411. ai : taicpu;
  1412. cond : TAsmCond;
  1413. begin
  1414. if not(cs_check_overflow in aktlocalswitches) then
  1415. exit;
  1416. objectlibrary.getlabel(hl);
  1417. if not ((p.resulttype.def.deftype=pointerdef) or
  1418. ((p.resulttype.def.deftype=orddef) and
  1419. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1420. bool8bit,bool16bit,bool32bit]))) then
  1421. cond:=C_NO
  1422. else
  1423. cond:=C_NB;
  1424. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1425. ai.SetCondition(cond);
  1426. ai.is_jmp:=true;
  1427. list.concat(ai);
  1428. a_call_name(list,'FPC_OVERFLOW');
  1429. a_label(list,hl);
  1430. end;
  1431. end.
  1432. {
  1433. $Log$
  1434. Revision 1.10 2002-08-15 08:13:54 carl
  1435. - a_load_sym_ofs_reg removed
  1436. * loadvmt now calls loadaddr_ref_reg instead
  1437. Revision 1.9 2002/08/11 14:32:33 peter
  1438. * renamed current_library to objectlibrary
  1439. Revision 1.8 2002/08/11 13:24:20 peter
  1440. * saving of asmsymbols in ppu supported
  1441. * asmsymbollist global is removed and moved into a new class
  1442. tasmlibrarydata that will hold the info of a .a file which
  1443. corresponds with a single module. Added librarydata to tmodule
  1444. to keep the library info stored for the module. In the future the
  1445. objectfiles will also be stored to the tasmlibrarydata class
  1446. * all getlabel/newasmsymbol and friends are moved to the new class
  1447. Revision 1.7 2002/08/10 10:06:04 jonas
  1448. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1449. Revision 1.6 2002/08/09 19:18:27 carl
  1450. * fix generic exception handling
  1451. Revision 1.5 2002/08/04 19:52:04 carl
  1452. + updated exception routines
  1453. Revision 1.4 2002/07/27 19:53:51 jonas
  1454. + generic implementation of tcg.g_flags2ref()
  1455. * tcg.flags2xxx() now also needs a size parameter
  1456. Revision 1.3 2002/07/26 21:15:46 florian
  1457. * rewrote the system handling
  1458. Revision 1.2 2002/07/21 16:55:34 jonas
  1459. * fixed bug in op_const_reg_reg() for imul
  1460. Revision 1.1 2002/07/20 19:28:47 florian
  1461. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1462. cgx86.pas will contain the common code for i386 and x86_64
  1463. }