n386add.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Code generation for add nodes on the i386
  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 n386add;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nadd,cpubase,nx86add;
  22. type
  23. ti386addnode = class(tx86addnode)
  24. function use_generic_mul32to64: boolean; override;
  25. function use_generic_mul64bit: boolean; override;
  26. procedure second_addordinal; override;
  27. procedure second_add64bit;override;
  28. procedure second_cmp64bit;override;
  29. procedure second_mul(unsigned: boolean);
  30. procedure second_mul64bit;
  31. protected
  32. procedure set_mul_result_location;
  33. end;
  34. implementation
  35. uses
  36. globtype,systems,
  37. cutils,verbose,globals,
  38. symconst,symdef,paramgr,defutil,
  39. aasmbase,aasmtai,aasmdata,aasmcpu,
  40. cgbase,procinfo,
  41. ncon,nset,cgutils,tgobj,
  42. cga,ncgutil,cgobj,cg64f32,cgx86,
  43. hlcgobj;
  44. {*****************************************************************************
  45. use_generic_mul32to64
  46. *****************************************************************************}
  47. function ti386addnode.use_generic_mul32to64: boolean;
  48. begin
  49. result := False;
  50. end;
  51. function ti386addnode.use_generic_mul64bit: boolean;
  52. begin
  53. result:=(cs_check_overflow in current_settings.localswitches) or
  54. (cs_opt_size in current_settings.optimizerswitches);
  55. end;
  56. { handles all unsigned multiplications, and 32->64 bit signed ones.
  57. 32bit-only signed mul is handled by generic codegen }
  58. procedure ti386addnode.second_addordinal;
  59. var
  60. unsigned: boolean;
  61. begin
  62. unsigned:=not(is_signed(left.resultdef)) or
  63. not(is_signed(right.resultdef));
  64. { use IMUL instead of MUL in case overflow checking is off and we're
  65. doing a 32->32-bit multiplication }
  66. if not (cs_check_overflow in current_settings.localswitches) and
  67. not is_64bit(resultdef) then
  68. unsigned:=false;
  69. if (nodetype=muln) and (unsigned or is_64bit(resultdef)) then
  70. second_mul(unsigned)
  71. else
  72. inherited second_addordinal;
  73. end;
  74. {*****************************************************************************
  75. Add64bit
  76. *****************************************************************************}
  77. procedure ti386addnode.second_add64bit;
  78. var
  79. op : TOpCG;
  80. op1,op2 : TAsmOp;
  81. opsize : TOpSize;
  82. hregister,
  83. hregister2 : tregister;
  84. hl4 : tasmlabel;
  85. mboverflow,
  86. unsigned:boolean;
  87. r:Tregister;
  88. begin
  89. pass_left_right;
  90. op1:=A_NONE;
  91. op2:=A_NONE;
  92. mboverflow:=false;
  93. opsize:=S_L;
  94. unsigned:=((left.resultdef.typ=orddef) and
  95. (torddef(left.resultdef).ordtype=u64bit)) or
  96. ((right.resultdef.typ=orddef) and
  97. (torddef(right.resultdef).ordtype=u64bit));
  98. case nodetype of
  99. addn :
  100. begin
  101. op:=OP_ADD;
  102. mboverflow:=true;
  103. end;
  104. subn :
  105. begin
  106. op:=OP_SUB;
  107. op1:=A_SUB;
  108. op2:=A_SBB;
  109. mboverflow:=true;
  110. end;
  111. xorn:
  112. op:=OP_XOR;
  113. orn:
  114. op:=OP_OR;
  115. andn:
  116. op:=OP_AND;
  117. muln:
  118. begin
  119. second_mul64bit;
  120. exit;
  121. end
  122. else
  123. begin
  124. { everything should be handled in pass_1 (JM) }
  125. internalerror(200109051);
  126. end;
  127. end;
  128. { left and right no register? }
  129. { then one must be demanded }
  130. if (left.location.loc<>LOC_REGISTER) then
  131. begin
  132. if (right.location.loc<>LOC_REGISTER) then
  133. begin
  134. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  135. hregister2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  136. cg64.a_load64_loc_reg(current_asmdata.CurrAsmList,left.location,joinreg64(hregister,hregister2));
  137. location_reset(left.location,LOC_REGISTER,left.location.size);
  138. left.location.register64.reglo:=hregister;
  139. left.location.register64.reghi:=hregister2;
  140. end
  141. else
  142. begin
  143. location_swap(left.location,right.location);
  144. toggleflag(nf_swapped);
  145. end;
  146. end;
  147. { at this point, left.location.loc should be LOC_REGISTER }
  148. if right.location.loc=LOC_REGISTER then
  149. begin
  150. { when swapped another result register }
  151. if (nodetype=subn) and (nf_swapped in flags) then
  152. begin
  153. cg64.a_op64_reg_reg(current_asmdata.CurrAsmList,op,location.size,
  154. left.location.register64,
  155. right.location.register64);
  156. location_swap(left.location,right.location);
  157. toggleflag(nf_swapped);
  158. end
  159. else
  160. begin
  161. cg64.a_op64_reg_reg(current_asmdata.CurrAsmList,op,location.size,
  162. right.location.register64,
  163. left.location.register64);
  164. end;
  165. end
  166. else
  167. begin
  168. { right.location<>LOC_REGISTER }
  169. if (nodetype=subn) and (nf_swapped in flags) then
  170. begin
  171. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  172. cg64.a_load64low_loc_reg(current_asmdata.CurrAsmList,right.location,r);
  173. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  174. emit_reg_reg(op1,opsize,left.location.register64.reglo,r);
  175. emit_reg_reg(A_MOV,opsize,r,left.location.register64.reglo);
  176. cg64.a_load64high_loc_reg(current_asmdata.CurrAsmList,right.location,r);
  177. { the carry flag is still ok }
  178. emit_reg_reg(op2,opsize,left.location.register64.reghi,r);
  179. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  180. emit_reg_reg(A_MOV,opsize,r,left.location.register64.reghi);
  181. end
  182. else
  183. begin
  184. cg64.a_op64_loc_reg(current_asmdata.CurrAsmList,op,location.size,right.location,
  185. left.location.register64);
  186. end;
  187. location_freetemp(current_asmdata.CurrAsmList,right.location);
  188. end;
  189. { only in case of overflow operations }
  190. { produce overflow code }
  191. { we must put it here directly, because sign of operation }
  192. { is in unsigned VAR!! }
  193. if mboverflow then
  194. begin
  195. if cs_check_overflow in current_settings.localswitches then
  196. begin
  197. current_asmdata.getjumplabel(hl4);
  198. if unsigned then
  199. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_AE,hl4)
  200. else
  201. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NO,hl4);
  202. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_OVERFLOW',false);
  203. cg.a_label(current_asmdata.CurrAsmList,hl4);
  204. end;
  205. end;
  206. location_copy(location,left.location);
  207. end;
  208. procedure ti386addnode.second_cmp64bit;
  209. var
  210. truelabel,
  211. falselabel,
  212. hlab : tasmlabel;
  213. href : treference;
  214. unsigned : boolean;
  215. procedure firstjmp64bitcmp;
  216. var
  217. oldnodetype : tnodetype;
  218. begin
  219. {$ifdef OLDREGVARS}
  220. load_all_regvars(current_asmdata.CurrAsmList);
  221. {$endif OLDREGVARS}
  222. { the jump the sequence is a little bit hairy }
  223. case nodetype of
  224. ltn,gtn:
  225. begin
  226. if (hlab<>location.truelabel) then
  227. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  228. { cheat a little bit for the negative test }
  229. toggleflag(nf_swapped);
  230. if (hlab<>location.falselabel) then
  231. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  232. toggleflag(nf_swapped);
  233. end;
  234. lten,gten:
  235. begin
  236. oldnodetype:=nodetype;
  237. if nodetype=lten then
  238. nodetype:=ltn
  239. else
  240. nodetype:=gtn;
  241. if (hlab<>location.truelabel) then
  242. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  243. { cheat for the negative test }
  244. if nodetype=ltn then
  245. nodetype:=gtn
  246. else
  247. nodetype:=ltn;
  248. if (hlab<>location.falselabel) then
  249. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  250. nodetype:=oldnodetype;
  251. end;
  252. equaln:
  253. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  254. unequaln:
  255. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  256. end;
  257. end;
  258. procedure secondjmp64bitcmp;
  259. begin
  260. { the jump the sequence is a little bit hairy }
  261. case nodetype of
  262. ltn,gtn,lten,gten:
  263. begin
  264. { the comparisaion of the low dword have to be }
  265. { always unsigned! }
  266. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),location.truelabel);
  267. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  268. end;
  269. equaln:
  270. begin
  271. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  272. cg.a_jmp_always(current_asmdata.CurrAsmList,location.truelabel);
  273. end;
  274. unequaln:
  275. begin
  276. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  277. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  278. end;
  279. end;
  280. end;
  281. begin
  282. truelabel:=nil;
  283. falselabel:=nil;
  284. pass_left_right;
  285. unsigned:=((left.resultdef.typ=orddef) and
  286. (torddef(left.resultdef).ordtype=u64bit)) or
  287. ((right.resultdef.typ=orddef) and
  288. (torddef(right.resultdef).ordtype=u64bit));
  289. { we have LOC_JUMP as result }
  290. current_asmdata.getjumplabel(truelabel);
  291. current_asmdata.getjumplabel(falselabel);
  292. location_reset_jump(location,truelabel,falselabel);
  293. { Relational compares against constants having low dword=0 can omit the
  294. second compare based on the fact that any unsigned value is >=0 }
  295. hlab:=nil;
  296. if (right.location.loc=LOC_CONSTANT) and
  297. (lo(right.location.value64)=0) then
  298. begin
  299. case getresflags(true) of
  300. F_AE: hlab:=location.truelabel ;
  301. F_B: hlab:=location.falselabel;
  302. end;
  303. end;
  304. if (right.location.loc=LOC_CONSTANT) and
  305. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  306. begin
  307. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
  308. href:=left.location.reference;
  309. inc(href.offset,4);
  310. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  311. emit_const_ref(A_CMP,S_L,aint(hi(right.location.value64)),href);
  312. firstjmp64bitcmp;
  313. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  314. if assigned(hlab) then
  315. cg.a_jmp_always(current_asmdata.CurrAsmList,hlab)
  316. else
  317. begin
  318. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  319. emit_const_ref(A_CMP,S_L,aint(lo(right.location.value64)),left.location.reference);
  320. secondjmp64bitcmp;
  321. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  322. end;
  323. location_freetemp(current_asmdata.CurrAsmList,left.location);
  324. exit;
  325. end;
  326. { left and right no register? }
  327. { then one must be demanded }
  328. if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  329. begin
  330. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  331. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  332. else
  333. begin
  334. location_swap(left.location,right.location);
  335. toggleflag(nf_swapped);
  336. end;
  337. end;
  338. { at this point, left.location.loc should be LOC_[C]REGISTER }
  339. case right.location.loc of
  340. LOC_REGISTER,
  341. LOC_CREGISTER :
  342. begin
  343. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  344. emit_reg_reg(A_CMP,S_L,right.location.register64.reghi,left.location.register64.reghi);
  345. firstjmp64bitcmp;
  346. emit_reg_reg(A_CMP,S_L,right.location.register64.reglo,left.location.register64.reglo);
  347. secondjmp64bitcmp;
  348. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  349. end;
  350. LOC_CREFERENCE,
  351. LOC_REFERENCE :
  352. begin
  353. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,right.location.reference);
  354. href:=right.location.reference;
  355. inc(href.offset,4);
  356. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  357. emit_ref_reg(A_CMP,S_L,href,left.location.register64.reghi);
  358. firstjmp64bitcmp;
  359. emit_ref_reg(A_CMP,S_L,right.location.reference,left.location.register64.reglo);
  360. secondjmp64bitcmp;
  361. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  362. location_freetemp(current_asmdata.CurrAsmList,right.location);
  363. end;
  364. LOC_CONSTANT :
  365. begin
  366. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  367. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(hi(right.location.value64)),left.location.register64.reghi));
  368. firstjmp64bitcmp;
  369. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  370. if assigned(hlab) then
  371. cg.a_jmp_always(current_asmdata.CurrAsmList,hlab)
  372. else
  373. begin
  374. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  375. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(lo(right.location.value64)),left.location.register64.reglo));
  376. secondjmp64bitcmp;
  377. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  378. end;
  379. end;
  380. else
  381. internalerror(200203282);
  382. end;
  383. end;
  384. {*****************************************************************************
  385. x86 MUL
  386. *****************************************************************************}
  387. procedure ti386addnode.set_mul_result_location;
  388. begin
  389. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  390. {Free EAX,EDX}
  391. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_EDX);
  392. if is_64bit(resultdef) then
  393. begin
  394. {Allocate a couple of registers and store EDX:EAX into it}
  395. location.register64.reghi := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  396. cg.a_load_reg_reg(current_asmdata.CurrAsmList, OS_INT, OS_INT, NR_EDX, location.register64.reghi);
  397. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_EAX);
  398. location.register64.reglo := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  399. cg.a_load_reg_reg(current_asmdata.CurrAsmList, OS_INT, OS_INT, NR_EAX, location.register64.reglo);
  400. end
  401. else
  402. begin
  403. {Allocate a new register and store the result in EAX in it.}
  404. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  405. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_EAX);
  406. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,NR_EAX,location.register);
  407. end;
  408. location_freetemp(current_asmdata.CurrAsmList,left.location);
  409. location_freetemp(current_asmdata.CurrAsmList,right.location);
  410. end;
  411. procedure ti386addnode.second_mul(unsigned: boolean);
  412. var reg:Tregister;
  413. ref:Treference;
  414. use_ref:boolean;
  415. hl4 : tasmlabel;
  416. const
  417. asmops: array[boolean] of tasmop = (A_IMUL, A_MUL);
  418. begin
  419. pass_left_right;
  420. reg:=NR_NO;
  421. reference_reset(ref,sizeof(pint),[]);
  422. { Mul supports registers and references, so if not register/reference,
  423. load the location into a register.
  424. The variant of IMUL which is capable of doing 32->64 bits has the same restrictions. }
  425. use_ref:=false;
  426. if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  427. reg:=left.location.register
  428. else if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  429. begin
  430. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
  431. ref:=left.location.reference;
  432. use_ref:=true;
  433. end
  434. else
  435. begin
  436. {LOC_CONSTANT for example.}
  437. reg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  438. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,left.resultdef,osuinttype,left.location,reg);
  439. end;
  440. {Allocate EAX.}
  441. cg.getcpuregister(current_asmdata.CurrAsmList,NR_EAX);
  442. {Load the right value.}
  443. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,right.resultdef,osuinttype,right.location,NR_EAX);
  444. {Also allocate EDX, since it is also modified by a mul (JM).}
  445. cg.getcpuregister(current_asmdata.CurrAsmList,NR_EDX);
  446. if use_ref then
  447. emit_ref(asmops[unsigned],S_L,ref)
  448. else
  449. emit_reg(asmops[unsigned],S_L,reg);
  450. if (cs_check_overflow in current_settings.localswitches) and
  451. { 32->64 bit cannot overflow }
  452. (not is_64bit(resultdef)) then
  453. begin
  454. current_asmdata.getjumplabel(hl4);
  455. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_AE,hl4);
  456. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_OVERFLOW',false);
  457. cg.a_label(current_asmdata.CurrAsmList,hl4);
  458. end;
  459. set_mul_result_location;
  460. end;
  461. procedure ti386addnode.second_mul64bit;
  462. var
  463. list: TAsmList;
  464. hreg1,hreg2: tregister;
  465. begin
  466. { 64x64 multiplication yields 128-bit result, but we're only
  467. interested in its lower 64 bits. This lower part is independent
  468. of operand signs, and so is the generated code. }
  469. { pass_left_right already called from second_add64bit }
  470. list:=current_asmdata.CurrAsmList;
  471. if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  472. tcgx86(cg).make_simple_ref(list,left.location.reference);
  473. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  474. tcgx86(cg).make_simple_ref(list,right.location.reference);
  475. { calculate 32-bit terms lo(right)*hi(left) and hi(left)*lo(right) }
  476. if (right.location.loc=LOC_CONSTANT) then
  477. begin
  478. { Omit zero terms, if any }
  479. hreg1:=NR_NO;
  480. hreg2:=NR_NO;
  481. if lo(right.location.value64)<>0 then
  482. hreg1:=cg.getintregister(list,OS_INT);
  483. if hi(right.location.value64)<>0 then
  484. hreg2:=cg.getintregister(list,OS_INT);
  485. { Take advantage of 3-operand form of IMUL }
  486. case left.location.loc of
  487. LOC_REGISTER,LOC_CREGISTER:
  488. begin
  489. if hreg1<>NR_NO then
  490. emit_const_reg_reg(A_IMUL,S_L,longint(lo(right.location.value64)),left.location.register64.reghi,hreg1);
  491. if hreg2<>NR_NO then
  492. emit_const_reg_reg(A_IMUL,S_L,longint(hi(right.location.value64)),left.location.register64.reglo,hreg2);
  493. end;
  494. LOC_REFERENCE,LOC_CREFERENCE:
  495. begin
  496. if hreg2<>NR_NO then
  497. list.concat(taicpu.op_const_ref_reg(A_IMUL,S_L,longint(hi(right.location.value64)),left.location.reference,hreg2));
  498. inc(left.location.reference.offset,4);
  499. if hreg1<>NR_NO then
  500. list.concat(taicpu.op_const_ref_reg(A_IMUL,S_L,longint(lo(right.location.value64)),left.location.reference,hreg1));
  501. dec(left.location.reference.offset,4);
  502. end;
  503. else
  504. InternalError(2014011602);
  505. end;
  506. end
  507. else
  508. begin
  509. hreg1:=cg.getintregister(list,OS_INT);
  510. hreg2:=cg.getintregister(list,OS_INT);
  511. cg64.a_load64low_loc_reg(list,left.location,hreg1);
  512. cg64.a_load64high_loc_reg(list,left.location,hreg2);
  513. case right.location.loc of
  514. LOC_REGISTER,LOC_CREGISTER:
  515. begin
  516. emit_reg_reg(A_IMUL,S_L,right.location.register64.reghi,hreg1);
  517. emit_reg_reg(A_IMUL,S_L,right.location.register64.reglo,hreg2);
  518. end;
  519. LOC_REFERENCE,LOC_CREFERENCE:
  520. begin
  521. emit_ref_reg(A_IMUL,S_L,right.location.reference,hreg2);
  522. inc(right.location.reference.offset,4);
  523. emit_ref_reg(A_IMUL,S_L,right.location.reference,hreg1);
  524. dec(right.location.reference.offset,4);
  525. end;
  526. else
  527. InternalError(2014011603);
  528. end;
  529. end;
  530. { add hi*lo and lo*hi terms together }
  531. if (hreg1<>NR_NO) and (hreg2<>NR_NO) then
  532. emit_reg_reg(A_ADD,S_L,hreg2,hreg1);
  533. { load lo(right) into EAX }
  534. cg.getcpuregister(list,NR_EAX);
  535. cg64.a_load64low_loc_reg(list,right.location,NR_EAX);
  536. { multiply EAX by lo(left), producing 64-bit value in EDX:EAX }
  537. cg.getcpuregister(list,NR_EDX);
  538. if (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  539. emit_reg(A_MUL,S_L,left.location.register64.reglo)
  540. else if (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  541. emit_ref(A_MUL,S_L,left.location.reference)
  542. else
  543. InternalError(2014011604);
  544. { add previously calculated terms to the high half }
  545. if (hreg1<>NR_NO) then
  546. emit_reg_reg(A_ADD,S_L,hreg1,NR_EDX)
  547. else if (hreg2<>NR_NO) then
  548. emit_reg_reg(A_ADD,S_L,hreg2,NR_EDX)
  549. else
  550. InternalError(2014011604);
  551. { Result is now in EDX:EAX. Copy it to virtual registers. }
  552. set_mul_result_location;
  553. end;
  554. begin
  555. caddnode:=ti386addnode;
  556. end.