nx86inl.pas 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate x86 inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nx86inl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl;
  22. type
  23. tx86inlinenode = class(tcginlinenode)
  24. protected
  25. procedure maybe_remove_round_trunc_typeconv; virtual;
  26. public
  27. function pass_typecheck_cpu:tnode;override;
  28. { first pass override
  29. so that the code generator will actually generate
  30. these nodes.
  31. }
  32. function first_cpu: tnode;override;
  33. function first_pi: tnode ; override;
  34. function first_arctan_real: tnode; override;
  35. function first_abs_real: tnode; override;
  36. function first_sqr_real: tnode; override;
  37. function first_sqrt_real: tnode; override;
  38. function first_ln_real: tnode; override;
  39. function first_cos_real: tnode; override;
  40. function first_sin_real: tnode; override;
  41. function first_round_real: tnode; override;
  42. function first_trunc_real: tnode; override;
  43. function first_popcnt: tnode; override;
  44. function first_fma: tnode; override;
  45. function first_frac_real : tnode; override;
  46. function first_int_real : tnode; override;
  47. function simplify(forinline : boolean) : tnode; override;
  48. { second pass override to generate these nodes }
  49. procedure pass_generate_code_cpu;override;
  50. procedure second_IncludeExclude;override;
  51. procedure second_pi; override;
  52. procedure second_arctan_real; override;
  53. procedure second_abs_real; override;
  54. procedure second_round_real; override;
  55. procedure second_sqr_real; override;
  56. procedure second_sqrt_real; override;
  57. procedure second_ln_real; override;
  58. procedure second_cos_real; override;
  59. procedure second_sin_real; override;
  60. procedure second_trunc_real; override;
  61. procedure second_prefetch;override;
  62. procedure second_abs_long;override;
  63. procedure second_popcnt;override;
  64. procedure second_fma;override;
  65. procedure second_frac_real;override;
  66. procedure second_int_real;override;
  67. private
  68. procedure load_fpu_location(lnode: tnode);
  69. end;
  70. implementation
  71. uses
  72. systems,
  73. globtype,globals,
  74. verbose,compinnr,
  75. defutil,
  76. aasmbase,aasmdata,aasmcpu,
  77. symconst,symtype,symdef,symcpu,
  78. ncnv,
  79. htypechk,
  80. cgbase,pass_1,pass_2,
  81. cpuinfo,cpubase,nutils,
  82. ncal,ncgutil,nld,
  83. tgobj,
  84. cga,cgutils,cgx86,cgobj,hlcgobj;
  85. {*****************************************************************************
  86. TX86INLINENODE
  87. *****************************************************************************}
  88. procedure tx86inlinenode.maybe_remove_round_trunc_typeconv;
  89. begin
  90. { only makes a difference for x86_64 }
  91. end;
  92. function tx86inlinenode.pass_typecheck_cpu: tnode;
  93. begin
  94. Result:=nil;
  95. case inlinenumber of
  96. in_x86_inportb:
  97. begin
  98. CheckParameters(1);
  99. resultdef:=u8inttype;
  100. end;
  101. in_x86_inportw:
  102. begin
  103. CheckParameters(1);
  104. resultdef:=u16inttype;
  105. end;
  106. in_x86_inportl:
  107. begin
  108. CheckParameters(1);
  109. resultdef:=s32inttype;
  110. end;
  111. in_x86_outportb,
  112. in_x86_outportw,
  113. in_x86_outportl:
  114. begin
  115. CheckParameters(2);
  116. resultdef:=voidtype;
  117. end;
  118. in_x86_cli,
  119. in_x86_sti:
  120. resultdef:=voidtype;
  121. in_x86_get_cs,
  122. in_x86_get_ss,
  123. in_x86_get_ds,
  124. in_x86_get_es,
  125. in_x86_get_fs,
  126. in_x86_get_gs:
  127. {$ifdef i8086}
  128. resultdef:=u16inttype;
  129. {$else i8086}
  130. resultdef:=s32inttype;
  131. {$endif i8086}
  132. else
  133. Result:=inherited pass_typecheck_cpu;
  134. end;
  135. end;
  136. function tx86inlinenode.first_cpu: tnode;
  137. begin
  138. Result:=nil;
  139. case inlinenumber of
  140. in_x86_inportb,
  141. in_x86_inportw,
  142. in_x86_inportl,
  143. in_x86_get_cs,
  144. in_x86_get_ss,
  145. in_x86_get_ds,
  146. in_x86_get_es,
  147. in_x86_get_fs,
  148. in_x86_get_gs:
  149. expectloc:=LOC_REGISTER;
  150. in_x86_outportb,
  151. in_x86_outportw,
  152. in_x86_outportl,
  153. in_x86_cli,
  154. in_x86_sti:
  155. expectloc:=LOC_VOID;
  156. else
  157. Result:=inherited first_cpu;
  158. end;
  159. end;
  160. function tx86inlinenode.first_pi : tnode;
  161. begin
  162. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  163. begin
  164. expectloc:=LOC_FPUREGISTER;
  165. first_pi := nil;
  166. end
  167. else
  168. result:=inherited;
  169. end;
  170. function tx86inlinenode.first_arctan_real : tnode;
  171. begin
  172. {$ifdef i8086}
  173. { FPATAN's range is limited to (0 <= value < 1) on the 8087 and 80287,
  174. so we need to use the RTL helper on these FPUs }
  175. if current_settings.cputype < cpu_386 then
  176. begin
  177. result := inherited;
  178. exit;
  179. end;
  180. {$endif i8086}
  181. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  182. begin
  183. expectloc:=LOC_FPUREGISTER;
  184. first_arctan_real := nil;
  185. end
  186. else
  187. result:=inherited;
  188. end;
  189. function tx86inlinenode.first_abs_real : tnode;
  190. begin
  191. if use_vectorfpu(resultdef) then
  192. expectloc:=LOC_MMREGISTER
  193. else
  194. expectloc:=LOC_FPUREGISTER;
  195. first_abs_real := nil;
  196. end;
  197. function tx86inlinenode.first_sqr_real : tnode;
  198. begin
  199. if use_vectorfpu(resultdef) then
  200. expectloc:=LOC_MMREGISTER
  201. else
  202. expectloc:=LOC_FPUREGISTER;
  203. first_sqr_real := nil;
  204. end;
  205. function tx86inlinenode.first_sqrt_real : tnode;
  206. begin
  207. if use_vectorfpu(resultdef) then
  208. expectloc:=LOC_MMREGISTER
  209. else
  210. expectloc:=LOC_FPUREGISTER;
  211. first_sqrt_real := nil;
  212. end;
  213. function tx86inlinenode.first_ln_real : tnode;
  214. begin
  215. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  216. begin
  217. expectloc:=LOC_FPUREGISTER;
  218. first_ln_real := nil;
  219. end
  220. else
  221. result:=inherited;
  222. end;
  223. function tx86inlinenode.first_cos_real : tnode;
  224. begin
  225. {$ifdef i8086}
  226. { FCOS is 387+ }
  227. if current_settings.cputype < cpu_386 then
  228. begin
  229. result := inherited;
  230. exit;
  231. end;
  232. {$endif i8086}
  233. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  234. begin
  235. expectloc:=LOC_FPUREGISTER;
  236. result:=nil;
  237. end
  238. else
  239. result:=inherited;
  240. end;
  241. function tx86inlinenode.first_sin_real : tnode;
  242. begin
  243. {$ifdef i8086}
  244. { FSIN is 387+ }
  245. if current_settings.cputype < cpu_386 then
  246. begin
  247. result := inherited;
  248. exit;
  249. end;
  250. {$endif i8086}
  251. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  252. begin
  253. expectloc:=LOC_FPUREGISTER;
  254. result:=nil;
  255. end
  256. else
  257. result:=inherited;
  258. end;
  259. function tx86inlinenode.first_round_real : tnode;
  260. begin
  261. maybe_remove_round_trunc_typeconv;
  262. {$ifdef x86_64}
  263. if use_vectorfpu(left.resultdef) then
  264. expectloc:=LOC_REGISTER
  265. else
  266. {$endif x86_64}
  267. expectloc:=LOC_REFERENCE;
  268. result:=nil;
  269. end;
  270. function tx86inlinenode.first_trunc_real: tnode;
  271. begin
  272. maybe_remove_round_trunc_typeconv;
  273. if (cs_opt_size in current_settings.optimizerswitches)
  274. {$ifdef x86_64}
  275. and not(use_vectorfpu(left.resultdef))
  276. {$endif x86_64}
  277. then
  278. result:=inherited
  279. else
  280. begin
  281. {$ifdef x86_64}
  282. if use_vectorfpu(left.resultdef) then
  283. expectloc:=LOC_REGISTER
  284. else
  285. {$endif x86_64}
  286. expectloc:=LOC_REFERENCE;
  287. result:=nil;
  288. end;
  289. end;
  290. function tx86inlinenode.first_popcnt: tnode;
  291. begin
  292. Result:=nil;
  293. {$ifndef i8086}
  294. if (CPUX86_HAS_POPCNT in cpu_capabilities[current_settings.cputype])
  295. {$ifdef i386}
  296. and not is_64bit(left.resultdef)
  297. {$endif i386}
  298. then
  299. expectloc:=LOC_REGISTER
  300. else
  301. {$endif not i8086}
  302. Result:=inherited first_popcnt
  303. end;
  304. function tx86inlinenode.first_fma : tnode;
  305. begin
  306. {$ifndef i8086}
  307. if ((cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[]) and
  308. ((is_double(resultdef)) or (is_single(resultdef))) then
  309. begin
  310. expectloc:=LOC_MMREGISTER;
  311. Result:=nil;
  312. end
  313. else
  314. {$endif i8086}
  315. Result:=inherited first_fma;
  316. end;
  317. function tx86inlinenode.first_frac_real : tnode;
  318. begin
  319. if (current_settings.fputype>=fpu_sse41) and
  320. ((is_double(resultdef)) or (is_single(resultdef))) then
  321. begin
  322. maybe_remove_round_trunc_typeconv;
  323. expectloc:=LOC_MMREGISTER;
  324. Result:=nil;
  325. end
  326. else
  327. Result:=inherited first_frac_real;
  328. end;
  329. function tx86inlinenode.first_int_real : tnode;
  330. begin
  331. if (current_settings.fputype>=fpu_sse41) and
  332. ((is_double(resultdef)) or (is_single(resultdef))) then
  333. begin
  334. Result:=nil;
  335. expectloc:=LOC_MMREGISTER;
  336. end
  337. else
  338. Result:=inherited first_int_real;
  339. end;
  340. function tx86inlinenode.simplify(forinline : boolean) : tnode;
  341. var
  342. temp : tnode;
  343. begin
  344. if (current_settings.fputype>=fpu_sse41) and
  345. (inlinenumber=in_int_real) and (left.nodetype=typeconvn) and
  346. not(nf_explicit in left.flags) and
  347. (ttypeconvnode(left).left.resultdef.typ=floatdef) and
  348. ((is_double(ttypeconvnode(left).left.resultdef)) or (is_single(ttypeconvnode(left).left.resultdef))) then
  349. begin
  350. { get rid of the type conversion }
  351. temp:=ttypeconvnode(left).left;
  352. ttypeconvnode(left).left:=nil;
  353. left.free;
  354. left:=temp;
  355. result:=self.getcopy;
  356. tinlinenode(result).resultdef:=temp.resultdef;
  357. typecheckpass(result);
  358. end
  359. else
  360. Result:=inherited simplify(forinline);
  361. end;
  362. procedure tx86inlinenode.pass_generate_code_cpu;
  363. procedure inport(dreg:TRegister;dsize:topsize;dtype:tdef);
  364. var
  365. portnumber: tnode;
  366. begin
  367. portnumber:=left;
  368. secondpass(portnumber);
  369. if (portnumber.location.loc=LOC_CONSTANT) and
  370. (portnumber.location.value>=0) and
  371. (portnumber.location.value<=255) then
  372. begin
  373. hlcg.getcpuregister(current_asmdata.CurrAsmList,dreg);
  374. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_IN,dsize,portnumber.location.value,dreg));
  375. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  376. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  377. hlcg.ungetcpuregister(current_asmdata.CurrAsmList,dreg);
  378. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,dtype,resultdef,dreg,location.register);
  379. end
  380. else
  381. begin
  382. hlcg.getcpuregister(current_asmdata.CurrAsmList,NR_DX);
  383. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portnumber.resultdef,u16inttype,portnumber.location,NR_DX);
  384. hlcg.getcpuregister(current_asmdata.CurrAsmList,dreg);
  385. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_IN,dsize,NR_DX,dreg));
  386. hlcg.ungetcpuregister(current_asmdata.CurrAsmList,NR_DX);
  387. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  388. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  389. hlcg.ungetcpuregister(current_asmdata.CurrAsmList,dreg);
  390. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,dtype,resultdef,dreg,location.register);
  391. end;
  392. end;
  393. procedure outport(dreg:TRegister;dsize:topsize;dtype:tdef);
  394. var
  395. portnumber, portdata: tnode;
  396. begin
  397. portnumber:=tcallparanode(tcallparanode(left).right).left;
  398. portdata:=tcallparanode(left).left;
  399. secondpass(portdata);
  400. secondpass(portnumber);
  401. hlcg.getcpuregister(current_asmdata.CurrAsmList,dreg);
  402. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portdata.resultdef,dtype,portdata.location,dreg);
  403. if (portnumber.location.loc=LOC_CONSTANT) and
  404. (portnumber.location.value>=0) and
  405. (portnumber.location.value<=255) then
  406. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_OUT,dsize,dreg,portnumber.location.value))
  407. else
  408. begin
  409. hlcg.getcpuregister(current_asmdata.CurrAsmList,NR_DX);
  410. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,portnumber.resultdef,u16inttype,portnumber.location,NR_DX);
  411. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_OUT,dsize,dreg,NR_DX));
  412. hlcg.ungetcpuregister(current_asmdata.CurrAsmList,NR_DX);
  413. end;
  414. hlcg.ungetcpuregister(current_asmdata.CurrAsmList,dreg);
  415. end;
  416. procedure get_segreg(segreg:tregister);
  417. begin
  418. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  419. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  420. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOV,TCGSize2OpSize[def_cgsize(resultdef)],segreg,location.register));
  421. end;
  422. begin
  423. case inlinenumber of
  424. in_x86_inportb:
  425. inport(NR_AL,S_B,u8inttype);
  426. in_x86_inportw:
  427. inport(NR_AX,S_W,u16inttype);
  428. in_x86_inportl:
  429. inport(NR_EAX,S_L,s32inttype);
  430. in_x86_outportb:
  431. outport(NR_AL,S_B,u8inttype);
  432. in_x86_outportw:
  433. outport(NR_AX,S_W,u16inttype);
  434. in_x86_outportl:
  435. outport(NR_EAX,S_L,s32inttype);
  436. in_x86_cli:
  437. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLI));
  438. in_x86_sti:
  439. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_STI));
  440. in_x86_get_cs:
  441. get_segreg(NR_CS);
  442. in_x86_get_ss:
  443. get_segreg(NR_SS);
  444. in_x86_get_ds:
  445. get_segreg(NR_DS);
  446. in_x86_get_es:
  447. get_segreg(NR_ES);
  448. in_x86_get_fs:
  449. get_segreg(NR_FS);
  450. in_x86_get_gs:
  451. get_segreg(NR_GS);
  452. else
  453. inherited pass_generate_code_cpu;
  454. end;
  455. end;
  456. procedure tx86inlinenode.second_pi;
  457. begin
  458. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  459. emit_none(A_FLDPI,S_NO);
  460. tcgx86(cg).inc_fpu_stack;
  461. location.register:=NR_FPU_RESULT_REG;
  462. end;
  463. { load the FPU into the an fpu register }
  464. procedure tx86inlinenode.load_fpu_location(lnode: tnode);
  465. begin
  466. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  467. location.register:=NR_FPU_RESULT_REG;
  468. secondpass(lnode);
  469. case lnode.location.loc of
  470. LOC_FPUREGISTER:
  471. ;
  472. LOC_CFPUREGISTER:
  473. begin
  474. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,lnode.location.size,
  475. lnode.location.size,lnode.location.register,location.register);
  476. end;
  477. LOC_REFERENCE,LOC_CREFERENCE:
  478. begin
  479. cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,
  480. lnode.location.size,lnode.location.size,
  481. lnode.location.reference,location.register);
  482. end;
  483. LOC_MMREGISTER,LOC_CMMREGISTER:
  484. begin
  485. location:=lnode.location;
  486. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,location,resultdef,false);
  487. end;
  488. else
  489. internalerror(309991);
  490. end;
  491. end;
  492. procedure tx86inlinenode.second_arctan_real;
  493. begin
  494. load_fpu_location(left);
  495. emit_none(A_FLD1,S_NO);
  496. emit_none(A_FPATAN,S_NO);
  497. end;
  498. procedure tx86inlinenode.second_abs_real;
  499. var
  500. href : treference;
  501. begin
  502. if use_vectorfpu(resultdef) then
  503. begin
  504. secondpass(left);
  505. if left.location.loc<>LOC_MMREGISTER then
  506. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,UseAVX);
  507. if UseAVX then
  508. begin
  509. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  510. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  511. end
  512. else
  513. location:=left.location;
  514. case tfloatdef(resultdef).floattype of
  515. s32real:
  516. begin
  517. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(target_info.cprefix+'FPC_ABSMASK_SINGLE',AT_DATA),0,4,[]);
  518. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList, href);
  519. if UseAVX then
  520. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg_reg(
  521. A_VANDPS,S_XMM,href,left.location.register,location.register))
  522. else
  523. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_ANDPS,S_XMM,href,location.register));
  524. end;
  525. s64real:
  526. begin
  527. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(target_info.cprefix+'FPC_ABSMASK_DOUBLE',AT_DATA),0,4,[]);
  528. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList, href);
  529. if UseAVX then
  530. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg_reg(
  531. A_VANDPD,S_XMM,href,left.location.register,location.register))
  532. else
  533. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_ANDPD,S_XMM,href,location.register))
  534. end;
  535. else
  536. internalerror(200506081);
  537. end;
  538. end
  539. else
  540. begin
  541. load_fpu_location(left);
  542. emit_none(A_FABS,S_NO);
  543. end;
  544. end;
  545. procedure tx86inlinenode.second_round_real;
  546. begin
  547. {$ifdef x86_64}
  548. if use_vectorfpu(left.resultdef) then
  549. begin
  550. secondpass(left);
  551. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  552. location_reset(location,LOC_REGISTER,OS_S64);
  553. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  554. if UseAVX then
  555. case left.location.size of
  556. OS_F32:
  557. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSS2SI,S_NO,left.location.register,location.register));
  558. OS_F64:
  559. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSD2SI,S_NO,left.location.register,location.register));
  560. else
  561. internalerror(2007031402);
  562. end
  563. else
  564. case left.location.size of
  565. OS_F32:
  566. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSS2SI,S_NO,left.location.register,location.register));
  567. OS_F64:
  568. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSD2SI,S_NO,left.location.register,location.register));
  569. else
  570. internalerror(2007031402);
  571. end;
  572. end
  573. else
  574. {$endif x86_64}
  575. begin
  576. load_fpu_location(left);
  577. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  578. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  579. emit_ref(A_FISTP,S_IQ,location.reference);
  580. tcgx86(cg).dec_fpu_stack;
  581. emit_none(A_FWAIT,S_NO);
  582. end;
  583. end;
  584. procedure tx86inlinenode.second_trunc_real;
  585. var
  586. oldcw,newcw : treference;
  587. begin
  588. {$ifdef x86_64}
  589. if use_vectorfpu(left.resultdef) and
  590. not((left.location.loc=LOC_FPUREGISTER) and (current_settings.fputype>=fpu_sse3)) then
  591. begin
  592. secondpass(left);
  593. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  594. location_reset(location,LOC_REGISTER,OS_S64);
  595. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  596. if UseAVX then
  597. case left.location.size of
  598. OS_F32:
  599. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSS2SI,S_NO,left.location.register,location.register));
  600. OS_F64:
  601. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSD2SI,S_NO,left.location.register,location.register));
  602. else
  603. internalerror(2007031401);
  604. end
  605. else
  606. case left.location.size of
  607. OS_F32:
  608. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSS2SI,S_NO,left.location.register,location.register));
  609. OS_F64:
  610. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSD2SI,S_NO,left.location.register,location.register));
  611. else
  612. internalerror(2007031401);
  613. end;
  614. end
  615. else
  616. {$endif x86_64}
  617. begin
  618. if (current_settings.fputype>=fpu_sse3) then
  619. begin
  620. load_fpu_location(left);
  621. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  622. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  623. emit_ref(A_FISTTP,S_IQ,location.reference);
  624. tcgx86(cg).dec_fpu_stack;
  625. end
  626. else
  627. begin
  628. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,oldcw);
  629. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,newcw);
  630. {$ifdef i8086}
  631. if current_settings.cputype<=cpu_286 then
  632. begin
  633. emit_ref(A_FSTCW,S_NO,newcw);
  634. emit_ref(A_FSTCW,S_NO,oldcw);
  635. emit_none(A_FWAIT,S_NO);
  636. end
  637. else
  638. {$endif i8086}
  639. begin
  640. emit_ref(A_FNSTCW,S_NO,newcw);
  641. emit_ref(A_FNSTCW,S_NO,oldcw);
  642. end;
  643. emit_const_ref(A_OR,S_W,$0f00,newcw);
  644. load_fpu_location(left);
  645. emit_ref(A_FLDCW,S_NO,newcw);
  646. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  647. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  648. emit_ref(A_FISTP,S_IQ,location.reference);
  649. tcgx86(cg).dec_fpu_stack;
  650. emit_ref(A_FLDCW,S_NO,oldcw);
  651. emit_none(A_FWAIT,S_NO);
  652. tg.UnGetTemp(current_asmdata.CurrAsmList,oldcw);
  653. tg.UnGetTemp(current_asmdata.CurrAsmList,newcw);
  654. end;
  655. end;
  656. end;
  657. procedure tx86inlinenode.second_sqr_real;
  658. begin
  659. if use_vectorfpu(resultdef) then
  660. begin
  661. secondpass(left);
  662. location_reset(location,LOC_MMREGISTER,left.location.size);
  663. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  664. if UseAVX then
  665. begin
  666. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  667. cg.a_opmm_reg_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,left.location.register,left.location.register,location.register,mms_movescalar);
  668. end
  669. else
  670. begin
  671. if left.location.loc in [LOC_CFPUREGISTER,LOC_FPUREGISTER] then
  672. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  673. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar);
  674. cg.a_opmm_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,location.register,location.register,mms_movescalar);
  675. end;
  676. end
  677. else
  678. begin
  679. load_fpu_location(left);
  680. emit_reg_reg(A_FMUL,S_NO,NR_ST0,NR_ST0);
  681. end;
  682. end;
  683. procedure tx86inlinenode.second_sqrt_real;
  684. begin
  685. if use_vectorfpu(resultdef) then
  686. begin
  687. secondpass(left);
  688. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  689. location_reset(location,LOC_MMREGISTER,left.location.size);
  690. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  691. if UseAVX then
  692. case tfloatdef(resultdef).floattype of
  693. s32real:
  694. { we use S_NO instead of S_XMM here, regardless of the register size, as the size of the memory location is 32/64 bit }
  695. { using left.location.register here as 2nd parameter is crucial to break dependency chains }
  696. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSS,S_NO,left.location.register,left.location.register,location.register));
  697. s64real:
  698. { we use S_NO instead of S_XMM here, regardless of the register size, as the size of the memory location is 32/64 bit }
  699. { using left.location.register here as 2nd parameter is crucial to break dependency chains }
  700. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSD,S_NO,left.location.register,left.location.register,location.register));
  701. else
  702. internalerror(200510031);
  703. end
  704. else
  705. case tfloatdef(resultdef).floattype of
  706. s32real:
  707. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSS,S_NO,left.location.register,location.register));
  708. s64real:
  709. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSD,S_NO,left.location.register,location.register));
  710. else
  711. internalerror(200510031);
  712. end;
  713. end
  714. else
  715. begin
  716. load_fpu_location(left);
  717. emit_none(A_FSQRT,S_NO);
  718. end;
  719. end;
  720. procedure tx86inlinenode.second_ln_real;
  721. begin
  722. load_fpu_location(left);
  723. emit_none(A_FLDLN2,S_NO);
  724. emit_none(A_FXCH,S_NO);
  725. emit_none(A_FYL2X,S_NO);
  726. end;
  727. procedure tx86inlinenode.second_cos_real;
  728. begin
  729. {$ifdef i8086}
  730. { FCOS is 387+ }
  731. if current_settings.cputype < cpu_386 then
  732. begin
  733. inherited;
  734. exit;
  735. end;
  736. {$endif i8086}
  737. load_fpu_location(left);
  738. emit_none(A_FCOS,S_NO);
  739. end;
  740. procedure tx86inlinenode.second_sin_real;
  741. begin
  742. {$ifdef i8086}
  743. { FSIN is 387+ }
  744. if current_settings.cputype < cpu_386 then
  745. begin
  746. inherited;
  747. exit;
  748. end;
  749. {$endif i8086}
  750. load_fpu_location(left);
  751. emit_none(A_FSIN,S_NO)
  752. end;
  753. procedure tx86inlinenode.second_prefetch;
  754. var
  755. ref : treference;
  756. r : tregister;
  757. checkpointer_used : boolean;
  758. begin
  759. {$if defined(i386) or defined(i8086)}
  760. if current_settings.cputype>=cpu_Pentium3 then
  761. {$endif i386 or i8086}
  762. begin
  763. { do not call Checkpointer for left node }
  764. checkpointer_used:=(cs_checkpointer in current_settings.localswitches);
  765. if checkpointer_used then
  766. node_change_local_switch(left,cs_checkpointer,false);
  767. secondpass(left);
  768. if checkpointer_used then
  769. node_change_local_switch(left,cs_checkpointer,false);
  770. case left.location.loc of
  771. LOC_CREFERENCE,
  772. LOC_REFERENCE:
  773. begin
  774. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  775. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  776. reference_reset_base(ref,r,0,left.location.reference.temppos,left.location.reference.alignment,left.location.reference.volatility);
  777. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PREFETCHNTA,S_NO,ref));
  778. end;
  779. else
  780. { nothing to prefetch };
  781. end;
  782. end;
  783. end;
  784. procedure tx86inlinenode.second_abs_long;
  785. var
  786. hregister : tregister;
  787. opsize : tcgsize;
  788. hp : taicpu;
  789. begin
  790. {$if defined(i8086) or defined(i386)}
  791. if not(CPUX86_HAS_CMOV in cpu_capabilities[current_settings.cputype]) then
  792. begin
  793. opsize:=def_cgsize(left.resultdef);
  794. secondpass(left);
  795. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  796. location:=left.location;
  797. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  798. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
  799. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,opsize,tcgsize2size[opsize]*8-1,left.location.register);
  800. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_XOR,opsize,left.location.register,location.register);
  801. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,left.location.register,location.register);
  802. end
  803. else
  804. {$endif i8086 or i386}
  805. begin
  806. opsize:=def_cgsize(left.resultdef);
  807. secondpass(left);
  808. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  809. hregister:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  810. location:=left.location;
  811. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  812. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,hregister);
  813. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
  814. emit_reg(A_NEG,tcgsize2opsize[opsize],hregister);
  815. hp:=taicpu.op_reg_reg(A_CMOVcc,tcgsize2opsize[opsize],hregister,location.register);
  816. hp.condition:=C_NS;
  817. current_asmdata.CurrAsmList.concat(hp);
  818. end;
  819. end;
  820. {*****************************************************************************
  821. INCLUDE/EXCLUDE GENERIC HANDLING
  822. *****************************************************************************}
  823. procedure tx86inlinenode.second_IncludeExclude;
  824. var
  825. hregister,
  826. hregister2: tregister;
  827. setbase : aint;
  828. bitsperop,l : longint;
  829. cgop : topcg;
  830. asmop : tasmop;
  831. opdef : tdef;
  832. opsize,
  833. orgsize: tcgsize;
  834. begin
  835. {$ifdef i8086}
  836. { BTS and BTR are 386+ }
  837. if current_settings.cputype < cpu_386 then
  838. begin
  839. inherited;
  840. exit;
  841. end;
  842. {$endif i8086}
  843. if is_smallset(tcallparanode(left).resultdef) then
  844. begin
  845. opdef:=tcallparanode(left).resultdef;
  846. opsize:=int_cgsize(opdef.size)
  847. end
  848. else
  849. begin
  850. opdef:=u32inttype;
  851. opsize:=OS_32;
  852. end;
  853. bitsperop:=(8*tcgsize2size[opsize]);
  854. secondpass(tcallparanode(left).left);
  855. secondpass(tcallparanode(tcallparanode(left).right).left);
  856. setbase:=tsetdef(tcallparanode(left).left.resultdef).setbase;
  857. if tcallparanode(tcallparanode(left).right).left.location.loc=LOC_CONSTANT then
  858. begin
  859. { calculate bit position }
  860. l:=1 shl ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) mod bitsperop);
  861. { determine operator }
  862. if inlinenumber=in_include_x_y then
  863. cgop:=OP_OR
  864. else
  865. begin
  866. cgop:=OP_AND;
  867. l:=not(l);
  868. end;
  869. case tcallparanode(left).left.location.loc of
  870. LOC_REFERENCE :
  871. begin
  872. inc(tcallparanode(left).left.location.reference.offset,
  873. ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) div bitsperop)*tcgsize2size[opsize]);
  874. cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
  875. end;
  876. LOC_CREGISTER :
  877. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.location.size,l,tcallparanode(left).left.location.register);
  878. else
  879. internalerror(200405022);
  880. end;
  881. end
  882. else
  883. begin
  884. orgsize:=opsize;
  885. if opsize in [OS_8,OS_S8] then
  886. begin
  887. opdef:=u32inttype;
  888. opsize:=OS_32;
  889. end;
  890. { determine asm operator }
  891. if inlinenumber=in_include_x_y then
  892. asmop:=A_BTS
  893. else
  894. asmop:=A_BTR;
  895. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,opdef,true);
  896. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.resultdef,tcallparanode(tcallparanode(left).right).left.location,setbase);
  897. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  898. if (tcallparanode(left).left.location.loc=LOC_REFERENCE) then
  899. emit_reg_ref(asmop,tcgsize2opsize[opsize],hregister,tcallparanode(left).left.location.reference)
  900. else
  901. begin
  902. { second argument can't be an 8 bit register either }
  903. hregister2:=tcallparanode(left).left.location.register;
  904. if (orgsize in [OS_8,OS_S8]) then
  905. hregister2:=cg.makeregsize(current_asmdata.CurrAsmList,hregister2,opsize);
  906. emit_reg_reg(asmop,tcgsize2opsize[opsize],hregister,hregister2);
  907. end;
  908. end;
  909. end;
  910. procedure tx86inlinenode.second_popcnt;
  911. var
  912. opsize: tcgsize;
  913. begin
  914. secondpass(left);
  915. opsize:=tcgsize2unsigned[left.location.size];
  916. { no 8 Bit popcont }
  917. if opsize=OS_8 then
  918. opsize:=OS_16;
  919. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) or
  920. (left.location.size<>opsize) then
  921. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  922. location_reset(location,LOC_REGISTER,opsize);
  923. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  924. if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  925. emit_reg_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.register,location.register)
  926. else
  927. emit_ref_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.reference,location.register);
  928. if resultdef.size=1 then
  929. begin
  930. location.size:=OS_8;
  931. location.register:=cg.makeregsize(current_asmdata.CurrAsmList,location.register,location.size);
  932. end;
  933. end;
  934. procedure tx86inlinenode.second_fma;
  935. const
  936. op : array[false..true,false..true,s32real..s64real,0..3] of TAsmOp =
  937. (
  938. { positive product }
  939. (
  940. { positive third operand }
  941. ((A_VFMADD231SS,A_VFMADD231SS,A_VFMADD231SS,A_VFMADD213SS),
  942. (A_VFMADD231SD,A_VFMADD231SD,A_VFMADD231SD,A_VFMADD213SD)
  943. ),
  944. { negative third operand }
  945. ((A_VFMSUB231SS,A_VFMSUB231SS,A_VFMSUB231SS,A_VFMSUB213SS),
  946. (A_VFMSUB231SD,A_VFMSUB231SD,A_VFMSUB231SD,A_VFMSUB213SD)
  947. )
  948. ),
  949. { negative product }
  950. (
  951. { positive third operand }
  952. ((A_VFNMADD231SS,A_VFNMADD231SS,A_VFNMADD231SS,A_VFNMADD213SS),
  953. (A_VFNMADD231SD,A_VFNMADD231SD,A_VFNMADD231SD,A_VFNMADD213SD)
  954. ),
  955. { negative third operand }
  956. ((A_VFNMSUB231SS,A_VFNMSUB231SS,A_VFNMSUB231SS,A_VFNMSUB213SS),
  957. (A_VFNMSUB231SD,A_VFNMSUB231SD,A_VFNMSUB231SD,A_VFNMSUB213SD)
  958. )
  959. )
  960. );
  961. var
  962. paraarray : array[1..3] of tnode;
  963. memop,
  964. i : integer;
  965. negop3,
  966. negproduct,
  967. gotmem : boolean;
  968. begin
  969. {$ifndef i8086}
  970. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  971. begin
  972. negop3:=false;
  973. negproduct:=false;
  974. paraarray[1]:=tcallparanode(tcallparanode(tcallparanode(parameters).nextpara).nextpara).paravalue;
  975. paraarray[2]:=tcallparanode(tcallparanode(parameters).nextpara).paravalue;
  976. paraarray[3]:=tcallparanode(parameters).paravalue;
  977. { check if a neg. node can be removed
  978. this is possible because changing the sign of
  979. a floating point number does not affect its absolute
  980. value in any way
  981. }
  982. if paraarray[1].nodetype=unaryminusn then
  983. begin
  984. paraarray[1]:=tunarynode(paraarray[1]).left;
  985. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  986. only no code is generated for it }
  987. negproduct:=not(negproduct);
  988. end;
  989. if paraarray[2].nodetype=unaryminusn then
  990. begin
  991. paraarray[2]:=tunarynode(paraarray[2]).left;
  992. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  993. only no code is generated for it }
  994. negproduct:=not(negproduct);
  995. end;
  996. if paraarray[3].nodetype=unaryminusn then
  997. begin
  998. paraarray[3]:=tunarynode(paraarray[3]).left;
  999. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  1000. only no code is generated for it }
  1001. negop3:=true;
  1002. end;
  1003. for i:=1 to 3 do
  1004. secondpass(paraarray[i]);
  1005. { only one memory operand is allowed }
  1006. gotmem:=false;
  1007. memop:=0;
  1008. { in case parameters come on the FPU stack, we have to pop them in reverse order as we
  1009. called secondpass }
  1010. for i:=3 downto 1 do
  1011. begin
  1012. if not(paraarray[i].location.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  1013. begin
  1014. if (paraarray[i].location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and not(gotmem) then
  1015. begin
  1016. memop:=i;
  1017. gotmem:=true;
  1018. end
  1019. else
  1020. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,paraarray[i].location,paraarray[i].resultdef,true);
  1021. end;
  1022. end;
  1023. location_reset(location,LOC_MMREGISTER,paraarray[1].location.size);
  1024. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1025. if gotmem then
  1026. begin
  1027. case memop of
  1028. 1:
  1029. begin
  1030. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1031. paraarray[3].location.register,location.register,mms_movescalar);
  1032. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1033. paraarray[1].location.reference,paraarray[2].location.register,location.register);
  1034. end;
  1035. 2:
  1036. begin
  1037. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1038. paraarray[3].location.register,location.register,mms_movescalar);
  1039. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1040. paraarray[2].location.reference,paraarray[1].location.register,location.register);
  1041. end;
  1042. 3:
  1043. begin
  1044. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[1].resultdef,resultdef,
  1045. paraarray[1].location.register,location.register,mms_movescalar);
  1046. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1047. paraarray[3].location.reference,paraarray[2].location.register,location.register);
  1048. end
  1049. else
  1050. internalerror(2014041301);
  1051. end;
  1052. end
  1053. else
  1054. begin
  1055. { try to use the location which is already in a temp. mm register as destination,
  1056. so the compiler might be able to re-use the register }
  1057. if paraarray[1].location.loc=LOC_MMREGISTER then
  1058. begin
  1059. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[1].resultdef,resultdef,
  1060. paraarray[1].location.register,location.register,mms_movescalar);
  1061. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,3],S_NO,
  1062. paraarray[3].location.register,paraarray[2].location.register,location.register);
  1063. end
  1064. else if paraarray[2].location.loc=LOC_MMREGISTER then
  1065. begin
  1066. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[2].resultdef,resultdef,
  1067. paraarray[2].location.register,location.register,mms_movescalar);
  1068. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,3],S_NO,
  1069. paraarray[3].location.register,paraarray[1].location.register,location.register);
  1070. end
  1071. else
  1072. begin
  1073. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1074. paraarray[3].location.register,location.register,mms_movescalar);
  1075. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,0],S_NO,
  1076. paraarray[1].location.register,paraarray[2].location.register,location.register);
  1077. end;
  1078. end;
  1079. end
  1080. else
  1081. {$endif i8086}
  1082. internalerror(2014032301);
  1083. end;
  1084. procedure tx86inlinenode.second_frac_real;
  1085. var
  1086. extrareg : TRegister;
  1087. begin
  1088. if use_vectorfpu(resultdef) then
  1089. begin
  1090. secondpass(left);
  1091. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  1092. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  1093. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1094. if UseAVX then
  1095. case tfloatdef(left.resultdef).floattype of
  1096. s32real:
  1097. begin
  1098. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1099. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSS,S_NO,3,left.location.register,left.location.register,location.register));
  1100. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSUBSS,S_NO,location.register,left.location.register,location.register));
  1101. end;
  1102. s64real:
  1103. begin
  1104. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1105. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSD,S_NO,3,left.location.register,left.location.register,location.register));
  1106. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSUBSD,S_NO,location.register,left.location.register,location.register));
  1107. end;
  1108. else
  1109. internalerror(2017052102);
  1110. end
  1111. else
  1112. begin
  1113. extrareg:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1114. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar);
  1115. case tfloatdef(left.resultdef).floattype of
  1116. s32real:
  1117. begin
  1118. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSS,S_NO,3,left.location.register,extrareg));
  1119. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SUBSS,S_NO,extrareg,location.register));
  1120. end;
  1121. s64real:
  1122. begin
  1123. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSD,S_NO,3,left.location.register,extrareg));
  1124. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SUBSD,S_NO,extrareg,location.register));
  1125. end;
  1126. else
  1127. internalerror(2017052103);
  1128. end;
  1129. end;
  1130. if tfloatdef(left.resultdef).floattype<>tfloatdef(resultdef).floattype then
  1131. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,left.resultdef,resultdef,location.register,location.register,mms_movescalar);
  1132. end
  1133. else
  1134. internalerror(2017052101);
  1135. end;
  1136. procedure tx86inlinenode.second_int_real;
  1137. var
  1138. extrareg : TRegister;
  1139. begin
  1140. if use_vectorfpu(resultdef) then
  1141. begin
  1142. secondpass(left);
  1143. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  1144. location_reset(location,LOC_MMREGISTER,left.location.size);
  1145. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1146. if UseAVX then
  1147. case tfloatdef(resultdef).floattype of
  1148. s32real:
  1149. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1150. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSS,S_NO,3,left.location.register,left.location.register,location.register));
  1151. s64real:
  1152. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1153. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSD,S_NO,3,left.location.register,left.location.register,location.register));
  1154. else
  1155. internalerror(2017052105);
  1156. end
  1157. else
  1158. begin
  1159. case tfloatdef(resultdef).floattype of
  1160. s32real:
  1161. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSS,S_NO,3,left.location.register,location.register));
  1162. s64real:
  1163. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSD,S_NO,3,left.location.register,location.register));
  1164. else
  1165. internalerror(2017052106);
  1166. end;
  1167. end;
  1168. end
  1169. else
  1170. internalerror(2017052107);
  1171. end;
  1172. end.