rax86.pas 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Handles the common x86 assembler reader routines
  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. {
  18. Contains the common x86 (i386 and x86-64) assembler reader routines.
  19. }
  20. unit rax86;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. aasmbase,aasmtai,aasmdata,aasmcpu,
  25. cpubase,rautils,cclasses;
  26. { Parser helpers }
  27. function is_prefix(t:tasmop):boolean;
  28. function is_override(t:tasmop):boolean;
  29. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  30. Function CheckOverride(overrideop,op:tasmop): Boolean;
  31. Procedure FWaitWarning;
  32. type
  33. Tx86Operand=class(TOperand)
  34. opsize : topsize;
  35. vopext : smallint; // bitmask: vector-operand extention AVX512 (e.g. vaddps xmm0 {k1} {z})
  36. vbcst : byte;
  37. Procedure SetSize(_size:longint;force:boolean);override;
  38. Procedure SetCorrectSize(opcode:tasmop);override;
  39. Function CheckOperand: boolean; override;
  40. { handles the @Code symbol }
  41. Procedure SetupCode;
  42. { handles the @Data symbol }
  43. Procedure SetupData;
  44. constructor create; override;
  45. end;
  46. { Operands are always in AT&T order.
  47. Intel reader attaches them right-to-left, then shifts to start with 1 }
  48. { Tx86Instruction }
  49. Tx86Instruction=class(TInstruction)
  50. opsize : topsize;
  51. constructor Create(optype : tcoperand);override;
  52. { Operand sizes }
  53. procedure AddReferenceSizes; virtual;
  54. procedure SetInstructionOpsize;
  55. procedure CheckOperandSizes;
  56. procedure CheckNonCommutativeOpcodes;
  57. { Additional actions required by specific reader }
  58. procedure FixupOpcode;virtual;
  59. { opcode adding }
  60. function ConcatInstruction(p : TAsmList) : tai;override;
  61. function getstring: string;
  62. { returns true, if the opcode might have an extension as used by AVX512 }
  63. function MightHaveExtension : boolean;
  64. end;
  65. const
  66. AsmPrefixes = 8{$ifdef i8086}+2{$endif i8086};
  67. AsmPrefix : array[0..AsmPrefixes-1] of TasmOP =(
  68. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ,A_XACQUIRE,A_XRELEASE{$ifdef i8086},A_REPC,A_REPNC{$endif i8086}
  69. );
  70. AsmOverrides = 6;
  71. AsmOverride : array[0..AsmOverrides-1] of TasmOP =(
  72. A_SEGCS,A_SEGES,A_SEGDS,A_SEGFS,A_SEGGS,A_SEGSS
  73. );
  74. CondAsmOps=3;
  75. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  76. A_CMOVcc, A_Jcc, A_SETcc
  77. );
  78. CondAsmOpStr:array[0..CondAsmOps-1] of string[4]=(
  79. 'CMOV','J','SET'
  80. );
  81. implementation
  82. uses
  83. globtype,globals,systems,verbose,
  84. procinfo,
  85. cgbase,cgutils,
  86. itcpugas,cgx86, cutils;
  87. {*****************************************************************************
  88. Parser Helpers
  89. *****************************************************************************}
  90. function is_prefix(t:tasmop):boolean;
  91. var
  92. i : longint;
  93. Begin
  94. is_prefix:=false;
  95. for i:=1 to AsmPrefixes do
  96. if t=AsmPrefix[i-1] then
  97. begin
  98. is_prefix:=true;
  99. exit;
  100. end;
  101. end;
  102. function is_override(t:tasmop):boolean;
  103. var
  104. i : longint;
  105. Begin
  106. is_override:=false;
  107. for i:=1 to AsmOverrides do
  108. if t=AsmOverride[i-1] then
  109. begin
  110. is_override:=true;
  111. exit;
  112. end;
  113. end;
  114. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  115. { Checks if the prefix is valid with the following opcode }
  116. { return false if not, otherwise true }
  117. Begin
  118. CheckPrefix := TRUE;
  119. (* Case prefix of
  120. A_REP,A_REPNE,A_REPE:
  121. Case opcode Of
  122. A_SCASB,A_SCASW,A_SCASD,
  123. A_INS,A_OUTS,A_MOVS,A_CMPS,A_LODS,A_STOS:;
  124. Else
  125. Begin
  126. CheckPrefix := FALSE;
  127. exit;
  128. end;
  129. end; { case }
  130. A_LOCK:
  131. Case opcode Of
  132. A_BT,A_BTS,A_BTR,A_BTC,A_XCHG,A_ADD,A_OR,A_ADC,A_SBB,A_AND,A_SUB,
  133. A_XOR,A_NOT,A_NEG,A_INC,A_DEC:;
  134. Else
  135. Begin
  136. CheckPrefix := FALSE;
  137. Exit;
  138. end;
  139. end; { case }
  140. A_NONE: exit; { no prefix here }
  141. else
  142. CheckPrefix := FALSE;
  143. end; { end case } *)
  144. end;
  145. Function CheckOverride(overrideop,op:tasmop): Boolean;
  146. { Check if the override is valid, and if so then }
  147. { update the instr variable accordingly. }
  148. Begin
  149. CheckOverride := true;
  150. { Case instr.getinstruction of
  151. A_MOVS,A_XLAT,A_CMPS:
  152. Begin
  153. CheckOverride := TRUE;
  154. Message(assem_e_segment_override_not_supported);
  155. end
  156. end }
  157. end;
  158. Procedure FWaitWarning;
  159. begin
  160. if (target_info.system=system_i386_GO32V2) and (cs_fp_emulation in current_settings.moduleswitches) then
  161. Message(asmr_w_fwait_emu_prob);
  162. end;
  163. {*****************************************************************************
  164. TX86Operand
  165. *****************************************************************************}
  166. Procedure Tx86Operand.SetSize(_size:longint;force:boolean);
  167. begin
  168. inherited SetSize(_size,force);
  169. { OS_64 will be set to S_L and be fixed later
  170. in SetCorrectSize }
  171. // multimedia register
  172. case _size of
  173. 16: size := OS_M128;
  174. 32: size := OS_M256;
  175. 64: size := OS_M512;
  176. end;
  177. {$ifdef i8086}
  178. { allows e.g. using 32-bit registers in i8086 inline asm }
  179. if size in [OS_32,OS_S32] then
  180. opsize:=S_L
  181. else
  182. {$endif i8086}
  183. opsize:=TCGSize2Opsize[size];
  184. end;
  185. Procedure Tx86Operand.SetCorrectSize(opcode:tasmop);
  186. begin
  187. if gas_needsuffix[opcode]=attsufFPU then
  188. begin
  189. case size of
  190. OS_32 : opsize:=S_FS;
  191. OS_64 : opsize:=S_FL;
  192. else
  193. ;
  194. end;
  195. end
  196. else if gas_needsuffix[opcode]=attsufFPUint then
  197. begin
  198. case size of
  199. OS_16 : opsize:=S_IS;
  200. OS_32 : opsize:=S_IL;
  201. OS_64 : opsize:=S_IQ;
  202. else
  203. ;
  204. end;
  205. end
  206. else if gas_needsuffix[opcode]=AttSufMM then
  207. begin
  208. if (opr.typ=OPR_Reference) then
  209. begin
  210. case size of
  211. OS_32 : size := OS_M32;
  212. OS_64 : size := OS_M64;
  213. else
  214. ;
  215. end;
  216. end;
  217. end
  218. else
  219. begin
  220. if size=OS_64 then
  221. opsize:=S_Q;
  222. end;
  223. end;
  224. Function Tx86Operand.CheckOperand: boolean;
  225. var
  226. ErrorRefStr: string;
  227. begin
  228. result:=true;
  229. if (opr.typ=OPR_Reference) then
  230. begin
  231. if not hasvar then
  232. begin
  233. if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset>0) then
  234. begin
  235. if current_settings.asmmode in asmmodes_x86_intel then
  236. begin
  237. case getsubreg(opr.ref.base) of
  238. R_SUBW:
  239. ErrorRefStr:='[BP+offset]';
  240. R_SUBD:
  241. ErrorRefStr:='[EBP+offset]';
  242. R_SUBQ:
  243. ErrorRefStr:='[RBP+offset]';
  244. else
  245. internalerror(2019061001);
  246. end;
  247. end
  248. else
  249. begin
  250. case getsubreg(opr.ref.base) of
  251. R_SUBW:
  252. ErrorRefStr:='+offset(%bp)';
  253. R_SUBD:
  254. ErrorRefStr:='+offset(%ebp)';
  255. R_SUBQ:
  256. ErrorRefStr:='+offset(%rbp)';
  257. else
  258. internalerror(2019061002);
  259. end;
  260. end;
  261. if current_procinfo.procdef.proccalloption=pocall_register then
  262. message1(asmr_w_no_direct_ebp_for_parameter,ErrorRefStr)
  263. else
  264. message1(asmr_w_direct_ebp_for_parameter_regcall,ErrorRefStr);
  265. end
  266. else if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset<0) then
  267. begin
  268. if current_settings.asmmode in asmmodes_x86_intel then
  269. begin
  270. case getsubreg(opr.ref.base) of
  271. R_SUBW:
  272. ErrorRefStr:='[BP-offset]';
  273. R_SUBD:
  274. ErrorRefStr:='[EBP-offset]';
  275. R_SUBQ:
  276. ErrorRefStr:='[RBP-offset]';
  277. else
  278. internalerror(2019061003);
  279. end;
  280. end
  281. else
  282. begin
  283. case getsubreg(opr.ref.base) of
  284. R_SUBW:
  285. ErrorRefStr:='-offset(%bp)';
  286. R_SUBD:
  287. ErrorRefStr:='-offset(%ebp)';
  288. R_SUBQ:
  289. ErrorRefStr:='-offset(%rbp)';
  290. else
  291. internalerror(2019061004);
  292. end;
  293. end;
  294. message1(asmr_w_direct_ebp_neg_offset,ErrorRefStr);
  295. end
  296. else if (getsupreg(opr.ref.base)=RS_ESP) and (getsubreg(opr.ref.base)<>R_SUBW) and (opr.ref.offset<0) then
  297. begin
  298. if current_settings.asmmode in asmmodes_x86_intel then
  299. begin
  300. case getsubreg(opr.ref.base) of
  301. R_SUBD:
  302. ErrorRefStr:='[ESP-offset]';
  303. R_SUBQ:
  304. ErrorRefStr:='[RSP-offset]';
  305. else
  306. internalerror(2019061005);
  307. end;
  308. end
  309. else
  310. begin
  311. case getsubreg(opr.ref.base) of
  312. R_SUBD:
  313. ErrorRefStr:='-offset(%esp)';
  314. R_SUBQ:
  315. ErrorRefStr:='-offset(%rsp)';
  316. else
  317. internalerror(2019061006);
  318. end;
  319. end;
  320. message1(asmr_w_direct_esp_neg_offset,ErrorRefStr);
  321. end;
  322. end;
  323. if (cs_create_pic in current_settings.moduleswitches) and
  324. assigned(opr.ref.symbol) and
  325. not assigned(opr.ref.relsymbol) then
  326. begin
  327. if not(opr.ref.refaddr in [addr_pic,addr_pic_no_got]) then
  328. begin
  329. if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
  330. begin
  331. message(asmr_e_need_pic_ref);
  332. result:=false;
  333. end
  334. else
  335. opr.ref.refaddr:=addr_pic;
  336. end
  337. else
  338. begin
  339. {$ifdef x86_64}
  340. { should probably be extended to i386, but there the situation
  341. is more complex and ELF-style PIC still need to be
  342. tested/debugged }
  343. if (opr.ref.symbol.bind in [AB_LOCAL,AB_PRIVATE_EXTERN]) and
  344. (opr.ref.refaddr=addr_pic) then
  345. message(asmr_w_useless_got_for_local)
  346. else if (opr.ref.symbol.bind in [AB_GLOBAL,AB_EXTERNAL,AB_COMMON,AB_WEAK_EXTERNAL]) and
  347. (opr.ref.refaddr=addr_pic_no_got) then
  348. message(asmr_w_global_access_without_got);
  349. {$endif x86_64}
  350. end;
  351. end;
  352. end;
  353. end;
  354. procedure Tx86Operand.SetupCode;
  355. begin
  356. {$ifdef i8086}
  357. opr.typ:=OPR_SYMBOL;
  358. opr.symofs:=0;
  359. opr.symbol:=current_asmdata.RefAsmSymbol(current_procinfo.procdef.mangledname,AT_FUNCTION);
  360. opr.symseg:=true;
  361. opr.sym_farproc_entry:=false;
  362. {$else i8086}
  363. Message(asmr_w_CODE_and_DATA_not_supported);
  364. {$endif i8086}
  365. end;
  366. procedure Tx86Operand.SetupData;
  367. begin
  368. {$ifdef i8086}
  369. InitRef;
  370. if current_settings.x86memorymodel=mm_huge then
  371. opr.ref.refaddr:=addr_fardataseg
  372. else
  373. opr.ref.refaddr:=addr_dgroup;
  374. {$else i8086}
  375. Message(asmr_w_CODE_and_DATA_not_supported);
  376. {$endif i8086}
  377. end;
  378. constructor Tx86Operand.create;
  379. begin
  380. inherited;
  381. vopext := 0;
  382. vbcst := 0;
  383. end;
  384. {*****************************************************************************
  385. T386Instruction
  386. *****************************************************************************}
  387. constructor Tx86Instruction.Create(optype : tcoperand);
  388. begin
  389. inherited Create(optype);
  390. Opsize:=S_NO;
  391. end;
  392. procedure Tx86Instruction.AddReferenceSizes;
  393. { this will add the sizes for references like [esi] which do not
  394. have the size set yet, it will take only the size if the other
  395. operand is a register }
  396. var
  397. operand2,i,j,k : longint;
  398. t: topsize;
  399. s : tasmsymbol;
  400. so : aint;
  401. ExistsMemRefNoSize: boolean;
  402. ExistsMemRef: boolean;
  403. ExistsConstNoSize: boolean;
  404. ExistConst: boolean;
  405. ExistsLocalSymSize: boolean;
  406. ExistsBCST: boolean;
  407. memrefsize: integer;
  408. memopsize: integer;
  409. memoffset: asizeint;
  410. vbcst: byte;
  411. mmregs: Set of TSubregister;
  412. multiplicator: integer;
  413. bcst1,bcst2: string;
  414. begin
  415. ExistsMemRefNoSize := false;
  416. ExistsMemRef := false;
  417. ExistsConstNoSize := false;
  418. ExistsLocalSymSize := false;
  419. ExistsBCST := false;
  420. // EXIST A MEMORY- OR CONSTANT-OPERAND WITHOUT SIZE ?
  421. for i := 1 to ops do
  422. begin
  423. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then
  424. begin
  425. ExistsMemRef := true;
  426. ExistsBCST := (MemRefInfo(opcode).ExistsSSEAVX) and
  427. (tx86operand(operands[i]).vbcst <> 0);
  428. if (tx86operand(operands[i]).opsize = S_NO) then
  429. begin
  430. ExistsMemRefNoSize := true;
  431. case operands[i].opr.Typ of
  432. OPR_LOCAL: ExistsLocalSymSize := tx86operand(operands[i]).opr.localsym.getsize > 0;
  433. OPR_REFERENCE: ExistsLocalSymSize := true;
  434. else
  435. ;
  436. end;
  437. end;
  438. end
  439. else if operands[i].Opr.Typ in [OPR_CONSTANT] then
  440. begin
  441. ExistsConstNoSize := tx86operand(operands[i]).opsize = S_NO;
  442. end;
  443. end;
  444. // ONLY SUPPORTED OPCODES WITH SSE- OR AVX-REGISTERS
  445. if (ExistsMemRef) and
  446. (MemRefInfo(opcode).ExistsSSEAVX) then
  447. begin
  448. // 1. WE HAVE AN SSE- OR AVX-OPCODE WITH MEMORY OPERAND
  449. if (not(ExistsMemRefNoSize)) or
  450. (ExistsLocalSymSize) then
  451. begin
  452. // 2. WE KNOWN THE MEMORYSIZE OF THE MEMORY-OPERAND OR WE CAN
  453. // CALC THE MEMORYSIZE
  454. // 3. CALC THE SIZE OF THE MEMORYOPERAND BY OPCODE-DEFINITION
  455. // 4. COMPARE THE SIZE FROM OPCODE-DEFINITION AND THE REAL MEMORY-OPERAND-SIZE
  456. // - validate memory-reference-size
  457. for i := 1 to ops do
  458. begin
  459. if (operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL]) then
  460. begin
  461. memrefsize := -1;
  462. if ExistsBCST then
  463. begin
  464. case MemRefInfo(opcode).MemRefSizeBCST of
  465. msbBCST32: memrefsize := 32;
  466. msbBCST64: memrefsize := 64;
  467. else
  468. Internalerror(2019081005);
  469. end;
  470. end
  471. else
  472. case MemRefInfo(opcode).MemRefSize of
  473. msiMultiple8,
  474. msiMem8: memrefsize := 8;
  475. msiMultiple16,
  476. msiMem16: memrefsize := 16;
  477. msiXMem32,
  478. msiYMem32,
  479. msiMultiple32,
  480. msiMem32: memrefsize := 32;
  481. msiXMem64,
  482. msiYMem64,
  483. msiMultiple64,
  484. msiMem64: memrefsize := 64;
  485. msiMultiple128,
  486. msiMem128: memrefsize := 128;
  487. msiMultiple256,
  488. msiMem256: memrefsize := 256;
  489. msiMultiple512,
  490. msiMem512: memrefsize := 512;
  491. msiMemRegx16y32:
  492. begin
  493. for j := 1 to ops do
  494. begin
  495. if operands[j].Opr.Typ = OPR_REGISTER then
  496. begin
  497. case getsubreg(operands[j].opr.reg) of
  498. R_SUBMMX: memrefsize := 16;
  499. R_SUBMMY: memrefsize := 32;
  500. else Message(asmr_e_unable_to_determine_reference_size);
  501. end;
  502. end;
  503. end;
  504. end;
  505. msiMemRegx32y64:
  506. begin
  507. for j := 1 to ops do
  508. begin
  509. if operands[j].Opr.Typ = OPR_REGISTER then
  510. begin
  511. case getsubreg(operands[j].opr.reg) of
  512. R_SUBMMX: memrefsize := 32;
  513. R_SUBMMY: memrefsize := 64;
  514. else Message(asmr_e_unable_to_determine_reference_size);
  515. end;
  516. end;
  517. end;
  518. end;
  519. msiMemRegx64y128:
  520. begin
  521. for j := 1 to ops do
  522. begin
  523. if operands[j].Opr.Typ = OPR_REGISTER then
  524. begin
  525. case getsubreg(operands[j].opr.reg) of
  526. R_SUBMMX: memrefsize := 64;
  527. R_SUBMMY: memrefsize := 128;
  528. else Message(asmr_e_unable_to_determine_reference_size);
  529. end;
  530. end;
  531. end;
  532. end;
  533. msiMemRegx64y256:
  534. begin
  535. for j := 1 to ops do
  536. begin
  537. if operands[j].Opr.Typ = OPR_REGISTER then
  538. begin
  539. case getsubreg(operands[j].opr.reg) of
  540. R_SUBMMX: memrefsize := 64;
  541. R_SUBMMY: memrefsize := 256;
  542. else Message(asmr_e_unable_to_determine_reference_size);
  543. end;
  544. end;
  545. end;
  546. end;
  547. msiMemRegx64y128z256:
  548. begin
  549. begin
  550. for j := 1 to ops do
  551. begin
  552. if operands[j].Opr.Typ = OPR_REGISTER then
  553. begin
  554. case getsubreg(operands[j].opr.reg) of
  555. R_SUBMMX: memrefsize := 64;
  556. R_SUBMMY: memrefsize := 128;
  557. R_SUBMMZ: memrefsize := 256;
  558. else Message(asmr_e_unable_to_determine_reference_size);
  559. end;
  560. end;
  561. end;
  562. end;
  563. end;
  564. msiMemRegx64y256z512:
  565. begin
  566. begin
  567. for j := 1 to ops do
  568. begin
  569. if operands[j].Opr.Typ = OPR_REGISTER then
  570. begin
  571. case getsubreg(operands[j].opr.reg) of
  572. R_SUBMMX: memrefsize := 64;
  573. R_SUBMMY: memrefsize := 256;
  574. R_SUBMMZ: memrefsize := 512;
  575. else Message(asmr_e_unable_to_determine_reference_size);
  576. end;
  577. end;
  578. end;
  579. end;
  580. end;
  581. msiMemRegSize:
  582. begin
  583. for j := 1 to ops do
  584. begin
  585. if operands[j].Opr.Typ = OPR_REGISTER then
  586. begin
  587. if (tx86operand(operands[j]).opsize <> S_NO) and
  588. (tx86operand(operands[j]).size <> OS_NO) then
  589. begin
  590. case tx86operand(operands[j]).opsize of
  591. S_B : memrefsize := 8;
  592. S_W : memrefsize := 16;
  593. S_L : memrefsize := 32;
  594. S_Q : memrefsize := 64;
  595. S_XMM : memrefsize := 128;
  596. S_YMM : memrefsize := 256;
  597. S_ZMM : memrefsize := 512;
  598. else Internalerror(2019081001);
  599. end;
  600. break;
  601. end;
  602. end;
  603. end;
  604. end;
  605. msiMemRegConst128,
  606. msiMemRegConst256,
  607. msiMemRegConst512:
  608. begin
  609. for j := 1 to ops do
  610. begin
  611. if operands[j].Opr.Typ = OPR_CONSTANT then
  612. begin
  613. for k := 1 to ops do
  614. begin
  615. if operands[k].Opr.Typ = OPR_REGISTER then
  616. begin
  617. if (tx86operand(operands[k]).opsize <> S_NO) and
  618. (tx86operand(operands[k]).size <> OS_NO) then
  619. begin
  620. case tx86operand(operands[k]).opsize of
  621. S_B : memrefsize := 8;
  622. S_W : memrefsize := 16;
  623. S_L : memrefsize := 32;
  624. S_Q : memrefsize := 64;
  625. S_XMM : memrefsize := 128;
  626. S_YMM : memrefsize := 256;
  627. S_ZMM : memrefsize := 512;
  628. else Internalerror(777200);
  629. end;
  630. break;
  631. end;
  632. end;
  633. end;
  634. break;
  635. end;
  636. end;
  637. // no exists const-operand
  638. if memrefsize = -1 then
  639. begin
  640. case MemRefInfo(opcode).MemRefSize of
  641. msiMemRegConst128: memrefsize := 128;
  642. msiMemRegConst256: memrefsize := 256;
  643. msiMemRegConst512: memrefsize := 512;
  644. else Internalerror(2019081002);
  645. end;
  646. end;
  647. end;
  648. msiNoSize,
  649. msiUnkown,
  650. msiUnsupported,
  651. msiVMemMultiple,
  652. msiVMemRegSize,
  653. msiMultiple:
  654. ;
  655. else
  656. Internalerror(2019081005);
  657. end;
  658. if memrefsize > -1 then
  659. begin
  660. // CALC REAL-MEMORY-OPERAND-SIZE AND A POSSIBLE OFFSET
  661. // OFFSET:
  662. // e.g. PAND XMM0, [RAX + 16] =>> OFFSET = 16 BYTES
  663. // PAND XMM0, [RAX + a.b + 10] =>> OFFSET = 10 BYTES (a = record-variable)
  664. memopsize := 0;
  665. case operands[i].opr.typ of
  666. OPR_LOCAL: memopsize := operands[i].opr.localvarsize * 8;
  667. OPR_REFERENCE:
  668. if operands[i].opr.ref.refaddr = addr_pic then
  669. memopsize := sizeof(pint) * 8
  670. else
  671. memopsize := operands[i].opr.varsize * 8;
  672. else
  673. ;
  674. end;
  675. if memopsize = 0 then memopsize := topsize2memsize[tx86operand(operands[i]).opsize];
  676. if (memopsize > 0) and
  677. (memrefsize > 0) then
  678. begin
  679. memoffset := 0;
  680. case operands[i].opr.typ of
  681. OPR_LOCAL:
  682. memoffset := operands[i].opr.localconstoffset;
  683. OPR_REFERENCE:
  684. memoffset := operands[i].opr.constoffset;
  685. else
  686. ;
  687. end;
  688. if memoffset < 0 then
  689. begin
  690. Message2(asmr_w_check_mem_operand_negative_offset,
  691. std_op2str[opcode],
  692. ToStr(memoffset));
  693. end
  694. else if (memopsize < (memrefsize + memoffset * 8)) then
  695. begin
  696. if memoffset = 0 then
  697. begin
  698. Message3(asmr_w_check_mem_operand_size3,
  699. std_op2str[opcode],
  700. ToStr(memopsize),
  701. ToStr(memrefsize)
  702. );
  703. end
  704. else
  705. begin
  706. Message4(asmr_w_check_mem_operand_size_offset,
  707. std_op2str[opcode],
  708. ToStr(memopsize),
  709. ToStr(memrefsize),
  710. ToStr(memoffset)
  711. );
  712. end;
  713. end;
  714. end;
  715. end;
  716. end;
  717. end;
  718. end;
  719. end;
  720. if (ExistsMemRefNoSize or ExistsConstNoSize) and
  721. (MemRefInfo(opcode).ExistsSSEAVX) then
  722. begin
  723. for i := 1 to ops do
  724. begin
  725. if (tx86operand(operands[i]).opsize = S_NO) then
  726. begin
  727. case operands[i].Opr.Typ of
  728. OPR_REFERENCE:
  729. begin
  730. if ExistsBCST then
  731. begin
  732. case MemRefInfo(opcode).MemRefSizeBCST of
  733. msbBCST32: begin
  734. tx86operand(operands[i]).opsize := S_L;
  735. tx86operand(operands[i]).size := OS_32;
  736. end;
  737. msbBCST64: begin
  738. tx86operand(operands[i]).opsize := S_Q;
  739. tx86operand(operands[i]).size := OS_M64;
  740. end;
  741. else
  742. Internalerror(2019081006);
  743. end;
  744. end
  745. else
  746. case MemRefInfo(opcode).MemRefSize of
  747. msiMem8:
  748. begin
  749. tx86operand(operands[i]).opsize := S_B;
  750. tx86operand(operands[i]).size := OS_8;
  751. end;
  752. msiMultiple8:
  753. begin
  754. tx86operand(operands[i]).opsize := S_B;
  755. tx86operand(operands[i]).size := OS_8;
  756. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"8 bit memory operand"');
  757. end;
  758. msiMem16:
  759. begin
  760. tx86operand(operands[i]).opsize := S_W;
  761. tx86operand(operands[i]).size := OS_16;
  762. end;
  763. msiMultiple16:
  764. begin
  765. tx86operand(operands[i]).opsize := S_W;
  766. tx86operand(operands[i]).size := OS_16;
  767. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"16 bit memory operand"');
  768. end;
  769. msiXMem32,
  770. msiYMem32,
  771. msiMem32:
  772. begin
  773. tx86operand(operands[i]).opsize := S_L;
  774. tx86operand(operands[i]).size := OS_32;
  775. end;
  776. msiMultiple32:
  777. begin
  778. tx86operand(operands[i]).opsize := S_L;
  779. tx86operand(operands[i]).size := OS_32;
  780. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"32 bit memory operand"');
  781. end;
  782. msiXMem64,
  783. msiYMem64,
  784. msiMem64:
  785. begin
  786. tx86operand(operands[i]).opsize := S_Q;
  787. tx86operand(operands[i]).size := OS_M64;
  788. end;
  789. msiMultiple64:
  790. begin
  791. tx86operand(operands[i]).opsize := S_Q;
  792. tx86operand(operands[i]).size := OS_M64;
  793. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"64 bit memory operand"');
  794. end;
  795. msiMem128:
  796. begin
  797. tx86operand(operands[i]).opsize := S_XMM;
  798. tx86operand(operands[i]).size := OS_M128;
  799. end;
  800. msiMultiple128:
  801. begin
  802. tx86operand(operands[i]).opsize := S_XMM;
  803. tx86operand(operands[i]).size := OS_M128;
  804. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"128 bit memory operand"');
  805. end;
  806. msiMem256:
  807. begin
  808. tx86operand(operands[i]).opsize := S_YMM;
  809. tx86operand(operands[i]).size := OS_M256;
  810. opsize := S_YMM;
  811. end;
  812. msiMultiple256:
  813. begin
  814. tx86operand(operands[i]).opsize := S_YMM;
  815. tx86operand(operands[i]).size := OS_M256;
  816. opsize := S_YMM;
  817. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"256 bit memory operand"');
  818. end;
  819. msiMem512:
  820. begin
  821. tx86operand(operands[i]).opsize := S_ZMM;
  822. tx86operand(operands[i]).size := OS_M512;
  823. opsize := S_ZMM;
  824. end;
  825. msiMultiple512:
  826. begin
  827. tx86operand(operands[i]).opsize := S_ZMM;
  828. tx86operand(operands[i]).size := OS_M512;
  829. opsize := S_ZMM;
  830. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"512 bit memory operand"');
  831. end;
  832. msiMemRegSize:
  833. begin
  834. // mem-ref-size = register size
  835. for j := 1 to ops do
  836. begin
  837. if operands[j].Opr.Typ = OPR_REGISTER then
  838. begin
  839. if (tx86operand(operands[j]).opsize <> S_NO) and
  840. (tx86operand(operands[j]).size <> OS_NO) then
  841. begin
  842. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  843. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  844. break;
  845. end
  846. else Message(asmr_e_unable_to_determine_reference_size);
  847. end;
  848. end;
  849. end;
  850. msiMemRegx16y32:
  851. begin
  852. for j := 1 to ops do
  853. begin
  854. if operands[j].Opr.Typ = OPR_REGISTER then
  855. begin
  856. case getsubreg(operands[j].opr.reg) of
  857. R_SUBMMX: begin
  858. tx86operand(operands[i]).opsize := S_W;
  859. tx86operand(operands[i]).size := OS_M16;
  860. break;
  861. end;
  862. R_SUBMMY: begin
  863. tx86operand(operands[i]).opsize := S_L;
  864. tx86operand(operands[i]).size := OS_M32;
  865. break;
  866. end;
  867. else Message(asmr_e_unable_to_determine_reference_size);
  868. end;
  869. end;
  870. end;
  871. end;
  872. msiMemRegx16y32z64:
  873. begin
  874. for j := 1 to ops do
  875. begin
  876. if operands[j].Opr.Typ = OPR_REGISTER then
  877. begin
  878. case getsubreg(operands[j].opr.reg) of
  879. R_SUBMMX: begin
  880. tx86operand(operands[i]).opsize := S_W;
  881. tx86operand(operands[i]).size := OS_M16;
  882. break;
  883. end;
  884. R_SUBMMY: begin
  885. tx86operand(operands[i]).opsize := S_L;
  886. tx86operand(operands[i]).size := OS_M32;
  887. break;
  888. end;
  889. R_SUBMMZ: begin
  890. tx86operand(operands[i]).opsize := S_Q;
  891. tx86operand(operands[i]).size := OS_M64;
  892. break;
  893. end;
  894. else Message(asmr_e_unable_to_determine_reference_size);
  895. end;
  896. end;
  897. end;
  898. end;
  899. msiMemRegx32y64:
  900. begin
  901. for j := 1 to ops do
  902. begin
  903. if operands[j].Opr.Typ = OPR_REGISTER then
  904. begin
  905. case getsubreg(operands[j].opr.reg) of
  906. R_SUBMMX: begin
  907. tx86operand(operands[i]).opsize := S_L;
  908. tx86operand(operands[i]).size := OS_M32;
  909. break;
  910. end;
  911. R_SUBMMY: begin
  912. tx86operand(operands[i]).opsize := S_Q;
  913. tx86operand(operands[i]).size := OS_M64;
  914. break;
  915. end;
  916. else Message(asmr_e_unable_to_determine_reference_size);
  917. end;
  918. end;
  919. end;
  920. end;
  921. msiMemRegx32y64z128:
  922. for j := 1 to ops do
  923. begin
  924. if operands[j].Opr.Typ = OPR_REGISTER then
  925. begin
  926. case getsubreg(operands[j].opr.reg) of
  927. R_SUBMMX: begin
  928. tx86operand(operands[i]).opsize := S_L;
  929. tx86operand(operands[i]).size := OS_M32;
  930. break;
  931. end;
  932. R_SUBMMY: begin
  933. tx86operand(operands[i]).opsize := S_Q;
  934. tx86operand(operands[i]).size := OS_M64;
  935. break;
  936. end;
  937. R_SUBMMZ: begin
  938. tx86operand(operands[i]).opsize := S_XMM;
  939. tx86operand(operands[i]).size := OS_M128;
  940. break;
  941. end;
  942. else Message(asmr_e_unable_to_determine_reference_size);
  943. end;
  944. end;
  945. end;
  946. msiMemRegx64y128:
  947. begin
  948. for j := 1 to ops do
  949. begin
  950. if operands[j].Opr.Typ = OPR_REGISTER then
  951. begin
  952. case getsubreg(operands[j].opr.reg) of
  953. R_SUBMMX: begin
  954. tx86operand(operands[i]).opsize := S_Q;
  955. tx86operand(operands[i]).size := OS_M64;
  956. break;
  957. end;
  958. R_SUBMMY: begin
  959. tx86operand(operands[i]).opsize := S_XMM;
  960. tx86operand(operands[i]).size := OS_M128;
  961. break;
  962. end;
  963. else Message(asmr_e_unable_to_determine_reference_size);
  964. end;
  965. end;
  966. end;
  967. end;
  968. msiMemRegx64y128z256:
  969. begin
  970. for j := 1 to ops do
  971. begin
  972. if operands[j].Opr.Typ = OPR_REGISTER then
  973. begin
  974. case getsubreg(operands[j].opr.reg) of
  975. R_SUBMMX: begin
  976. tx86operand(operands[i]).opsize := S_Q;
  977. tx86operand(operands[i]).size := OS_M64;
  978. break;
  979. end;
  980. R_SUBMMY: begin
  981. tx86operand(operands[i]).opsize := S_XMM;
  982. tx86operand(operands[i]).size := OS_M128;
  983. break;
  984. end;
  985. R_SUBMMZ: begin
  986. tx86operand(operands[i]).opsize := S_YMM;
  987. tx86operand(operands[i]).size := OS_M256;
  988. break;
  989. end;
  990. else Message(asmr_e_unable_to_determine_reference_size);
  991. end;
  992. end;
  993. end;
  994. end;
  995. msiMemRegx64y256:
  996. begin
  997. for j := 1 to ops do
  998. begin
  999. if operands[j].Opr.Typ = OPR_REGISTER then
  1000. begin
  1001. case getsubreg(operands[j].opr.reg) of
  1002. R_SUBMMX: begin
  1003. tx86operand(operands[i]).opsize := S_Q;
  1004. tx86operand(operands[i]).size := OS_M64;
  1005. break;
  1006. end;
  1007. R_SUBMMY: begin
  1008. tx86operand(operands[i]).opsize := S_YMM;
  1009. tx86operand(operands[i]).size := OS_M256;
  1010. break;
  1011. end;
  1012. else Message(asmr_e_unable_to_determine_reference_size);
  1013. end;
  1014. end;
  1015. end;
  1016. end;
  1017. msiMemRegx64y256z512:
  1018. begin
  1019. for j := 1 to ops do
  1020. begin
  1021. if operands[j].Opr.Typ = OPR_REGISTER then
  1022. begin
  1023. case getsubreg(operands[j].opr.reg) of
  1024. R_SUBMMX: begin
  1025. tx86operand(operands[i]).opsize := S_Q;
  1026. tx86operand(operands[i]).size := OS_M64;
  1027. break;
  1028. end;
  1029. R_SUBMMY: begin
  1030. tx86operand(operands[i]).opsize := S_YMM;
  1031. tx86operand(operands[i]).size := OS_M256;
  1032. break;
  1033. end;
  1034. R_SUBMMZ: begin
  1035. tx86operand(operands[i]).opsize := S_ZMM;
  1036. tx86operand(operands[i]).size := OS_M512;
  1037. break;
  1038. end;
  1039. else Message(asmr_e_unable_to_determine_reference_size);
  1040. end;
  1041. end;
  1042. end;
  1043. end;
  1044. msiMemRegConst128,
  1045. msiMemRegConst256,
  1046. msiMemRegConst512:
  1047. begin
  1048. ExistConst := false;
  1049. for j := 1 to ops do
  1050. begin
  1051. if operands[j].Opr.Typ = OPR_CONSTANT then
  1052. begin
  1053. ExistConst := true;
  1054. break;
  1055. end;
  1056. end;
  1057. if ExistConst then
  1058. begin
  1059. for j := 1 to ops do
  1060. begin
  1061. if operands[j].Opr.Typ = OPR_REGISTER then
  1062. begin
  1063. if (tx86operand(operands[j]).opsize <> S_NO) and
  1064. (tx86operand(operands[j]).size <> OS_NO) then
  1065. begin
  1066. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  1067. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  1068. break;
  1069. end
  1070. else Message(asmr_e_unable_to_determine_reference_size);
  1071. end;
  1072. end;
  1073. end
  1074. else
  1075. begin
  1076. case MemRefInfo(opcode).MemRefSize of
  1077. msiMemRegConst128: begin
  1078. tx86operand(operands[i]).opsize := S_XMM;
  1079. tx86operand(operands[i]).size := OS_M128;
  1080. break;
  1081. end;
  1082. msiMemRegConst256: begin
  1083. tx86operand(operands[i]).opsize := S_YMM;
  1084. tx86operand(operands[i]).size := OS_M256;
  1085. break;
  1086. end;
  1087. msiMemRegConst512: begin
  1088. tx86operand(operands[i]).opsize := S_ZMM;
  1089. tx86operand(operands[i]).size := OS_M512;
  1090. break;
  1091. end;
  1092. else
  1093. Internalerror(2019081007);
  1094. end;
  1095. end;
  1096. end;
  1097. msiNoSize: ; // all memory-sizes are ok
  1098. msiUnkown,
  1099. msiUnsupported,
  1100. msiVMemMultiple,
  1101. msiVMemRegSize,
  1102. msiMultiple: Message(asmr_e_unable_to_determine_reference_size); // TODO individual message
  1103. else
  1104. Internalerror(2019081008);
  1105. end;
  1106. end;
  1107. OPR_CONSTANT:
  1108. case MemRefInfo(opcode).ConstSize of
  1109. csiMem8: begin
  1110. tx86operand(operands[i]).opsize := S_B;
  1111. tx86operand(operands[i]).size := OS_8;
  1112. end;
  1113. csiMem16: begin
  1114. tx86operand(operands[i]).opsize := S_W;
  1115. tx86operand(operands[i]).size := OS_16;
  1116. end;
  1117. csiMem32: begin
  1118. tx86operand(operands[i]).opsize := S_L;
  1119. tx86operand(operands[i]).size := OS_32;
  1120. end;
  1121. {$ifdef x86_64}
  1122. csiMem64: begin
  1123. tx86operand(operands[i]).opsize := S_Q;
  1124. tx86operand(operands[i]).size := OS_64;
  1125. end;
  1126. {$else}
  1127. csiMem64: begin
  1128. internalerror(2019050910);
  1129. end;
  1130. {$endif}
  1131. csiUnkown, csiMultiple, csiNoSize:
  1132. ;
  1133. end;
  1134. else
  1135. ;
  1136. end;
  1137. end;
  1138. end;
  1139. end;
  1140. for i:=1 to ops do
  1141. begin
  1142. operands[i].SetCorrectSize(opcode);
  1143. if tx86operand(operands[i]).opsize=S_NO then
  1144. begin
  1145. {$ifdef x86_64}
  1146. if (opcode=A_MOVQ) and
  1147. (ops=2) and
  1148. (operands[1].opr.typ=OPR_CONSTANT) then
  1149. opsize:=S_Q
  1150. else
  1151. {$endif x86_64}
  1152. case operands[i].Opr.Typ of
  1153. OPR_LOCAL,
  1154. OPR_REFERENCE :
  1155. begin
  1156. { for 3-operand opcodes, operand #1 (in ATT order) is always an immediate,
  1157. don't consider it. }
  1158. if i=ops then
  1159. operand2:=i-1
  1160. else
  1161. operand2:=i+1;
  1162. if operand2>0 then
  1163. begin
  1164. { Only allow register as operand to take the size from }
  1165. if operands[operand2].opr.typ=OPR_REGISTER then
  1166. begin
  1167. if ((opcode<>A_MOVD) and
  1168. (opcode<>A_CVTSI2SS)) then
  1169. begin
  1170. //tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  1171. // torsten - 31.01.2012
  1172. // old: xmm/ymm-register operands have a opsize = "S_NO"
  1173. // new: xmm/ymm-register operands have a opsize = "S_XMM/S_YMM"
  1174. // any SSE- and AVX-opcodes have mixed operand sizes (e.g. cvtsd2ss xmmreg, xmmreg/m32)
  1175. // in this case is we need the old handling ("S_NO")
  1176. // =>> ignore
  1177. if (tx86operand(operands[operand2]).opsize <> S_XMM) and
  1178. (tx86operand(operands[operand2]).opsize <> S_YMM) and
  1179. (tx86operand(operands[operand2]).opsize <> S_ZMM) then
  1180. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize
  1181. else tx86operand(operands[operand2]).opsize := S_NO;
  1182. end;
  1183. end
  1184. else
  1185. begin
  1186. { if no register then take the opsize (which is available with ATT),
  1187. if not availble then give an error }
  1188. if opsize<>S_NO then
  1189. tx86operand(operands[i]).opsize:=opsize
  1190. else
  1191. begin
  1192. if (m_delphi in current_settings.modeswitches) then
  1193. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  1194. else
  1195. Message(asmr_e_unable_to_determine_reference_size);
  1196. { recovery }
  1197. tx86operand(operands[i]).opsize:=S_L;
  1198. end;
  1199. end;
  1200. end
  1201. else
  1202. begin
  1203. if opsize<>S_NO then
  1204. tx86operand(operands[i]).opsize:=opsize
  1205. end;
  1206. end;
  1207. OPR_SYMBOL :
  1208. begin
  1209. { Fix lea which need a reference }
  1210. if opcode=A_LEA then
  1211. begin
  1212. s:=operands[i].opr.symbol;
  1213. so:=operands[i].opr.symofs;
  1214. operands[i].opr.typ:=OPR_REFERENCE;
  1215. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  1216. operands[i].opr.ref.symbol:=s;
  1217. operands[i].opr.ref.offset:=so;
  1218. end;
  1219. {$if defined(x86_64)}
  1220. tx86operand(operands[i]).opsize:=S_Q;
  1221. {$elseif defined(i386)}
  1222. tx86operand(operands[i]).opsize:=S_L;
  1223. {$elseif defined(i8086)}
  1224. tx86operand(operands[i]).opsize:=S_W;
  1225. {$endif}
  1226. end;
  1227. else
  1228. ;
  1229. end;
  1230. end;
  1231. end;
  1232. if MemRefInfo(opcode).ExistsSSEAVX then
  1233. begin
  1234. // validate broadcast-memory-operands
  1235. vbcst := 0;
  1236. mmregs := [];
  1237. for i := 1 to ops do
  1238. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then vbcst := tx86operand(operands[i]).vbcst
  1239. else if operands[i].Opr.Typ = OPR_REGISTER then
  1240. begin
  1241. if getsubreg(operands[i].opr.reg) in [R_SUBMMX, R_SUBMMY, R_SUBMMZ] then
  1242. begin
  1243. include(mmregs, getsubreg(operands[i].opr.reg));
  1244. end;
  1245. end;
  1246. if vbcst <> 0 then
  1247. begin
  1248. // found broadcast-memory-operand (e.g. "{1to8}")
  1249. // check is correct
  1250. multiplicator := 0;
  1251. if mmregs = [R_SUBMMX] then multiplicator := 1
  1252. else if mmregs = [R_SUBMMY] then multiplicator := 2
  1253. else if mmregs = [R_SUBMMZ] then multiplicator := 4
  1254. else
  1255. begin
  1256. //TG TODO
  1257. end;
  1258. if MemRefInfo(opcode).BCSTTypes <> [] then
  1259. begin
  1260. str(MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator, bcst1);
  1261. str(vbcst, bcst2);
  1262. case vbcst of
  1263. 2: if not(bt1to2 in MemRefInfo(opcode).BCSTTypes) then
  1264. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1265. 4: if not(bt1to4 in MemRefInfo(opcode).BCSTTypes) then
  1266. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1267. 8: if not(bt1to8 in MemRefInfo(opcode).BCSTTypes) then
  1268. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1269. 16: if not(bt1to16 in MemRefInfo(opcode).BCSTTypes) then
  1270. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1271. end;
  1272. end
  1273. else if MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator <> vbcst then
  1274. begin
  1275. str(MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator, bcst1);
  1276. str(vbcst, bcst2);
  1277. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1278. end;
  1279. end;
  1280. end;
  1281. end;
  1282. procedure Tx86Instruction.SetInstructionOpsize;
  1283. begin
  1284. if opsize<>S_NO then
  1285. exit;
  1286. case ops of
  1287. 0 : ;
  1288. 1 :
  1289. begin
  1290. { "push es" must be stored as a long PM }
  1291. if ((opcode=A_PUSH) or
  1292. (opcode=A_POP)) and
  1293. (operands[1].opr.typ=OPR_REGISTER) and
  1294. is_segment_reg(operands[1].opr.reg) then
  1295. {$ifdef i8086}
  1296. opsize:=S_W
  1297. {$else i8086}
  1298. opsize:=S_L
  1299. {$endif i8086}
  1300. else
  1301. opsize:=tx86operand(operands[1]).opsize;
  1302. end;
  1303. 2 :
  1304. begin
  1305. case opcode of
  1306. A_MOVZX,A_MOVSX :
  1307. begin
  1308. if tx86operand(operands[1]).opsize=S_NO then
  1309. begin
  1310. tx86operand(operands[1]).opsize:=S_B;
  1311. if (m_delphi in current_settings.modeswitches) then
  1312. Message(asmr_w_unable_to_determine_reference_size_using_byte)
  1313. else
  1314. Message(asmr_e_unable_to_determine_reference_size);
  1315. end;
  1316. case tx86operand(operands[1]).opsize of
  1317. S_W :
  1318. case tx86operand(operands[2]).opsize of
  1319. S_L :
  1320. opsize:=S_WL;
  1321. {$ifdef x86_64}
  1322. S_Q :
  1323. opsize:=S_WQ;
  1324. {$endif}
  1325. else
  1326. ;
  1327. end;
  1328. S_B :
  1329. begin
  1330. case tx86operand(operands[2]).opsize of
  1331. S_W :
  1332. opsize:=S_BW;
  1333. S_L :
  1334. opsize:=S_BL;
  1335. {$ifdef x86_64}
  1336. S_Q :
  1337. opsize:=S_BQ;
  1338. {$endif}
  1339. else
  1340. ;
  1341. end;
  1342. end;
  1343. else
  1344. ;
  1345. end;
  1346. end;
  1347. A_MOVSS,
  1348. A_VMOVSS,
  1349. A_MOVD : { movd is a move from a mmx register to a
  1350. 32 bit register or memory, so no opsize is correct here PM }
  1351. exit;
  1352. A_MOVQ :
  1353. opsize:=S_IQ;
  1354. A_CVTSI2SS,
  1355. A_CVTSI2SD,
  1356. A_OUT :
  1357. opsize:=tx86operand(operands[1]).opsize;
  1358. else
  1359. opsize:=tx86operand(operands[2]).opsize;
  1360. end;
  1361. end;
  1362. 3 :
  1363. begin
  1364. case opcode of
  1365. A_VCVTSI2SS,
  1366. A_VCVTSI2SD:
  1367. opsize:=tx86operand(operands[1]).opsize;
  1368. else
  1369. opsize:=tx86operand(operands[ops]).opsize;
  1370. end;
  1371. end;
  1372. 4 :
  1373. opsize:=tx86operand(operands[ops]).opsize;
  1374. end;
  1375. end;
  1376. procedure Tx86Instruction.CheckOperandSizes;
  1377. var
  1378. sizeerr : boolean;
  1379. i : longint;
  1380. begin
  1381. { Check only the most common opcodes here, the others are done in
  1382. the assembler pass }
  1383. case opcode of
  1384. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  1385. A_CMP,A_MOV,
  1386. A_ADD,A_SUB,A_ADC,A_SBB,
  1387. A_AND,A_OR,A_TEST,A_XOR: ;
  1388. else
  1389. exit;
  1390. end;
  1391. { Handle the BW,BL,WL separatly }
  1392. sizeerr:=false;
  1393. { special push/pop selector case }
  1394. if ((opcode=A_PUSH) or
  1395. (opcode=A_POP)) and
  1396. (operands[1].opr.typ=OPR_REGISTER) and
  1397. is_segment_reg(operands[1].opr.reg) then
  1398. exit;
  1399. if opsize in [S_BW,S_BL,S_WL] then
  1400. begin
  1401. if ops<>2 then
  1402. sizeerr:=true
  1403. else
  1404. begin
  1405. case opsize of
  1406. S_BW :
  1407. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  1408. S_BL :
  1409. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  1410. S_WL :
  1411. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  1412. {$ifdef x86_64}
  1413. S_BQ:
  1414. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_Q);
  1415. S_WQ:
  1416. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_Q);
  1417. S_LQ:
  1418. sizeerr:=(tx86operand(operands[1]).opsize<>S_L) or (tx86operand(operands[2]).opsize<>S_Q);
  1419. {$endif}
  1420. else
  1421. ;
  1422. end;
  1423. end;
  1424. end
  1425. else
  1426. begin
  1427. for i:=1 to ops do
  1428. begin
  1429. if (operands[i].opr.typ<>OPR_CONSTANT) and
  1430. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  1431. (tx86operand(operands[i]).opsize<>opsize) then
  1432. sizeerr:=true;
  1433. end;
  1434. end;
  1435. if sizeerr then
  1436. begin
  1437. { if range checks are on then generate an error }
  1438. if (cs_compilesystem in current_settings.moduleswitches) or
  1439. not (cs_check_range in current_settings.localswitches) then
  1440. Message(asmr_w_size_suffix_and_dest_dont_match)
  1441. else
  1442. Message(asmr_e_size_suffix_and_dest_dont_match);
  1443. end;
  1444. end;
  1445. { This check must be done with the operand in ATT order
  1446. i.e.after swapping in the intel reader
  1447. but before swapping in the NASM and TASM writers PM }
  1448. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  1449. begin
  1450. if (
  1451. (ops=2) and
  1452. (operands[1].opr.typ=OPR_REGISTER) and
  1453. (operands[2].opr.typ=OPR_REGISTER) and
  1454. { if the first is ST and the second is also a register
  1455. it is necessarily ST1 .. ST7 }
  1456. ((operands[1].opr.reg=NR_ST) or
  1457. (operands[1].opr.reg=NR_ST0))
  1458. ) or
  1459. (ops=0) then
  1460. if opcode=A_FSUBR then
  1461. opcode:=A_FSUB
  1462. else if opcode=A_FSUB then
  1463. opcode:=A_FSUBR
  1464. else if opcode=A_FDIVR then
  1465. opcode:=A_FDIV
  1466. else if opcode=A_FDIV then
  1467. opcode:=A_FDIVR
  1468. else if opcode=A_FSUBRP then
  1469. opcode:=A_FSUBP
  1470. else if opcode=A_FSUBP then
  1471. opcode:=A_FSUBRP
  1472. else if opcode=A_FDIVRP then
  1473. opcode:=A_FDIVP
  1474. else if opcode=A_FDIVP then
  1475. opcode:=A_FDIVRP;
  1476. if (
  1477. (ops=1) and
  1478. (operands[1].opr.typ=OPR_REGISTER) and
  1479. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1480. (operands[1].opr.reg<>NR_ST) and
  1481. (operands[1].opr.reg<>NR_ST0)
  1482. ) then
  1483. if opcode=A_FSUBRP then
  1484. opcode:=A_FSUBP
  1485. else if opcode=A_FSUBP then
  1486. opcode:=A_FSUBRP
  1487. else if opcode=A_FDIVRP then
  1488. opcode:=A_FDIVP
  1489. else if opcode=A_FDIVP then
  1490. opcode:=A_FDIVRP;
  1491. end;
  1492. procedure Tx86Instruction.FixupOpcode;
  1493. begin
  1494. { does nothing by default }
  1495. end;
  1496. {*****************************************************************************
  1497. opcode Adding
  1498. *****************************************************************************}
  1499. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  1500. var
  1501. siz : topsize;
  1502. i : longint;
  1503. asize : int64;
  1504. ai : taicpu;
  1505. begin
  1506. ConcatInstruction:=nil;
  1507. ai:=nil;
  1508. for i:=1 to Ops do
  1509. if not operands[i].CheckOperand then
  1510. exit;
  1511. { Get Opsize }
  1512. if (opsize<>S_NO) or (Ops=0) then
  1513. siz:=opsize
  1514. else
  1515. begin
  1516. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  1517. siz:=tx86operand(operands[1]).opsize
  1518. else
  1519. siz:=tx86operand(operands[Ops]).opsize;
  1520. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  1521. if (ops=2) and
  1522. (tx86operand(operands[1]).opsize<>S_NO) and
  1523. (tx86operand(operands[2]).opsize<>S_NO) and
  1524. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  1525. siz:=S_NO;
  1526. end;
  1527. if ((opcode=A_MOVD)or
  1528. (opcode=A_CVTSI2SS)) and
  1529. ((tx86operand(operands[1]).opsize=S_NO) or
  1530. (tx86operand(operands[2]).opsize=S_NO)) then
  1531. siz:=S_NO;
  1532. { NASM does not support FADD without args
  1533. as alias of FADDP
  1534. and GNU AS interprets FADD without operand differently
  1535. for version 2.9.1 and 2.9.5 !! }
  1536. if (ops=0) and
  1537. ((opcode=A_FADD) or
  1538. (opcode=A_FMUL) or
  1539. (opcode=A_FSUB) or
  1540. (opcode=A_FSUBR) or
  1541. (opcode=A_FDIV) or
  1542. (opcode=A_FDIVR)) then
  1543. begin
  1544. if opcode=A_FADD then
  1545. opcode:=A_FADDP
  1546. else if opcode=A_FMUL then
  1547. opcode:=A_FMULP
  1548. else if opcode=A_FSUB then
  1549. opcode:=A_FSUBP
  1550. else if opcode=A_FSUBR then
  1551. opcode:=A_FSUBRP
  1552. else if opcode=A_FDIV then
  1553. opcode:=A_FDIVP
  1554. else if opcode=A_FDIVR then
  1555. opcode:=A_FDIVRP;
  1556. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  1557. end;
  1558. {It is valid to specify some instructions without operand size.}
  1559. if siz=S_NO then
  1560. begin
  1561. if (ops=1) and (opcode=A_INT) then
  1562. siz:=S_B;
  1563. if (ops=1) and (opcode=A_XABORT) then
  1564. siz:=S_B;
  1565. {$ifdef i8086}
  1566. if (ops=1) and (opcode=A_BRKEM) then
  1567. siz:=S_B;
  1568. {$endif i8086}
  1569. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) or
  1570. (opcode=A_RETW) or (opcode=A_RETNW) or (opcode=A_RETFW) or
  1571. {$ifndef x86_64}
  1572. (opcode=A_RETD) or (opcode=A_RETND) or
  1573. {$endif x86_64}
  1574. (opcode=A_RETFD)
  1575. {$ifdef x86_64}
  1576. or (opcode=A_RETQ) or (opcode=A_RETNQ) or (opcode=A_RETFQ)
  1577. {$endif x86_64}
  1578. then
  1579. siz:=S_W;
  1580. if (ops=1) and (opcode=A_PUSH) then
  1581. begin
  1582. {$ifdef i8086}
  1583. if (tx86operand(operands[1]).opr.val>=-128) and (tx86operand(operands[1]).opr.val<=127) then
  1584. begin
  1585. siz:=S_B;
  1586. message(asmr_w_unable_to_determine_constant_size_using_byte);
  1587. end
  1588. else
  1589. begin
  1590. siz:=S_W;
  1591. message(asmr_w_unable_to_determine_constant_size_using_word);
  1592. end;
  1593. {$else i8086}
  1594. { We are a 32 compiler, assume 32-bit by default. This is Delphi
  1595. compatible but bad coding practise.}
  1596. siz:=S_L;
  1597. message(asmr_w_unable_to_determine_reference_size_using_dword);
  1598. {$endif i8086}
  1599. end;
  1600. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  1601. if ops=1 then
  1602. siz:=S_NEAR
  1603. else
  1604. siz:=S_FAR;
  1605. end;
  1606. { GNU AS interprets FDIV without operand differently
  1607. for version 2.9.1 and 2.10
  1608. we add explicit args to it !! }
  1609. if (ops=0) and
  1610. ((opcode=A_FSUBP) or
  1611. (opcode=A_FSUBRP) or
  1612. (opcode=A_FDIVP) or
  1613. (opcode=A_FDIVRP) or
  1614. (opcode=A_FSUB) or
  1615. (opcode=A_FSUBR) or
  1616. (opcode=A_FADD) or
  1617. (opcode=A_FADDP) or
  1618. (opcode=A_FDIV) or
  1619. (opcode=A_FDIVR)) then
  1620. begin
  1621. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  1622. ops:=2;
  1623. operands[1].opr.typ:=OPR_REGISTER;
  1624. operands[2].opr.typ:=OPR_REGISTER;
  1625. operands[1].opr.reg:=NR_ST0;
  1626. operands[2].opr.reg:=NR_ST1;
  1627. end;
  1628. if (ops=1) and
  1629. (
  1630. (operands[1].opr.typ=OPR_REGISTER) and
  1631. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1632. (operands[1].opr.reg<>NR_ST) and
  1633. (operands[1].opr.reg<>NR_ST0)
  1634. ) and
  1635. (
  1636. (opcode=A_FSUBP) or
  1637. (opcode=A_FSUBRP) or
  1638. (opcode=A_FDIVP) or
  1639. (opcode=A_FDIVRP) or
  1640. (opcode=A_FADDP) or
  1641. (opcode=A_FMULP)
  1642. ) then
  1643. begin
  1644. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  1645. ops:=2;
  1646. operands[2].opr.typ:=OPR_REGISTER;
  1647. operands[2].opr.reg:=operands[1].opr.reg;
  1648. operands[1].opr.reg:=NR_ST0;
  1649. end;
  1650. if (ops=1) and
  1651. (
  1652. (operands[1].opr.typ=OPR_REGISTER) and
  1653. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1654. (operands[1].opr.reg<>NR_ST) and
  1655. (operands[1].opr.reg<>NR_ST0)
  1656. ) and
  1657. (
  1658. (opcode=A_FSUB) or
  1659. (opcode=A_FSUBR) or
  1660. (opcode=A_FDIV) or
  1661. (opcode=A_FDIVR) or
  1662. (opcode=A_FADD) or
  1663. (opcode=A_FMUL)
  1664. ) then
  1665. begin
  1666. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  1667. ops:=2;
  1668. operands[2].opr.typ:=OPR_REGISTER;
  1669. operands[2].opr.reg:=NR_ST0;
  1670. end;
  1671. { Check for 'POP CS' }
  1672. if (opcode=A_POP) and (ops=1) and (operands[1].opr.typ=OPR_REGISTER) and
  1673. (operands[1].opr.reg=NR_CS) then
  1674. {$ifdef i8086}
  1675. { On i8086 we print only a warning, because 'POP CS' works on 8086 and 8088
  1676. CPUs, but isn't supported on any later CPU }
  1677. Message(asmr_w_pop_cs_not_portable);
  1678. {$else i8086}
  1679. { On the i386 and x86_64 targets, we print out an error, because no CPU,
  1680. supported by these targets support 'POP CS' }
  1681. Message(asmr_e_pop_cs_not_valid);
  1682. {$endif i8086}
  1683. { I tried to convince Linus Torvalds to add
  1684. code to support ENTER instruction
  1685. (when raising a stack page fault)
  1686. but he replied that ENTER is a bad instruction and
  1687. Linux does not need to support it
  1688. So I think its at least a good idea to add a warning
  1689. if someone uses this in assembler code
  1690. FPC itself does not use it at all PM }
  1691. if (opcode=A_ENTER) and
  1692. (target_info.system in [system_i386_linux,system_i386_FreeBSD,system_i386_android]) then
  1693. Message(asmr_w_enter_not_supported_by_linux);
  1694. ai:=taicpu.op_none(opcode,siz);
  1695. ai.fileinfo:=filepos;
  1696. ai.SetOperandOrder(op_att);
  1697. ai.Ops:=Ops;
  1698. ai.Allocate_oper(Ops);
  1699. for i:=1 to Ops do
  1700. begin
  1701. ai.oper[i-1]^.vopext := (operands[i] as tx86operand).vopext;
  1702. case operands[i].opr.typ of
  1703. OPR_CONSTANT :
  1704. ai.loadconst(i-1,operands[i].opr.val);
  1705. OPR_REGISTER:
  1706. ai.loadreg(i-1,operands[i].opr.reg);
  1707. OPR_SYMBOL:
  1708. {$ifdef i8086}
  1709. if operands[i].opr.symseg then
  1710. taicpu(ai).loadsegsymbol(i-1,operands[i].opr.symbol)
  1711. else
  1712. {$endif i8086}
  1713. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  1714. OPR_LOCAL :
  1715. with operands[i].opr do
  1716. begin
  1717. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  1718. localscale,localgetoffset,localforceref);
  1719. ai.oper[i-1]^.localoper^.localsegment:=localsegment;
  1720. end;
  1721. OPR_REFERENCE:
  1722. begin
  1723. if current_settings.optimizerswitches <> [] then
  1724. if (not(MemRefInfo(opcode).MemRefSize in MemRefSizeInfoVMems)) and (opcode<>A_XLAT) and not is_x86_string_op(opcode) then
  1725. optimize_ref(operands[i].opr.ref,true);
  1726. ai.loadref(i-1,operands[i].opr.ref);
  1727. if operands[i].size<>OS_NO then
  1728. begin
  1729. asize:=0;
  1730. case operands[i].size of
  1731. OS_8,OS_S8 :
  1732. asize:=OT_BITS8;
  1733. OS_16,OS_S16, OS_M16:
  1734. asize:=OT_BITS16;
  1735. OS_32,OS_S32 :
  1736. {$ifdef i8086}
  1737. if siz=S_FAR then
  1738. asize:=OT_FAR
  1739. else
  1740. asize:=OT_BITS32;
  1741. {$else i8086}
  1742. asize:=OT_BITS32;
  1743. {$endif i8086}
  1744. OS_F32,OS_M32 :
  1745. asize:=OT_BITS32;
  1746. OS_64,OS_S64:
  1747. begin
  1748. { Only FPU operations know about 64bit values, for all
  1749. integer operations it is seen as 32bit
  1750. this applies only to i386, see tw16622}
  1751. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  1752. asize:=OT_BITS64
  1753. else if MemRefInfo(opcode).ExistsSSEAVX then asize:=OT_BITS64
  1754. {$ifdef i386}
  1755. else
  1756. asize:=OT_BITS32
  1757. {$endif i386}
  1758. ;
  1759. end;
  1760. OS_F64,OS_C64, OS_M64 :
  1761. asize:=OT_BITS64;
  1762. OS_F80 :
  1763. asize:=OT_BITS80;
  1764. OS_128,OS_M128,OS_MS128:
  1765. asize := OT_BITS128;
  1766. OS_M256,OS_MS256:
  1767. asize := OT_BITS256;
  1768. OS_M512,OS_MS512:
  1769. asize := OT_BITS512;
  1770. else
  1771. ;
  1772. end;
  1773. if asize<>0 then
  1774. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and OT_NON_SIZE) or asize;
  1775. end;
  1776. end;
  1777. else
  1778. ;
  1779. end;
  1780. end;
  1781. { Condition ? }
  1782. if condition<>C_None then
  1783. ai.SetCondition(condition);
  1784. { Set is_jmp, it enables asmwriter to emit short jumps if appropriate }
  1785. if (opcode=A_JMP) or (opcode=A_JCC) then
  1786. ai.is_jmp := True;
  1787. { Concat the opcode or give an error }
  1788. if assigned(ai) then
  1789. p.concat(ai)
  1790. else
  1791. Message(asmr_e_invalid_opcode_and_operand);
  1792. result:=ai;
  1793. end;
  1794. function Tx86Instruction.getstring: string;
  1795. var
  1796. i : longint;
  1797. s, sval : string;
  1798. regnr: string;
  1799. addsize : boolean;
  1800. begin
  1801. s:='['+std_op2str[opcode];
  1802. for i:=1 to ops do
  1803. begin
  1804. with operands[i] as Tx86Operand do
  1805. begin
  1806. if i=0 then
  1807. s:=s+' '
  1808. else
  1809. s:=s+',';
  1810. { type }
  1811. addsize:=false;
  1812. case operands[i].opr.typ of
  1813. OPR_CONSTANT : begin
  1814. str(operands[i].opr.val, sval);
  1815. s:=s+ sval;
  1816. end;
  1817. OPR_REGISTER : begin
  1818. regnr := '';
  1819. str(getsupreg(opr.reg),regnr);
  1820. if getsubreg(opr.reg)= R_SUBMMX then
  1821. s:=s+'xmmreg' + regnr
  1822. else
  1823. if getsubreg(opr.reg)= R_SUBMMY then
  1824. s:=s+'ymmreg' + regnr
  1825. else
  1826. if getsubreg(opr.reg)= R_SUBMMZ then
  1827. s:=s+'zmmreg' + regnr
  1828. else
  1829. if getregtype(opr.reg)= R_MMXREGISTER then
  1830. s:=s+'mmxreg'
  1831. else
  1832. if getregtype(opr.reg)= R_FPUREGISTER then
  1833. s:=s+'fpureg'
  1834. else
  1835. if getregtype(opr.reg)=R_INTREGISTER then
  1836. begin
  1837. s:=s+'reg';
  1838. addsize:=true;
  1839. end;
  1840. end;
  1841. OPR_LOCAL,
  1842. OPR_REFERENCE: begin
  1843. s:=s + 'mem';
  1844. addsize:=true;
  1845. end;
  1846. else s:=s + '???';
  1847. end;
  1848. if addsize then
  1849. begin
  1850. sval := '';
  1851. str(tcgsize2size[size], sval);
  1852. s := s + sval;
  1853. end;
  1854. if vopext <> 0 then
  1855. begin
  1856. str(vopext and $07, regnr);
  1857. if vopext and OTVE_VECTOR_WRITEMASK = OTVE_VECTOR_WRITEMASK then
  1858. s := s + ' {k' + regnr + '}';
  1859. if vopext and OTVE_VECTOR_ZERO = OTVE_VECTOR_ZERO then
  1860. s := s + ' {z}';
  1861. if vopext and OTVE_VECTOR_SAE = OTVE_VECTOR_SAE then
  1862. s := s + ' {sae}';
  1863. if vopext and OTVE_VECTOR_BCST = OTVE_VECTOR_BCST then
  1864. case vopext and OTVE_VECTOR_BCST_MASK of
  1865. OTVE_VECTOR_BCST2: s := s + ' {1to2}';
  1866. OTVE_VECTOR_BCST4: s := s + ' {1to4}';
  1867. OTVE_VECTOR_BCST8: s := s + ' {1to8}';
  1868. OTVE_VECTOR_BCST16: s := s + ' {1to16}';
  1869. end;
  1870. if vopext and OTVE_VECTOR_ER = OTVE_VECTOR_ER then
  1871. case vopext and OTVE_VECTOR_ER_MASK of
  1872. OTVE_VECTOR_RNSAE: s := s + ' {rn-sae}';
  1873. OTVE_VECTOR_RDSAE: s := s + ' {rd-sae}';
  1874. OTVE_VECTOR_RUSAE: s := s + ' {ru-sae}';
  1875. OTVE_VECTOR_RZSAE: s := s + ' {rz-sae}';
  1876. end;
  1877. end;
  1878. end;
  1879. end;
  1880. GetString:=s+']';
  1881. end;
  1882. function Tx86Instruction.MightHaveExtension: boolean;
  1883. begin
  1884. Result:=aasmcpu.MightHaveExtension(opcode);
  1885. end;
  1886. end.