aasmcpu.pas 50 KB

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