cgcpu.pas 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. {
  2. Copyright (c) 2003 by Florian Klaempfl
  3. Member of the Free Pascal development team
  4. This unit implements the code generator for the ARM
  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 fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,symtype,symdef,
  23. cgbase,cgutils,cgobj,
  24. aasmbase,aasmcpu,aasmtai,aasmdata,
  25. parabase,
  26. cpubase,cpuinfo,node,cg64f32,rgcpu;
  27. type
  28. tcgarm = class(tcg)
  29. { true, if the next arithmetic operation should modify the flags }
  30. cgsetflags : boolean;
  31. procedure init_register_allocators;override;
  32. procedure done_register_allocators;override;
  33. procedure a_param_const(list : TAsmList;size : tcgsize;a : aint;const paraloc : TCGPara);override;
  34. procedure a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : TCGPara);override;
  35. procedure a_paramaddr_ref(list : TAsmList;const r : treference;const paraloc : TCGPara);override;
  36. procedure a_call_name(list : TAsmList;const s : string);override;
  37. procedure a_call_reg(list : TAsmList;reg: tregister);override;
  38. procedure a_call_ref(list : TAsmList;ref: treference);override;
  39. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  40. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  41. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  42. size: tcgsize; a: aint; src, dst: tregister); override;
  43. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  44. size: tcgsize; src1, src2, dst: tregister); override;
  45. procedure a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);override;
  46. procedure a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);override;
  47. { move instructions }
  48. procedure a_load_const_reg(list : TAsmList; size: tcgsize; a : aint;reg : tregister);override;
  49. procedure a_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);override;
  50. procedure a_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  51. procedure a_load_reg_reg(list : TAsmList; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  52. function a_internal_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference):treference;
  53. function a_internal_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister):treference;
  54. { fpu move instructions }
  55. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister); override;
  56. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister); override;
  57. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
  58. procedure a_paramfpu_ref(list : TAsmList;size : tcgsize;const ref : treference;const paraloc : TCGPara);override;
  59. { comparison operations }
  60. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  61. l : tasmlabel);override;
  62. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  63. procedure a_jmp_name(list : TAsmList;const s : string); override;
  64. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  65. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  66. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  67. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  68. procedure g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean); override;
  69. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  70. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);override;
  71. procedure g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : aint);override;
  72. procedure g_concatcopy_move(list : TAsmList;const source,dest : treference;len : aint);
  73. procedure g_concatcopy_internal(list : TAsmList;const source,dest : treference;len : aint;aligned : boolean);
  74. procedure g_overflowcheck(list: TAsmList; const l: tlocation; def: tdef); override;
  75. procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);override;
  76. procedure g_save_standard_registers(list : TAsmList);override;
  77. procedure g_restore_standard_registers(list : TAsmList);override;
  78. procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  79. procedure fixref(list : TAsmList;var ref : treference);
  80. function handle_load_store(list:TAsmList;op: tasmop;oppostfix : toppostfix;reg:tregister;ref: treference):treference;
  81. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  82. end;
  83. tcg64farm = class(tcg64f32)
  84. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);override;
  85. procedure a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);override;
  86. procedure a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);override;
  87. procedure a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);override;
  88. procedure a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);override;
  89. procedure a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);override;
  90. end;
  91. const
  92. OpCmp2AsmCond : Array[topcmp] of TAsmCond = (C_NONE,C_EQ,C_GT,
  93. C_LT,C_GE,C_LE,C_NE,C_LS,C_CC,C_CS,C_HI);
  94. winstackpagesize = 4096;
  95. function get_fpu_postfix(def : tdef) : toppostfix;
  96. implementation
  97. uses
  98. globals,verbose,systems,cutils,
  99. fmodule,
  100. symconst,symsym,
  101. tgobj,
  102. procinfo,cpupi,
  103. paramgr;
  104. function get_fpu_postfix(def : tdef) : toppostfix;
  105. begin
  106. if def.typ=floatdef then
  107. begin
  108. case tfloatdef(def).floattype of
  109. s32real:
  110. result:=PF_S;
  111. s64real:
  112. result:=PF_D;
  113. s80real:
  114. result:=PF_E;
  115. else
  116. internalerror(200401272);
  117. end;
  118. end
  119. else
  120. internalerror(200401271);
  121. end;
  122. procedure tcgarm.init_register_allocators;
  123. begin
  124. inherited init_register_allocators;
  125. { currently, we save R14 always, so we can use it }
  126. rg[R_INTREGISTER]:=trgintcpu.create(R_INTREGISTER,R_SUBWHOLE,
  127. [RS_R0,RS_R1,RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  128. RS_R9,RS_R10,RS_R12,RS_R14],first_int_imreg,[]);
  129. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  130. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7],first_fpu_imreg,[]);
  131. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  132. [RS_S0,RS_S1,RS_R2,RS_R3,RS_R4,RS_S31],first_mm_imreg,[]);
  133. end;
  134. procedure tcgarm.done_register_allocators;
  135. begin
  136. rg[R_INTREGISTER].free;
  137. rg[R_FPUREGISTER].free;
  138. rg[R_MMREGISTER].free;
  139. inherited done_register_allocators;
  140. end;
  141. procedure tcgarm.a_param_const(list : TAsmList;size : tcgsize;a : aint;const paraloc : TCGPara);
  142. var
  143. ref: treference;
  144. begin
  145. paraloc.check_simple_location;
  146. case paraloc.location^.loc of
  147. LOC_REGISTER,LOC_CREGISTER:
  148. a_load_const_reg(list,size,a,paraloc.location^.register);
  149. LOC_REFERENCE:
  150. begin
  151. reference_reset(ref);
  152. ref.base:=paraloc.location^.reference.index;
  153. ref.offset:=paraloc.location^.reference.offset;
  154. a_load_const_ref(list,size,a,ref);
  155. end;
  156. else
  157. internalerror(2002081101);
  158. end;
  159. end;
  160. procedure tcgarm.a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : TCGPara);
  161. var
  162. tmpref, ref: treference;
  163. location: pcgparalocation;
  164. sizeleft: aint;
  165. begin
  166. location := paraloc.location;
  167. tmpref := r;
  168. sizeleft := paraloc.intsize;
  169. while assigned(location) do
  170. begin
  171. case location^.loc of
  172. LOC_REGISTER,LOC_CREGISTER:
  173. a_load_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  174. LOC_REFERENCE:
  175. begin
  176. reference_reset_base(ref,location^.reference.index,location^.reference.offset);
  177. { doubles in softemu mode have a strange order of registers and references }
  178. if location^.size=OS_32 then
  179. g_concatcopy(list,tmpref,ref,4)
  180. else
  181. begin
  182. g_concatcopy(list,tmpref,ref,sizeleft);
  183. if assigned(location^.next) then
  184. internalerror(2005010710);
  185. end;
  186. end;
  187. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  188. case location^.size of
  189. OS_F32, OS_F64:
  190. a_loadfpu_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  191. else
  192. internalerror(2002072801);
  193. end;
  194. LOC_VOID:
  195. begin
  196. // nothing to do
  197. end;
  198. else
  199. internalerror(2002081103);
  200. end;
  201. inc(tmpref.offset,tcgsize2size[location^.size]);
  202. dec(sizeleft,tcgsize2size[location^.size]);
  203. location := location^.next;
  204. end;
  205. end;
  206. procedure tcgarm.a_paramaddr_ref(list : TAsmList;const r : treference;const paraloc : TCGPara);
  207. var
  208. ref: treference;
  209. tmpreg: tregister;
  210. begin
  211. paraloc.check_simple_location;
  212. case paraloc.location^.loc of
  213. LOC_REGISTER,LOC_CREGISTER:
  214. a_loadaddr_ref_reg(list,r,paraloc.location^.register);
  215. LOC_REFERENCE:
  216. begin
  217. reference_reset(ref);
  218. ref.base := paraloc.location^.reference.index;
  219. ref.offset := paraloc.location^.reference.offset;
  220. tmpreg := getintregister(list,OS_ADDR);
  221. a_loadaddr_ref_reg(list,r,tmpreg);
  222. a_load_reg_ref(list,OS_ADDR,OS_ADDR,tmpreg,ref);
  223. end;
  224. else
  225. internalerror(2002080701);
  226. end;
  227. end;
  228. procedure tcgarm.a_call_name(list : TAsmList;const s : string);
  229. begin
  230. list.concat(taicpu.op_sym(A_BL,current_asmdata.RefAsmSymbol(s)));
  231. {
  232. the compiler does not properly set this flag anymore in pass 1, and
  233. for now we only need it after pass 2 (I hope) (JM)
  234. if not(pi_do_call in current_procinfo.flags) then
  235. internalerror(2003060703);
  236. }
  237. include(current_procinfo.flags,pi_do_call);
  238. end;
  239. procedure tcgarm.a_call_reg(list : TAsmList;reg: tregister);
  240. begin
  241. list.concat(taicpu.op_reg_reg(A_MOV,NR_R14,NR_PC));
  242. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,reg));
  243. {
  244. the compiler does not properly set this flag anymore in pass 1, and
  245. for now we only need it after pass 2 (I hope) (JM)
  246. if not(pi_do_call in current_procinfo.flags) then
  247. internalerror(2003060703);
  248. }
  249. include(current_procinfo.flags,pi_do_call);
  250. end;
  251. procedure tcgarm.a_call_ref(list : TAsmList;ref: treference);
  252. begin
  253. a_reg_alloc(list,NR_R12);
  254. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,NR_R12);
  255. list.concat(taicpu.op_reg_reg(A_MOV,NR_R14,NR_PC));
  256. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,NR_R12));
  257. a_reg_dealloc(list,NR_R12);
  258. include(current_procinfo.flags,pi_do_call);
  259. end;
  260. procedure tcgarm.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  261. begin
  262. a_op_const_reg_reg(list,op,size,a,reg,reg);
  263. end;
  264. procedure tcgarm.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  265. begin
  266. case op of
  267. OP_NEG:
  268. list.concat(taicpu.op_reg_reg_const(A_RSB,dst,src,0));
  269. OP_NOT:
  270. begin
  271. list.concat(taicpu.op_reg_reg(A_MVN,dst,src));
  272. case size of
  273. OS_8 :
  274. a_op_const_reg_reg(list,OP_AND,OS_INT,$ff,dst,dst);
  275. OS_16 :
  276. a_op_const_reg_reg(list,OP_AND,OS_INT,$ffff,dst,dst);
  277. end;
  278. end
  279. else
  280. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  281. end;
  282. end;
  283. const
  284. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  285. (A_NONE,A_MOV,A_ADD,A_AND,A_NONE,A_NONE,A_MUL,A_MUL,A_NONE,A_NONE,A_ORR,
  286. A_NONE,A_NONE,A_NONE,A_SUB,A_EOR);
  287. procedure tcgarm.a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  288. size: tcgsize; a: aint; src, dst: tregister);
  289. var
  290. ovloc : tlocation;
  291. begin
  292. a_op_const_reg_reg_checkoverflow(list,op,size,a,src,dst,false,ovloc);
  293. end;
  294. procedure tcgarm.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  295. size: tcgsize; src1, src2, dst: tregister);
  296. var
  297. ovloc : tlocation;
  298. begin
  299. a_op_reg_reg_reg_checkoverflow(list,op,size,src1,src2,dst,false,ovloc);
  300. end;
  301. procedure tcgarm.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  302. var
  303. shift : byte;
  304. tmpreg : tregister;
  305. so : tshifterop;
  306. l1 : longint;
  307. begin
  308. ovloc.loc:=LOC_VOID;
  309. if is_shifter_const(-a,shift) then
  310. case op of
  311. OP_ADD:
  312. begin
  313. op:=OP_SUB;
  314. a:=aint(dword(-a));
  315. end;
  316. OP_SUB:
  317. begin
  318. op:=OP_ADD;
  319. a:=aint(dword(-a));
  320. end
  321. end;
  322. if is_shifter_const(a,shift) and not(op in [OP_IMUL,OP_MUL]) then
  323. case op of
  324. OP_NEG,OP_NOT,
  325. OP_DIV,OP_IDIV:
  326. internalerror(200308281);
  327. OP_SHL:
  328. begin
  329. if a>32 then
  330. internalerror(200308294);
  331. if a<>0 then
  332. begin
  333. shifterop_reset(so);
  334. so.shiftmode:=SM_LSL;
  335. so.shiftimm:=a;
  336. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src,so));
  337. end
  338. else
  339. list.concat(taicpu.op_reg_reg(A_MOV,dst,src));
  340. end;
  341. OP_SHR:
  342. begin
  343. if a>32 then
  344. internalerror(200308292);
  345. shifterop_reset(so);
  346. if a<>0 then
  347. begin
  348. so.shiftmode:=SM_LSR;
  349. so.shiftimm:=a;
  350. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src,so));
  351. end
  352. else
  353. list.concat(taicpu.op_reg_reg(A_MOV,dst,src));
  354. end;
  355. OP_SAR:
  356. begin
  357. if a>32 then
  358. internalerror(200308295);
  359. if a<>0 then
  360. begin
  361. shifterop_reset(so);
  362. so.shiftmode:=SM_ASR;
  363. so.shiftimm:=a;
  364. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src,so));
  365. end
  366. else
  367. list.concat(taicpu.op_reg_reg(A_MOV,dst,src));
  368. end;
  369. else
  370. list.concat(setoppostfix(
  371. taicpu.op_reg_reg_const(op_reg_reg_opcg2asmop[op],dst,src,a),toppostfix(ord(cgsetflags or setflags)*ord(PF_S))
  372. ));
  373. if (cgsetflags or setflags) and (size in [OS_8,OS_16,OS_32]) then
  374. begin
  375. ovloc.loc:=LOC_FLAGS;
  376. case op of
  377. OP_ADD:
  378. ovloc.resflags:=F_CS;
  379. OP_SUB:
  380. ovloc.resflags:=F_CC;
  381. end;
  382. end;
  383. end
  384. else
  385. begin
  386. { there could be added some more sophisticated optimizations }
  387. if (op in [OP_MUL,OP_IMUL]) and (a=1) then
  388. a_load_reg_reg(list,size,size,src,dst)
  389. else if (op in [OP_MUL,OP_IMUL]) and (a=0) then
  390. a_load_const_reg(list,size,0,dst)
  391. else if (op in [OP_IMUL]) and (a=-1) then
  392. a_op_reg_reg(list,OP_NEG,size,src,dst)
  393. { we do this here instead in the peephole optimizer because
  394. it saves us a register }
  395. else if (op in [OP_MUL,OP_IMUL]) and ispowerof2(a,l1) and not(cgsetflags or setflags) then
  396. a_op_const_reg_reg(list,OP_SHL,size,l1,src,dst)
  397. { for example : b=a*5 -> b=a*4+a with add instruction and shl }
  398. else if (op in [OP_MUL,OP_IMUL]) and ispowerof2(a-1,l1) and not(cgsetflags or setflags) then
  399. begin
  400. if l1>32 then{roozbeh does this ever happen?}
  401. internalerror(200308296);
  402. shifterop_reset(so);
  403. so.shiftmode:=SM_LSL;
  404. so.shiftimm:=l1;
  405. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ADD,dst,src,src,so));
  406. end
  407. else
  408. begin
  409. tmpreg:=getintregister(list,size);
  410. a_load_const_reg(list,size,a,tmpreg);
  411. a_op_reg_reg_reg_checkoverflow(list,op,size,tmpreg,src,dst,setflags,ovloc);
  412. end;
  413. end;
  414. end;
  415. procedure tcgarm.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  416. var
  417. so : tshifterop;
  418. tmpreg,overflowreg : tregister;
  419. asmop : tasmop;
  420. begin
  421. ovloc.loc:=LOC_VOID;
  422. case op of
  423. OP_NEG,OP_NOT,
  424. OP_DIV,OP_IDIV:
  425. internalerror(200308281);
  426. OP_SHL:
  427. begin
  428. shifterop_reset(so);
  429. so.rs:=src1;
  430. so.shiftmode:=SM_LSL;
  431. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src2,so));
  432. end;
  433. OP_SHR:
  434. begin
  435. shifterop_reset(so);
  436. so.rs:=src1;
  437. so.shiftmode:=SM_LSR;
  438. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src2,so));
  439. end;
  440. OP_SAR:
  441. begin
  442. shifterop_reset(so);
  443. so.rs:=src1;
  444. so.shiftmode:=SM_ASR;
  445. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,dst,src2,so));
  446. end;
  447. OP_IMUL,
  448. OP_MUL:
  449. begin
  450. if cgsetflags or setflags then
  451. begin
  452. overflowreg:=getintregister(list,size);
  453. if op=OP_IMUL then
  454. asmop:=A_SMULL
  455. else
  456. asmop:=A_UMULL;
  457. { the arm doesn't allow that rd and rm are the same }
  458. if dst=src2 then
  459. begin
  460. if dst<>src1 then
  461. list.concat(taicpu.op_reg_reg_reg_reg(asmop,dst,overflowreg,src1,src2))
  462. else
  463. begin
  464. tmpreg:=getintregister(list,size);
  465. a_load_reg_reg(list,size,size,src2,dst);
  466. list.concat(taicpu.op_reg_reg_reg_reg(asmop,dst,overflowreg,tmpreg,src1));
  467. end;
  468. end
  469. else
  470. list.concat(taicpu.op_reg_reg_reg_reg(asmop,dst,overflowreg,src2,src1));
  471. if op=OP_IMUL then
  472. begin
  473. shifterop_reset(so);
  474. so.shiftmode:=SM_ASR;
  475. so.shiftimm:=31;
  476. list.concat(taicpu.op_reg_reg_shifterop(A_CMP,overflowreg,dst,so));
  477. end
  478. else
  479. list.concat(taicpu.op_reg_const(A_CMP,overflowreg,0));
  480. ovloc.loc:=LOC_FLAGS;
  481. ovloc.resflags:=F_NE;
  482. end
  483. else
  484. begin
  485. { the arm doesn't allow that rd and rm are the same }
  486. if dst=src2 then
  487. begin
  488. if dst<>src1 then
  489. list.concat(taicpu.op_reg_reg_reg(A_MUL,dst,src1,src2))
  490. else
  491. begin
  492. tmpreg:=getintregister(list,size);
  493. a_load_reg_reg(list,size,size,src2,dst);
  494. list.concat(taicpu.op_reg_reg_reg(A_MUL,dst,tmpreg,src1));
  495. end;
  496. end
  497. else
  498. list.concat(taicpu.op_reg_reg_reg(A_MUL,dst,src2,src1));
  499. end;
  500. end;
  501. else
  502. list.concat(setoppostfix(
  503. taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1),toppostfix(ord(cgsetflags or setflags)*ord(PF_S))
  504. ));
  505. end;
  506. end;
  507. procedure tcgarm.a_load_const_reg(list : TAsmList; size: tcgsize; a : aint;reg : tregister);
  508. var
  509. imm_shift : byte;
  510. l : tasmlabel;
  511. hr : treference;
  512. begin
  513. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  514. internalerror(2002090902);
  515. if is_shifter_const(a,imm_shift) then
  516. list.concat(taicpu.op_reg_const(A_MOV,reg,a))
  517. else if is_shifter_const(not(a),imm_shift) then
  518. list.concat(taicpu.op_reg_const(A_MVN,reg,not(a)))
  519. { loading of constants with mov and orr }
  520. else if (is_shifter_const(a-byte(a),imm_shift)) then
  521. begin
  522. list.concat(taicpu.op_reg_const(A_MOV,reg,a-byte(a)));
  523. list.concat(taicpu.op_reg_reg_const(A_ORR,reg,reg,byte(a)));
  524. end
  525. else if (is_shifter_const(a-word(a),imm_shift)) and (is_shifter_const(word(a),imm_shift)) then
  526. begin
  527. list.concat(taicpu.op_reg_const(A_MOV,reg,a-word(a)));
  528. list.concat(taicpu.op_reg_reg_const(A_ORR,reg,reg,word(a)));
  529. end
  530. else if (is_shifter_const(a-(dword(a) shl 8) shr 8,imm_shift)) and (is_shifter_const((dword(a) shl 8) shr 8,imm_shift)) then
  531. begin
  532. list.concat(taicpu.op_reg_const(A_MOV,reg,a-(dword(a) shl 8) shr 8));
  533. list.concat(taicpu.op_reg_reg_const(A_ORR,reg,reg,(dword(a) shl 8) shr 8));
  534. end
  535. else
  536. begin
  537. reference_reset(hr);
  538. current_asmdata.getjumplabel(l);
  539. cg.a_label(current_procinfo.aktlocaldata,l);
  540. hr.symboldata:=current_procinfo.aktlocaldata.last;
  541. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(longint(a)));
  542. hr.symbol:=l;
  543. list.concat(taicpu.op_reg_ref(A_LDR,reg,hr));
  544. end;
  545. end;
  546. function tcgarm.handle_load_store(list:TAsmList;op: tasmop;oppostfix : toppostfix;reg:tregister;ref: treference):treference;
  547. var
  548. tmpreg : tregister;
  549. tmpref : treference;
  550. l : tasmlabel;
  551. begin
  552. tmpreg:=NR_NO;
  553. { Be sure to have a base register }
  554. if (ref.base=NR_NO) then
  555. begin
  556. if ref.shiftmode<>SM_None then
  557. internalerror(200308294);
  558. ref.base:=ref.index;
  559. ref.index:=NR_NO;
  560. end;
  561. { absolute symbols can't be handled directly, we've to store the symbol reference
  562. in the text segment and access it pc relative
  563. For now, we assume that references where base or index equals to PC are already
  564. relative, all other references are assumed to be absolute and thus they need
  565. to be handled extra.
  566. A proper solution would be to change refoptions to a set and store the information
  567. if the symbol is absolute or relative there.
  568. }
  569. if (assigned(ref.symbol) and
  570. not(is_pc(ref.base)) and
  571. not(is_pc(ref.index))
  572. ) or
  573. { [#xxx] isn't a valid address operand }
  574. ((ref.base=NR_NO) and (ref.index=NR_NO)) or
  575. (ref.offset<-4095) or
  576. (ref.offset>4095) or
  577. ((oppostfix in [PF_SB,PF_H,PF_SH]) and
  578. ((ref.offset<-255) or
  579. (ref.offset>255)
  580. )
  581. ) or
  582. ((op in [A_LDF,A_STF]) and
  583. ((ref.offset<-1020) or
  584. (ref.offset>1020) or
  585. { the usual pc relative symbol handling assumes possible offsets of +/- 4095 }
  586. assigned(ref.symbol)
  587. )
  588. ) then
  589. begin
  590. reference_reset(tmpref);
  591. { load symbol }
  592. tmpreg:=getintregister(list,OS_INT);
  593. if assigned(ref.symbol) then
  594. begin
  595. current_asmdata.getjumplabel(l);
  596. cg.a_label(current_procinfo.aktlocaldata,l);
  597. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  598. current_procinfo.aktlocaldata.concat(tai_const.create_sym_offset(ref.symbol,ref.offset));
  599. { load consts entry }
  600. tmpref.symbol:=l;
  601. tmpref.base:=NR_R15;
  602. list.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  603. { in case of LDF/STF, we got rid of the NR_R15 }
  604. if is_pc(ref.base) then
  605. ref.base:=NR_NO;
  606. if is_pc(ref.index) then
  607. ref.index:=NR_NO;
  608. end
  609. else
  610. a_load_const_reg(list,OS_ADDR,ref.offset,tmpreg);
  611. if (ref.base<>NR_NO) then
  612. begin
  613. if ref.index<>NR_NO then
  614. begin
  615. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  616. ref.base:=tmpreg;
  617. end
  618. else
  619. begin
  620. ref.index:=tmpreg;
  621. ref.shiftimm:=0;
  622. ref.signindex:=1;
  623. ref.shiftmode:=SM_None;
  624. end;
  625. end
  626. else
  627. ref.base:=tmpreg;
  628. ref.offset:=0;
  629. ref.symbol:=nil;
  630. end;
  631. if (ref.base<>NR_NO) and (ref.index<>NR_NO) and (ref.offset<>0) then
  632. begin
  633. if tmpreg<>NR_NO then
  634. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,ref.offset,tmpreg,tmpreg)
  635. else
  636. begin
  637. tmpreg:=getintregister(list,OS_ADDR);
  638. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,ref.offset,ref.base,tmpreg);
  639. ref.base:=tmpreg;
  640. end;
  641. ref.offset:=0;
  642. end;
  643. { floating point operations have only limited references
  644. we expect here, that a base is already set }
  645. if (op in [A_LDF,A_STF]) and (ref.index<>NR_NO) then
  646. begin
  647. if ref.shiftmode<>SM_none then
  648. internalerror(200309121);
  649. if tmpreg<>NR_NO then
  650. begin
  651. if ref.base=tmpreg then
  652. begin
  653. if ref.signindex<0 then
  654. list.concat(taicpu.op_reg_reg_reg(A_SUB,tmpreg,tmpreg,ref.index))
  655. else
  656. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,tmpreg,ref.index));
  657. ref.index:=NR_NO;
  658. end
  659. else
  660. begin
  661. if ref.index<>tmpreg then
  662. internalerror(200403161);
  663. if ref.signindex<0 then
  664. list.concat(taicpu.op_reg_reg_reg(A_SUB,tmpreg,ref.base,tmpreg))
  665. else
  666. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  667. ref.base:=tmpreg;
  668. ref.index:=NR_NO;
  669. end;
  670. end
  671. else
  672. begin
  673. tmpreg:=getintregister(list,OS_ADDR);
  674. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,ref.index));
  675. ref.base:=tmpreg;
  676. ref.index:=NR_NO;
  677. end;
  678. end;
  679. list.concat(setoppostfix(taicpu.op_reg_ref(op,reg,ref),oppostfix));
  680. Result := ref;
  681. end;
  682. procedure tcgarm.a_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);
  683. var
  684. oppostfix:toppostfix;
  685. usedtmpref: treference;
  686. tmpreg : tregister;
  687. so : tshifterop;
  688. begin
  689. case ToSize of
  690. { signed integer registers }
  691. OS_8,
  692. OS_S8:
  693. oppostfix:=PF_B;
  694. OS_16,
  695. OS_S16:
  696. oppostfix:=PF_H;
  697. OS_32,
  698. OS_S32:
  699. oppostfix:=PF_None;
  700. else
  701. InternalError(200308295);
  702. end;
  703. if ref.alignment<>0 then
  704. begin
  705. case FromSize of
  706. OS_16,OS_S16:
  707. begin
  708. shifterop_reset(so);so.shiftmode:=SM_LSR;so.shiftimm:=8;
  709. tmpreg:=getintregister(list,OS_INT);
  710. usedtmpref:=a_internal_load_reg_ref(list,OS_8,OS_8,reg,Ref);
  711. inc(usedtmpref.offset);
  712. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,reg,so));
  713. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  714. end;
  715. OS_32,OS_S32:
  716. begin
  717. shifterop_reset(so);so.shiftmode:=SM_LSR;so.shiftimm:=8;
  718. tmpreg:=getintregister(list,OS_INT);
  719. usedtmpref:=a_internal_load_reg_ref(list,OS_8,OS_8,reg,Ref);
  720. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,reg,so));
  721. inc(usedtmpref.offset);
  722. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  723. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,tmpreg,so));
  724. inc(usedtmpref.offset);
  725. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  726. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,tmpreg,so));
  727. inc(usedtmpref.offset);
  728. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  729. end
  730. else
  731. handle_load_store(list,A_STR,oppostfix,reg,ref);
  732. end;
  733. end
  734. else
  735. handle_load_store(list,A_STR,oppostfix,reg,ref);
  736. end;
  737. procedure tcgarm.a_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);
  738. var
  739. oppostfix:toppostfix;
  740. usedtmpref: treference;
  741. tmpreg,tmpreg2,tmpreg3 : tregister;
  742. so : tshifterop;
  743. begin
  744. case FromSize of
  745. { signed integer registers }
  746. OS_8:
  747. oppostfix:=PF_B;
  748. OS_S8:
  749. oppostfix:=PF_SB;
  750. OS_16:
  751. oppostfix:=PF_H;
  752. OS_S16:
  753. oppostfix:=PF_SH;
  754. OS_32,
  755. OS_S32:
  756. oppostfix:=PF_None;
  757. else
  758. InternalError(200308297);
  759. end;
  760. if Ref.alignment<>0 then
  761. begin
  762. case FromSize of
  763. OS_16,OS_S16:
  764. begin
  765. { only complicated references need an extra loadaddr }
  766. if assigned(ref.symbol) or
  767. (ref.index<>NR_NO) or
  768. (ref.offset<-4095) or
  769. (ref.offset>4094) or
  770. { sometimes the compiler reused registers }
  771. (reg=ref.index) or
  772. (reg=ref.base) then
  773. begin
  774. tmpreg3:=getintregister(list,OS_INT);
  775. a_loadaddr_ref_reg(list,ref,tmpreg3);
  776. reference_reset_base(usedtmpref,tmpreg3,0);
  777. end
  778. else
  779. usedtmpref:=ref;
  780. shifterop_reset(so);so.shiftmode:=SM_LSL;so.shiftimm:=8;
  781. tmpreg:=getintregister(list,OS_INT);
  782. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  783. inc(usedtmpref.offset);
  784. tmpreg2:=getintregister(list,OS_INT);
  785. if FromSize=OS_16 then
  786. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg2)
  787. else
  788. a_internal_load_ref_reg(list,OS_S8,OS_S8,usedtmpref,tmpreg2);
  789. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,reg,tmpreg,tmpreg2,so));
  790. end;
  791. OS_32,OS_S32:
  792. begin
  793. tmpreg:=getintregister(list,OS_INT);
  794. tmpreg2:=getintregister(list,OS_INT);
  795. { only complicated references need an extra loadaddr }
  796. if assigned(ref.symbol) or
  797. (ref.index<>NR_NO) or
  798. (ref.offset<-4095) or
  799. (ref.offset>4092) or
  800. { sometimes the compiler reused registers }
  801. (reg=ref.index) or
  802. (reg=ref.base) then
  803. begin
  804. tmpreg3:=getintregister(list,OS_INT);
  805. a_loadaddr_ref_reg(list,ref,tmpreg3);
  806. reference_reset_base(usedtmpref,tmpreg3,0);
  807. end
  808. else
  809. usedtmpref:=ref;
  810. shifterop_reset(so);so.shiftmode:=SM_LSL;so.shiftimm:=8;
  811. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,reg);
  812. inc(usedtmpref.offset);
  813. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  814. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,tmpreg2,reg,tmpreg,so));
  815. inc(usedtmpref.offset);
  816. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,reg);
  817. so.shiftimm:=16;
  818. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,tmpreg,tmpreg2,reg,so));
  819. inc(usedtmpref.offset);
  820. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg2);
  821. so.shiftimm:=24;
  822. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,reg,tmpreg,tmpreg2,so));
  823. end
  824. else
  825. handle_load_store(list,A_LDR,oppostfix,reg,ref);
  826. end;
  827. end
  828. else
  829. handle_load_store(list,A_LDR,oppostfix,reg,ref);
  830. end;
  831. function tcgarm.a_internal_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference):treference;
  832. var
  833. oppostfix:toppostfix;
  834. begin
  835. case ToSize of
  836. { signed integer registers }
  837. OS_8,
  838. OS_S8:
  839. oppostfix:=PF_B;
  840. OS_16,
  841. OS_S16:
  842. oppostfix:=PF_H;
  843. OS_32,
  844. OS_S32:
  845. oppostfix:=PF_None;
  846. else
  847. InternalError(2003082910);
  848. end;
  849. result:=handle_load_store(list,A_STR,oppostfix,reg,ref);
  850. end;
  851. function tcgarm.a_internal_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister):treference;
  852. var
  853. oppostfix:toppostfix;
  854. begin
  855. case FromSize of
  856. { signed integer registers }
  857. OS_8:
  858. oppostfix:=PF_B;
  859. OS_S8:
  860. oppostfix:=PF_SB;
  861. OS_16:
  862. oppostfix:=PF_H;
  863. OS_S16:
  864. oppostfix:=PF_SH;
  865. OS_32,
  866. OS_S32:
  867. oppostfix:=PF_None;
  868. else
  869. InternalError(200308291);
  870. end;
  871. result:=handle_load_store(list,A_LDR,oppostfix,reg,ref);
  872. end;
  873. procedure tcgarm.a_load_reg_reg(list : TAsmList; fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  874. var
  875. so : tshifterop;
  876. conv_done: boolean;
  877. procedure do_shift(shiftmode : tshiftmode; shiftimm : byte; reg : tregister);
  878. begin
  879. so.shiftmode:=shiftmode;
  880. so.shiftimm:=shiftimm;
  881. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,reg2,reg,so));
  882. end;
  883. function do_conv(size : tcgsize) : boolean;
  884. begin
  885. result:=true;
  886. case size of
  887. OS_8:
  888. list.concat(taicpu.op_reg_reg_const(A_AND,reg2,reg1,$ff));
  889. OS_S8:
  890. begin
  891. do_shift(SM_LSL,24,reg1);
  892. do_shift(SM_ASR,24,reg2);
  893. end;
  894. OS_16,OS_S16:
  895. begin
  896. do_shift(SM_LSL,16,reg1);
  897. if size=OS_S16 then
  898. do_shift(SM_ASR,16,reg2)
  899. else
  900. do_shift(SM_LSR,16,reg2);
  901. end;
  902. else
  903. result:=false;
  904. end;
  905. conv_done:=result;
  906. end;
  907. var
  908. instr: taicpu;
  909. begin
  910. conv_done:=false;
  911. if tcgsize2size[tosize]<>tcgsize2size[fromsize] then
  912. begin
  913. shifterop_reset(so);
  914. if not do_conv(tosize) then
  915. if tosize in [OS_32,OS_S32] then
  916. do_conv(fromsize)
  917. else
  918. internalerror(2002090901);
  919. end;
  920. if not conv_done and (reg1<>reg2) then
  921. begin
  922. { same size, only a register mov required }
  923. instr:=taicpu.op_reg_reg(A_MOV,reg2,reg1);
  924. list.Concat(instr);
  925. { Notify the register allocator that we have written a move instruction so
  926. it can try to eliminate it. }
  927. add_move_instruction(instr);
  928. end;
  929. end;
  930. procedure tcgarm.a_paramfpu_ref(list : TAsmList;size : tcgsize;const ref : treference;const paraloc : TCGPara);
  931. var
  932. href,href2 : treference;
  933. hloc : pcgparalocation;
  934. begin
  935. href:=ref;
  936. hloc:=paraloc.location;
  937. while assigned(hloc) do
  938. begin
  939. case hloc^.loc of
  940. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  941. a_loadfpu_ref_reg(list,size,size,ref,hloc^.register);
  942. LOC_REGISTER :
  943. case hloc^.size of
  944. OS_F32:
  945. a_load_ref_reg(list,OS_32,OS_32,href,hloc^.register);
  946. OS_64,
  947. OS_F64:
  948. cg64.a_param64_ref(list,href,paraloc);
  949. else
  950. a_load_ref_reg(list,hloc^.size,hloc^.size,href,hloc^.register);
  951. end;
  952. LOC_REFERENCE :
  953. begin
  954. reference_reset_base(href2,hloc^.reference.index,hloc^.reference.offset);
  955. { concatcopy should choose the best way to copy the data }
  956. g_concatcopy(list,href,href2,tcgsize2size[size]);
  957. end;
  958. else
  959. internalerror(200408241);
  960. end;
  961. inc(href.offset,tcgsize2size[hloc^.size]);
  962. hloc:=hloc^.next;
  963. end;
  964. end;
  965. procedure tcgarm.a_loadfpu_reg_reg(list: TAsmList; fromsize,tosize: tcgsize; reg1, reg2: tregister);
  966. begin
  967. list.concat(setoppostfix(taicpu.op_reg_reg(A_MVF,reg2,reg1),cgsize2fpuoppostfix[tosize]));
  968. end;
  969. procedure tcgarm.a_loadfpu_ref_reg(list: TAsmList; fromsize,tosize: tcgsize; const ref: treference; reg: tregister);
  970. var
  971. oppostfix:toppostfix;
  972. begin
  973. case tosize of
  974. OS_32,
  975. OS_F32:
  976. oppostfix:=PF_S;
  977. OS_64,
  978. OS_F64:
  979. oppostfix:=PF_D;
  980. OS_F80:
  981. oppostfix:=PF_E;
  982. else
  983. InternalError(200309021);
  984. end;
  985. handle_load_store(list,A_LDF,oppostfix,reg,ref);
  986. end;
  987. procedure tcgarm.a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference);
  988. var
  989. oppostfix:toppostfix;
  990. begin
  991. case tosize of
  992. OS_F32:
  993. oppostfix:=PF_S;
  994. OS_F64:
  995. oppostfix:=PF_D;
  996. OS_F80:
  997. oppostfix:=PF_E;
  998. else
  999. InternalError(200309022);
  1000. end;
  1001. handle_load_store(list,A_STF,oppostfix,reg,ref);
  1002. end;
  1003. { comparison operations }
  1004. procedure tcgarm.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  1005. l : tasmlabel);
  1006. var
  1007. tmpreg : tregister;
  1008. b : byte;
  1009. begin
  1010. if is_shifter_const(a,b) then
  1011. list.concat(taicpu.op_reg_const(A_CMP,reg,a))
  1012. { CMN reg,0 and CMN reg,$80000000 are different from CMP reg,$ffffffff
  1013. and CMP reg,$7fffffff regarding the flags according to the ARM manual }
  1014. else if (a<>$7fffffff) and (a<>-1) and is_shifter_const(-a,b) then
  1015. list.concat(taicpu.op_reg_const(A_CMN,reg,-a))
  1016. else
  1017. begin
  1018. tmpreg:=getintregister(list,size);
  1019. a_load_const_reg(list,size,a,tmpreg);
  1020. list.concat(taicpu.op_reg_reg(A_CMP,reg,tmpreg));
  1021. end;
  1022. a_jmp_cond(list,cmp_op,l);
  1023. end;
  1024. procedure tcgarm.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
  1025. begin
  1026. list.concat(taicpu.op_reg_reg(A_CMP,reg2,reg1));
  1027. a_jmp_cond(list,cmp_op,l);
  1028. end;
  1029. procedure tcgarm.a_jmp_name(list : TAsmList;const s : string);
  1030. var
  1031. ai : taicpu;
  1032. begin
  1033. ai:=taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  1034. ai.is_jmp:=true;
  1035. list.concat(ai);
  1036. end;
  1037. procedure tcgarm.a_jmp_always(list : TAsmList;l: tasmlabel);
  1038. var
  1039. ai : taicpu;
  1040. begin
  1041. ai:=taicpu.op_sym(A_B,l);
  1042. ai.is_jmp:=true;
  1043. list.concat(ai);
  1044. end;
  1045. procedure tcgarm.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  1046. var
  1047. ai : taicpu;
  1048. begin
  1049. ai:=setcondition(taicpu.op_sym(A_B,l),flags_to_cond(f));
  1050. ai.is_jmp:=true;
  1051. list.concat(ai);
  1052. end;
  1053. procedure tcgarm.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  1054. begin
  1055. list.concat(setcondition(taicpu.op_reg_const(A_MOV,reg,1),flags_to_cond(f)));
  1056. list.concat(setcondition(taicpu.op_reg_const(A_MOV,reg,0),inverse_cond(flags_to_cond(f))));
  1057. end;
  1058. procedure tcgarm.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  1059. var
  1060. ref : treference;
  1061. shift : byte;
  1062. firstfloatreg,lastfloatreg,
  1063. r : byte;
  1064. regs : tcpuregisterset;
  1065. begin
  1066. LocalSize:=align(LocalSize,4);
  1067. if not(nostackframe) then
  1068. begin
  1069. firstfloatreg:=RS_NO;
  1070. { save floating point registers? }
  1071. for r:=RS_F0 to RS_F7 do
  1072. if r in rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall) then
  1073. begin
  1074. if firstfloatreg=RS_NO then
  1075. firstfloatreg:=r;
  1076. lastfloatreg:=r;
  1077. end;
  1078. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1079. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1080. begin
  1081. a_reg_alloc(list,NR_FRAME_POINTER_REG);
  1082. a_reg_alloc(list,NR_R12);
  1083. list.concat(taicpu.op_reg_reg(A_MOV,NR_R12,NR_STACK_POINTER_REG));
  1084. end;
  1085. { save int registers }
  1086. reference_reset(ref);
  1087. ref.index:=NR_STACK_POINTER_REG;
  1088. ref.addressmode:=AM_PREINDEXED;
  1089. regs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1090. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1091. regs:=regs+[RS_R11,RS_R12,RS_R14,RS_R15]
  1092. else
  1093. if (regs<>[]) or (pi_do_call in current_procinfo.flags) then
  1094. include(regs,RS_R14);
  1095. if regs<>[] then
  1096. list.concat(setoppostfix(taicpu.op_ref_regset(A_STM,ref,regs),PF_FD));
  1097. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1098. list.concat(taicpu.op_reg_reg_const(A_SUB,NR_FRAME_POINTER_REG,NR_R12,4));
  1099. { allocate necessary stack size
  1100. not necessary according to Yury Sidorov
  1101. { don't use a_op_const_reg_reg here because we don't allow register allocations
  1102. in the entry/exit code }
  1103. if (target_info.system in [system_arm_wince]) and
  1104. (localsize>=winstackpagesize) then
  1105. begin
  1106. if localsize div winstackpagesize<=5 then
  1107. begin
  1108. if is_shifter_const(localsize,shift) then
  1109. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,localsize))
  1110. else
  1111. begin
  1112. a_load_const_reg(list,OS_ADDR,localsize,NR_R12);
  1113. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1114. end;
  1115. for i:=1 to localsize div winstackpagesize do
  1116. begin
  1117. if localsize-i*winstackpagesize<4096 then
  1118. reference_reset_base(href,NR_STACK_POINTER_REG,-(localsize-i*winstackpagesize))
  1119. else
  1120. begin
  1121. a_load_const_reg(list,OS_ADDR,-(localsize-i*winstackpagesize),NR_R12);
  1122. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1123. href.index:=NR_R12;
  1124. end;
  1125. { the data stored doesn't matter }
  1126. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1127. end;
  1128. a_reg_dealloc(list,NR_R12);
  1129. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1130. { the data stored doesn't matter }
  1131. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1132. end
  1133. else
  1134. begin
  1135. current_asmdata.getjumplabel(again);
  1136. list.concat(Taicpu.op_reg_const(A_MOV,NR_R12,localsize div winstackpagesize));
  1137. a_label(list,again);
  1138. { always shifterop }
  1139. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,winstackpagesize));
  1140. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1141. { the data stored doesn't matter }
  1142. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1143. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_R12,NR_R12,1));
  1144. a_jmp_cond(list,OC_NE,again);
  1145. if is_shifter_const(localsize mod winstackpagesize,shift) then
  1146. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,localsize mod winstackpagesize))
  1147. else
  1148. begin
  1149. a_load_const_reg(list,OS_ADDR,localsize mod winstackpagesize,NR_R12);
  1150. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1151. end;
  1152. a_reg_dealloc(list,NR_R12);
  1153. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1154. { the data stored doesn't matter }
  1155. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1156. end
  1157. end
  1158. else
  1159. }
  1160. if LocalSize<>0 then
  1161. if not(is_shifter_const(localsize,shift)) then
  1162. begin
  1163. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  1164. a_reg_alloc(list,NR_R12);
  1165. a_load_const_reg(list,OS_ADDR,LocalSize,NR_R12);
  1166. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1167. a_reg_dealloc(list,NR_R12);
  1168. end
  1169. else
  1170. begin
  1171. a_reg_dealloc(list,NR_R12);
  1172. list.concat(taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,LocalSize));
  1173. end;
  1174. if firstfloatreg<>RS_NO then
  1175. begin
  1176. reference_reset(ref);
  1177. if tg.direction*tarmprocinfo(current_procinfo).floatregstart>=1023 then
  1178. begin
  1179. a_load_const_reg(list,OS_ADDR,-tarmprocinfo(current_procinfo).floatregstart,NR_R12);
  1180. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_R12,current_procinfo.framepointer,NR_R12));
  1181. ref.base:=NR_R12;
  1182. end
  1183. else
  1184. begin
  1185. ref.base:=current_procinfo.framepointer;
  1186. ref.offset:=tarmprocinfo(current_procinfo).floatregstart;
  1187. end;
  1188. list.concat(taicpu.op_reg_const_ref(A_SFM,newreg(R_FPUREGISTER,firstfloatreg,R_SUBWHOLE),
  1189. lastfloatreg-firstfloatreg+1,ref));
  1190. end;
  1191. end;
  1192. end;
  1193. procedure tcgarm.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  1194. var
  1195. ref : treference;
  1196. firstfloatreg,lastfloatreg,
  1197. r : byte;
  1198. shift : byte;
  1199. regs : tcpuregisterset;
  1200. LocalSize : longint;
  1201. begin
  1202. if not(nostackframe) then
  1203. begin
  1204. { restore floating point register }
  1205. firstfloatreg:=RS_NO;
  1206. { save floating point registers? }
  1207. for r:=RS_F0 to RS_F7 do
  1208. if r in rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall) then
  1209. begin
  1210. if firstfloatreg=RS_NO then
  1211. firstfloatreg:=r;
  1212. lastfloatreg:=r;
  1213. end;
  1214. if firstfloatreg<>RS_NO then
  1215. begin
  1216. reference_reset(ref);
  1217. if tg.direction*tarmprocinfo(current_procinfo).floatregstart>=1023 then
  1218. begin
  1219. a_load_const_reg(list,OS_ADDR,-tarmprocinfo(current_procinfo).floatregstart,NR_R12);
  1220. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_R12,current_procinfo.framepointer,NR_R12));
  1221. ref.base:=NR_R12;
  1222. end
  1223. else
  1224. begin
  1225. ref.base:=current_procinfo.framepointer;
  1226. ref.offset:=tarmprocinfo(current_procinfo).floatregstart;
  1227. end;
  1228. list.concat(taicpu.op_reg_const_ref(A_LFM,newreg(R_FPUREGISTER,firstfloatreg,R_SUBWHOLE),
  1229. lastfloatreg-firstfloatreg+1,ref));
  1230. end;
  1231. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1232. begin
  1233. LocalSize:=current_procinfo.calc_stackframe_size;
  1234. if LocalSize<>0 then
  1235. if not(is_shifter_const(LocalSize,shift)) then
  1236. begin
  1237. a_reg_alloc(list,NR_R12);
  1238. a_load_const_reg(list,OS_ADDR,LocalSize,NR_R12);
  1239. list.concat(taicpu.op_reg_reg_reg(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1240. a_reg_dealloc(list,NR_R12);
  1241. end
  1242. else
  1243. begin
  1244. list.concat(taicpu.op_reg_reg_const(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,LocalSize));
  1245. end;
  1246. regs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1247. if (pi_do_call in current_procinfo.flags) or (regs<>[]) then
  1248. begin
  1249. exclude(regs,RS_R14);
  1250. include(regs,RS_R15);
  1251. end;
  1252. if regs=[] then
  1253. list.concat(taicpu.op_reg_reg(A_MOV,NR_R15,NR_R14))
  1254. else
  1255. begin
  1256. reference_reset(ref);
  1257. ref.index:=NR_STACK_POINTER_REG;
  1258. ref.addressmode:=AM_PREINDEXED;
  1259. list.concat(setoppostfix(taicpu.op_ref_regset(A_LDM,ref,regs),PF_FD));
  1260. end;
  1261. end
  1262. else
  1263. begin
  1264. { restore int registers and return }
  1265. reference_reset(ref);
  1266. ref.index:=NR_FRAME_POINTER_REG;
  1267. list.concat(setoppostfix(taicpu.op_ref_regset(A_LDM,ref,rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall)+[RS_R11,RS_R13,RS_R15]),PF_EA));
  1268. end;
  1269. end
  1270. else
  1271. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,NR_R14));
  1272. end;
  1273. procedure tcgarm.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1274. var
  1275. b : byte;
  1276. tmpref : treference;
  1277. instr : taicpu;
  1278. begin
  1279. if ref.addressmode<>AM_OFFSET then
  1280. internalerror(200309071);
  1281. tmpref:=ref;
  1282. { Be sure to have a base register }
  1283. if (tmpref.base=NR_NO) then
  1284. begin
  1285. if tmpref.shiftmode<>SM_None then
  1286. internalerror(200308294);
  1287. if tmpref.signindex<0 then
  1288. internalerror(200312023);
  1289. tmpref.base:=tmpref.index;
  1290. tmpref.index:=NR_NO;
  1291. end;
  1292. if assigned(tmpref.symbol) or
  1293. not((is_shifter_const(tmpref.offset,b)) or
  1294. (is_shifter_const(-tmpref.offset,b))
  1295. ) then
  1296. fixref(list,tmpref);
  1297. { expect a base here if there is an index }
  1298. if (tmpref.base=NR_NO) and (tmpref.index<>NR_NO) then
  1299. internalerror(200312022);
  1300. if tmpref.index<>NR_NO then
  1301. begin
  1302. if tmpref.shiftmode<>SM_None then
  1303. internalerror(200312021);
  1304. if tmpref.signindex<0 then
  1305. a_op_reg_reg_reg(list,OP_SUB,OS_ADDR,tmpref.base,tmpref.index,r)
  1306. else
  1307. a_op_reg_reg_reg(list,OP_ADD,OS_ADDR,tmpref.base,tmpref.index,r);
  1308. if tmpref.offset<>0 then
  1309. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,tmpref.offset,r,r);
  1310. end
  1311. else
  1312. begin
  1313. if tmpref.base=NR_NO then
  1314. a_load_const_reg(list,OS_ADDR,tmpref.offset,r)
  1315. else
  1316. if tmpref.offset<>0 then
  1317. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,tmpref.offset,tmpref.base,r)
  1318. else
  1319. begin
  1320. instr:=taicpu.op_reg_reg(A_MOV,r,tmpref.base);
  1321. list.concat(instr);
  1322. add_move_instruction(instr);
  1323. end;
  1324. end;
  1325. end;
  1326. procedure tcgarm.fixref(list : TAsmList;var ref : treference);
  1327. var
  1328. tmpreg : tregister;
  1329. tmpref : treference;
  1330. l : tasmlabel;
  1331. begin
  1332. { absolute symbols can't be handled directly, we've to store the symbol reference
  1333. in the text segment and access it pc relative
  1334. For now, we assume that references where base or index equals to PC are already
  1335. relative, all other references are assumed to be absolute and thus they need
  1336. to be handled extra.
  1337. A proper solution would be to change refoptions to a set and store the information
  1338. if the symbol is absolute or relative there.
  1339. }
  1340. { create consts entry }
  1341. reference_reset(tmpref);
  1342. current_asmdata.getjumplabel(l);
  1343. cg.a_label(current_procinfo.aktlocaldata,l);
  1344. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  1345. if assigned(ref.symbol) then
  1346. current_procinfo.aktlocaldata.concat(tai_const.create_sym_offset(ref.symbol,ref.offset))
  1347. else
  1348. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  1349. { load consts entry }
  1350. tmpreg:=getintregister(list,OS_INT);
  1351. tmpref.symbol:=l;
  1352. tmpref.base:=NR_PC;
  1353. list.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  1354. if (ref.base<>NR_NO) then
  1355. begin
  1356. if ref.index<>NR_NO then
  1357. begin
  1358. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1359. ref.base:=tmpreg;
  1360. end
  1361. else
  1362. if ref.base<>NR_PC then
  1363. begin
  1364. ref.index:=tmpreg;
  1365. ref.shiftimm:=0;
  1366. ref.signindex:=1;
  1367. ref.shiftmode:=SM_None;
  1368. end
  1369. else
  1370. ref.base:=tmpreg;
  1371. end
  1372. else
  1373. ref.base:=tmpreg;
  1374. ref.offset:=0;
  1375. ref.symbol:=nil;
  1376. end;
  1377. procedure tcgarm.g_concatcopy_move(list : TAsmList;const source,dest : treference;len : aint);
  1378. var
  1379. paraloc1,paraloc2,paraloc3 : TCGPara;
  1380. begin
  1381. paraloc1.init;
  1382. paraloc2.init;
  1383. paraloc3.init;
  1384. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1385. paramanager.getintparaloc(pocall_default,2,paraloc2);
  1386. paramanager.getintparaloc(pocall_default,3,paraloc3);
  1387. paramanager.allocparaloc(list,paraloc3);
  1388. a_param_const(list,OS_INT,len,paraloc3);
  1389. paramanager.allocparaloc(list,paraloc2);
  1390. a_paramaddr_ref(list,dest,paraloc2);
  1391. paramanager.allocparaloc(list,paraloc2);
  1392. a_paramaddr_ref(list,source,paraloc1);
  1393. paramanager.freeparaloc(list,paraloc3);
  1394. paramanager.freeparaloc(list,paraloc2);
  1395. paramanager.freeparaloc(list,paraloc1);
  1396. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1397. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1398. a_call_name(list,'FPC_MOVE');
  1399. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1400. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1401. paraloc3.done;
  1402. paraloc2.done;
  1403. paraloc1.done;
  1404. end;
  1405. procedure tcgarm.g_concatcopy_internal(list : TAsmList;const source,dest : treference;len : aint;aligned : boolean);
  1406. const
  1407. maxtmpreg=10;{roozbeh: can be reduced to 8 or lower if might conflick with reserved ones,also +2 is used becouse of regs required for referencing}
  1408. var
  1409. srcref,dstref,usedtmpref,usedtmpref2:treference;
  1410. srcreg,destreg,countreg,r,tmpreg:tregister;
  1411. helpsize:aint;
  1412. copysize:byte;
  1413. cgsize:Tcgsize;
  1414. tmpregisters:array[1..maxtmpreg] of tregister;
  1415. tmpregi,tmpregi2:byte;
  1416. { will never be called with count<=4 }
  1417. procedure genloop(count : aword;size : byte);
  1418. const
  1419. size2opsize : array[1..4] of tcgsize = (OS_8,OS_16,OS_NO,OS_32);
  1420. var
  1421. l : tasmlabel;
  1422. begin
  1423. current_asmdata.getjumplabel(l);
  1424. if count<size then size:=1;
  1425. a_load_const_reg(list,OS_INT,count div size,countreg);
  1426. cg.a_label(list,l);
  1427. srcref.addressmode:=AM_POSTINDEXED;
  1428. dstref.addressmode:=AM_POSTINDEXED;
  1429. srcref.offset:=size;
  1430. dstref.offset:=size;
  1431. r:=getintregister(list,size2opsize[size]);
  1432. a_load_ref_reg(list,size2opsize[size],size2opsize[size],srcref,r);
  1433. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,countreg,countreg,1),PF_S));
  1434. a_load_reg_ref(list,size2opsize[size],size2opsize[size],r,dstref);
  1435. a_jmp_flags(list,F_NE,l);
  1436. srcref.offset:=1;
  1437. dstref.offset:=1;
  1438. case count mod size of
  1439. 1:
  1440. begin
  1441. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1442. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1443. end;
  1444. 2:
  1445. if aligned then
  1446. begin
  1447. a_load_ref_reg(list,OS_16,OS_16,srcref,r);
  1448. a_load_reg_ref(list,OS_16,OS_16,r,dstref);
  1449. end
  1450. else
  1451. begin
  1452. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1453. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1454. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1455. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1456. end;
  1457. 3:
  1458. if aligned then
  1459. begin
  1460. srcref.offset:=2;
  1461. dstref.offset:=2;
  1462. a_load_ref_reg(list,OS_16,OS_16,srcref,r);
  1463. a_load_reg_ref(list,OS_16,OS_16,r,dstref);
  1464. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1465. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1466. end
  1467. else
  1468. begin
  1469. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1470. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1471. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1472. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1473. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1474. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1475. end;
  1476. end;
  1477. { keep the registers alive }
  1478. list.concat(taicpu.op_reg_reg(A_MOV,countreg,countreg));
  1479. list.concat(taicpu.op_reg_reg(A_MOV,srcreg,srcreg));
  1480. list.concat(taicpu.op_reg_reg(A_MOV,destreg,destreg));
  1481. end;
  1482. begin
  1483. if len=0 then
  1484. exit;
  1485. helpsize:=12+maxtmpreg*4;//52 with maxtmpreg=10
  1486. dstref:=dest;
  1487. srcref:=source;
  1488. if cs_opt_size in current_settings.optimizerswitches then
  1489. helpsize:=8;
  1490. if (len<=helpsize) and aligned then
  1491. begin
  1492. tmpregi:=0;
  1493. srcreg:=getintregister(list,OS_ADDR);
  1494. { explicit pc relative addressing, could be
  1495. e.g. a floating point constant }
  1496. if source.base=NR_PC then
  1497. begin
  1498. { ... then we don't need a loadaddr }
  1499. srcref:=source;
  1500. end
  1501. else
  1502. begin
  1503. a_loadaddr_ref_reg(list,source,srcreg);
  1504. reference_reset_base(srcref,srcreg,0);
  1505. end;
  1506. while (len div 4 <> 0) and (tmpregi<maxtmpreg) do
  1507. begin
  1508. inc(tmpregi);
  1509. tmpregisters[tmpregi]:=getintregister(list,OS_32);
  1510. a_load_ref_reg(list,OS_32,OS_32,srcref,tmpregisters[tmpregi]);
  1511. inc(srcref.offset,4);
  1512. dec(len,4);
  1513. end;
  1514. destreg:=getintregister(list,OS_ADDR);
  1515. a_loadaddr_ref_reg(list,dest,destreg);
  1516. reference_reset_base(dstref,destreg,0);
  1517. tmpregi2:=1;
  1518. while (tmpregi2<=tmpregi) do
  1519. begin
  1520. a_load_reg_ref(list,OS_32,OS_32,tmpregisters[tmpregi2],dstref);
  1521. inc(dstref.offset,4);
  1522. inc(tmpregi2);
  1523. end;
  1524. copysize:=4;
  1525. cgsize:=OS_32;
  1526. while len<>0 do
  1527. begin
  1528. if len<2 then
  1529. begin
  1530. copysize:=1;
  1531. cgsize:=OS_8;
  1532. end
  1533. else if len<4 then
  1534. begin
  1535. copysize:=2;
  1536. cgsize:=OS_16;
  1537. end;
  1538. dec(len,copysize);
  1539. r:=getintregister(list,cgsize);
  1540. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1541. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1542. inc(srcref.offset,copysize);
  1543. inc(dstref.offset,copysize);
  1544. end;{end of while}
  1545. end
  1546. else
  1547. begin
  1548. cgsize:=OS_32;
  1549. if (len<=4) then{len<=4 and not aligned}
  1550. begin
  1551. r:=getintregister(list,cgsize);
  1552. usedtmpref:=a_internal_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1553. if Len=1 then
  1554. a_load_reg_ref(list,OS_8,OS_8,r,dstref)
  1555. else
  1556. begin
  1557. tmpreg:=getintregister(list,cgsize);
  1558. usedtmpref2:=a_internal_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1559. inc(usedtmpref.offset,1);
  1560. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1561. inc(usedtmpref2.offset,1);
  1562. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1563. if len>2 then
  1564. begin
  1565. inc(usedtmpref.offset,1);
  1566. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1567. inc(usedtmpref2.offset,1);
  1568. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1569. if len>3 then
  1570. begin
  1571. inc(usedtmpref.offset,1);
  1572. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1573. inc(usedtmpref2.offset,1);
  1574. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1575. end;
  1576. end;
  1577. end;
  1578. end{end of if len<=4}
  1579. else
  1580. begin{unaligned & 4<len<helpsize **or** aligned/unaligned & len>helpsize}
  1581. destreg:=getintregister(list,OS_ADDR);
  1582. a_loadaddr_ref_reg(list,dest,destreg);
  1583. reference_reset_base(dstref,destreg,0);
  1584. srcreg:=getintregister(list,OS_ADDR);
  1585. a_loadaddr_ref_reg(list,source,srcreg);
  1586. reference_reset_base(srcref,srcreg,0);
  1587. countreg:=getintregister(list,OS_32);
  1588. // if cs_opt_size in current_settings.optimizerswitches then
  1589. { roozbeh : it seems loading 1 byte is faster becouse of caching/fetching(?) }
  1590. {if aligned then
  1591. genloop(len,4)
  1592. else}
  1593. genloop(len,1);
  1594. end;
  1595. end;
  1596. end;
  1597. procedure tcgarm.g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : aint);
  1598. begin
  1599. g_concatcopy_internal(list,source,dest,len,false);
  1600. end;
  1601. procedure tcgarm.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1602. begin
  1603. if (source.alignment in [1..3]) or
  1604. (dest.alignment in [1..3]) then
  1605. g_concatcopy_internal(list,source,dest,len,false)
  1606. else
  1607. g_concatcopy_internal(list,source,dest,len,true);
  1608. end;
  1609. procedure tcgarm.g_overflowCheck(list : TAsmList;const l : tlocation;def : tdef);
  1610. var
  1611. ovloc : tlocation;
  1612. begin
  1613. ovloc.loc:=LOC_VOID;
  1614. g_overflowCheck_loc(list,l,def,ovloc);
  1615. end;
  1616. procedure tcgarm.g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1617. var
  1618. hl : tasmlabel;
  1619. ai:TAiCpu;
  1620. hflags : tresflags;
  1621. begin
  1622. if not(cs_check_overflow in current_settings.localswitches) then
  1623. exit;
  1624. current_asmdata.getjumplabel(hl);
  1625. case ovloc.loc of
  1626. LOC_VOID:
  1627. begin
  1628. ai:=taicpu.op_sym(A_B,hl);
  1629. ai.is_jmp:=true;
  1630. if not((def.typ=pointerdef) or
  1631. ((def.typ=orddef) and
  1632. (torddef(def).ordtype in [u64bit,u16bit,u32bit,u8bit,uchar,bool8bit,bool16bit,bool32bit]))) then
  1633. ai.SetCondition(C_VC)
  1634. else
  1635. if TAiCpu(List.Last).opcode in [A_RSB,A_RSC,A_SBC,A_SUB] then
  1636. ai.SetCondition(C_CS)
  1637. else
  1638. ai.SetCondition(C_CC);
  1639. list.concat(ai);
  1640. end;
  1641. LOC_FLAGS:
  1642. begin
  1643. hflags:=ovloc.resflags;
  1644. inverse_flags(hflags);
  1645. cg.a_jmp_flags(list,hflags,hl);
  1646. end;
  1647. else
  1648. internalerror(200409281);
  1649. end;
  1650. a_call_name(list,'FPC_OVERFLOW');
  1651. a_label(list,hl);
  1652. end;
  1653. procedure tcgarm.g_save_standard_registers(list : TAsmList);
  1654. begin
  1655. { this work is done in g_proc_entry }
  1656. end;
  1657. procedure tcgarm.g_restore_standard_registers(list : TAsmList);
  1658. begin
  1659. { this work is done in g_proc_exit }
  1660. end;
  1661. procedure tcgarm.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  1662. var
  1663. ai : taicpu;
  1664. begin
  1665. ai:=Taicpu.Op_sym(A_B,l);
  1666. ai.SetCondition(OpCmp2AsmCond[cond]);
  1667. ai.is_jmp:=true;
  1668. list.concat(ai);
  1669. end;
  1670. procedure tcgarm.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1671. procedure loadvmttor12;
  1672. var
  1673. href : treference;
  1674. begin
  1675. reference_reset_base(href,NR_R0,0);
  1676. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R12);
  1677. end;
  1678. procedure op_onr12methodaddr;
  1679. var
  1680. href : treference;
  1681. begin
  1682. if (procdef.extnumber=$ffff) then
  1683. Internalerror(200006139);
  1684. { call/jmp vmtoffs(%eax) ; method offs }
  1685. reference_reset_base(href,NR_R12,procdef._class.vmtmethodoffset(procdef.extnumber));
  1686. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R12);
  1687. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,NR_R12));
  1688. end;
  1689. var
  1690. make_global : boolean;
  1691. begin
  1692. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1693. Internalerror(200006137);
  1694. if not assigned(procdef._class) or
  1695. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1696. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1697. Internalerror(200006138);
  1698. if procdef.owner.symtabletype<>ObjectSymtable then
  1699. Internalerror(200109191);
  1700. make_global:=false;
  1701. if (not current_module.is_unit) or
  1702. create_smartlink or
  1703. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1704. make_global:=true;
  1705. if make_global then
  1706. list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1707. else
  1708. list.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1709. { set param1 interface to self }
  1710. g_adjust_self_value(list,procdef,ioffset);
  1711. { case 4 }
  1712. if po_virtualmethod in procdef.procoptions then
  1713. begin
  1714. loadvmttor12;
  1715. op_onr12methodaddr;
  1716. end
  1717. { case 0 }
  1718. else
  1719. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)));
  1720. list.concat(Tai_symbol_end.Createname(labelname));
  1721. end;
  1722. procedure tcg64farm.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1723. begin
  1724. case op of
  1725. OP_NEG:
  1726. begin
  1727. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_RSB,regdst.reglo,regsrc.reglo,0),PF_S));
  1728. list.concat(taicpu.op_reg_reg_const(A_RSC,regdst.reghi,regsrc.reghi,0));
  1729. end;
  1730. OP_NOT:
  1731. begin
  1732. cg.a_op_reg_reg(list,OP_NOT,OS_INT,regsrc.reglo,regdst.reglo);
  1733. cg.a_op_reg_reg(list,OP_NOT,OS_INT,regsrc.reghi,regdst.reghi);
  1734. end;
  1735. else
  1736. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1737. end;
  1738. end;
  1739. procedure tcg64farm.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1740. begin
  1741. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1742. end;
  1743. procedure tcg64farm.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1744. var
  1745. ovloc : tlocation;
  1746. begin
  1747. a_op64_const_reg_reg_checkoverflow(list,op,size,value,regsrc,regdst,false,ovloc);
  1748. end;
  1749. procedure tcg64farm.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1750. var
  1751. ovloc : tlocation;
  1752. begin
  1753. a_op64_reg_reg_reg_checkoverflow(list,op,size,regsrc1,regsrc2,regdst,false,ovloc);
  1754. end;
  1755. procedure tcg64farm.a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1756. var
  1757. tmpreg : tregister;
  1758. b : byte;
  1759. begin
  1760. ovloc.loc:=LOC_VOID;
  1761. case op of
  1762. OP_NEG,
  1763. OP_NOT :
  1764. internalerror(200306017);
  1765. end;
  1766. if (setflags or tcgarm(cg).cgsetflags) and (op in [OP_ADD,OP_SUB]) then
  1767. begin
  1768. case op of
  1769. OP_ADD:
  1770. begin
  1771. if is_shifter_const(lo(value),b) then
  1772. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADD,regdst.reglo,regsrc.reglo,lo(value)),PF_S))
  1773. else
  1774. begin
  1775. tmpreg:=cg.getintregister(list,OS_32);
  1776. cg.a_load_const_reg(list,OS_32,lo(value),tmpreg);
  1777. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1778. end;
  1779. if is_shifter_const(hi(value),b) then
  1780. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADC,regdst.reghi,regsrc.reghi,hi(value)),PF_S))
  1781. else
  1782. begin
  1783. tmpreg:=cg.getintregister(list,OS_32);
  1784. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1785. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc.reghi,tmpreg),PF_S));
  1786. end;
  1787. end;
  1788. OP_SUB:
  1789. begin
  1790. if is_shifter_const(lo(value),b) then
  1791. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,regdst.reglo,regsrc.reglo,lo(value)),PF_S))
  1792. else
  1793. begin
  1794. tmpreg:=cg.getintregister(list,OS_32);
  1795. cg.a_load_const_reg(list,OS_32,lo(value),tmpreg);
  1796. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1797. end;
  1798. if is_shifter_const(hi(value),b) then
  1799. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SBC,regdst.reghi,regsrc.reghi,aint(hi(value))),PF_S))
  1800. else
  1801. begin
  1802. tmpreg:=cg.getintregister(list,OS_32);
  1803. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1804. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc.reghi,tmpreg),PF_S));
  1805. end;
  1806. end;
  1807. else
  1808. internalerror(200502131);
  1809. end;
  1810. if size=OS_64 then
  1811. begin
  1812. { the arm has an weired opinion how flags for SUB/ADD are handled }
  1813. ovloc.loc:=LOC_FLAGS;
  1814. case op of
  1815. OP_ADD:
  1816. ovloc.resflags:=F_CS;
  1817. OP_SUB:
  1818. ovloc.resflags:=F_CC;
  1819. end;
  1820. end;
  1821. end
  1822. else
  1823. begin
  1824. case op of
  1825. OP_AND,OP_OR,OP_XOR:
  1826. begin
  1827. cg.a_op_const_reg_reg(list,op,OS_32,aint(lo(value)),regsrc.reglo,regdst.reglo);
  1828. cg.a_op_const_reg_reg(list,op,OS_32,aint(hi(value)),regsrc.reghi,regdst.reghi);
  1829. end;
  1830. OP_ADD:
  1831. begin
  1832. if is_shifter_const(aint(lo(value)),b) then
  1833. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADD,regdst.reglo,regsrc.reglo,aint(lo(value))),PF_S))
  1834. else
  1835. begin
  1836. tmpreg:=cg.getintregister(list,OS_32);
  1837. cg.a_load_const_reg(list,OS_32,aint(lo(value)),tmpreg);
  1838. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1839. end;
  1840. if is_shifter_const(aint(hi(value)),b) then
  1841. list.concat(taicpu.op_reg_reg_const(A_ADC,regdst.reghi,regsrc.reghi,aint(hi(value))))
  1842. else
  1843. begin
  1844. tmpreg:=cg.getintregister(list,OS_32);
  1845. cg.a_load_const_reg(list,OS_32,aint(hi(value)),tmpreg);
  1846. list.concat(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc.reghi,tmpreg));
  1847. end;
  1848. end;
  1849. OP_SUB:
  1850. begin
  1851. if is_shifter_const(aint(lo(value)),b) then
  1852. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,regdst.reglo,regsrc.reglo,aint(lo(value))),PF_S))
  1853. else
  1854. begin
  1855. tmpreg:=cg.getintregister(list,OS_32);
  1856. cg.a_load_const_reg(list,OS_32,aint(lo(value)),tmpreg);
  1857. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1858. end;
  1859. if is_shifter_const(aint(hi(value)),b) then
  1860. list.concat(taicpu.op_reg_reg_const(A_SBC,regdst.reghi,regsrc.reghi,aint(hi(value))))
  1861. else
  1862. begin
  1863. tmpreg:=cg.getintregister(list,OS_32);
  1864. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1865. list.concat(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc.reghi,tmpreg));
  1866. end;
  1867. end;
  1868. else
  1869. internalerror(2003083101);
  1870. end;
  1871. end;
  1872. end;
  1873. procedure tcg64farm.a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1874. begin
  1875. ovloc.loc:=LOC_VOID;
  1876. case op of
  1877. OP_NEG,
  1878. OP_NOT :
  1879. internalerror(200306017);
  1880. end;
  1881. if (setflags or tcgarm(cg).cgsetflags) and (op in [OP_ADD,OP_SUB]) then
  1882. begin
  1883. case op of
  1884. OP_ADD:
  1885. begin
  1886. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc1.reglo,regsrc2.reglo),PF_S));
  1887. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc1.reghi,regsrc2.reghi),PF_S));
  1888. end;
  1889. OP_SUB:
  1890. begin
  1891. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc2.reglo,regsrc1.reglo),PF_S));
  1892. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc2.reghi,regsrc1.reghi),PF_S));
  1893. end;
  1894. else
  1895. internalerror(2003083101);
  1896. end;
  1897. if size=OS_64 then
  1898. begin
  1899. { the arm has an weired opinion how flags for SUB/ADD are handled }
  1900. ovloc.loc:=LOC_FLAGS;
  1901. case op of
  1902. OP_ADD:
  1903. ovloc.resflags:=F_CS;
  1904. OP_SUB:
  1905. ovloc.resflags:=F_CC;
  1906. end;
  1907. end;
  1908. end
  1909. else
  1910. begin
  1911. case op of
  1912. OP_AND,OP_OR,OP_XOR:
  1913. begin
  1914. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1915. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1916. end;
  1917. OP_ADD:
  1918. begin
  1919. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc1.reglo,regsrc2.reglo),PF_S));
  1920. list.concat(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1921. end;
  1922. OP_SUB:
  1923. begin
  1924. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc2.reglo,regsrc1.reglo),PF_S));
  1925. list.concat(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc2.reghi,regsrc1.reghi));
  1926. end;
  1927. else
  1928. internalerror(2003083101);
  1929. end;
  1930. end;
  1931. end;
  1932. begin
  1933. cg:=tcgarm.create;
  1934. cg64:=tcg64farm.create;
  1935. end.