nx86inl.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. { first pass override
  25. so that the code generator will actually generate
  26. these nodes.
  27. }
  28. function first_pi: tnode ; override;
  29. function first_arctan_real: tnode; override;
  30. function first_abs_real: tnode; override;
  31. function first_sqr_real: tnode; override;
  32. function first_sqrt_real: tnode; override;
  33. function first_ln_real: tnode; override;
  34. function first_cos_real: tnode; override;
  35. function first_sin_real: tnode; override;
  36. function first_round_real: tnode; override;
  37. function first_trunc_real: tnode; override;
  38. function first_popcnt: tnode; override;
  39. { second pass override to generate these nodes }
  40. procedure second_IncludeExclude;override;
  41. procedure second_pi; override;
  42. procedure second_arctan_real; override;
  43. procedure second_abs_real; override;
  44. procedure second_round_real; override;
  45. procedure second_sqr_real; override;
  46. procedure second_sqrt_real; override;
  47. procedure second_ln_real; override;
  48. procedure second_cos_real; override;
  49. procedure second_sin_real; override;
  50. procedure second_trunc_real; override;
  51. procedure second_prefetch;override;
  52. {$ifndef i8086}
  53. procedure second_abs_long;override;
  54. {$endif not i8086}
  55. procedure second_popcnt;override;
  56. private
  57. procedure load_fpu_location(lnode: tnode);
  58. end;
  59. implementation
  60. uses
  61. systems,
  62. globtype,globals,
  63. cutils,verbose,
  64. symconst,
  65. defutil,
  66. aasmbase,aasmtai,aasmdata,aasmcpu,
  67. symtype,symdef,
  68. cgbase,pass_2,
  69. cpuinfo,cpubase,paramgr,
  70. nbas,ncon,ncal,ncnv,nld,ncgutil,
  71. tgobj,
  72. cga,cgutils,cgx86,cgobj,hlcgobj;
  73. {*****************************************************************************
  74. TX86INLINENODE
  75. *****************************************************************************}
  76. function tx86inlinenode.first_pi : tnode;
  77. begin
  78. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  79. begin
  80. expectloc:=LOC_FPUREGISTER;
  81. first_pi := nil;
  82. end
  83. else
  84. result:=inherited;
  85. end;
  86. function tx86inlinenode.first_arctan_real : tnode;
  87. begin
  88. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  89. begin
  90. expectloc:=LOC_FPUREGISTER;
  91. first_arctan_real := nil;
  92. end
  93. else
  94. result:=inherited;
  95. end;
  96. function tx86inlinenode.first_abs_real : tnode;
  97. begin
  98. if use_vectorfpu(resultdef) then
  99. expectloc:=LOC_MMREGISTER
  100. else
  101. expectloc:=LOC_FPUREGISTER;
  102. first_abs_real := nil;
  103. end;
  104. function tx86inlinenode.first_sqr_real : tnode;
  105. begin
  106. if use_vectorfpu(resultdef) then
  107. expectloc:=LOC_MMREGISTER
  108. else
  109. expectloc:=LOC_FPUREGISTER;
  110. first_sqr_real := nil;
  111. end;
  112. function tx86inlinenode.first_sqrt_real : tnode;
  113. begin
  114. if use_vectorfpu(resultdef) then
  115. expectloc:=LOC_MMREGISTER
  116. else
  117. expectloc:=LOC_FPUREGISTER;
  118. first_sqrt_real := nil;
  119. end;
  120. function tx86inlinenode.first_ln_real : tnode;
  121. begin
  122. if (tfloatdef(pbestrealtype^).floattype=s80real) then
  123. begin
  124. expectloc:=LOC_FPUREGISTER;
  125. first_ln_real := nil;
  126. end
  127. else
  128. result:=inherited;
  129. end;
  130. function tx86inlinenode.first_cos_real : tnode;
  131. begin
  132. {$ifdef i8086}
  133. { FCOS is 387+ }
  134. if current_settings.cputype < cpu_386 then
  135. begin
  136. result := inherited;
  137. exit;
  138. end;
  139. {$endif i8086}
  140. expectloc:=LOC_FPUREGISTER;
  141. first_cos_real := nil;
  142. end;
  143. function tx86inlinenode.first_sin_real : tnode;
  144. begin
  145. {$ifdef i8086}
  146. { FSIN is 387+ }
  147. if current_settings.cputype < cpu_386 then
  148. begin
  149. result := inherited;
  150. exit;
  151. end;
  152. {$endif i8086}
  153. expectloc:=LOC_FPUREGISTER;
  154. first_sin_real := nil;
  155. end;
  156. function tx86inlinenode.first_round_real : tnode;
  157. begin
  158. {$ifdef x86_64}
  159. if use_vectorfpu(left.resultdef) then
  160. expectloc:=LOC_REGISTER
  161. else
  162. {$endif x86_64}
  163. expectloc:=LOC_REFERENCE;
  164. result:=nil;
  165. end;
  166. function tx86inlinenode.first_trunc_real: tnode;
  167. begin
  168. if (cs_opt_size in current_settings.optimizerswitches)
  169. {$ifdef x86_64}
  170. and not(use_vectorfpu(left.resultdef))
  171. {$endif x86_64}
  172. then
  173. result:=inherited
  174. else
  175. begin
  176. {$ifdef x86_64}
  177. if use_vectorfpu(left.resultdef) then
  178. expectloc:=LOC_REGISTER
  179. else
  180. {$endif x86_64}
  181. expectloc:=LOC_REFERENCE;
  182. result:=nil;
  183. end;
  184. end;
  185. function tx86inlinenode.first_popcnt: tnode;
  186. begin
  187. Result:=nil;
  188. if (current_settings.fputype<fpu_sse42)
  189. {$ifdef i386}
  190. or is_64bit(left.resultdef)
  191. {$endif i386}
  192. then
  193. Result:=inherited first_popcnt
  194. else
  195. expectloc:=LOC_REGISTER;
  196. end;
  197. procedure tx86inlinenode.second_Pi;
  198. begin
  199. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  200. emit_none(A_FLDPI,S_NO);
  201. tcgx86(cg).inc_fpu_stack;
  202. location.register:=NR_FPU_RESULT_REG;
  203. end;
  204. { load the FPU into the an fpu register }
  205. procedure tx86inlinenode.load_fpu_location(lnode: tnode);
  206. begin
  207. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  208. location.register:=NR_FPU_RESULT_REG;
  209. secondpass(lnode);
  210. case lnode.location.loc of
  211. LOC_FPUREGISTER:
  212. ;
  213. LOC_CFPUREGISTER:
  214. begin
  215. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,lnode.location.size,
  216. lnode.location.size,lnode.location.register,location.register);
  217. end;
  218. LOC_REFERENCE,LOC_CREFERENCE:
  219. begin
  220. cg.a_loadfpu_ref_reg(current_asmdata.CurrAsmList,
  221. lnode.location.size,lnode.location.size,
  222. lnode.location.reference,location.register);
  223. end;
  224. LOC_MMREGISTER,LOC_CMMREGISTER:
  225. begin
  226. location:=lnode.location;
  227. location_force_fpureg(current_asmdata.CurrAsmList,location,false);
  228. end;
  229. else
  230. internalerror(309991);
  231. end;
  232. end;
  233. procedure tx86inlinenode.second_arctan_real;
  234. begin
  235. load_fpu_location(left);
  236. emit_none(A_FLD1,S_NO);
  237. emit_none(A_FPATAN,S_NO);
  238. end;
  239. procedure tx86inlinenode.second_abs_real;
  240. var
  241. href : treference;
  242. begin
  243. if use_vectorfpu(resultdef) then
  244. begin
  245. secondpass(left);
  246. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,false);
  247. location:=left.location;
  248. case tfloatdef(resultdef).floattype of
  249. s32real:
  250. reference_reset_symbol(href,current_asmdata.RefAsmSymbol('FPC_ABSMASK_SINGLE'),0,4);
  251. s64real:
  252. reference_reset_symbol(href,current_asmdata.RefAsmSymbol('FPC_ABSMASK_DOUBLE'),0,4);
  253. else
  254. internalerror(200506081);
  255. end;
  256. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList, href);
  257. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_ANDPS,S_XMM,href,location.register))
  258. end
  259. else
  260. begin
  261. load_fpu_location(left);
  262. emit_none(A_FABS,S_NO);
  263. end;
  264. end;
  265. procedure tx86inlinenode.second_round_real;
  266. begin
  267. {$ifdef x86_64}
  268. if use_vectorfpu(left.resultdef) then
  269. begin
  270. secondpass(left);
  271. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,false);
  272. location_reset(location,LOC_REGISTER,OS_S64);
  273. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  274. if UseAVX then
  275. case left.location.size of
  276. OS_F32:
  277. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSS2SI,S_Q,left.location.register,location.register));
  278. OS_F64:
  279. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTSD2SI,S_Q,left.location.register,location.register));
  280. else
  281. internalerror(2007031402);
  282. end
  283. else
  284. case left.location.size of
  285. OS_F32:
  286. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSS2SI,S_Q,left.location.register,location.register));
  287. OS_F64:
  288. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTSD2SI,S_Q,left.location.register,location.register));
  289. else
  290. internalerror(2007031402);
  291. end;
  292. end
  293. else
  294. {$endif x86_64}
  295. begin
  296. load_fpu_location(left);
  297. location_reset_ref(location,LOC_REFERENCE,OS_S64,0);
  298. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  299. emit_ref(A_FISTP,S_IQ,location.reference);
  300. tcgx86(cg).dec_fpu_stack;
  301. emit_none(A_FWAIT,S_NO);
  302. end;
  303. end;
  304. procedure tx86inlinenode.second_trunc_real;
  305. var
  306. oldcw,newcw : treference;
  307. begin
  308. {$ifdef x86_64}
  309. if use_vectorfpu(left.resultdef) and
  310. not((left.location.loc=LOC_FPUREGISTER) and (current_settings.fputype>=fpu_sse3)) then
  311. begin
  312. secondpass(left);
  313. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,false);
  314. location_reset(location,LOC_REGISTER,OS_S64);
  315. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_S64);
  316. if UseAVX then
  317. case left.location.size of
  318. OS_F32:
  319. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSS2SI,S_Q,left.location.register,location.register));
  320. OS_F64:
  321. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VCVTTSD2SI,S_Q,left.location.register,location.register));
  322. else
  323. internalerror(2007031401);
  324. end
  325. else
  326. case left.location.size of
  327. OS_F32:
  328. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSS2SI,S_Q,left.location.register,location.register));
  329. OS_F64:
  330. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CVTTSD2SI,S_Q,left.location.register,location.register));
  331. else
  332. internalerror(2007031401);
  333. end;
  334. end
  335. else
  336. {$endif x86_64}
  337. begin
  338. if (current_settings.fputype>=fpu_sse3) then
  339. begin
  340. load_fpu_location(left);
  341. location_reset_ref(location,LOC_REFERENCE,OS_S64,0);
  342. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  343. emit_ref(A_FISTTP,S_IQ,location.reference);
  344. tcgx86(cg).dec_fpu_stack;
  345. end
  346. else
  347. begin
  348. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,oldcw);
  349. tg.GetTemp(current_asmdata.CurrAsmList,2,2,tt_normal,newcw);
  350. emit_ref(A_FNSTCW,S_NO,newcw);
  351. emit_ref(A_FNSTCW,S_NO,oldcw);
  352. emit_const_ref(A_OR,S_W,$0f00,newcw);
  353. load_fpu_location(left);
  354. emit_ref(A_FLDCW,S_NO,newcw);
  355. location_reset_ref(location,LOC_REFERENCE,OS_S64,0);
  356. tg.GetTemp(current_asmdata.CurrAsmList,resultdef.size,resultdef.alignment,tt_normal,location.reference);
  357. emit_ref(A_FISTP,S_IQ,location.reference);
  358. tcgx86(cg).dec_fpu_stack;
  359. emit_ref(A_FLDCW,S_NO,oldcw);
  360. emit_none(A_FWAIT,S_NO);
  361. tg.UnGetTemp(current_asmdata.CurrAsmList,oldcw);
  362. tg.UnGetTemp(current_asmdata.CurrAsmList,newcw);
  363. end;
  364. end;
  365. end;
  366. procedure tx86inlinenode.second_sqr_real;
  367. begin
  368. if use_vectorfpu(resultdef) then
  369. begin
  370. secondpass(left);
  371. location_reset(location,LOC_MMREGISTER,left.location.size);
  372. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  373. if UseAVX then
  374. begin
  375. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  376. cg.a_opmm_reg_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,left.location.register,left.location.register,location.register,mms_movescalar);
  377. end
  378. else
  379. begin
  380. if left.location.loc in [LOC_CFPUREGISTER,LOC_FPUREGISTER] then
  381. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  382. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar);
  383. cg.a_opmm_reg_reg(current_asmdata.CurrAsmList,OP_MUL,left.location.size,location.register,location.register,mms_movescalar);
  384. end;
  385. end
  386. else
  387. begin
  388. load_fpu_location(left);
  389. emit_reg_reg(A_FMUL,S_NO,NR_ST0,NR_ST0);
  390. end;
  391. end;
  392. procedure tx86inlinenode.second_sqrt_real;
  393. begin
  394. if use_vectorfpu(resultdef) then
  395. begin
  396. secondpass(left);
  397. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  398. location_reset(location,LOC_MMREGISTER,left.location.size);
  399. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  400. if UseAVX then
  401. case tfloatdef(resultdef).floattype of
  402. s32real:
  403. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSS,S_XMM,left.location.register,location.register,location.register));
  404. s64real:
  405. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_VSQRTSD,S_XMM,left.location.register,location.register,location.register));
  406. else
  407. internalerror(200510031);
  408. end
  409. else
  410. case tfloatdef(resultdef).floattype of
  411. s32real:
  412. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSS,S_XMM,left.location.register,location.register));
  413. s64real:
  414. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRTSD,S_XMM,left.location.register,location.register));
  415. else
  416. internalerror(200510031);
  417. end;
  418. end
  419. else
  420. begin
  421. load_fpu_location(left);
  422. emit_none(A_FSQRT,S_NO);
  423. end;
  424. end;
  425. procedure tx86inlinenode.second_ln_real;
  426. begin
  427. load_fpu_location(left);
  428. emit_none(A_FLDLN2,S_NO);
  429. emit_none(A_FXCH,S_NO);
  430. emit_none(A_FYL2X,S_NO);
  431. end;
  432. procedure tx86inlinenode.second_cos_real;
  433. begin
  434. {$ifdef i8086}
  435. { FCOS is 387+ }
  436. if current_settings.cputype < cpu_386 then
  437. begin
  438. inherited;
  439. exit;
  440. end;
  441. {$endif i8086}
  442. load_fpu_location(left);
  443. emit_none(A_FCOS,S_NO);
  444. end;
  445. procedure tx86inlinenode.second_sin_real;
  446. begin
  447. {$ifdef i8086}
  448. { FSIN is 387+ }
  449. if current_settings.cputype < cpu_386 then
  450. begin
  451. inherited;
  452. exit;
  453. end;
  454. {$endif i8086}
  455. load_fpu_location(left);
  456. emit_none(A_FSIN,S_NO)
  457. end;
  458. procedure tx86inlinenode.second_prefetch;
  459. var
  460. ref : treference;
  461. r : tregister;
  462. begin
  463. {$if defined(i386) or defined(i8086)}
  464. if current_settings.cputype>=cpu_Pentium3 then
  465. {$endif i386 or i8086}
  466. begin
  467. secondpass(left);
  468. case left.location.loc of
  469. LOC_CREFERENCE,
  470. LOC_REFERENCE:
  471. begin
  472. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  473. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  474. reference_reset_base(ref,r,0,left.location.reference.alignment);
  475. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PREFETCHNTA,S_NO,ref));
  476. end;
  477. else
  478. internalerror(200402021);
  479. end;
  480. end;
  481. end;
  482. {$ifndef i8086}
  483. procedure tx86inlinenode.second_abs_long;
  484. var
  485. hregister : tregister;
  486. opsize : tcgsize;
  487. hp : taicpu;
  488. begin
  489. {$ifdef i386}
  490. if current_settings.cputype<cpu_Pentium2 then
  491. begin
  492. opsize:=def_cgsize(left.resultdef);
  493. secondpass(left);
  494. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  495. location:=left.location;
  496. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  497. emit_reg_reg(A_MOV,S_L,left.location.register,location.register);
  498. emit_const_reg(A_SAR,tcgsize2opsize[opsize],31,left.location.register);
  499. emit_reg_reg(A_XOR,S_L,left.location.register,location.register);
  500. emit_reg_reg(A_SUB,S_L,left.location.register,location.register);
  501. end
  502. else
  503. {$endif i386}
  504. begin
  505. opsize:=def_cgsize(left.resultdef);
  506. secondpass(left);
  507. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  508. hregister:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  509. location:=left.location;
  510. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  511. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,hregister);
  512. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.register,location.register);
  513. emit_reg(A_NEG,tcgsize2opsize[opsize],hregister);
  514. hp:=taicpu.op_reg_reg(A_CMOVcc,tcgsize2opsize[opsize],hregister,location.register);
  515. hp.condition:=C_NS;
  516. current_asmdata.CurrAsmList.concat(hp);
  517. end;
  518. end;
  519. {$endif not i8086}
  520. {*****************************************************************************
  521. INCLUDE/EXCLUDE GENERIC HANDLING
  522. *****************************************************************************}
  523. procedure tx86inlinenode.second_IncludeExclude;
  524. var
  525. hregister,
  526. hregister2: tregister;
  527. setbase : aint;
  528. bitsperop,l : longint;
  529. cgop : topcg;
  530. asmop : tasmop;
  531. opdef : tdef;
  532. opsize,
  533. orgsize: tcgsize;
  534. begin
  535. {$ifdef i8086}
  536. { BTS and BTR are 386+ }
  537. if current_settings.cputype < cpu_386 then
  538. begin
  539. inherited;
  540. exit;
  541. end;
  542. {$endif i8086}
  543. if is_smallset(tcallparanode(left).resultdef) then
  544. begin
  545. opdef:=tcallparanode(left).resultdef;
  546. opsize:=int_cgsize(opdef.size)
  547. end
  548. else
  549. begin
  550. opdef:=u32inttype;
  551. opsize:=OS_32;
  552. end;
  553. bitsperop:=(8*tcgsize2size[opsize]);
  554. secondpass(tcallparanode(left).left);
  555. secondpass(tcallparanode(tcallparanode(left).right).left);
  556. setbase:=tsetdef(tcallparanode(left).left.resultdef).setbase;
  557. if tcallparanode(tcallparanode(left).right).left.location.loc=LOC_CONSTANT then
  558. begin
  559. { calculate bit position }
  560. l:=1 shl ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) mod bitsperop);
  561. { determine operator }
  562. if inlinenumber=in_include_x_y then
  563. cgop:=OP_OR
  564. else
  565. begin
  566. cgop:=OP_AND;
  567. l:=not(l);
  568. end;
  569. case tcallparanode(left).left.location.loc of
  570. LOC_REFERENCE :
  571. begin
  572. inc(tcallparanode(left).left.location.reference.offset,
  573. ((tcallparanode(tcallparanode(left).right).left.location.value-setbase) div bitsperop)*tcgsize2size[opsize]);
  574. cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
  575. end;
  576. LOC_CREGISTER :
  577. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.location.size,l,tcallparanode(left).left.location.register);
  578. else
  579. internalerror(200405022);
  580. end;
  581. end
  582. else
  583. begin
  584. orgsize:=opsize;
  585. if opsize in [OS_8,OS_S8] then
  586. begin
  587. opdef:=u32inttype;
  588. opsize:=OS_32;
  589. end;
  590. { determine asm operator }
  591. if inlinenumber=in_include_x_y then
  592. asmop:=A_BTS
  593. else
  594. asmop:=A_BTR;
  595. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,opdef,true);
  596. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,setbase);
  597. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  598. if (tcallparanode(left).left.location.loc=LOC_REFERENCE) then
  599. emit_reg_ref(asmop,tcgsize2opsize[opsize],hregister,tcallparanode(left).left.location.reference)
  600. else
  601. begin
  602. { second argument can't be an 8 bit register either }
  603. hregister2:=tcallparanode(left).left.location.register;
  604. if (orgsize in [OS_8,OS_S8]) then
  605. hregister2:=cg.makeregsize(current_asmdata.CurrAsmList,hregister2,opsize);
  606. emit_reg_reg(asmop,tcgsize2opsize[opsize],hregister,hregister2);
  607. end;
  608. end;
  609. end;
  610. procedure tx86inlinenode.second_popcnt;
  611. var
  612. opsize: tcgsize;
  613. begin
  614. secondpass(left);
  615. opsize:=tcgsize2unsigned[left.location.size];
  616. { no 8 Bit popcont }
  617. if opsize=OS_8 then
  618. opsize:=OS_16;
  619. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE]) or
  620. (left.location.size<>opsize) then
  621. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  622. location_reset(location,LOC_REGISTER,opsize);
  623. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  624. if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  625. emit_reg_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.register,location.register)
  626. else
  627. emit_ref_reg(A_POPCNT,TCGSize2OpSize[opsize],left.location.reference,location.register);
  628. end;
  629. end.