cgcpu.pas 81 KB

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