cgx86.pas 66 KB

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