cgx86.pas 61 KB

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