cgcpu.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. This unit implements the code generator for the x86-64.
  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 cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase,cgutils,cgobj,cgx86,
  22. aasmbase,aasmtai,aasmdata,aasmcpu,
  23. cpubase,parabase,
  24. symdef,
  25. symconst,rgx86,procinfo;
  26. type
  27. tcgx86_64 = class(tcgx86)
  28. procedure init_register_allocators;override;
  29. procedure a_loadfpu_ref_cgpara(list: TAsmList; size: tcgsize; const ref: treference; const cgpara: TCGPara); override;
  30. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
  31. procedure g_proc_entry(list : TAsmList;localsize:longint; nostackframe:boolean);override;
  32. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);override;
  33. procedure g_local_unwind(list: TAsmList; l: TAsmLabel);override;
  34. procedure g_save_registers(list: TAsmList);override;
  35. procedure g_restore_registers(list: TAsmList);override;
  36. procedure a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize : tcgsize;intreg, mmreg: tregister; shuffle: pmmshuffle); override;
  37. procedure a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize : tcgsize;mmreg, intreg: tregister;shuffle : pmmshuffle); override;
  38. function use_ms_abi: boolean;
  39. private
  40. function use_push: boolean;
  41. function saved_xmm_reg_size: longint;
  42. end;
  43. procedure create_codegen;
  44. implementation
  45. uses
  46. globtype,globals,verbose,systems,cutils,cclasses,
  47. cpuinfo,
  48. symtable,paramgr,cpupi,
  49. rgcpu,ncgutil;
  50. procedure Tcgx86_64.init_register_allocators;
  51. var
  52. ms_abi: boolean;
  53. begin
  54. inherited init_register_allocators;
  55. ms_abi:=use_ms_abi;
  56. if ms_abi then
  57. begin
  58. if (cs_userbp in current_settings.optimizerswitches) and assigned(current_procinfo) and (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  59. begin
  60. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_RAX,RS_RDX,RS_RCX,RS_R8,RS_R9,RS_R10,
  61. RS_R11,RS_RBX,RS_RSI,RS_RDI,RS_R12,RS_R13,RS_R14,RS_R15,RS_RBP],first_int_imreg,[]);
  62. end
  63. else
  64. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_RAX,RS_RDX,RS_RCX,RS_R8,RS_R9,RS_R10,
  65. RS_R11,RS_RBX,RS_RSI,RS_RDI,RS_R12,RS_R13,RS_R14,RS_R15],first_int_imreg,[])
  66. end
  67. else
  68. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_RAX,RS_RDX,RS_RCX,RS_RSI,RS_RDI,RS_R8,
  69. RS_R9,RS_R10,RS_R11,RS_RBX,RS_R12,RS_R13,RS_R14,RS_R15],first_int_imreg,[]);
  70. if FPUX86_HAS_32MMREGS in fpu_capabilities[current_settings.fputype] then
  71. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBWHOLE,[RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7,
  72. RS_XMM8,RS_XMM9,RS_XMM10,RS_XMM11,RS_XMM12,RS_XMM13,RS_XMM14,RS_XMM15,RS_XMM16,RS_XMM17,RS_XMM18,RS_XMM19,RS_XMM20,
  73. RS_XMM21,RS_XMM22,RS_XMM23,RS_XMM24,RS_XMM25,RS_XMM26,RS_XMM27,RS_XMM28,RS_XMM29,RS_XMM30,RS_XMM31],first_mm_imreg,[])
  74. else
  75. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBWHOLE,[RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7,
  76. RS_XMM8,RS_XMM9,RS_XMM10,RS_XMM11,RS_XMM12,RS_XMM13,RS_XMM14,RS_XMM15],first_mm_imreg,[]);
  77. rgfpu:=Trgx86fpu.create;
  78. end;
  79. procedure tcgx86_64.a_loadfpu_ref_cgpara(list: TAsmList; size: tcgsize; const ref: treference; const cgpara: TCGPara);
  80. begin
  81. { a record containing an extended value is returned on the x87 stack
  82. -> size will be OS_F128 (if not packed), while cgpara.paraloc^.size
  83. contains the proper size
  84. In the future we should probably always use cgpara.location^.size, but
  85. that should only be tested/done after 2.8 is branched }
  86. if size in [OS_128,OS_F128] then
  87. size:=cgpara.location^.size;
  88. inherited;
  89. end;
  90. procedure tcgx86_64.a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference);
  91. begin
  92. { same as with a_loadfpu_ref_cgpara() above, but on the callee side
  93. when the value is moved from the fpu register into a memory location }
  94. if tosize in [OS_128,OS_F128] then
  95. tosize:=OS_F80;
  96. inherited;
  97. end;
  98. function tcgx86_64.use_push: boolean;
  99. begin
  100. result:=(current_procinfo.framepointer=NR_STACK_POINTER_REG) or
  101. (current_procinfo.procdef.proctypeoption=potype_exceptfilter);
  102. end;
  103. function tcgx86_64.saved_xmm_reg_size: longint;
  104. var
  105. i: longint;
  106. regs_to_save_mm: tcpuregisterarray;
  107. begin
  108. result:=0;
  109. if (target_info.system<>system_x86_64_win64) or
  110. (not uses_registers(R_MMREGISTER)) then
  111. exit;
  112. regs_to_save_mm:=paramanager.get_saved_registers_mm(current_procinfo.procdef.proccalloption);
  113. for i:=low(regs_to_save_mm) to high(regs_to_save_mm) do
  114. begin
  115. if (regs_to_save_mm[i] in rg[R_MMREGISTER].used_in_proc) then
  116. inc(result,tcgsize2size[OS_VECTOR]);
  117. end;
  118. end;
  119. procedure tcgx86_64.g_proc_entry(list : TAsmList;localsize:longint;nostackframe:boolean);
  120. var
  121. hitem: tlinkedlistitem;
  122. seh_proc: tai_seh_directive;
  123. regsize: longint;
  124. r: integer;
  125. href: treference;
  126. templist: TAsmList;
  127. frame_offset: longint;
  128. suppress_endprologue: boolean;
  129. stackmisalignment: longint;
  130. xmmsize: longint;
  131. regs_to_save_int,
  132. regs_to_save_mm: tcpuregisterarray;
  133. procedure push_one_reg(reg: tregister);
  134. begin
  135. list.concat(taicpu.op_reg(A_PUSH,tcgsize2opsize[OS_ADDR],reg));
  136. if (target_info.system=system_x86_64_win64) then
  137. begin
  138. list.concat(cai_seh_directive.create_reg(ash_pushreg,reg));
  139. include(current_procinfo.flags,pi_has_unwind_info);
  140. end;
  141. end;
  142. procedure push_regs;
  143. var
  144. r: longint;
  145. usedregs: tcpuregisterset;
  146. hreg: TRegister;
  147. begin
  148. usedregs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(current_procinfo.procdef.proccalloption);
  149. for r := low(regs_to_save_int) to high(regs_to_save_int) do
  150. if regs_to_save_int[r] in usedregs then
  151. begin
  152. inc(regsize,sizeof(aint));
  153. inc(stackmisalignment,sizeof(aint));
  154. push_one_reg(newreg(R_INTREGISTER,regs_to_save_int[r],R_SUBWHOLE));
  155. hreg:=newreg(R_INTREGISTER,regs_to_save_int[r],R_SUBWHOLE);
  156. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  157. current_asmdata.asmcfi.cfa_offset(list,hreg,-(regsize+sizeof(pint)*2+localsize))
  158. else
  159. begin
  160. current_asmdata.asmcfi.cfa_offset(list,hreg,-(regsize+sizeof(pint)+localsize));
  161. current_asmdata.asmcfi.cfa_def_cfa_offset(list,regsize+sizeof(pint)+localsize);
  162. end;
  163. end;
  164. end;
  165. begin
  166. regsize:=0;
  167. regs_to_save_int:=paramanager.get_saved_registers_int(current_procinfo.procdef.proccalloption);
  168. regs_to_save_mm:=paramanager.get_saved_registers_mm(current_procinfo.procdef.proccalloption);
  169. hitem:=list.last;
  170. { pi_has_unwind_info may already be set at this point if there are
  171. SEH directives in assembler body. In this case, .seh_endprologue
  172. is expected to be one of those directives, and not generated here. }
  173. suppress_endprologue:=(pi_has_unwind_info in current_procinfo.flags);
  174. { save old framepointer }
  175. if not nostackframe then
  176. begin
  177. { return address }
  178. stackmisalignment := sizeof(pint);
  179. list.concat(tai_regalloc.alloc(current_procinfo.framepointer,nil));
  180. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  181. begin
  182. push_regs;
  183. CGmessage(cg_d_stackframe_omited);
  184. end
  185. else
  186. begin
  187. { push <frame_pointer> }
  188. inc(stackmisalignment,sizeof(pint));
  189. push_one_reg(NR_FRAME_POINTER_REG);
  190. { Return address and FP are both on stack }
  191. current_asmdata.asmcfi.cfa_def_cfa_offset(list,2*sizeof(pint));
  192. current_asmdata.asmcfi.cfa_offset(list,NR_FRAME_POINTER_REG,-(2*sizeof(pint)));
  193. if current_procinfo.procdef.proctypeoption<>potype_exceptfilter then
  194. list.concat(Taicpu.op_reg_reg(A_MOV,tcgsize2opsize[OS_ADDR],NR_STACK_POINTER_REG,NR_FRAME_POINTER_REG))
  195. else
  196. begin
  197. push_regs;
  198. gen_load_frame_for_exceptfilter(list);
  199. { Need only as much stack space as necessary to do the calls.
  200. Exception filters don't have own local vars, and temps are 'mapped'
  201. to the parent procedure.
  202. maxpushedparasize is already aligned at least on x86_64. }
  203. localsize:=current_procinfo.maxpushedparasize;
  204. end;
  205. current_asmdata.asmcfi.cfa_def_cfa_register(list,NR_FRAME_POINTER_REG);
  206. {
  207. TODO: current framepointer handling is not compatible with Win64 at all:
  208. Win64 expects FP to point to the top or into the middle of local area.
  209. In FPC it points to the bottom, making it impossible to generate
  210. UWOP_SET_FPREG unwind code if local area is > 240 bytes.
  211. So for now pretend we never have a framepointer.
  212. }
  213. end;
  214. xmmsize:=saved_xmm_reg_size;
  215. if use_push and (xmmsize<>0) then
  216. begin
  217. localsize:=align(localsize,target_info.stackalign)+xmmsize;
  218. reference_reset_base(current_procinfo.save_regs_ref,NR_STACK_POINTER_REG,
  219. localsize-xmmsize,ctempposinvalid,tcgsize2size[OS_VECTOR],[]);
  220. end;
  221. { allocate stackframe space }
  222. if (localsize<>0) or
  223. ((target_info.stackalign>sizeof(pint)) and
  224. (stackmisalignment <> 0) and
  225. ((pi_do_call in current_procinfo.flags) or
  226. (po_assembler in current_procinfo.procdef.procoptions))) then
  227. begin
  228. if target_info.stackalign>sizeof(pint) then
  229. localsize := align(localsize+stackmisalignment,target_info.stackalign)-stackmisalignment;
  230. g_stackpointer_alloc(list,localsize);
  231. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  232. current_asmdata.asmcfi.cfa_def_cfa_offset(list,regsize+localsize+sizeof(pint));
  233. current_procinfo.final_localsize:=localsize;
  234. if (target_info.system=system_x86_64_win64) then
  235. begin
  236. if localsize<>0 then
  237. list.concat(cai_seh_directive.create_offset(ash_stackalloc,localsize));
  238. include(current_procinfo.flags,pi_has_unwind_info);
  239. if use_push and (xmmsize<>0) then
  240. begin
  241. href:=current_procinfo.save_regs_ref;
  242. for r:=low(regs_to_save_mm) to high(regs_to_save_mm) do
  243. if regs_to_save_mm[r] in rg[R_MMREGISTER].used_in_proc then
  244. begin
  245. a_loadmm_reg_ref(list,OS_VECTOR,OS_VECTOR,newreg(R_MMREGISTER,regs_to_save_mm[r],R_SUBMMWHOLE),href,nil);
  246. inc(href.offset,tcgsize2size[OS_VECTOR]);
  247. end;
  248. end;
  249. end;
  250. end;
  251. end;
  252. if not (pi_has_unwind_info in current_procinfo.flags) then
  253. exit;
  254. { Generate unwind data for x86_64-win64 }
  255. seh_proc:=cai_seh_directive.create_name(ash_proc,current_procinfo.procdef.mangledname);
  256. if assigned(hitem) then
  257. list.insertafter(seh_proc,hitem)
  258. else
  259. list.insert(seh_proc);
  260. { the directive creates another section }
  261. inc(list.section_count);
  262. templist:=TAsmList.Create;
  263. { We need to record postive offsets from RSP; if registers are saved
  264. at negative offsets from RBP we need to account for it. }
  265. if (not use_push) then
  266. frame_offset:=current_procinfo.final_localsize
  267. else
  268. frame_offset:=0;
  269. { There's no need to describe position of register saves precisely;
  270. since registers are not modified before they are saved, and saves do not
  271. change RSP, 'logically' all saves can happen at the end of prologue. }
  272. href:=current_procinfo.save_regs_ref;
  273. if (not use_push) then
  274. begin
  275. for r:=low(regs_to_save_int) to high(regs_to_save_int) do
  276. if regs_to_save_int[r] in rg[R_INTREGISTER].used_in_proc then
  277. begin
  278. templist.concat(cai_seh_directive.create_reg_offset(ash_savereg,
  279. newreg(R_INTREGISTER,regs_to_save_int[r],R_SUBWHOLE),
  280. href.offset+frame_offset));
  281. inc(href.offset,sizeof(aint));
  282. end;
  283. end;
  284. if uses_registers(R_MMREGISTER) then
  285. begin
  286. if (href.offset mod tcgsize2size[OS_VECTOR])<>0 then
  287. inc(href.offset,tcgsize2size[OS_VECTOR]-(href.offset mod tcgsize2size[OS_VECTOR]));
  288. for r:=low(regs_to_save_mm) to high(regs_to_save_mm) do
  289. begin
  290. if regs_to_save_mm[r] in rg[R_MMREGISTER].used_in_proc then
  291. begin
  292. templist.concat(cai_seh_directive.create_reg_offset(ash_savexmm,
  293. newreg(R_MMREGISTER,regs_to_save_mm[r],R_SUBMMWHOLE),
  294. href.offset+frame_offset));
  295. inc(href.offset,tcgsize2size[OS_VECTOR]);
  296. end;
  297. end;
  298. end;
  299. if not suppress_endprologue then
  300. templist.concat(cai_seh_directive.create(ash_endprologue));
  301. if assigned(current_procinfo.endprologue_ai) then
  302. current_procinfo.aktproccode.insertlistafter(current_procinfo.endprologue_ai,templist)
  303. else
  304. list.concatlist(templist);
  305. templist.free;
  306. end;
  307. procedure tcgx86_64.g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);
  308. procedure increase_sp(a : tcgint);
  309. var
  310. href : treference;
  311. begin
  312. if a=8 then
  313. list.concat(Taicpu.op_reg(A_POP,TCGSize2OpSize[OS_ADDR],NR_RCX))
  314. else
  315. begin
  316. reference_reset_base(href,NR_STACK_POINTER_REG,a,ctempposinvalid,0,[]);
  317. { normally, lea is a better choice than an add }
  318. list.concat(Taicpu.op_ref_reg(A_LEA,TCGSize2OpSize[OS_ADDR],href,NR_STACK_POINTER_REG));
  319. end;
  320. end;
  321. var
  322. href : treference;
  323. hreg : tregister;
  324. r : longint;
  325. regs_to_save_mm: tcpuregisterarray;
  326. begin
  327. regs_to_save_mm:=paramanager.get_saved_registers_mm(current_procinfo.procdef.proccalloption);
  328. { Prevent return address from a possible call from ending up in the epilogue }
  329. { (restoring registers happens before epilogue, providing necessary padding) }
  330. if (current_procinfo.flags*[pi_has_unwind_info,pi_do_call,pi_has_saved_regs])=[pi_has_unwind_info,pi_do_call] then
  331. list.concat(Taicpu.op_none(A_NOP));
  332. { remove stackframe }
  333. if not(nostackframe) and
  334. { we do not need an exit stack frame when we never return
  335. * the final ret is left so the peephole optimizer can easily do call/ret -> jmp or call conversions
  336. * the entry stack frame must be normally generated because the subroutine could be still left by
  337. an exception and then the unwinding code might need to restore the registers stored by the entry code
  338. }
  339. not(po_noreturn in current_procinfo.procdef.procoptions) then
  340. begin
  341. if use_push then
  342. begin
  343. if (saved_xmm_reg_size<>0) then
  344. begin
  345. href:=current_procinfo.save_regs_ref;
  346. for r:=low(regs_to_save_mm) to high(regs_to_save_mm) do
  347. if regs_to_save_mm[r] in rg[R_MMREGISTER].used_in_proc then
  348. begin
  349. { Allocate register so the optimizer does not remove the load }
  350. hreg:=newreg(R_MMREGISTER,regs_to_save_mm[r],R_SUBMMWHOLE);
  351. a_reg_alloc(list,hreg);
  352. a_loadmm_ref_reg(list,OS_VECTOR,OS_VECTOR,href,hreg,nil);
  353. inc(href.offset,tcgsize2size[OS_VECTOR]);
  354. end;
  355. end;
  356. if (current_procinfo.final_localsize<>0) then
  357. increase_sp(current_procinfo.final_localsize);
  358. internal_restore_regs(list,true);
  359. if (current_procinfo.procdef.proctypeoption=potype_exceptfilter) then
  360. list.concat(Taicpu.op_reg(A_POP,tcgsize2opsize[OS_ADDR],NR_FRAME_POINTER_REG));
  361. current_asmdata.asmcfi.cfa_def_cfa_offset(list,sizeof(pint));
  362. end
  363. else if (target_info.system=system_x86_64_win64) then
  364. begin
  365. { Comply with Win64 unwinding mechanism, which only recognizes
  366. 'add $constant,%rsp' and 'lea offset(FPREG),%rsp' as belonging to
  367. the function epilog.
  368. Neither 'leave' nor even 'mov %FPREG,%rsp' are allowed. }
  369. reference_reset_base(href,current_procinfo.framepointer,0,ctempposinvalid,sizeof(pint),[]);
  370. list.concat(Taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],href,NR_STACK_POINTER_REG));
  371. list.concat(Taicpu.op_reg(A_POP,tcgsize2opsize[OS_ADDR],current_procinfo.framepointer));
  372. end
  373. else
  374. generate_leave(list);
  375. list.concat(tai_regalloc.dealloc(current_procinfo.framepointer,nil));
  376. end;
  377. if pi_uses_ymm in current_procinfo.flags then
  378. list.Concat(taicpu.op_none(A_VZEROUPPER));
  379. list.concat(Taicpu.Op_none(A_RET,S_NO));
  380. if (pi_has_unwind_info in current_procinfo.flags) then
  381. begin
  382. tcpuprocinfo(current_procinfo).dump_scopes(list);
  383. list.concat(cai_seh_directive.create(ash_endproc));
  384. end;
  385. end;
  386. procedure tcgx86_64.g_save_registers(list: TAsmList);
  387. begin
  388. if (not use_push) then
  389. inherited g_save_registers(list);
  390. end;
  391. procedure tcgx86_64.g_restore_registers(list: TAsmList);
  392. begin
  393. if (not use_push) then
  394. inherited g_restore_registers(list);
  395. end;
  396. procedure tcgx86_64.g_local_unwind(list: TAsmList; l: TAsmLabel);
  397. var
  398. para1,para2: tcgpara;
  399. href: treference;
  400. pd: tprocdef;
  401. begin
  402. if (target_info.system<>system_x86_64_win64) then
  403. begin
  404. inherited g_local_unwind(list,l);
  405. exit;
  406. end;
  407. pd:=search_system_proc('_fpc_local_unwind');
  408. para1.init;
  409. para2.init;
  410. paramanager.getcgtempparaloc(list,pd,1,para1);
  411. paramanager.getcgtempparaloc(list,pd,2,para2);
  412. reference_reset_symbol(href,l,0,1,[]);
  413. { TODO: using RSP is correct only while the stack is fixed!!
  414. (true now, but will change if/when allocating from stack is implemented) }
  415. a_load_reg_cgpara(list,OS_ADDR,NR_STACK_POINTER_REG,para1);
  416. a_loadaddr_ref_cgpara(list,href,para2);
  417. paramanager.freecgpara(list,para2);
  418. paramanager.freecgpara(list,para1);
  419. g_call(list,'_FPC_local_unwind');
  420. para2.done;
  421. para1.done;
  422. end;
  423. procedure tcgx86_64.a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize : tcgsize; intreg, mmreg: tregister; shuffle: pmmshuffle);
  424. var
  425. opc: tasmop;
  426. begin
  427. { this code can only be used to transfer raw data, not to perform
  428. conversions }
  429. if (tcgsize2size[fromsize]<>tcgsize2size[tosize]) or
  430. not(tosize in [OS_F32,OS_F64,OS_M64]) then
  431. internalerror(2009112505);
  432. case fromsize of
  433. OS_32,OS_S32:
  434. opc:=A_MOVD;
  435. OS_64,OS_S64:
  436. opc:=A_MOVQ;
  437. else
  438. internalerror(2009112506);
  439. end;
  440. if assigned(shuffle) and
  441. not shufflescalar(shuffle) then
  442. internalerror(2009112517);
  443. list.concat(taicpu.op_reg_reg(opc,S_NO,intreg,mmreg));
  444. end;
  445. procedure tcgx86_64.a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize : tcgsize; mmreg, intreg: tregister;shuffle : pmmshuffle);
  446. var
  447. opc: tasmop;
  448. begin
  449. { this code can only be used to transfer raw data, not to perform
  450. conversions }
  451. if (tcgsize2size[fromsize]<>tcgsize2size[tosize]) or
  452. not (fromsize in [OS_F32,OS_F64,OS_M64]) then
  453. internalerror(2009112507);
  454. case tosize of
  455. OS_32,OS_S32:
  456. opc:=A_MOVD;
  457. OS_64,OS_S64:
  458. opc:=A_MOVQ;
  459. else
  460. internalerror(2009112408);
  461. end;
  462. if assigned(shuffle) and
  463. not shufflescalar(shuffle) then
  464. internalerror(2009112515);
  465. list.concat(taicpu.op_reg_reg(opc,S_NO,mmreg,intreg));
  466. end;
  467. function tcgx86_64.use_ms_abi: boolean;
  468. begin
  469. if assigned(current_procinfo) then
  470. use_ms_abi:=x86_64_use_ms_abi(current_procinfo.procdef.proccalloption)
  471. else
  472. use_ms_abi:=target_info.system=system_x86_64_win64;
  473. end;
  474. procedure create_codegen;
  475. begin
  476. cg:=tcgx86_64.create;
  477. cg128:=tcg128.create;
  478. end;
  479. end.