aasmcpu.pas 51 KB

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