aasmcpu.pas 52 KB

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