rax86.pas 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032
  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. 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. msiXMem32,
  647. msiYMem32,
  648. msiZMem32,
  649. msiXMem64,
  650. msiYMem64,
  651. msiZMem64: ; // ignore; gather/scatter opcodes haven a fixed element-size, not a fixed memory-size
  652. // the vector-register have indices with base of the memory-address in the memory-operand
  653. msiNoSize,
  654. msiUnkown,
  655. msiUnsupported,
  656. msiVMemMultiple,
  657. msiVMemRegSize,
  658. msiMultiple:
  659. ;
  660. else
  661. Internalerror(2019081005);
  662. end;
  663. if memrefsize > -1 then
  664. begin
  665. // CALC REAL-MEMORY-OPERAND-SIZE AND A POSSIBLE OFFSET
  666. // OFFSET:
  667. // e.g. PAND XMM0, [RAX + 16] =>> OFFSET = 16 BYTES
  668. // PAND XMM0, [RAX + a.b + 10] =>> OFFSET = 10 BYTES (a = record-variable)
  669. memopsize := 0;
  670. case operands[i].opr.typ of
  671. OPR_LOCAL: memopsize := operands[i].opr.localvarsize * 8;
  672. OPR_REFERENCE:
  673. if operands[i].opr.ref.refaddr = addr_pic then
  674. memopsize := sizeof(pint) * 8
  675. else
  676. memopsize := operands[i].opr.varsize * 8;
  677. else
  678. ;
  679. end;
  680. if memopsize = 0 then memopsize := topsize2memsize[tx86operand(operands[i]).opsize];
  681. if (memopsize > 0) and
  682. (memrefsize > 0) then
  683. begin
  684. memoffset := 0;
  685. case operands[i].opr.typ of
  686. OPR_LOCAL:
  687. memoffset := operands[i].opr.localconstoffset;
  688. OPR_REFERENCE:
  689. memoffset := operands[i].opr.constoffset;
  690. else
  691. ;
  692. end;
  693. if memoffset < 0 then
  694. begin
  695. Message2(asmr_w_check_mem_operand_negative_offset,
  696. std_op2str[opcode],
  697. ToStr(memoffset));
  698. end
  699. else if (memopsize < (memrefsize + memoffset * 8)) then
  700. begin
  701. if memoffset = 0 then
  702. begin
  703. Message3(asmr_w_check_mem_operand_size3,
  704. std_op2str[opcode],
  705. ToStr(memopsize),
  706. ToStr(memrefsize)
  707. );
  708. end
  709. else
  710. begin
  711. Message4(asmr_w_check_mem_operand_size_offset,
  712. std_op2str[opcode],
  713. ToStr(memopsize),
  714. ToStr(memrefsize),
  715. ToStr(memoffset)
  716. );
  717. end;
  718. end;
  719. end;
  720. end;
  721. end;
  722. end;
  723. end;
  724. end;
  725. if (ExistsMemRefNoSize or ExistsConstNoSize) and
  726. (MemRefInfo(opcode).ExistsSSEAVX) then
  727. begin
  728. for i := 1 to ops do
  729. begin
  730. if (tx86operand(operands[i]).opsize = S_NO) then
  731. begin
  732. case operands[i].Opr.Typ of
  733. OPR_REFERENCE:
  734. begin
  735. if ExistsBCST then
  736. begin
  737. case MemRefInfo(opcode).MemRefSizeBCST of
  738. msbBCST32: begin
  739. tx86operand(operands[i]).opsize := S_L;
  740. tx86operand(operands[i]).size := OS_32;
  741. end;
  742. msbBCST64: begin
  743. tx86operand(operands[i]).opsize := S_Q;
  744. tx86operand(operands[i]).size := OS_M64;
  745. end;
  746. else
  747. Internalerror(2019081006);
  748. end;
  749. end
  750. else
  751. case MemRefInfo(opcode).MemRefSize of
  752. msiMem8:
  753. begin
  754. tx86operand(operands[i]).opsize := S_B;
  755. tx86operand(operands[i]).size := OS_8;
  756. end;
  757. msiMultiple8:
  758. begin
  759. tx86operand(operands[i]).opsize := S_B;
  760. tx86operand(operands[i]).size := OS_8;
  761. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"8 bit memory operand"');
  762. end;
  763. msiMem16:
  764. begin
  765. tx86operand(operands[i]).opsize := S_W;
  766. tx86operand(operands[i]).size := OS_16;
  767. end;
  768. msiMultiple16:
  769. begin
  770. tx86operand(operands[i]).opsize := S_W;
  771. tx86operand(operands[i]).size := OS_16;
  772. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"16 bit memory operand"');
  773. end;
  774. msiMem32:
  775. begin
  776. tx86operand(operands[i]).opsize := S_L;
  777. tx86operand(operands[i]).size := OS_32;
  778. end;
  779. msiMultiple32:
  780. begin
  781. tx86operand(operands[i]).opsize := S_L;
  782. tx86operand(operands[i]).size := OS_32;
  783. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"32 bit memory operand"');
  784. end;
  785. msiMem64:
  786. begin
  787. tx86operand(operands[i]).opsize := S_Q;
  788. tx86operand(operands[i]).size := OS_M64;
  789. end;
  790. msiMultiple64:
  791. begin
  792. tx86operand(operands[i]).opsize := S_Q;
  793. tx86operand(operands[i]).size := OS_M64;
  794. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"64 bit memory operand"');
  795. end;
  796. msiMem128:
  797. begin
  798. tx86operand(operands[i]).opsize := S_XMM;
  799. tx86operand(operands[i]).size := OS_M128;
  800. end;
  801. msiMultiple128:
  802. begin
  803. tx86operand(operands[i]).opsize := S_XMM;
  804. tx86operand(operands[i]).size := OS_M128;
  805. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"128 bit memory operand"');
  806. end;
  807. msiMem256:
  808. begin
  809. tx86operand(operands[i]).opsize := S_YMM;
  810. tx86operand(operands[i]).size := OS_M256;
  811. opsize := S_YMM;
  812. end;
  813. msiMultiple256:
  814. begin
  815. tx86operand(operands[i]).opsize := S_YMM;
  816. tx86operand(operands[i]).size := OS_M256;
  817. opsize := S_YMM;
  818. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"256 bit memory operand"');
  819. end;
  820. msiMem512:
  821. begin
  822. tx86operand(operands[i]).opsize := S_ZMM;
  823. tx86operand(operands[i]).size := OS_M512;
  824. opsize := S_ZMM;
  825. end;
  826. msiMultiple512:
  827. begin
  828. tx86operand(operands[i]).opsize := S_ZMM;
  829. tx86operand(operands[i]).size := OS_M512;
  830. opsize := S_ZMM;
  831. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"512 bit memory operand"');
  832. end;
  833. msiMemRegSize:
  834. begin
  835. // mem-ref-size = register size
  836. for j := 1 to ops do
  837. begin
  838. if operands[j].Opr.Typ = OPR_REGISTER then
  839. begin
  840. if (tx86operand(operands[j]).opsize <> S_NO) and
  841. (tx86operand(operands[j]).size <> OS_NO) then
  842. begin
  843. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  844. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  845. break;
  846. end
  847. else Message(asmr_e_unable_to_determine_reference_size);
  848. end;
  849. end;
  850. end;
  851. msiMemRegx16y32:
  852. begin
  853. for j := 1 to ops do
  854. begin
  855. if operands[j].Opr.Typ = OPR_REGISTER then
  856. begin
  857. case getsubreg(operands[j].opr.reg) of
  858. R_SUBMMX: begin
  859. tx86operand(operands[i]).opsize := S_W;
  860. tx86operand(operands[i]).size := OS_M16;
  861. break;
  862. end;
  863. R_SUBMMY: begin
  864. tx86operand(operands[i]).opsize := S_L;
  865. tx86operand(operands[i]).size := OS_M32;
  866. break;
  867. end;
  868. else Message(asmr_e_unable_to_determine_reference_size);
  869. end;
  870. end;
  871. end;
  872. end;
  873. msiMemRegx16y32z64:
  874. begin
  875. for j := 1 to ops do
  876. begin
  877. if operands[j].Opr.Typ = OPR_REGISTER then
  878. begin
  879. case getsubreg(operands[j].opr.reg) of
  880. R_SUBMMX: begin
  881. tx86operand(operands[i]).opsize := S_W;
  882. tx86operand(operands[i]).size := OS_M16;
  883. break;
  884. end;
  885. R_SUBMMY: begin
  886. tx86operand(operands[i]).opsize := S_L;
  887. tx86operand(operands[i]).size := OS_M32;
  888. break;
  889. end;
  890. R_SUBMMZ: begin
  891. tx86operand(operands[i]).opsize := S_Q;
  892. tx86operand(operands[i]).size := OS_M64;
  893. break;
  894. end;
  895. else Message(asmr_e_unable_to_determine_reference_size);
  896. end;
  897. end;
  898. end;
  899. end;
  900. msiMemRegx32y64:
  901. begin
  902. for j := 1 to ops do
  903. begin
  904. if operands[j].Opr.Typ = OPR_REGISTER then
  905. begin
  906. case getsubreg(operands[j].opr.reg) of
  907. R_SUBMMX: begin
  908. tx86operand(operands[i]).opsize := S_L;
  909. tx86operand(operands[i]).size := OS_M32;
  910. break;
  911. end;
  912. R_SUBMMY: begin
  913. tx86operand(operands[i]).opsize := S_Q;
  914. tx86operand(operands[i]).size := OS_M64;
  915. break;
  916. end;
  917. else Message(asmr_e_unable_to_determine_reference_size);
  918. end;
  919. end;
  920. end;
  921. end;
  922. msiMemRegx32y64z128:
  923. for j := 1 to ops do
  924. begin
  925. if operands[j].Opr.Typ = OPR_REGISTER then
  926. begin
  927. case getsubreg(operands[j].opr.reg) of
  928. R_SUBMMX: begin
  929. tx86operand(operands[i]).opsize := S_L;
  930. tx86operand(operands[i]).size := OS_M32;
  931. break;
  932. end;
  933. R_SUBMMY: begin
  934. tx86operand(operands[i]).opsize := S_Q;
  935. tx86operand(operands[i]).size := OS_M64;
  936. break;
  937. end;
  938. R_SUBMMZ: begin
  939. tx86operand(operands[i]).opsize := S_XMM;
  940. tx86operand(operands[i]).size := OS_M128;
  941. break;
  942. end;
  943. else Message(asmr_e_unable_to_determine_reference_size);
  944. end;
  945. end;
  946. end;
  947. msiMemRegx64y128:
  948. begin
  949. for j := 1 to ops do
  950. begin
  951. if operands[j].Opr.Typ = OPR_REGISTER then
  952. begin
  953. case getsubreg(operands[j].opr.reg) of
  954. R_SUBMMX: begin
  955. tx86operand(operands[i]).opsize := S_Q;
  956. tx86operand(operands[i]).size := OS_M64;
  957. break;
  958. end;
  959. R_SUBMMY: begin
  960. tx86operand(operands[i]).opsize := S_XMM;
  961. tx86operand(operands[i]).size := OS_M128;
  962. break;
  963. end;
  964. else Message(asmr_e_unable_to_determine_reference_size);
  965. end;
  966. end;
  967. end;
  968. end;
  969. msiMemRegx64y128z256:
  970. begin
  971. for j := 1 to ops do
  972. begin
  973. if operands[j].Opr.Typ = OPR_REGISTER then
  974. begin
  975. case getsubreg(operands[j].opr.reg) of
  976. R_SUBMMX: begin
  977. tx86operand(operands[i]).opsize := S_Q;
  978. tx86operand(operands[i]).size := OS_M64;
  979. break;
  980. end;
  981. R_SUBMMY: begin
  982. tx86operand(operands[i]).opsize := S_XMM;
  983. tx86operand(operands[i]).size := OS_M128;
  984. break;
  985. end;
  986. R_SUBMMZ: begin
  987. tx86operand(operands[i]).opsize := S_YMM;
  988. tx86operand(operands[i]).size := OS_M256;
  989. break;
  990. end;
  991. else Message(asmr_e_unable_to_determine_reference_size);
  992. end;
  993. end;
  994. end;
  995. end;
  996. msiMemRegx64y256:
  997. begin
  998. for j := 1 to ops do
  999. begin
  1000. if operands[j].Opr.Typ = OPR_REGISTER then
  1001. begin
  1002. case getsubreg(operands[j].opr.reg) of
  1003. R_SUBMMX: begin
  1004. tx86operand(operands[i]).opsize := S_Q;
  1005. tx86operand(operands[i]).size := OS_M64;
  1006. break;
  1007. end;
  1008. R_SUBMMY: begin
  1009. tx86operand(operands[i]).opsize := S_YMM;
  1010. tx86operand(operands[i]).size := OS_M256;
  1011. break;
  1012. end;
  1013. else Message(asmr_e_unable_to_determine_reference_size);
  1014. end;
  1015. end;
  1016. end;
  1017. end;
  1018. msiMemRegx64y256z512:
  1019. begin
  1020. for j := 1 to ops do
  1021. begin
  1022. if operands[j].Opr.Typ = OPR_REGISTER then
  1023. begin
  1024. case getsubreg(operands[j].opr.reg) of
  1025. R_SUBMMX: begin
  1026. tx86operand(operands[i]).opsize := S_Q;
  1027. tx86operand(operands[i]).size := OS_M64;
  1028. break;
  1029. end;
  1030. R_SUBMMY: begin
  1031. tx86operand(operands[i]).opsize := S_YMM;
  1032. tx86operand(operands[i]).size := OS_M256;
  1033. break;
  1034. end;
  1035. R_SUBMMZ: begin
  1036. tx86operand(operands[i]).opsize := S_ZMM;
  1037. tx86operand(operands[i]).size := OS_M512;
  1038. break;
  1039. end;
  1040. else Message(asmr_e_unable_to_determine_reference_size);
  1041. end;
  1042. end;
  1043. end;
  1044. end;
  1045. msiMemRegConst128,
  1046. msiMemRegConst256,
  1047. msiMemRegConst512:
  1048. begin
  1049. ExistConst := false;
  1050. for j := 1 to ops do
  1051. begin
  1052. if operands[j].Opr.Typ = OPR_CONSTANT then
  1053. begin
  1054. ExistConst := true;
  1055. break;
  1056. end;
  1057. end;
  1058. if ExistConst then
  1059. begin
  1060. for j := 1 to ops do
  1061. begin
  1062. if operands[j].Opr.Typ = OPR_REGISTER then
  1063. begin
  1064. if (tx86operand(operands[j]).opsize <> S_NO) and
  1065. (tx86operand(operands[j]).size <> OS_NO) then
  1066. begin
  1067. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  1068. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  1069. break;
  1070. end
  1071. else Message(asmr_e_unable_to_determine_reference_size);
  1072. end;
  1073. end;
  1074. end
  1075. else
  1076. begin
  1077. case MemRefInfo(opcode).MemRefSize of
  1078. msiMemRegConst128: begin
  1079. tx86operand(operands[i]).opsize := S_XMM;
  1080. tx86operand(operands[i]).size := OS_M128;
  1081. break;
  1082. end;
  1083. msiMemRegConst256: begin
  1084. tx86operand(operands[i]).opsize := S_YMM;
  1085. tx86operand(operands[i]).size := OS_M256;
  1086. break;
  1087. end;
  1088. msiMemRegConst512: begin
  1089. tx86operand(operands[i]).opsize := S_ZMM;
  1090. tx86operand(operands[i]).size := OS_M512;
  1091. break;
  1092. end;
  1093. else
  1094. Internalerror(2019081007);
  1095. end;
  1096. end;
  1097. end;
  1098. msiXMem32,
  1099. msiYMem32,
  1100. msiZMem32,
  1101. msiXMem64,
  1102. msiYMem64,
  1103. msiZMem64: ; // ignore; gather/scatter opcodes haven a fixed element-size, not a fixed memory-size
  1104. // the vector-register have indices with base of the memory-address in the memory-operand
  1105. msiNoSize: ; // all memory-sizes are ok
  1106. msiVMemMultiple,
  1107. msiVMemRegSize: ; // ignore
  1108. msiUnkown,
  1109. msiUnsupported,
  1110. msiMultiple: Message(asmr_e_unable_to_determine_reference_size); // TODO individual message
  1111. else
  1112. Internalerror(2019081008);
  1113. end;
  1114. end;
  1115. OPR_CONSTANT:
  1116. case MemRefInfo(opcode).ConstSize of
  1117. csiMem8: begin
  1118. tx86operand(operands[i]).opsize := S_B;
  1119. tx86operand(operands[i]).size := OS_8;
  1120. end;
  1121. csiMem16: begin
  1122. tx86operand(operands[i]).opsize := S_W;
  1123. tx86operand(operands[i]).size := OS_16;
  1124. end;
  1125. csiMem32: begin
  1126. tx86operand(operands[i]).opsize := S_L;
  1127. tx86operand(operands[i]).size := OS_32;
  1128. end;
  1129. {$ifdef x86_64}
  1130. csiMem64: begin
  1131. tx86operand(operands[i]).opsize := S_Q;
  1132. tx86operand(operands[i]).size := OS_64;
  1133. end;
  1134. {$else}
  1135. csiMem64: begin
  1136. internalerror(2019050910);
  1137. end;
  1138. {$endif}
  1139. csiUnkown, csiMultiple, csiNoSize:
  1140. ;
  1141. end;
  1142. else
  1143. ;
  1144. end;
  1145. end;
  1146. end;
  1147. end;
  1148. for i:=1 to ops do
  1149. begin
  1150. operands[i].SetCorrectSize(opcode);
  1151. if tx86operand(operands[i]).opsize=S_NO then
  1152. begin
  1153. {$ifdef x86_64}
  1154. if (opcode=A_MOVQ) and
  1155. (ops=2) and
  1156. (operands[1].opr.typ=OPR_CONSTANT) then
  1157. opsize:=S_Q
  1158. else
  1159. {$endif x86_64}
  1160. case operands[i].Opr.Typ of
  1161. OPR_LOCAL,
  1162. OPR_REFERENCE :
  1163. begin
  1164. { for 3-operand opcodes, operand #1 (in ATT order) is always an immediate,
  1165. don't consider it. }
  1166. if i=ops then
  1167. operand2:=i-1
  1168. else
  1169. operand2:=i+1;
  1170. if operand2>0 then
  1171. begin
  1172. { Only allow register as operand to take the size from }
  1173. if operands[operand2].opr.typ=OPR_REGISTER then
  1174. begin
  1175. if ((opcode<>A_MOVD) and
  1176. (opcode<>A_CVTSI2SS)) then
  1177. begin
  1178. //tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  1179. // torsten - 31.01.2012
  1180. // old: xmm/ymm-register operands have a opsize = "S_NO"
  1181. // new: xmm/ymm-register operands have a opsize = "S_XMM/S_YMM"
  1182. // any SSE- and AVX-opcodes have mixed operand sizes (e.g. cvtsd2ss xmmreg, xmmreg/m32)
  1183. // in this case is we need the old handling ("S_NO")
  1184. // =>> ignore
  1185. if (tx86operand(operands[operand2]).opsize <> S_XMM) and
  1186. (tx86operand(operands[operand2]).opsize <> S_YMM) and
  1187. (tx86operand(operands[operand2]).opsize <> S_ZMM) then
  1188. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize
  1189. else tx86operand(operands[operand2]).opsize := S_NO;
  1190. end;
  1191. end
  1192. else
  1193. begin
  1194. { if no register then take the opsize (which is available with ATT),
  1195. if not availble then give an error }
  1196. if opsize<>S_NO then
  1197. tx86operand(operands[i]).opsize:=opsize
  1198. else
  1199. begin
  1200. if (m_delphi in current_settings.modeswitches) then
  1201. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  1202. else
  1203. Message(asmr_e_unable_to_determine_reference_size);
  1204. { recovery }
  1205. tx86operand(operands[i]).opsize:=S_L;
  1206. end;
  1207. end;
  1208. end
  1209. else
  1210. begin
  1211. if opsize<>S_NO then
  1212. tx86operand(operands[i]).opsize:=opsize
  1213. end;
  1214. end;
  1215. OPR_SYMBOL :
  1216. begin
  1217. { Fix lea which need a reference }
  1218. if opcode=A_LEA then
  1219. begin
  1220. s:=operands[i].opr.symbol;
  1221. so:=operands[i].opr.symofs;
  1222. operands[i].opr.typ:=OPR_REFERENCE;
  1223. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  1224. operands[i].opr.ref.symbol:=s;
  1225. operands[i].opr.ref.offset:=so;
  1226. end;
  1227. {$if defined(x86_64)}
  1228. tx86operand(operands[i]).opsize:=S_Q;
  1229. {$elseif defined(i386)}
  1230. tx86operand(operands[i]).opsize:=S_L;
  1231. {$elseif defined(i8086)}
  1232. tx86operand(operands[i]).opsize:=S_W;
  1233. {$endif}
  1234. end;
  1235. else
  1236. ;
  1237. end;
  1238. end;
  1239. end;
  1240. if MemRefInfo(opcode).ExistsSSEAVX then
  1241. begin
  1242. // validate broadcast-memory-operands
  1243. vbcst := 0;
  1244. mmregs := [];
  1245. for i := 1 to ops do
  1246. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then vbcst := tx86operand(operands[i]).vbcst
  1247. else if operands[i].Opr.Typ = OPR_REGISTER then
  1248. begin
  1249. if getsubreg(operands[i].opr.reg) in [R_SUBMMX, R_SUBMMY, R_SUBMMZ] then
  1250. begin
  1251. include(mmregs, getsubreg(operands[i].opr.reg));
  1252. end;
  1253. end;
  1254. if vbcst <> 0 then
  1255. begin
  1256. // found broadcast-memory-operand (e.g. "{1to8}")
  1257. // check is correct
  1258. multiplicator := 0;
  1259. if mmregs = [R_SUBMMX] then multiplicator := 1
  1260. else if mmregs = [R_SUBMMY] then multiplicator := 2
  1261. else if mmregs = [R_SUBMMZ] then multiplicator := 4
  1262. else
  1263. begin
  1264. //TG TODO
  1265. end;
  1266. if MemRefInfo(opcode).BCSTTypes <> [] then
  1267. begin
  1268. str(MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator, bcst1);
  1269. str(vbcst, bcst2);
  1270. case vbcst of
  1271. 2: if not(bt1to2 in MemRefInfo(opcode).BCSTTypes) then
  1272. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1273. 4: if not(bt1to4 in MemRefInfo(opcode).BCSTTypes) then
  1274. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1275. 8: if not(bt1to8 in MemRefInfo(opcode).BCSTTypes) then
  1276. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1277. 16: if not(bt1to16 in MemRefInfo(opcode).BCSTTypes) then
  1278. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1279. end;
  1280. end
  1281. else if MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator <> vbcst then
  1282. begin
  1283. str(MemRefInfo(opcode).BCSTXMMMultiplicator * multiplicator, bcst1);
  1284. str(vbcst, bcst2);
  1285. Message2(asmr_e_mismatch_broadcasting_elements, '1to' + bcst1, '1to' + bcst2);
  1286. end;
  1287. end;
  1288. end;
  1289. end;
  1290. procedure Tx86Instruction.SetInstructionOpsize;
  1291. begin
  1292. if opsize<>S_NO then
  1293. exit;
  1294. case ops of
  1295. 0 : ;
  1296. 1 :
  1297. begin
  1298. { "push es" must be stored as a long PM }
  1299. if ((opcode=A_PUSH) or
  1300. (opcode=A_POP)) and
  1301. (operands[1].opr.typ=OPR_REGISTER) and
  1302. is_segment_reg(operands[1].opr.reg) then
  1303. {$ifdef i8086}
  1304. opsize:=S_W
  1305. {$else i8086}
  1306. opsize:=S_L
  1307. {$endif i8086}
  1308. else
  1309. opsize:=tx86operand(operands[1]).opsize;
  1310. end;
  1311. 2 :
  1312. begin
  1313. case opcode of
  1314. A_MOVZX,A_MOVSX :
  1315. begin
  1316. if tx86operand(operands[1]).opsize=S_NO then
  1317. begin
  1318. tx86operand(operands[1]).opsize:=S_B;
  1319. if (m_delphi in current_settings.modeswitches) then
  1320. Message(asmr_w_unable_to_determine_reference_size_using_byte)
  1321. else
  1322. Message(asmr_e_unable_to_determine_reference_size);
  1323. end;
  1324. case tx86operand(operands[1]).opsize of
  1325. S_W :
  1326. case tx86operand(operands[2]).opsize of
  1327. S_L :
  1328. opsize:=S_WL;
  1329. {$ifdef x86_64}
  1330. S_Q :
  1331. opsize:=S_WQ;
  1332. {$endif}
  1333. else
  1334. ;
  1335. end;
  1336. S_B :
  1337. begin
  1338. case tx86operand(operands[2]).opsize of
  1339. S_W :
  1340. opsize:=S_BW;
  1341. S_L :
  1342. opsize:=S_BL;
  1343. {$ifdef x86_64}
  1344. S_Q :
  1345. opsize:=S_BQ;
  1346. {$endif}
  1347. else
  1348. ;
  1349. end;
  1350. end;
  1351. else
  1352. ;
  1353. end;
  1354. end;
  1355. A_MOVSS,
  1356. A_VMOVSS,
  1357. A_MOVD : { movd is a move from a mmx register to a
  1358. 32 bit register or memory, so no opsize is correct here PM }
  1359. exit;
  1360. A_MOVQ :
  1361. opsize:=S_IQ;
  1362. A_CVTSI2SS,
  1363. A_CVTSI2SD,
  1364. A_OUT :
  1365. opsize:=tx86operand(operands[1]).opsize;
  1366. else
  1367. opsize:=tx86operand(operands[2]).opsize;
  1368. end;
  1369. end;
  1370. 3 :
  1371. begin
  1372. case opcode of
  1373. A_VCVTSI2SS,
  1374. A_VCVTSI2SD:
  1375. opsize:=tx86operand(operands[1]).opsize;
  1376. else
  1377. opsize:=tx86operand(operands[ops]).opsize;
  1378. end;
  1379. end;
  1380. 4 :
  1381. opsize:=tx86operand(operands[ops]).opsize;
  1382. end;
  1383. end;
  1384. procedure Tx86Instruction.CheckOperandSizes;
  1385. var
  1386. sizeerr : boolean;
  1387. i : longint;
  1388. begin
  1389. { Check only the most common opcodes here, the others are done in
  1390. the assembler pass }
  1391. case opcode of
  1392. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  1393. A_CMP,A_MOV,
  1394. A_ADD,A_SUB,A_ADC,A_SBB,
  1395. A_AND,A_OR,A_TEST,A_XOR: ;
  1396. else
  1397. exit;
  1398. end;
  1399. { Handle the BW,BL,WL separatly }
  1400. sizeerr:=false;
  1401. { special push/pop selector case }
  1402. if ((opcode=A_PUSH) or
  1403. (opcode=A_POP)) and
  1404. (operands[1].opr.typ=OPR_REGISTER) and
  1405. is_segment_reg(operands[1].opr.reg) then
  1406. exit;
  1407. if opsize in [S_BW,S_BL,S_WL] then
  1408. begin
  1409. if ops<>2 then
  1410. sizeerr:=true
  1411. else
  1412. begin
  1413. case opsize of
  1414. S_BW :
  1415. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  1416. S_BL :
  1417. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  1418. S_WL :
  1419. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  1420. {$ifdef x86_64}
  1421. S_BQ:
  1422. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_Q);
  1423. S_WQ:
  1424. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_Q);
  1425. S_LQ:
  1426. sizeerr:=(tx86operand(operands[1]).opsize<>S_L) or (tx86operand(operands[2]).opsize<>S_Q);
  1427. {$endif}
  1428. else
  1429. ;
  1430. end;
  1431. end;
  1432. end
  1433. else
  1434. begin
  1435. for i:=1 to ops do
  1436. begin
  1437. if (operands[i].opr.typ<>OPR_CONSTANT) and
  1438. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  1439. (tx86operand(operands[i]).opsize<>opsize) then
  1440. sizeerr:=true;
  1441. end;
  1442. end;
  1443. if sizeerr then
  1444. begin
  1445. { if range checks are on then generate an error }
  1446. if (cs_compilesystem in current_settings.moduleswitches) or
  1447. not (cs_check_range in current_settings.localswitches) then
  1448. Message(asmr_w_size_suffix_and_dest_dont_match)
  1449. else
  1450. Message(asmr_e_size_suffix_and_dest_dont_match);
  1451. end;
  1452. end;
  1453. { This check must be done with the operand in ATT order
  1454. i.e.after swapping in the intel reader
  1455. but before swapping in the NASM and TASM writers PM }
  1456. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  1457. begin
  1458. if (
  1459. (ops=2) and
  1460. (operands[1].opr.typ=OPR_REGISTER) and
  1461. (operands[2].opr.typ=OPR_REGISTER) and
  1462. { if the first is ST and the second is also a register
  1463. it is necessarily ST1 .. ST7 }
  1464. ((operands[1].opr.reg=NR_ST) or
  1465. (operands[1].opr.reg=NR_ST0))
  1466. ) or
  1467. (ops=0) then
  1468. if opcode=A_FSUBR then
  1469. opcode:=A_FSUB
  1470. else if opcode=A_FSUB then
  1471. opcode:=A_FSUBR
  1472. else if opcode=A_FDIVR then
  1473. opcode:=A_FDIV
  1474. else if opcode=A_FDIV then
  1475. opcode:=A_FDIVR
  1476. else if opcode=A_FSUBRP then
  1477. opcode:=A_FSUBP
  1478. else if opcode=A_FSUBP then
  1479. opcode:=A_FSUBRP
  1480. else if opcode=A_FDIVRP then
  1481. opcode:=A_FDIVP
  1482. else if opcode=A_FDIVP then
  1483. opcode:=A_FDIVRP;
  1484. if (
  1485. (ops=1) and
  1486. (operands[1].opr.typ=OPR_REGISTER) and
  1487. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1488. (operands[1].opr.reg<>NR_ST) and
  1489. (operands[1].opr.reg<>NR_ST0)
  1490. ) then
  1491. if opcode=A_FSUBRP then
  1492. opcode:=A_FSUBP
  1493. else if opcode=A_FSUBP then
  1494. opcode:=A_FSUBRP
  1495. else if opcode=A_FDIVRP then
  1496. opcode:=A_FDIVP
  1497. else if opcode=A_FDIVP then
  1498. opcode:=A_FDIVRP;
  1499. end;
  1500. procedure Tx86Instruction.FixupOpcode;
  1501. begin
  1502. { does nothing by default }
  1503. end;
  1504. {*****************************************************************************
  1505. opcode Adding
  1506. *****************************************************************************}
  1507. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  1508. var
  1509. siz : topsize;
  1510. i : longint;
  1511. asize : int64;
  1512. ai : taicpu;
  1513. begin
  1514. ConcatInstruction:=nil;
  1515. ai:=nil;
  1516. for i:=1 to Ops do
  1517. if not operands[i].CheckOperand then
  1518. exit;
  1519. { Get Opsize }
  1520. if (opsize<>S_NO) or (Ops=0) then
  1521. siz:=opsize
  1522. else
  1523. begin
  1524. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  1525. siz:=tx86operand(operands[1]).opsize
  1526. else
  1527. siz:=tx86operand(operands[Ops]).opsize;
  1528. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  1529. if (ops=2) and
  1530. (tx86operand(operands[1]).opsize<>S_NO) and
  1531. (tx86operand(operands[2]).opsize<>S_NO) and
  1532. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  1533. siz:=S_NO;
  1534. end;
  1535. if ((opcode=A_MOVD)or
  1536. (opcode=A_CVTSI2SS)) and
  1537. ((tx86operand(operands[1]).opsize=S_NO) or
  1538. (tx86operand(operands[2]).opsize=S_NO)) then
  1539. siz:=S_NO;
  1540. { NASM does not support FADD without args
  1541. as alias of FADDP
  1542. and GNU AS interprets FADD without operand differently
  1543. for version 2.9.1 and 2.9.5 !! }
  1544. if (ops=0) and
  1545. ((opcode=A_FADD) or
  1546. (opcode=A_FMUL) or
  1547. (opcode=A_FSUB) or
  1548. (opcode=A_FSUBR) or
  1549. (opcode=A_FDIV) or
  1550. (opcode=A_FDIVR)) then
  1551. begin
  1552. if opcode=A_FADD then
  1553. opcode:=A_FADDP
  1554. else if opcode=A_FMUL then
  1555. opcode:=A_FMULP
  1556. else if opcode=A_FSUB then
  1557. opcode:=A_FSUBP
  1558. else if opcode=A_FSUBR then
  1559. opcode:=A_FSUBRP
  1560. else if opcode=A_FDIV then
  1561. opcode:=A_FDIVP
  1562. else if opcode=A_FDIVR then
  1563. opcode:=A_FDIVRP;
  1564. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  1565. end;
  1566. {It is valid to specify some instructions without operand size.}
  1567. if siz=S_NO then
  1568. begin
  1569. if (ops=1) and (opcode=A_INT) then
  1570. siz:=S_B;
  1571. if (ops=1) and (opcode=A_XABORT) then
  1572. siz:=S_B;
  1573. {$ifdef i8086}
  1574. if (ops=1) and (opcode=A_BRKEM) then
  1575. siz:=S_B;
  1576. {$endif i8086}
  1577. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) or
  1578. (opcode=A_RETW) or (opcode=A_RETNW) or (opcode=A_RETFW) or
  1579. {$ifndef x86_64}
  1580. (opcode=A_RETD) or (opcode=A_RETND) or
  1581. {$endif x86_64}
  1582. (opcode=A_RETFD)
  1583. {$ifdef x86_64}
  1584. or (opcode=A_RETQ) or (opcode=A_RETNQ) or (opcode=A_RETFQ)
  1585. {$endif x86_64}
  1586. then
  1587. siz:=S_W;
  1588. if (ops=1) and (opcode=A_PUSH) then
  1589. begin
  1590. {$ifdef i8086}
  1591. if (tx86operand(operands[1]).opr.val>=-128) and (tx86operand(operands[1]).opr.val<=127) then
  1592. begin
  1593. siz:=S_B;
  1594. message(asmr_w_unable_to_determine_constant_size_using_byte);
  1595. end
  1596. else
  1597. begin
  1598. siz:=S_W;
  1599. message(asmr_w_unable_to_determine_constant_size_using_word);
  1600. end;
  1601. {$else i8086}
  1602. { We are a 32 compiler, assume 32-bit by default. This is Delphi
  1603. compatible but bad coding practise.}
  1604. siz:=S_L;
  1605. message(asmr_w_unable_to_determine_reference_size_using_dword);
  1606. {$endif i8086}
  1607. end;
  1608. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  1609. if ops=1 then
  1610. siz:=S_NEAR
  1611. else
  1612. siz:=S_FAR;
  1613. end;
  1614. { GNU AS interprets FDIV without operand differently
  1615. for version 2.9.1 and 2.10
  1616. we add explicit args to it !! }
  1617. if (ops=0) and
  1618. ((opcode=A_FSUBP) or
  1619. (opcode=A_FSUBRP) or
  1620. (opcode=A_FDIVP) or
  1621. (opcode=A_FDIVRP) or
  1622. (opcode=A_FSUB) or
  1623. (opcode=A_FSUBR) or
  1624. (opcode=A_FADD) or
  1625. (opcode=A_FADDP) or
  1626. (opcode=A_FDIV) or
  1627. (opcode=A_FDIVR)) then
  1628. begin
  1629. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  1630. ops:=2;
  1631. operands[1].opr.typ:=OPR_REGISTER;
  1632. operands[2].opr.typ:=OPR_REGISTER;
  1633. operands[1].opr.reg:=NR_ST0;
  1634. operands[2].opr.reg:=NR_ST1;
  1635. end;
  1636. if (ops=1) and
  1637. (
  1638. (operands[1].opr.typ=OPR_REGISTER) and
  1639. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1640. (operands[1].opr.reg<>NR_ST) and
  1641. (operands[1].opr.reg<>NR_ST0)
  1642. ) and
  1643. (
  1644. (opcode=A_FSUBP) or
  1645. (opcode=A_FSUBRP) or
  1646. (opcode=A_FDIVP) or
  1647. (opcode=A_FDIVRP) or
  1648. (opcode=A_FADDP) or
  1649. (opcode=A_FMULP)
  1650. ) then
  1651. begin
  1652. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  1653. ops:=2;
  1654. operands[2].opr.typ:=OPR_REGISTER;
  1655. operands[2].opr.reg:=operands[1].opr.reg;
  1656. operands[1].opr.reg:=NR_ST0;
  1657. end;
  1658. if (ops=1) and
  1659. (
  1660. (operands[1].opr.typ=OPR_REGISTER) and
  1661. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1662. (operands[1].opr.reg<>NR_ST) and
  1663. (operands[1].opr.reg<>NR_ST0)
  1664. ) and
  1665. (
  1666. (opcode=A_FSUB) or
  1667. (opcode=A_FSUBR) or
  1668. (opcode=A_FDIV) or
  1669. (opcode=A_FDIVR) or
  1670. (opcode=A_FADD) or
  1671. (opcode=A_FMUL)
  1672. ) then
  1673. begin
  1674. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  1675. ops:=2;
  1676. operands[2].opr.typ:=OPR_REGISTER;
  1677. operands[2].opr.reg:=NR_ST0;
  1678. end;
  1679. { Check for 'POP CS' }
  1680. if (opcode=A_POP) and (ops=1) and (operands[1].opr.typ=OPR_REGISTER) and
  1681. (operands[1].opr.reg=NR_CS) then
  1682. {$ifdef i8086}
  1683. { On i8086 we print only a warning, because 'POP CS' works on 8086 and 8088
  1684. CPUs, but isn't supported on any later CPU }
  1685. Message(asmr_w_pop_cs_not_portable);
  1686. {$else i8086}
  1687. { On the i386 and x86_64 targets, we print out an error, because no CPU,
  1688. supported by these targets support 'POP CS' }
  1689. Message(asmr_e_pop_cs_not_valid);
  1690. {$endif i8086}
  1691. { I tried to convince Linus Torvalds to add
  1692. code to support ENTER instruction
  1693. (when raising a stack page fault)
  1694. but he replied that ENTER is a bad instruction and
  1695. Linux does not need to support it
  1696. So I think its at least a good idea to add a warning
  1697. if someone uses this in assembler code
  1698. FPC itself does not use it at all PM }
  1699. if (opcode=A_ENTER) and
  1700. (target_info.system in [system_i386_linux,system_i386_FreeBSD,system_i386_android]) then
  1701. Message(asmr_w_enter_not_supported_by_linux);
  1702. ai:=taicpu.op_none(opcode,siz);
  1703. ai.fileinfo:=filepos;
  1704. ai.SetOperandOrder(op_att);
  1705. ai.Ops:=Ops;
  1706. ai.Allocate_oper(Ops);
  1707. for i:=1 to Ops do
  1708. begin
  1709. ai.oper[i-1]^.vopext := (operands[i] as tx86operand).vopext;
  1710. case operands[i].opr.typ of
  1711. OPR_CONSTANT :
  1712. ai.loadconst(i-1,operands[i].opr.val);
  1713. OPR_REGISTER:
  1714. ai.loadreg(i-1,operands[i].opr.reg);
  1715. OPR_SYMBOL:
  1716. {$ifdef i8086}
  1717. if operands[i].opr.symseg then
  1718. taicpu(ai).loadsegsymbol(i-1,operands[i].opr.symbol)
  1719. else
  1720. {$endif i8086}
  1721. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  1722. OPR_LOCAL :
  1723. with operands[i].opr do
  1724. begin
  1725. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  1726. localscale,localgetoffset,localforceref);
  1727. ai.oper[i-1]^.localoper^.localsegment:=localsegment;
  1728. end;
  1729. OPR_REFERENCE:
  1730. begin
  1731. if current_settings.optimizerswitches <> [] then
  1732. if (not(MemRefInfo(opcode).MemRefSize in MemRefSizeInfoVMems)) and (opcode<>A_XLAT) and not is_x86_string_op(opcode) then
  1733. optimize_ref(operands[i].opr.ref,true);
  1734. ai.loadref(i-1,operands[i].opr.ref);
  1735. if operands[i].size<>OS_NO then
  1736. begin
  1737. asize:=0;
  1738. case operands[i].size of
  1739. OS_8,OS_S8 :
  1740. asize:=OT_BITS8;
  1741. OS_16,OS_S16, OS_M16:
  1742. asize:=OT_BITS16;
  1743. OS_32,OS_S32 :
  1744. {$ifdef i8086}
  1745. if siz=S_FAR then
  1746. asize:=OT_FAR
  1747. else
  1748. asize:=OT_BITS32;
  1749. {$else i8086}
  1750. asize:=OT_BITS32;
  1751. {$endif i8086}
  1752. OS_F32,OS_M32 :
  1753. asize:=OT_BITS32;
  1754. OS_64,OS_S64:
  1755. begin
  1756. { Only FPU operations know about 64bit values, for all
  1757. integer operations it is seen as 32bit
  1758. this applies only to i386, see tw16622}
  1759. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  1760. asize:=OT_BITS64
  1761. else if MemRefInfo(opcode).ExistsSSEAVX then asize:=OT_BITS64
  1762. {$ifdef i386}
  1763. else
  1764. asize:=OT_BITS32
  1765. {$endif i386}
  1766. ;
  1767. end;
  1768. OS_F64,OS_C64, OS_M64 :
  1769. asize:=OT_BITS64;
  1770. OS_F80 :
  1771. asize:=OT_BITS80;
  1772. OS_128,OS_M128,OS_MS128:
  1773. asize := OT_BITS128;
  1774. OS_M256,OS_MS256:
  1775. asize := OT_BITS256;
  1776. OS_M512,OS_MS512:
  1777. asize := OT_BITS512;
  1778. else
  1779. ;
  1780. end;
  1781. if asize<>0 then
  1782. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and OT_NON_SIZE) or asize;
  1783. end;
  1784. end;
  1785. else
  1786. ;
  1787. end;
  1788. end;
  1789. { Condition ? }
  1790. if condition<>C_None then
  1791. ai.SetCondition(condition);
  1792. { Set is_jmp, it enables asmwriter to emit short jumps if appropriate }
  1793. if (opcode=A_JMP) or (opcode=A_JCC) then
  1794. ai.is_jmp := True;
  1795. { Concat the opcode or give an error }
  1796. if assigned(ai) then
  1797. p.concat(ai)
  1798. else
  1799. Message(asmr_e_invalid_opcode_and_operand);
  1800. result:=ai;
  1801. end;
  1802. function Tx86Instruction.getstring: string;
  1803. var
  1804. i : longint;
  1805. s, sval : string;
  1806. regnr: string;
  1807. addsize : boolean;
  1808. begin
  1809. s:='['+std_op2str[opcode];
  1810. for i:=1 to ops do
  1811. begin
  1812. with operands[i] as Tx86Operand do
  1813. begin
  1814. if i=0 then
  1815. s:=s+' '
  1816. else
  1817. s:=s+',';
  1818. { type }
  1819. addsize:=false;
  1820. case operands[i].opr.typ of
  1821. OPR_CONSTANT : begin
  1822. str(operands[i].opr.val, sval);
  1823. s:=s+ sval;
  1824. end;
  1825. OPR_REGISTER : begin
  1826. regnr := '';
  1827. str(getsupreg(opr.reg),regnr);
  1828. if getsubreg(opr.reg)= R_SUBMMX then
  1829. s:=s+'xmmreg' + regnr
  1830. else
  1831. if getsubreg(opr.reg)= R_SUBMMY then
  1832. s:=s+'ymmreg' + regnr
  1833. else
  1834. if getsubreg(opr.reg)= R_SUBMMZ then
  1835. s:=s+'zmmreg' + regnr
  1836. else
  1837. if getregtype(opr.reg)= R_MMXREGISTER then
  1838. s:=s+'mmxreg'
  1839. else
  1840. if getregtype(opr.reg)= R_FPUREGISTER then
  1841. s:=s+'fpureg'
  1842. else
  1843. if getregtype(opr.reg)=R_INTREGISTER then
  1844. begin
  1845. s:=s+'reg';
  1846. addsize:=true;
  1847. end;
  1848. end;
  1849. OPR_LOCAL,
  1850. OPR_REFERENCE: begin
  1851. s:=s + 'mem';
  1852. addsize:=true;
  1853. end;
  1854. else s:=s + '???';
  1855. end;
  1856. if addsize then
  1857. begin
  1858. sval := '';
  1859. str(tcgsize2size[size], sval);
  1860. s := s + sval;
  1861. end;
  1862. if vopext <> 0 then
  1863. begin
  1864. str(vopext and $07, regnr);
  1865. if vopext and OTVE_VECTOR_WRITEMASK = OTVE_VECTOR_WRITEMASK then
  1866. s := s + ' {k' + regnr + '}';
  1867. if vopext and OTVE_VECTOR_ZERO = OTVE_VECTOR_ZERO then
  1868. s := s + ' {z}';
  1869. if vopext and OTVE_VECTOR_SAE = OTVE_VECTOR_SAE then
  1870. s := s + ' {sae}';
  1871. if vopext and OTVE_VECTOR_BCST = OTVE_VECTOR_BCST then
  1872. case vopext and OTVE_VECTOR_BCST_MASK of
  1873. OTVE_VECTOR_BCST2: s := s + ' {1to2}';
  1874. OTVE_VECTOR_BCST4: s := s + ' {1to4}';
  1875. OTVE_VECTOR_BCST8: s := s + ' {1to8}';
  1876. OTVE_VECTOR_BCST16: s := s + ' {1to16}';
  1877. end;
  1878. if vopext and OTVE_VECTOR_ER = OTVE_VECTOR_ER then
  1879. case vopext and OTVE_VECTOR_ER_MASK of
  1880. OTVE_VECTOR_RNSAE: s := s + ' {rn-sae}';
  1881. OTVE_VECTOR_RDSAE: s := s + ' {rd-sae}';
  1882. OTVE_VECTOR_RUSAE: s := s + ' {ru-sae}';
  1883. OTVE_VECTOR_RZSAE: s := s + ' {rz-sae}';
  1884. end;
  1885. end;
  1886. end;
  1887. end;
  1888. GetString:=s+']';
  1889. end;
  1890. function Tx86Instruction.MightHaveExtension: boolean;
  1891. begin
  1892. Result:=aasmcpu.MightHaveExtension(opcode);
  1893. end;
  1894. end.