cgx86.pas 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  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,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 locpara.alignment = 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 locpara.alignment = 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 locpara.alignment = 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. tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
  1348. cg.a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESP,current_procinfo.save_regs_ref);
  1349. end;
  1350. procedure tcgx86.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  1351. var
  1352. href : treference;
  1353. begin
  1354. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_ESP);
  1355. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1356. if acchiused then
  1357. begin
  1358. reference_reset_base(href,NR_ESP,20);
  1359. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EDX,href));
  1360. end;
  1361. if accused then
  1362. begin
  1363. reference_reset_base(href,NR_ESP,28);
  1364. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1365. end;
  1366. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1367. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1368. list.concat(taicpu.op_none(A_NOP,S_L));
  1369. end;
  1370. { produces if necessary overflowcode }
  1371. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1372. var
  1373. hl : tasmlabel;
  1374. ai : taicpu;
  1375. cond : TAsmCond;
  1376. begin
  1377. if not(cs_check_overflow in aktlocalswitches) then
  1378. exit;
  1379. objectlibrary.getlabel(hl);
  1380. if not ((def.deftype=pointerdef) or
  1381. ((def.deftype=orddef) and
  1382. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1383. bool8bit,bool16bit,bool32bit]))) then
  1384. cond:=C_NO
  1385. else
  1386. cond:=C_NB;
  1387. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1388. ai.SetCondition(cond);
  1389. ai.is_jmp:=true;
  1390. list.concat(ai);
  1391. a_call_name(list,'FPC_OVERFLOW');
  1392. a_label(list,hl);
  1393. end;
  1394. end.
  1395. {
  1396. $Log$
  1397. Revision 1.72 2003-10-03 22:00:33 peter
  1398. * parameter alignment fixes
  1399. Revision 1.71 2003/10/03 14:45:37 peter
  1400. * save ESP after pusha and restore before popa for save all registers
  1401. Revision 1.70 2003/10/01 20:34:51 peter
  1402. * procinfo unit contains tprocinfo
  1403. * cginfo renamed to cgbase
  1404. * moved cgmessage to verbose
  1405. * fixed ppc and sparc compiles
  1406. Revision 1.69 2003/09/30 19:53:47 peter
  1407. * fix pushw reg
  1408. Revision 1.68 2003/09/29 20:58:56 peter
  1409. * optimized releasing of registers
  1410. Revision 1.67 2003/09/28 13:37:19 peter
  1411. * a_call_ref removed
  1412. Revision 1.66 2003/09/25 21:29:16 peter
  1413. * change push/pop in getreg/ungetreg
  1414. Revision 1.65 2003/09/25 13:13:32 florian
  1415. * more x86-64 fixes
  1416. Revision 1.64 2003/09/11 11:55:00 florian
  1417. * improved arm code generation
  1418. * move some protected and private field around
  1419. * the temp. register for register parameters/arguments are now released
  1420. before the move to the parameter register is done. This improves
  1421. the code in a lot of cases.
  1422. Revision 1.63 2003/09/09 21:03:17 peter
  1423. * basics for x86 register calling
  1424. Revision 1.62 2003/09/09 20:59:27 daniel
  1425. * Adding register allocation order
  1426. Revision 1.61 2003/09/07 22:09:35 peter
  1427. * preparations for different default calling conventions
  1428. * various RA fixes
  1429. Revision 1.60 2003/09/05 17:41:13 florian
  1430. * merged Wiktor's Watcom patches in 1.1
  1431. Revision 1.59 2003/09/03 15:55:02 peter
  1432. * NEWRA branch merged
  1433. Revision 1.58.2.5 2003/08/31 20:40:50 daniel
  1434. * Fixed add_edges_used
  1435. Revision 1.58.2.4 2003/08/31 15:46:26 peter
  1436. * more updates for tregister
  1437. Revision 1.58.2.3 2003/08/29 17:29:00 peter
  1438. * next batch of updates
  1439. Revision 1.58.2.2 2003/08/28 18:35:08 peter
  1440. * tregister changed to cardinal
  1441. Revision 1.58.2.1 2003/08/27 21:06:34 peter
  1442. * more updates
  1443. Revision 1.58 2003/08/20 19:28:21 daniel
  1444. * Small NOTARGETWIN32 conditional tweak
  1445. Revision 1.57 2003/07/03 18:59:25 peter
  1446. * loadfpu_reg_reg size specifier
  1447. Revision 1.56 2003/06/14 14:53:50 jonas
  1448. * fixed newra cycle for x86
  1449. * added constants for indicating source and destination operands of the
  1450. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1451. Revision 1.55 2003/06/13 21:19:32 peter
  1452. * current_procdef removed, use current_procinfo.procdef instead
  1453. Revision 1.54 2003/06/12 18:31:18 peter
  1454. * fix newra cycle for i386
  1455. Revision 1.53 2003/06/07 10:24:10 peter
  1456. * fixed copyvaluepara for left-to-right pushing
  1457. Revision 1.52 2003/06/07 10:06:55 jonas
  1458. * fixed cycling problem
  1459. Revision 1.51 2003/06/03 21:11:09 peter
  1460. * cg.a_load_* get a from and to size specifier
  1461. * makeregsize only accepts newregister
  1462. * i386 uses generic tcgnotnode,tcgunaryminus
  1463. Revision 1.50 2003/06/03 13:01:59 daniel
  1464. * Register allocator finished
  1465. Revision 1.49 2003/06/01 21:38:07 peter
  1466. * getregisterfpu size parameter added
  1467. * op_const_reg size parameter added
  1468. * sparc updates
  1469. Revision 1.48 2003/05/30 23:57:08 peter
  1470. * more sparc cleanup
  1471. * accumulator removed, splitted in function_return_reg (called) and
  1472. function_result_reg (caller)
  1473. Revision 1.47 2003/05/22 21:33:31 peter
  1474. * removed some unit dependencies
  1475. Revision 1.46 2003/05/16 14:33:31 peter
  1476. * regvar fixes
  1477. Revision 1.45 2003/05/15 18:58:54 peter
  1478. * removed selfpointer_offset, vmtpointer_offset
  1479. * tvarsym.adjusted_address
  1480. * address in localsymtable is now in the real direction
  1481. * removed some obsolete globals
  1482. Revision 1.44 2003/04/30 20:53:32 florian
  1483. * error when address of an abstract method is taken
  1484. * fixed some x86-64 problems
  1485. * merged some more x86-64 and i386 code
  1486. Revision 1.43 2003/04/27 11:21:36 peter
  1487. * aktprocdef renamed to current_procinfo.procdef
  1488. * procinfo renamed to current_procinfo
  1489. * procinfo will now be stored in current_module so it can be
  1490. cleaned up properly
  1491. * gen_main_procsym changed to create_main_proc and release_main_proc
  1492. to also generate a tprocinfo structure
  1493. * fixed unit implicit initfinal
  1494. Revision 1.42 2003/04/23 14:42:08 daniel
  1495. * Further register allocator work. Compiler now smaller with new
  1496. allocator than without.
  1497. * Somebody forgot to adjust ppu version number
  1498. Revision 1.41 2003/04/23 09:51:16 daniel
  1499. * Removed usage of edi in a lot of places when new register allocator used
  1500. + Added newra versions of g_concatcopy and secondadd_float
  1501. Revision 1.40 2003/04/22 13:47:08 peter
  1502. * fixed C style array of const
  1503. * fixed C array passing
  1504. * fixed left to right with high parameters
  1505. Revision 1.39 2003/04/22 10:09:35 daniel
  1506. + Implemented the actual register allocator
  1507. + Scratch registers unavailable when new register allocator used
  1508. + maybe_save/maybe_restore unavailable when new register allocator used
  1509. Revision 1.38 2003/04/17 16:48:21 daniel
  1510. * Added some code to keep track of move instructions in register
  1511. allocator
  1512. Revision 1.37 2003/03/28 19:16:57 peter
  1513. * generic constructor working for i386
  1514. * remove fixed self register
  1515. * esi added as address register for i386
  1516. Revision 1.36 2003/03/18 18:17:46 peter
  1517. * reg2opsize()
  1518. Revision 1.35 2003/03/13 19:52:23 jonas
  1519. * and more new register allocator fixes (in the i386 code generator this
  1520. time). At least now the ppc cross compiler can compile the linux
  1521. system unit again, but I haven't tested it.
  1522. Revision 1.34 2003/02/27 16:40:32 daniel
  1523. * Fixed ie 200301234 problem on Win32 target
  1524. Revision 1.33 2003/02/26 21:15:43 daniel
  1525. * Fixed the optimizer
  1526. Revision 1.32 2003/02/19 22:00:17 daniel
  1527. * Code generator converted to new register notation
  1528. - Horribily outdated todo.txt removed
  1529. Revision 1.31 2003/01/21 10:41:13 daniel
  1530. * Fixed another 200301081
  1531. Revision 1.30 2003/01/13 23:00:18 daniel
  1532. * Fixed internalerror
  1533. Revision 1.29 2003/01/13 14:54:34 daniel
  1534. * Further work to convert codegenerator register convention;
  1535. internalerror bug fixed.
  1536. Revision 1.28 2003/01/09 20:41:00 daniel
  1537. * Converted some code in cgx86.pas to new register numbering
  1538. Revision 1.27 2003/01/08 18:43:58 daniel
  1539. * Tregister changed into a record
  1540. Revision 1.26 2003/01/05 13:36:53 florian
  1541. * x86-64 compiles
  1542. + very basic support for float128 type (x86-64 only)
  1543. Revision 1.25 2003/01/02 16:17:50 peter
  1544. * align stack on 4 bytes in copyvalueopenarray
  1545. Revision 1.24 2002/12/24 15:56:50 peter
  1546. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1547. this for the pageprotection
  1548. Revision 1.23 2002/11/25 18:43:34 carl
  1549. - removed the invalid if <> checking (Delphi is strange on this)
  1550. + implemented abstract warning on instance creation of class with
  1551. abstract methods.
  1552. * some error message cleanups
  1553. Revision 1.22 2002/11/25 17:43:29 peter
  1554. * splitted defbase in defutil,symutil,defcmp
  1555. * merged isconvertable and is_equal into compare_defs(_ext)
  1556. * made operator search faster by walking the list only once
  1557. Revision 1.21 2002/11/18 17:32:01 peter
  1558. * pass proccalloption to ret_in_xxx and push_xxx functions
  1559. Revision 1.20 2002/11/09 21:18:31 carl
  1560. * flags2reg() was not extending the byte register to the correct result size
  1561. Revision 1.19 2002/10/16 19:01:43 peter
  1562. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1563. implicit exception frames for procedures with initialized variables
  1564. and for constructors. The default is on for compatibility
  1565. Revision 1.18 2002/10/05 12:43:30 carl
  1566. * fixes for Delphi 6 compilation
  1567. (warning : Some features do not work under Delphi)
  1568. Revision 1.17 2002/09/17 18:54:06 jonas
  1569. * a_load_reg_reg() now has two size parameters: source and dest. This
  1570. allows some optimizations on architectures that don't encode the
  1571. register size in the register name.
  1572. Revision 1.16 2002/09/16 19:08:47 peter
  1573. * support references without registers and symbol in paramref_addr. It
  1574. pushes only the offset
  1575. Revision 1.15 2002/09/16 18:06:29 peter
  1576. * move CGSize2Opsize to interface
  1577. Revision 1.14 2002/09/01 14:42:41 peter
  1578. * removevaluepara added to fix the stackpointer so restoring of
  1579. saved registers works
  1580. Revision 1.13 2002/09/01 12:09:27 peter
  1581. + a_call_reg, a_call_loc added
  1582. * removed exprasmlist references
  1583. Revision 1.12 2002/08/17 09:23:50 florian
  1584. * first part of procinfo rewrite
  1585. Revision 1.11 2002/08/16 14:25:00 carl
  1586. * issameref() to test if two references are the same (then emit no opcodes)
  1587. + ret_in_reg to replace ret_in_acc
  1588. (fix some register allocation bugs at the same time)
  1589. + save_std_register now has an extra parameter which is the
  1590. usedinproc registers
  1591. Revision 1.10 2002/08/15 08:13:54 carl
  1592. - a_load_sym_ofs_reg removed
  1593. * loadvmt now calls loadaddr_ref_reg instead
  1594. Revision 1.9 2002/08/11 14:32:33 peter
  1595. * renamed current_library to objectlibrary
  1596. Revision 1.8 2002/08/11 13:24:20 peter
  1597. * saving of asmsymbols in ppu supported
  1598. * asmsymbollist global is removed and moved into a new class
  1599. tasmlibrarydata that will hold the info of a .a file which
  1600. corresponds with a single module. Added librarydata to tmodule
  1601. to keep the library info stored for the module. In the future the
  1602. objectfiles will also be stored to the tasmlibrarydata class
  1603. * all getlabel/newasmsymbol and friends are moved to the new class
  1604. Revision 1.7 2002/08/10 10:06:04 jonas
  1605. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1606. Revision 1.6 2002/08/09 19:18:27 carl
  1607. * fix generic exception handling
  1608. Revision 1.5 2002/08/04 19:52:04 carl
  1609. + updated exception routines
  1610. Revision 1.4 2002/07/27 19:53:51 jonas
  1611. + generic implementation of tcg.g_flags2ref()
  1612. * tcg.flags2xxx() now also needs a size parameter
  1613. Revision 1.3 2002/07/26 21:15:46 florian
  1614. * rewrote the system handling
  1615. Revision 1.2 2002/07/21 16:55:34 jonas
  1616. * fixed bug in op_const_reg_reg() for imul
  1617. Revision 1.1 2002/07/20 19:28:47 florian
  1618. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1619. cgx86.pas will contain the common code for i386 and x86_64
  1620. }