cgx86.pas 66 KB

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