rax86.pas 72 KB

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