aasmcpu.pas 52 KB

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