cgx86.pas 66 KB

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