aasmcpu.pas 50 KB

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