cgcpu.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements the code generator for the i386
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. cgbase,cgobj,aasm,cpuasm,cpubase,cpuinfo;
  23. type
  24. tcg386 = class(tcg)
  25. { passing parameters, per default the parameter is pushed }
  26. { nr gives the number of the parameter (enumerated from }
  27. { left to right), this allows to move the parameter to }
  28. { register, if the cpu supports register calling }
  29. { conventions }
  30. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;nr : longint);override;
  31. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);override;
  32. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);override;
  33. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);override;
  34. procedure a_call_name(list : taasmoutput;const s : string;
  35. offset : longint);override;
  36. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  37. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); override;
  38. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  39. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  40. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  41. { move instructions }
  42. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  43. procedure a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);override;
  44. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  45. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;reg : tregister);override;
  46. procedure a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);override;
  47. procedure a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister); override;
  48. { comparison operations }
  49. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  50. l : tasmlabel);override;
  51. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  52. l : tasmlabel);override;
  53. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  54. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  55. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel); override;
  56. procedure g_flags2reg(list: taasmoutput; const f: tresflags; reg: TRegister); override;
  57. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  58. procedure g_restore_frame_pointer(list : taasmoutput);override;
  59. procedure g_push_exception_value_reg(list : taasmoutput;reg : tregister);override;
  60. procedure g_push_exception_value_const(list : taasmoutput;reg : tregister);override;
  61. procedure g_pop_exception_value_reg(list : taasmoutput;reg : tregister);override;
  62. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  63. procedure a_loadaddress_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  65. function makeregsize(var reg: tregister; size: tcgsize): topsize; override;
  66. private
  67. procedure sizes2load(s1: tcgsize; s2: topsize; var op: tasmop; var s3: topsize);
  68. end;
  69. const
  70. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_ADD,A_AND,A_DIV,
  71. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  72. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  73. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,C_E,C_G,
  74. C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  75. TCGSize2OpSize: Array[tcgsize] of topsize = (S_NO,S_B,S_W,S_L,S_L,
  76. S_B,S_W,S_L,S_L);
  77. implementation
  78. uses
  79. globtype,globals,verbose,systems,cutils,cga;
  80. { we implement the following routines because otherwise we can't }
  81. { instantiate the class since it's abstract }
  82. procedure tcg386.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;nr : longint);
  83. begin
  84. runerror(211);
  85. end;
  86. procedure tcg386.a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);
  87. begin
  88. runerror(211);
  89. end;
  90. procedure tcg386.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);
  91. var
  92. tmpreg: tregister;
  93. begin
  94. case size of
  95. OS_8,OS_S8,OS_16,OS_S16:
  96. begin
  97. tmpreg := get_scratch_reg(list);
  98. a_load_ref_reg(list,size,r,tmpreg);
  99. if target_info.alignment.paraalign = 2 then
  100. list.concat(taicpu.op_reg(A_PUSH,S_W,makereg16(tmpreg)))
  101. else
  102. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  103. end;
  104. OS_32,OS_S32:
  105. list.concat(taicpu.op_ref(A_PUSH,S_L,newreference(r)));
  106. else
  107. internalerror(200109301);
  108. end;
  109. end;
  110. procedure tcg386.a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);
  111. begin
  112. runerror(211);
  113. end;
  114. procedure tcg386.a_call_name(list : taasmoutput;const s : string;
  115. offset : longint);
  116. begin
  117. list.concat(taicpu.op_sym_ofs(A_CALL,S_NO,newasmsymbol(s),offset));
  118. end;
  119. {********************** load instructions ********************}
  120. procedure tcg386.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  121. begin
  122. { the optimizer will change it to "xor reg,reg" when loading zero, }
  123. { no need to do it here too (JM) }
  124. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[size],
  125. longint(a),reg))
  126. end;
  127. procedure tcg386.a_load_const_ref(list : taasmoutput; size: tcgsize; a : aword;const ref : treference);
  128. begin
  129. { zero is often used several times in succession -> load it in a }
  130. { register and then store it to memory, so the optimizer can then }
  131. { remove the unnecessary loads of registers and you get smaller }
  132. { (and faster) code }
  133. if (a = 0) and
  134. (size in [OS_32,OS_S32]) then
  135. inherited a_load_const_ref(list,size,a,ref)
  136. else
  137. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[size],
  138. longint(a),newreference(ref)));
  139. end;
  140. procedure tcg386.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  141. begin
  142. list.concat(taicpu.op_reg_ref(A_MOV,TCGSize2OpSize[size],reg,
  143. newreference(ref)));
  144. End;
  145. procedure tcg386.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  146. var
  147. op: tasmop;
  148. s: topsize;
  149. begin
  150. if ref.is_immediate then
  151. a_load_const_reg(list,size,ref.offset,reg)
  152. else
  153. begin
  154. sizes2load(size,regsize(reg),op,s);
  155. list.concat(taicpu.op_ref_reg(op,s,newreference(ref),reg));
  156. end;
  157. end;
  158. procedure tcg386.a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);
  159. var
  160. op: tasmop;
  161. s: topsize;
  162. begin
  163. sizes2load(size,regsize(reg2),op,s);
  164. if (makereg32(reg1) = makereg32(reg2)) then
  165. { "mov reg1, reg1" doesn't make sense }
  166. if op = A_MOV then
  167. exit
  168. else if (op = A_MOVZX) then
  169. case size of
  170. OS_8:
  171. begin
  172. list.concat(taicpu.op_const_reg(A_AND,regsize(reg2),255,reg2));
  173. exit;
  174. end;
  175. OS_16:
  176. begin
  177. list.concat(taicpu.op_const_reg(A_AND,S_L,65535,reg1));
  178. exit;
  179. end;
  180. end;
  181. list.concat(taicpu.op_reg_reg(op,s,reg1,reg2));
  182. end;
  183. procedure tcg386.a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister);
  184. begin
  185. list.concat(taicpu.op_sym_ofs_reg(A_MOV,S_L,sym,ofs,reg));
  186. end;
  187. procedure tcg386.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  188. var
  189. opcode: tasmop;
  190. power: longint;
  191. scratch_register: TRegister;
  192. begin
  193. Case Op of
  194. OP_DIV, OP_IDIV:
  195. Begin
  196. if ispowerof2(longint(a),power) then
  197. begin
  198. case op of
  199. OP_DIV:
  200. opcode := A_SHR;
  201. OP_IDIV:
  202. opcode := A_SAR;
  203. end;
  204. list.concat(taicpu.op_const_reg(opcode,regsize(reg),power,
  205. reg));
  206. exit;
  207. end;
  208. { the rest should be handled specifically in the code }
  209. { generator because of the silly register usage restraints }
  210. internalerror(200109224);
  211. End;
  212. OP_MUL,OP_IMUL:
  213. begin
  214. if not(cs_check_overflow in aktlocalswitches) and
  215. ispowerof2(longint(a),power) then
  216. begin
  217. list.concat(taicpu.op_const_reg(A_SHL,regsize(reg),power,
  218. reg));
  219. exit;
  220. end;
  221. if op = OP_IMUL then
  222. list.concat(taicpu.op_const_reg(A_IMUL,regsize(reg),
  223. longint(a),reg))
  224. else
  225. { OP_MUL should be handled specifically in the code }
  226. { generator because of the silly register usage restraints }
  227. internalerror(200109225);
  228. end;
  229. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  230. if (a = 1) and
  231. (op in [OP_ADD,OP_SUB]) then
  232. if op = OP_ADD then
  233. list.concat(taicpu.op_reg(A_INC,regsize(reg),reg))
  234. else
  235. list.concat(taicpu.op_reg(A_DEC,regsize(reg),reg))
  236. else
  237. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],regsize(reg),
  238. longint(a),reg));
  239. OP_SHL,OP_SHR,OP_SAR:
  240. begin
  241. if (a and 31) <> 0 Then
  242. list.concat(taicpu.op_const_reg(
  243. TOpCG2AsmOp[op],regsize(reg),a and 31,reg));
  244. if (a shr 5) <> 0 Then
  245. internalerror(68991);
  246. end
  247. else internalerror(68992);
  248. end;
  249. end;
  250. procedure tcg386.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  251. var
  252. opcode: tasmop;
  253. power: longint;
  254. scratch_register: TRegister;
  255. begin
  256. Case Op of
  257. OP_DIV, OP_IDIV:
  258. Begin
  259. if ispowerof2(longint(a),power) then
  260. begin
  261. case op of
  262. OP_DIV:
  263. opcode := A_SHR;
  264. OP_IDIV:
  265. opcode := A_SAR;
  266. end;
  267. list.concat(taicpu.op_const_ref(opcode,
  268. TCgSize2OpSize[size],power,newreference(ref)));
  269. exit;
  270. end;
  271. { the rest should be handled specifically in the code }
  272. { generator because of the silly register usage restraints }
  273. internalerror(200109231);
  274. End;
  275. OP_MUL,OP_IMUL:
  276. begin
  277. if not(cs_check_overflow in aktlocalswitches) and
  278. ispowerof2(longint(a),power) then
  279. begin
  280. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  281. power,newreference(ref)));
  282. exit;
  283. end;
  284. { can't multiply a memory location directly with a constant }
  285. if op = OP_IMUL then
  286. inherited a_op_const_ref(list,op,size,a,ref)
  287. else
  288. { OP_MUL should be handled specifically in the code }
  289. { generator because of the silly register usage restraints }
  290. internalerror(200109232);
  291. end;
  292. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  293. if (a = 1) and
  294. (op in [OP_ADD,OP_SUB]) then
  295. if op = OP_ADD then
  296. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],
  297. newreference(ref)))
  298. else
  299. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],
  300. newreference(ref)))
  301. else
  302. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  303. TCgSize2OpSize[size],longint(a),newreference(ref)));
  304. OP_SHL,OP_SHR,OP_SAR:
  305. begin
  306. if (a and 31) <> 0 Then
  307. list.concat(taicpu.op_const_ref(
  308. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,newreference(ref)));
  309. if (a shr 5) <> 0 Then
  310. internalerror(68991);
  311. end
  312. else internalerror(68992);
  313. end;
  314. end;
  315. procedure tcg386.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  316. var
  317. dstsize: topsize;
  318. begin
  319. dstsize := makeregsize(dst,size);
  320. case op of
  321. OP_NEG,OP_NOT:
  322. begin
  323. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  324. end;
  325. OP_MUL,OP_DIV,OP_IDIV:
  326. { special stuff, needs separate handling inside code }
  327. { generator }
  328. internalerror(200109233);
  329. else
  330. begin
  331. if regsize(src) <> dstsize then
  332. internalerror(200109226);
  333. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  334. src,dst));
  335. end;
  336. end;
  337. end;
  338. procedure tcg386.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  339. var
  340. opsize: topsize;
  341. begin
  342. if ref.is_immediate then
  343. a_op_const_reg(list,op,ref.offset,reg)
  344. else
  345. begin
  346. case op of
  347. OP_NEG,OP_NOT,OP_IMUL:
  348. begin
  349. inherited a_op_ref_reg(list,op,size,ref,reg);
  350. end;
  351. OP_MUL,OP_DIV,OP_IDIV:
  352. { special stuff, needs separate handling inside code }
  353. { generator }
  354. internalerror(200109239);
  355. else
  356. begin
  357. opsize := makeregsize(reg,size);
  358. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],opsize,
  359. newreference(ref),reg));
  360. end;
  361. end;
  362. end;
  363. end;
  364. procedure tcg386.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  365. var
  366. opsize: topsize;
  367. begin
  368. case op of
  369. OP_NEG,OP_NOT:
  370. begin
  371. if reg <> R_NO then
  372. internalerror(200109237);
  373. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],
  374. newreference(ref)));
  375. end;
  376. OP_IMUL:
  377. begin
  378. { this one needs a load/imul/store, which is the default }
  379. inherited a_op_ref_reg(list,op,size,ref,reg);
  380. end;
  381. OP_MUL,OP_DIV,OP_IDIV:
  382. { special stuff, needs separate handling inside code }
  383. { generator }
  384. internalerror(200109238);
  385. else
  386. begin
  387. opsize := tcgsize2opsize[size];
  388. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],opsize,reg,
  389. newreference(ref)));
  390. end;
  391. end;
  392. end;
  393. {*************** compare instructructions ****************}
  394. procedure tcg386.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  395. l : tasmlabel);
  396. begin
  397. if a <> 0 then
  398. list.concat(taicpu.op_const_reg(A_CMP,regsize(reg),longint(a),
  399. reg))
  400. else
  401. list.concat(taicpu.op_reg_reg(A_TEST,regsize(reg),reg,reg));
  402. a_jmp_cond(list,cmp_op,l);
  403. end;
  404. procedure tcg386.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  405. l : tasmlabel);
  406. begin
  407. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],
  408. longint(a),newreference(ref)));
  409. a_jmp_cond(list,cmp_op,l);
  410. end;
  411. procedure tcg386.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  412. reg1,reg2 : tregister;l : tasmlabel);
  413. begin
  414. if regsize(reg1) <> regsize(reg2) then
  415. internalerror(200109226);
  416. list.concat(taicpu.op_reg_reg(A_CMP,regsize(reg1),reg1,reg2));
  417. a_jmp_cond(list,cmp_op,l);
  418. end;
  419. procedure tcg386.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  420. var
  421. opsize: topsize;
  422. begin
  423. opsize := makeregsize(reg,size);
  424. list.concat(taicpu.op_ref_reg(A_CMP,opsize,newreference(ref),reg));
  425. a_jmp_cond(list,cmp_op,l);
  426. end;
  427. procedure tcg386.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  428. var
  429. ai : taicpu;
  430. begin
  431. if cond=OC_None then
  432. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  433. else
  434. begin
  435. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  436. ai.SetCondition(TOpCmp2AsmCond[cond]);
  437. end;
  438. ai.is_jmp:=true;
  439. list.concat(ai);
  440. end;
  441. procedure tcg386.g_flags2reg(list: taasmoutput; const f: tresflags; reg: TRegister);
  442. var
  443. ai : taicpu;
  444. hreg : tregister;
  445. begin
  446. hreg := makereg8(reg);
  447. ai:=Taicpu.Op_reg(A_Setcc,S_B,hreg);
  448. ai.SetCondition(flag_2_cond[f]);
  449. list.concat(ai);
  450. if hreg<>reg then
  451. begin
  452. if reg in regset16bit then
  453. emit_to_reg16(hreg)
  454. else
  455. emit_to_reg32(hreg);
  456. end;
  457. end;
  458. { *********** entry/exit code and address loading ************ }
  459. procedure tcg386.g_stackframe_entry(list : taasmoutput;localsize : longint);
  460. begin
  461. runerror(211);
  462. end;
  463. procedure tcg386.g_restore_frame_pointer(list : taasmoutput);
  464. begin
  465. runerror(211);
  466. end;
  467. procedure tcg386.g_push_exception_value_reg(list : taasmoutput;reg : tregister);
  468. begin
  469. runerror(211);
  470. end;
  471. procedure tcg386.g_push_exception_value_const(list : taasmoutput;reg : tregister);
  472. begin
  473. runerror(211);
  474. end;
  475. procedure tcg386.g_pop_exception_value_reg(list : taasmoutput;reg : tregister);
  476. begin
  477. runerror(211);
  478. end;
  479. procedure tcg386.g_return_from_proc(list : taasmoutput;parasize : aword);
  480. begin
  481. runerror(211);
  482. end;
  483. procedure tcg386.a_loadaddress_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  484. begin
  485. list.concat(taicpu.op_ref_reg(A_LEA,S_L,newreference(ref),r));
  486. end;
  487. function tcg386.makeregsize(var reg: tregister; size: tcgsize): topsize;
  488. begin
  489. { this function only allows downsizing a register, because otherwise }
  490. { we may start working with garbage (JM) }
  491. case size of
  492. OS_32,OS_S32:
  493. begin
  494. if not (reg in [R_EAX..R_EDI]) then
  495. internalerror(2001092313);
  496. result := S_L;
  497. end;
  498. OS_8,OS_S8:
  499. begin
  500. reg := makereg8(reg);
  501. result := S_B;
  502. end;
  503. OS_16,OS_S16:
  504. begin
  505. if reg in [R_AL..R_BH] then
  506. internalerror(2001092314);
  507. reg := makereg16(reg);
  508. result := S_W;
  509. end;
  510. else
  511. internalerror(2001092312);
  512. end;
  513. end;
  514. { ************* concatcopy ************ }
  515. procedure tcg386.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  516. { temp implementation, until it's permanenty moved here from cga.pas }
  517. var
  518. oldlist: taasmoutput;
  519. begin
  520. if list <> exprasmlist then
  521. begin
  522. oldlist := exprasmlist;
  523. exprasmlist := list;
  524. end;
  525. cga.concatcopy(source,dest,len,delsource,loadref);
  526. if list <> exprasmlist then
  527. list := oldlist;
  528. end;
  529. {***************** This is private property, keep out! :) *****************}
  530. procedure tcg386.sizes2load(s1: tcgsize; s2: topsize; var op: tasmop; var s3: topsize);
  531. begin
  532. case s2 of
  533. S_B:
  534. if S1 in [OS_8,OS_S8] then
  535. s3 := S_B
  536. else internalerror(200109221);
  537. S_W:
  538. case s1 of
  539. OS_8,OS_S8:
  540. s3 := S_BW;
  541. OS_16,OS_S16:
  542. s3 := S_W;
  543. else internalerror(200109222);
  544. end;
  545. S_L:
  546. case s1 of
  547. OS_8,OS_S8:
  548. s3 := S_BL;
  549. OS_16,OS_S16:
  550. s3 := S_WL;
  551. OS_32,OS_S32:
  552. s3 := S_L;
  553. else internalerror(200109223);
  554. end;
  555. else internalerror(200109227);
  556. end;
  557. if s3 in [S_B,S_W,S_L] then
  558. op := A_MOV
  559. else if s1 in [OS_8,OS_16,OS_32] then
  560. op := A_MOVZX
  561. else
  562. op := A_MOVSX;
  563. end;
  564. begin
  565. cg := tcg386.create;
  566. end.
  567. {
  568. $Log$
  569. Revision 1.3 2001-09-30 16:17:18 jonas
  570. * made most constant and mem handling processor independent
  571. Revision 1.2 2001/09/29 21:32:19 jonas
  572. * fixed bug in a_load_reg_reg + implemented a_call
  573. Revision 1.1 2001/09/28 20:39:33 jonas
  574. * changed all flow control structures (except for exception handling
  575. related things) to processor independent code (in new ncgflw unit)
  576. + generic cgobj unit which contains lots of code generator helpers with
  577. global "cg" class instance variable
  578. + cgcpu unit for i386 (implements processor specific routines of the above
  579. unit)
  580. * updated cgbase and cpubase for the new code generator units
  581. * include ncgflw unit in cpunode unit
  582. }