cgx86.pas 66 KB

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