nx86inl.pas 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  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,left.location.size);
  1093. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1094. if UseAVX then
  1095. case tfloatdef(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(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. end
  1131. else
  1132. internalerror(2017052101);
  1133. end;
  1134. procedure tx86inlinenode.second_int_real;
  1135. var
  1136. extrareg : TRegister;
  1137. begin
  1138. if use_vectorfpu(resultdef) then
  1139. begin
  1140. secondpass(left);
  1141. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  1142. location_reset(location,LOC_MMREGISTER,left.location.size);
  1143. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  1144. if UseAVX then
  1145. case tfloatdef(resultdef).floattype of
  1146. s32real:
  1147. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1148. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSS,S_NO,3,left.location.register,left.location.register,location.register));
  1149. s64real:
  1150. { using left.location.register here as 3rd parameter is crucial to break dependency chains }
  1151. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg_reg(A_VROUNDSD,S_NO,3,left.location.register,left.location.register,location.register));
  1152. else
  1153. internalerror(2017052105);
  1154. end
  1155. else
  1156. begin
  1157. case tfloatdef(resultdef).floattype of
  1158. s32real:
  1159. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSS,S_NO,3,left.location.register,location.register));
  1160. s64real:
  1161. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg_reg(A_ROUNDSD,S_NO,3,left.location.register,location.register));
  1162. else
  1163. internalerror(2017052106);
  1164. end;
  1165. end;
  1166. end
  1167. else
  1168. internalerror(2017052107);
  1169. end;
  1170. end.