cgx86.pas 64 KB

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