aasmcpu.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  1. {
  2. Copyright (c) 2003-2012 by Florian Klaempfl and others
  3. Contains the assembler object for Aarch64
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,globtype,globals,verbose,
  22. aasmbase,aasmtai,aasmdata,aasmsym,
  23. ogbase,
  24. symtype,
  25. cpubase,cpuinfo,cgbase,cgutils;
  26. const
  27. { "mov reg,reg" source operand number }
  28. O_MOV_SOURCE = 1;
  29. { "mov reg,reg" source operand number }
  30. O_MOV_DEST = 0;
  31. { Operand types }
  32. OT_NONE = $00000000;
  33. OT_BITS8 = $00000001; { size, and other attributes, of the operand }
  34. OT_BITS16 = $00000002;
  35. OT_BITS32 = $00000004;
  36. OT_BITS64 = $00000008; { FPU only }
  37. OT_BITS80 = $00000010;
  38. OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
  39. OT_NEAR = $00000040;
  40. OT_SHORT = $00000080;
  41. OT_BITSTINY = $00000100; { fpu constant }
  42. OT_BITSSHIFTER =
  43. $00000200;
  44. OT_SIZE_MASK = $000003FF; { all the size attributes }
  45. OT_NON_SIZE = longint(not OT_SIZE_MASK);
  46. OT_SIGNED = $00000100; { the operand need to be signed -128-127 }
  47. OT_TO = $00000200; { operand is followed by a colon }
  48. { reverse effect in FADD, FSUB &c }
  49. OT_COLON = $00000400;
  50. OT_SHIFTEROP = $00000800;
  51. OT_REGISTER = $00001000;
  52. OT_IMMEDIATE = $00002000;
  53. OT_REGLIST = $00008000;
  54. OT_IMM8 = $00002001;
  55. OT_IMM24 = $00002002;
  56. OT_IMM32 = $00002004;
  57. OT_IMM64 = $00002008;
  58. OT_IMM80 = $00002010;
  59. OT_IMMTINY = $00002100;
  60. OT_IMMSHIFTER= $00002200;
  61. OT_IMMEDIATE24 = OT_IMM24;
  62. OT_SHIFTIMM = OT_SHIFTEROP or OT_IMMSHIFTER;
  63. OT_SHIFTIMMEDIATE = OT_SHIFTIMM;
  64. OT_IMMEDIATESHIFTER = OT_IMMSHIFTER;
  65. OT_IMMEDIATEFPU = OT_IMMTINY;
  66. OT_REGMEM = $00200000; { for r/m, ie EA, operands }
  67. OT_REGNORM = $00201000; { 'normal' reg, qualifies as EA }
  68. OT_REG8 = $00201001;
  69. OT_REG16 = $00201002;
  70. OT_REG32 = $00201004;
  71. OT_REG64 = $00201008;
  72. OT_VREG = $00201010; { vector register }
  73. OT_REGF = $00201020; { coproc register }
  74. OT_MEMORY = $00204000; { register number in 'basereg' }
  75. OT_MEM8 = $00204001;
  76. OT_MEM16 = $00204002;
  77. OT_MEM32 = $00204004;
  78. OT_MEM64 = $00204008;
  79. OT_MEM80 = $00204010;
  80. { word/byte load/store }
  81. OT_AM2 = $00010000;
  82. { misc ld/st operations }
  83. OT_AM3 = $00020000;
  84. { multiple ld/st operations }
  85. OT_AM4 = $00040000;
  86. { co proc. ld/st operations }
  87. OT_AM5 = $00080000;
  88. OT_AMMASK = $000f0000;
  89. { IT instruction }
  90. OT_CONDITION = $00100000;
  91. OT_MEMORYAM2 = OT_MEMORY or OT_AM2;
  92. OT_MEMORYAM3 = OT_MEMORY or OT_AM3;
  93. OT_MEMORYAM4 = OT_MEMORY or OT_AM4;
  94. OT_MEMORYAM5 = OT_MEMORY or OT_AM5;
  95. OT_FPUREG = $01000000; { floating point stack registers }
  96. OT_REG_SMASK = $00070000; { special register operands: these may be treated differently }
  97. { a mask for the following }
  98. OT_MEM_OFFS = $00604000; { special type of EA }
  99. { simple [address] offset }
  100. OT_ONENESS = $00800000; { special type of immediate operand }
  101. { so UNITY == IMMEDIATE | ONENESS }
  102. OT_UNITY = $00802000; { for shift/rotate instructions }
  103. instabentries = {$i a64nop.inc}
  104. maxinfolen = 5;
  105. IF_NONE = $00000000;
  106. IF_ARMMASK = $000F0000;
  107. IF_ARM7 = $00070000;
  108. IF_FPMASK = $00F00000;
  109. IF_FPA = $00100000;
  110. { if the instruction can change in a second pass }
  111. IF_PASS2 = longint($80000000);
  112. type
  113. TInsTabCache=array[TasmOp] of longint;
  114. PInsTabCache=^TInsTabCache;
  115. tinsentry = record
  116. opcode : tasmop;
  117. ops : byte;
  118. optypes : array[0..3] of longint;
  119. code : array[0..maxinfolen] of char;
  120. flags : longint;
  121. end;
  122. pinsentry=^tinsentry;
  123. var
  124. InsTabCache : PInsTabCache;
  125. type
  126. taicpu = class(tai_cpu_abstract_sym)
  127. oppostfix : TOpPostfix;
  128. procedure loadshifterop(opidx:longint;const so:tshifterop);
  129. procedure loadconditioncode(opidx: longint; const c: tasmcond);
  130. procedure loadrealconst(opidx: longint; const _value: bestreal);
  131. constructor op_none(op : tasmop);
  132. constructor op_reg(op : tasmop;_op1 : tregister);
  133. constructor op_ref(op : tasmop;const _op1 : treference);
  134. constructor op_const(op : tasmop;_op1 : longint);
  135. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  136. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  137. constructor op_reg_cond(op: tasmop; _op1: tregister; _op2: tasmcond);
  138. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  139. constructor op_reg_const_shifterop(op : tasmop;_op1: tregister; _op2: aint;_op3 : tshifterop);
  140. constructor op_reg_realconst(op: tasmop; _op1: tregister; _op2: bestreal);
  141. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  142. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  143. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  144. constructor op_reg_reg_const_const(op : tasmop;_op1,_op2 : tregister; _op3, _op4: aint);
  145. constructor op_reg_reg_const_shifterop(op : tasmop;_op1,_op2 : tregister; _op3: aint; const _op4 : tshifterop);
  146. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  147. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  148. constructor op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  149. constructor op_reg_reg_reg_shifterop(op : tasmop;_op1,_op2,_op3 : tregister; const _op4 : tshifterop);
  150. constructor op_reg_reg_reg_cond(op : tasmop;_op1,_op2,_op3 : tregister; const _op4: tasmcond);
  151. { this is for Jmp instructions }
  152. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  153. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  154. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  155. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  156. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  157. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  158. function spilling_get_operation_type(opnr: longint): topertype;override;
  159. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;override;
  160. { assembler }
  161. public
  162. { the next will reset all instructions that can change in pass 2 }
  163. procedure ResetPass1;override;
  164. procedure ResetPass2;override;
  165. function CheckIfValid:boolean;
  166. function GetString:string;
  167. function Pass1(objdata:TObjData):longint;override;
  168. procedure Pass2(objdata:TObjData);override;
  169. protected
  170. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
  171. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
  172. procedure ppubuildderefimploper(var o:toper);override;
  173. procedure ppuderefoper(var o:toper);override;
  174. end;
  175. tai_align = class(tai_align_abstract)
  176. { nothing to add }
  177. end;
  178. type
  179. tsimplereftype =
  180. { valid reference }
  181. (sr_simple,
  182. { invalid reference, should not be generated by the code generator (but
  183. can be encountered via inline assembly, where it must be rejected) }
  184. sr_internal_illegal,
  185. { invalid reference, may be generated by the code generator and then
  186. must be simplified (also rejected in inline assembly) }
  187. sr_complex);
  188. function simple_ref_type(op: tasmop; size:tcgsize; oppostfix: toppostfix; const ref: treference): tsimplereftype;
  189. function can_be_shifter_operand(opc: tasmop; opnr: longint): boolean;
  190. function valid_shifter_operand(opc: tasmop; useszr, usessp, is64bit: boolean; sm: tshiftmode; shiftimm: longint): boolean;
  191. function spilling_create_load(const ref: treference; r: tregister): taicpu;
  192. function spilling_create_store(r: tregister; const ref: treference): taicpu;
  193. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  194. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  195. { inserts pc relative symbols at places where they are reachable
  196. and transforms special instructions to valid instruction encodings }
  197. procedure finalizearmcode(list,listtoinsert : TAsmList);
  198. procedure InitAsm;
  199. procedure DoneAsm;
  200. implementation
  201. uses
  202. cutils,rgobj,itcpugas,aoptcpu;
  203. procedure taicpu.loadshifterop(opidx:longint;const so:tshifterop);
  204. begin
  205. allocate_oper(opidx+1);
  206. with oper[opidx]^ do
  207. begin
  208. if typ<>top_shifterop then
  209. begin
  210. clearop(opidx);
  211. new(shifterop);
  212. end;
  213. shifterop^:=so;
  214. typ:=top_shifterop;
  215. end;
  216. end;
  217. procedure taicpu.loadconditioncode(opidx: longint; const c: tasmcond);
  218. begin
  219. allocate_oper(opidx+1);
  220. with oper[opidx]^ do
  221. begin
  222. if typ<>top_conditioncode then
  223. begin
  224. clearop(opidx);
  225. end;
  226. cc:=c;
  227. typ:=top_conditioncode;
  228. end;
  229. end;
  230. procedure taicpu.loadrealconst(opidx:longint;const _value:bestreal);
  231. begin
  232. allocate_oper(opidx+1);
  233. with oper[opidx]^ do
  234. begin
  235. if typ<>top_realconst then
  236. clearop(opidx);
  237. val_real:=_value;
  238. typ:=top_realconst;
  239. end;
  240. end;
  241. {*****************************************************************************
  242. taicpu Constructors
  243. *****************************************************************************}
  244. constructor taicpu.op_none(op : tasmop);
  245. begin
  246. inherited create(op);
  247. end;
  248. { for pld }
  249. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  250. begin
  251. inherited create(op);
  252. ops:=1;
  253. loadref(0,_op1);
  254. end;
  255. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  256. begin
  257. inherited create(op);
  258. ops:=1;
  259. loadreg(0,_op1);
  260. end;
  261. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  262. begin
  263. inherited create(op);
  264. ops:=1;
  265. loadconst(0,aint(_op1));
  266. end;
  267. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  268. begin
  269. inherited create(op);
  270. ops:=2;
  271. loadreg(0,_op1);
  272. loadreg(1,_op2);
  273. end;
  274. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  275. begin
  276. inherited create(op);
  277. ops:=2;
  278. loadreg(0,_op1);
  279. loadconst(1,aint(_op2));
  280. end;
  281. constructor taicpu.op_reg_const_shifterop(op: tasmop; _op1: tregister; _op2: aint; _op3: tshifterop);
  282. begin
  283. inherited create(op);
  284. ops:=3;
  285. loadreg(0,_op1);
  286. loadconst(1,_op2);
  287. loadshifterop(2,_op3);
  288. end;
  289. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  290. begin
  291. inherited create(op);
  292. ops:=2;
  293. loadreg(0,_op1);
  294. loadref(1,_op2);
  295. end;
  296. constructor taicpu.op_reg_cond(op: tasmop; _op1: tregister; _op2: tasmcond);
  297. begin
  298. inherited create(op);
  299. ops:=2;
  300. loadreg(0,_op1);
  301. loadconditioncode(1,_op2);
  302. end;
  303. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  304. begin
  305. inherited create(op);
  306. ops:=3;
  307. loadreg(0,_op1);
  308. loadreg(1,_op2);
  309. loadreg(2,_op3);
  310. end;
  311. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  312. begin
  313. inherited create(op);
  314. ops:=4;
  315. loadreg(0,_op1);
  316. loadreg(1,_op2);
  317. loadreg(2,_op3);
  318. loadreg(3,_op4);
  319. end;
  320. constructor taicpu.op_reg_realconst(op : tasmop; _op1 : tregister; _op2 : bestreal);
  321. begin
  322. inherited create(op);
  323. ops:=2;
  324. loadreg(0,_op1);
  325. loadrealconst(1,_op2);
  326. end;
  327. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  328. begin
  329. inherited create(op);
  330. ops:=3;
  331. loadreg(0,_op1);
  332. loadreg(1,_op2);
  333. loadconst(2,aint(_op3));
  334. end;
  335. constructor taicpu.op_reg_reg_const_const(op: tasmop; _op1, _op2: tregister; _op3, _op4: aint);
  336. begin
  337. inherited create(op);
  338. ops:=4;
  339. loadreg(0,_op1);
  340. loadreg(1,_op2);
  341. loadconst(2,aint(_op3));
  342. loadconst(3,aint(_op4));
  343. end;
  344. constructor taicpu.op_reg_reg_const_shifterop(op: tasmop; _op1, _op2: tregister; _op3: aint; const _op4: tshifterop);
  345. begin
  346. inherited create(op);
  347. ops:=4;
  348. loadreg(0,_op1);
  349. loadreg(1,_op2);
  350. loadconst(2,aint(_op3));
  351. loadshifterop(3,_op4);
  352. end;
  353. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  354. begin
  355. inherited create(op);
  356. ops:=3;
  357. loadreg(0,_op1);
  358. loadreg(1,_op2);
  359. loadsymbol(0,_op3,_op3ofs);
  360. end;
  361. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  362. begin
  363. inherited create(op);
  364. ops:=3;
  365. loadreg(0,_op1);
  366. loadreg(1,_op2);
  367. loadref(2,_op3);
  368. end;
  369. constructor taicpu.op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  370. begin
  371. inherited create(op);
  372. ops:=3;
  373. loadreg(0,_op1);
  374. loadreg(1,_op2);
  375. loadshifterop(2,_op3);
  376. end;
  377. constructor taicpu.op_reg_reg_reg_shifterop(op : tasmop;_op1,_op2,_op3 : tregister; const _op4 : tshifterop);
  378. begin
  379. inherited create(op);
  380. ops:=4;
  381. loadreg(0,_op1);
  382. loadreg(1,_op2);
  383. loadreg(2,_op3);
  384. loadshifterop(3,_op4);
  385. end;
  386. constructor taicpu.op_reg_reg_reg_cond(op: tasmop; _op1, _op2, _op3: tregister; const _op4: tasmcond);
  387. begin
  388. inherited create(op);
  389. ops:=4;
  390. loadreg(0,_op1);
  391. loadreg(1,_op2);
  392. loadreg(2,_op3);
  393. loadconditioncode(3,_op4);
  394. end;
  395. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  396. begin
  397. inherited create(op);
  398. condition:=cond;
  399. ops:=1;
  400. loadsymbol(0,_op1,0);
  401. end;
  402. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  403. begin
  404. inherited create(op);
  405. ops:=1;
  406. loadsymbol(0,_op1,0);
  407. end;
  408. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  409. begin
  410. inherited create(op);
  411. ops:=1;
  412. loadsymbol(0,_op1,_op1ofs);
  413. end;
  414. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  415. begin
  416. inherited create(op);
  417. ops:=2;
  418. loadreg(0,_op1);
  419. loadsymbol(1,_op2,_op2ofs);
  420. end;
  421. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  422. begin
  423. inherited create(op);
  424. ops:=2;
  425. loadsymbol(0,_op1,_op1ofs);
  426. loadref(1,_op2);
  427. end;
  428. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  429. begin
  430. { allow the register allocator to remove unnecessary moves }
  431. result:=(
  432. ((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  433. ((opcode=A_FMOV) and (regtype = R_MMREGISTER))
  434. ) and
  435. (oppostfix in [PF_None]) and
  436. (condition=C_None) and
  437. (ops=2) and
  438. (oper[0]^.typ=top_reg) and
  439. (oper[1]^.typ=top_reg) and
  440. (oper[0]^.reg=oper[1]^.reg);
  441. end;
  442. function spilling_create_op(op: tasmop; const ref: treference; r: tregister): taicpu;
  443. const
  444. { invalid sizes for aarch64 are 0 }
  445. subreg2bytesize: array[TSubRegister] of byte =
  446. (0,0,0,0,4,8,0,0,0,4,8,0,0,0,0,0,0,0,0,0,0,0,0,8,16,0);
  447. var
  448. scalefactor: byte;
  449. begin
  450. scalefactor:=subreg2bytesize[getsubreg(r)];
  451. if scalefactor=0 then
  452. internalerror(2014120301);
  453. if (ref.offset>4095*scalefactor) or
  454. ((ref.offset>255) and
  455. ((ref.offset mod scalefactor)<>0)) or
  456. (ref.offset<-256) then
  457. internalerror(2014120302);
  458. case getregtype(r) of
  459. R_INTREGISTER,
  460. R_MMREGISTER:
  461. result:=taicpu.op_reg_ref(op,r,ref);
  462. else
  463. internalerror(200401041);
  464. end;
  465. end;
  466. function is_valid_load_symbol(op: tasmop; oppostfix: toppostfix; const ref: treference): tsimplereftype;
  467. begin
  468. result:=sr_complex;
  469. if not assigned(ref.symboldata) and
  470. not(ref.refaddr in [addr_pic,addr_gotpageoffset,addr_gotpage,addr_pageoffset,addr_page]) then
  471. exit;
  472. { can't use pre-/post-indexed mode here (makes no sense either) }
  473. if ref.addressmode<>AM_OFFSET then
  474. exit;
  475. { "ldr literal" must be a 32/64 bit LDR and have a symbol }
  476. if (ref.refaddr=addr_pic) and
  477. (not (op in [A_LDR,A_B,A_BL]) or
  478. not(oppostfix in [PF_NONE,PF_W,PF_SW]) or
  479. (not assigned(ref.symbol) and
  480. not assigned(ref.symboldata))) then
  481. exit;
  482. { if this is a (got) page offset load, we must have a base register and a
  483. symbol (except if we have an ADD with a non-got page offset load) }
  484. if (ref.refaddr in [addr_gotpageoffset,addr_pageoffset]) and
  485. (
  486. (
  487. (
  488. (op<>A_ADD) or
  489. (ref.refaddr=addr_gotpageoffset)
  490. ) and
  491. (
  492. not assigned(ref.symbol) or
  493. (ref.base=NR_NO)
  494. )
  495. ) or
  496. (
  497. (
  498. (op=A_ADD) and
  499. (ref.refaddr=addr_pageoffset)
  500. ) and
  501. not assigned(ref.symbol) and
  502. (ref.base=NR_NO)
  503. ) or
  504. (ref.index<>NR_NO) or
  505. (ref.offset<>0)) then
  506. begin
  507. result:=sr_internal_illegal;
  508. exit;
  509. end;
  510. { cannot have base or index register (we generate these kind of
  511. references internally, they should never end up here with an
  512. extra base or offset) }
  513. if (ref.refaddr in [addr_gotpage,addr_page]) and
  514. (ref.base<>NR_NO) or
  515. (ref.index<>NR_NO) then
  516. begin
  517. result:=sr_internal_illegal;
  518. exit;
  519. end;
  520. result:=sr_simple;
  521. end;
  522. function simple_ref_type(op: tasmop; size:tcgsize; oppostfix: toppostfix; const ref: treference): tsimplereftype;
  523. var
  524. accesssize: longint;
  525. begin
  526. result:=sr_internal_illegal;
  527. { post-indexed is only allowed for vector and immediate loads/stores }
  528. if (ref.addressmode=AM_POSTINDEXED) and
  529. not(op in [A_LD1,A_LD2,A_LD3,A_LD4,A_ST1,A_ST2,A_ST3,A_ST4]) and
  530. (not(op in [A_LDR,A_STR,A_LDP,A_STP]) or
  531. (ref.base=NR_NO) or
  532. (ref.index<>NR_NO)) then
  533. exit;
  534. { can only have a shift mode if we have an index }
  535. if (ref.index=NR_NO) and
  536. (ref.shiftmode<>SM_None) then
  537. exit;
  538. { the index can never be the stack pointer }
  539. if ref.index=NR_SP then
  540. exit;
  541. { no instruction supports an index without a base }
  542. if (ref.base=NR_NO) and
  543. (ref.index<>NR_NO) then
  544. begin
  545. result:=sr_complex;
  546. exit;
  547. end;
  548. { LDR literal or GOT entry: 32 or 64 bit, label }
  549. if assigned(ref.symboldata) or
  550. assigned(ref.symbol) then
  551. begin
  552. { we generate these kind of references internally; at least for now,
  553. they should never end up here with an extra base or offset or so }
  554. result:=is_valid_load_symbol(op,oppostfix,ref);
  555. exit;
  556. end;
  557. { any other reference cannot be gotpage/gotpageoffset/pic }
  558. if ref.refaddr in [addr_gotpage,addr_gotpageoffset,addr_page,addr_pageoffset,addr_pic] then
  559. exit;
  560. { base & index:
  561. * index cannot be the stack pointer
  562. * offset must be 0
  563. * can scale with the size of the access
  564. * can zero/sign extend 32 bit index register, and/or multiple by
  565. access size
  566. * no pre/post-indexing
  567. }
  568. if (ref.base<>NR_NO) and
  569. (ref.index<>NR_NO) then
  570. begin
  571. if ref.addressmode in [AM_PREINDEXED,AM_POSTINDEXED] then
  572. exit;
  573. case op of
  574. { this holds for both integer and fpu/vector loads }
  575. A_LDR,A_STR:
  576. if (ref.offset=0) and
  577. (((ref.shiftmode=SM_None) and
  578. (ref.shiftimm=0)) or
  579. ((ref.shiftmode in [SM_LSL,SM_UXTW,SM_SXTW]) and
  580. (ref.shiftimm=tcgsizep2size[size]))) then
  581. result:=sr_simple
  582. else
  583. result:=sr_complex;
  584. { todo }
  585. A_LD1,A_LD2,A_LD3,A_LD4,
  586. A_ST1,A_ST2,A_ST3,A_ST4:
  587. internalerror(2014110704);
  588. { these don't support base+index }
  589. A_LDUR,A_STUR,
  590. A_LDP,A_STP:
  591. result:=sr_complex;
  592. else
  593. { nothing: result is already sr_internal_illegal };
  594. end;
  595. exit;
  596. end;
  597. { base + immediate offset. Variants:
  598. * LDR*/STR*:
  599. - pre- or post-indexed with signed 9 bit immediate
  600. - regular with unsiged scaled immediate (multiple of access
  601. size), in the range 0 to (12 bit * access_size)-1
  602. * LDP/STP
  603. - pre- or post-indexed with signed 9 bit immediate
  604. - regular with signed 9 bit immediate
  605. * LDUR*/STUR*:
  606. - regular with signed 9 bit immediate
  607. }
  608. if ref.base<>NR_NO then
  609. begin
  610. accesssize:=1 shl tcgsizep2size[size];
  611. case op of
  612. A_LDR,A_STR:
  613. begin
  614. if (ref.addressmode=AM_OFFSET) and
  615. (ref.offset>=0) and
  616. (ref.offset<(((1 shl 12)-1)*accesssize)) and
  617. ((ref.offset mod accesssize)=0) then
  618. result:=sr_simple
  619. else if (ref.offset>=-256) and
  620. (ref.offset<=255) then
  621. begin
  622. { non pre-/post-indexed regular loads/stores can only be
  623. performed using LDUR/STUR }
  624. if ref.addressmode in [AM_PREINDEXED,AM_POSTINDEXED] then
  625. result:=sr_simple
  626. else
  627. result:=sr_complex
  628. end
  629. else
  630. result:=sr_complex;
  631. end;
  632. A_LDP,A_LDNP,
  633. A_STP,A_STNP:
  634. begin
  635. { only supported for 32/64 bit }
  636. if not(oppostfix in [PF_W,PF_SW,PF_None]) then
  637. exit;
  638. { offset must be a multple of the access size }
  639. if (ref.offset mod accesssize)<>0 then
  640. exit;
  641. { offset must fit in a signed 7 bit offset }
  642. if (ref.offset>=-(1 shl (6+tcgsizep2size[size]))) and
  643. (ref.offset<=(1 shl (6+tcgsizep2size[size]))-1) then
  644. result:=sr_simple
  645. else
  646. result:=sr_complex;
  647. end;
  648. A_LDUR,A_STUR:
  649. begin
  650. if (ref.addressmode=AM_OFFSET) and
  651. (ref.offset>=-256) and
  652. (ref.offset<=255) then
  653. result:=sr_simple
  654. else
  655. result:=sr_complex;
  656. end;
  657. { todo }
  658. A_LD1,A_LD2,A_LD3,A_LD4,
  659. A_ST1,A_ST2,A_ST3,A_ST4:
  660. internalerror(2014110907);
  661. A_LDAR,
  662. A_LDAXR,
  663. A_LDXR,
  664. A_LDXP,
  665. A_STLR,
  666. A_STLXR,
  667. A_STLXP,
  668. A_STXP,
  669. A_STXR:
  670. begin
  671. if (ref.addressmode=AM_OFFSET) and
  672. (ref.offset=0) then
  673. result:=sr_simple;
  674. end
  675. else
  676. { nothing: result is already sr_internal_illegal };
  677. end;
  678. exit;
  679. end;
  680. { absolute addresses are not supported, have to load them first into
  681. a register }
  682. result:=sr_complex;
  683. end;
  684. function can_be_shifter_operand(opc: tasmop; opnr: longint): boolean;
  685. begin
  686. case opc of
  687. A_ADD,
  688. A_AND,
  689. A_EON,
  690. A_EOR,
  691. A_ORN,
  692. A_ORR,
  693. A_SUB:
  694. result:=opnr=3;
  695. A_BIC,
  696. A_CMN,
  697. A_CMP,
  698. A_MOVK,
  699. A_MOVZ,
  700. A_MOVN,
  701. A_MVN,
  702. A_NEG,
  703. A_TST:
  704. result:=opnr=2;
  705. else
  706. result:=false;
  707. end;
  708. end;
  709. function valid_shifter_operand(opc: tasmop; useszr, usessp, is64bit: boolean; sm: tshiftmode; shiftimm: longint): boolean;
  710. begin
  711. case opc of
  712. A_ADD,
  713. A_SUB,
  714. A_NEG,
  715. A_AND,
  716. A_TST,
  717. A_CMN,
  718. A_CMP:
  719. begin
  720. result:=false;
  721. if not useszr then
  722. result:=
  723. (sm in shiftedregmodes) and
  724. ((shiftimm in [0..31]) or
  725. (is64bit and
  726. (shiftimm in [32..63])));
  727. if not usessp then
  728. result:=
  729. result or
  730. ((sm in extendedregmodes) and
  731. (shiftimm in [0..4]));
  732. end;
  733. A_BIC,
  734. A_EON,
  735. A_EOR,
  736. A_MVN,
  737. A_ORN,
  738. A_ORR:
  739. result:=
  740. (sm in shiftedregmodes) and
  741. (shiftimm in [0..31*(ord(is64bit)+1)+ord(is64bit)]);
  742. A_MOVK,
  743. A_MOVZ,
  744. A_MOVN:
  745. result:=
  746. (sm=SM_LSL) and
  747. ((shiftimm in [0,16]) or
  748. (is64bit and
  749. (shiftimm in [32,48])));
  750. else
  751. result:=false;
  752. end;
  753. end;
  754. function spilling_create_load(const ref: treference; r: tregister): taicpu;
  755. var
  756. op: tasmop;
  757. begin
  758. if (ref.index<>NR_NO) or
  759. (ref.offset<-256) or
  760. (ref.offset>255) then
  761. op:=A_LDR
  762. else
  763. op:=A_LDUR;
  764. result:=spilling_create_op(op,ref,r);
  765. end;
  766. function spilling_create_store(r: tregister; const ref: treference): taicpu;
  767. var
  768. op: tasmop;
  769. begin
  770. if (ref.index<>NR_NO) or
  771. (ref.offset<-256) or
  772. (ref.offset>255) then
  773. op:=A_STR
  774. else
  775. op:=A_STUR;
  776. result:=spilling_create_op(op,ref,r);
  777. end;
  778. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  779. begin
  780. case opcode of
  781. A_B,A_BL,A_BR,A_BLR,
  782. A_CMN,A_CMP,
  783. A_CCMN,A_CCMP,
  784. A_TST,
  785. A_FCMP,A_FCMPE,
  786. A_CBZ,A_CBNZ,
  787. A_RET:
  788. result:=operand_read;
  789. A_STR,A_STUR:
  790. if opnr=0 then
  791. result:=operand_read
  792. else
  793. { check for pre/post indexed in spilling_get_operation_type_ref }
  794. result:=operand_read;
  795. A_STLXP,
  796. A_STLXR,
  797. A_STXP,
  798. A_STXR:
  799. if opnr=0 then
  800. result:=operand_write
  801. else
  802. result:=operand_read;
  803. A_STP:
  804. begin
  805. if opnr in [0,1] then
  806. result:=operand_read
  807. else
  808. { check for pre/post indexed in spilling_get_operation_type_ref }
  809. result:=operand_read;
  810. end;
  811. A_LDP,
  812. A_LDXP:
  813. begin
  814. if opnr in [0,1] then
  815. result:=operand_write
  816. else
  817. { check for pre/post indexed in spilling_get_operation_type_ref }
  818. result:=operand_read;
  819. end;
  820. {$ifdef EXTDEBUG}
  821. { play save to avoid hard to find bugs, better fail at compile time }
  822. A_ADD,
  823. A_ADRP,
  824. A_AND,
  825. A_ASR,
  826. A_BFI,
  827. A_BFXIL,
  828. A_CLZ,
  829. A_CSEL,
  830. A_CSET,
  831. A_CSETM,
  832. A_FABS,
  833. A_EON,
  834. A_EOR,
  835. A_FADD,
  836. A_FCVT,
  837. A_FDIV,
  838. A_FMADD,
  839. A_FMOV,
  840. A_FMSUB,
  841. A_FMUL,
  842. A_FNEG,
  843. A_FNMADD,
  844. A_FNMSUB,
  845. A_FRINTX,
  846. A_FSQRT,
  847. A_FSUB,
  848. A_ORR,
  849. A_LSL,
  850. A_LSLV,
  851. A_LSR,
  852. A_LSRV,
  853. A_MOV,
  854. A_MOVK,
  855. A_MOVN,
  856. A_MOVZ,
  857. A_MSUB,
  858. A_MUL,
  859. A_MVN,
  860. A_NEG,
  861. A_LDR,
  862. A_LDUR,
  863. A_RBIT,
  864. A_ROR,
  865. A_RORV,
  866. A_SBFX,
  867. A_SCVTF,
  868. A_FCVTZS,
  869. A_SDIV,
  870. A_SMULL,
  871. A_SUB,
  872. A_SXT,
  873. A_UBFIZ,
  874. A_UBFX,
  875. A_UCVTF,
  876. A_UDIV,
  877. A_UMULL,
  878. A_UXT:
  879. if opnr=0 then
  880. result:=operand_write
  881. else
  882. result:=operand_read;
  883. else
  884. Internalerror(2019090802);
  885. {$else EXTDEBUG}
  886. else
  887. if opnr=0 then
  888. result:=operand_write
  889. else
  890. result:=operand_read;
  891. {$endif EXTDEBUG}
  892. end;
  893. end;
  894. function taicpu.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  895. begin
  896. result:=operand_read;
  897. if (oper[opnr]^.ref^.base = reg) and
  898. (oper[opnr]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  899. result:=operand_readwrite;
  900. end;
  901. procedure BuildInsTabCache;
  902. // var
  903. // i : longint;
  904. begin
  905. (* new(instabcache);
  906. FillChar(instabcache^,sizeof(tinstabcache),$ff);
  907. i:=0;
  908. while (i<InsTabEntries) do
  909. begin
  910. if InsTabCache^[InsTab[i].Opcode]=-1 then
  911. InsTabCache^[InsTab[i].Opcode]:=i;
  912. inc(i);
  913. end; *)
  914. end;
  915. procedure InitAsm;
  916. begin
  917. if not assigned(instabcache) then
  918. BuildInsTabCache;
  919. end;
  920. procedure DoneAsm;
  921. begin
  922. if assigned(instabcache) then
  923. begin
  924. dispose(instabcache);
  925. instabcache:=nil;
  926. end;
  927. end;
  928. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  929. begin
  930. i.oppostfix:=pf;
  931. result:=i;
  932. end;
  933. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  934. begin
  935. i.condition:=c;
  936. result:=i;
  937. end;
  938. Function SimpleGetNextInstruction(Current: tai; Var Next: tai): Boolean;
  939. Begin
  940. Current:=tai(Current.Next);
  941. While Assigned(Current) And (Current.typ In SkipInstr) Do
  942. Current:=tai(Current.Next);
  943. Next:=Current;
  944. If Assigned(Next) And Not(Next.typ In SkipInstr) Then
  945. Result:=True
  946. Else
  947. Begin
  948. Next:=Nil;
  949. Result:=False;
  950. End;
  951. End;
  952. (*
  953. function armconstequal(hp1,hp2: tai): boolean;
  954. begin
  955. result:=false;
  956. if hp1.typ<>hp2.typ then
  957. exit;
  958. case hp1.typ of
  959. tai_const:
  960. result:=
  961. (tai_const(hp2).sym=tai_const(hp).sym) and
  962. (tai_const(hp2).value=tai_const(hp).value) and
  963. (tai(hp2.previous).typ=ait_label);
  964. tai_const:
  965. result:=
  966. (tai_const(hp2).sym=tai_const(hp).sym) and
  967. (tai_const(hp2).value=tai_const(hp).value) and
  968. (tai(hp2.previous).typ=ait_label);
  969. end;
  970. end;
  971. *)
  972. procedure insertpcrelativedata(list,listtoinsert : TAsmList);
  973. (*
  974. var
  975. curinspos,
  976. penalty,
  977. lastinspos,
  978. { increased for every data element > 4 bytes inserted }
  979. currentsize,
  980. extradataoffset,
  981. limit: longint;
  982. curop : longint;
  983. curtai : tai;
  984. curdatatai,hp,hp2 : tai;
  985. curdata : TAsmList;
  986. l : tasmlabel;
  987. doinsert,
  988. removeref : boolean;
  989. *)
  990. begin
  991. (*
  992. curdata:=TAsmList.create;
  993. lastinspos:=-1;
  994. curinspos:=0;
  995. extradataoffset:=0;
  996. limit:=1016;
  997. curtai:=tai(list.first);
  998. doinsert:=false;
  999. while assigned(curtai) do
  1000. begin
  1001. { instruction? }
  1002. case curtai.typ of
  1003. ait_instruction:
  1004. begin
  1005. { walk through all operand of the instruction }
  1006. for curop:=0 to taicpu(curtai).ops-1 do
  1007. begin
  1008. { reference? }
  1009. if (taicpu(curtai).oper[curop]^.typ=top_ref) then
  1010. begin
  1011. { pc relative symbol? }
  1012. curdatatai:=tai(taicpu(curtai).oper[curop]^.ref^.symboldata);
  1013. if assigned(curdatatai) and
  1014. { move only if we're at the first reference of a label }
  1015. not(tai_label(curdatatai).moved) then
  1016. begin
  1017. tai_label(curdatatai).moved:=true;
  1018. { check if symbol already used. }
  1019. { if yes, reuse the symbol }
  1020. hp:=tai(curdatatai.next);
  1021. removeref:=false;
  1022. if assigned(hp) then
  1023. begin
  1024. case hp.typ of
  1025. ait_const:
  1026. begin
  1027. if (tai_const(hp).consttype=aitconst_64bit) then
  1028. inc(extradataoffset);
  1029. end;
  1030. ait_realconst:
  1031. begin
  1032. inc(extradataoffset,((tai_realconst(hp).savesize-4+3) div 4));
  1033. end;
  1034. end;
  1035. if (hp.typ=ait_const) then
  1036. begin
  1037. hp2:=tai(curdata.first);
  1038. while assigned(hp2) do
  1039. begin
  1040. { if armconstequal(hp2,hp) then }
  1041. if (hp2.typ=ait_const) and (tai_const(hp2).sym=tai_const(hp).sym)
  1042. and (tai_const(hp2).value=tai_const(hp).value) and (tai(hp2.previous).typ=ait_label)
  1043. then
  1044. begin
  1045. with taicpu(curtai).oper[curop]^.ref^ do
  1046. begin
  1047. symboldata:=hp2.previous;
  1048. symbol:=tai_label(hp2.previous).labsym;
  1049. end;
  1050. removeref:=true;
  1051. break;
  1052. end;
  1053. hp2:=tai(hp2.next);
  1054. end;
  1055. end;
  1056. end;
  1057. { move or remove symbol reference }
  1058. repeat
  1059. hp:=tai(curdatatai.next);
  1060. listtoinsert.remove(curdatatai);
  1061. if removeref then
  1062. curdatatai.free
  1063. else
  1064. curdata.concat(curdatatai);
  1065. curdatatai:=hp;
  1066. until (curdatatai=nil) or (curdatatai.typ=ait_label);
  1067. if lastinspos=-1 then
  1068. lastinspos:=curinspos;
  1069. end;
  1070. end;
  1071. end;
  1072. inc(curinspos);
  1073. end;
  1074. ait_align:
  1075. begin
  1076. { code is always 4 byte aligned, so we don't have to take care of .align 2 which would
  1077. requires also incrementing curinspos by 1 }
  1078. inc(curinspos,(tai_align(curtai).aligntype div 4));
  1079. end;
  1080. ait_const:
  1081. begin
  1082. inc(curinspos);
  1083. if (tai_const(curtai).consttype=aitconst_64bit) then
  1084. inc(curinspos);
  1085. end;
  1086. ait_realconst:
  1087. begin
  1088. inc(curinspos,(tai_realconst(hp).savesize+3) div 4);
  1089. end;
  1090. end;
  1091. { special case for case jump tables }
  1092. if SimpleGetNextInstruction(curtai,hp) and
  1093. (tai(hp).typ=ait_instruction) and
  1094. (taicpu(hp).opcode=A_LDR) and
  1095. (taicpu(hp).oper[0]^.typ=top_reg) and
  1096. (taicpu(hp).oper[0]^.reg=NR_PC) then
  1097. begin
  1098. penalty:=1;
  1099. hp:=tai(hp.next);
  1100. { skip register allocations and comments inserted by the optimizer }
  1101. while assigned(hp) and (hp.typ in [ait_comment,ait_regalloc]) do
  1102. hp:=tai(hp.next);
  1103. while assigned(hp) and (hp.typ=ait_const) do
  1104. begin
  1105. inc(penalty);
  1106. hp:=tai(hp.next);
  1107. end;
  1108. end
  1109. else
  1110. penalty:=0;
  1111. { FLD/FST VFP instructions have a limit of +/- 1024, not 4096 }
  1112. if SimpleGetNextInstruction(curtai,hp) and
  1113. (tai(hp).typ=ait_instruction) and
  1114. ((taicpu(hp).opcode=A_FLDS) or
  1115. (taicpu(hp).opcode=A_FLDD)) then
  1116. limit:=254;
  1117. { don't miss an insert }
  1118. doinsert:=doinsert or
  1119. (not(curdata.empty) and
  1120. (curinspos-lastinspos+penalty+extradataoffset>limit));
  1121. { split only at real instructions else the test below fails }
  1122. if doinsert and (curtai.typ=ait_instruction) and
  1123. (
  1124. { don't split loads of pc to lr and the following move }
  1125. not(
  1126. (taicpu(curtai).opcode=A_MOV) and
  1127. (taicpu(curtai).oper[0]^.typ=top_reg) and
  1128. (taicpu(curtai).oper[0]^.reg=NR_R14) and
  1129. (taicpu(curtai).oper[1]^.typ=top_reg) and
  1130. (taicpu(curtai).oper[1]^.reg=NR_PC)
  1131. )
  1132. ) then
  1133. begin
  1134. lastinspos:=-1;
  1135. extradataoffset:=0;
  1136. limit:=1016;
  1137. doinsert:=false;
  1138. hp:=tai(curtai.next);
  1139. current_asmdata.getjumplabel(l);
  1140. curdata.insert(taicpu.op_sym(A_B,l));
  1141. curdata.concat(tai_label.create(l));
  1142. list.insertlistafter(curtai,curdata);
  1143. curtai:=hp;
  1144. end
  1145. else
  1146. curtai:=tai(curtai.next);
  1147. end;
  1148. list.concatlist(curdata);
  1149. curdata.free;
  1150. *)
  1151. end;
  1152. procedure finalizearmcode(list, listtoinsert: TAsmList);
  1153. begin
  1154. insertpcrelativedata(list, listtoinsert);
  1155. end;
  1156. (*
  1157. Floating point instruction format information, taken from the linux kernel
  1158. ARM Floating Point Instruction Classes
  1159. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  1160. |c o n d|1 1 0 P|U|u|W|L| Rn |v| Fd |0|0|0|1| o f f s e t | CPDT
  1161. |c o n d|1 1 0 P|U|w|W|L| Rn |x| Fd |0|0|1|0| o f f s e t | CPDT (copro 2)
  1162. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  1163. |c o n d|1 1 1 0|a|b|c|d|e| Fn |j| Fd |0|0|0|1|f|g|h|0|i| Fm | CPDO
  1164. |c o n d|1 1 1 0|a|b|c|L|e| Fn | Rd |0|0|0|1|f|g|h|1|i| Fm | CPRT
  1165. |c o n d|1 1 1 0|a|b|c|1|e| Fn |1|1|1|1|0|0|0|1|f|g|h|1|i| Fm | comparisons
  1166. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  1167. CPDT data transfer instructions
  1168. LDF, STF, LFM (copro 2), SFM (copro 2)
  1169. CPDO dyadic arithmetic instructions
  1170. ADF, MUF, SUF, RSF, DVF, RDF,
  1171. POW, RPW, RMF, FML, FDV, FRD, POL
  1172. CPDO monadic arithmetic instructions
  1173. MVF, MNF, ABS, RND, SQT, LOG, LGN, EXP,
  1174. SIN, COS, TAN, ASN, ACS, ATN, URD, NRM
  1175. CPRT joint arithmetic/data transfer instructions
  1176. FIX (arithmetic followed by load/store)
  1177. FLT (load/store followed by arithmetic)
  1178. CMF, CNF CMFE, CNFE (comparisons)
  1179. WFS, RFS (write/read floating point status register)
  1180. WFC, RFC (write/read floating point control register)
  1181. cond condition codes
  1182. P pre/post index bit: 0 = postindex, 1 = preindex
  1183. U up/down bit: 0 = stack grows down, 1 = stack grows up
  1184. W write back bit: 1 = update base register (Rn)
  1185. L load/store bit: 0 = store, 1 = load
  1186. Rn base register
  1187. Rd destination/source register
  1188. Fd floating point destination register
  1189. Fn floating point source register
  1190. Fm floating point source register or floating point constant
  1191. uv transfer length (TABLE 1)
  1192. wx register count (TABLE 2)
  1193. abcd arithmetic opcode (TABLES 3 & 4)
  1194. ef destination size (rounding precision) (TABLE 5)
  1195. gh rounding mode (TABLE 6)
  1196. j dyadic/monadic bit: 0 = dyadic, 1 = monadic
  1197. i constant bit: 1 = constant (TABLE 6)
  1198. */
  1199. /*
  1200. TABLE 1
  1201. +-------------------------+---+---+---------+---------+
  1202. | Precision | u | v | FPSR.EP | length |
  1203. +-------------------------+---+---+---------+---------+
  1204. | Single | 0 | 0 | x | 1 words |
  1205. | Double | 1 | 1 | x | 2 words |
  1206. | Extended | 1 | 1 | x | 3 words |
  1207. | Packed decimal | 1 | 1 | 0 | 3 words |
  1208. | Expanded packed decimal | 1 | 1 | 1 | 4 words |
  1209. +-------------------------+---+---+---------+---------+
  1210. Note: x = don't care
  1211. */
  1212. /*
  1213. TABLE 2
  1214. +---+---+---------------------------------+
  1215. | w | x | Number of registers to transfer |
  1216. +---+---+---------------------------------+
  1217. | 0 | 1 | 1 |
  1218. | 1 | 0 | 2 |
  1219. | 1 | 1 | 3 |
  1220. | 0 | 0 | 4 |
  1221. +---+---+---------------------------------+
  1222. */
  1223. /*
  1224. TABLE 3: Dyadic Floating Point Opcodes
  1225. +---+---+---+---+----------+-----------------------+-----------------------+
  1226. | a | b | c | d | Mnemonic | Description | Operation |
  1227. +---+---+---+---+----------+-----------------------+-----------------------+
  1228. | 0 | 0 | 0 | 0 | ADF | Add | Fd := Fn + Fm |
  1229. | 0 | 0 | 0 | 1 | MUF | Multiply | Fd := Fn * Fm |
  1230. | 0 | 0 | 1 | 0 | SUF | Subtract | Fd := Fn - Fm |
  1231. | 0 | 0 | 1 | 1 | RSF | Reverse subtract | Fd := Fm - Fn |
  1232. | 0 | 1 | 0 | 0 | DVF | Divide | Fd := Fn / Fm |
  1233. | 0 | 1 | 0 | 1 | RDF | Reverse divide | Fd := Fm / Fn |
  1234. | 0 | 1 | 1 | 0 | POW | Power | Fd := Fn ^ Fm |
  1235. | 0 | 1 | 1 | 1 | RPW | Reverse power | Fd := Fm ^ Fn |
  1236. | 1 | 0 | 0 | 0 | RMF | Remainder | Fd := IEEE rem(Fn/Fm) |
  1237. | 1 | 0 | 0 | 1 | FML | Fast Multiply | Fd := Fn * Fm |
  1238. | 1 | 0 | 1 | 0 | FDV | Fast Divide | Fd := Fn / Fm |
  1239. | 1 | 0 | 1 | 1 | FRD | Fast reverse divide | Fd := Fm / Fn |
  1240. | 1 | 1 | 0 | 0 | POL | Polar angle (ArcTan2) | Fd := arctan2(Fn,Fm) |
  1241. | 1 | 1 | 0 | 1 | | undefined instruction | trap |
  1242. | 1 | 1 | 1 | 0 | | undefined instruction | trap |
  1243. | 1 | 1 | 1 | 1 | | undefined instruction | trap |
  1244. +---+---+---+---+----------+-----------------------+-----------------------+
  1245. Note: POW, RPW, POL are deprecated, and are available for backwards
  1246. compatibility only.
  1247. */
  1248. /*
  1249. TABLE 4: Monadic Floating Point Opcodes
  1250. +---+---+---+---+----------+-----------------------+-----------------------+
  1251. | a | b | c | d | Mnemonic | Description | Operation |
  1252. +---+---+---+---+----------+-----------------------+-----------------------+
  1253. | 0 | 0 | 0 | 0 | MVF | Move | Fd := Fm |
  1254. | 0 | 0 | 0 | 1 | MNF | Move negated | Fd := - Fm |
  1255. | 0 | 0 | 1 | 0 | ABS | Absolute value | Fd := abs(Fm) |
  1256. | 0 | 0 | 1 | 1 | RND | Round to integer | Fd := int(Fm) |
  1257. | 0 | 1 | 0 | 0 | SQT | Square root | Fd := sqrt(Fm) |
  1258. | 0 | 1 | 0 | 1 | LOG | Log base 10 | Fd := log10(Fm) |
  1259. | 0 | 1 | 1 | 0 | LGN | Log base e | Fd := ln(Fm) |
  1260. | 0 | 1 | 1 | 1 | EXP | Exponent | Fd := e ^ Fm |
  1261. | 1 | 0 | 0 | 0 | SIN | Sine | Fd := sin(Fm) |
  1262. | 1 | 0 | 0 | 1 | COS | Cosine | Fd := cos(Fm) |
  1263. | 1 | 0 | 1 | 0 | TAN | Tangent | Fd := tan(Fm) |
  1264. | 1 | 0 | 1 | 1 | ASN | Arc Sine | Fd := arcsin(Fm) |
  1265. | 1 | 1 | 0 | 0 | ACS | Arc Cosine | Fd := arccos(Fm) |
  1266. | 1 | 1 | 0 | 1 | ATN | Arc Tangent | Fd := arctan(Fm) |
  1267. | 1 | 1 | 1 | 0 | URD | Unnormalized round | Fd := int(Fm) |
  1268. | 1 | 1 | 1 | 1 | NRM | Normalize | Fd := norm(Fm) |
  1269. +---+---+---+---+----------+-----------------------+-----------------------+
  1270. Note: LOG, LGN, EXP, SIN, COS, TAN, ASN, ACS, ATN are deprecated, and are
  1271. available for backwards compatibility only.
  1272. */
  1273. /*
  1274. TABLE 5
  1275. +-------------------------+---+---+
  1276. | Rounding Precision | e | f |
  1277. +-------------------------+---+---+
  1278. | IEEE Single precision | 0 | 0 |
  1279. | IEEE Double precision | 0 | 1 |
  1280. | IEEE Extended precision | 1 | 0 |
  1281. | undefined (trap) | 1 | 1 |
  1282. +-------------------------+---+---+
  1283. */
  1284. /*
  1285. TABLE 5
  1286. +---------------------------------+---+---+
  1287. | Rounding Mode | g | h |
  1288. +---------------------------------+---+---+
  1289. | Round to nearest (default) | 0 | 0 |
  1290. | Round toward plus infinity | 0 | 1 |
  1291. | Round toward negative infinity | 1 | 0 |
  1292. | Round toward zero | 1 | 1 |
  1293. +---------------------------------+---+---+
  1294. *)
  1295. function taicpu.GetString:string;
  1296. var
  1297. i : longint;
  1298. s : string;
  1299. addsize : boolean;
  1300. begin
  1301. s:='['+gas_op2str[opcode];
  1302. for i:=0 to ops-1 do
  1303. begin
  1304. with oper[i]^ do
  1305. begin
  1306. if i=0 then
  1307. s:=s+' '
  1308. else
  1309. s:=s+',';
  1310. { type }
  1311. addsize:=false;
  1312. if (ot and OT_VREG)=OT_VREG then
  1313. s:=s+'vreg'
  1314. else
  1315. if (ot and OT_FPUREG)=OT_FPUREG then
  1316. s:=s+'fpureg'
  1317. else
  1318. if (ot and OT_REGISTER)=OT_REGISTER then
  1319. begin
  1320. s:=s+'reg';
  1321. addsize:=true;
  1322. end
  1323. else
  1324. if (ot and OT_REGLIST)=OT_REGLIST then
  1325. begin
  1326. s:=s+'reglist';
  1327. addsize:=false;
  1328. end
  1329. else
  1330. if (ot and OT_IMMEDIATE)=OT_IMMEDIATE then
  1331. begin
  1332. s:=s+'imm';
  1333. addsize:=true;
  1334. end
  1335. else
  1336. if (ot and OT_MEMORY)=OT_MEMORY then
  1337. begin
  1338. s:=s+'mem';
  1339. addsize:=true;
  1340. if (ot and OT_AM2)<>0 then
  1341. s:=s+' am2 ';
  1342. end
  1343. else
  1344. s:=s+'???';
  1345. { size }
  1346. if addsize then
  1347. begin
  1348. if (ot and OT_BITS8)<>0 then
  1349. s:=s+'8'
  1350. else
  1351. if (ot and OT_BITS16)<>0 then
  1352. s:=s+'24'
  1353. else
  1354. if (ot and OT_BITS32)<>0 then
  1355. s:=s+'32'
  1356. else
  1357. if (ot and OT_BITSSHIFTER)<>0 then
  1358. s:=s+'shifter'
  1359. else
  1360. s:=s+'??';
  1361. { signed }
  1362. if (ot and OT_SIGNED)<>0 then
  1363. s:=s+'s';
  1364. end;
  1365. end;
  1366. end;
  1367. GetString:=s+']';
  1368. end;
  1369. procedure taicpu.ResetPass1;
  1370. begin
  1371. { we need to reset everything here, because the choosen insentry
  1372. can be invalid for a new situation where the previously optimized
  1373. insentry is not correct }
  1374. end;
  1375. procedure taicpu.ResetPass2;
  1376. begin
  1377. { we are here in a second pass, check if the instruction can be optimized }
  1378. end;
  1379. function taicpu.CheckIfValid:boolean;
  1380. begin
  1381. Result:=False; { unimplemented }
  1382. end;
  1383. function taicpu.Pass1(objdata:TObjData):longint;
  1384. begin
  1385. Pass1:=0;
  1386. end;
  1387. procedure taicpu.Pass2(objdata:TObjData);
  1388. begin
  1389. { error in pass1 ? }
  1390. current_filepos:=fileinfo;
  1391. { Generate the instruction }
  1392. { GenCode(objdata); }
  1393. end;
  1394. procedure taicpu.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  1395. begin
  1396. end;
  1397. procedure taicpu.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  1398. begin
  1399. end;
  1400. procedure taicpu.ppubuildderefimploper(var o:toper);
  1401. begin
  1402. end;
  1403. procedure taicpu.ppuderefoper(var o:toper);
  1404. begin
  1405. end;
  1406. begin
  1407. cai_align:=tai_align;
  1408. end.