cgx86.pas 59 KB

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