cgx86.pas 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287
  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. cgbase,cgobj,
  25. aasmbase,aasmtai,aasmcpu,
  26. cpubase,cpuinfo,rgobj,rgcpu,
  27. symconst,symtype;
  28. type
  29. tcgx86 = class(tcg)
  30. rgfpu : Trgx86fpu;
  31. procedure init_register_allocators;override;
  32. procedure done_register_allocators;override;
  33. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;override;
  34. function getmmxregister(list:Taasmoutput):Tregister;
  35. procedure getexplicitregister(list:Taasmoutput;r:Tregister);override;
  36. procedure ungetregister(list:Taasmoutput;r:Tregister);override;
  37. procedure allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);override;
  38. procedure deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);override;
  39. function uses_registers(rt:Tregistertype):boolean;override;
  40. procedure add_reg_instruction(instr:Tai;r:tregister);override;
  41. procedure dec_fpu_stack;
  42. procedure inc_fpu_stack;
  43. { passing parameters, per default the parameter is pushed }
  44. { nr gives the number of the parameter (enumerated from }
  45. { left to right), this allows to move the parameter to }
  46. { register, if the cpu supports register calling }
  47. { conventions }
  48. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);override;
  49. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  50. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  51. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  52. procedure a_call_name(list : taasmoutput;const s : string);override;
  53. procedure a_call_reg(list : taasmoutput;reg : tregister);override;
  54. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); override;
  55. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); override;
  56. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  57. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  58. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  59. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  60. size: tcgsize; a: aword; src, dst: tregister); override;
  61. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  62. size: tcgsize; src1, src2, dst: tregister); override;
  63. { move instructions }
  64. procedure a_load_const_reg(list : taasmoutput; tosize: tcgsize; a : aword;reg : tregister);override;
  65. procedure a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aword;const ref : treference);override;
  66. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize: tcgsize; reg : tregister;const ref : treference);override;
  67. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize: tcgsize;const ref : treference;reg : tregister);override;
  68. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize: tcgsize;reg1,reg2 : tregister);override;
  69. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  70. { fpu move instructions }
  71. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  72. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  73. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  74. { vector register move instructions }
  75. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); override;
  76. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  77. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  78. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  79. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);override;
  80. { comparison operations }
  81. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  82. l : tasmlabel);override;
  83. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  84. l : tasmlabel);override;
  85. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  86. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  87. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  88. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  89. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  90. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference); override;
  91. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  92. procedure g_exception_reason_save(list : taasmoutput; const href : treference);override;
  93. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);override;
  94. procedure g_exception_reason_load(list : taasmoutput; const href : treference);override;
  95. { entry/exit code helpers }
  96. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);override;
  97. procedure g_interrupt_stackframe_entry(list : taasmoutput);override;
  98. procedure g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);override;
  99. procedure g_profilecode(list : taasmoutput);override;
  100. procedure g_stackpointer_alloc(list : taasmoutput;localsize : longint);override;
  101. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  102. procedure g_restore_frame_pointer(list : taasmoutput);override;
  103. procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
  104. procedure g_save_standard_registers(list:Taasmoutput);override;
  105. procedure g_restore_standard_registers(list:Taasmoutput);override;
  106. procedure g_save_all_registers(list : taasmoutput);override;
  107. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
  108. procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
  109. protected
  110. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  111. procedure check_register_size(size:tcgsize;reg:tregister);
  112. procedure opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  113. private
  114. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  115. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  116. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  117. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  118. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  119. end;
  120. const
  121. TCGSize2OpSize: Array[tcgsize] of topsize =
  122. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  123. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  124. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  125. implementation
  126. uses
  127. globtype,globals,verbose,systems,cutils,
  128. symdef,paramgr,tgobj,procinfo;
  129. {$ifndef NOTARGETWIN32}
  130. const
  131. winstackpagesize = 4096;
  132. {$endif NOTARGETWIN32}
  133. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  134. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  135. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  136. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  137. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  138. procedure Tcgx86.init_register_allocators;
  139. begin
  140. if cs_create_pic in aktmoduleswitches then
  141. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_EAX,RS_EDX,RS_ECX,RS_ESI,RS_EDI],first_int_imreg,[RS_EBP,RS_EBX])
  142. else
  143. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_EAX,RS_EDX,RS_ECX,RS_EBX,RS_ESI,RS_EDI],first_int_imreg,[RS_EBP]);
  144. rg[R_MMXREGISTER]:=trgcpu.create(R_MMXREGISTER,R_SUBNONE,[RS_MM0,RS_MM1,RS_MM2,RS_MM3,RS_MM4,RS_MM5,RS_MM6,RS_MM7],first_sse_imreg,[]);
  145. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,[RS_MM0,RS_MM1,RS_MM2,RS_MM3,RS_MM4,RS_MM5,RS_MM6,RS_MM7],first_sse_imreg,[]);
  146. rgfpu:=Trgx86fpu.create;
  147. end;
  148. procedure Tcgx86.done_register_allocators;
  149. begin
  150. rg[R_INTREGISTER].free;
  151. rg[R_INTREGISTER]:=nil;
  152. rg[R_MMREGISTER].free;
  153. rg[R_MMREGISTER]:=nil;
  154. rg[R_MMXREGISTER].free;
  155. rg[R_MMXREGISTER]:=nil;
  156. rgfpu.free;
  157. end;
  158. function Tcgx86.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  159. begin
  160. result:=rgfpu.getregisterfpu(list);
  161. end;
  162. function Tcgx86.getmmxregister(list:Taasmoutput):Tregister;
  163. begin
  164. if not assigned(rg[R_MMXREGISTER]) then
  165. internalerror(200312124);
  166. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  167. end;
  168. procedure Tcgx86.getexplicitregister(list:Taasmoutput;r:Tregister);
  169. begin
  170. if getregtype(r)=R_FPUREGISTER then
  171. internalerror(2003121210)
  172. else
  173. inherited getexplicitregister(list,r);
  174. end;
  175. procedure tcgx86.ungetregister(list:Taasmoutput;r:Tregister);
  176. begin
  177. if getregtype(r)=R_FPUREGISTER then
  178. rgfpu.ungetregisterfpu(list,r)
  179. else
  180. inherited ungetregister(list,r);
  181. end;
  182. procedure Tcgx86.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  183. begin
  184. if rt<>R_FPUREGISTER then
  185. inherited allocexplicitregisters(list,rt,r);
  186. end;
  187. procedure Tcgx86.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  188. begin
  189. if rt<>R_FPUREGISTER then
  190. inherited deallocexplicitregisters(list,rt,r);
  191. end;
  192. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  193. begin
  194. if rt=R_FPUREGISTER then
  195. result:=false
  196. else
  197. result:=inherited uses_registers(rt);
  198. end;
  199. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  200. begin
  201. if getregtype(r)<>R_FPUREGISTER then
  202. inherited add_reg_instruction(instr,r);
  203. end;
  204. procedure tcgx86.dec_fpu_stack;
  205. begin
  206. dec(rgfpu.fpuvaroffset);
  207. end;
  208. procedure tcgx86.inc_fpu_stack;
  209. begin
  210. inc(rgfpu.fpuvaroffset);
  211. end;
  212. {****************************************************************************
  213. This is private property, keep out! :)
  214. ****************************************************************************}
  215. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  216. begin
  217. case s2 of
  218. OS_8,OS_S8 :
  219. if S1 in [OS_8,OS_S8] then
  220. s3 := S_B
  221. else internalerror(200109221);
  222. OS_16,OS_S16:
  223. case s1 of
  224. OS_8,OS_S8:
  225. s3 := S_BW;
  226. OS_16,OS_S16:
  227. s3 := S_W;
  228. else
  229. internalerror(200109222);
  230. end;
  231. OS_32,OS_S32:
  232. case s1 of
  233. OS_8,OS_S8:
  234. s3 := S_BL;
  235. OS_16,OS_S16:
  236. s3 := S_WL;
  237. OS_32,OS_S32:
  238. s3 := S_L;
  239. else
  240. internalerror(200109223);
  241. end;
  242. {$ifdef x86_64}
  243. OS_64,OS_S64:
  244. case s1 of
  245. OS_8,OS_S8:
  246. s3 := S_BQ;
  247. OS_16,OS_S16:
  248. s3 := S_WQ;
  249. OS_32,OS_S32:
  250. s3 := S_LQ;
  251. OS_64,OS_S64:
  252. s3 := S_Q;
  253. else
  254. internalerror(200304302);
  255. end;
  256. {$endif x86_64}
  257. else
  258. internalerror(200109227);
  259. end;
  260. if s3 in [S_B,S_W,S_L,S_Q] then
  261. op := A_MOV
  262. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  263. op := A_MOVZX
  264. else
  265. op := A_MOVSX;
  266. end;
  267. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  268. begin
  269. case t of
  270. OS_F32 :
  271. begin
  272. op:=A_FLD;
  273. s:=S_FS;
  274. end;
  275. OS_F64 :
  276. begin
  277. op:=A_FLD;
  278. { ???? }
  279. s:=S_FL;
  280. end;
  281. OS_F80 :
  282. begin
  283. op:=A_FLD;
  284. s:=S_FX;
  285. end;
  286. OS_C64 :
  287. begin
  288. op:=A_FILD;
  289. s:=S_IQ;
  290. end;
  291. else
  292. internalerror(200204041);
  293. end;
  294. end;
  295. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  296. var
  297. op : tasmop;
  298. s : topsize;
  299. begin
  300. floatloadops(t,op,s);
  301. list.concat(Taicpu.Op_ref(op,s,ref));
  302. inc_fpu_stack;
  303. end;
  304. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  305. begin
  306. case t of
  307. OS_F32 :
  308. begin
  309. op:=A_FSTP;
  310. s:=S_FS;
  311. end;
  312. OS_F64 :
  313. begin
  314. op:=A_FSTP;
  315. s:=S_FL;
  316. end;
  317. OS_F80 :
  318. begin
  319. op:=A_FSTP;
  320. s:=S_FX;
  321. end;
  322. OS_C64 :
  323. begin
  324. op:=A_FISTP;
  325. s:=S_IQ;
  326. end;
  327. else
  328. internalerror(200204042);
  329. end;
  330. end;
  331. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  332. var
  333. op : tasmop;
  334. s : topsize;
  335. begin
  336. floatstoreops(t,op,s);
  337. list.concat(Taicpu.Op_ref(op,s,ref));
  338. dec_fpu_stack;
  339. end;
  340. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  341. begin
  342. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  343. internalerror(200306031);
  344. end;
  345. {****************************************************************************
  346. Assembler code
  347. ****************************************************************************}
  348. { currently does nothing }
  349. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  350. begin
  351. a_jmp_cond(list, OC_NONE, l);
  352. end;
  353. { we implement the following routines because otherwise we can't }
  354. { instantiate the class since it's abstract }
  355. procedure tcgx86.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  356. begin
  357. check_register_size(size,r);
  358. if (locpara.loc=LOC_REFERENCE) and
  359. (locpara.reference.index=NR_STACK_POINTER_REG) then
  360. begin
  361. case size of
  362. OS_8,OS_S8,
  363. OS_16,OS_S16:
  364. begin
  365. if locpara.alignment = 2 then
  366. list.concat(taicpu.op_reg(A_PUSH,S_W,makeregsize(r,OS_16)))
  367. else
  368. list.concat(taicpu.op_reg(A_PUSH,S_L,makeregsize(r,OS_32)));
  369. end;
  370. OS_32,OS_S32:
  371. begin
  372. if getsubreg(r)<>R_SUBD then
  373. internalerror(7843);
  374. list.concat(taicpu.op_reg(A_PUSH,S_L,r));
  375. end
  376. else
  377. internalerror(2002032212);
  378. end;
  379. end
  380. else
  381. inherited a_param_reg(list,size,r,locpara);
  382. end;
  383. procedure tcgx86.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  384. begin
  385. if (locpara.loc=LOC_REFERENCE) and
  386. (locpara.reference.index=NR_STACK_POINTER_REG) then
  387. begin
  388. case size of
  389. OS_8,OS_S8,OS_16,OS_S16:
  390. begin
  391. if locpara.alignment = 2 then
  392. list.concat(taicpu.op_const(A_PUSH,S_W,a))
  393. else
  394. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  395. end;
  396. OS_32,OS_S32:
  397. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  398. else
  399. internalerror(2002032213);
  400. end;
  401. end
  402. else
  403. inherited a_param_const(list,size,a,locpara);
  404. end;
  405. procedure tcgx86.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  406. var
  407. pushsize : tcgsize;
  408. tmpreg : tregister;
  409. begin
  410. if (locpara.loc=LOC_REFERENCE) and
  411. (locpara.reference.index=NR_STACK_POINTER_REG) then
  412. begin
  413. case size of
  414. OS_8,OS_S8,
  415. OS_16,OS_S16:
  416. begin
  417. if locpara.alignment = 2 then
  418. pushsize:=OS_16
  419. else
  420. pushsize:=OS_32;
  421. tmpreg:=getintregister(list,pushsize);
  422. a_load_ref_reg(list,size,pushsize,r,tmpreg);
  423. list.concat(taicpu.op_reg(A_PUSH,TCgsize2opsize[pushsize],tmpreg));
  424. ungetregister(list,tmpreg);
  425. end;
  426. OS_32,OS_S32:
  427. list.concat(taicpu.op_ref(A_PUSH,S_L,r));
  428. {$ifdef cpu64bit}
  429. OS_64,OS_S64:
  430. list.concat(taicpu.op_ref(A_PUSH,S_Q,r));
  431. {$endif cpu64bit}
  432. else
  433. internalerror(2002032214);
  434. end;
  435. end
  436. else
  437. inherited a_param_ref(list,size,r,locpara);
  438. end;
  439. procedure tcgx86.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  440. var
  441. tmpreg : tregister;
  442. begin
  443. if (r.segment<>NR_NO) then
  444. CGMessage(cg_e_cant_use_far_pointer_there);
  445. if (locpara.loc=LOC_REFERENCE) and
  446. (locpara.reference.index=NR_STACK_POINTER_REG) then
  447. begin
  448. if (r.base=NR_NO) and (r.index=NR_NO) then
  449. begin
  450. if assigned(r.symbol) then
  451. list.concat(Taicpu.Op_sym_ofs(A_PUSH,S_L,r.symbol,r.offset))
  452. else
  453. list.concat(Taicpu.Op_const(A_PUSH,S_L,r.offset));
  454. end
  455. else if (r.base=NR_NO) and (r.index<>NR_NO) and
  456. (r.offset=0) and (r.scalefactor=0) and (r.symbol=nil) then
  457. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.index))
  458. else if (r.base<>NR_NO) and (r.index=NR_NO) and
  459. (r.offset=0) and (r.symbol=nil) then
  460. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.base))
  461. else
  462. begin
  463. tmpreg:=getaddressregister(list);
  464. a_loadaddr_ref_reg(list,r,tmpreg);
  465. ungetregister(list,tmpreg);
  466. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  467. end;
  468. end
  469. else
  470. inherited a_paramaddr_ref(list,r,locpara);
  471. end;
  472. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  473. begin
  474. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s)));
  475. end;
  476. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  477. begin
  478. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  479. end;
  480. {********************** load instructions ********************}
  481. procedure tcgx86.a_load_const_reg(list : taasmoutput; tosize: TCGSize; a : aword; reg : TRegister);
  482. begin
  483. check_register_size(tosize,reg);
  484. { the optimizer will change it to "xor reg,reg" when loading zero, }
  485. { no need to do it here too (JM) }
  486. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  487. end;
  488. procedure tcgx86.a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aword;const ref : treference);
  489. begin
  490. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,ref));
  491. end;
  492. procedure tcgx86.a_load_reg_ref(list : taasmoutput; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  493. var
  494. op: tasmop;
  495. s: topsize;
  496. tmpreg : tregister;
  497. begin
  498. check_register_size(fromsize,reg);
  499. sizes2load(fromsize,tosize,op,s);
  500. case s of
  501. S_BW,S_BL,S_WL
  502. {$ifdef x86_64}
  503. ,S_BQ,S_WQ,S_LQ
  504. {$endif x86_64}
  505. :
  506. begin
  507. tmpreg:=getintregister(list,tosize);
  508. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  509. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  510. ungetregister(list,tmpreg);
  511. end;
  512. else
  513. list.concat(taicpu.op_reg_ref(op,s,reg,ref));
  514. end;
  515. end;
  516. procedure tcgx86.a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  517. var
  518. op: tasmop;
  519. s: topsize;
  520. begin
  521. check_register_size(tosize,reg);
  522. sizes2load(fromsize,tosize,op,s);
  523. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  524. end;
  525. procedure tcgx86.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  526. var
  527. op: tasmop;
  528. s: topsize;
  529. eq:boolean;
  530. instr:Taicpu;
  531. begin
  532. check_register_size(fromsize,reg1);
  533. check_register_size(tosize,reg2);
  534. sizes2load(fromsize,tosize,op,s);
  535. eq:=getsupreg(reg1)=getsupreg(reg2);
  536. if eq then
  537. begin
  538. { "mov reg1, reg1" doesn't make sense }
  539. if op = A_MOV then
  540. exit;
  541. end;
  542. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  543. {Notify the register allocator that we have written a move instruction so
  544. it can try to eliminate it.}
  545. add_move_instruction(instr);
  546. list.concat(instr);
  547. end;
  548. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  549. begin
  550. if (ref.base=NR_NO) and (ref.index=NR_NO) then
  551. begin
  552. if assigned(ref.symbol) then
  553. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,ref.symbol,ref.offset,r))
  554. else
  555. a_load_const_reg(list,OS_INT,ref.offset,r);
  556. end
  557. else if (ref.base=NR_NO) and (ref.index<>NR_NO) and
  558. (ref.offset=0) and (ref.scalefactor=0) and (ref.symbol=nil) then
  559. a_load_reg_reg(list,OS_INT,OS_INT,ref.index,r)
  560. else if (ref.base<>NR_NO) and (ref.index=NR_NO) and
  561. (ref.offset=0) and (ref.symbol=nil) then
  562. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r)
  563. else
  564. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  565. end;
  566. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  567. { R_ST means "the current value at the top of the fpu stack" (JM) }
  568. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  569. begin
  570. if (reg1<>NR_ST) then
  571. begin
  572. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  573. inc_fpu_stack;
  574. end;
  575. if (reg2<>NR_ST) then
  576. begin
  577. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  578. dec_fpu_stack;
  579. end;
  580. end;
  581. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  582. begin
  583. floatload(list,size,ref);
  584. if (reg<>NR_ST) then
  585. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  586. end;
  587. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  588. begin
  589. if reg<>NR_ST then
  590. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  591. floatstore(list,size,ref);
  592. end;
  593. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  594. begin
  595. case fromsize of
  596. OS_F32:
  597. case tosize of
  598. OS_F64:
  599. result:=A_CVTSS2SD;
  600. OS_F32:
  601. result:=A_MOVSS;
  602. else
  603. internalerror(200312205);
  604. end;
  605. OS_F64:
  606. case tosize of
  607. OS_F64:
  608. result:=A_MOVSD;
  609. OS_F32:
  610. result:=A_CVTSD2SS;
  611. else
  612. internalerror(200312204);
  613. end;
  614. else
  615. internalerror(200312203);
  616. end;
  617. end;
  618. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  619. begin
  620. if shuffle=nil then
  621. begin
  622. if fromsize=tosize then
  623. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  624. else
  625. internalerror(200312202);
  626. end
  627. else
  628. begin
  629. if shufflescalar(shuffle) then
  630. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  631. else
  632. internalerror(200312201);
  633. end;
  634. end;
  635. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  636. begin
  637. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  638. end;
  639. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  640. begin
  641. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  642. end;
  643. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  644. var
  645. l : tlocation;
  646. begin
  647. l.loc:=LOC_REFERENCE;
  648. l.reference:=ref;
  649. l.size:=size;
  650. opmm_loc_reg(list,op,size,l,reg,shuffle);
  651. end;
  652. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  653. var
  654. l : tlocation;
  655. begin
  656. l.loc:=LOC_REGISTER;
  657. l.register:=src;
  658. l.size:=size;
  659. opmm_loc_reg(list,op,size,l,dst,shuffle);
  660. end;
  661. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  662. const
  663. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  664. ( { scalar }
  665. ( { OS_F32 }
  666. A_NOP,A_ADDSS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP
  667. ),
  668. { Intel did again a "nice" job: they added packed double operations (*PD) to SSE2 but
  669. no scalar ones (*SD)
  670. }
  671. {$ifdef x86_64}
  672. ( { OS_F64 }
  673. A_NOP,A_ADDSD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP
  674. )
  675. {$else x86_64}
  676. ( { OS_F64 }
  677. A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP
  678. )
  679. {$endif x86_64}
  680. ),
  681. ( { vectorized/packed }
  682. ( { OS_F32 }
  683. A_NOP,A_ADDPS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP
  684. ),
  685. ( { OS_F64 }
  686. A_NOP,A_ADDPD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP
  687. )
  688. )
  689. );
  690. var
  691. resultreg : tregister;
  692. asmop : tasmop;
  693. begin
  694. { this is an internally used procedure so the parameters have
  695. some constrains
  696. }
  697. if loc.size<>size then
  698. internalerror(200312213);
  699. resultreg:=dst;
  700. { deshuffle }
  701. //!!!
  702. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  703. begin
  704. end
  705. else if (shuffle=nil) then
  706. asmop:=opmm2asmop[1,size,op]
  707. else if shufflescalar(shuffle) then
  708. begin
  709. asmop:=opmm2asmop[0,size,op];
  710. { no scalar operation available? }
  711. if asmop=A_NOP then
  712. begin
  713. { do vectorized and shuffle finally }
  714. //!!!
  715. end;
  716. end
  717. else
  718. internalerror(200312211);
  719. if asmop=A_NOP then
  720. internalerror(200312215);
  721. case loc.loc of
  722. LOC_CREFERENCE,LOC_REFERENCE:
  723. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  724. LOC_CMMREGISTER,LOC_MMREGISTER:
  725. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  726. else
  727. internalerror(200312214);
  728. end;
  729. { shuffle }
  730. if resultreg<>dst then
  731. begin
  732. internalerror(200312212);
  733. end;
  734. end;
  735. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister);
  736. var
  737. opcode: tasmop;
  738. power: longint;
  739. begin
  740. check_register_size(size,reg);
  741. case op of
  742. OP_DIV, OP_IDIV:
  743. begin
  744. if ispowerof2(a,power) then
  745. begin
  746. case op of
  747. OP_DIV:
  748. opcode := A_SHR;
  749. OP_IDIV:
  750. opcode := A_SAR;
  751. end;
  752. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  753. exit;
  754. end;
  755. { the rest should be handled specifically in the code }
  756. { generator because of the silly register usage restraints }
  757. internalerror(200109224);
  758. end;
  759. OP_MUL,OP_IMUL:
  760. begin
  761. if not(cs_check_overflow in aktlocalswitches) and
  762. ispowerof2(a,power) then
  763. begin
  764. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  765. exit;
  766. end;
  767. if op = OP_IMUL then
  768. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  769. else
  770. { OP_MUL should be handled specifically in the code }
  771. { generator because of the silly register usage restraints }
  772. internalerror(200109225);
  773. end;
  774. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  775. if not(cs_check_overflow in aktlocalswitches) and
  776. (a = 1) and
  777. (op in [OP_ADD,OP_SUB]) then
  778. if op = OP_ADD then
  779. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  780. else
  781. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  782. else if (a = 0) then
  783. if (op <> OP_AND) then
  784. exit
  785. else
  786. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  787. else if (a = high(aword)) and
  788. (op in [OP_AND,OP_OR,OP_XOR]) then
  789. begin
  790. case op of
  791. OP_AND:
  792. exit;
  793. OP_OR:
  794. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],high(aword),reg));
  795. OP_XOR:
  796. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  797. end
  798. end
  799. else
  800. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  801. OP_SHL,OP_SHR,OP_SAR:
  802. begin
  803. if (a and 31) <> 0 Then
  804. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  805. if (a shr 5) <> 0 Then
  806. internalerror(68991);
  807. end
  808. else internalerror(68992);
  809. end;
  810. end;
  811. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  812. var
  813. opcode: tasmop;
  814. power: longint;
  815. begin
  816. Case Op of
  817. OP_DIV, OP_IDIV:
  818. Begin
  819. if ispowerof2(a,power) then
  820. begin
  821. case op of
  822. OP_DIV:
  823. opcode := A_SHR;
  824. OP_IDIV:
  825. opcode := A_SAR;
  826. end;
  827. list.concat(taicpu.op_const_ref(opcode,
  828. TCgSize2OpSize[size],power,ref));
  829. exit;
  830. end;
  831. { the rest should be handled specifically in the code }
  832. { generator because of the silly register usage restraints }
  833. internalerror(200109231);
  834. End;
  835. OP_MUL,OP_IMUL:
  836. begin
  837. if not(cs_check_overflow in aktlocalswitches) and
  838. ispowerof2(a,power) then
  839. begin
  840. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  841. power,ref));
  842. exit;
  843. end;
  844. { can't multiply a memory location directly with a constant }
  845. if op = OP_IMUL then
  846. inherited a_op_const_ref(list,op,size,a,ref)
  847. else
  848. { OP_MUL should be handled specifically in the code }
  849. { generator because of the silly register usage restraints }
  850. internalerror(200109232);
  851. end;
  852. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  853. if not(cs_check_overflow in aktlocalswitches) and
  854. (a = 1) and
  855. (op in [OP_ADD,OP_SUB]) then
  856. if op = OP_ADD then
  857. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  858. else
  859. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  860. else if (a = 0) then
  861. if (op <> OP_AND) then
  862. exit
  863. else
  864. a_load_const_ref(list,size,0,ref)
  865. else if (a = high(aword)) and
  866. (op in [OP_AND,OP_OR,OP_XOR]) then
  867. begin
  868. case op of
  869. OP_AND:
  870. exit;
  871. OP_OR:
  872. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],high(aword),ref));
  873. OP_XOR:
  874. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  875. end
  876. end
  877. else
  878. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  879. TCgSize2OpSize[size],a,ref));
  880. OP_SHL,OP_SHR,OP_SAR:
  881. begin
  882. if (a and 31) <> 0 then
  883. list.concat(taicpu.op_const_ref(
  884. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  885. if (a shr 5) <> 0 Then
  886. internalerror(68991);
  887. end
  888. else internalerror(68992);
  889. end;
  890. end;
  891. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  892. var
  893. dstsize: topsize;
  894. instr:Taicpu;
  895. begin
  896. check_register_size(size,src);
  897. check_register_size(size,dst);
  898. dstsize := tcgsize2opsize[size];
  899. case op of
  900. OP_NEG,OP_NOT:
  901. begin
  902. if src<>dst then
  903. a_load_reg_reg(list,size,size,src,dst);
  904. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  905. end;
  906. OP_MUL,OP_DIV,OP_IDIV:
  907. { special stuff, needs separate handling inside code }
  908. { generator }
  909. internalerror(200109233);
  910. OP_SHR,OP_SHL,OP_SAR:
  911. begin
  912. getexplicitregister(list,NR_CL);
  913. a_load_reg_reg(list,size,OS_8,dst,NR_CL);
  914. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],S_B,src,NR_CL));
  915. ungetregister(list,NR_CL);
  916. end;
  917. else
  918. begin
  919. if reg2opsize(src) <> dstsize then
  920. internalerror(200109226);
  921. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  922. list.concat(instr);
  923. end;
  924. end;
  925. end;
  926. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  927. begin
  928. check_register_size(size,reg);
  929. case op of
  930. OP_NEG,OP_NOT,OP_IMUL:
  931. begin
  932. inherited a_op_ref_reg(list,op,size,ref,reg);
  933. end;
  934. OP_MUL,OP_DIV,OP_IDIV:
  935. { special stuff, needs separate handling inside code }
  936. { generator }
  937. internalerror(200109239);
  938. else
  939. begin
  940. reg := makeregsize(reg,size);
  941. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  942. end;
  943. end;
  944. end;
  945. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  946. begin
  947. check_register_size(size,reg);
  948. case op of
  949. OP_NEG,OP_NOT:
  950. begin
  951. if reg<>NR_NO then
  952. internalerror(200109237);
  953. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  954. end;
  955. OP_IMUL:
  956. begin
  957. { this one needs a load/imul/store, which is the default }
  958. inherited a_op_ref_reg(list,op,size,ref,reg);
  959. end;
  960. OP_MUL,OP_DIV,OP_IDIV:
  961. { special stuff, needs separate handling inside code }
  962. { generator }
  963. internalerror(200109238);
  964. else
  965. begin
  966. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,ref));
  967. end;
  968. end;
  969. end;
  970. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aword; src, dst: tregister);
  971. var
  972. tmpref: treference;
  973. power: longint;
  974. begin
  975. check_register_size(size,src);
  976. check_register_size(size,dst);
  977. if not (size in [OS_32,OS_S32]) then
  978. begin
  979. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  980. exit;
  981. end;
  982. { if we get here, we have to do a 32 bit calculation, guaranteed }
  983. case op of
  984. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  985. OP_SAR:
  986. { can't do anything special for these }
  987. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  988. OP_IMUL:
  989. begin
  990. if not(cs_check_overflow in aktlocalswitches) and
  991. ispowerof2(a,power) then
  992. { can be done with a shift }
  993. begin
  994. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  995. exit;
  996. end;
  997. list.concat(taicpu.op_const_reg_reg(A_IMUL,S_L,a,src,dst));
  998. end;
  999. OP_ADD, OP_SUB:
  1000. if (a = 0) then
  1001. a_load_reg_reg(list,size,size,src,dst)
  1002. else
  1003. begin
  1004. reference_reset(tmpref);
  1005. tmpref.base := src;
  1006. tmpref.offset := longint(a);
  1007. if op = OP_SUB then
  1008. tmpref.offset := -tmpref.offset;
  1009. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  1010. end
  1011. else internalerror(200112302);
  1012. end;
  1013. end;
  1014. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;size: tcgsize; src1, src2, dst: tregister);
  1015. var
  1016. tmpref: treference;
  1017. begin
  1018. check_register_size(size,src1);
  1019. check_register_size(size,src2);
  1020. check_register_size(size,dst);
  1021. if not(size in [OS_32,OS_S32]) then
  1022. begin
  1023. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  1024. exit;
  1025. end;
  1026. { if we get here, we have to do a 32 bit calculation, guaranteed }
  1027. Case Op of
  1028. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  1029. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  1030. { can't do anything special for these }
  1031. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  1032. OP_IMUL:
  1033. list.concat(taicpu.op_reg_reg_reg(A_IMUL,S_L,src1,src2,dst));
  1034. OP_ADD:
  1035. begin
  1036. reference_reset(tmpref);
  1037. tmpref.base := src1;
  1038. tmpref.index := src2;
  1039. tmpref.scalefactor := 1;
  1040. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  1041. end
  1042. else internalerror(200112303);
  1043. end;
  1044. end;
  1045. {*************** compare instructructions ****************}
  1046. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  1047. l : tasmlabel);
  1048. begin
  1049. if (a = 0) then
  1050. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1051. else
  1052. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1053. a_jmp_cond(list,cmp_op,l);
  1054. end;
  1055. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  1056. l : tasmlabel);
  1057. begin
  1058. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  1059. a_jmp_cond(list,cmp_op,l);
  1060. end;
  1061. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  1062. reg1,reg2 : tregister;l : tasmlabel);
  1063. begin
  1064. check_register_size(size,reg1);
  1065. check_register_size(size,reg2);
  1066. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1067. a_jmp_cond(list,cmp_op,l);
  1068. end;
  1069. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1070. begin
  1071. check_register_size(size,reg);
  1072. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],ref,reg));
  1073. a_jmp_cond(list,cmp_op,l);
  1074. end;
  1075. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1076. var
  1077. ai : taicpu;
  1078. begin
  1079. if cond=OC_None then
  1080. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1081. else
  1082. begin
  1083. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1084. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1085. end;
  1086. ai.is_jmp:=true;
  1087. list.concat(ai);
  1088. end;
  1089. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  1090. var
  1091. ai : taicpu;
  1092. begin
  1093. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1094. ai.SetCondition(flags_to_cond(f));
  1095. ai.is_jmp := true;
  1096. list.concat(ai);
  1097. end;
  1098. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  1099. var
  1100. ai : taicpu;
  1101. hreg : tregister;
  1102. begin
  1103. hreg:=makeregsize(reg,OS_8);
  1104. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1105. ai.setcondition(flags_to_cond(f));
  1106. list.concat(ai);
  1107. if (reg<>hreg) then
  1108. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1109. end;
  1110. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  1111. var
  1112. ai : taicpu;
  1113. begin
  1114. if not(size in [OS_8,OS_S8]) then
  1115. a_load_const_ref(list,size,0,ref);
  1116. ai:=Taicpu.op_ref(A_SETcc,S_B,ref);
  1117. ai.setcondition(flags_to_cond(f));
  1118. list.concat(ai);
  1119. end;
  1120. { ************* concatcopy ************ }
  1121. procedure Tcgx86.g_concatcopy(list:Taasmoutput;const source,dest:Treference;
  1122. len:aword;delsource,loadref:boolean);
  1123. type copymode=(copy_move,copy_mmx,copy_string);
  1124. var srcref,dstref:Treference;
  1125. r,r0,r1,r2,r3:Tregister;
  1126. helpsize:aword;
  1127. copysize:byte;
  1128. cgsize:Tcgsize;
  1129. cm:copymode;
  1130. begin
  1131. cm:=copy_move;
  1132. helpsize:=12;
  1133. if cs_littlesize in aktglobalswitches then
  1134. helpsize:=8;
  1135. if (cs_mmx in aktlocalswitches) and
  1136. not(pi_uses_fpu in current_procinfo.flags) and
  1137. ((len=8) or (len=16) or (len=24) or (len=32)) then
  1138. cm:=copy_mmx;
  1139. if (cs_littlesize in aktglobalswitches) and
  1140. (len>helpsize) and
  1141. not((len<=16) and (cm=copy_mmx)) then
  1142. cm:=copy_string;
  1143. if loadref then
  1144. cm:=copy_string;
  1145. case cm of
  1146. copy_move:
  1147. begin
  1148. dstref:=dest;
  1149. srcref:=source;
  1150. copysize:=4;
  1151. cgsize:=OS_32;
  1152. while len<>0 do
  1153. begin
  1154. if len<2 then
  1155. begin
  1156. copysize:=1;
  1157. cgsize:=OS_8;
  1158. end
  1159. else if len<4 then
  1160. begin
  1161. copysize:=2;
  1162. cgsize:=OS_16;
  1163. end;
  1164. dec(len,copysize);
  1165. if (len=0) and delsource then
  1166. reference_release(list,source);
  1167. r:=getintregister(list,cgsize);
  1168. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1169. ungetregister(list,r);
  1170. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1171. inc(srcref.offset,copysize);
  1172. inc(dstref.offset,copysize);
  1173. end;
  1174. end;
  1175. copy_mmx:
  1176. begin
  1177. dstref:=dest;
  1178. srcref:=source;
  1179. r0:=getmmxregister(list);
  1180. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r0,nil);
  1181. if len>=16 then
  1182. begin
  1183. inc(srcref.offset,8);
  1184. r1:=getmmxregister(list);
  1185. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r1,nil);
  1186. end;
  1187. if len>=24 then
  1188. begin
  1189. inc(srcref.offset,8);
  1190. r2:=getmmxregister(list);
  1191. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r2,nil);
  1192. end;
  1193. if len>=32 then
  1194. begin
  1195. inc(srcref.offset,8);
  1196. r3:=getmmxregister(list);
  1197. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r3,nil);
  1198. end;
  1199. a_loadmm_reg_ref(list,OS_M64,OS_M64,r0,dstref,nil);
  1200. ungetregister(list,r0);
  1201. if len>=16 then
  1202. begin
  1203. inc(dstref.offset,8);
  1204. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1205. ungetregister(list,r1);
  1206. end;
  1207. if len>=24 then
  1208. begin
  1209. inc(dstref.offset,8);
  1210. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  1211. ungetregister(list,r2);
  1212. end;
  1213. if len>=32 then
  1214. begin
  1215. inc(dstref.offset,8);
  1216. a_loadmm_reg_ref(list,OS_M64,OS_M64,r3,dstref,nil);
  1217. ungetregister(list,r3);
  1218. end;
  1219. end
  1220. else {copy_string, should be a good fallback in case of unhandled}
  1221. begin
  1222. getexplicitregister(list,NR_EDI);
  1223. a_loadaddr_ref_reg(list,dest,NR_EDI);
  1224. getexplicitregister(list,NR_ESI);
  1225. if loadref then
  1226. a_load_ref_reg(list,OS_ADDR,OS_ADDR,source,NR_ESI)
  1227. else
  1228. begin
  1229. a_loadaddr_ref_reg(list,source,NR_ESI);
  1230. if delsource then
  1231. begin
  1232. srcref:=source;
  1233. { Don't release ESI register yet, it's needed
  1234. by the movsl }
  1235. if (srcref.base=NR_ESI) then
  1236. srcref.base:=NR_NO
  1237. else if (srcref.index=NR_ESI) then
  1238. srcref.index:=NR_NO;
  1239. reference_release(list,srcref);
  1240. end;
  1241. end;
  1242. getexplicitregister(list,NR_ECX);
  1243. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1244. if cs_littlesize in aktglobalswitches then
  1245. begin
  1246. a_load_const_reg(list,OS_INT,len,NR_ECX);
  1247. list.concat(Taicpu.op_none(A_REP,S_NO));
  1248. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1249. end
  1250. else
  1251. begin
  1252. helpsize:=len shr 2;
  1253. len:=len and 3;
  1254. if helpsize>1 then
  1255. begin
  1256. a_load_const_reg(list,OS_INT,helpsize,NR_ECX);
  1257. list.concat(Taicpu.op_none(A_REP,S_NO));
  1258. end;
  1259. if helpsize>0 then
  1260. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1261. if len>1 then
  1262. begin
  1263. dec(len,2);
  1264. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1265. end;
  1266. if len=1 then
  1267. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1268. end;
  1269. ungetregister(list,NR_ECX);
  1270. ungetregister(list,NR_ESI);
  1271. ungetregister(list,NR_EDI);
  1272. end;
  1273. end;
  1274. if delsource then
  1275. tg.ungetiftemp(list,source);
  1276. end;
  1277. procedure tcgx86.g_exception_reason_save(list : taasmoutput; const href : treference);
  1278. begin
  1279. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1280. end;
  1281. procedure tcgx86.g_exception_reason_save_const(list : taasmoutput;const href : treference; a: aword);
  1282. begin
  1283. list.concat(Taicpu.op_const(A_PUSH,S_L,a));
  1284. end;
  1285. procedure tcgx86.g_exception_reason_load(list : taasmoutput; const href : treference);
  1286. begin
  1287. list.concat(Taicpu.op_reg(A_POP,S_L,NR_EAX));
  1288. end;
  1289. {****************************************************************************
  1290. Entry/Exit Code Helpers
  1291. ****************************************************************************}
  1292. procedure tcgx86.g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);
  1293. var
  1294. power,len : longint;
  1295. opsize : topsize;
  1296. {$ifndef __NOWINPECOFF__}
  1297. again,ok : tasmlabel;
  1298. {$endif}
  1299. begin
  1300. { get stack space }
  1301. getexplicitregister(list,NR_EDI);
  1302. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,NR_EDI));
  1303. list.concat(Taicpu.op_reg(A_INC,S_L,NR_EDI));
  1304. if (elesize<>1) then
  1305. begin
  1306. if ispowerof2(elesize, power) then
  1307. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_EDI))
  1308. else
  1309. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,NR_EDI));
  1310. end;
  1311. {$ifndef __NOWINPECOFF__}
  1312. { windows guards only a few pages for stack growing, }
  1313. { so we have to access every page first }
  1314. if target_info.system=system_i386_win32 then
  1315. begin
  1316. objectlibrary.getlabel(again);
  1317. objectlibrary.getlabel(ok);
  1318. a_label(list,again);
  1319. list.concat(Taicpu.op_const_reg(A_CMP,S_L,winstackpagesize,NR_EDI));
  1320. a_jmp_cond(list,OC_B,ok);
  1321. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1322. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EDI));
  1323. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize,NR_EDI));
  1324. a_jmp_always(list,again);
  1325. a_label(list,ok);
  1326. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,NR_EDI,NR_ESP));
  1327. ungetregister(list,NR_EDI);
  1328. { now reload EDI }
  1329. getexplicitregister(list,NR_EDI);
  1330. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,NR_EDI));
  1331. list.concat(Taicpu.op_reg(A_INC,S_L,NR_EDI));
  1332. if (elesize<>1) then
  1333. begin
  1334. if ispowerof2(elesize, power) then
  1335. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_EDI))
  1336. else
  1337. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,NR_EDI));
  1338. end;
  1339. end
  1340. else
  1341. {$endif __NOWINPECOFF__}
  1342. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,NR_EDI,NR_ESP));
  1343. { align stack on 4 bytes }
  1344. list.concat(Taicpu.op_const_reg(A_AND,S_L,$fffffff4,NR_ESP));
  1345. { load destination }
  1346. a_load_reg_reg(list,OS_INT,OS_INT,NR_ESP,NR_EDI);
  1347. { Allocate other registers }
  1348. getexplicitregister(list,NR_ECX);
  1349. getexplicitregister(list,NR_ESI);
  1350. { load count }
  1351. a_load_ref_reg(list,OS_INT,OS_INT,lenref,NR_ECX);
  1352. { load source }
  1353. a_load_ref_reg(list,OS_INT,OS_INT,ref,NR_ESI);
  1354. { scheduled .... }
  1355. list.concat(Taicpu.op_reg(A_INC,S_L,NR_ECX));
  1356. { calculate size }
  1357. len:=elesize;
  1358. opsize:=S_B;
  1359. if (len and 3)=0 then
  1360. begin
  1361. opsize:=S_L;
  1362. len:=len shr 2;
  1363. end
  1364. else
  1365. if (len and 1)=0 then
  1366. begin
  1367. opsize:=S_W;
  1368. len:=len shr 1;
  1369. end;
  1370. if ispowerof2(len, power) then
  1371. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_ECX))
  1372. else
  1373. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,NR_ECX));
  1374. list.concat(Taicpu.op_none(A_REP,S_NO));
  1375. case opsize of
  1376. S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1377. S_W : list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1378. S_L : list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1379. end;
  1380. ungetregister(list,NR_EDI);
  1381. ungetregister(list,NR_ECX);
  1382. ungetregister(list,NR_ESI);
  1383. { patch the new address }
  1384. a_load_reg_ref(list,OS_INT,OS_INT,NR_ESP,ref);
  1385. end;
  1386. procedure tcgx86.g_interrupt_stackframe_entry(list : taasmoutput);
  1387. begin
  1388. { .... also the segment registers }
  1389. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1390. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1391. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1392. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1393. { save the registers of an interrupt procedure }
  1394. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1395. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1396. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1397. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1398. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1399. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1400. end;
  1401. procedure tcgx86.g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);
  1402. begin
  1403. if accused then
  1404. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1405. else
  1406. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EAX));
  1407. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EBX));
  1408. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ECX));
  1409. if acchiused then
  1410. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1411. else
  1412. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1413. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ESI));
  1414. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDI));
  1415. { .... also the segment registers }
  1416. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_DS));
  1417. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_ES));
  1418. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_FS));
  1419. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_GS));
  1420. { this restores the flags }
  1421. list.concat(Taicpu.Op_none(A_IRET,S_NO));
  1422. end;
  1423. procedure tcgx86.g_profilecode(list : taasmoutput);
  1424. var
  1425. pl : tasmlabel;
  1426. mcountprefix : String[4];
  1427. begin
  1428. case target_info.system of
  1429. {$ifndef NOTARGETWIN32}
  1430. system_i386_win32,
  1431. {$endif}
  1432. system_i386_freebsd,
  1433. system_i386_netbsd,
  1434. // system_i386_openbsd,
  1435. system_i386_wdosx,
  1436. system_i386_linux:
  1437. begin
  1438. Case target_info.system Of
  1439. system_i386_freebsd : mcountprefix:='.';
  1440. system_i386_netbsd : mcountprefix:='__';
  1441. // system_i386_openbsd : mcountprefix:='.';
  1442. else
  1443. mcountPrefix:='';
  1444. end;
  1445. objectlibrary.getaddrlabel(pl);
  1446. list.concat(Tai_section.Create(sec_data));
  1447. list.concat(Tai_align.Create(4));
  1448. list.concat(Tai_label.Create(pl));
  1449. list.concat(Tai_const.Create_32bit(0));
  1450. list.concat(Tai_section.Create(sec_code));
  1451. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1452. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1453. include(rg[R_INTREGISTER].used_in_proc,RS_EDX);
  1454. end;
  1455. system_i386_go32v2,system_i386_watcom:
  1456. begin
  1457. a_call_name(list,'MCOUNT');
  1458. end;
  1459. end;
  1460. end;
  1461. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1462. var
  1463. href : treference;
  1464. i : integer;
  1465. again : tasmlabel;
  1466. begin
  1467. if localsize>0 then
  1468. begin
  1469. {$ifndef NOTARGETWIN32}
  1470. { windows guards only a few pages for stack growing, }
  1471. { so we have to access every page first }
  1472. if (target_info.system=system_i386_win32) and
  1473. (localsize>=winstackpagesize) then
  1474. begin
  1475. if localsize div winstackpagesize<=5 then
  1476. begin
  1477. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1478. for i:=1 to localsize div winstackpagesize do
  1479. begin
  1480. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1481. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1482. end;
  1483. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1484. end
  1485. else
  1486. begin
  1487. objectlibrary.getlabel(again);
  1488. getexplicitregister(list,NR_EDI);
  1489. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1490. a_label(list,again);
  1491. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1492. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1493. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1494. a_jmp_cond(list,OC_NE,again);
  1495. ungetregister(list,NR_EDI);
  1496. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1497. end
  1498. end
  1499. else
  1500. {$endif NOTARGETWIN32}
  1501. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize,NR_ESP));
  1502. end;
  1503. end;
  1504. procedure tcgx86.g_stackframe_entry(list : taasmoutput;localsize : longint);
  1505. begin
  1506. list.concat(tai_regalloc.alloc(NR_EBP));
  1507. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBP);
  1508. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EBP));
  1509. list.concat(Taicpu.op_reg_reg(A_MOV,S_L,NR_ESP,NR_EBP));
  1510. if localsize>0 then
  1511. g_stackpointer_alloc(list,localsize);
  1512. if cs_create_pic in aktmoduleswitches then
  1513. begin
  1514. a_call_name(list,'FPC_GETEIPINEBX');
  1515. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,objectlibrary.newasmsymboldata('_GLOBAL_OFFSET_TABLE_'),0,NR_EBX));
  1516. list.concat(tai_regalloc.alloc(NR_EBX));
  1517. end;
  1518. end;
  1519. procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
  1520. begin
  1521. if cs_create_pic in aktmoduleswitches then
  1522. list.concat(tai_regalloc.dealloc(NR_EBX));
  1523. list.concat(tai_regalloc.dealloc(NR_EBP));
  1524. list.concat(Taicpu.op_none(A_LEAVE,S_NO));
  1525. if assigned(rg[R_MMXREGISTER]) and (rg[R_MMXREGISTER].uses_registers) then
  1526. list.concat(Taicpu.op_none(A_EMMS,S_NO));
  1527. end;
  1528. procedure tcgx86.g_return_from_proc(list : taasmoutput;parasize : aword);
  1529. begin
  1530. { Routines with the poclearstack flag set use only a ret }
  1531. { also routines with parasize=0 }
  1532. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1533. begin
  1534. { complex return values are removed from stack in C code PM }
  1535. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,
  1536. current_procinfo.procdef.proccalloption) then
  1537. list.concat(Taicpu.Op_const(A_RET,S_NO,4))
  1538. else
  1539. list.concat(Taicpu.Op_none(A_RET,S_NO));
  1540. end
  1541. else if (parasize=0) then
  1542. list.concat(Taicpu.Op_none(A_RET,S_NO))
  1543. else
  1544. begin
  1545. { parameters are limited to 65535 bytes because }
  1546. { ret allows only imm16 }
  1547. if (parasize>65535) then
  1548. CGMessage(cg_e_parasize_too_big);
  1549. list.concat(Taicpu.Op_const(A_RET,S_NO,parasize));
  1550. end;
  1551. end;
  1552. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1553. var
  1554. href : treference;
  1555. size : longint;
  1556. begin
  1557. { Get temp }
  1558. size:=0;
  1559. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1560. inc(size,POINTER_SIZE);
  1561. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1562. inc(size,POINTER_SIZE);
  1563. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1564. inc(size,POINTER_SIZE);
  1565. if size>0 then
  1566. begin
  1567. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1568. { Copy registers to temp }
  1569. href:=current_procinfo.save_regs_ref;
  1570. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1571. begin
  1572. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EBX,href);
  1573. inc(href.offset,POINTER_SIZE);
  1574. end;
  1575. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1576. begin
  1577. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESI,href);
  1578. inc(href.offset,POINTER_SIZE);
  1579. end;
  1580. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1581. begin
  1582. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EDI,href);
  1583. inc(href.offset,POINTER_SIZE);
  1584. end;
  1585. end;
  1586. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBX);
  1587. include(rg[R_INTREGISTER].preserved_by_proc,RS_ESI);
  1588. include(rg[R_INTREGISTER].preserved_by_proc,RS_EDI);
  1589. end;
  1590. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1591. var
  1592. href : treference;
  1593. begin
  1594. { Copy registers from temp }
  1595. href:=current_procinfo.save_regs_ref;
  1596. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1597. begin
  1598. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EBX);
  1599. inc(href.offset,POINTER_SIZE);
  1600. end;
  1601. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1602. begin
  1603. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_ESI);
  1604. inc(href.offset,POINTER_SIZE);
  1605. end;
  1606. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1607. begin
  1608. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EDI);
  1609. inc(href.offset,POINTER_SIZE);
  1610. end;
  1611. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1612. end;
  1613. procedure tcgx86.g_save_all_registers(list : taasmoutput);
  1614. begin
  1615. list.concat(Taicpu.Op_none(A_PUSHA,S_L));
  1616. tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
  1617. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESP,current_procinfo.save_regs_ref);
  1618. end;
  1619. procedure tcgx86.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  1620. var
  1621. href : treference;
  1622. begin
  1623. a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_ESP);
  1624. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1625. if acchiused then
  1626. begin
  1627. reference_reset_base(href,NR_ESP,20);
  1628. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EDX,href));
  1629. end;
  1630. if accused then
  1631. begin
  1632. reference_reset_base(href,NR_ESP,28);
  1633. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1634. end;
  1635. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1636. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1637. list.concat(taicpu.op_none(A_NOP,S_L));
  1638. end;
  1639. { produces if necessary overflowcode }
  1640. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1641. var
  1642. hl : tasmlabel;
  1643. ai : taicpu;
  1644. cond : TAsmCond;
  1645. begin
  1646. if not(cs_check_overflow in aktlocalswitches) then
  1647. exit;
  1648. objectlibrary.getlabel(hl);
  1649. if not ((def.deftype=pointerdef) or
  1650. ((def.deftype=orddef) and
  1651. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1652. bool8bit,bool16bit,bool32bit]))) then
  1653. cond:=C_NO
  1654. else
  1655. cond:=C_NB;
  1656. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1657. ai.SetCondition(cond);
  1658. ai.is_jmp:=true;
  1659. list.concat(ai);
  1660. a_call_name(list,'FPC_OVERFLOW');
  1661. a_label(list,hl);
  1662. end;
  1663. end.
  1664. {
  1665. $Log$
  1666. Revision 1.93 2003-12-21 19:42:43 florian
  1667. * fixed ppc inlining stuff
  1668. * fixed wrong unit writing
  1669. + added some sse stuff
  1670. Revision 1.92 2003/12/19 22:08:44 daniel
  1671. * Some work to restore the MMX capabilities
  1672. Revision 1.91 2003/12/15 21:25:49 peter
  1673. * reg allocations for imaginary register are now inserted just
  1674. before reg allocation
  1675. * tregister changed to enum to allow compile time check
  1676. * fixed several tregister-tsuperregister errors
  1677. Revision 1.90 2003/12/12 17:16:18 peter
  1678. * rg[tregistertype] added in tcg
  1679. Revision 1.89 2003/12/06 01:15:23 florian
  1680. * reverted Peter's alloctemp patch; hopefully properly
  1681. Revision 1.88 2003/12/03 23:13:20 peter
  1682. * delayed paraloc allocation, a_param_*() gets extra parameter
  1683. if it needs to allocate temp or real paralocation
  1684. * optimized/simplified int-real loading
  1685. Revision 1.87 2003/11/05 23:06:03 florian
  1686. * elesize of g_copyvaluepara_openarray changed
  1687. Revision 1.86 2003/10/30 18:53:53 marco
  1688. * profiling fix
  1689. Revision 1.85 2003/10/30 16:22:40 peter
  1690. * call firstpass before allocation and codegeneration is started
  1691. * move leftover code from pass_2.generatecode() to psub
  1692. Revision 1.84 2003/10/29 21:24:14 jonas
  1693. + support for fpu temp parameters
  1694. + saving/restoring of fpu register before/after a procedure call
  1695. Revision 1.83 2003/10/20 19:30:08 peter
  1696. * remove memdebug code for rg
  1697. Revision 1.82 2003/10/18 15:41:26 peter
  1698. * made worklists dynamic in size
  1699. Revision 1.81 2003/10/17 15:25:18 florian
  1700. * fixed more ppc stuff
  1701. Revision 1.80 2003/10/17 14:38:32 peter
  1702. * 64k registers supported
  1703. * fixed some memory leaks
  1704. Revision 1.79 2003/10/14 00:30:48 florian
  1705. + some code for PIC support added
  1706. Revision 1.78 2003/10/13 01:23:13 florian
  1707. * some ideas for mm support implemented
  1708. Revision 1.77 2003/10/11 16:06:42 florian
  1709. * fixed some MMX<->SSE
  1710. * started to fix ppc, needs an overhaul
  1711. + stabs info improve for spilling, not sure if it works correctly/completly
  1712. - MMX_SUPPORT removed from Makefile.fpc
  1713. Revision 1.76 2003/10/10 17:48:14 peter
  1714. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1715. * tregisteralloctor renamed to trgobj
  1716. * removed rgobj from a lot of units
  1717. * moved location_* and reference_* to cgobj
  1718. * first things for mmx register allocation
  1719. Revision 1.75 2003/10/09 21:31:37 daniel
  1720. * Register allocator splitted, ans abstract now
  1721. Revision 1.74 2003/10/07 16:09:03 florian
  1722. * x86 supports only mem/reg to reg for movsx and movzx
  1723. Revision 1.73 2003/10/07 15:17:07 peter
  1724. * inline supported again, LOC_REFERENCEs are used to pass the
  1725. parameters
  1726. * inlineparasymtable,inlinelocalsymtable removed
  1727. * exitlabel inserting fixed
  1728. Revision 1.72 2003/10/03 22:00:33 peter
  1729. * parameter alignment fixes
  1730. Revision 1.71 2003/10/03 14:45:37 peter
  1731. * save ESP after pusha and restore before popa for save all registers
  1732. Revision 1.70 2003/10/01 20:34:51 peter
  1733. * procinfo unit contains tprocinfo
  1734. * cginfo renamed to cgbase
  1735. * moved cgmessage to verbose
  1736. * fixed ppc and sparc compiles
  1737. Revision 1.69 2003/09/30 19:53:47 peter
  1738. * fix pushw reg
  1739. Revision 1.68 2003/09/29 20:58:56 peter
  1740. * optimized releasing of registers
  1741. Revision 1.67 2003/09/28 13:37:19 peter
  1742. * a_call_ref removed
  1743. Revision 1.66 2003/09/25 21:29:16 peter
  1744. * change push/pop in getreg/ungetreg
  1745. Revision 1.65 2003/09/25 13:13:32 florian
  1746. * more x86-64 fixes
  1747. Revision 1.64 2003/09/11 11:55:00 florian
  1748. * improved arm code generation
  1749. * move some protected and private field around
  1750. * the temp. register for register parameters/arguments are now released
  1751. before the move to the parameter register is done. This improves
  1752. the code in a lot of cases.
  1753. Revision 1.63 2003/09/09 21:03:17 peter
  1754. * basics for x86 register calling
  1755. Revision 1.62 2003/09/09 20:59:27 daniel
  1756. * Adding register allocation order
  1757. Revision 1.61 2003/09/07 22:09:35 peter
  1758. * preparations for different default calling conventions
  1759. * various RA fixes
  1760. Revision 1.60 2003/09/05 17:41:13 florian
  1761. * merged Wiktor's Watcom patches in 1.1
  1762. Revision 1.59 2003/09/03 15:55:02 peter
  1763. * NEWRA branch merged
  1764. Revision 1.58.2.5 2003/08/31 20:40:50 daniel
  1765. * Fixed add_edges_used
  1766. Revision 1.58.2.4 2003/08/31 15:46:26 peter
  1767. * more updates for tregister
  1768. Revision 1.58.2.3 2003/08/29 17:29:00 peter
  1769. * next batch of updates
  1770. Revision 1.58.2.2 2003/08/28 18:35:08 peter
  1771. * tregister changed to cardinal
  1772. Revision 1.58.2.1 2003/08/27 21:06:34 peter
  1773. * more updates
  1774. Revision 1.58 2003/08/20 19:28:21 daniel
  1775. * Small NOTARGETWIN32 conditional tweak
  1776. Revision 1.57 2003/07/03 18:59:25 peter
  1777. * loadfpu_reg_reg size specifier
  1778. Revision 1.56 2003/06/14 14:53:50 jonas
  1779. * fixed newra cycle for x86
  1780. * added constants for indicating source and destination operands of the
  1781. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1782. Revision 1.55 2003/06/13 21:19:32 peter
  1783. * current_procdef removed, use current_procinfo.procdef instead
  1784. Revision 1.54 2003/06/12 18:31:18 peter
  1785. * fix newra cycle for i386
  1786. Revision 1.53 2003/06/07 10:24:10 peter
  1787. * fixed copyvaluepara for left-to-right pushing
  1788. Revision 1.52 2003/06/07 10:06:55 jonas
  1789. * fixed cycling problem
  1790. Revision 1.51 2003/06/03 21:11:09 peter
  1791. * cg.a_load_* get a from and to size specifier
  1792. * makeregsize only accepts newregister
  1793. * i386 uses generic tcgnotnode,tcgunaryminus
  1794. Revision 1.50 2003/06/03 13:01:59 daniel
  1795. * Register allocator finished
  1796. Revision 1.49 2003/06/01 21:38:07 peter
  1797. * getregisterfpu size parameter added
  1798. * op_const_reg size parameter added
  1799. * sparc updates
  1800. Revision 1.48 2003/05/30 23:57:08 peter
  1801. * more sparc cleanup
  1802. * accumulator removed, splitted in function_return_reg (called) and
  1803. function_result_reg (caller)
  1804. Revision 1.47 2003/05/22 21:33:31 peter
  1805. * removed some unit dependencies
  1806. Revision 1.46 2003/05/16 14:33:31 peter
  1807. * regvar fixes
  1808. Revision 1.45 2003/05/15 18:58:54 peter
  1809. * removed selfpointer_offset, vmtpointer_offset
  1810. * tvarsym.adjusted_address
  1811. * address in localsymtable is now in the real direction
  1812. * removed some obsolete globals
  1813. Revision 1.44 2003/04/30 20:53:32 florian
  1814. * error when address of an abstract method is taken
  1815. * fixed some x86-64 problems
  1816. * merged some more x86-64 and i386 code
  1817. Revision 1.43 2003/04/27 11:21:36 peter
  1818. * aktprocdef renamed to current_procinfo.procdef
  1819. * procinfo renamed to current_procinfo
  1820. * procinfo will now be stored in current_module so it can be
  1821. cleaned up properly
  1822. * gen_main_procsym changed to create_main_proc and release_main_proc
  1823. to also generate a tprocinfo structure
  1824. * fixed unit implicit initfinal
  1825. Revision 1.42 2003/04/23 14:42:08 daniel
  1826. * Further register allocator work. Compiler now smaller with new
  1827. allocator than without.
  1828. * Somebody forgot to adjust ppu version number
  1829. Revision 1.41 2003/04/23 09:51:16 daniel
  1830. * Removed usage of edi in a lot of places when new register allocator used
  1831. + Added newra versions of g_concatcopy and secondadd_float
  1832. Revision 1.40 2003/04/22 13:47:08 peter
  1833. * fixed C style array of const
  1834. * fixed C array passing
  1835. * fixed left to right with high parameters
  1836. Revision 1.39 2003/04/22 10:09:35 daniel
  1837. + Implemented the actual register allocator
  1838. + Scratch registers unavailable when new register allocator used
  1839. + maybe_save/maybe_restore unavailable when new register allocator used
  1840. Revision 1.38 2003/04/17 16:48:21 daniel
  1841. * Added some code to keep track of move instructions in register
  1842. allocator
  1843. Revision 1.37 2003/03/28 19:16:57 peter
  1844. * generic constructor working for i386
  1845. * remove fixed self register
  1846. * esi added as address register for i386
  1847. Revision 1.36 2003/03/18 18:17:46 peter
  1848. * reg2opsize()
  1849. Revision 1.35 2003/03/13 19:52:23 jonas
  1850. * and more new register allocator fixes (in the i386 code generator this
  1851. time). At least now the ppc cross compiler can compile the linux
  1852. system unit again, but I haven't tested it.
  1853. Revision 1.34 2003/02/27 16:40:32 daniel
  1854. * Fixed ie 200301234 problem on Win32 target
  1855. Revision 1.33 2003/02/26 21:15:43 daniel
  1856. * Fixed the optimizer
  1857. Revision 1.32 2003/02/19 22:00:17 daniel
  1858. * Code generator converted to new register notation
  1859. - Horribily outdated todo.txt removed
  1860. Revision 1.31 2003/01/21 10:41:13 daniel
  1861. * Fixed another 200301081
  1862. Revision 1.30 2003/01/13 23:00:18 daniel
  1863. * Fixed internalerror
  1864. Revision 1.29 2003/01/13 14:54:34 daniel
  1865. * Further work to convert codegenerator register convention;
  1866. internalerror bug fixed.
  1867. Revision 1.28 2003/01/09 20:41:00 daniel
  1868. * Converted some code in cgx86.pas to new register numbering
  1869. Revision 1.27 2003/01/08 18:43:58 daniel
  1870. * Tregister changed into a record
  1871. Revision 1.26 2003/01/05 13:36:53 florian
  1872. * x86-64 compiles
  1873. + very basic support for float128 type (x86-64 only)
  1874. Revision 1.25 2003/01/02 16:17:50 peter
  1875. * align stack on 4 bytes in copyvalueopenarray
  1876. Revision 1.24 2002/12/24 15:56:50 peter
  1877. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1878. this for the pageprotection
  1879. Revision 1.23 2002/11/25 18:43:34 carl
  1880. - removed the invalid if <> checking (Delphi is strange on this)
  1881. + implemented abstract warning on instance creation of class with
  1882. abstract methods.
  1883. * some error message cleanups
  1884. Revision 1.22 2002/11/25 17:43:29 peter
  1885. * splitted defbase in defutil,symutil,defcmp
  1886. * merged isconvertable and is_equal into compare_defs(_ext)
  1887. * made operator search faster by walking the list only once
  1888. Revision 1.21 2002/11/18 17:32:01 peter
  1889. * pass proccalloption to ret_in_xxx and push_xxx functions
  1890. Revision 1.20 2002/11/09 21:18:31 carl
  1891. * flags2reg() was not extending the byte register to the correct result size
  1892. Revision 1.19 2002/10/16 19:01:43 peter
  1893. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1894. implicit exception frames for procedures with initialized variables
  1895. and for constructors. The default is on for compatibility
  1896. Revision 1.18 2002/10/05 12:43:30 carl
  1897. * fixes for Delphi 6 compilation
  1898. (warning : Some features do not work under Delphi)
  1899. Revision 1.17 2002/09/17 18:54:06 jonas
  1900. * a_load_reg_reg() now has two size parameters: source and dest. This
  1901. allows some optimizations on architectures that don't encode the
  1902. register size in the register name.
  1903. Revision 1.16 2002/09/16 19:08:47 peter
  1904. * support references without registers and symbol in paramref_addr. It
  1905. pushes only the offset
  1906. Revision 1.15 2002/09/16 18:06:29 peter
  1907. * move CGSize2Opsize to interface
  1908. Revision 1.14 2002/09/01 14:42:41 peter
  1909. * removevaluepara added to fix the stackpointer so restoring of
  1910. saved registers works
  1911. Revision 1.13 2002/09/01 12:09:27 peter
  1912. + a_call_reg, a_call_loc added
  1913. * removed exprasmlist references
  1914. Revision 1.12 2002/08/17 09:23:50 florian
  1915. * first part of procinfo rewrite
  1916. Revision 1.11 2002/08/16 14:25:00 carl
  1917. * issameref() to test if two references are the same (then emit no opcodes)
  1918. + ret_in_reg to replace ret_in_acc
  1919. (fix some register allocation bugs at the same time)
  1920. + save_std_register now has an extra parameter which is the
  1921. usedinproc registers
  1922. Revision 1.10 2002/08/15 08:13:54 carl
  1923. - a_load_sym_ofs_reg removed
  1924. * loadvmt now calls loadaddr_ref_reg instead
  1925. Revision 1.9 2002/08/11 14:32:33 peter
  1926. * renamed current_library to objectlibrary
  1927. Revision 1.8 2002/08/11 13:24:20 peter
  1928. * saving of asmsymbols in ppu supported
  1929. * asmsymbollist global is removed and moved into a new class
  1930. tasmlibrarydata that will hold the info of a .a file which
  1931. corresponds with a single module. Added librarydata to tmodule
  1932. to keep the library info stored for the module. In the future the
  1933. objectfiles will also be stored to the tasmlibrarydata class
  1934. * all getlabel/newasmsymbol and friends are moved to the new class
  1935. Revision 1.7 2002/08/10 10:06:04 jonas
  1936. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1937. Revision 1.6 2002/08/09 19:18:27 carl
  1938. * fix generic exception handling
  1939. Revision 1.5 2002/08/04 19:52:04 carl
  1940. + updated exception routines
  1941. Revision 1.4 2002/07/27 19:53:51 jonas
  1942. + generic implementation of tcg.g_flags2ref()
  1943. * tcg.flags2xxx() now also needs a size parameter
  1944. Revision 1.3 2002/07/26 21:15:46 florian
  1945. * rewrote the system handling
  1946. Revision 1.2 2002/07/21 16:55:34 jonas
  1947. * fixed bug in op_const_reg_reg() for imul
  1948. Revision 1.1 2002/07/20 19:28:47 florian
  1949. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1950. cgx86.pas will contain the common code for i386 and x86_64
  1951. }