cgcpu.pas 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  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_registers(list : TAsmList);override;
  77. procedure g_restore_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. dir : integer;
  689. begin
  690. if (TCGSize2Size[FromSize] >= TCGSize2Size[ToSize]) then
  691. FromSize := ToSize;
  692. case ToSize of
  693. { signed integer registers }
  694. OS_8,
  695. OS_S8:
  696. oppostfix:=PF_B;
  697. OS_16,
  698. OS_S16:
  699. oppostfix:=PF_H;
  700. OS_32,
  701. OS_S32:
  702. oppostfix:=PF_None;
  703. else
  704. InternalError(200308295);
  705. end;
  706. if ref.alignment<>0 then
  707. begin
  708. if target_info.endian=endian_big then
  709. dir:=-1
  710. else
  711. dir:=1;
  712. case FromSize of
  713. OS_16,OS_S16:
  714. begin
  715. shifterop_reset(so);so.shiftmode:=SM_LSR;so.shiftimm:=8;
  716. tmpreg:=getintregister(list,OS_INT);
  717. usedtmpref:=ref;
  718. if target_info.endian=endian_big then
  719. inc(usedtmpref.offset,1);
  720. usedtmpref:=a_internal_load_reg_ref(list,OS_8,OS_8,reg,usedtmpref);
  721. inc(usedtmpref.offset,dir);
  722. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,reg,so));
  723. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  724. end;
  725. OS_32,OS_S32:
  726. begin
  727. shifterop_reset(so);so.shiftmode:=SM_LSR;so.shiftimm:=8;
  728. tmpreg:=getintregister(list,OS_INT);
  729. usedtmpref:=ref;
  730. if target_info.endian=endian_big then
  731. inc(usedtmpref.offset,3);
  732. usedtmpref:=a_internal_load_reg_ref(list,OS_8,OS_8,reg,usedtmpref);
  733. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,reg,so));
  734. inc(usedtmpref.offset,dir);
  735. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  736. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,tmpreg,so));
  737. inc(usedtmpref.offset,dir);
  738. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  739. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,tmpreg,tmpreg,so));
  740. inc(usedtmpref.offset,dir);
  741. a_internal_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref);
  742. end
  743. else
  744. handle_load_store(list,A_STR,oppostfix,reg,ref);
  745. end;
  746. end
  747. else
  748. handle_load_store(list,A_STR,oppostfix,reg,ref);
  749. end;
  750. procedure tcgarm.a_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);
  751. var
  752. oppostfix:toppostfix;
  753. usedtmpref: treference;
  754. tmpreg,tmpreg2,tmpreg3 : tregister;
  755. so : tshifterop;
  756. dir : integer;
  757. begin
  758. if (TCGSize2Size[FromSize] >= TCGSize2Size[ToSize]) then
  759. FromSize := ToSize;
  760. case FromSize of
  761. { signed integer registers }
  762. OS_8:
  763. oppostfix:=PF_B;
  764. OS_S8:
  765. oppostfix:=PF_SB;
  766. OS_16:
  767. oppostfix:=PF_H;
  768. OS_S16:
  769. oppostfix:=PF_SH;
  770. OS_32,
  771. OS_S32:
  772. oppostfix:=PF_None;
  773. else
  774. InternalError(200308297);
  775. end;
  776. if Ref.alignment<>0 then
  777. begin
  778. if target_info.endian=endian_big then
  779. dir:=-1
  780. else
  781. dir:=1;
  782. case FromSize of
  783. OS_16,OS_S16:
  784. begin
  785. { only complicated references need an extra loadaddr }
  786. if assigned(ref.symbol) or
  787. (ref.index<>NR_NO) or
  788. (ref.offset<-4095) or
  789. (ref.offset>4094) or
  790. { sometimes the compiler reused registers }
  791. (reg=ref.index) or
  792. (reg=ref.base) then
  793. begin
  794. tmpreg3:=getintregister(list,OS_INT);
  795. a_loadaddr_ref_reg(list,ref,tmpreg3);
  796. reference_reset_base(usedtmpref,tmpreg3,0);
  797. end
  798. else
  799. usedtmpref:=ref;
  800. if target_info.endian=endian_big then
  801. inc(usedtmpref.offset,1);
  802. shifterop_reset(so);so.shiftmode:=SM_LSL;so.shiftimm:=8;
  803. tmpreg:=getintregister(list,OS_INT);
  804. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  805. inc(usedtmpref.offset,dir);
  806. tmpreg2:=getintregister(list,OS_INT);
  807. if FromSize=OS_16 then
  808. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg2)
  809. else
  810. a_internal_load_ref_reg(list,OS_S8,OS_S8,usedtmpref,tmpreg2);
  811. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,reg,tmpreg,tmpreg2,so));
  812. end;
  813. OS_32,OS_S32:
  814. begin
  815. tmpreg:=getintregister(list,OS_INT);
  816. tmpreg2:=getintregister(list,OS_INT);
  817. { only complicated references need an extra loadaddr }
  818. if assigned(ref.symbol) or
  819. (ref.index<>NR_NO) or
  820. (ref.offset<-4095) or
  821. (ref.offset>4092) or
  822. { sometimes the compiler reused registers }
  823. (reg=ref.index) or
  824. (reg=ref.base) then
  825. begin
  826. tmpreg3:=getintregister(list,OS_INT);
  827. a_loadaddr_ref_reg(list,ref,tmpreg3);
  828. reference_reset_base(usedtmpref,tmpreg3,0);
  829. end
  830. else
  831. usedtmpref:=ref;
  832. if target_info.endian=endian_big then
  833. inc(usedtmpref.offset,3);
  834. shifterop_reset(so);so.shiftmode:=SM_LSL;so.shiftimm:=8;
  835. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,reg);
  836. inc(usedtmpref.offset,dir);
  837. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  838. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,tmpreg2,reg,tmpreg,so));
  839. inc(usedtmpref.offset,dir);
  840. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,reg);
  841. so.shiftimm:=16;
  842. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,tmpreg,tmpreg2,reg,so));
  843. inc(usedtmpref.offset,dir);
  844. a_internal_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg2);
  845. so.shiftimm:=24;
  846. list.concat(taicpu.op_reg_reg_reg_shifterop(A_ORR,reg,tmpreg,tmpreg2,so));
  847. end
  848. else
  849. handle_load_store(list,A_LDR,oppostfix,reg,ref);
  850. end;
  851. end
  852. else
  853. handle_load_store(list,A_LDR,oppostfix,reg,ref);
  854. end;
  855. function tcgarm.a_internal_load_reg_ref(list : TAsmList; fromsize, tosize: tcgsize; reg : tregister;const ref : treference):treference;
  856. var
  857. oppostfix:toppostfix;
  858. begin
  859. case ToSize of
  860. { signed integer registers }
  861. OS_8,
  862. OS_S8:
  863. oppostfix:=PF_B;
  864. OS_16,
  865. OS_S16:
  866. oppostfix:=PF_H;
  867. OS_32,
  868. OS_S32:
  869. oppostfix:=PF_None;
  870. else
  871. InternalError(2003082910);
  872. end;
  873. result:=handle_load_store(list,A_STR,oppostfix,reg,ref);
  874. end;
  875. function tcgarm.a_internal_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister):treference;
  876. var
  877. oppostfix:toppostfix;
  878. begin
  879. case FromSize of
  880. { signed integer registers }
  881. OS_8:
  882. oppostfix:=PF_B;
  883. OS_S8:
  884. oppostfix:=PF_SB;
  885. OS_16:
  886. oppostfix:=PF_H;
  887. OS_S16:
  888. oppostfix:=PF_SH;
  889. OS_32,
  890. OS_S32:
  891. oppostfix:=PF_None;
  892. else
  893. InternalError(200308291);
  894. end;
  895. result:=handle_load_store(list,A_LDR,oppostfix,reg,ref);
  896. end;
  897. procedure tcgarm.a_load_reg_reg(list : TAsmList; fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  898. var
  899. so : tshifterop;
  900. conv_done: boolean;
  901. procedure do_shift(shiftmode : tshiftmode; shiftimm : byte; reg : tregister);
  902. begin
  903. so.shiftmode:=shiftmode;
  904. so.shiftimm:=shiftimm;
  905. list.concat(taicpu.op_reg_reg_shifterop(A_MOV,reg2,reg,so));
  906. end;
  907. function do_conv(size : tcgsize) : boolean;
  908. begin
  909. result:=true;
  910. case size of
  911. OS_8:
  912. list.concat(taicpu.op_reg_reg_const(A_AND,reg2,reg1,$ff));
  913. OS_S8:
  914. begin
  915. do_shift(SM_LSL,24,reg1);
  916. do_shift(SM_ASR,24,reg2);
  917. end;
  918. OS_16,OS_S16:
  919. begin
  920. do_shift(SM_LSL,16,reg1);
  921. if size=OS_S16 then
  922. do_shift(SM_ASR,16,reg2)
  923. else
  924. do_shift(SM_LSR,16,reg2);
  925. end;
  926. else
  927. result:=false;
  928. end;
  929. conv_done:=result;
  930. end;
  931. var
  932. instr: taicpu;
  933. begin
  934. conv_done:=false;
  935. if tosize<>fromsize then
  936. begin
  937. shifterop_reset(so);
  938. if not do_conv(tosize) then
  939. if tosize in [OS_32,OS_S32] then
  940. do_conv(fromsize)
  941. else
  942. internalerror(2002090901);
  943. end;
  944. if not conv_done and (reg1<>reg2) then
  945. begin
  946. { same size, only a register mov required }
  947. instr:=taicpu.op_reg_reg(A_MOV,reg2,reg1);
  948. list.Concat(instr);
  949. { Notify the register allocator that we have written a move instruction so
  950. it can try to eliminate it. }
  951. add_move_instruction(instr);
  952. end;
  953. end;
  954. procedure tcgarm.a_paramfpu_ref(list : TAsmList;size : tcgsize;const ref : treference;const paraloc : TCGPara);
  955. var
  956. href,href2 : treference;
  957. hloc : pcgparalocation;
  958. begin
  959. href:=ref;
  960. hloc:=paraloc.location;
  961. while assigned(hloc) do
  962. begin
  963. case hloc^.loc of
  964. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  965. a_loadfpu_ref_reg(list,size,size,ref,hloc^.register);
  966. LOC_REGISTER :
  967. case hloc^.size of
  968. OS_F32:
  969. a_load_ref_reg(list,OS_32,OS_32,href,hloc^.register);
  970. OS_64,
  971. OS_F64:
  972. cg64.a_param64_ref(list,href,paraloc);
  973. else
  974. a_load_ref_reg(list,hloc^.size,hloc^.size,href,hloc^.register);
  975. end;
  976. LOC_REFERENCE :
  977. begin
  978. reference_reset_base(href2,hloc^.reference.index,hloc^.reference.offset);
  979. { concatcopy should choose the best way to copy the data }
  980. g_concatcopy(list,href,href2,tcgsize2size[size]);
  981. end;
  982. else
  983. internalerror(200408241);
  984. end;
  985. inc(href.offset,tcgsize2size[hloc^.size]);
  986. hloc:=hloc^.next;
  987. end;
  988. end;
  989. procedure tcgarm.a_loadfpu_reg_reg(list: TAsmList; fromsize,tosize: tcgsize; reg1, reg2: tregister);
  990. begin
  991. list.concat(setoppostfix(taicpu.op_reg_reg(A_MVF,reg2,reg1),cgsize2fpuoppostfix[tosize]));
  992. end;
  993. procedure tcgarm.a_loadfpu_ref_reg(list: TAsmList; fromsize,tosize: tcgsize; const ref: treference; reg: tregister);
  994. var
  995. oppostfix:toppostfix;
  996. begin
  997. case tosize of
  998. OS_32,
  999. OS_F32:
  1000. oppostfix:=PF_S;
  1001. OS_64,
  1002. OS_F64:
  1003. oppostfix:=PF_D;
  1004. OS_F80:
  1005. oppostfix:=PF_E;
  1006. else
  1007. InternalError(200309021);
  1008. end;
  1009. handle_load_store(list,A_LDF,oppostfix,reg,ref);
  1010. end;
  1011. procedure tcgarm.a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference);
  1012. var
  1013. oppostfix:toppostfix;
  1014. begin
  1015. case tosize of
  1016. OS_F32:
  1017. oppostfix:=PF_S;
  1018. OS_F64:
  1019. oppostfix:=PF_D;
  1020. OS_F80:
  1021. oppostfix:=PF_E;
  1022. else
  1023. InternalError(200309022);
  1024. end;
  1025. handle_load_store(list,A_STF,oppostfix,reg,ref);
  1026. end;
  1027. { comparison operations }
  1028. procedure tcgarm.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  1029. l : tasmlabel);
  1030. var
  1031. tmpreg : tregister;
  1032. b : byte;
  1033. begin
  1034. if is_shifter_const(a,b) then
  1035. list.concat(taicpu.op_reg_const(A_CMP,reg,a))
  1036. { CMN reg,0 and CMN reg,$80000000 are different from CMP reg,$ffffffff
  1037. and CMP reg,$7fffffff regarding the flags according to the ARM manual }
  1038. else if (a<>$7fffffff) and (a<>-1) and is_shifter_const(-a,b) then
  1039. list.concat(taicpu.op_reg_const(A_CMN,reg,-a))
  1040. else
  1041. begin
  1042. tmpreg:=getintregister(list,size);
  1043. a_load_const_reg(list,size,a,tmpreg);
  1044. list.concat(taicpu.op_reg_reg(A_CMP,reg,tmpreg));
  1045. end;
  1046. a_jmp_cond(list,cmp_op,l);
  1047. end;
  1048. procedure tcgarm.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel);
  1049. begin
  1050. list.concat(taicpu.op_reg_reg(A_CMP,reg2,reg1));
  1051. a_jmp_cond(list,cmp_op,l);
  1052. end;
  1053. procedure tcgarm.a_jmp_name(list : TAsmList;const s : string);
  1054. var
  1055. ai : taicpu;
  1056. begin
  1057. ai:=taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  1058. ai.is_jmp:=true;
  1059. list.concat(ai);
  1060. end;
  1061. procedure tcgarm.a_jmp_always(list : TAsmList;l: tasmlabel);
  1062. var
  1063. ai : taicpu;
  1064. begin
  1065. ai:=taicpu.op_sym(A_B,l);
  1066. ai.is_jmp:=true;
  1067. list.concat(ai);
  1068. end;
  1069. procedure tcgarm.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  1070. var
  1071. ai : taicpu;
  1072. begin
  1073. ai:=setcondition(taicpu.op_sym(A_B,l),flags_to_cond(f));
  1074. ai.is_jmp:=true;
  1075. list.concat(ai);
  1076. end;
  1077. procedure tcgarm.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  1078. begin
  1079. list.concat(setcondition(taicpu.op_reg_const(A_MOV,reg,1),flags_to_cond(f)));
  1080. list.concat(setcondition(taicpu.op_reg_const(A_MOV,reg,0),inverse_cond(flags_to_cond(f))));
  1081. end;
  1082. procedure tcgarm.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  1083. var
  1084. ref : treference;
  1085. shift : byte;
  1086. firstfloatreg,lastfloatreg,
  1087. r : byte;
  1088. regs : tcpuregisterset;
  1089. begin
  1090. LocalSize:=align(LocalSize,4);
  1091. if not(nostackframe) then
  1092. begin
  1093. firstfloatreg:=RS_NO;
  1094. { save floating point registers? }
  1095. for r:=RS_F0 to RS_F7 do
  1096. if r in rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall) then
  1097. begin
  1098. if firstfloatreg=RS_NO then
  1099. firstfloatreg:=r;
  1100. lastfloatreg:=r;
  1101. end;
  1102. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1103. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1104. begin
  1105. a_reg_alloc(list,NR_FRAME_POINTER_REG);
  1106. a_reg_alloc(list,NR_R12);
  1107. list.concat(taicpu.op_reg_reg(A_MOV,NR_R12,NR_STACK_POINTER_REG));
  1108. end;
  1109. { save int registers }
  1110. reference_reset(ref);
  1111. ref.index:=NR_STACK_POINTER_REG;
  1112. ref.addressmode:=AM_PREINDEXED;
  1113. regs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1114. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1115. regs:=regs+[RS_R11,RS_R12,RS_R14,RS_R15]
  1116. else
  1117. if (regs<>[]) or (pi_do_call in current_procinfo.flags) then
  1118. include(regs,RS_R14);
  1119. if regs<>[] then
  1120. list.concat(setoppostfix(taicpu.op_ref_regset(A_STM,ref,regs),PF_FD));
  1121. if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1122. list.concat(taicpu.op_reg_reg_const(A_SUB,NR_FRAME_POINTER_REG,NR_R12,4));
  1123. { allocate necessary stack size
  1124. not necessary according to Yury Sidorov
  1125. { don't use a_op_const_reg_reg here because we don't allow register allocations
  1126. in the entry/exit code }
  1127. if (target_info.system in [system_arm_wince]) and
  1128. (localsize>=winstackpagesize) then
  1129. begin
  1130. if localsize div winstackpagesize<=5 then
  1131. begin
  1132. if is_shifter_const(localsize,shift) then
  1133. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,localsize))
  1134. else
  1135. begin
  1136. a_load_const_reg(list,OS_ADDR,localsize,NR_R12);
  1137. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1138. end;
  1139. for i:=1 to localsize div winstackpagesize do
  1140. begin
  1141. if localsize-i*winstackpagesize<4096 then
  1142. reference_reset_base(href,NR_STACK_POINTER_REG,-(localsize-i*winstackpagesize))
  1143. else
  1144. begin
  1145. a_load_const_reg(list,OS_ADDR,-(localsize-i*winstackpagesize),NR_R12);
  1146. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1147. href.index:=NR_R12;
  1148. end;
  1149. { the data stored doesn't matter }
  1150. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  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. else
  1158. begin
  1159. current_asmdata.getjumplabel(again);
  1160. list.concat(Taicpu.op_reg_const(A_MOV,NR_R12,localsize div winstackpagesize));
  1161. a_label(list,again);
  1162. { always shifterop }
  1163. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,winstackpagesize));
  1164. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1165. { the data stored doesn't matter }
  1166. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1167. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_R12,NR_R12,1));
  1168. a_jmp_cond(list,OC_NE,again);
  1169. if is_shifter_const(localsize mod winstackpagesize,shift) then
  1170. list.concat(Taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,localsize mod winstackpagesize))
  1171. else
  1172. begin
  1173. a_load_const_reg(list,OS_ADDR,localsize mod winstackpagesize,NR_R12);
  1174. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1175. end;
  1176. a_reg_dealloc(list,NR_R12);
  1177. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1178. { the data stored doesn't matter }
  1179. list.concat(Taicpu.op_reg_ref(A_STR,NR_R0,href));
  1180. end
  1181. end
  1182. else
  1183. }
  1184. if LocalSize<>0 then
  1185. if not(is_shifter_const(localsize,shift)) then
  1186. begin
  1187. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  1188. a_reg_alloc(list,NR_R12);
  1189. a_load_const_reg(list,OS_ADDR,LocalSize,NR_R12);
  1190. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1191. a_reg_dealloc(list,NR_R12);
  1192. end
  1193. else
  1194. begin
  1195. a_reg_dealloc(list,NR_R12);
  1196. list.concat(taicpu.op_reg_reg_const(A_SUB,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,LocalSize));
  1197. end;
  1198. if firstfloatreg<>RS_NO then
  1199. begin
  1200. reference_reset(ref);
  1201. if tg.direction*tarmprocinfo(current_procinfo).floatregstart>=1023 then
  1202. begin
  1203. a_load_const_reg(list,OS_ADDR,-tarmprocinfo(current_procinfo).floatregstart,NR_R12);
  1204. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_R12,current_procinfo.framepointer,NR_R12));
  1205. ref.base:=NR_R12;
  1206. end
  1207. else
  1208. begin
  1209. ref.base:=current_procinfo.framepointer;
  1210. ref.offset:=tarmprocinfo(current_procinfo).floatregstart;
  1211. end;
  1212. list.concat(taicpu.op_reg_const_ref(A_SFM,newreg(R_FPUREGISTER,firstfloatreg,R_SUBWHOLE),
  1213. lastfloatreg-firstfloatreg+1,ref));
  1214. end;
  1215. end;
  1216. end;
  1217. procedure tcgarm.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  1218. var
  1219. ref : treference;
  1220. firstfloatreg,lastfloatreg,
  1221. r : byte;
  1222. shift : byte;
  1223. regs : tcpuregisterset;
  1224. LocalSize : longint;
  1225. begin
  1226. if not(nostackframe) then
  1227. begin
  1228. { restore floating point register }
  1229. firstfloatreg:=RS_NO;
  1230. { save floating point registers? }
  1231. for r:=RS_F0 to RS_F7 do
  1232. if r in rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall) then
  1233. begin
  1234. if firstfloatreg=RS_NO then
  1235. firstfloatreg:=r;
  1236. lastfloatreg:=r;
  1237. end;
  1238. if firstfloatreg<>RS_NO then
  1239. begin
  1240. reference_reset(ref);
  1241. if tg.direction*tarmprocinfo(current_procinfo).floatregstart>=1023 then
  1242. begin
  1243. a_load_const_reg(list,OS_ADDR,-tarmprocinfo(current_procinfo).floatregstart,NR_R12);
  1244. list.concat(taicpu.op_reg_reg_reg(A_SUB,NR_R12,current_procinfo.framepointer,NR_R12));
  1245. ref.base:=NR_R12;
  1246. end
  1247. else
  1248. begin
  1249. ref.base:=current_procinfo.framepointer;
  1250. ref.offset:=tarmprocinfo(current_procinfo).floatregstart;
  1251. end;
  1252. list.concat(taicpu.op_reg_const_ref(A_LFM,newreg(R_FPUREGISTER,firstfloatreg,R_SUBWHOLE),
  1253. lastfloatreg-firstfloatreg+1,ref));
  1254. end;
  1255. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1256. begin
  1257. LocalSize:=current_procinfo.calc_stackframe_size;
  1258. if LocalSize<>0 then
  1259. if not(is_shifter_const(LocalSize,shift)) then
  1260. begin
  1261. a_reg_alloc(list,NR_R12);
  1262. a_load_const_reg(list,OS_ADDR,LocalSize,NR_R12);
  1263. list.concat(taicpu.op_reg_reg_reg(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R12));
  1264. a_reg_dealloc(list,NR_R12);
  1265. end
  1266. else
  1267. begin
  1268. list.concat(taicpu.op_reg_reg_const(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,LocalSize));
  1269. end;
  1270. regs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1271. if (pi_do_call in current_procinfo.flags) or (regs<>[]) then
  1272. begin
  1273. exclude(regs,RS_R14);
  1274. include(regs,RS_R15);
  1275. end;
  1276. if regs=[] then
  1277. list.concat(taicpu.op_reg_reg(A_MOV,NR_R15,NR_R14))
  1278. else
  1279. begin
  1280. reference_reset(ref);
  1281. ref.index:=NR_STACK_POINTER_REG;
  1282. ref.addressmode:=AM_PREINDEXED;
  1283. list.concat(setoppostfix(taicpu.op_ref_regset(A_LDM,ref,regs),PF_FD));
  1284. end;
  1285. end
  1286. else
  1287. begin
  1288. { restore int registers and return }
  1289. reference_reset(ref);
  1290. ref.index:=NR_FRAME_POINTER_REG;
  1291. 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));
  1292. end;
  1293. end
  1294. else
  1295. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,NR_R14));
  1296. end;
  1297. procedure tcgarm.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1298. var
  1299. b : byte;
  1300. tmpref : treference;
  1301. instr : taicpu;
  1302. begin
  1303. if ref.addressmode<>AM_OFFSET then
  1304. internalerror(200309071);
  1305. tmpref:=ref;
  1306. { Be sure to have a base register }
  1307. if (tmpref.base=NR_NO) then
  1308. begin
  1309. if tmpref.shiftmode<>SM_None then
  1310. internalerror(200308294);
  1311. if tmpref.signindex<0 then
  1312. internalerror(200312023);
  1313. tmpref.base:=tmpref.index;
  1314. tmpref.index:=NR_NO;
  1315. end;
  1316. if assigned(tmpref.symbol) or
  1317. not((is_shifter_const(tmpref.offset,b)) or
  1318. (is_shifter_const(-tmpref.offset,b))
  1319. ) then
  1320. fixref(list,tmpref);
  1321. { expect a base here if there is an index }
  1322. if (tmpref.base=NR_NO) and (tmpref.index<>NR_NO) then
  1323. internalerror(200312022);
  1324. if tmpref.index<>NR_NO then
  1325. begin
  1326. if tmpref.shiftmode<>SM_None then
  1327. internalerror(200312021);
  1328. if tmpref.signindex<0 then
  1329. a_op_reg_reg_reg(list,OP_SUB,OS_ADDR,tmpref.base,tmpref.index,r)
  1330. else
  1331. a_op_reg_reg_reg(list,OP_ADD,OS_ADDR,tmpref.base,tmpref.index,r);
  1332. if tmpref.offset<>0 then
  1333. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,tmpref.offset,r,r);
  1334. end
  1335. else
  1336. begin
  1337. if tmpref.base=NR_NO then
  1338. a_load_const_reg(list,OS_ADDR,tmpref.offset,r)
  1339. else
  1340. if tmpref.offset<>0 then
  1341. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,tmpref.offset,tmpref.base,r)
  1342. else
  1343. begin
  1344. instr:=taicpu.op_reg_reg(A_MOV,r,tmpref.base);
  1345. list.concat(instr);
  1346. add_move_instruction(instr);
  1347. end;
  1348. end;
  1349. end;
  1350. procedure tcgarm.fixref(list : TAsmList;var ref : treference);
  1351. var
  1352. tmpreg : tregister;
  1353. tmpref : treference;
  1354. l : tasmlabel;
  1355. begin
  1356. { absolute symbols can't be handled directly, we've to store the symbol reference
  1357. in the text segment and access it pc relative
  1358. For now, we assume that references where base or index equals to PC are already
  1359. relative, all other references are assumed to be absolute and thus they need
  1360. to be handled extra.
  1361. A proper solution would be to change refoptions to a set and store the information
  1362. if the symbol is absolute or relative there.
  1363. }
  1364. { create consts entry }
  1365. reference_reset(tmpref);
  1366. current_asmdata.getjumplabel(l);
  1367. cg.a_label(current_procinfo.aktlocaldata,l);
  1368. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  1369. if assigned(ref.symbol) then
  1370. current_procinfo.aktlocaldata.concat(tai_const.create_sym_offset(ref.symbol,ref.offset))
  1371. else
  1372. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  1373. { load consts entry }
  1374. tmpreg:=getintregister(list,OS_INT);
  1375. tmpref.symbol:=l;
  1376. tmpref.base:=NR_PC;
  1377. list.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  1378. if (ref.base<>NR_NO) then
  1379. begin
  1380. if ref.index<>NR_NO then
  1381. begin
  1382. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1383. ref.base:=tmpreg;
  1384. end
  1385. else
  1386. if ref.base<>NR_PC then
  1387. begin
  1388. ref.index:=tmpreg;
  1389. ref.shiftimm:=0;
  1390. ref.signindex:=1;
  1391. ref.shiftmode:=SM_None;
  1392. end
  1393. else
  1394. ref.base:=tmpreg;
  1395. end
  1396. else
  1397. ref.base:=tmpreg;
  1398. ref.offset:=0;
  1399. ref.symbol:=nil;
  1400. end;
  1401. procedure tcgarm.g_concatcopy_move(list : TAsmList;const source,dest : treference;len : aint);
  1402. var
  1403. paraloc1,paraloc2,paraloc3 : TCGPara;
  1404. begin
  1405. paraloc1.init;
  1406. paraloc2.init;
  1407. paraloc3.init;
  1408. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1409. paramanager.getintparaloc(pocall_default,2,paraloc2);
  1410. paramanager.getintparaloc(pocall_default,3,paraloc3);
  1411. paramanager.allocparaloc(list,paraloc3);
  1412. a_param_const(list,OS_INT,len,paraloc3);
  1413. paramanager.allocparaloc(list,paraloc2);
  1414. a_paramaddr_ref(list,dest,paraloc2);
  1415. paramanager.allocparaloc(list,paraloc2);
  1416. a_paramaddr_ref(list,source,paraloc1);
  1417. paramanager.freeparaloc(list,paraloc3);
  1418. paramanager.freeparaloc(list,paraloc2);
  1419. paramanager.freeparaloc(list,paraloc1);
  1420. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1421. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1422. a_call_name(list,'FPC_MOVE');
  1423. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1424. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1425. paraloc3.done;
  1426. paraloc2.done;
  1427. paraloc1.done;
  1428. end;
  1429. procedure tcgarm.g_concatcopy_internal(list : TAsmList;const source,dest : treference;len : aint;aligned : boolean);
  1430. const
  1431. 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}
  1432. var
  1433. srcref,dstref,usedtmpref,usedtmpref2:treference;
  1434. srcreg,destreg,countreg,r,tmpreg:tregister;
  1435. helpsize:aint;
  1436. copysize:byte;
  1437. cgsize:Tcgsize;
  1438. tmpregisters:array[1..maxtmpreg] of tregister;
  1439. tmpregi,tmpregi2:byte;
  1440. { will never be called with count<=4 }
  1441. procedure genloop(count : aword;size : byte);
  1442. const
  1443. size2opsize : array[1..4] of tcgsize = (OS_8,OS_16,OS_NO,OS_32);
  1444. var
  1445. l : tasmlabel;
  1446. begin
  1447. current_asmdata.getjumplabel(l);
  1448. if count<size then size:=1;
  1449. a_load_const_reg(list,OS_INT,count div size,countreg);
  1450. cg.a_label(list,l);
  1451. srcref.addressmode:=AM_POSTINDEXED;
  1452. dstref.addressmode:=AM_POSTINDEXED;
  1453. srcref.offset:=size;
  1454. dstref.offset:=size;
  1455. r:=getintregister(list,size2opsize[size]);
  1456. a_load_ref_reg(list,size2opsize[size],size2opsize[size],srcref,r);
  1457. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,countreg,countreg,1),PF_S));
  1458. a_load_reg_ref(list,size2opsize[size],size2opsize[size],r,dstref);
  1459. a_jmp_flags(list,F_NE,l);
  1460. srcref.offset:=1;
  1461. dstref.offset:=1;
  1462. case count mod size of
  1463. 1:
  1464. begin
  1465. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1466. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1467. end;
  1468. 2:
  1469. if aligned then
  1470. begin
  1471. a_load_ref_reg(list,OS_16,OS_16,srcref,r);
  1472. a_load_reg_ref(list,OS_16,OS_16,r,dstref);
  1473. end
  1474. else
  1475. begin
  1476. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1477. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1478. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1479. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1480. end;
  1481. 3:
  1482. if aligned then
  1483. begin
  1484. srcref.offset:=2;
  1485. dstref.offset:=2;
  1486. a_load_ref_reg(list,OS_16,OS_16,srcref,r);
  1487. a_load_reg_ref(list,OS_16,OS_16,r,dstref);
  1488. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1489. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1490. end
  1491. else
  1492. begin
  1493. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1494. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1495. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1496. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1497. a_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1498. a_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1499. end;
  1500. end;
  1501. { keep the registers alive }
  1502. list.concat(taicpu.op_reg_reg(A_MOV,countreg,countreg));
  1503. list.concat(taicpu.op_reg_reg(A_MOV,srcreg,srcreg));
  1504. list.concat(taicpu.op_reg_reg(A_MOV,destreg,destreg));
  1505. end;
  1506. begin
  1507. if len=0 then
  1508. exit;
  1509. helpsize:=12+maxtmpreg*4;//52 with maxtmpreg=10
  1510. dstref:=dest;
  1511. srcref:=source;
  1512. if cs_opt_size in current_settings.optimizerswitches then
  1513. helpsize:=8;
  1514. if (len<=helpsize) and aligned then
  1515. begin
  1516. tmpregi:=0;
  1517. srcreg:=getintregister(list,OS_ADDR);
  1518. { explicit pc relative addressing, could be
  1519. e.g. a floating point constant }
  1520. if source.base=NR_PC then
  1521. begin
  1522. { ... then we don't need a loadaddr }
  1523. srcref:=source;
  1524. end
  1525. else
  1526. begin
  1527. a_loadaddr_ref_reg(list,source,srcreg);
  1528. reference_reset_base(srcref,srcreg,0);
  1529. end;
  1530. while (len div 4 <> 0) and (tmpregi<maxtmpreg) do
  1531. begin
  1532. inc(tmpregi);
  1533. tmpregisters[tmpregi]:=getintregister(list,OS_32);
  1534. a_load_ref_reg(list,OS_32,OS_32,srcref,tmpregisters[tmpregi]);
  1535. inc(srcref.offset,4);
  1536. dec(len,4);
  1537. end;
  1538. destreg:=getintregister(list,OS_ADDR);
  1539. a_loadaddr_ref_reg(list,dest,destreg);
  1540. reference_reset_base(dstref,destreg,0);
  1541. tmpregi2:=1;
  1542. while (tmpregi2<=tmpregi) do
  1543. begin
  1544. a_load_reg_ref(list,OS_32,OS_32,tmpregisters[tmpregi2],dstref);
  1545. inc(dstref.offset,4);
  1546. inc(tmpregi2);
  1547. end;
  1548. copysize:=4;
  1549. cgsize:=OS_32;
  1550. while len<>0 do
  1551. begin
  1552. if len<2 then
  1553. begin
  1554. copysize:=1;
  1555. cgsize:=OS_8;
  1556. end
  1557. else if len<4 then
  1558. begin
  1559. copysize:=2;
  1560. cgsize:=OS_16;
  1561. end;
  1562. dec(len,copysize);
  1563. r:=getintregister(list,cgsize);
  1564. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1565. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1566. inc(srcref.offset,copysize);
  1567. inc(dstref.offset,copysize);
  1568. end;{end of while}
  1569. end
  1570. else
  1571. begin
  1572. cgsize:=OS_32;
  1573. if (len<=4) then{len<=4 and not aligned}
  1574. begin
  1575. r:=getintregister(list,cgsize);
  1576. usedtmpref:=a_internal_load_ref_reg(list,OS_8,OS_8,srcref,r);
  1577. if Len=1 then
  1578. a_load_reg_ref(list,OS_8,OS_8,r,dstref)
  1579. else
  1580. begin
  1581. tmpreg:=getintregister(list,cgsize);
  1582. usedtmpref2:=a_internal_load_reg_ref(list,OS_8,OS_8,r,dstref);
  1583. inc(usedtmpref.offset,1);
  1584. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1585. inc(usedtmpref2.offset,1);
  1586. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1587. if len>2 then
  1588. begin
  1589. inc(usedtmpref.offset,1);
  1590. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1591. inc(usedtmpref2.offset,1);
  1592. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1593. if len>3 then
  1594. begin
  1595. inc(usedtmpref.offset,1);
  1596. a_load_ref_reg(list,OS_8,OS_8,usedtmpref,tmpreg);
  1597. inc(usedtmpref2.offset,1);
  1598. a_load_reg_ref(list,OS_8,OS_8,tmpreg,usedtmpref2);
  1599. end;
  1600. end;
  1601. end;
  1602. end{end of if len<=4}
  1603. else
  1604. begin{unaligned & 4<len<helpsize **or** aligned/unaligned & len>helpsize}
  1605. destreg:=getintregister(list,OS_ADDR);
  1606. a_loadaddr_ref_reg(list,dest,destreg);
  1607. reference_reset_base(dstref,destreg,0);
  1608. srcreg:=getintregister(list,OS_ADDR);
  1609. a_loadaddr_ref_reg(list,source,srcreg);
  1610. reference_reset_base(srcref,srcreg,0);
  1611. countreg:=getintregister(list,OS_32);
  1612. // if cs_opt_size in current_settings.optimizerswitches then
  1613. { roozbeh : it seems loading 1 byte is faster becouse of caching/fetching(?) }
  1614. {if aligned then
  1615. genloop(len,4)
  1616. else}
  1617. genloop(len,1);
  1618. end;
  1619. end;
  1620. end;
  1621. procedure tcgarm.g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : aint);
  1622. begin
  1623. g_concatcopy_internal(list,source,dest,len,false);
  1624. end;
  1625. procedure tcgarm.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1626. begin
  1627. if (source.alignment in [1..3]) or
  1628. (dest.alignment in [1..3]) then
  1629. g_concatcopy_internal(list,source,dest,len,false)
  1630. else
  1631. g_concatcopy_internal(list,source,dest,len,true);
  1632. end;
  1633. procedure tcgarm.g_overflowCheck(list : TAsmList;const l : tlocation;def : tdef);
  1634. var
  1635. ovloc : tlocation;
  1636. begin
  1637. ovloc.loc:=LOC_VOID;
  1638. g_overflowCheck_loc(list,l,def,ovloc);
  1639. end;
  1640. procedure tcgarm.g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1641. var
  1642. hl : tasmlabel;
  1643. ai:TAiCpu;
  1644. hflags : tresflags;
  1645. begin
  1646. if not(cs_check_overflow in current_settings.localswitches) then
  1647. exit;
  1648. current_asmdata.getjumplabel(hl);
  1649. case ovloc.loc of
  1650. LOC_VOID:
  1651. begin
  1652. ai:=taicpu.op_sym(A_B,hl);
  1653. ai.is_jmp:=true;
  1654. if not((def.typ=pointerdef) or
  1655. ((def.typ=orddef) and
  1656. (torddef(def).ordtype in [u64bit,u16bit,u32bit,u8bit,uchar,pasbool]))) then
  1657. ai.SetCondition(C_VC)
  1658. else
  1659. if TAiCpu(List.Last).opcode in [A_RSB,A_RSC,A_SBC,A_SUB] then
  1660. ai.SetCondition(C_CS)
  1661. else
  1662. ai.SetCondition(C_CC);
  1663. list.concat(ai);
  1664. end;
  1665. LOC_FLAGS:
  1666. begin
  1667. hflags:=ovloc.resflags;
  1668. inverse_flags(hflags);
  1669. cg.a_jmp_flags(list,hflags,hl);
  1670. end;
  1671. else
  1672. internalerror(200409281);
  1673. end;
  1674. a_call_name(list,'FPC_OVERFLOW');
  1675. a_label(list,hl);
  1676. end;
  1677. procedure tcgarm.g_save_registers(list : TAsmList);
  1678. begin
  1679. { this work is done in g_proc_entry }
  1680. end;
  1681. procedure tcgarm.g_restore_registers(list : TAsmList);
  1682. begin
  1683. { this work is done in g_proc_exit }
  1684. end;
  1685. procedure tcgarm.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  1686. var
  1687. ai : taicpu;
  1688. begin
  1689. ai:=Taicpu.Op_sym(A_B,l);
  1690. ai.SetCondition(OpCmp2AsmCond[cond]);
  1691. ai.is_jmp:=true;
  1692. list.concat(ai);
  1693. end;
  1694. procedure tcgarm.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1695. procedure loadvmttor12;
  1696. var
  1697. href : treference;
  1698. begin
  1699. reference_reset_base(href,NR_R0,0);
  1700. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R12);
  1701. end;
  1702. procedure op_onr12methodaddr;
  1703. var
  1704. href : treference;
  1705. begin
  1706. if (procdef.extnumber=$ffff) then
  1707. Internalerror(200006139);
  1708. { call/jmp vmtoffs(%eax) ; method offs }
  1709. reference_reset_base(href,NR_R12,procdef._class.vmtmethodoffset(procdef.extnumber));
  1710. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R12);
  1711. list.concat(taicpu.op_reg_reg(A_MOV,NR_PC,NR_R12));
  1712. end;
  1713. var
  1714. make_global : boolean;
  1715. begin
  1716. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1717. Internalerror(200006137);
  1718. if not assigned(procdef._class) or
  1719. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1720. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1721. Internalerror(200006138);
  1722. if procdef.owner.symtabletype<>ObjectSymtable then
  1723. Internalerror(200109191);
  1724. make_global:=false;
  1725. if (not current_module.is_unit) or
  1726. create_smartlink or
  1727. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1728. make_global:=true;
  1729. if make_global then
  1730. list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1731. else
  1732. list.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1733. { set param1 interface to self }
  1734. g_adjust_self_value(list,procdef,ioffset);
  1735. { case 4 }
  1736. if po_virtualmethod in procdef.procoptions then
  1737. begin
  1738. loadvmttor12;
  1739. op_onr12methodaddr;
  1740. end
  1741. { case 0 }
  1742. else
  1743. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)));
  1744. list.concat(Tai_symbol_end.Createname(labelname));
  1745. end;
  1746. procedure tcg64farm.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1747. begin
  1748. case op of
  1749. OP_NEG:
  1750. begin
  1751. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_RSB,regdst.reglo,regsrc.reglo,0),PF_S));
  1752. list.concat(taicpu.op_reg_reg_const(A_RSC,regdst.reghi,regsrc.reghi,0));
  1753. end;
  1754. OP_NOT:
  1755. begin
  1756. cg.a_op_reg_reg(list,OP_NOT,OS_INT,regsrc.reglo,regdst.reglo);
  1757. cg.a_op_reg_reg(list,OP_NOT,OS_INT,regsrc.reghi,regdst.reghi);
  1758. end;
  1759. else
  1760. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1761. end;
  1762. end;
  1763. procedure tcg64farm.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1764. begin
  1765. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1766. end;
  1767. procedure tcg64farm.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1768. var
  1769. ovloc : tlocation;
  1770. begin
  1771. a_op64_const_reg_reg_checkoverflow(list,op,size,value,regsrc,regdst,false,ovloc);
  1772. end;
  1773. procedure tcg64farm.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1774. var
  1775. ovloc : tlocation;
  1776. begin
  1777. a_op64_reg_reg_reg_checkoverflow(list,op,size,regsrc1,regsrc2,regdst,false,ovloc);
  1778. end;
  1779. procedure tcg64farm.a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1780. var
  1781. tmpreg : tregister;
  1782. b : byte;
  1783. begin
  1784. ovloc.loc:=LOC_VOID;
  1785. case op of
  1786. OP_NEG,
  1787. OP_NOT :
  1788. internalerror(200306017);
  1789. end;
  1790. if (setflags or tcgarm(cg).cgsetflags) and (op in [OP_ADD,OP_SUB]) then
  1791. begin
  1792. case op of
  1793. OP_ADD:
  1794. begin
  1795. if is_shifter_const(lo(value),b) then
  1796. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADD,regdst.reglo,regsrc.reglo,lo(value)),PF_S))
  1797. else
  1798. begin
  1799. tmpreg:=cg.getintregister(list,OS_32);
  1800. cg.a_load_const_reg(list,OS_32,lo(value),tmpreg);
  1801. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1802. end;
  1803. if is_shifter_const(hi(value),b) then
  1804. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADC,regdst.reghi,regsrc.reghi,hi(value)),PF_S))
  1805. else
  1806. begin
  1807. tmpreg:=cg.getintregister(list,OS_32);
  1808. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1809. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc.reghi,tmpreg),PF_S));
  1810. end;
  1811. end;
  1812. OP_SUB:
  1813. begin
  1814. if is_shifter_const(lo(value),b) then
  1815. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,regdst.reglo,regsrc.reglo,lo(value)),PF_S))
  1816. else
  1817. begin
  1818. tmpreg:=cg.getintregister(list,OS_32);
  1819. cg.a_load_const_reg(list,OS_32,lo(value),tmpreg);
  1820. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1821. end;
  1822. if is_shifter_const(hi(value),b) then
  1823. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SBC,regdst.reghi,regsrc.reghi,aint(hi(value))),PF_S))
  1824. else
  1825. begin
  1826. tmpreg:=cg.getintregister(list,OS_32);
  1827. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1828. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc.reghi,tmpreg),PF_S));
  1829. end;
  1830. end;
  1831. else
  1832. internalerror(200502131);
  1833. end;
  1834. if size=OS_64 then
  1835. begin
  1836. { the arm has an weired opinion how flags for SUB/ADD are handled }
  1837. ovloc.loc:=LOC_FLAGS;
  1838. case op of
  1839. OP_ADD:
  1840. ovloc.resflags:=F_CS;
  1841. OP_SUB:
  1842. ovloc.resflags:=F_CC;
  1843. end;
  1844. end;
  1845. end
  1846. else
  1847. begin
  1848. case op of
  1849. OP_AND,OP_OR,OP_XOR:
  1850. begin
  1851. cg.a_op_const_reg_reg(list,op,OS_32,aint(lo(value)),regsrc.reglo,regdst.reglo);
  1852. cg.a_op_const_reg_reg(list,op,OS_32,aint(hi(value)),regsrc.reghi,regdst.reghi);
  1853. end;
  1854. OP_ADD:
  1855. begin
  1856. if is_shifter_const(aint(lo(value)),b) then
  1857. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_ADD,regdst.reglo,regsrc.reglo,aint(lo(value))),PF_S))
  1858. else
  1859. begin
  1860. tmpreg:=cg.getintregister(list,OS_32);
  1861. cg.a_load_const_reg(list,OS_32,aint(lo(value)),tmpreg);
  1862. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1863. end;
  1864. if is_shifter_const(aint(hi(value)),b) then
  1865. list.concat(taicpu.op_reg_reg_const(A_ADC,regdst.reghi,regsrc.reghi,aint(hi(value))))
  1866. else
  1867. begin
  1868. tmpreg:=cg.getintregister(list,OS_32);
  1869. cg.a_load_const_reg(list,OS_32,aint(hi(value)),tmpreg);
  1870. list.concat(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc.reghi,tmpreg));
  1871. end;
  1872. end;
  1873. OP_SUB:
  1874. begin
  1875. if is_shifter_const(aint(lo(value)),b) then
  1876. list.concat(setoppostfix(taicpu.op_reg_reg_const(A_SUB,regdst.reglo,regsrc.reglo,aint(lo(value))),PF_S))
  1877. else
  1878. begin
  1879. tmpreg:=cg.getintregister(list,OS_32);
  1880. cg.a_load_const_reg(list,OS_32,aint(lo(value)),tmpreg);
  1881. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc.reglo,tmpreg),PF_S));
  1882. end;
  1883. if is_shifter_const(aint(hi(value)),b) then
  1884. list.concat(taicpu.op_reg_reg_const(A_SBC,regdst.reghi,regsrc.reghi,aint(hi(value))))
  1885. else
  1886. begin
  1887. tmpreg:=cg.getintregister(list,OS_32);
  1888. cg.a_load_const_reg(list,OS_32,hi(value),tmpreg);
  1889. list.concat(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc.reghi,tmpreg));
  1890. end;
  1891. end;
  1892. else
  1893. internalerror(2003083101);
  1894. end;
  1895. end;
  1896. end;
  1897. procedure tcg64farm.a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1898. begin
  1899. ovloc.loc:=LOC_VOID;
  1900. case op of
  1901. OP_NEG,
  1902. OP_NOT :
  1903. internalerror(200306017);
  1904. end;
  1905. if (setflags or tcgarm(cg).cgsetflags) and (op in [OP_ADD,OP_SUB]) then
  1906. begin
  1907. case op of
  1908. OP_ADD:
  1909. begin
  1910. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc1.reglo,regsrc2.reglo),PF_S));
  1911. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc1.reghi,regsrc2.reghi),PF_S));
  1912. end;
  1913. OP_SUB:
  1914. begin
  1915. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc2.reglo,regsrc1.reglo),PF_S));
  1916. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc2.reghi,regsrc1.reghi),PF_S));
  1917. end;
  1918. else
  1919. internalerror(2003083101);
  1920. end;
  1921. if size=OS_64 then
  1922. begin
  1923. { the arm has an weired opinion how flags for SUB/ADD are handled }
  1924. ovloc.loc:=LOC_FLAGS;
  1925. case op of
  1926. OP_ADD:
  1927. ovloc.resflags:=F_CS;
  1928. OP_SUB:
  1929. ovloc.resflags:=F_CC;
  1930. end;
  1931. end;
  1932. end
  1933. else
  1934. begin
  1935. case op of
  1936. OP_AND,OP_OR,OP_XOR:
  1937. begin
  1938. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1939. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1940. end;
  1941. OP_ADD:
  1942. begin
  1943. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ADD,regdst.reglo,regsrc1.reglo,regsrc2.reglo),PF_S));
  1944. list.concat(taicpu.op_reg_reg_reg(A_ADC,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1945. end;
  1946. OP_SUB:
  1947. begin
  1948. list.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,regdst.reglo,regsrc2.reglo,regsrc1.reglo),PF_S));
  1949. list.concat(taicpu.op_reg_reg_reg(A_SBC,regdst.reghi,regsrc2.reghi,regsrc1.reghi));
  1950. end;
  1951. else
  1952. internalerror(2003083101);
  1953. end;
  1954. end;
  1955. end;
  1956. begin
  1957. cg:=tcgarm.create;
  1958. cg64:=tcg64farm.create;
  1959. end.