cgx86.pas 62 KB

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