cgx86.pas 63 KB

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