cgx86.pas 63 KB

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