cgx86.pas 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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,cpupara,
  27. node,symconst;
  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; 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; size: tcgsize; a : aword;reg : tregister);override;
  53. procedure a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);override;
  54. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  55. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;reg : tregister);override;
  56. procedure a_load_reg_reg(list : taasmoutput;size : 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; 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:treference;elesize:integer);override;
  85. procedure g_removevaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);override;
  86. procedure g_interrupt_stackframe_entry(list : taasmoutput);override;
  87. procedure g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  88. procedure g_profilecode(list : taasmoutput);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. {$ifndef TEST_GENERIC}
  93. procedure g_call_constructor_helper(list : taasmoutput);override;
  94. procedure g_call_destructor_helper(list : taasmoutput);override;
  95. procedure g_call_fail_helper(list : taasmoutput);override;
  96. {$endif}
  97. procedure g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  98. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  99. procedure g_save_all_registers(list : taasmoutput);override;
  100. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  101. procedure g_overflowcheck(list: taasmoutput; const p: tnode);override;
  102. private
  103. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  104. procedure sizes2load(s1 : tcgsize;s2 : topsize; var op: tasmop; var s3: topsize);
  105. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  106. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  107. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  108. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  109. end;
  110. const
  111. TCGSize2OpSize: Array[tcgsize] of topsize =
  112. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  113. S_FS,S_FL,S_FX,S_IQ,
  114. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  115. implementation
  116. uses
  117. globtype,globals,verbose,systems,cutils,
  118. symdef,symsym,defbase,paramgr,
  119. rgobj,tgobj,rgcpu;
  120. {$ifndef NOTARGETWIN32}
  121. const
  122. winstackpagesize = 4096;
  123. {$endif NOTARGETWIN32}
  124. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  125. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  126. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  127. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  128. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  129. {****************************************************************************
  130. This is private property, keep out! :)
  131. ****************************************************************************}
  132. procedure tcgx86.sizes2load(s1 : tcgsize;s2: topsize; var op: tasmop; var s3: topsize);
  133. begin
  134. case s2 of
  135. S_B:
  136. if S1 in [OS_8,OS_S8] then
  137. s3 := S_B
  138. else internalerror(200109221);
  139. S_W:
  140. case s1 of
  141. OS_8,OS_S8:
  142. s3 := S_BW;
  143. OS_16,OS_S16:
  144. s3 := S_W;
  145. else internalerror(200109222);
  146. end;
  147. S_L:
  148. case s1 of
  149. OS_8,OS_S8:
  150. s3 := S_BL;
  151. OS_16,OS_S16:
  152. s3 := S_WL;
  153. OS_32,OS_S32:
  154. s3 := S_L;
  155. else internalerror(200109223);
  156. end;
  157. else internalerror(200109227);
  158. end;
  159. if s3 in [S_B,S_W,S_L] then
  160. op := A_MOV
  161. else if s1 in [OS_8,OS_16,OS_32] then
  162. op := A_MOVZX
  163. else
  164. op := A_MOVSX;
  165. end;
  166. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  167. begin
  168. case t of
  169. OS_F32 :
  170. begin
  171. op:=A_FLD;
  172. s:=S_FS;
  173. end;
  174. OS_F64 :
  175. begin
  176. op:=A_FLD;
  177. { ???? }
  178. s:=S_FL;
  179. end;
  180. OS_F80 :
  181. begin
  182. op:=A_FLD;
  183. s:=S_FX;
  184. end;
  185. OS_C64 :
  186. begin
  187. op:=A_FILD;
  188. s:=S_IQ;
  189. end;
  190. else
  191. internalerror(200204041);
  192. end;
  193. end;
  194. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  195. var
  196. op : tasmop;
  197. s : topsize;
  198. begin
  199. floatloadops(t,op,s);
  200. list.concat(Taicpu.Op_ref(op,s,ref));
  201. inc(trgcpu(rg).fpuvaroffset);
  202. end;
  203. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  204. begin
  205. case t of
  206. OS_F32 :
  207. begin
  208. op:=A_FSTP;
  209. s:=S_FS;
  210. end;
  211. OS_F64 :
  212. begin
  213. op:=A_FSTP;
  214. s:=S_FL;
  215. end;
  216. OS_F80 :
  217. begin
  218. op:=A_FSTP;
  219. s:=S_FX;
  220. end;
  221. OS_C64 :
  222. begin
  223. op:=A_FISTP;
  224. s:=S_IQ;
  225. end;
  226. else
  227. internalerror(200204042);
  228. end;
  229. end;
  230. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  231. var
  232. op : tasmop;
  233. s : topsize;
  234. begin
  235. floatstoreops(t,op,s);
  236. list.concat(Taicpu.Op_ref(op,s,ref));
  237. dec(trgcpu(rg).fpuvaroffset);
  238. end;
  239. {****************************************************************************
  240. Assembler code
  241. ****************************************************************************}
  242. function tcgx86.reg_cgsize(const reg: tregister): tcgsize;
  243. const
  244. regsize_2_cgsize: array[S_B..S_L] of tcgsize = (OS_8,OS_16,OS_32);
  245. begin
  246. result := regsize_2_cgsize[reg2opsize[reg]];
  247. end;
  248. { currently does nothing }
  249. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  250. begin
  251. a_jmp_cond(list, OC_NONE, l);
  252. end;
  253. { we implement the following routines because otherwise we can't }
  254. { instantiate the class since it's abstract }
  255. procedure tcgx86.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  256. begin
  257. case size of
  258. OS_8,OS_S8,
  259. OS_16,OS_S16:
  260. begin
  261. if target_info.alignment.paraalign = 2 then
  262. list.concat(taicpu.op_reg(A_PUSH,S_W,rg.makeregsize(r,OS_16)))
  263. else
  264. list.concat(taicpu.op_reg(A_PUSH,S_L,rg.makeregsize(r,OS_32)));
  265. end;
  266. OS_32,OS_S32:
  267. list.concat(taicpu.op_reg(A_PUSH,S_L,r));
  268. else
  269. internalerror(2002032212);
  270. end;
  271. end;
  272. procedure tcgx86.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  273. begin
  274. case size of
  275. OS_8,OS_S8,OS_16,OS_S16:
  276. begin
  277. if target_info.alignment.paraalign = 2 then
  278. list.concat(taicpu.op_const(A_PUSH,S_W,a))
  279. else
  280. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  281. end;
  282. OS_32,OS_S32:
  283. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  284. else
  285. internalerror(2002032213);
  286. end;
  287. end;
  288. procedure tcgx86.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  289. var
  290. tmpreg: tregister;
  291. begin
  292. case size of
  293. OS_8,OS_S8,
  294. OS_16,OS_S16:
  295. begin
  296. tmpreg := get_scratch_reg_address(list);
  297. a_load_ref_reg(list,size,r,tmpreg);
  298. if target_info.alignment.paraalign = 2 then
  299. list.concat(taicpu.op_reg(A_PUSH,S_W,rg.makeregsize(tmpreg,OS_16)))
  300. else
  301. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  302. free_scratch_reg(list,tmpreg);
  303. end;
  304. OS_32,OS_S32:
  305. list.concat(taicpu.op_ref(A_PUSH,S_L,r));
  306. else
  307. internalerror(2002032214);
  308. end;
  309. end;
  310. procedure tcgx86.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  311. var
  312. tmpreg: tregister;
  313. begin
  314. if r.segment<>R_NO then
  315. CGMessage(cg_e_cant_use_far_pointer_there);
  316. if (r.base=R_NO) and (r.index=R_NO) then
  317. list.concat(Taicpu.Op_sym_ofs(A_PUSH,S_L,r.symbol,r.offset))
  318. else if (r.base=R_NO) and (r.index<>R_NO) and
  319. (r.offset=0) and (r.scalefactor=0) and (r.symbol=nil) then
  320. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.index))
  321. else if (r.base<>R_NO) and (r.index=R_NO) and
  322. (r.offset=0) and (r.symbol=nil) then
  323. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.base))
  324. else
  325. begin
  326. tmpreg := get_scratch_reg_address(list);
  327. a_loadaddr_ref_reg(list,r,tmpreg);
  328. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  329. free_scratch_reg(list,tmpreg);
  330. end;
  331. end;
  332. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  333. begin
  334. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s)));
  335. end;
  336. procedure tcgx86.a_call_ref(list : taasmoutput;const ref : treference);
  337. begin
  338. list.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  339. end;
  340. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  341. begin
  342. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  343. end;
  344. {********************** load instructions ********************}
  345. procedure tcgx86.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  346. begin
  347. { the optimizer will change it to "xor reg,reg" when loading zero, }
  348. { no need to do it here too (JM) }
  349. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[size],a,reg))
  350. end;
  351. procedure tcgx86.a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);
  352. begin
  353. {$ifdef OPTLOAD0}
  354. { zero is often used several times in succession -> load it in a }
  355. { register and then store it to memory, so the optimizer can then }
  356. { remove the unnecessary loads of registers and you get smaller }
  357. { (and faster) code }
  358. if (a = 0) and
  359. (size in [OS_32,OS_S32]) then
  360. inherited a_load_const_ref(list,size,a,ref)
  361. else
  362. {$endif OPTLOAD0}
  363. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[size],a,ref));
  364. end;
  365. procedure tcgx86.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  366. begin
  367. list.concat(taicpu.op_reg_ref(A_MOV,TCGSize2OpSize[size],reg,
  368. ref));
  369. End;
  370. procedure tcgx86.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  371. var
  372. op: tasmop;
  373. s: topsize;
  374. begin
  375. sizes2load(size,reg2opsize[reg],op,s);
  376. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  377. end;
  378. procedure tcgx86.a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);
  379. var
  380. op: tasmop;
  381. s: topsize;
  382. begin
  383. sizes2load(size,reg2opsize[reg2],op,s);
  384. if (rg.makeregsize(reg1,OS_INT) = rg.makeregsize(reg2,OS_INT)) then
  385. begin
  386. { "mov reg1, reg1" doesn't make sense }
  387. if op = A_MOV then
  388. exit;
  389. { optimize movzx with "and ffff,<reg>" operation }
  390. if (op = A_MOVZX) then
  391. begin
  392. case size of
  393. OS_8:
  394. begin
  395. list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2],255,reg2));
  396. exit;
  397. end;
  398. OS_16:
  399. begin
  400. list.concat(taicpu.op_const_reg(A_AND,reg2opsize[reg2],65535,reg2));
  401. exit;
  402. end;
  403. end;
  404. end;
  405. end;
  406. list.concat(taicpu.op_reg_reg(op,s,reg1,reg2));
  407. end;
  408. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  409. begin
  410. if assigned(ref.symbol) and
  411. (ref.base=R_NO) and
  412. (ref.index=R_NO) then
  413. list.concat(taicpu.op_sym_ofs_reg(A_MOV,S_L,ref.symbol,ref.offset,r))
  414. else
  415. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  416. end;
  417. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  418. { R_ST means "the current value at the top of the fpu stack" (JM) }
  419. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  420. begin
  421. if (reg1 <> R_ST) then
  422. begin
  423. list.concat(taicpu.op_reg(A_FLD,S_NO,
  424. trgcpu(rg).correct_fpuregister(reg1,trgcpu(rg).fpuvaroffset)));
  425. inc(trgcpu(rg).fpuvaroffset);
  426. end;
  427. if (reg2 <> R_ST) then
  428. begin
  429. list.concat(taicpu.op_reg(A_FSTP,S_NO,
  430. trgcpu(rg).correct_fpuregister(reg2,trgcpu(rg).fpuvaroffset)));
  431. dec(trgcpu(rg).fpuvaroffset);
  432. end;
  433. end;
  434. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  435. begin
  436. floatload(list,size,ref);
  437. if (reg <> R_ST) then
  438. a_loadfpu_reg_reg(list,R_ST,reg);
  439. end;
  440. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  441. begin
  442. if reg <> R_ST then
  443. a_loadfpu_reg_reg(list,reg,R_ST);
  444. floatstore(list,size,ref);
  445. end;
  446. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  447. begin
  448. list.concat(taicpu.op_reg_reg(A_MOVQ,S_NO,reg1,reg2));
  449. end;
  450. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister);
  451. begin
  452. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  453. end;
  454. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference);
  455. begin
  456. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  457. end;
  458. procedure tcgx86.a_parammm_reg(list: taasmoutput; reg: tregister);
  459. var
  460. href : treference;
  461. begin
  462. list.concat(taicpu.op_const_reg(A_SUB,S_L,8,R_ESP));
  463. reference_reset_base(href,R_ESP,0);
  464. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,href));
  465. end;
  466. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  467. var
  468. opcode: tasmop;
  469. power: longint;
  470. begin
  471. Case Op of
  472. OP_DIV, OP_IDIV:
  473. Begin
  474. if ispowerof2(a,power) then
  475. begin
  476. case op of
  477. OP_DIV:
  478. opcode := A_SHR;
  479. OP_IDIV:
  480. opcode := A_SAR;
  481. end;
  482. list.concat(taicpu.op_const_reg(opcode,reg2opsize[reg],power,
  483. reg));
  484. exit;
  485. end;
  486. { the rest should be handled specifically in the code }
  487. { generator because of the silly register usage restraints }
  488. internalerror(200109224);
  489. End;
  490. OP_MUL,OP_IMUL:
  491. begin
  492. if not(cs_check_overflow in aktlocalswitches) and
  493. ispowerof2(a,power) then
  494. begin
  495. list.concat(taicpu.op_const_reg(A_SHL,reg2opsize[reg],power,
  496. reg));
  497. exit;
  498. end;
  499. if op = OP_IMUL then
  500. list.concat(taicpu.op_const_reg(A_IMUL,reg2opsize[reg],
  501. a,reg))
  502. else
  503. { OP_MUL should be handled specifically in the code }
  504. { generator because of the silly register usage restraints }
  505. internalerror(200109225);
  506. end;
  507. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  508. if not(cs_check_overflow in aktlocalswitches) and
  509. (a = 1) and
  510. (op in [OP_ADD,OP_SUB]) then
  511. if op = OP_ADD then
  512. list.concat(taicpu.op_reg(A_INC,reg2opsize[reg],reg))
  513. else
  514. list.concat(taicpu.op_reg(A_DEC,reg2opsize[reg],reg))
  515. else if (a = 0) then
  516. if (op <> OP_AND) then
  517. exit
  518. else
  519. list.concat(taicpu.op_const_reg(A_MOV,reg2opsize[reg],0,reg))
  520. else if (a = high(aword)) and
  521. (op in [OP_AND,OP_OR,OP_XOR]) then
  522. begin
  523. case op of
  524. OP_AND:
  525. exit;
  526. OP_OR:
  527. list.concat(taicpu.op_const_reg(A_MOV,reg2opsize[reg],high(aword),reg));
  528. OP_XOR:
  529. list.concat(taicpu.op_reg(A_NOT,reg2opsize[reg],reg));
  530. end
  531. end
  532. else
  533. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],reg2opsize[reg],
  534. a,reg));
  535. OP_SHL,OP_SHR,OP_SAR:
  536. begin
  537. if (a and 31) <> 0 Then
  538. list.concat(taicpu.op_const_reg(
  539. TOpCG2AsmOp[op],reg2opsize[reg],a and 31,reg));
  540. if (a shr 5) <> 0 Then
  541. internalerror(68991);
  542. end
  543. else internalerror(68992);
  544. end;
  545. end;
  546. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  547. var
  548. opcode: tasmop;
  549. power: longint;
  550. begin
  551. Case Op of
  552. OP_DIV, OP_IDIV:
  553. Begin
  554. if ispowerof2(a,power) then
  555. begin
  556. case op of
  557. OP_DIV:
  558. opcode := A_SHR;
  559. OP_IDIV:
  560. opcode := A_SAR;
  561. end;
  562. list.concat(taicpu.op_const_ref(opcode,
  563. TCgSize2OpSize[size],power,ref));
  564. exit;
  565. end;
  566. { the rest should be handled specifically in the code }
  567. { generator because of the silly register usage restraints }
  568. internalerror(200109231);
  569. End;
  570. OP_MUL,OP_IMUL:
  571. begin
  572. if not(cs_check_overflow in aktlocalswitches) and
  573. ispowerof2(a,power) then
  574. begin
  575. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  576. power,ref));
  577. exit;
  578. end;
  579. { can't multiply a memory location directly with a constant }
  580. if op = OP_IMUL then
  581. inherited a_op_const_ref(list,op,size,a,ref)
  582. else
  583. { OP_MUL should be handled specifically in the code }
  584. { generator because of the silly register usage restraints }
  585. internalerror(200109232);
  586. end;
  587. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  588. if not(cs_check_overflow in aktlocalswitches) and
  589. (a = 1) and
  590. (op in [OP_ADD,OP_SUB]) then
  591. if op = OP_ADD then
  592. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  593. else
  594. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  595. else if (a = 0) then
  596. if (op <> OP_AND) then
  597. exit
  598. else
  599. a_load_const_ref(list,size,0,ref)
  600. else if (a = high(aword)) and
  601. (op in [OP_AND,OP_OR,OP_XOR]) then
  602. begin
  603. case op of
  604. OP_AND:
  605. exit;
  606. OP_OR:
  607. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],high(aword),ref));
  608. OP_XOR:
  609. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  610. end
  611. end
  612. else
  613. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  614. TCgSize2OpSize[size],a,ref));
  615. OP_SHL,OP_SHR,OP_SAR:
  616. begin
  617. if (a and 31) <> 0 Then
  618. list.concat(taicpu.op_const_ref(
  619. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  620. if (a shr 5) <> 0 Then
  621. internalerror(68991);
  622. end
  623. else internalerror(68992);
  624. end;
  625. end;
  626. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  627. var
  628. regloadsize: tcgsize;
  629. dstsize: topsize;
  630. tmpreg : tregister;
  631. popecx : boolean;
  632. begin
  633. dstsize := tcgsize2opsize[size];
  634. dst := rg.makeregsize(dst,size);
  635. case op of
  636. OP_NEG,OP_NOT:
  637. begin
  638. if src <> R_NO then
  639. internalerror(200112291);
  640. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  641. end;
  642. OP_MUL,OP_DIV,OP_IDIV:
  643. { special stuff, needs separate handling inside code }
  644. { generator }
  645. internalerror(200109233);
  646. OP_SHR,OP_SHL,OP_SAR:
  647. begin
  648. tmpreg := R_NO;
  649. popecx := false;
  650. { we need cl to hold the shift count, so if the destination }
  651. { is ecx, save it to a temp for now }
  652. if dst in [R_ECX,R_CX,R_CL] then
  653. begin
  654. case reg2opsize[dst] of
  655. S_B: regloadsize := OS_8;
  656. S_W: regloadsize := OS_16;
  657. else regloadsize := OS_32;
  658. end;
  659. tmpreg := get_scratch_reg_int(list);
  660. a_load_reg_reg(list,regloadsize,src,tmpreg);
  661. end;
  662. if not(src in [R_ECX,R_CX,R_CL]) then
  663. begin
  664. { is ecx still free (it's also free if it was allocated }
  665. { to dst, since we've moved dst somewhere else already) }
  666. if not((dst = R_ECX) or
  667. ((R_ECX in rg.unusedregsint) and
  668. { this will always be true, it's just here to }
  669. { allocate ecx }
  670. (rg.getexplicitregisterint(list,R_ECX) = R_ECX))) then
  671. begin
  672. list.concat(taicpu.op_reg(A_PUSH,S_L,R_ECX));
  673. popecx := true;
  674. end;
  675. a_load_reg_reg(list,OS_32,rg.makeregsize(src,OS_32),R_ECX);
  676. end
  677. else
  678. src := R_CL;
  679. { do the shift }
  680. if tmpreg = R_NO then
  681. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  682. R_CL,dst))
  683. else
  684. begin
  685. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],S_L,
  686. R_CL,tmpreg));
  687. { move result back to the destination }
  688. a_load_reg_reg(list,OS_32,tmpreg,R_ECX);
  689. free_scratch_reg(list,tmpreg);
  690. end;
  691. if popecx then
  692. list.concat(taicpu.op_reg(A_POP,S_L,R_ECX))
  693. else if not (dst in [R_ECX,R_CX,R_CL]) then
  694. rg.ungetregisterint(list,R_ECX);
  695. end;
  696. else
  697. begin
  698. if reg2opsize[src] <> dstsize then
  699. internalerror(200109226);
  700. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  701. src,dst));
  702. end;
  703. end;
  704. end;
  705. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  706. begin
  707. case op of
  708. OP_NEG,OP_NOT,OP_IMUL:
  709. begin
  710. inherited a_op_ref_reg(list,op,size,ref,reg);
  711. end;
  712. OP_MUL,OP_DIV,OP_IDIV:
  713. { special stuff, needs separate handling inside code }
  714. { generator }
  715. internalerror(200109239);
  716. else
  717. begin
  718. reg := rg.makeregsize(reg,size);
  719. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  720. end;
  721. end;
  722. end;
  723. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  724. var
  725. opsize: topsize;
  726. begin
  727. case op of
  728. OP_NEG,OP_NOT:
  729. begin
  730. if reg <> R_NO then
  731. internalerror(200109237);
  732. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  733. end;
  734. OP_IMUL:
  735. begin
  736. { this one needs a load/imul/store, which is the default }
  737. inherited a_op_ref_reg(list,op,size,ref,reg);
  738. end;
  739. OP_MUL,OP_DIV,OP_IDIV:
  740. { special stuff, needs separate handling inside code }
  741. { generator }
  742. internalerror(200109238);
  743. else
  744. begin
  745. opsize := tcgsize2opsize[size];
  746. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],opsize,reg,ref));
  747. end;
  748. end;
  749. end;
  750. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  751. size: tcgsize; a: aword; src, dst: tregister);
  752. var
  753. tmpref: treference;
  754. power: longint;
  755. opsize: topsize;
  756. begin
  757. opsize := reg2opsize[src];
  758. if (opsize <> S_L) or
  759. not (size in [OS_32,OS_S32]) then
  760. begin
  761. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  762. exit;
  763. end;
  764. { if we get here, we have to do a 32 bit calculation, guaranteed }
  765. Case Op of
  766. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  767. OP_SAR:
  768. { can't do anything special for these }
  769. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  770. OP_IMUL:
  771. begin
  772. if not(cs_check_overflow in aktlocalswitches) and
  773. ispowerof2(a,power) then
  774. { can be done with a shift }
  775. begin
  776. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  777. exit;
  778. end;
  779. list.concat(taicpu.op_const_reg_reg(A_IMUL,S_L,a,src,dst));
  780. end;
  781. OP_ADD, OP_SUB:
  782. if (a = 0) then
  783. a_load_reg_reg(list,size,src,dst)
  784. else
  785. begin
  786. reference_reset(tmpref);
  787. tmpref.base := src;
  788. tmpref.offset := longint(a);
  789. if op = OP_SUB then
  790. tmpref.offset := -tmpref.offset;
  791. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  792. end
  793. else internalerror(200112302);
  794. end;
  795. end;
  796. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  797. size: tcgsize; src1, src2, dst: tregister);
  798. var
  799. tmpref: treference;
  800. opsize: topsize;
  801. begin
  802. opsize := reg2opsize[src1];
  803. if (opsize <> S_L) or
  804. (reg2opsize[src2] <> S_L) or
  805. not (size in [OS_32,OS_S32]) then
  806. begin
  807. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  808. exit;
  809. end;
  810. { if we get here, we have to do a 32 bit calculation, guaranteed }
  811. Case Op of
  812. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  813. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  814. { can't do anything special for these }
  815. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  816. OP_IMUL:
  817. list.concat(taicpu.op_reg_reg_reg(A_IMUL,S_L,src1,src2,dst));
  818. OP_ADD:
  819. begin
  820. reference_reset(tmpref);
  821. tmpref.base := src1;
  822. tmpref.index := src2;
  823. tmpref.scalefactor := 1;
  824. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  825. end
  826. else internalerror(200112303);
  827. end;
  828. end;
  829. {*************** compare instructructions ****************}
  830. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  831. l : tasmlabel);
  832. begin
  833. if (a = 0) then
  834. list.concat(taicpu.op_reg_reg(A_TEST,reg2opsize[reg],reg,reg))
  835. else
  836. list.concat(taicpu.op_const_reg(A_CMP,reg2opsize[reg],a,reg));
  837. a_jmp_cond(list,cmp_op,l);
  838. end;
  839. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  840. l : tasmlabel);
  841. begin
  842. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  843. a_jmp_cond(list,cmp_op,l);
  844. end;
  845. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  846. reg1,reg2 : tregister;l : tasmlabel);
  847. begin
  848. if reg2opsize[reg1] <> reg2opsize[reg2] then
  849. internalerror(200109226);
  850. list.concat(taicpu.op_reg_reg(A_CMP,reg2opsize[reg1],reg1,reg2));
  851. a_jmp_cond(list,cmp_op,l);
  852. end;
  853. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  854. begin
  855. reg := rg.makeregsize(reg,size);
  856. list.concat(taicpu.op_ref_reg(A_CMP,tcgsize2opsize[size],ref,reg));
  857. a_jmp_cond(list,cmp_op,l);
  858. end;
  859. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  860. var
  861. ai : taicpu;
  862. begin
  863. if cond=OC_None then
  864. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  865. else
  866. begin
  867. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  868. ai.SetCondition(TOpCmp2AsmCond[cond]);
  869. end;
  870. ai.is_jmp:=true;
  871. list.concat(ai);
  872. end;
  873. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  874. var
  875. ai : taicpu;
  876. begin
  877. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  878. ai.SetCondition(flags_to_cond(f));
  879. ai.is_jmp := true;
  880. list.concat(ai);
  881. end;
  882. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  883. var
  884. ai : taicpu;
  885. hreg : tregister;
  886. begin
  887. hreg := rg.makeregsize(reg,OS_8);
  888. ai:=Taicpu.Op_reg(A_Setcc,S_B,hreg);
  889. ai.SetCondition(flags_to_cond(f));
  890. list.concat(ai);
  891. if (reg <> hreg) then
  892. a_load_reg_reg(list,OS_8,hreg,reg);
  893. end;
  894. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  895. var
  896. ai : taicpu;
  897. begin
  898. if not(size in [OS_8,OS_S8]) then
  899. a_load_const_ref(list,size,0,ref);
  900. ai:=Taicpu.Op_ref(A_Setcc,S_B,ref);
  901. ai.SetCondition(flags_to_cond(f));
  902. list.concat(ai);
  903. end;
  904. { ************* concatcopy ************ }
  905. procedure tcgx86.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  906. var
  907. ecxpushed : boolean;
  908. helpsize : longint;
  909. i : byte;
  910. reg8,reg32 : tregister;
  911. srcref,dstref : treference;
  912. swap : boolean;
  913. procedure maybepushecx;
  914. begin
  915. if not(R_ECX in rg.unusedregsint) then
  916. begin
  917. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ECX));
  918. ecxpushed:=true;
  919. end
  920. else rg.getexplicitregisterint(list,R_ECX);
  921. end;
  922. begin
  923. if (not loadref) and
  924. ((len<=8) or
  925. (not(cs_littlesize in aktglobalswitches ) and (len<=12))) then
  926. begin
  927. helpsize:=len shr 2;
  928. rg.getexplicitregisterint(list,R_EDI);
  929. dstref:=dest;
  930. srcref:=source;
  931. for i:=1 to helpsize do
  932. begin
  933. a_load_ref_reg(list,OS_32,srcref,R_EDI);
  934. If (len = 4) and delsource then
  935. reference_release(list,source);
  936. a_load_reg_ref(list,OS_32,R_EDI,dstref);
  937. inc(srcref.offset,4);
  938. inc(dstref.offset,4);
  939. dec(len,4);
  940. end;
  941. if len>1 then
  942. begin
  943. a_load_ref_reg(list,OS_16,srcref,R_DI);
  944. If (len = 2) and delsource then
  945. reference_release(list,source);
  946. a_load_reg_ref(list,OS_16,R_DI,dstref);
  947. inc(srcref.offset,2);
  948. inc(dstref.offset,2);
  949. dec(len,2);
  950. end;
  951. rg.ungetregisterint(list,R_EDI);
  952. if len>0 then
  953. begin
  954. { and now look for an 8 bit register }
  955. swap:=false;
  956. if R_EAX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EAX),OS_8)
  957. else if R_EDX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EDX),OS_8)
  958. else if R_EBX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_EBX),OS_8)
  959. else if R_ECX in rg.unusedregsint then reg8:=rg.makeregsize(rg.getexplicitregisterint(list,R_ECX),OS_8)
  960. else
  961. begin
  962. swap:=true;
  963. { we need only to check 3 registers, because }
  964. { one is always not index or base }
  965. if (dest.base<>R_EAX) and (dest.index<>R_EAX) then
  966. begin
  967. reg8:=R_AL;
  968. reg32:=R_EAX;
  969. end
  970. else if (dest.base<>R_EBX) and (dest.index<>R_EBX) then
  971. begin
  972. reg8:=R_BL;
  973. reg32:=R_EBX;
  974. end
  975. else if (dest.base<>R_ECX) and (dest.index<>R_ECX) then
  976. begin
  977. reg8:=R_CL;
  978. reg32:=R_ECX;
  979. end;
  980. end;
  981. if swap then
  982. { was earlier XCHG, of course nonsense }
  983. begin
  984. rg.getexplicitregisterint(list,R_EDI);
  985. a_load_reg_reg(list,OS_32,reg32,R_EDI);
  986. end;
  987. a_load_ref_reg(list,OS_8,srcref,reg8);
  988. If delsource and (len=1) then
  989. reference_release(list,source);
  990. a_load_reg_ref(list,OS_8,reg8,dstref);
  991. if swap then
  992. begin
  993. a_load_reg_reg(list,OS_32,R_EDI,reg32);
  994. rg.ungetregisterint(list,R_EDI);
  995. end
  996. else
  997. rg.ungetregister(list,reg8);
  998. end;
  999. end
  1000. else
  1001. begin
  1002. rg.getexplicitregisterint(list,R_EDI);
  1003. a_loadaddr_ref_reg(list,dest,R_EDI);
  1004. list.concat(tai_regalloc.Alloc(R_ESI));
  1005. if loadref then
  1006. a_load_ref_reg(list,OS_ADDR,source,R_ESI)
  1007. else
  1008. begin
  1009. a_loadaddr_ref_reg(list,source,R_ESI);
  1010. if delsource then
  1011. reference_release(list,source);
  1012. end;
  1013. list.concat(Taicpu.Op_none(A_CLD,S_NO));
  1014. ecxpushed:=false;
  1015. if cs_littlesize in aktglobalswitches then
  1016. begin
  1017. maybepushecx;
  1018. a_load_const_reg(list,OS_INT,len,R_ECX);
  1019. list.concat(Taicpu.Op_none(A_REP,S_NO));
  1020. list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1021. end
  1022. else
  1023. begin
  1024. helpsize:=len shr 2;
  1025. len:=len and 3;
  1026. if helpsize>1 then
  1027. begin
  1028. maybepushecx;
  1029. a_load_const_reg(list,OS_INT,helpsize,R_ECX);
  1030. list.concat(Taicpu.Op_none(A_REP,S_NO));
  1031. end;
  1032. if helpsize>0 then
  1033. list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1034. if len>1 then
  1035. begin
  1036. dec(len,2);
  1037. list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1038. end;
  1039. if len=1 then
  1040. list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1041. end;
  1042. rg.ungetregisterint(list,R_EDI);
  1043. list.concat(tai_regalloc.DeAlloc(R_ESI));
  1044. if ecxpushed then
  1045. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ECX))
  1046. else
  1047. rg.ungetregisterint(list,R_ECX);
  1048. { loading SELF-reference again }
  1049. g_maybe_loadself(list);
  1050. end;
  1051. if delsource then
  1052. tg.ungetiftemp(list,source);
  1053. end;
  1054. procedure tcgx86.g_exception_reason_save(list : taasmoutput; const href : treference);
  1055. begin
  1056. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1057. end;
  1058. procedure tcgx86.g_exception_reason_save_const(list : taasmoutput;const href : treference; a: aword);
  1059. begin
  1060. list.concat(Taicpu.op_const(A_PUSH,S_L,a));
  1061. end;
  1062. procedure tcgx86.g_exception_reason_load(list : taasmoutput; const href : treference);
  1063. begin
  1064. list.concat(Taicpu.op_reg(A_POP,S_L,R_EAX));
  1065. end;
  1066. {****************************************************************************
  1067. Entry/Exit Code Helpers
  1068. ****************************************************************************}
  1069. procedure tcgx86.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);
  1070. var
  1071. lenref : treference;
  1072. power,len : longint;
  1073. opsize : topsize;
  1074. {$ifndef __NOWINPECOFF__}
  1075. again,ok : tasmlabel;
  1076. {$endif}
  1077. begin
  1078. lenref:=ref;
  1079. inc(lenref.offset,4);
  1080. { get stack space }
  1081. rg.getexplicitregisterint(list,R_EDI);
  1082. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_EDI));
  1083. list.concat(Taicpu.op_reg(A_INC,S_L,R_EDI));
  1084. if (elesize<>1) then
  1085. begin
  1086. if ispowerof2(elesize, power) then
  1087. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_EDI))
  1088. else
  1089. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,R_EDI));
  1090. end;
  1091. {$ifndef __NOWINPECOFF__}
  1092. { windows guards only a few pages for stack growing, }
  1093. { so we have to access every page first }
  1094. if target_info.system=system_i386_win32 then
  1095. begin
  1096. objectlibrary.getlabel(again);
  1097. objectlibrary.getlabel(ok);
  1098. a_label(list,again);
  1099. list.concat(Taicpu.op_const_reg(A_CMP,S_L,winstackpagesize,R_EDI));
  1100. a_jmp_cond(list,OC_B,ok);
  1101. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,R_ESP));
  1102. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1103. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize,R_EDI));
  1104. a_jmp_always(list,again);
  1105. a_label(list,ok);
  1106. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,R_EDI,R_ESP));
  1107. rg.ungetregisterint(list,R_EDI);
  1108. { now reload EDI }
  1109. rg.getexplicitregisterint(list,R_EDI);
  1110. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_EDI));
  1111. list.concat(Taicpu.op_reg(A_INC,S_L,R_EDI));
  1112. if (elesize<>1) then
  1113. begin
  1114. if ispowerof2(elesize, power) then
  1115. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_EDI))
  1116. else
  1117. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,R_EDI));
  1118. end;
  1119. end
  1120. else
  1121. {$endif __NOWINPECOFF__}
  1122. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,R_EDI,R_ESP));
  1123. { load destination }
  1124. list.concat(Taicpu.op_reg_reg(A_MOV,S_L,R_ESP,R_EDI));
  1125. { don't destroy the registers! }
  1126. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_ECX));
  1127. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_ESI));
  1128. { load count }
  1129. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_ECX));
  1130. { load source }
  1131. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,ref,R_ESI));
  1132. { scheduled .... }
  1133. list.concat(Taicpu.op_reg(A_INC,S_L,R_ECX));
  1134. { calculate size }
  1135. len:=elesize;
  1136. opsize:=S_B;
  1137. if (len and 3)=0 then
  1138. begin
  1139. opsize:=S_L;
  1140. len:=len shr 2;
  1141. end
  1142. else
  1143. if (len and 1)=0 then
  1144. begin
  1145. opsize:=S_W;
  1146. len:=len shr 1;
  1147. end;
  1148. if ispowerof2(len, power) then
  1149. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_ECX))
  1150. else
  1151. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,R_ECX));
  1152. list.concat(Taicpu.op_none(A_REP,S_NO));
  1153. case opsize of
  1154. S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1155. S_W : list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1156. S_L : list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1157. end;
  1158. rg.ungetregisterint(list,R_EDI);
  1159. list.concat(Taicpu.op_reg(A_POP,S_L,R_ESI));
  1160. list.concat(Taicpu.op_reg(A_POP,S_L,R_ECX));
  1161. { patch the new address }
  1162. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,R_ESP,ref));
  1163. end;
  1164. procedure tcgx86.g_removevaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);
  1165. var
  1166. lenref : treference;
  1167. power,len : longint;
  1168. begin
  1169. lenref:=ref;
  1170. inc(lenref.offset,4);
  1171. { caluclate size and adjust stack space }
  1172. rg.getexplicitregisterint(list,R_EDI);
  1173. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,R_EDI));
  1174. list.concat(Taicpu.op_reg(A_INC,S_L,R_EDI));
  1175. if (elesize<>1) then
  1176. begin
  1177. if ispowerof2(elesize, power) then
  1178. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,R_EDI))
  1179. else
  1180. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,R_EDI));
  1181. end;
  1182. list.concat(Taicpu.op_reg_reg(A_ADD,S_L,R_EDI,R_ESP));
  1183. end;
  1184. procedure tcgx86.g_interrupt_stackframe_entry(list : taasmoutput);
  1185. begin
  1186. { .... also the segment registers }
  1187. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_GS));
  1188. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_FS));
  1189. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_ES));
  1190. list.concat(Taicpu.Op_reg(A_PUSH,S_W,R_DS));
  1191. { save the registers of an interrupt procedure }
  1192. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDI));
  1193. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ESI));
  1194. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDX));
  1195. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ECX));
  1196. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBX));
  1197. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EAX));
  1198. end;
  1199. procedure tcgx86.g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);
  1200. begin
  1201. if accused then
  1202. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1203. else
  1204. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EAX));
  1205. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EBX));
  1206. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ECX));
  1207. if acchiused then
  1208. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1209. else
  1210. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDX));
  1211. if selfused then
  1212. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,R_ESP))
  1213. else
  1214. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ESI));
  1215. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDI));
  1216. { .... also the segment registers }
  1217. list.concat(Taicpu.Op_reg(A_POP,S_W,R_DS));
  1218. list.concat(Taicpu.Op_reg(A_POP,S_W,R_ES));
  1219. list.concat(Taicpu.Op_reg(A_POP,S_W,R_FS));
  1220. list.concat(Taicpu.Op_reg(A_POP,S_W,R_GS));
  1221. { this restores the flags }
  1222. list.concat(Taicpu.Op_none(A_IRET,S_NO));
  1223. end;
  1224. procedure tcgx86.g_profilecode(list : taasmoutput);
  1225. var
  1226. pl : tasmlabel;
  1227. begin
  1228. case target_info.system of
  1229. system_i386_win32,
  1230. system_i386_freebsd,
  1231. system_i386_wdosx,
  1232. system_i386_linux:
  1233. begin
  1234. objectlibrary.getaddrlabel(pl);
  1235. list.concat(Tai_section.Create(sec_data));
  1236. list.concat(Tai_align.Create(4));
  1237. list.concat(Tai_label.Create(pl));
  1238. list.concat(Tai_const.Create_32bit(0));
  1239. list.concat(Tai_section.Create(sec_code));
  1240. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,R_EDX));
  1241. a_call_name(list,target_info.Cprefix+'mcount');
  1242. include(rg.usedinproc,R_EDX);
  1243. end;
  1244. system_i386_go32v2:
  1245. begin
  1246. a_call_name(list,'MCOUNT');
  1247. end;
  1248. end;
  1249. end;
  1250. procedure tcgx86.g_stackframe_entry(list : taasmoutput;localsize : longint);
  1251. var
  1252. href : treference;
  1253. i : integer;
  1254. again : tasmlabel;
  1255. begin
  1256. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBP));
  1257. list.concat(Taicpu.Op_reg_reg(A_MOV,S_L,R_ESP,R_EBP));
  1258. if localsize>0 then
  1259. begin
  1260. {$ifndef NOTARGETWIN32}
  1261. { windows guards only a few pages for stack growing, }
  1262. { so we have to access every page first }
  1263. if (target_info.system=system_i386_win32) and
  1264. (localsize>=winstackpagesize) then
  1265. begin
  1266. if localsize div winstackpagesize<=5 then
  1267. begin
  1268. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,R_ESP));
  1269. for i:=1 to localsize div winstackpagesize do
  1270. begin
  1271. reference_reset_base(href,R_ESP,localsize-i*winstackpagesize);
  1272. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1273. end;
  1274. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1275. end
  1276. else
  1277. begin
  1278. objectlibrary.getlabel(again);
  1279. rg.getexplicitregisterint(list,R_EDI);
  1280. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,R_EDI));
  1281. a_label(list,again);
  1282. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,R_ESP));
  1283. list.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  1284. list.concat(Taicpu.op_reg(A_DEC,S_L,R_EDI));
  1285. a_jmp_cond(list,OC_NE,again);
  1286. rg.ungetregisterint(list,R_EDI);
  1287. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,R_ESP));
  1288. end
  1289. end
  1290. else
  1291. {$endif NOTARGETWIN32}
  1292. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize,R_ESP));
  1293. end;
  1294. end;
  1295. procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
  1296. begin
  1297. list.concat(Taicpu.Op_none(A_LEAVE,S_NO));
  1298. end;
  1299. procedure tcgx86.g_return_from_proc(list : taasmoutput;parasize : aword);
  1300. begin
  1301. { Routines with the poclearstack flag set use only a ret }
  1302. { also routines with parasize=0 }
  1303. if (po_clearstack in aktprocdef.procoptions) then
  1304. begin
  1305. { complex return values are removed from stack in C code PM }
  1306. if paramanager.ret_in_param(aktprocdef.rettype.def) then
  1307. list.concat(Taicpu.Op_const(A_RET,S_NO,4))
  1308. else
  1309. list.concat(Taicpu.Op_none(A_RET,S_NO));
  1310. end
  1311. else if (parasize=0) then
  1312. list.concat(Taicpu.Op_none(A_RET,S_NO))
  1313. else
  1314. begin
  1315. { parameters are limited to 65535 bytes because }
  1316. { ret allows only imm16 }
  1317. if (parasize>65535) then
  1318. CGMessage(cg_e_parasize_too_big);
  1319. list.concat(Taicpu.Op_const(A_RET,S_NO,parasize));
  1320. end;
  1321. end;
  1322. {$ifndef TEST_GENERIC}
  1323. procedure tcgx86.g_call_constructor_helper(list : taasmoutput);
  1324. begin
  1325. if is_class(procinfo._class) then
  1326. begin
  1327. procinfo.flags:=procinfo.flags or pi_needs_implicit_finally;
  1328. a_call_name(list,'FPC_NEW_CLASS');
  1329. list.concat(Taicpu.Op_cond_sym(A_Jcc,C_Z,S_NO,faillabel));
  1330. end
  1331. else if is_object(procinfo._class) then
  1332. begin
  1333. rg.getexplicitregisterint(list,R_EDI);
  1334. a_load_const_reg(list,OS_ADDR,procinfo._class.vmt_offset,R_EDI);
  1335. a_call_name(list,'FPC_HELP_CONSTRUCTOR');
  1336. list.concat(Taicpu.Op_cond_sym(A_Jcc,C_Z,S_NO,faillabel));
  1337. end
  1338. else
  1339. internalerror(200006161);
  1340. end;
  1341. procedure tcgx86.g_call_destructor_helper(list : taasmoutput);
  1342. var
  1343. nofinal : tasmlabel;
  1344. href : treference;
  1345. begin
  1346. if is_class(procinfo._class) then
  1347. begin
  1348. a_call_name(list,'FPC_DISPOSE_CLASS')
  1349. end
  1350. else if is_object(procinfo._class) then
  1351. begin
  1352. { must the object be finalized ? }
  1353. if procinfo._class.needs_inittable then
  1354. begin
  1355. objectlibrary.getlabel(nofinal);
  1356. reference_reset_base(href,R_EBP,8);
  1357. a_cmp_const_ref_label(list,OS_ADDR,OC_EQ,0,href,nofinal);
  1358. reference_reset_base(href,R_ESI,0);
  1359. g_finalize(list,procinfo._class,href,false);
  1360. a_label(list,nofinal);
  1361. end;
  1362. rg.getexplicitregisterint(list,R_EDI);
  1363. a_load_const_reg(list,OS_ADDR,procinfo._class.vmt_offset,R_EDI);
  1364. rg.ungetregisterint(list,R_EDI);
  1365. a_call_name(list,'FPC_HELP_DESTRUCTOR')
  1366. end
  1367. else
  1368. internalerror(200006162);
  1369. end;
  1370. procedure tcgx86.g_call_fail_helper(list : taasmoutput);
  1371. var
  1372. href : treference;
  1373. begin
  1374. if is_class(procinfo._class) then
  1375. begin
  1376. reference_reset_base(href,procinfo.framepointer,8);
  1377. a_load_ref_reg(list,OS_ADDR,href,R_ESI);
  1378. a_call_name(list,'FPC_HELP_FAIL_CLASS');
  1379. end
  1380. else if is_object(procinfo._class) then
  1381. begin
  1382. reference_reset_base(href,procinfo.framepointer,12);
  1383. a_load_ref_reg(list,OS_ADDR,href,R_ESI);
  1384. rg.getexplicitregisterint(list,R_EDI);
  1385. a_load_const_reg(list,OS_ADDR,procinfo._class.vmt_offset,R_EDI);
  1386. a_call_name(list,'FPC_HELP_FAIL');
  1387. rg.ungetregisterint(list,R_EDI);
  1388. end
  1389. else
  1390. internalerror(200006163);
  1391. end;
  1392. {$endif}
  1393. procedure tcgx86.g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  1394. begin
  1395. if (R_EBX in usedinproc) then
  1396. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EBX));
  1397. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_ESI));
  1398. list.concat(Taicpu.Op_reg(A_PUSH,S_L,R_EDI));
  1399. end;
  1400. procedure tcgx86.g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  1401. begin
  1402. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EDI));
  1403. list.concat(Taicpu.Op_reg(A_POP,S_L,R_ESI));
  1404. if (R_EBX in usedinproc) then
  1405. list.concat(Taicpu.Op_reg(A_POP,S_L,R_EBX));
  1406. end;
  1407. procedure tcgx86.g_save_all_registers(list : taasmoutput);
  1408. begin
  1409. list.concat(Taicpu.Op_none(A_PUSHA,S_L));
  1410. end;
  1411. procedure tcgx86.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  1412. var
  1413. href : treference;
  1414. begin
  1415. if selfused then
  1416. begin
  1417. reference_reset_base(href,R_ESP,4);
  1418. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_ESI,href));
  1419. end;
  1420. if acchiused then
  1421. begin
  1422. reference_reset_base(href,R_ESP,20);
  1423. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_EDX,href));
  1424. end;
  1425. if accused then
  1426. begin
  1427. reference_reset_base(href,R_ESP,28);
  1428. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,R_EAX,href));
  1429. end;
  1430. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1431. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1432. list.concat(taicpu.op_none(A_NOP,S_L));
  1433. end;
  1434. { produces if necessary overflowcode }
  1435. procedure tcgx86.g_overflowcheck(list: taasmoutput; const p: tnode);
  1436. var
  1437. hl : tasmlabel;
  1438. ai : taicpu;
  1439. cond : TAsmCond;
  1440. begin
  1441. if not(cs_check_overflow in aktlocalswitches) then
  1442. exit;
  1443. objectlibrary.getlabel(hl);
  1444. if not ((p.resulttype.def.deftype=pointerdef) or
  1445. ((p.resulttype.def.deftype=orddef) and
  1446. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1447. bool8bit,bool16bit,bool32bit]))) then
  1448. cond:=C_NO
  1449. else
  1450. cond:=C_NB;
  1451. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1452. ai.SetCondition(cond);
  1453. ai.is_jmp:=true;
  1454. list.concat(ai);
  1455. a_call_name(list,'FPC_OVERFLOW');
  1456. a_label(list,hl);
  1457. end;
  1458. end.
  1459. {
  1460. $Log$
  1461. Revision 1.15 2002-09-16 18:06:29 peter
  1462. * move CGSize2Opsize to interface
  1463. Revision 1.14 2002/09/01 14:42:41 peter
  1464. * removevaluepara added to fix the stackpointer so restoring of
  1465. saved registers works
  1466. Revision 1.13 2002/09/01 12:09:27 peter
  1467. + a_call_reg, a_call_loc added
  1468. * removed exprasmlist references
  1469. Revision 1.12 2002/08/17 09:23:50 florian
  1470. * first part of procinfo rewrite
  1471. Revision 1.11 2002/08/16 14:25:00 carl
  1472. * issameref() to test if two references are the same (then emit no opcodes)
  1473. + ret_in_reg to replace ret_in_acc
  1474. (fix some register allocation bugs at the same time)
  1475. + save_std_register now has an extra parameter which is the
  1476. usedinproc registers
  1477. Revision 1.10 2002/08/15 08:13:54 carl
  1478. - a_load_sym_ofs_reg removed
  1479. * loadvmt now calls loadaddr_ref_reg instead
  1480. Revision 1.9 2002/08/11 14:32:33 peter
  1481. * renamed current_library to objectlibrary
  1482. Revision 1.8 2002/08/11 13:24:20 peter
  1483. * saving of asmsymbols in ppu supported
  1484. * asmsymbollist global is removed and moved into a new class
  1485. tasmlibrarydata that will hold the info of a .a file which
  1486. corresponds with a single module. Added librarydata to tmodule
  1487. to keep the library info stored for the module. In the future the
  1488. objectfiles will also be stored to the tasmlibrarydata class
  1489. * all getlabel/newasmsymbol and friends are moved to the new class
  1490. Revision 1.7 2002/08/10 10:06:04 jonas
  1491. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1492. Revision 1.6 2002/08/09 19:18:27 carl
  1493. * fix generic exception handling
  1494. Revision 1.5 2002/08/04 19:52:04 carl
  1495. + updated exception routines
  1496. Revision 1.4 2002/07/27 19:53:51 jonas
  1497. + generic implementation of tcg.g_flags2ref()
  1498. * tcg.flags2xxx() now also needs a size parameter
  1499. Revision 1.3 2002/07/26 21:15:46 florian
  1500. * rewrote the system handling
  1501. Revision 1.2 2002/07/21 16:55:34 jonas
  1502. * fixed bug in op_const_reg_reg() for imul
  1503. Revision 1.1 2002/07/20 19:28:47 florian
  1504. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1505. cgx86.pas will contain the common code for i386 and x86_64
  1506. }