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,fmodule,
  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. function needs_indirect:boolean; inline;
  500. begin
  501. result:=(tf_supports_packages in target_info.flags) and
  502. (target_info.system in systems_indirect_var_imports);
  503. end;
  504. var
  505. href : treference;
  506. sym : tasmsymbol;
  507. begin
  508. if use_vectorfpu(resultdef) then
  509. begin
  510. secondpass(left);
  511. if left.location.loc<>LOC_MMREGISTER then
  512. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,UseAVX);
  513. if UseAVX then
  514. begin
  515. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  516. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  517. end
  518. else
  519. location:=left.location;
  520. case tfloatdef(resultdef).floattype of
  521. s32real:
  522. begin
  523. sym:=current_asmdata.RefAsmSymbol(target_info.cprefix+'FPC_ABSMASK_SINGLE',AT_DATA,needs_indirect);
  524. reference_reset_symbol(href,sym,0,4,[]);
  525. current_module.add_extern_asmsym(sym);
  526. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList, href);
  527. if UseAVX then
  528. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg_reg(
  529. A_VANDPS,S_XMM,href,left.location.register,location.register))
  530. else
  531. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_ANDPS,S_XMM,href,location.register));
  532. end;
  533. s64real:
  534. begin
  535. sym:=current_asmdata.RefAsmSymbol(target_info.cprefix+'FPC_ABSMASK_DOUBLE',AT_DATA,needs_indirect);
  536. reference_reset_symbol(href,sym,0,4,[]);
  537. current_module.add_extern_asmsym(sym);
  538. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList, href);
  539. if UseAVX then
  540. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg_reg(
  541. A_VANDPD,S_XMM,href,left.location.register,location.register))
  542. else
  543. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_ANDPD,S_XMM,href,location.register))
  544. end;
  545. else
  546. internalerror(200506081);
  547. end;
  548. end
  549. else
  550. begin
  551. load_fpu_location(left);
  552. emit_none(A_FABS,S_NO);
  553. end;
  554. end;
  555. procedure tx86inlinenode.second_round_real;
  556. begin
  557. {$ifdef x86_64}
  558. if use_vectorfpu(left.resultdef) then
  559. begin
  560. secondpass(left);
  561. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  562. location_reset(location,LOC_REGISTER,OS_S64);
  563. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  564. if UseAVX then
  565. case left.location.size of
  566. OS_F32:
  567. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSS2SI,S_NO,left.location.register,location.register));
  568. OS_F64:
  569. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSD2SI,S_NO,left.location.register,location.register));
  570. else
  571. internalerror(2007031402);
  572. end
  573. else
  574. case left.location.size of
  575. OS_F32:
  576. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSS2SI,S_NO,left.location.register,location.register));
  577. OS_F64:
  578. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSD2SI,S_NO,left.location.register,location.register));
  579. else
  580. internalerror(2007031402);
  581. end;
  582. end
  583. else
  584. {$endif x86_64}
  585. begin
  586. load_fpu_location(left);
  587. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  588. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  589. emit_ref(A_FISTP,S_IQ,location.reference);
  590. tcgx86(cg).dec_fpu_stack;
  591. emit_none(A_FWAIT,S_NO);
  592. end;
  593. end;
  594. procedure tx86inlinenode.second_trunc_real;
  595. var
  596. oldcw,newcw : treference;
  597. begin
  598. {$ifdef x86_64}
  599. if use_vectorfpu(left.resultdef) and
  600. not((left.location.loc=LOC_FPUREGISTER) and (current_settings.fputype>=fpu_sse3)) then
  601. begin
  602. secondpass(left);
  603. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  604. location_reset(location,LOC_REGISTER,OS_S64);
  605. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  606. if UseAVX then
  607. case left.location.size of
  608. OS_F32:
  609. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSS2SI,S_NO,left.location.register,location.register));
  610. OS_F64:
  611. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSD2SI,S_NO,left.location.register,location.register));
  612. else
  613. internalerror(2007031401);
  614. end
  615. else
  616. case left.location.size of
  617. OS_F32:
  618. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSS2SI,S_NO,left.location.register,location.register));
  619. OS_F64:
  620. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSD2SI,S_NO,left.location.register,location.register));
  621. else
  622. internalerror(2007031401);
  623. end;
  624. end
  625. else
  626. {$endif x86_64}
  627. begin
  628. if (current_settings.fputype>=fpu_sse3) then
  629. begin
  630. load_fpu_location(left);
  631. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  632. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  633. emit_ref(A_FISTTP,S_IQ,location.reference);
  634. tcgx86(cg).dec_fpu_stack;
  635. end
  636. else
  637. begin
  638. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,oldcw);
  639. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,newcw);
  640. {$ifdef i8086}
  641. if current_settings.cputype<=cpu_286 then
  642. begin
  643. emit_ref(A_FSTCW,S_NO,newcw);
  644. emit_ref(A_FSTCW,S_NO,oldcw);
  645. emit_none(A_FWAIT,S_NO);
  646. end
  647. else
  648. {$endif i8086}
  649. begin
  650. emit_ref(A_FNSTCW,S_NO,newcw);
  651. emit_ref(A_FNSTCW,S_NO,oldcw);
  652. end;
  653. emit_const_ref(A_OR,S_W,$0f00,newcw);
  654. load_fpu_location(left);
  655. emit_ref(A_FLDCW,S_NO,newcw);
  656. location_reset_ref(location,LOC_REFERENCE,OS_S64,0,[]);
  657. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  658. emit_ref(A_FISTP,S_IQ,location.reference);
  659. tcgx86(cg).dec_fpu_stack;
  660. emit_ref(A_FLDCW,S_NO,oldcw);
  661. emit_none(A_FWAIT,S_NO);
  662. tg.UnGetTemp(current_asmdata.CurrAsmList,oldcw);
  663. tg.UnGetTemp(current_asmdata.CurrAsmList,newcw);
  664. end;
  665. end;
  666. end;
  667. procedure tx86inlinenode.second_sqr_real;
  668. begin
  669. if use_vectorfpu(resultdef) then
  670. begin
  671. secondpass(left);
  672. location_reset(location,LOC_MMREGISTER,left.location.size);
  673. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  674. if UseAVX then
  675. begin
  676. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  677. cg.a_opmm_reg_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,left.location.register,left.location.register,location.register,mms_movescalar);
  678. end
  679. else
  680. begin
  681. if left.location.loc in [LOC_CFPUREGISTER,LOC_FPUREGISTER] then
  682. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  683. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar);
  684. cg.a_opmm_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,location.register,location.register,mms_movescalar);
  685. end;
  686. end
  687. else
  688. begin
  689. load_fpu_location(left);
  690. emit_reg_reg(A_FMUL,S_NO,NR_ST0,NR_ST0);
  691. end;
  692. end;
  693. procedure tx86inlinenode.second_sqrt_real;
  694. begin
  695. if use_vectorfpu(resultdef) then
  696. begin
  697. secondpass(left);
  698. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  699. location_reset(location,LOC_MMREGISTER,left.location.size);
  700. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  701. if UseAVX then
  702. case tfloatdef(resultdef).floattype of
  703. s32real:
  704. { 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 }
  705. { using left.location.register here as 2nd parameter is crucial to break dependency chains }
  706. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSS,S_NO,left.location.register,left.location.register,location.register));
  707. s64real:
  708. { 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 }
  709. { using left.location.register here as 2nd parameter is crucial to break dependency chains }
  710. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSD,S_NO,left.location.register,left.location.register,location.register));
  711. else
  712. internalerror(200510031);
  713. end
  714. else
  715. case tfloatdef(resultdef).floattype of
  716. s32real:
  717. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSS,S_NO,left.location.register,location.register));
  718. s64real:
  719. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSD,S_NO,left.location.register,location.register));
  720. else
  721. internalerror(200510031);
  722. end;
  723. end
  724. else
  725. begin
  726. load_fpu_location(left);
  727. emit_none(A_FSQRT,S_NO);
  728. end;
  729. end;
  730. procedure tx86inlinenode.second_ln_real;
  731. begin
  732. load_fpu_location(left);
  733. emit_none(A_FLDLN2,S_NO);
  734. emit_none(A_FXCH,S_NO);
  735. emit_none(A_FYL2X,S_NO);
  736. end;
  737. procedure tx86inlinenode.second_cos_real;
  738. begin
  739. {$ifdef i8086}
  740. { FCOS is 387+ }
  741. if current_settings.cputype < cpu_386 then
  742. begin
  743. inherited;
  744. exit;
  745. end;
  746. {$endif i8086}
  747. load_fpu_location(left);
  748. emit_none(A_FCOS,S_NO);
  749. end;
  750. procedure tx86inlinenode.second_sin_real;
  751. begin
  752. {$ifdef i8086}
  753. { FSIN is 387+ }
  754. if current_settings.cputype < cpu_386 then
  755. begin
  756. inherited;
  757. exit;
  758. end;
  759. {$endif i8086}
  760. load_fpu_location(left);
  761. emit_none(A_FSIN,S_NO)
  762. end;
  763. procedure tx86inlinenode.second_prefetch;
  764. var
  765. ref : treference;
  766. r : tregister;
  767. checkpointer_used : boolean;
  768. begin
  769. {$if defined(i386) or defined(i8086)}
  770. if current_settings.cputype>=cpu_Pentium3 then
  771. {$endif i386 or i8086}
  772. begin
  773. { do not call Checkpointer for left node }
  774. checkpointer_used:=(cs_checkpointer in current_settings.localswitches);
  775. if checkpointer_used then
  776. node_change_local_switch(left,cs_checkpointer,false);
  777. secondpass(left);
  778. if checkpointer_used then
  779. node_change_local_switch(left,cs_checkpointer,false);
  780. case left.location.loc of
  781. LOC_CREFERENCE,
  782. LOC_REFERENCE:
  783. begin
  784. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  785. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  786. reference_reset_base(ref,r,0,left.location.reference.temppos,left.location.reference.alignment,left.location.reference.volatility);
  787. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PREFETCHNTA,S_NO,ref));
  788. end;
  789. else
  790. { nothing to prefetch };
  791. end;
  792. end;
  793. end;
  794. procedure tx86inlinenode.second_abs_long;
  795. var
  796. hregister : tregister;
  797. opsize : tcgsize;
  798. hp : taicpu;
  799. begin
  800. {$if defined(i8086) or defined(i386)}
  801. if not(CPUX86_HAS_CMOV in cpu_capabilities[current_settings.cputype]) then
  802. begin
  803. opsize:=def_cgsize(left.resultdef);
  804. secondpass(left);
  805. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  806. location:=left.location;
  807. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  808. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
  809. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,opsize,tcgsize2size[opsize]*8-1,left.location.register);
  810. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_XOR,opsize,left.location.register,location.register);
  811. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,left.location.register,location.register);
  812. end
  813. else
  814. {$endif i8086 or i386}
  815. begin
  816. opsize:=def_cgsize(left.resultdef);
  817. secondpass(left);
  818. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  819. hregister:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  820. location:=left.location;
  821. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  822. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,hregister);
  823. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
  824. emit_reg(A_NEG,tcgsize2opsize[opsize],hregister);
  825. hp:=taicpu.op_reg_reg(A_CMOVcc,tcgsize2opsize[opsize],hregister,location.register);
  826. hp.condition:=C_NS;
  827. current_asmdata.CurrAsmList.concat(hp);
  828. end;
  829. end;
  830. {*****************************************************************************
  831. INCLUDE/EXCLUDE GENERIC HANDLING
  832. *****************************************************************************}
  833. procedure tx86inlinenode.second_IncludeExclude;
  834. var
  835. hregister,
  836. hregister2: tregister;
  837. setbase : aint;
  838. bitsperop,l : longint;
  839. cgop : topcg;
  840. asmop : tasmop;
  841. opdef : tdef;
  842. opsize,
  843. orgsize: tcgsize;
  844. begin
  845. {$ifdef i8086}
  846. { BTS and BTR are 386+ }
  847. if current_settings.cputype < cpu_386 then
  848. begin
  849. inherited;
  850. exit;
  851. end;
  852. {$endif i8086}
  853. if is_smallset(tcallparanode(left).resultdef) then
  854. begin
  855. opdef:=tcallparanode(left).resultdef;
  856. opsize:=int_cgsize(opdef.size)
  857. end
  858. else
  859. begin
  860. opdef:=u32inttype;
  861. opsize:=OS_32;
  862. end;
  863. bitsperop:=(8*tcgsize2size[opsize]);
  864. secondpass(tcallparanode(left).left);
  865. secondpass(tcallparanode(tcallparanode(left).right).left);
  866. setbase:=tsetdef(tcallparanode(left).left.resultdef).setbase;
  867. if tcallparanode(tcallparanode(left).right).left.location.loc=LOC_CONSTANT then
  868. begin
  869. { calculate bit position }
  870. l:=1 shl ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) mod bitsperop);
  871. { determine operator }
  872. if inlinenumber=in_include_x_y then
  873. cgop:=OP_OR
  874. else
  875. begin
  876. cgop:=OP_AND;
  877. l:=not(l);
  878. end;
  879. case tcallparanode(left).left.location.loc of
  880. LOC_REFERENCE :
  881. begin
  882. inc(tcallparanode(left).left.location.reference.offset,
  883. ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) div bitsperop)*tcgsize2size[opsize]);
  884. cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
  885. end;
  886. LOC_CREGISTER :
  887. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.location.size,l,tcallparanode(left).left.location.register);
  888. else
  889. internalerror(200405022);
  890. end;
  891. end
  892. else
  893. begin
  894. orgsize:=opsize;
  895. if opsize in [OS_8,OS_S8] then
  896. begin
  897. opdef:=u32inttype;
  898. opsize:=OS_32;
  899. end;
  900. { determine asm operator }
  901. if inlinenumber=in_include_x_y then
  902. asmop:=A_BTS
  903. else
  904. asmop:=A_BTR;
  905. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,opdef,true);
  906. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.resultdef,tcallparanode(tcallparanode(left).right).left.location,setbase);
  907. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  908. if (tcallparanode(left).left.location.loc=LOC_REFERENCE) then
  909. emit_reg_ref(asmop,tcgsize2opsize[opsize],hregister,tcallparanode(left).left.location.reference)
  910. else
  911. begin
  912. { second argument can't be an 8 bit register either }
  913. hregister2:=tcallparanode(left).left.location.register;
  914. if (orgsize in [OS_8,OS_S8]) then
  915. hregister2:=cg.makeregsize(current_asmdata.CurrAsmList,hregister2,opsize);
  916. emit_reg_reg(asmop,tcgsize2opsize[opsize],hregister,hregister2);
  917. end;
  918. end;
  919. end;
  920. procedure tx86inlinenode.second_popcnt;
  921. var
  922. opsize: tcgsize;
  923. begin
  924. secondpass(left);
  925. opsize:=tcgsize2unsigned[left.location.size];
  926. { no 8 Bit popcont }
  927. if opsize=OS_8 then
  928. opsize:=OS_16;
  929. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) or
  930. (left.location.size<>opsize) then
  931. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  932. location_reset(location,LOC_REGISTER,opsize);
  933. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  934. if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  935. emit_reg_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.register,location.register)
  936. else
  937. emit_ref_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.reference,location.register);
  938. end;
  939. procedure tx86inlinenode.second_fma;
  940. const
  941. op : array[false..true,false..true,s32real..s64real,0..3] of TAsmOp =
  942. (
  943. { positive product }
  944. (
  945. { positive third operand }
  946. ((A_VFMADD231SS,A_VFMADD231SS,A_VFMADD231SS,A_VFMADD213SS),
  947. (A_VFMADD231SD,A_VFMADD231SD,A_VFMADD231SD,A_VFMADD213SD)
  948. ),
  949. { negative third operand }
  950. ((A_VFMSUB231SS,A_VFMSUB231SS,A_VFMSUB231SS,A_VFMSUB213SS),
  951. (A_VFMSUB231SD,A_VFMSUB231SD,A_VFMSUB231SD,A_VFMSUB213SD)
  952. )
  953. ),
  954. { negative product }
  955. (
  956. { positive third operand }
  957. ((A_VFNMADD231SS,A_VFNMADD231SS,A_VFNMADD231SS,A_VFNMADD213SS),
  958. (A_VFNMADD231SD,A_VFNMADD231SD,A_VFNMADD231SD,A_VFNMADD213SD)
  959. ),
  960. { negative third operand }
  961. ((A_VFNMSUB231SS,A_VFNMSUB231SS,A_VFNMSUB231SS,A_VFNMSUB213SS),
  962. (A_VFNMSUB231SD,A_VFNMSUB231SD,A_VFNMSUB231SD,A_VFNMSUB213SD)
  963. )
  964. )
  965. );
  966. var
  967. paraarray : array[1..3] of tnode;
  968. memop,
  969. i : integer;
  970. negop3,
  971. negproduct,
  972. gotmem : boolean;
  973. begin
  974. {$ifndef i8086}
  975. if (cpu_capabilities[current_settings.cputype]*[CPUX86_HAS_FMA,CPUX86_HAS_FMA4])<>[] then
  976. begin
  977. negop3:=false;
  978. negproduct:=false;
  979. paraarray[1]:=tcallparanode(tcallparanode(tcallparanode(parameters).nextpara).nextpara).paravalue;
  980. paraarray[2]:=tcallparanode(tcallparanode(parameters).nextpara).paravalue;
  981. paraarray[3]:=tcallparanode(parameters).paravalue;
  982. { check if a neg. node can be removed
  983. this is possible because changing the sign of
  984. a floating point number does not affect its absolute
  985. value in any way
  986. }
  987. if paraarray[1].nodetype=unaryminusn then
  988. begin
  989. paraarray[1]:=tunarynode(paraarray[1]).left;
  990. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  991. only no code is generated for it }
  992. negproduct:=not(negproduct);
  993. end;
  994. if paraarray[2].nodetype=unaryminusn then
  995. begin
  996. paraarray[2]:=tunarynode(paraarray[2]).left;
  997. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  998. only no code is generated for it }
  999. negproduct:=not(negproduct);
  1000. end;
  1001. if paraarray[3].nodetype=unaryminusn then
  1002. begin
  1003. paraarray[3]:=tunarynode(paraarray[3]).left;
  1004. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  1005. only no code is generated for it }
  1006. negop3:=true;
  1007. end;
  1008. for i:=1 to 3 do
  1009. secondpass(paraarray[i]);
  1010. { only one memory operand is allowed }
  1011. gotmem:=false;
  1012. memop:=0;
  1013. for i:=1 to 3 do
  1014. begin
  1015. if not(paraarray[i].location.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  1016. begin
  1017. if (paraarray[i].location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and not(gotmem) then
  1018. begin
  1019. memop:=i;
  1020. gotmem:=true;
  1021. end
  1022. else
  1023. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,paraarray[i].location,paraarray[i].resultdef,true);
  1024. end;
  1025. end;
  1026. location_reset(location,LOC_MMREGISTER,paraarray[1].location.size);
  1027. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1028. if gotmem then
  1029. begin
  1030. case memop of
  1031. 1:
  1032. begin
  1033. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1034. paraarray[3].location.register,location.register,mms_movescalar);
  1035. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1036. paraarray[1].location.reference,paraarray[2].location.register,location.register);
  1037. end;
  1038. 2:
  1039. begin
  1040. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1041. paraarray[3].location.register,location.register,mms_movescalar);
  1042. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1043. paraarray[2].location.reference,paraarray[1].location.register,location.register);
  1044. end;
  1045. 3:
  1046. begin
  1047. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[1].resultdef,resultdef,
  1048. paraarray[1].location.register,location.register,mms_movescalar);
  1049. emit_ref_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,memop],S_NO,
  1050. paraarray[3].location.reference,paraarray[2].location.register,location.register);
  1051. end
  1052. else
  1053. internalerror(2014041301);
  1054. end;
  1055. end
  1056. else
  1057. begin
  1058. { try to use the location which is already in a temp. mm register as destination,
  1059. so the compiler might be able to re-use the register }
  1060. if paraarray[1].location.loc=LOC_MMREGISTER then
  1061. begin
  1062. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[1].resultdef,resultdef,
  1063. paraarray[1].location.register,location.register,mms_movescalar);
  1064. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,3],S_NO,
  1065. paraarray[3].location.register,paraarray[2].location.register,location.register);
  1066. end
  1067. else if paraarray[2].location.loc=LOC_MMREGISTER then
  1068. begin
  1069. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[2].resultdef,resultdef,
  1070. paraarray[2].location.register,location.register,mms_movescalar);
  1071. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,3],S_NO,
  1072. paraarray[3].location.register,paraarray[1].location.register,location.register);
  1073. end
  1074. else
  1075. begin
  1076. hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  1077. paraarray[3].location.register,location.register,mms_movescalar);
  1078. emit_reg_reg_reg(op[negproduct,negop3,tfloatdef(resultdef).floattype,0],S_NO,
  1079. paraarray[1].location.register,paraarray[2].location.register,location.register);
  1080. end;
  1081. end;
  1082. end
  1083. else
  1084. {$endif i8086}
  1085. internalerror(2014032301);
  1086. end;
  1087. procedure tx86inlinenode.second_frac_real;
  1088. var
  1089. extrareg : TRegister;
  1090. begin
  1091. if use_vectorfpu(resultdef) then
  1092. begin
  1093. secondpass(left);
  1094. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  1095. location_reset(location,LOC_MMREGISTER,left.location.size);
  1096. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1097. if UseAVX then
  1098. case tfloatdef(resultdef).floattype of
  1099. s32real:
  1100. begin
  1101. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1102. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSS,S_NO,3,left.location.register,left.location.register,location.register));
  1103. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSUBSS,S_NO,location.register,left.location.register,location.register));
  1104. end;
  1105. s64real:
  1106. begin
  1107. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1108. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSD,S_NO,3,left.location.register,left.location.register,location.register));
  1109. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSUBSD,S_NO,location.register,left.location.register,location.register));
  1110. end;
  1111. else
  1112. internalerror(2017052102);
  1113. end
  1114. else
  1115. begin
  1116. extrareg:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1117. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar);
  1118. case tfloatdef(resultdef).floattype of
  1119. s32real:
  1120. begin
  1121. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSS,S_NO,3,left.location.register,extrareg));
  1122. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SUBSS,S_NO,extrareg,location.register));
  1123. end;
  1124. s64real:
  1125. begin
  1126. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSD,S_NO,3,left.location.register,extrareg));
  1127. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SUBSD,S_NO,extrareg,location.register));
  1128. end;
  1129. else
  1130. internalerror(2017052103);
  1131. end;
  1132. end;
  1133. end
  1134. else
  1135. internalerror(2017052101);
  1136. end;
  1137. procedure tx86inlinenode.second_int_real;
  1138. begin
  1139. if use_vectorfpu(resultdef) then
  1140. begin
  1141. secondpass(left);
  1142. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  1143. location_reset(location,LOC_MMREGISTER,left.location.size);
  1144. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1145. if UseAVX then
  1146. case tfloatdef(resultdef).floattype of
  1147. s32real:
  1148. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1149. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSS,S_NO,3,left.location.register,left.location.register,location.register));
  1150. s64real:
  1151. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1152. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSD,S_NO,3,left.location.register,left.location.register,location.register));
  1153. else
  1154. internalerror(2017052105);
  1155. end
  1156. else
  1157. begin
  1158. case tfloatdef(resultdef).floattype of
  1159. s32real:
  1160. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSS,S_NO,3,left.location.register,location.register));
  1161. s64real:
  1162. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSD,S_NO,3,left.location.register,location.register));
  1163. else
  1164. internalerror(2017052106);
  1165. end;
  1166. end;
  1167. end
  1168. else
  1169. internalerror(2017052107);
  1170. end;
  1171. end.