cgx86.pas 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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. if (reg1<>reg2) then
  459. begin
  460. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  461. { Notify the register allocator that we have written a move instruction so
  462. it can try to eliminate it. }
  463. add_move_instruction(instr);
  464. list.concat(instr);
  465. end;
  466. end;
  467. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  468. begin
  469. with ref do
  470. if (base=NR_NO) and (index=NR_NO) then
  471. begin
  472. if assigned(ref.symbol) then
  473. list.concat(Taicpu.op_sym_ofs_reg(A_MOV,tcgsize2opsize[OS_ADDR],symbol,offset,r))
  474. else
  475. a_load_const_reg(list,OS_ADDR,offset,r);
  476. end
  477. else if (base=NR_NO) and (index<>NR_NO) and
  478. (offset=0) and (scalefactor=0) and (symbol=nil) then
  479. a_load_reg_reg(list,OS_ADDR,OS_ADDR,index,r)
  480. else if (base<>NR_NO) and (index=NR_NO) and
  481. (offset=0) and (symbol=nil) then
  482. a_load_reg_reg(list,OS_ADDR,OS_ADDR,base,r)
  483. else
  484. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],ref,r));
  485. end;
  486. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  487. { R_ST means "the current value at the top of the fpu stack" (JM) }
  488. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  489. begin
  490. if (reg1<>NR_ST) then
  491. begin
  492. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  493. inc_fpu_stack;
  494. end;
  495. if (reg2<>NR_ST) then
  496. begin
  497. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  498. dec_fpu_stack;
  499. end;
  500. end;
  501. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  502. begin
  503. floatload(list,size,ref);
  504. if (reg<>NR_ST) then
  505. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  506. end;
  507. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  508. begin
  509. if reg<>NR_ST then
  510. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  511. floatstore(list,size,ref);
  512. end;
  513. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  514. const
  515. convertop : array[OS_F32..OS_F128,OS_F32..OS_F128] of tasmop = (
  516. (A_MOVSS,A_CVTSS2SD,A_NONE,A_NONE,A_NONE),
  517. (A_CVTSD2SS,A_MOVSD,A_NONE,A_NONE,A_NONE),
  518. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE),
  519. (A_NONE,A_NONE,A_NONE,A_MOVQ,A_NONE),
  520. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE));
  521. begin
  522. result:=convertop[fromsize,tosize];
  523. if result=A_NONE then
  524. internalerror(200312205);
  525. end;
  526. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  527. begin
  528. if shuffle=nil then
  529. begin
  530. if fromsize=tosize then
  531. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  532. else
  533. internalerror(200312202);
  534. end
  535. else if shufflescalar(shuffle) then
  536. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  537. else
  538. internalerror(200312201);
  539. end;
  540. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  541. begin
  542. if shuffle=nil then
  543. begin
  544. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  545. end
  546. else if shufflescalar(shuffle) then
  547. list.concat(taicpu.op_ref_reg(get_scalar_mm_op(fromsize,tosize),S_NO,ref,reg))
  548. else
  549. internalerror(200312252);
  550. end;
  551. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  552. begin
  553. if shuffle=nil then
  554. begin
  555. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  556. end
  557. else if shufflescalar(shuffle) then
  558. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(fromsize,tosize),S_NO,reg,ref))
  559. else
  560. internalerror(200312252);
  561. end;
  562. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  563. var
  564. l : tlocation;
  565. begin
  566. l.loc:=LOC_REFERENCE;
  567. l.reference:=ref;
  568. l.size:=size;
  569. opmm_loc_reg(list,op,size,l,reg,shuffle);
  570. end;
  571. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  572. var
  573. l : tlocation;
  574. begin
  575. l.loc:=LOC_MMREGISTER;
  576. l.register:=src;
  577. l.size:=size;
  578. opmm_loc_reg(list,op,size,l,dst,shuffle);
  579. end;
  580. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  581. const
  582. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  583. ( { scalar }
  584. ( { OS_F32 }
  585. 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
  586. ),
  587. ( { OS_F64 }
  588. 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
  589. )
  590. ),
  591. ( { vectorized/packed }
  592. { because the logical packed single instructions have shorter op codes, we use always
  593. these
  594. }
  595. ( { OS_F32 }
  596. 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
  597. ),
  598. ( { OS_F64 }
  599. 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
  600. )
  601. )
  602. );
  603. var
  604. resultreg : tregister;
  605. asmop : tasmop;
  606. begin
  607. { this is an internally used procedure so the parameters have
  608. some constrains
  609. }
  610. if loc.size<>size then
  611. internalerror(200312213);
  612. resultreg:=dst;
  613. { deshuffle }
  614. //!!!
  615. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  616. begin
  617. end
  618. else if (shuffle=nil) then
  619. asmop:=opmm2asmop[1,size,op]
  620. else if shufflescalar(shuffle) then
  621. begin
  622. asmop:=opmm2asmop[0,size,op];
  623. { no scalar operation available? }
  624. if asmop=A_NOP then
  625. begin
  626. { do vectorized and shuffle finally }
  627. //!!!
  628. end;
  629. end
  630. else
  631. internalerror(200312211);
  632. if asmop=A_NOP then
  633. internalerror(200312215);
  634. case loc.loc of
  635. LOC_CREFERENCE,LOC_REFERENCE:
  636. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  637. LOC_CMMREGISTER,LOC_MMREGISTER:
  638. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  639. else
  640. internalerror(200312214);
  641. end;
  642. { shuffle }
  643. if resultreg<>dst then
  644. begin
  645. internalerror(200312212);
  646. end;
  647. end;
  648. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  649. var
  650. opcode : tasmop;
  651. power : longint;
  652. {$ifdef x86_64}
  653. tmpreg : tregister;
  654. {$endif x86_64}
  655. begin
  656. {$ifdef x86_64}
  657. { x86_64 only supports signed 32 bits constants directly }
  658. if (size in [OS_S64,OS_64]) and
  659. ((a<low(longint)) or (a>high(longint))) then
  660. begin
  661. tmpreg:=getintregister(list,size);
  662. a_load_const_reg(list,size,a,tmpreg);
  663. a_op_reg_reg(list,op,size,tmpreg,reg);
  664. exit;
  665. end;
  666. {$endif x86_64}
  667. check_register_size(size,reg);
  668. case op of
  669. OP_DIV, OP_IDIV:
  670. begin
  671. if ispowerof2(int64(a),power) then
  672. begin
  673. case op of
  674. OP_DIV:
  675. opcode := A_SHR;
  676. OP_IDIV:
  677. opcode := A_SAR;
  678. end;
  679. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  680. exit;
  681. end;
  682. { the rest should be handled specifically in the code }
  683. { generator because of the silly register usage restraints }
  684. internalerror(200109224);
  685. end;
  686. OP_MUL,OP_IMUL:
  687. begin
  688. if not(cs_check_overflow in aktlocalswitches) and
  689. ispowerof2(int64(a),power) then
  690. begin
  691. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  692. exit;
  693. end;
  694. if op = OP_IMUL then
  695. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  696. else
  697. { OP_MUL should be handled specifically in the code }
  698. { generator because of the silly register usage restraints }
  699. internalerror(200109225);
  700. end;
  701. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  702. if not(cs_check_overflow in aktlocalswitches) and
  703. (a = 1) and
  704. (op in [OP_ADD,OP_SUB]) then
  705. if op = OP_ADD then
  706. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  707. else
  708. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  709. else if (a = 0) then
  710. if (op <> OP_AND) then
  711. exit
  712. else
  713. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  714. else if (aword(a) = high(aword)) and
  715. (op in [OP_AND,OP_OR,OP_XOR]) then
  716. begin
  717. case op of
  718. OP_AND:
  719. exit;
  720. OP_OR:
  721. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],aint(high(aword)),reg));
  722. OP_XOR:
  723. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  724. end
  725. end
  726. else
  727. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  728. OP_SHL,OP_SHR,OP_SAR:
  729. begin
  730. if (a and 31) <> 0 Then
  731. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  732. if (a shr 5) <> 0 Then
  733. internalerror(68991);
  734. end
  735. else internalerror(68992);
  736. end;
  737. end;
  738. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  739. var
  740. opcode: tasmop;
  741. power: longint;
  742. {$ifdef x86_64}
  743. tmpreg : tregister;
  744. {$endif x86_64}
  745. begin
  746. {$ifdef x86_64}
  747. { x86_64 only supports signed 32 bits constants directly }
  748. if (size in [OS_S64,OS_64]) and
  749. ((a<low(longint)) or (a>high(longint))) then
  750. begin
  751. tmpreg:=getintregister(list,size);
  752. a_load_const_reg(list,size,a,tmpreg);
  753. a_op_reg_ref(list,op,size,tmpreg,ref);
  754. exit;
  755. end;
  756. {$endif x86_64}
  757. Case Op of
  758. OP_DIV, OP_IDIV:
  759. Begin
  760. if ispowerof2(int64(a),power) then
  761. begin
  762. case op of
  763. OP_DIV:
  764. opcode := A_SHR;
  765. OP_IDIV:
  766. opcode := A_SAR;
  767. end;
  768. list.concat(taicpu.op_const_ref(opcode,
  769. TCgSize2OpSize[size],power,ref));
  770. exit;
  771. end;
  772. { the rest should be handled specifically in the code }
  773. { generator because of the silly register usage restraints }
  774. internalerror(200109231);
  775. End;
  776. OP_MUL,OP_IMUL:
  777. begin
  778. if not(cs_check_overflow in aktlocalswitches) and
  779. ispowerof2(int64(a),power) then
  780. begin
  781. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  782. power,ref));
  783. exit;
  784. end;
  785. { can't multiply a memory location directly with a constant }
  786. if op = OP_IMUL then
  787. inherited a_op_const_ref(list,op,size,a,ref)
  788. else
  789. { OP_MUL should be handled specifically in the code }
  790. { generator because of the silly register usage restraints }
  791. internalerror(200109232);
  792. end;
  793. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  794. if not(cs_check_overflow in aktlocalswitches) and
  795. (a = 1) and
  796. (op in [OP_ADD,OP_SUB]) then
  797. if op = OP_ADD then
  798. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  799. else
  800. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  801. else if (a = 0) then
  802. if (op <> OP_AND) then
  803. exit
  804. else
  805. a_load_const_ref(list,size,0,ref)
  806. else if (aword(a) = high(aword)) and
  807. (op in [OP_AND,OP_OR,OP_XOR]) then
  808. begin
  809. case op of
  810. OP_AND:
  811. exit;
  812. OP_OR:
  813. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],aint(high(aword)),ref));
  814. OP_XOR:
  815. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  816. end
  817. end
  818. else
  819. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  820. TCgSize2OpSize[size],a,ref));
  821. OP_SHL,OP_SHR,OP_SAR:
  822. begin
  823. if (a and 31) <> 0 then
  824. list.concat(taicpu.op_const_ref(
  825. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  826. if (a shr 5) <> 0 Then
  827. internalerror(68991);
  828. end
  829. else internalerror(68992);
  830. end;
  831. end;
  832. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  833. var
  834. dstsize: topsize;
  835. instr:Taicpu;
  836. begin
  837. check_register_size(size,src);
  838. check_register_size(size,dst);
  839. dstsize := tcgsize2opsize[size];
  840. case op of
  841. OP_NEG,OP_NOT:
  842. begin
  843. if src<>dst then
  844. a_load_reg_reg(list,size,size,src,dst);
  845. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  846. end;
  847. OP_MUL,OP_DIV,OP_IDIV:
  848. { special stuff, needs separate handling inside code }
  849. { generator }
  850. internalerror(200109233);
  851. OP_SHR,OP_SHL,OP_SAR:
  852. begin
  853. getcpuregister(list,NR_CL);
  854. a_load_reg_reg(list,OS_8,OS_8,makeregsize(list,src,OS_8),NR_CL);
  855. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],tcgsize2opsize[size],NR_CL,src));
  856. ungetcpuregister(list,NR_CL);
  857. end;
  858. else
  859. begin
  860. if reg2opsize(src) <> dstsize then
  861. internalerror(200109226);
  862. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  863. list.concat(instr);
  864. end;
  865. end;
  866. end;
  867. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  868. begin
  869. check_register_size(size,reg);
  870. case op of
  871. OP_NEG,OP_NOT,OP_IMUL:
  872. begin
  873. inherited a_op_ref_reg(list,op,size,ref,reg);
  874. end;
  875. OP_MUL,OP_DIV,OP_IDIV:
  876. { special stuff, needs separate handling inside code }
  877. { generator }
  878. internalerror(200109239);
  879. else
  880. begin
  881. reg := makeregsize(list,reg,size);
  882. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  883. end;
  884. end;
  885. end;
  886. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  887. begin
  888. check_register_size(size,reg);
  889. case op of
  890. OP_NEG,OP_NOT:
  891. begin
  892. if reg<>NR_NO then
  893. internalerror(200109237);
  894. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  895. end;
  896. OP_IMUL:
  897. begin
  898. { this one needs a load/imul/store, which is the default }
  899. inherited a_op_ref_reg(list,op,size,ref,reg);
  900. end;
  901. OP_MUL,OP_DIV,OP_IDIV:
  902. { special stuff, needs separate handling inside code }
  903. { generator }
  904. internalerror(200109238);
  905. else
  906. begin
  907. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,ref));
  908. end;
  909. end;
  910. end;
  911. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister);
  912. var
  913. tmpref: treference;
  914. power: longint;
  915. {$ifdef x86_64}
  916. tmpreg : tregister;
  917. {$endif x86_64}
  918. begin
  919. {$ifdef x86_64}
  920. { x86_64 only supports signed 32 bits constants directly }
  921. if (size in [OS_S64,OS_64]) and
  922. ((a<low(longint)) or (a>high(longint))) then
  923. begin
  924. tmpreg:=getintregister(list,size);
  925. a_load_const_reg(list,size,a,tmpreg);
  926. a_op_reg_reg_reg(list,op,size,tmpreg,src,dst);
  927. exit;
  928. end;
  929. {$endif x86_64}
  930. check_register_size(size,src);
  931. check_register_size(size,dst);
  932. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  933. begin
  934. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  935. exit;
  936. end;
  937. { if we get here, we have to do a 32 bit calculation, guaranteed }
  938. case op of
  939. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  940. OP_SAR:
  941. { can't do anything special for these }
  942. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  943. OP_IMUL:
  944. begin
  945. if not(cs_check_overflow in aktlocalswitches) and
  946. ispowerof2(int64(a),power) then
  947. { can be done with a shift }
  948. begin
  949. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  950. exit;
  951. end;
  952. list.concat(taicpu.op_const_reg_reg(A_IMUL,tcgsize2opsize[size],a,src,dst));
  953. end;
  954. OP_ADD, OP_SUB:
  955. if (a = 0) then
  956. a_load_reg_reg(list,size,size,src,dst)
  957. else
  958. begin
  959. reference_reset(tmpref);
  960. tmpref.base := src;
  961. tmpref.offset := longint(a);
  962. if op = OP_SUB then
  963. tmpref.offset := -tmpref.offset;
  964. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  965. end
  966. else internalerror(200112302);
  967. end;
  968. end;
  969. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;size: tcgsize; src1, src2, dst: tregister);
  970. var
  971. tmpref: treference;
  972. begin
  973. check_register_size(size,src1);
  974. check_register_size(size,src2);
  975. check_register_size(size,dst);
  976. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  977. begin
  978. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  979. exit;
  980. end;
  981. { if we get here, we have to do a 32 bit calculation, guaranteed }
  982. Case Op of
  983. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  984. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  985. { can't do anything special for these }
  986. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  987. OP_IMUL:
  988. list.concat(taicpu.op_reg_reg_reg(A_IMUL,tcgsize2opsize[size],src1,src2,dst));
  989. OP_ADD:
  990. begin
  991. reference_reset(tmpref);
  992. tmpref.base := src1;
  993. tmpref.index := src2;
  994. tmpref.scalefactor := 1;
  995. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  996. end
  997. else internalerror(200112303);
  998. end;
  999. end;
  1000. {*************** compare instructructions ****************}
  1001. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  1002. l : tasmlabel);
  1003. {$ifdef x86_64}
  1004. var
  1005. tmpreg : tregister;
  1006. {$endif x86_64}
  1007. begin
  1008. {$ifdef x86_64}
  1009. { x86_64 only supports signed 32 bits constants directly }
  1010. if (size in [OS_S64,OS_64]) and
  1011. ((a<low(longint)) or (a>high(longint))) then
  1012. begin
  1013. tmpreg:=getintregister(list,size);
  1014. a_load_const_reg(list,size,a,tmpreg);
  1015. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1016. exit;
  1017. end;
  1018. {$endif x86_64}
  1019. if (a = 0) then
  1020. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1021. else
  1022. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1023. a_jmp_cond(list,cmp_op,l);
  1024. end;
  1025. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  1026. l : tasmlabel);
  1027. {$ifdef x86_64}
  1028. var
  1029. tmpreg : tregister;
  1030. {$endif x86_64}
  1031. begin
  1032. {$ifdef x86_64}
  1033. { x86_64 only supports signed 32 bits constants directly }
  1034. if (size in [OS_S64,OS_64]) and
  1035. ((a<low(longint)) or (a>high(longint))) then
  1036. begin
  1037. tmpreg:=getintregister(list,size);
  1038. a_load_const_reg(list,size,a,tmpreg);
  1039. a_cmp_reg_ref_label(list,size,cmp_op,tmpreg,ref,l);
  1040. exit;
  1041. end;
  1042. {$endif x86_64}
  1043. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  1044. a_jmp_cond(list,cmp_op,l);
  1045. end;
  1046. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  1047. reg1,reg2 : tregister;l : tasmlabel);
  1048. begin
  1049. check_register_size(size,reg1);
  1050. check_register_size(size,reg2);
  1051. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1052. a_jmp_cond(list,cmp_op,l);
  1053. end;
  1054. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1055. begin
  1056. check_register_size(size,reg);
  1057. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],ref,reg));
  1058. a_jmp_cond(list,cmp_op,l);
  1059. end;
  1060. procedure tcgx86.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister;const ref: treference; l : tasmlabel);
  1061. begin
  1062. check_register_size(size,reg);
  1063. list.concat(taicpu.op_reg_ref(A_CMP,TCgSize2OpSize[size],reg,ref));
  1064. a_jmp_cond(list,cmp_op,l);
  1065. end;
  1066. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1067. var
  1068. ai : taicpu;
  1069. begin
  1070. if cond=OC_None then
  1071. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1072. else
  1073. begin
  1074. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1075. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1076. end;
  1077. ai.is_jmp:=true;
  1078. list.concat(ai);
  1079. end;
  1080. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  1081. var
  1082. ai : taicpu;
  1083. begin
  1084. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1085. ai.SetCondition(flags_to_cond(f));
  1086. ai.is_jmp := true;
  1087. list.concat(ai);
  1088. end;
  1089. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  1090. var
  1091. ai : taicpu;
  1092. hreg : tregister;
  1093. begin
  1094. hreg:=makeregsize(list,reg,OS_8);
  1095. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1096. ai.setcondition(flags_to_cond(f));
  1097. list.concat(ai);
  1098. if (reg<>hreg) then
  1099. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1100. end;
  1101. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  1102. var
  1103. ai : taicpu;
  1104. begin
  1105. if not(size in [OS_8,OS_S8]) then
  1106. a_load_const_ref(list,size,0,ref);
  1107. ai:=Taicpu.op_ref(A_SETcc,S_B,ref);
  1108. ai.setcondition(flags_to_cond(f));
  1109. list.concat(ai);
  1110. end;
  1111. { ************* concatcopy ************ }
  1112. procedure Tcgx86.g_concatcopy(list:Taasmoutput;const source,dest:Treference;len:aint;loadref:boolean);
  1113. const
  1114. {$ifdef cpu64bit}
  1115. REGCX=NR_RCX;
  1116. REGSI=NR_RSI;
  1117. REGDI=NR_RDI;
  1118. {$else cpu64bit}
  1119. REGCX=NR_ECX;
  1120. REGSI=NR_ESI;
  1121. REGDI=NR_EDI;
  1122. {$endif cpu64bit}
  1123. type copymode=(copy_move,copy_mmx,copy_string);
  1124. var srcref,dstref:Treference;
  1125. r,r0,r1,r2,r3:Tregister;
  1126. helpsize:aint;
  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 (len>helpsize) then
  1140. cm:=copy_string;
  1141. if (cs_littlesize in aktglobalswitches) and
  1142. not((len<=16) and (cm=copy_mmx)) then
  1143. cm:=copy_string;
  1144. if loadref then
  1145. cm:=copy_string;
  1146. case cm of
  1147. copy_move:
  1148. begin
  1149. dstref:=dest;
  1150. srcref:=source;
  1151. copysize:=sizeof(aint);
  1152. cgsize:=int_cgsize(copysize);
  1153. while len<>0 do
  1154. begin
  1155. if len<2 then
  1156. begin
  1157. copysize:=1;
  1158. cgsize:=OS_8;
  1159. end
  1160. else if len<4 then
  1161. begin
  1162. copysize:=2;
  1163. cgsize:=OS_16;
  1164. end
  1165. else if len<8 then
  1166. begin
  1167. copysize:=4;
  1168. cgsize:=OS_32;
  1169. end;
  1170. dec(len,copysize);
  1171. r:=getintregister(list,cgsize);
  1172. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1173. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1174. inc(srcref.offset,copysize);
  1175. inc(dstref.offset,copysize);
  1176. end;
  1177. end;
  1178. copy_mmx:
  1179. begin
  1180. dstref:=dest;
  1181. srcref:=source;
  1182. r0:=getmmxregister(list);
  1183. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r0,nil);
  1184. if len>=16 then
  1185. begin
  1186. inc(srcref.offset,8);
  1187. r1:=getmmxregister(list);
  1188. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r1,nil);
  1189. end;
  1190. if len>=24 then
  1191. begin
  1192. inc(srcref.offset,8);
  1193. r2:=getmmxregister(list);
  1194. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r2,nil);
  1195. end;
  1196. if len>=32 then
  1197. begin
  1198. inc(srcref.offset,8);
  1199. r3:=getmmxregister(list);
  1200. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r3,nil);
  1201. end;
  1202. a_loadmm_reg_ref(list,OS_M64,OS_M64,r0,dstref,nil);
  1203. if len>=16 then
  1204. begin
  1205. inc(dstref.offset,8);
  1206. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1207. end;
  1208. if len>=24 then
  1209. begin
  1210. inc(dstref.offset,8);
  1211. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  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. end;
  1218. end
  1219. else {copy_string, should be a good fallback in case of unhandled}
  1220. begin
  1221. getcpuregister(list,REGDI);
  1222. a_loadaddr_ref_reg(list,dest,REGDI);
  1223. getcpuregister(list,REGSI);
  1224. if loadref then
  1225. a_load_ref_reg(list,OS_ADDR,OS_ADDR,source,REGSI)
  1226. else
  1227. a_loadaddr_ref_reg(list,source,REGSI);
  1228. getcpuregister(list,REGCX);
  1229. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1230. if cs_littlesize in aktglobalswitches then
  1231. begin
  1232. a_load_const_reg(list,OS_INT,len,REGCX);
  1233. list.concat(Taicpu.op_none(A_REP,S_NO));
  1234. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1235. end
  1236. else
  1237. begin
  1238. helpsize:=len div sizeof(aint);
  1239. len:=len mod sizeof(aint);
  1240. if helpsize>1 then
  1241. begin
  1242. a_load_const_reg(list,OS_INT,helpsize,REGCX);
  1243. list.concat(Taicpu.op_none(A_REP,S_NO));
  1244. end;
  1245. if helpsize>0 then
  1246. begin
  1247. {$ifdef cpu64bit}
  1248. if sizeof(aint)=8 then
  1249. list.concat(Taicpu.op_none(A_MOVSQ,S_NO))
  1250. else
  1251. {$endif cpu64bit}
  1252. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1253. end;
  1254. if len>=4 then
  1255. begin
  1256. dec(len,4);
  1257. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1258. end;
  1259. if len>=2 then
  1260. begin
  1261. dec(len,2);
  1262. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1263. end;
  1264. if len=1 then
  1265. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1266. end;
  1267. ungetcpuregister(list,REGCX);
  1268. ungetcpuregister(list,REGSI);
  1269. ungetcpuregister(list,REGDI);
  1270. end;
  1271. end;
  1272. end;
  1273. {****************************************************************************
  1274. Entry/Exit Code Helpers
  1275. ****************************************************************************}
  1276. procedure tcgx86.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1277. begin
  1278. { Nothing to release }
  1279. end;
  1280. procedure tcgx86.g_profilecode(list : taasmoutput);
  1281. var
  1282. pl : tasmlabel;
  1283. mcountprefix : String[4];
  1284. begin
  1285. case target_info.system of
  1286. {$ifndef NOTARGETWIN32}
  1287. system_i386_win32,
  1288. {$endif}
  1289. system_i386_freebsd,
  1290. system_i386_netbsd,
  1291. // system_i386_openbsd,
  1292. system_i386_wdosx :
  1293. begin
  1294. Case target_info.system Of
  1295. system_i386_freebsd : mcountprefix:='.';
  1296. system_i386_netbsd : mcountprefix:='__';
  1297. // system_i386_openbsd : mcountprefix:='.';
  1298. else
  1299. mcountPrefix:='';
  1300. end;
  1301. objectlibrary.getaddrlabel(pl);
  1302. new_section(list,sec_data,lower(current_procinfo.procdef.mangledname),sizeof(aint));
  1303. list.concat(Tai_label.Create(pl));
  1304. list.concat(Tai_const.Create_32bit(0));
  1305. new_section(list,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1306. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1307. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1308. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1309. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1310. end;
  1311. system_i386_linux:
  1312. a_call_name(list,target_info.Cprefix+'mcount');
  1313. system_i386_go32v2,system_i386_watcom:
  1314. begin
  1315. a_call_name(list,'MCOUNT');
  1316. end;
  1317. end;
  1318. end;
  1319. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1320. {$ifdef i386}
  1321. {$ifndef NOTARGETWIN32}
  1322. var
  1323. href : treference;
  1324. i : integer;
  1325. again : tasmlabel;
  1326. {$endif NOTARGETWIN32}
  1327. {$endif i386}
  1328. begin
  1329. if localsize>0 then
  1330. begin
  1331. {$ifdef i386}
  1332. {$ifndef NOTARGETWIN32}
  1333. { windows guards only a few pages for stack growing, }
  1334. { so we have to access every page first }
  1335. if (target_info.system=system_i386_win32) and
  1336. (localsize>=winstackpagesize) then
  1337. begin
  1338. if localsize div winstackpagesize<=5 then
  1339. begin
  1340. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1341. for i:=1 to localsize div winstackpagesize do
  1342. begin
  1343. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1344. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1345. end;
  1346. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1347. end
  1348. else
  1349. begin
  1350. objectlibrary.getlabel(again);
  1351. getcpuregister(list,NR_EDI);
  1352. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1353. a_label(list,again);
  1354. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1355. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1356. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1357. a_jmp_cond(list,OC_NE,again);
  1358. ungetcpuregister(list,NR_EDI);
  1359. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1360. end
  1361. end
  1362. else
  1363. {$endif NOTARGETWIN32}
  1364. {$endif i386}
  1365. list.concat(Taicpu.Op_const_reg(A_SUB,tcgsize2opsize[OS_ADDR],localsize,NR_STACK_POINTER_REG));
  1366. end;
  1367. end;
  1368. procedure tcgx86.g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);
  1369. begin
  1370. {$ifdef i386}
  1371. { interrupt support for i386 }
  1372. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1373. begin
  1374. { .... also the segment registers }
  1375. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1376. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1377. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1378. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1379. { save the registers of an interrupt procedure }
  1380. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1381. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1382. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1383. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1384. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1385. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1386. end;
  1387. {$endif i386}
  1388. { save old framepointer }
  1389. if not nostackframe then
  1390. begin
  1391. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1392. CGmessage(cg_d_stackframe_omited)
  1393. else
  1394. begin
  1395. list.concat(tai_regalloc.alloc(NR_FRAME_POINTER_REG,nil));
  1396. include(rg[R_INTREGISTER].preserved_by_proc,RS_FRAME_POINTER_REG);
  1397. list.concat(Taicpu.op_reg(A_PUSH,tcgsize2opsize[OS_ADDR],NR_FRAME_POINTER_REG));
  1398. { Return address and FP are both on stack }
  1399. dwarfcfi.cfa_def_cfa_offset(list,2*sizeof(aint));
  1400. dwarfcfi.cfa_offset(list,NR_FRAME_POINTER_REG,-(2*sizeof(aint)));
  1401. list.concat(Taicpu.op_reg_reg(A_MOV,tcgsize2opsize[OS_ADDR],NR_STACK_POINTER_REG,NR_FRAME_POINTER_REG));
  1402. dwarfcfi.cfa_def_cfa_register(list,NR_FRAME_POINTER_REG);
  1403. end;
  1404. { allocate stackframe space }
  1405. if localsize<>0 then
  1406. begin
  1407. cg.g_stackpointer_alloc(list,localsize);
  1408. end;
  1409. end;
  1410. { allocate PIC register }
  1411. if cs_create_pic in aktmoduleswitches then
  1412. begin
  1413. a_call_name(list,'FPC_GETEIPINEBX');
  1414. 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));
  1415. list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG,nil));
  1416. end;
  1417. end;
  1418. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1419. var
  1420. href : treference;
  1421. size : longint;
  1422. r : integer;
  1423. begin
  1424. { Get temp }
  1425. size:=0;
  1426. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1427. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1428. inc(size,sizeof(aint));
  1429. if size>0 then
  1430. begin
  1431. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1432. { Copy registers to temp }
  1433. href:=current_procinfo.save_regs_ref;
  1434. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1435. begin
  1436. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1437. begin
  1438. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1439. inc(href.offset,sizeof(aint));
  1440. end;
  1441. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1442. end;
  1443. end;
  1444. end;
  1445. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1446. var
  1447. href : treference;
  1448. r : integer;
  1449. begin
  1450. { Copy registers from temp }
  1451. href:=current_procinfo.save_regs_ref;
  1452. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1453. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1454. begin
  1455. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE));
  1456. inc(href.offset,sizeof(aint));
  1457. end;
  1458. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1459. end;
  1460. { produces if necessary overflowcode }
  1461. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1462. var
  1463. hl : tasmlabel;
  1464. ai : taicpu;
  1465. cond : TAsmCond;
  1466. begin
  1467. if not(cs_check_overflow in aktlocalswitches) then
  1468. exit;
  1469. objectlibrary.getlabel(hl);
  1470. if not ((def.deftype=pointerdef) or
  1471. ((def.deftype=orddef) and
  1472. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1473. bool8bit,bool16bit,bool32bit]))) then
  1474. cond:=C_NO
  1475. else
  1476. cond:=C_NB;
  1477. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1478. ai.SetCondition(cond);
  1479. ai.is_jmp:=true;
  1480. list.concat(ai);
  1481. a_call_name(list,'FPC_OVERFLOW');
  1482. a_label(list,hl);
  1483. end;
  1484. end.
  1485. {
  1486. $Log$
  1487. Revision 1.128 2004-10-05 20:41:02 peter
  1488. * more spilling rewrites
  1489. Revision 1.127 2004/10/04 20:46:22 peter
  1490. * spilling code rewritten for x86. It now used the generic
  1491. spilling routines. Special x86 optimization still needs
  1492. to be added.
  1493. * Spilling fixed when both operands needed to be spilled
  1494. * Cleanup of spilling routine, do_spill_readwritten removed
  1495. Revision 1.126 2004/10/03 12:42:22 florian
  1496. * made sqrt, sqr and abs internal for the sparc
  1497. Revision 1.125 2004/09/25 14:23:55 peter
  1498. * ungetregister is now only used for cpuregisters, renamed to
  1499. ungetcpuregister
  1500. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1501. * removed location-release/reference_release
  1502. Revision 1.124 2004/06/20 08:55:32 florian
  1503. * logs truncated
  1504. Revision 1.123 2004/06/16 20:07:11 florian
  1505. * dwarf branch merged
  1506. Revision 1.122 2004/05/22 23:34:28 peter
  1507. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1508. Revision 1.121 2004/04/28 15:19:03 florian
  1509. + syscall directive support for MorphOS added
  1510. Revision 1.120 2004/04/09 14:36:05 peter
  1511. * A_MOVSL renamed to A_MOVSD
  1512. Revision 1.119.2.22 2004/05/28 20:29:50 florian
  1513. * fixed currency trouble on x86-64
  1514. }