cgcpu.pas 80 KB

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