cgx86.pas 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  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. globtype,
  25. cgbase,cgobj,
  26. aasmbase,aasmtai,aasmcpu,
  27. cpubase,cpuinfo,rgobj,rgx86,rgcpu,
  28. symconst,symtype;
  29. type
  30. tcgx86 = class(tcg)
  31. rgfpu : Trgx86fpu;
  32. procedure done_register_allocators;override;
  33. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;override;
  34. function getmmxregister(list:Taasmoutput):Tregister;
  35. procedure getcpuregister(list:Taasmoutput;r:Tregister);override;
  36. procedure ungetcpuregister(list:Taasmoutput;r:Tregister);override;
  37. procedure alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);override;
  38. procedure dealloccpuregisters(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. procedure a_call_name(list : taasmoutput;const s : string);override;
  44. procedure a_call_reg(list : taasmoutput;reg : tregister);override;
  45. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  46. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference); override;
  47. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  48. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  49. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  50. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  51. size: tcgsize; a: aint; src, dst: tregister); override;
  52. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  53. size: tcgsize; src1, src2, dst: tregister); override;
  54. { move instructions }
  55. procedure a_load_const_reg(list : taasmoutput; tosize: tcgsize; a : aint;reg : tregister);override;
  56. procedure a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aint;const ref : treference);override;
  57. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize: tcgsize; reg : tregister;const ref : treference);override;
  58. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize: tcgsize;const ref : treference;reg : tregister);override;
  59. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize: tcgsize;reg1,reg2 : tregister);override;
  60. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  61. { fpu move instructions }
  62. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  63. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  64. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  65. { vector register move instructions }
  66. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); override;
  67. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  68. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  69. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  70. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);override;
  71. { comparison operations }
  72. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  73. l : tasmlabel);override;
  74. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  75. l : tasmlabel);override;
  76. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  77. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  78. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); override;
  79. procedure a_jmp_name(list : taasmoutput;const s : string);override;
  80. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  81. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  82. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  83. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference); override;
  84. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint; loadref : boolean);override;
  85. { entry/exit code helpers }
  86. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);override;
  87. procedure g_profilecode(list : taasmoutput);override;
  88. procedure g_stackpointer_alloc(list : taasmoutput;localsize : longint);override;
  89. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);override;
  90. procedure g_save_standard_registers(list:Taasmoutput);override;
  91. procedure g_restore_standard_registers(list:Taasmoutput);override;
  92. procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
  93. protected
  94. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  95. procedure check_register_size(size:tcgsize;reg:tregister);
  96. procedure opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  97. private
  98. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  99. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  100. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  101. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  102. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  103. end;
  104. function use_sse(def : tdef) : boolean;
  105. const
  106. {$ifdef x86_64}
  107. TCGSize2OpSize: Array[tcgsize] of topsize =
  108. (S_NO,S_B,S_W,S_L,S_Q,S_Q,S_B,S_W,S_L,S_Q,S_Q,
  109. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  110. S_NO,S_NO,S_NO,S_MD,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  111. {$else x86_64}
  112. TCGSize2OpSize: Array[tcgsize] of topsize =
  113. (S_NO,S_B,S_W,S_L,S_L,S_L,S_B,S_W,S_L,S_L,S_L,
  114. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  115. S_NO,S_NO,S_NO,S_MD,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  116. {$endif x86_64}
  117. {$ifndef NOTARGETWIN32}
  118. winstackpagesize = 4096;
  119. {$endif NOTARGETWIN32}
  120. implementation
  121. uses
  122. globals,verbose,systems,cutils,
  123. cgutils,
  124. dwarf,
  125. symdef,defutil,paramgr,tgobj,procinfo;
  126. const
  127. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  128. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  129. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  130. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  131. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  132. function use_sse(def : tdef) : boolean;
  133. begin
  134. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  135. (is_double(def) and (aktfputype in sse_doublescalar));
  136. end;
  137. procedure Tcgx86.done_register_allocators;
  138. begin
  139. rg[R_INTREGISTER].free;
  140. rg[R_MMREGISTER].free;
  141. rg[R_MMXREGISTER].free;
  142. rgfpu.free;
  143. inherited done_register_allocators;
  144. end;
  145. function Tcgx86.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  146. begin
  147. result:=rgfpu.getregisterfpu(list);
  148. end;
  149. function Tcgx86.getmmxregister(list:Taasmoutput):Tregister;
  150. begin
  151. if not assigned(rg[R_MMXREGISTER]) then
  152. internalerror(200312124);
  153. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  154. end;
  155. procedure Tcgx86.getcpuregister(list:Taasmoutput;r:Tregister);
  156. begin
  157. if getregtype(r)=R_FPUREGISTER then
  158. internalerror(2003121210)
  159. else
  160. inherited getcpuregister(list,r);
  161. end;
  162. procedure tcgx86.ungetcpuregister(list:Taasmoutput;r:Tregister);
  163. begin
  164. if getregtype(r)=R_FPUREGISTER then
  165. rgfpu.ungetregisterfpu(list,r)
  166. else
  167. inherited ungetcpuregister(list,r);
  168. end;
  169. procedure Tcgx86.alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  170. begin
  171. if rt<>R_FPUREGISTER then
  172. inherited alloccpuregisters(list,rt,r);
  173. end;
  174. procedure Tcgx86.dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  175. begin
  176. if rt<>R_FPUREGISTER then
  177. inherited dealloccpuregisters(list,rt,r);
  178. end;
  179. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  180. begin
  181. if rt=R_FPUREGISTER then
  182. result:=false
  183. else
  184. result:=inherited uses_registers(rt);
  185. end;
  186. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  187. begin
  188. if getregtype(r)<>R_FPUREGISTER then
  189. inherited add_reg_instruction(instr,r);
  190. end;
  191. procedure tcgx86.dec_fpu_stack;
  192. begin
  193. dec(rgfpu.fpuvaroffset);
  194. end;
  195. procedure tcgx86.inc_fpu_stack;
  196. begin
  197. inc(rgfpu.fpuvaroffset);
  198. end;
  199. {****************************************************************************
  200. This is private property, keep out! :)
  201. ****************************************************************************}
  202. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  203. begin
  204. case s2 of
  205. OS_8,OS_S8 :
  206. if S1 in [OS_8,OS_S8] then
  207. s3 := S_B
  208. else
  209. internalerror(200109221);
  210. OS_16,OS_S16:
  211. case s1 of
  212. OS_8,OS_S8:
  213. s3 := S_BW;
  214. OS_16,OS_S16:
  215. s3 := S_W;
  216. else
  217. internalerror(200109222);
  218. end;
  219. OS_32,OS_S32:
  220. case s1 of
  221. OS_8,OS_S8:
  222. s3 := S_BL;
  223. OS_16,OS_S16:
  224. s3 := S_WL;
  225. OS_32,OS_S32:
  226. s3 := S_L;
  227. else
  228. internalerror(200109223);
  229. end;
  230. {$ifdef x86_64}
  231. OS_64,OS_S64:
  232. case s1 of
  233. OS_8:
  234. s3 := S_BL;
  235. OS_S8:
  236. s3 := S_BQ;
  237. OS_16:
  238. s3 := S_WL;
  239. OS_S16:
  240. s3 := S_WQ;
  241. OS_32:
  242. s3 := S_L;
  243. OS_S32:
  244. s3 := S_LQ;
  245. OS_64,OS_S64:
  246. s3 := S_Q;
  247. else
  248. internalerror(200304302);
  249. end;
  250. {$endif x86_64}
  251. else
  252. internalerror(200109227);
  253. end;
  254. if s3 in [S_B,S_W,S_L,S_Q] then
  255. op := A_MOV
  256. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  257. op := A_MOVZX
  258. else
  259. {$ifdef x86_64}
  260. if s3 in [S_LQ] then
  261. op := A_MOVSXD
  262. else
  263. {$endif x86_64}
  264. op := A_MOVSX;
  265. end;
  266. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  267. begin
  268. case t of
  269. OS_F32 :
  270. begin
  271. op:=A_FLD;
  272. s:=S_FS;
  273. end;
  274. OS_F64 :
  275. begin
  276. op:=A_FLD;
  277. s:=S_FL;
  278. end;
  279. OS_F80 :
  280. begin
  281. op:=A_FLD;
  282. s:=S_FX;
  283. end;
  284. OS_C64 :
  285. begin
  286. op:=A_FILD;
  287. s:=S_IQ;
  288. end;
  289. else
  290. internalerror(200204041);
  291. end;
  292. end;
  293. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  294. var
  295. op : tasmop;
  296. s : topsize;
  297. begin
  298. floatloadops(t,op,s);
  299. list.concat(Taicpu.Op_ref(op,s,ref));
  300. inc_fpu_stack;
  301. end;
  302. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  303. begin
  304. case t of
  305. OS_F32 :
  306. begin
  307. op:=A_FSTP;
  308. s:=S_FS;
  309. end;
  310. OS_F64 :
  311. begin
  312. op:=A_FSTP;
  313. s:=S_FL;
  314. end;
  315. OS_F80 :
  316. begin
  317. op:=A_FSTP;
  318. s:=S_FX;
  319. end;
  320. OS_C64 :
  321. begin
  322. op:=A_FISTP;
  323. s:=S_IQ;
  324. end;
  325. else
  326. internalerror(200204042);
  327. end;
  328. end;
  329. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  330. var
  331. op : tasmop;
  332. s : topsize;
  333. begin
  334. floatstoreops(t,op,s);
  335. list.concat(Taicpu.Op_ref(op,s,ref));
  336. dec_fpu_stack;
  337. end;
  338. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  339. begin
  340. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  341. internalerror(200306031);
  342. end;
  343. {****************************************************************************
  344. Assembler code
  345. ****************************************************************************}
  346. procedure tcgx86.a_jmp_name(list : taasmoutput;const s : string);
  347. begin
  348. list.concat(taicpu.op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
  349. end;
  350. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  351. begin
  352. a_jmp_cond(list, OC_NONE, l);
  353. end;
  354. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  355. begin
  356. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
  357. end;
  358. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  359. begin
  360. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  361. end;
  362. {********************** load instructions ********************}
  363. procedure tcgx86.a_load_const_reg(list : taasmoutput; tosize: TCGSize; a : aint; reg : TRegister);
  364. begin
  365. check_register_size(tosize,reg);
  366. { the optimizer will change it to "xor reg,reg" when loading zero, }
  367. { no need to do it here too (JM) }
  368. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  369. end;
  370. procedure tcgx86.a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aint;const ref : treference);
  371. {$ifdef x86_64}
  372. var
  373. href : treference;
  374. {$endif x86_64}
  375. begin
  376. {$ifdef x86_64}
  377. { x86_64 only supports signed 32 bits constants directly }
  378. if (tosize in [OS_S64,OS_64]) and
  379. ((a<low(longint)) or (a>high(longint))) then
  380. begin
  381. href:=ref;
  382. a_load_const_ref(list,OS_32,longint(a and $ffffffff),href);
  383. inc(href.offset,4);
  384. a_load_const_ref(list,OS_32,longint(a shr 32),href);
  385. end
  386. else
  387. {$endif x86_64}
  388. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,ref));
  389. end;
  390. procedure tcgx86.a_load_reg_ref(list : taasmoutput; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  391. var
  392. op: tasmop;
  393. s: topsize;
  394. tmpreg : tregister;
  395. begin
  396. check_register_size(fromsize,reg);
  397. sizes2load(fromsize,tosize,op,s);
  398. case s of
  399. {$ifdef x86_64}
  400. S_BQ,S_WQ,S_LQ,
  401. {$endif x86_64}
  402. S_BW,S_BL,S_WL :
  403. begin
  404. tmpreg:=getintregister(list,tosize);
  405. {$ifdef x86_64}
  406. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  407. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  408. 64 bit (FK) }
  409. if s in [S_BL,S_WL,S_L] then
  410. tmpreg:=makeregsize(list,tmpreg,OS_32);
  411. {$endif x86_64}
  412. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  413. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  414. end;
  415. else
  416. list.concat(taicpu.op_reg_ref(op,s,reg,ref));
  417. end;
  418. end;
  419. procedure tcgx86.a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  420. var
  421. op: tasmop;
  422. s: topsize;
  423. begin
  424. check_register_size(tosize,reg);
  425. sizes2load(fromsize,tosize,op,s);
  426. {$ifdef x86_64}
  427. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  428. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  429. 64 bit (FK) }
  430. if s in [S_BL,S_WL,S_L] then
  431. reg:=makeregsize(list,reg,OS_32);
  432. {$endif x86_64}
  433. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  434. end;
  435. procedure tcgx86.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  436. var
  437. op: tasmop;
  438. s: topsize;
  439. instr:Taicpu;
  440. begin
  441. check_register_size(fromsize,reg1);
  442. check_register_size(tosize,reg2);
  443. if tcgsize2size[fromsize]>tcgsize2size[tosize] then
  444. begin
  445. reg1:=makeregsize(list,reg1,tosize);
  446. s:=tcgsize2opsize[tosize];
  447. op:=A_MOV;
  448. end
  449. else
  450. sizes2load(fromsize,tosize,op,s);
  451. {$ifdef x86_64}
  452. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  453. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  454. 64 bit (FK) }
  455. if s in [S_BL,S_WL,S_L] then
  456. reg2:=makeregsize(list,reg2,OS_32);
  457. {$endif x86_64}
  458. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  459. { Notify the register allocator that we have written a move instruction so
  460. it can try to eliminate it. }
  461. add_move_instruction(instr);
  462. list.concat(instr);
  463. end;
  464. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  465. begin
  466. with ref do
  467. if (base=NR_NO) and (index=NR_NO) then
  468. begin
  469. if assigned(ref.symbol) then
  470. list.concat(Taicpu.op_sym_ofs_reg(A_MOV,tcgsize2opsize[OS_ADDR],symbol,offset,r))
  471. else
  472. a_load_const_reg(list,OS_ADDR,offset,r);
  473. end
  474. else if (base=NR_NO) and (index<>NR_NO) and
  475. (offset=0) and (scalefactor=0) and (symbol=nil) then
  476. a_load_reg_reg(list,OS_ADDR,OS_ADDR,index,r)
  477. else if (base<>NR_NO) and (index=NR_NO) and
  478. (offset=0) and (symbol=nil) then
  479. a_load_reg_reg(list,OS_ADDR,OS_ADDR,base,r)
  480. else
  481. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],ref,r));
  482. end;
  483. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  484. { R_ST means "the current value at the top of the fpu stack" (JM) }
  485. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  486. begin
  487. if (reg1<>NR_ST) then
  488. begin
  489. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  490. inc_fpu_stack;
  491. end;
  492. if (reg2<>NR_ST) then
  493. begin
  494. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  495. dec_fpu_stack;
  496. end;
  497. end;
  498. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  499. begin
  500. floatload(list,size,ref);
  501. if (reg<>NR_ST) then
  502. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  503. end;
  504. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  505. begin
  506. if reg<>NR_ST then
  507. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  508. floatstore(list,size,ref);
  509. end;
  510. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  511. const
  512. convertop : array[OS_F32..OS_F128,OS_F32..OS_F128] of tasmop = (
  513. (A_MOVSS,A_CVTSS2SD,A_NONE,A_NONE,A_NONE),
  514. (A_CVTSD2SS,A_MOVSD,A_NONE,A_NONE,A_NONE),
  515. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE),
  516. (A_NONE,A_NONE,A_NONE,A_MOVQ,A_NONE),
  517. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE));
  518. begin
  519. result:=convertop[fromsize,tosize];
  520. if result=A_NONE then
  521. internalerror(200312205);
  522. end;
  523. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  524. begin
  525. if shuffle=nil then
  526. begin
  527. if fromsize=tosize then
  528. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  529. else
  530. internalerror(200312202);
  531. end
  532. else if shufflescalar(shuffle) then
  533. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  534. else
  535. internalerror(200312201);
  536. end;
  537. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  538. begin
  539. if shuffle=nil then
  540. begin
  541. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  542. end
  543. else if shufflescalar(shuffle) then
  544. list.concat(taicpu.op_ref_reg(get_scalar_mm_op(fromsize,tosize),S_NO,ref,reg))
  545. else
  546. internalerror(200312252);
  547. end;
  548. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  549. begin
  550. if shuffle=nil then
  551. begin
  552. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  553. end
  554. else if shufflescalar(shuffle) then
  555. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(fromsize,tosize),S_NO,reg,ref))
  556. else
  557. internalerror(200312252);
  558. end;
  559. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  560. var
  561. l : tlocation;
  562. begin
  563. l.loc:=LOC_REFERENCE;
  564. l.reference:=ref;
  565. l.size:=size;
  566. opmm_loc_reg(list,op,size,l,reg,shuffle);
  567. end;
  568. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  569. var
  570. l : tlocation;
  571. begin
  572. l.loc:=LOC_MMREGISTER;
  573. l.register:=src;
  574. l.size:=size;
  575. opmm_loc_reg(list,op,size,l,dst,shuffle);
  576. end;
  577. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  578. const
  579. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  580. ( { scalar }
  581. ( { OS_F32 }
  582. A_NOP,A_ADDSS,A_NOP,A_DIVSS,A_NOP,A_NOP,A_MULSS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBSS,A_NOP
  583. ),
  584. ( { OS_F64 }
  585. A_NOP,A_ADDSD,A_NOP,A_DIVSD,A_NOP,A_NOP,A_MULSD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBSD,A_NOP
  586. )
  587. ),
  588. ( { vectorized/packed }
  589. { because the logical packed single instructions have shorter op codes, we use always
  590. these
  591. }
  592. ( { OS_F32 }
  593. 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_XORPS
  594. ),
  595. ( { OS_F64 }
  596. 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_XORPS
  597. )
  598. )
  599. );
  600. var
  601. resultreg : tregister;
  602. asmop : tasmop;
  603. begin
  604. { this is an internally used procedure so the parameters have
  605. some constrains
  606. }
  607. if loc.size<>size then
  608. internalerror(200312213);
  609. resultreg:=dst;
  610. { deshuffle }
  611. //!!!
  612. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  613. begin
  614. end
  615. else if (shuffle=nil) then
  616. asmop:=opmm2asmop[1,size,op]
  617. else if shufflescalar(shuffle) then
  618. begin
  619. asmop:=opmm2asmop[0,size,op];
  620. { no scalar operation available? }
  621. if asmop=A_NOP then
  622. begin
  623. { do vectorized and shuffle finally }
  624. //!!!
  625. end;
  626. end
  627. else
  628. internalerror(200312211);
  629. if asmop=A_NOP then
  630. internalerror(200312215);
  631. case loc.loc of
  632. LOC_CREFERENCE,LOC_REFERENCE:
  633. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  634. LOC_CMMREGISTER,LOC_MMREGISTER:
  635. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  636. else
  637. internalerror(200312214);
  638. end;
  639. { shuffle }
  640. if resultreg<>dst then
  641. begin
  642. internalerror(200312212);
  643. end;
  644. end;
  645. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  646. var
  647. opcode : tasmop;
  648. power : longint;
  649. {$ifdef x86_64}
  650. tmpreg : tregister;
  651. {$endif x86_64}
  652. begin
  653. {$ifdef x86_64}
  654. { x86_64 only supports signed 32 bits constants directly }
  655. if (size in [OS_S64,OS_64]) and
  656. ((a<low(longint)) or (a>high(longint))) then
  657. begin
  658. tmpreg:=getintregister(list,size);
  659. a_load_const_reg(list,size,a,tmpreg);
  660. a_op_reg_reg(list,op,size,tmpreg,reg);
  661. exit;
  662. end;
  663. {$endif x86_64}
  664. check_register_size(size,reg);
  665. case op of
  666. OP_DIV, OP_IDIV:
  667. begin
  668. if ispowerof2(int64(a),power) then
  669. begin
  670. case op of
  671. OP_DIV:
  672. opcode := A_SHR;
  673. OP_IDIV:
  674. opcode := A_SAR;
  675. end;
  676. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  677. exit;
  678. end;
  679. { the rest should be handled specifically in the code }
  680. { generator because of the silly register usage restraints }
  681. internalerror(200109224);
  682. end;
  683. OP_MUL,OP_IMUL:
  684. begin
  685. if not(cs_check_overflow in aktlocalswitches) and
  686. ispowerof2(int64(a),power) then
  687. begin
  688. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  689. exit;
  690. end;
  691. if op = OP_IMUL then
  692. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  693. else
  694. { OP_MUL should be handled specifically in the code }
  695. { generator because of the silly register usage restraints }
  696. internalerror(200109225);
  697. end;
  698. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  699. if not(cs_check_overflow in aktlocalswitches) and
  700. (a = 1) and
  701. (op in [OP_ADD,OP_SUB]) then
  702. if op = OP_ADD then
  703. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  704. else
  705. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  706. else if (a = 0) then
  707. if (op <> OP_AND) then
  708. exit
  709. else
  710. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  711. else if (aword(a) = high(aword)) and
  712. (op in [OP_AND,OP_OR,OP_XOR]) then
  713. begin
  714. case op of
  715. OP_AND:
  716. exit;
  717. OP_OR:
  718. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],aint(high(aword)),reg));
  719. OP_XOR:
  720. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  721. end
  722. end
  723. else
  724. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  725. OP_SHL,OP_SHR,OP_SAR:
  726. begin
  727. if (a and 31) <> 0 Then
  728. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  729. if (a shr 5) <> 0 Then
  730. internalerror(68991);
  731. end
  732. else internalerror(68992);
  733. end;
  734. end;
  735. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  736. var
  737. opcode: tasmop;
  738. power: longint;
  739. {$ifdef x86_64}
  740. tmpreg : tregister;
  741. {$endif x86_64}
  742. begin
  743. {$ifdef x86_64}
  744. { x86_64 only supports signed 32 bits constants directly }
  745. if (size in [OS_S64,OS_64]) and
  746. ((a<low(longint)) or (a>high(longint))) then
  747. begin
  748. tmpreg:=getintregister(list,size);
  749. a_load_const_reg(list,size,a,tmpreg);
  750. a_op_reg_ref(list,op,size,tmpreg,ref);
  751. exit;
  752. end;
  753. {$endif x86_64}
  754. Case Op of
  755. OP_DIV, OP_IDIV:
  756. Begin
  757. if ispowerof2(int64(a),power) then
  758. begin
  759. case op of
  760. OP_DIV:
  761. opcode := A_SHR;
  762. OP_IDIV:
  763. opcode := A_SAR;
  764. end;
  765. list.concat(taicpu.op_const_ref(opcode,
  766. TCgSize2OpSize[size],power,ref));
  767. exit;
  768. end;
  769. { the rest should be handled specifically in the code }
  770. { generator because of the silly register usage restraints }
  771. internalerror(200109231);
  772. End;
  773. OP_MUL,OP_IMUL:
  774. begin
  775. if not(cs_check_overflow in aktlocalswitches) and
  776. ispowerof2(int64(a),power) then
  777. begin
  778. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  779. power,ref));
  780. exit;
  781. end;
  782. { can't multiply a memory location directly with a constant }
  783. if op = OP_IMUL then
  784. inherited a_op_const_ref(list,op,size,a,ref)
  785. else
  786. { OP_MUL should be handled specifically in the code }
  787. { generator because of the silly register usage restraints }
  788. internalerror(200109232);
  789. end;
  790. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  791. if not(cs_check_overflow in aktlocalswitches) and
  792. (a = 1) and
  793. (op in [OP_ADD,OP_SUB]) then
  794. if op = OP_ADD then
  795. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  796. else
  797. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  798. else if (a = 0) then
  799. if (op <> OP_AND) then
  800. exit
  801. else
  802. a_load_const_ref(list,size,0,ref)
  803. else if (aword(a) = high(aword)) and
  804. (op in [OP_AND,OP_OR,OP_XOR]) then
  805. begin
  806. case op of
  807. OP_AND:
  808. exit;
  809. OP_OR:
  810. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],aint(high(aword)),ref));
  811. OP_XOR:
  812. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  813. end
  814. end
  815. else
  816. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  817. TCgSize2OpSize[size],a,ref));
  818. OP_SHL,OP_SHR,OP_SAR:
  819. begin
  820. if (a and 31) <> 0 then
  821. list.concat(taicpu.op_const_ref(
  822. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  823. if (a shr 5) <> 0 Then
  824. internalerror(68991);
  825. end
  826. else internalerror(68992);
  827. end;
  828. end;
  829. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  830. var
  831. dstsize: topsize;
  832. instr:Taicpu;
  833. begin
  834. check_register_size(size,src);
  835. check_register_size(size,dst);
  836. dstsize := tcgsize2opsize[size];
  837. case op of
  838. OP_NEG,OP_NOT:
  839. begin
  840. if src<>dst then
  841. a_load_reg_reg(list,size,size,src,dst);
  842. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  843. end;
  844. OP_MUL,OP_DIV,OP_IDIV:
  845. { special stuff, needs separate handling inside code }
  846. { generator }
  847. internalerror(200109233);
  848. OP_SHR,OP_SHL,OP_SAR:
  849. begin
  850. getcpuregister(list,NR_CL);
  851. a_load_reg_reg(list,OS_8,OS_8,makeregsize(list,src,OS_8),NR_CL);
  852. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],tcgsize2opsize[size],NR_CL,src));
  853. ungetcpuregister(list,NR_CL);
  854. end;
  855. else
  856. begin
  857. if reg2opsize(src) <> dstsize then
  858. internalerror(200109226);
  859. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  860. list.concat(instr);
  861. end;
  862. end;
  863. end;
  864. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  865. begin
  866. check_register_size(size,reg);
  867. case op of
  868. OP_NEG,OP_NOT,OP_IMUL:
  869. begin
  870. inherited a_op_ref_reg(list,op,size,ref,reg);
  871. end;
  872. OP_MUL,OP_DIV,OP_IDIV:
  873. { special stuff, needs separate handling inside code }
  874. { generator }
  875. internalerror(200109239);
  876. else
  877. begin
  878. reg := makeregsize(list,reg,size);
  879. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  880. end;
  881. end;
  882. end;
  883. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  884. begin
  885. check_register_size(size,reg);
  886. case op of
  887. OP_NEG,OP_NOT:
  888. begin
  889. if reg<>NR_NO then
  890. internalerror(200109237);
  891. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  892. end;
  893. OP_IMUL:
  894. begin
  895. { this one needs a load/imul/store, which is the default }
  896. inherited a_op_ref_reg(list,op,size,ref,reg);
  897. end;
  898. OP_MUL,OP_DIV,OP_IDIV:
  899. { special stuff, needs separate handling inside code }
  900. { generator }
  901. internalerror(200109238);
  902. else
  903. begin
  904. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,ref));
  905. end;
  906. end;
  907. end;
  908. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister);
  909. var
  910. tmpref: treference;
  911. power: longint;
  912. {$ifdef x86_64}
  913. tmpreg : tregister;
  914. {$endif x86_64}
  915. begin
  916. {$ifdef x86_64}
  917. { x86_64 only supports signed 32 bits constants directly }
  918. if (size in [OS_S64,OS_64]) and
  919. ((a<low(longint)) or (a>high(longint))) then
  920. begin
  921. tmpreg:=getintregister(list,size);
  922. a_load_const_reg(list,size,a,tmpreg);
  923. a_op_reg_reg_reg(list,op,size,tmpreg,src,dst);
  924. exit;
  925. end;
  926. {$endif x86_64}
  927. check_register_size(size,src);
  928. check_register_size(size,dst);
  929. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  930. begin
  931. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  932. exit;
  933. end;
  934. { if we get here, we have to do a 32 bit calculation, guaranteed }
  935. case op of
  936. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  937. OP_SAR:
  938. { can't do anything special for these }
  939. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  940. OP_IMUL:
  941. begin
  942. if not(cs_check_overflow in aktlocalswitches) and
  943. ispowerof2(int64(a),power) then
  944. { can be done with a shift }
  945. begin
  946. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  947. exit;
  948. end;
  949. list.concat(taicpu.op_const_reg_reg(A_IMUL,tcgsize2opsize[size],a,src,dst));
  950. end;
  951. OP_ADD, OP_SUB:
  952. if (a = 0) then
  953. a_load_reg_reg(list,size,size,src,dst)
  954. else
  955. begin
  956. reference_reset(tmpref);
  957. tmpref.base := src;
  958. tmpref.offset := longint(a);
  959. if op = OP_SUB then
  960. tmpref.offset := -tmpref.offset;
  961. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  962. end
  963. else internalerror(200112302);
  964. end;
  965. end;
  966. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;size: tcgsize; src1, src2, dst: tregister);
  967. var
  968. tmpref: treference;
  969. begin
  970. check_register_size(size,src1);
  971. check_register_size(size,src2);
  972. check_register_size(size,dst);
  973. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  974. begin
  975. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  976. exit;
  977. end;
  978. { if we get here, we have to do a 32 bit calculation, guaranteed }
  979. Case Op of
  980. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  981. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  982. { can't do anything special for these }
  983. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  984. OP_IMUL:
  985. list.concat(taicpu.op_reg_reg_reg(A_IMUL,tcgsize2opsize[size],src1,src2,dst));
  986. OP_ADD:
  987. begin
  988. reference_reset(tmpref);
  989. tmpref.base := src1;
  990. tmpref.index := src2;
  991. tmpref.scalefactor := 1;
  992. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  993. end
  994. else internalerror(200112303);
  995. end;
  996. end;
  997. {*************** compare instructructions ****************}
  998. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  999. l : tasmlabel);
  1000. {$ifdef x86_64}
  1001. var
  1002. tmpreg : tregister;
  1003. {$endif x86_64}
  1004. begin
  1005. {$ifdef x86_64}
  1006. { x86_64 only supports signed 32 bits constants directly }
  1007. if (size in [OS_S64,OS_64]) and
  1008. ((a<low(longint)) or (a>high(longint))) then
  1009. begin
  1010. tmpreg:=getintregister(list,size);
  1011. a_load_const_reg(list,size,a,tmpreg);
  1012. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1013. exit;
  1014. end;
  1015. {$endif x86_64}
  1016. if (a = 0) then
  1017. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1018. else
  1019. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1020. a_jmp_cond(list,cmp_op,l);
  1021. end;
  1022. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  1023. l : tasmlabel);
  1024. {$ifdef x86_64}
  1025. var
  1026. tmpreg : tregister;
  1027. {$endif x86_64}
  1028. begin
  1029. {$ifdef x86_64}
  1030. { x86_64 only supports signed 32 bits constants directly }
  1031. if (size in [OS_S64,OS_64]) and
  1032. ((a<low(longint)) or (a>high(longint))) then
  1033. begin
  1034. tmpreg:=getintregister(list,size);
  1035. a_load_const_reg(list,size,a,tmpreg);
  1036. a_cmp_reg_ref_label(list,size,cmp_op,tmpreg,ref,l);
  1037. exit;
  1038. end;
  1039. {$endif x86_64}
  1040. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  1041. a_jmp_cond(list,cmp_op,l);
  1042. end;
  1043. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  1044. reg1,reg2 : tregister;l : tasmlabel);
  1045. begin
  1046. check_register_size(size,reg1);
  1047. check_register_size(size,reg2);
  1048. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1049. a_jmp_cond(list,cmp_op,l);
  1050. end;
  1051. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1052. begin
  1053. check_register_size(size,reg);
  1054. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],ref,reg));
  1055. a_jmp_cond(list,cmp_op,l);
  1056. end;
  1057. procedure tcgx86.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister;const ref: treference; l : tasmlabel);
  1058. begin
  1059. check_register_size(size,reg);
  1060. list.concat(taicpu.op_reg_ref(A_CMP,TCgSize2OpSize[size],reg,ref));
  1061. a_jmp_cond(list,cmp_op,l);
  1062. end;
  1063. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1064. var
  1065. ai : taicpu;
  1066. begin
  1067. if cond=OC_None then
  1068. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1069. else
  1070. begin
  1071. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1072. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1073. end;
  1074. ai.is_jmp:=true;
  1075. list.concat(ai);
  1076. end;
  1077. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  1078. var
  1079. ai : taicpu;
  1080. begin
  1081. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1082. ai.SetCondition(flags_to_cond(f));
  1083. ai.is_jmp := true;
  1084. list.concat(ai);
  1085. end;
  1086. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  1087. var
  1088. ai : taicpu;
  1089. hreg : tregister;
  1090. begin
  1091. hreg:=makeregsize(list,reg,OS_8);
  1092. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1093. ai.setcondition(flags_to_cond(f));
  1094. list.concat(ai);
  1095. if (reg<>hreg) then
  1096. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1097. end;
  1098. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  1099. var
  1100. ai : taicpu;
  1101. begin
  1102. if not(size in [OS_8,OS_S8]) then
  1103. a_load_const_ref(list,size,0,ref);
  1104. ai:=Taicpu.op_ref(A_SETcc,S_B,ref);
  1105. ai.setcondition(flags_to_cond(f));
  1106. list.concat(ai);
  1107. end;
  1108. { ************* concatcopy ************ }
  1109. procedure Tcgx86.g_concatcopy(list:Taasmoutput;const source,dest:Treference;len:aint;loadref:boolean);
  1110. const
  1111. {$ifdef cpu64bit}
  1112. REGCX=NR_RCX;
  1113. REGSI=NR_RSI;
  1114. REGDI=NR_RDI;
  1115. {$else cpu64bit}
  1116. REGCX=NR_ECX;
  1117. REGSI=NR_ESI;
  1118. REGDI=NR_EDI;
  1119. {$endif cpu64bit}
  1120. type copymode=(copy_move,copy_mmx,copy_string);
  1121. var srcref,dstref:Treference;
  1122. r,r0,r1,r2,r3:Tregister;
  1123. helpsize:aint;
  1124. copysize:byte;
  1125. cgsize:Tcgsize;
  1126. cm:copymode;
  1127. begin
  1128. cm:=copy_move;
  1129. helpsize:=12;
  1130. if cs_littlesize in aktglobalswitches then
  1131. helpsize:=8;
  1132. if (cs_mmx in aktlocalswitches) and
  1133. not(pi_uses_fpu in current_procinfo.flags) and
  1134. ((len=8) or (len=16) or (len=24) or (len=32)) then
  1135. cm:=copy_mmx;
  1136. if (len>helpsize) then
  1137. cm:=copy_string;
  1138. if (cs_littlesize in aktglobalswitches) and
  1139. not((len<=16) and (cm=copy_mmx)) then
  1140. cm:=copy_string;
  1141. if loadref then
  1142. cm:=copy_string;
  1143. case cm of
  1144. copy_move:
  1145. begin
  1146. dstref:=dest;
  1147. srcref:=source;
  1148. copysize:=sizeof(aint);
  1149. cgsize:=int_cgsize(copysize);
  1150. while len<>0 do
  1151. begin
  1152. if len<2 then
  1153. begin
  1154. copysize:=1;
  1155. cgsize:=OS_8;
  1156. end
  1157. else if len<4 then
  1158. begin
  1159. copysize:=2;
  1160. cgsize:=OS_16;
  1161. end
  1162. else if len<8 then
  1163. begin
  1164. copysize:=4;
  1165. cgsize:=OS_32;
  1166. end;
  1167. dec(len,copysize);
  1168. r:=getintregister(list,cgsize);
  1169. a_load_ref_reg(list,cgsize,cgsize,srcref,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. if len>=16 then
  1201. begin
  1202. inc(dstref.offset,8);
  1203. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1204. end;
  1205. if len>=24 then
  1206. begin
  1207. inc(dstref.offset,8);
  1208. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  1209. end;
  1210. if len>=32 then
  1211. begin
  1212. inc(dstref.offset,8);
  1213. a_loadmm_reg_ref(list,OS_M64,OS_M64,r3,dstref,nil);
  1214. end;
  1215. end
  1216. else {copy_string, should be a good fallback in case of unhandled}
  1217. begin
  1218. getcpuregister(list,REGDI);
  1219. a_loadaddr_ref_reg(list,dest,REGDI);
  1220. getcpuregister(list,REGSI);
  1221. if loadref then
  1222. a_load_ref_reg(list,OS_ADDR,OS_ADDR,source,REGSI)
  1223. else
  1224. a_loadaddr_ref_reg(list,source,REGSI);
  1225. getcpuregister(list,REGCX);
  1226. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1227. if cs_littlesize in aktglobalswitches then
  1228. begin
  1229. a_load_const_reg(list,OS_INT,len,REGCX);
  1230. list.concat(Taicpu.op_none(A_REP,S_NO));
  1231. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1232. end
  1233. else
  1234. begin
  1235. helpsize:=len div sizeof(aint);
  1236. len:=len mod sizeof(aint);
  1237. if helpsize>1 then
  1238. begin
  1239. a_load_const_reg(list,OS_INT,helpsize,REGCX);
  1240. list.concat(Taicpu.op_none(A_REP,S_NO));
  1241. end;
  1242. if helpsize>0 then
  1243. begin
  1244. {$ifdef cpu64bit}
  1245. if sizeof(aint)=8 then
  1246. list.concat(Taicpu.op_none(A_MOVSQ,S_NO))
  1247. else
  1248. {$endif cpu64bit}
  1249. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1250. end;
  1251. if len>=4 then
  1252. begin
  1253. dec(len,4);
  1254. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1255. end;
  1256. if len>=2 then
  1257. begin
  1258. dec(len,2);
  1259. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1260. end;
  1261. if len=1 then
  1262. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1263. end;
  1264. ungetcpuregister(list,REGCX);
  1265. ungetcpuregister(list,REGSI);
  1266. ungetcpuregister(list,REGDI);
  1267. end;
  1268. end;
  1269. end;
  1270. {****************************************************************************
  1271. Entry/Exit Code Helpers
  1272. ****************************************************************************}
  1273. procedure tcgx86.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1274. begin
  1275. { Nothing to release }
  1276. end;
  1277. procedure tcgx86.g_profilecode(list : taasmoutput);
  1278. var
  1279. pl : tasmlabel;
  1280. mcountprefix : String[4];
  1281. begin
  1282. case target_info.system of
  1283. {$ifndef NOTARGETWIN32}
  1284. system_i386_win32,
  1285. {$endif}
  1286. system_i386_freebsd,
  1287. system_i386_netbsd,
  1288. // system_i386_openbsd,
  1289. system_i386_wdosx :
  1290. begin
  1291. Case target_info.system Of
  1292. system_i386_freebsd : mcountprefix:='.';
  1293. system_i386_netbsd : mcountprefix:='__';
  1294. // system_i386_openbsd : mcountprefix:='.';
  1295. else
  1296. mcountPrefix:='';
  1297. end;
  1298. objectlibrary.getaddrlabel(pl);
  1299. new_section(list,sec_data,lower(current_procinfo.procdef.mangledname),sizeof(aint));
  1300. list.concat(Tai_label.Create(pl));
  1301. list.concat(Tai_const.Create_32bit(0));
  1302. new_section(list,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1303. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1304. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1305. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1306. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1307. end;
  1308. system_i386_linux:
  1309. a_call_name(list,target_info.Cprefix+'mcount');
  1310. system_i386_go32v2,system_i386_watcom:
  1311. begin
  1312. a_call_name(list,'MCOUNT');
  1313. end;
  1314. end;
  1315. end;
  1316. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1317. {$ifdef i386}
  1318. {$ifndef NOTARGETWIN32}
  1319. var
  1320. href : treference;
  1321. i : integer;
  1322. again : tasmlabel;
  1323. {$endif NOTARGETWIN32}
  1324. {$endif i386}
  1325. begin
  1326. if localsize>0 then
  1327. begin
  1328. {$ifdef i386}
  1329. {$ifndef NOTARGETWIN32}
  1330. { windows guards only a few pages for stack growing, }
  1331. { so we have to access every page first }
  1332. if (target_info.system=system_i386_win32) and
  1333. (localsize>=winstackpagesize) then
  1334. begin
  1335. if localsize div winstackpagesize<=5 then
  1336. begin
  1337. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1338. for i:=1 to localsize div winstackpagesize do
  1339. begin
  1340. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1341. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1342. end;
  1343. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1344. end
  1345. else
  1346. begin
  1347. objectlibrary.getlabel(again);
  1348. getcpuregister(list,NR_EDI);
  1349. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1350. a_label(list,again);
  1351. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1352. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1353. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1354. a_jmp_cond(list,OC_NE,again);
  1355. ungetcpuregister(list,NR_EDI);
  1356. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1357. end
  1358. end
  1359. else
  1360. {$endif NOTARGETWIN32}
  1361. {$endif i386}
  1362. list.concat(Taicpu.Op_const_reg(A_SUB,tcgsize2opsize[OS_ADDR],localsize,NR_STACK_POINTER_REG));
  1363. end;
  1364. end;
  1365. procedure tcgx86.g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);
  1366. begin
  1367. {$ifdef i386}
  1368. { interrupt support for i386 }
  1369. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1370. begin
  1371. { .... also the segment registers }
  1372. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1373. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1374. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1375. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1376. { save the registers of an interrupt procedure }
  1377. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1378. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1379. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1380. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1381. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1382. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1383. end;
  1384. {$endif i386}
  1385. { save old framepointer }
  1386. if not nostackframe then
  1387. begin
  1388. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1389. CGmessage(cg_d_stackframe_omited)
  1390. else
  1391. begin
  1392. list.concat(tai_regalloc.alloc(NR_FRAME_POINTER_REG));
  1393. include(rg[R_INTREGISTER].preserved_by_proc,RS_FRAME_POINTER_REG);
  1394. list.concat(Taicpu.op_reg(A_PUSH,tcgsize2opsize[OS_ADDR],NR_FRAME_POINTER_REG));
  1395. { Return address and FP are both on stack }
  1396. dwarfcfi.cfa_def_cfa_offset(list,2*sizeof(aint));
  1397. dwarfcfi.cfa_offset(list,NR_FRAME_POINTER_REG,-(2*sizeof(aint)));
  1398. list.concat(Taicpu.op_reg_reg(A_MOV,tcgsize2opsize[OS_ADDR],NR_STACK_POINTER_REG,NR_FRAME_POINTER_REG));
  1399. dwarfcfi.cfa_def_cfa_register(list,NR_FRAME_POINTER_REG);
  1400. end;
  1401. { allocate stackframe space }
  1402. if localsize<>0 then
  1403. begin
  1404. cg.g_stackpointer_alloc(list,localsize);
  1405. end;
  1406. end;
  1407. { allocate PIC register }
  1408. if cs_create_pic in aktmoduleswitches then
  1409. begin
  1410. a_call_name(list,'FPC_GETEIPINEBX');
  1411. list.concat(taicpu.op_sym_ofs_reg(A_ADD,tcgsize2opsize[OS_ADDR],objectlibrary.newasmsymbol('_GLOBAL_OFFSET_TABLE_',AB_EXTERNAL,AT_DATA),0,NR_PIC_OFFSET_REG));
  1412. list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG));
  1413. end;
  1414. end;
  1415. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1416. var
  1417. href : treference;
  1418. size : longint;
  1419. r : integer;
  1420. begin
  1421. { Get temp }
  1422. size:=0;
  1423. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1424. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1425. inc(size,sizeof(aint));
  1426. if size>0 then
  1427. begin
  1428. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1429. { Copy registers to temp }
  1430. href:=current_procinfo.save_regs_ref;
  1431. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1432. begin
  1433. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1434. begin
  1435. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1436. inc(href.offset,sizeof(aint));
  1437. end;
  1438. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1439. end;
  1440. end;
  1441. end;
  1442. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1443. var
  1444. href : treference;
  1445. r : integer;
  1446. begin
  1447. { Copy registers from temp }
  1448. href:=current_procinfo.save_regs_ref;
  1449. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1450. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1451. begin
  1452. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE));
  1453. inc(href.offset,sizeof(aint));
  1454. end;
  1455. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1456. end;
  1457. { produces if necessary overflowcode }
  1458. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1459. var
  1460. hl : tasmlabel;
  1461. ai : taicpu;
  1462. cond : TAsmCond;
  1463. begin
  1464. if not(cs_check_overflow in aktlocalswitches) then
  1465. exit;
  1466. objectlibrary.getlabel(hl);
  1467. if not ((def.deftype=pointerdef) or
  1468. ((def.deftype=orddef) and
  1469. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1470. bool8bit,bool16bit,bool32bit]))) then
  1471. cond:=C_NO
  1472. else
  1473. cond:=C_NB;
  1474. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1475. ai.SetCondition(cond);
  1476. ai.is_jmp:=true;
  1477. list.concat(ai);
  1478. a_call_name(list,'FPC_OVERFLOW');
  1479. a_label(list,hl);
  1480. end;
  1481. end.
  1482. {
  1483. $Log$
  1484. Revision 1.126 2004-10-03 12:42:22 florian
  1485. * made sqrt, sqr and abs internal for the sparc
  1486. Revision 1.125 2004/09/25 14:23:55 peter
  1487. * ungetregister is now only used for cpuregisters, renamed to
  1488. ungetcpuregister
  1489. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1490. * removed location-release/reference_release
  1491. Revision 1.124 2004/06/20 08:55:32 florian
  1492. * logs truncated
  1493. Revision 1.123 2004/06/16 20:07:11 florian
  1494. * dwarf branch merged
  1495. Revision 1.122 2004/05/22 23:34:28 peter
  1496. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1497. Revision 1.121 2004/04/28 15:19:03 florian
  1498. + syscall directive support for MorphOS added
  1499. Revision 1.120 2004/04/09 14:36:05 peter
  1500. * A_MOVSL renamed to A_MOVSD
  1501. Revision 1.119.2.22 2004/05/28 20:29:50 florian
  1502. * fixed currency trouble on x86-64
  1503. }