libvex_ir.h 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207
  1. /*---------------------------------------------------------------*/
  2. /*--- begin libvex_ir.h ---*/
  3. /*---------------------------------------------------------------*/
  4. /*
  5. This file is part of Valgrind, a dynamic binary instrumentation
  6. framework.
  7. Copyright (C) 2004-2017 OpenWorks LLP
  8. info@open-works.net
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation; either version 2 of the
  12. License, or (at your option) any later version.
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. 02110-1301, USA.
  21. The GNU General Public License is contained in the file COPYING.
  22. Neither the names of the U.S. Department of Energy nor the
  23. University of California nor the names of its contributors may be
  24. used to endorse or promote products derived from this software
  25. without prior written permission.
  26. */
  27. #ifndef __LIBVEX_IR_H
  28. #define __LIBVEX_IR_H
  29. #include "libvex_basictypes.h"
  30. /*---------------------------------------------------------------*/
  31. /*--- High-level IR description ---*/
  32. /*---------------------------------------------------------------*/
  33. /* Vex IR is an architecture-neutral intermediate representation.
  34. Unlike some IRs in systems similar to Vex, it is not like assembly
  35. language (ie. a list of instructions). Rather, it is more like the
  36. IR that might be used in a compiler.
  37. Code blocks
  38. ~~~~~~~~~~~
  39. The code is broken into small code blocks ("superblocks", type:
  40. 'IRSB'). Each code block typically represents from 1 to perhaps 50
  41. instructions. IRSBs are single-entry, multiple-exit code blocks.
  42. Each IRSB contains three things:
  43. - a type environment, which indicates the type of each temporary
  44. value present in the IRSB
  45. - a list of statements, which represent code
  46. - a jump that exits from the end the IRSB
  47. Because the blocks are multiple-exit, there can be additional
  48. conditional exit statements that cause control to leave the IRSB
  49. before the final exit. Also because of this, IRSBs can cover
  50. multiple non-consecutive sequences of code (up to 3). These are
  51. recorded in the type VexGuestExtents (see libvex.h).
  52. Statements and expressions
  53. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. Statements (type 'IRStmt') represent operations with side-effects,
  55. eg. guest register writes, stores, and assignments to temporaries.
  56. Expressions (type 'IRExpr') represent operations without
  57. side-effects, eg. arithmetic operations, loads, constants.
  58. Expressions can contain sub-expressions, forming expression trees,
  59. eg. (3 + (4 * load(addr1)).
  60. Storage of guest state
  61. ~~~~~~~~~~~~~~~~~~~~~~
  62. The "guest state" contains the guest registers of the guest machine
  63. (ie. the machine that we are simulating). It is stored by default
  64. in a block of memory supplied by the user of the VEX library,
  65. generally referred to as the guest state (area). To operate on
  66. these registers, one must first read ("Get") them from the guest
  67. state into a temporary value. Afterwards, one can write ("Put")
  68. them back into the guest state.
  69. Get and Put are characterised by a byte offset into the guest
  70. state, a small integer which effectively gives the identity of the
  71. referenced guest register, and a type, which indicates the size of
  72. the value to be transferred.
  73. The basic "Get" and "Put" operations are sufficient to model normal
  74. fixed registers on the guest. Selected areas of the guest state
  75. can be treated as a circular array of registers (type:
  76. 'IRRegArray'), which can be indexed at run-time. This is done with
  77. the "GetI" and "PutI" primitives. This is necessary to describe
  78. rotating register files, for example the x87 FPU stack, SPARC
  79. register windows, and the Itanium register files.
  80. Examples, and flattened vs. unflattened code
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. For example, consider this x86 instruction:
  83. addl %eax, %ebx
  84. One Vex IR translation for this code would be this:
  85. ------ IMark(0x24F275, 7, 0) ------
  86. t3 = GET:I32(0) # get %eax, a 32-bit integer
  87. t2 = GET:I32(12) # get %ebx, a 32-bit integer
  88. t1 = Add32(t3,t2) # addl
  89. PUT(0) = t1 # put %eax
  90. (For simplicity, this ignores the effects on the condition codes, and
  91. the update of the instruction pointer.)
  92. The "IMark" is an IR statement that doesn't represent actual code.
  93. Instead it indicates the address and length of the original
  94. instruction. The numbers 0 and 12 are offsets into the guest state
  95. for %eax and %ebx. The full list of offsets for an architecture
  96. <ARCH> can be found in the type VexGuest<ARCH>State in the file
  97. VEX/pub/libvex_guest_<ARCH>.h.
  98. The five statements in this example are:
  99. - the IMark
  100. - three assignments to temporaries
  101. - one register write (put)
  102. The six expressions in this example are:
  103. - two register reads (gets)
  104. - one arithmetic (add) operation
  105. - three temporaries (two nested within the Add32, one in the PUT)
  106. The above IR is "flattened", ie. all sub-expressions are "atoms",
  107. either constants or temporaries. An equivalent, unflattened version
  108. would be:
  109. PUT(0) = Add32(GET:I32(0), GET:I32(12))
  110. IR is guaranteed to be flattened at instrumentation-time. This makes
  111. instrumentation easier. Equivalent flattened and unflattened IR
  112. typically results in the same generated code.
  113. Another example, this one showing loads and stores:
  114. addl %edx,4(%eax)
  115. This becomes (again ignoring condition code and instruction pointer
  116. updates):
  117. ------ IMark(0x4000ABA, 3, 0) ------
  118. t3 = Add32(GET:I32(0),0x4:I32)
  119. t2 = LDle:I32(t3)
  120. t1 = GET:I32(8)
  121. t0 = Add32(t2,t1)
  122. STle(t3) = t0
  123. The "le" in "LDle" and "STle" is short for "little-endian".
  124. No need for deallocations
  125. ~~~~~~~~~~~~~~~~~~~~~~~~~
  126. Although there are allocation functions for various data structures
  127. in this file, there are no deallocation functions. This is because
  128. Vex uses a memory allocation scheme that automatically reclaims the
  129. memory used by allocated structures once translation is completed.
  130. This makes things easier for tools that instruments/transforms code
  131. blocks.
  132. SSAness and typing
  133. ~~~~~~~~~~~~~~~~~~
  134. The IR is fully typed. For every IRSB (IR block) it is possible to
  135. say unambiguously whether or not it is correctly typed.
  136. Incorrectly typed IR has no meaning and the VEX will refuse to
  137. process it. At various points during processing VEX typechecks the
  138. IR and aborts if any violations are found. This seems overkill but
  139. makes it a great deal easier to build a reliable JIT.
  140. IR also has the SSA property. SSA stands for Static Single
  141. Assignment, and what it means is that each IR temporary may be
  142. assigned to only once. This idea became widely used in compiler
  143. construction in the mid to late 90s. It makes many IR-level
  144. transformations/code improvements easier, simpler and faster.
  145. Whenever it typechecks an IR block, VEX also checks the SSA
  146. property holds, and will abort if not so. So SSAness is
  147. mechanically and rigidly enforced.
  148. */
  149. /*---------------------------------------------------------------*/
  150. /*--- Type definitions for the IR ---*/
  151. /*---------------------------------------------------------------*/
  152. /* General comments about naming schemes:
  153. All publically visible functions contain the name of the primary
  154. type on which they operate (IRFoo, IRBar, etc). Hence you should
  155. be able to identify these functions by grepping for "IR[A-Z]".
  156. For some type 'IRFoo':
  157. - ppIRFoo is the printing method for IRFoo, printing it to the
  158. output channel specified in the LibVEX_Initialise call.
  159. - eqIRFoo is a structural equality predicate for IRFoos.
  160. - deepCopyIRFoo is a deep copy constructor for IRFoos.
  161. It recursively traverses the entire argument tree and
  162. produces a complete new tree. All types have a deep copy
  163. constructor.
  164. - shallowCopyIRFoo is the shallow copy constructor for IRFoos.
  165. It creates a new top-level copy of the supplied object,
  166. but does not copy any sub-objects. Only some types have a
  167. shallow copy constructor.
  168. */
  169. /* ------------------ Types ------------------ */
  170. /* A type indicates the size of a value, and whether it's an integer, a
  171. float, or a vector (SIMD) value. */
  172. typedef
  173. enum {
  174. Ity_INVALID=0x1100,
  175. Ity_I1,
  176. Ity_I8,
  177. Ity_I16,
  178. Ity_I32,
  179. Ity_I64,
  180. Ity_I128, /* 128-bit scalar */
  181. Ity_F16, /* 16 bit float */
  182. Ity_F32, /* IEEE 754 float */
  183. Ity_F64, /* IEEE 754 double */
  184. Ity_D32, /* 32-bit Decimal floating point */
  185. Ity_D64, /* 64-bit Decimal floating point */
  186. Ity_D128, /* 128-bit Decimal floating point */
  187. Ity_F128, /* 128-bit floating point; implementation defined */
  188. Ity_V128, /* 128-bit SIMD */
  189. Ity_V256 /* 256-bit SIMD */
  190. }
  191. IRType;
  192. /* Pretty-print an IRType */
  193. extern void ppIRType ( IRType );
  194. /* Get the size (in bytes) of an IRType */
  195. extern Int sizeofIRType ( IRType );
  196. /* Translate 1/2/4/8 into Ity_I{8,16,32,64} respectively. Asserts on
  197. any other input. */
  198. extern IRType integerIRTypeOfSize ( Int szB );
  199. /* ------------------ Endianness ------------------ */
  200. /* IREndness is used in load IRExprs and store IRStmts. */
  201. typedef
  202. enum {
  203. Iend_LE=0x1200, /* little endian */
  204. Iend_BE /* big endian */
  205. }
  206. IREndness;
  207. /* ------------------ Constants ------------------ */
  208. /* IRConsts are used within 'Const' and 'Exit' IRExprs. */
  209. /* The various kinds of constant. */
  210. typedef
  211. enum {
  212. Ico_U1=0x1300,
  213. Ico_U8,
  214. Ico_U16,
  215. Ico_U32,
  216. Ico_U64,
  217. Ico_F32, /* 32-bit IEEE754 floating */
  218. Ico_F32i, /* 32-bit unsigned int to be interpreted literally
  219. as a IEEE754 single value. */
  220. Ico_F64, /* 64-bit IEEE754 floating */
  221. Ico_F64i, /* 64-bit unsigned int to be interpreted literally
  222. as a IEEE754 double value. */
  223. Ico_V128, /* 128-bit restricted vector constant, with 1 bit
  224. (repeated 8 times) for each of the 16 x 1-byte lanes */
  225. Ico_V256 /* 256-bit restricted vector constant, with 1 bit
  226. (repeated 8 times) for each of the 32 x 1-byte lanes */
  227. }
  228. IRConstTag;
  229. /* A constant. Stored as a tagged union. 'tag' indicates what kind of
  230. constant this is. 'Ico' is the union that holds the fields. If an
  231. IRConst 'c' has c.tag equal to Ico_U32, then it's a 32-bit constant,
  232. and its value can be accessed with 'c.Ico.U32'. */
  233. typedef
  234. struct _IRConst {
  235. IRConstTag tag;
  236. union {
  237. Bool U1;
  238. UChar U8;
  239. UShort U16;
  240. UInt U32;
  241. ULong U64;
  242. Float F32;
  243. UInt F32i;
  244. Double F64;
  245. ULong F64i;
  246. UShort V128; /* 16-bit value; see Ico_V128 comment above */
  247. UInt V256; /* 32-bit value; see Ico_V256 comment above */
  248. } Ico;
  249. }
  250. IRConst;
  251. /* IRConst constructors */
  252. extern IRConst* IRConst_U1 ( Bool );
  253. extern IRConst* IRConst_U8 ( UChar );
  254. extern IRConst* IRConst_U16 ( UShort );
  255. extern IRConst* IRConst_U32 ( UInt );
  256. extern IRConst* IRConst_U64 ( ULong );
  257. extern IRConst* IRConst_F32 ( Float );
  258. extern IRConst* IRConst_F32i ( UInt );
  259. extern IRConst* IRConst_F64 ( Double );
  260. extern IRConst* IRConst_F64i ( ULong );
  261. extern IRConst* IRConst_V128 ( UShort );
  262. extern IRConst* IRConst_V256 ( UInt );
  263. /* Deep-copy an IRConst */
  264. extern IRConst* deepCopyIRConst ( const IRConst* );
  265. /* Pretty-print an IRConst */
  266. extern void ppIRConst ( const IRConst* );
  267. /* Compare two IRConsts for equality */
  268. extern Bool eqIRConst ( const IRConst*, const IRConst* );
  269. /* ------------------ Call targets ------------------ */
  270. /* Describes a helper function to call. The name part is purely for
  271. pretty printing and not actually used. regparms=n tells the back
  272. end that the callee has been declared
  273. "__attribute__((regparm(n)))", although indirectly using the
  274. VEX_REGPARM(n) macro. On some targets (x86) the back end will need
  275. to construct a non-standard sequence to call a function declared
  276. like this.
  277. mcx_mask is a sop to Memcheck. It indicates which args should be
  278. considered 'always defined' when lazily computing definedness of
  279. the result. Bit 0 of mcx_mask corresponds to args[0], bit 1 to
  280. args[1], etc. If a bit is set, the corresponding arg is excluded
  281. (hence "x" in "mcx") from definedness checking.
  282. */
  283. typedef
  284. struct {
  285. Int regparms;
  286. const HChar* name;
  287. void* addr;
  288. UInt mcx_mask;
  289. }
  290. IRCallee;
  291. /* Create an IRCallee. */
  292. extern IRCallee* mkIRCallee ( Int regparms, const HChar* name, void* addr );
  293. /* Deep-copy an IRCallee. */
  294. extern IRCallee* deepCopyIRCallee ( const IRCallee* );
  295. /* Pretty-print an IRCallee. */
  296. extern void ppIRCallee ( const IRCallee* );
  297. /* ------------------ Guest state arrays ------------------ */
  298. /* This describes a section of the guest state that we want to
  299. be able to index at run time, so as to be able to describe
  300. indexed or rotating register files on the guest. */
  301. typedef
  302. struct {
  303. Int base; /* guest state offset of start of indexed area */
  304. IRType elemTy; /* type of each element in the indexed area */
  305. Int nElems; /* number of elements in the indexed area */
  306. }
  307. IRRegArray;
  308. extern IRRegArray* mkIRRegArray ( Int, IRType, Int );
  309. extern IRRegArray* deepCopyIRRegArray ( const IRRegArray* );
  310. extern void ppIRRegArray ( const IRRegArray* );
  311. extern Bool eqIRRegArray ( const IRRegArray*, const IRRegArray* );
  312. /* ------------------ Temporaries ------------------ */
  313. /* This represents a temporary, eg. t1. The IR optimiser relies on the
  314. fact that IRTemps are 32-bit ints. Do not change them to be ints of
  315. any other size. */
  316. typedef UInt IRTemp;
  317. /* Pretty-print an IRTemp. */
  318. extern void ppIRTemp ( IRTemp );
  319. #define IRTemp_INVALID ((IRTemp)0xFFFFFFFF)
  320. /* --------------- Primops (arity 1,2,3 and 4) --------------- */
  321. /* Primitive operations that are used in Unop, Binop, Triop and Qop
  322. IRExprs. Once we take into account integer, floating point and SIMD
  323. operations of all the different sizes, there are quite a lot of them.
  324. Most instructions supported by the architectures that Vex supports
  325. (x86, PPC, etc) are represented. Some more obscure ones (eg. cpuid)
  326. are not; they are instead handled with dirty helpers that emulate
  327. their functionality. Such obscure ones are thus not directly visible
  328. in the IR, but their effects on guest state (memory and registers)
  329. are made visible via the annotations in IRDirty structures.
  330. 2018-Dec-27: some of int<->fp conversion operations have been renamed so as
  331. to have a trailing _DEP, meaning "deprecated". This is because they don't
  332. specify a rounding mode to be used for the conversion and so are
  333. underspecified. Their use should be replaced with equivalents that do
  334. specify a rounding mode, either as a first argument or using a suffix on the
  335. name, that indicates the rounding mode to use.
  336. */
  337. typedef
  338. enum {
  339. /* -- Do not change this ordering. The IR generators rely on
  340. (eg) Iop_Add64 == IopAdd8 + 3. -- */
  341. Iop_INVALID=0x1400,
  342. Iop_Add8, Iop_Add16, Iop_Add32, Iop_Add64,
  343. Iop_Sub8, Iop_Sub16, Iop_Sub32, Iop_Sub64,
  344. /* Signless mul. MullS/MullU is elsewhere. */
  345. Iop_Mul8, Iop_Mul16, Iop_Mul32, Iop_Mul64,
  346. Iop_Or8, Iop_Or16, Iop_Or32, Iop_Or64,
  347. Iop_And8, Iop_And16, Iop_And32, Iop_And64,
  348. Iop_Xor8, Iop_Xor16, Iop_Xor32, Iop_Xor64,
  349. Iop_Shl8, Iop_Shl16, Iop_Shl32, Iop_Shl64,
  350. Iop_Shr8, Iop_Shr16, Iop_Shr32, Iop_Shr64,
  351. Iop_Sar8, Iop_Sar16, Iop_Sar32, Iop_Sar64,
  352. /* Integer comparisons. */
  353. Iop_CmpEQ8, Iop_CmpEQ16, Iop_CmpEQ32, Iop_CmpEQ64,
  354. Iop_CmpNE8, Iop_CmpNE16, Iop_CmpNE32, Iop_CmpNE64,
  355. /* Tags for unary ops */
  356. Iop_Not8, Iop_Not16, Iop_Not32, Iop_Not64,
  357. /* Exactly like CmpEQ8/16/32/64, but carrying the additional
  358. hint that these compute the success/failure of a CAS
  359. operation, and hence are almost certainly applied to two
  360. copies of the same value, which in turn has implications for
  361. Memcheck's instrumentation. */
  362. Iop_CasCmpEQ8, Iop_CasCmpEQ16, Iop_CasCmpEQ32, Iop_CasCmpEQ64,
  363. Iop_CasCmpNE8, Iop_CasCmpNE16, Iop_CasCmpNE32, Iop_CasCmpNE64,
  364. /* Exactly like CmpNE8/16/32/64, but carrying the additional
  365. hint that these needs expensive definedness tracking. */
  366. Iop_ExpCmpNE8, Iop_ExpCmpNE16, Iop_ExpCmpNE32, Iop_ExpCmpNE64,
  367. /* -- Ordering not important after here. -- */
  368. /* Widening multiplies */
  369. Iop_MullS8, Iop_MullS16, Iop_MullS32, Iop_MullS64,
  370. Iop_MullU8, Iop_MullU16, Iop_MullU32, Iop_MullU64,
  371. /* Counting bits */
  372. /* Ctz64/Ctz32/Clz64/Clz32 are UNDEFINED when given arguments of zero.
  373. You must ensure they are never given a zero argument. As of
  374. 2018-Nov-14 they are deprecated. Try to use the Nat variants
  375. immediately below, if you can.
  376. */
  377. Iop_Clz64, Iop_Clz32, /* count leading zeroes */
  378. Iop_Ctz64, Iop_Ctz32, /* count trailing zeros */
  379. /* Count leading/trailing zeroes, with "natural" semantics for the
  380. case where the input is zero: then the result is the number of bits
  381. in the word. */
  382. Iop_ClzNat64, Iop_ClzNat32,
  383. Iop_CtzNat64, Iop_CtzNat32,
  384. /* Population count -- compute the number of 1 bits in the argument. */
  385. Iop_PopCount64, Iop_PopCount32,
  386. /* Standard integer comparisons */
  387. Iop_CmpLT32S, Iop_CmpLT64S,
  388. Iop_CmpLE32S, Iop_CmpLE64S,
  389. Iop_CmpLT32U, Iop_CmpLT64U,
  390. Iop_CmpLE32U, Iop_CmpLE64U,
  391. /* As a sop to Valgrind-Memcheck, the following are useful. */
  392. Iop_CmpNEZ8, Iop_CmpNEZ16, Iop_CmpNEZ32, Iop_CmpNEZ64,
  393. Iop_CmpwNEZ32, Iop_CmpwNEZ64, /* all-0s -> all-Os; other -> all-1s */
  394. Iop_Left8, Iop_Left16, Iop_Left32, Iop_Left64, /* \x -> x | -x */
  395. Iop_Max32U, /* unsigned max */
  396. /* PowerPC-style 3-way integer comparisons. Without them it is
  397. difficult to simulate PPC efficiently.
  398. op(x,y) | x < y = 0x8 else
  399. | x > y = 0x4 else
  400. | x == y = 0x2
  401. */
  402. Iop_CmpORD32U, Iop_CmpORD64U,
  403. Iop_CmpORD32S, Iop_CmpORD64S,
  404. /* Division */
  405. /* TODO: clarify semantics wrt rounding, negative values, whatever */
  406. Iop_DivU32, // :: I32,I32 -> I32 (simple div, no mod)
  407. Iop_DivS32, // ditto, signed
  408. Iop_DivU64, // :: I64,I64 -> I64 (simple div, no mod)
  409. Iop_DivS64, // ditto, signed
  410. Iop_DivU64E, // :: I64,I64 -> I64 (dividend is 64-bit arg (hi)
  411. // concat with 64 0's (low))
  412. Iop_DivS64E, // ditto, signed
  413. Iop_DivU32E, // :: I32,I32 -> I32 (dividend is 32-bit arg (hi)
  414. // concat with 32 0's (low))
  415. Iop_DivS32E, // ditto, signed
  416. Iop_DivModU64to32, // :: I64,I32 -> I64
  417. // of which lo half is div and hi half is mod
  418. Iop_DivModS64to32, // ditto, signed
  419. Iop_DivModU128to64, // :: V128,I64 -> V128
  420. // of which lo half is div and hi half is mod
  421. Iop_DivModS128to64, // ditto, signed
  422. Iop_DivModS64to64, // :: I64,I64 -> I128
  423. // of which lo half is div and hi half is mod
  424. Iop_DivModU64to64, // :: I64,I64 -> I128
  425. // of which lo half is div and hi half is mod
  426. Iop_DivModS32to32, // :: I32,I32 -> I64
  427. // of which lo half is div and hi half is mod
  428. Iop_DivModU32to32, // :: I32,I32 -> I64
  429. // of which lo half is div and hi half is mod
  430. /* Integer conversions. Some of these are redundant (eg
  431. Iop_64to8 is the same as Iop_64to32 and then Iop_32to8), but
  432. having a complete set reduces the typical dynamic size of IR
  433. and makes the instruction selectors easier to write. */
  434. /* Widening conversions */
  435. Iop_8Uto16, Iop_8Uto32, Iop_8Uto64,
  436. Iop_16Uto32, Iop_16Uto64,
  437. Iop_32Uto64,
  438. Iop_8Sto16, Iop_8Sto32, Iop_8Sto64,
  439. Iop_16Sto32, Iop_16Sto64,
  440. Iop_32Sto64,
  441. /* Narrowing conversions */
  442. Iop_64to8, Iop_32to8, Iop_64to16,
  443. /* 8 <-> 16 bit conversions */
  444. Iop_16to8, // :: I16 -> I8, low half
  445. Iop_16HIto8, // :: I16 -> I8, high half
  446. Iop_8HLto16, // :: (I8,I8) -> I16
  447. /* 16 <-> 32 bit conversions */
  448. Iop_32to16, // :: I32 -> I16, low half
  449. Iop_32HIto16, // :: I32 -> I16, high half
  450. Iop_16HLto32, // :: (I16,I16) -> I32
  451. /* 32 <-> 64 bit conversions */
  452. Iop_64to32, // :: I64 -> I32, low half
  453. Iop_64HIto32, // :: I64 -> I32, high half
  454. Iop_32HLto64, // :: (I32,I32) -> I64
  455. /* 64 <-> 128 bit conversions */
  456. Iop_128to64, // :: I128 -> I64, low half
  457. Iop_128HIto64, // :: I128 -> I64, high half
  458. Iop_64HLto128, // :: (I64,I64) -> I128
  459. /* 1-bit stuff */
  460. Iop_Not1, /* :: Ity_Bit -> Ity_Bit */
  461. Iop_32to1, /* :: Ity_I32 -> Ity_Bit, just select bit[0] */
  462. Iop_64to1, /* :: Ity_I64 -> Ity_Bit, just select bit[0] */
  463. Iop_1Uto8, /* :: Ity_Bit -> Ity_I8, unsigned widen */
  464. Iop_1Uto32, /* :: Ity_Bit -> Ity_I32, unsigned widen */
  465. Iop_1Uto64, /* :: Ity_Bit -> Ity_I64, unsigned widen */
  466. Iop_1Sto8, /* :: Ity_Bit -> Ity_I8, signed widen */
  467. Iop_1Sto16, /* :: Ity_Bit -> Ity_I16, signed widen */
  468. Iop_1Sto32, /* :: Ity_Bit -> Ity_I32, signed widen */
  469. Iop_1Sto64, /* :: Ity_Bit -> Ity_I64, signed widen */
  470. /* ------ Floating point. We try to be IEEE754 compliant. ------ */
  471. /* --- Simple stuff as mandated by 754. --- */
  472. /* Binary operations, with rounding. */
  473. /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */
  474. Iop_AddF64, Iop_SubF64, Iop_MulF64, Iop_DivF64,
  475. /* :: IRRoundingMode(I32) x F32 x F32 -> F32 */
  476. Iop_AddF32, Iop_SubF32, Iop_MulF32, Iop_DivF32,
  477. /* Variants of the above which produce a 64-bit result but which
  478. round their result to a IEEE float range first. */
  479. /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */
  480. Iop_AddF64r32, Iop_SubF64r32, Iop_MulF64r32, Iop_DivF64r32,
  481. /* Unary operations, without rounding. */
  482. /* :: F64 -> F64 */
  483. Iop_NegF64, Iop_AbsF64,
  484. /* :: F32 -> F32 */
  485. Iop_NegF32, Iop_AbsF32,
  486. /* Unary operations, with rounding. */
  487. /* :: IRRoundingMode(I32) x F64 -> F64 */
  488. Iop_SqrtF64,
  489. /* :: IRRoundingMode(I32) x F32 -> F32 */
  490. Iop_SqrtF32,
  491. /* Comparison, yielding GT/LT/EQ/UN(ordered), as per the following:
  492. 0x45 Unordered
  493. 0x01 LT
  494. 0x00 GT
  495. 0x40 EQ
  496. This just happens to be the Intel encoding. The values
  497. are recorded in the type IRCmpF64Result.
  498. */
  499. /* :: F64 x F64 -> IRCmpF64Result(I32) */
  500. Iop_CmpF64,
  501. Iop_CmpF32,
  502. Iop_CmpF128,
  503. /* --- Int to/from FP conversions. --- */
  504. /* For the most part, these take a first argument :: Ity_I32 (as
  505. IRRoundingMode) which is an indication of the rounding mode
  506. to use, as per the following encoding ("the standard
  507. encoding"):
  508. 00b to nearest (the default)
  509. 01b to -infinity
  510. 10b to +infinity
  511. 11b to zero
  512. This just happens to be the Intel encoding. For reference only,
  513. the PPC encoding is:
  514. 00b to nearest (the default)
  515. 01b to zero
  516. 10b to +infinity
  517. 11b to -infinity
  518. Any PPC -> IR front end will have to translate these PPC
  519. encodings, as encoded in the guest state, to the standard
  520. encodings, to pass to the primops.
  521. For reference only, the ARM VFP encoding is:
  522. 00b to nearest
  523. 01b to +infinity
  524. 10b to -infinity
  525. 11b to zero
  526. Again, this will have to be converted to the standard encoding
  527. to pass to primops.
  528. If one of these conversions gets an out-of-range condition,
  529. or a NaN, as an argument, the result is host-defined. On x86
  530. the "integer indefinite" value 0x80..00 is produced. On PPC
  531. it is either 0x80..00 or 0x7F..FF depending on the sign of
  532. the argument.
  533. On ARMvfp, when converting to a signed integer result, the
  534. overflow result is 0x80..00 for negative args and 0x7F..FF
  535. for positive args. For unsigned integer results it is
  536. 0x00..00 and 0xFF..FF respectively.
  537. Rounding is required whenever the destination type cannot
  538. represent exactly all values of the source type.
  539. */
  540. Iop_F64toI16S, /* IRRoundingMode(I32) x F64 -> signed I16 */
  541. Iop_F64toI32S, /* IRRoundingMode(I32) x F64 -> signed I32 */
  542. Iop_F64toI64S, /* IRRoundingMode(I32) x F64 -> signed I64 */
  543. Iop_F64toI64U, /* IRRoundingMode(I32) x F64 -> unsigned I64 */
  544. Iop_F64toI32U, /* IRRoundingMode(I32) x F64 -> unsigned I32 */
  545. Iop_I32StoF64, /* signed I32 -> F64 */
  546. Iop_I64StoF64, /* IRRoundingMode(I32) x signed I64 -> F64 */
  547. Iop_I64UtoF64, /* IRRoundingMode(I32) x unsigned I64 -> F64 */
  548. Iop_I64UtoF32, /* IRRoundingMode(I32) x unsigned I64 -> F32 */
  549. Iop_I32UtoF32, /* IRRoundingMode(I32) x unsigned I32 -> F32 */
  550. Iop_I32UtoF64, /* unsigned I32 -> F64 */
  551. Iop_F32toI32S, /* IRRoundingMode(I32) x F32 -> signed I32 */
  552. Iop_F32toI64S, /* IRRoundingMode(I32) x F32 -> signed I64 */
  553. Iop_F32toI32U, /* IRRoundingMode(I32) x F32 -> unsigned I32 */
  554. Iop_F32toI64U, /* IRRoundingMode(I32) x F32 -> unsigned I64 */
  555. Iop_I32StoF32, /* IRRoundingMode(I32) x signed I32 -> F32 */
  556. Iop_I64StoF32, /* IRRoundingMode(I32) x signed I64 -> F32 */
  557. /* Conversion between floating point formats */
  558. Iop_F32toF64, /* F32 -> F64 */
  559. Iop_F64toF32, /* IRRoundingMode(I32) x F64 -> F32 */
  560. /* Reinterpretation. Take an F64 and produce an I64 with
  561. the same bit pattern, or vice versa. */
  562. Iop_ReinterpF64asI64, Iop_ReinterpI64asF64,
  563. Iop_ReinterpF32asI32, Iop_ReinterpI32asF32,
  564. /* Support for 128-bit floating point */
  565. Iop_F64HLtoF128,/* (high half of F128,low half of F128) -> F128 */
  566. Iop_F128HItoF64,/* F128 -> high half of F128 into a F64 register */
  567. Iop_F128LOtoF64,/* F128 -> low half of F128 into a F64 register */
  568. /* :: IRRoundingMode(I32) x F128 x F128 -> F128 */
  569. Iop_AddF128, Iop_SubF128, Iop_MulF128, Iop_DivF128,
  570. Iop_MAddF128, // (A * B) + C
  571. Iop_MSubF128, // (A * B) - C
  572. Iop_NegMAddF128, // -((A * B) + C)
  573. Iop_NegMSubF128, // -((A * B) - C)
  574. /* :: F128 -> F128 */
  575. Iop_NegF128, Iop_AbsF128,
  576. /* :: IRRoundingMode(I32) x F128 -> F128 */
  577. Iop_SqrtF128,
  578. Iop_I32StoF128, /* signed I32 -> F128 */
  579. Iop_I64StoF128, /* signed I64 -> F128 */
  580. Iop_I32UtoF128, /* unsigned I32 -> F128 */
  581. Iop_I64UtoF128, /* unsigned I64 -> F128 */
  582. Iop_F32toF128, /* F32 -> F128 */
  583. Iop_F64toF128, /* F64 -> F128 */
  584. Iop_F128toI32S, /* IRRoundingMode(I32) x F128 -> signed I32 */
  585. Iop_F128toI64S, /* IRRoundingMode(I32) x F128 -> signed I64 */
  586. Iop_F128toI32U, /* IRRoundingMode(I32) x F128 -> unsigned I32 */
  587. Iop_F128toI64U, /* IRRoundingMode(I32) x F128 -> unsigned I64 */
  588. Iop_F128toI128S,/* IRRoundingMode(I32) x F128 -> signed I128 */
  589. Iop_F128toF64, /* IRRoundingMode(I32) x F128 -> F64 */
  590. Iop_F128toF32, /* IRRoundingMode(I32) x F128 -> F32 */
  591. Iop_RndF128, /* IRRoundingMode(I32) x F128 -> F128 */
  592. /* Truncate to the specified value, source and result
  593. * are stroed in a F128 register.
  594. */
  595. Iop_TruncF128toI32S, /* truncate F128 -> I32 */
  596. Iop_TruncF128toI32U, /* truncate F128 -> I32 */
  597. Iop_TruncF128toI64U, /* truncate F128 -> I64 */
  598. Iop_TruncF128toI64S, /* truncate F128 -> I64 */
  599. /* --- guest x86/amd64 specifics, not mandated by 754. --- */
  600. /* Binary ops, with rounding. */
  601. /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */
  602. Iop_AtanF64, /* FPATAN, arctan(arg1/arg2) */
  603. Iop_Yl2xF64, /* FYL2X, arg1 * log2(arg2) */
  604. Iop_Yl2xp1F64, /* FYL2XP1, arg1 * log2(arg2+1.0) */
  605. Iop_PRemF64, /* FPREM, non-IEEE remainder(arg1/arg2) */
  606. Iop_PRemC3210F64, /* C3210 flags resulting from FPREM, :: I32 */
  607. Iop_PRem1F64, /* FPREM1, IEEE remainder(arg1/arg2) */
  608. Iop_PRem1C3210F64, /* C3210 flags resulting from FPREM1, :: I32 */
  609. Iop_ScaleF64, /* FSCALE, arg1 * (2^RoundTowardsZero(arg2)) */
  610. /* Note that on x86 guest, PRem1{C3210} has the same behaviour
  611. as the IEEE mandated RemF64, except it is limited in the
  612. range of its operand. Hence the partialness. */
  613. /* Unary ops, with rounding. */
  614. /* :: IRRoundingMode(I32) x F64 -> F64 */
  615. Iop_SinF64, /* FSIN */
  616. Iop_CosF64, /* FCOS */
  617. Iop_TanF64, /* FTAN */
  618. Iop_2xm1F64, /* (2^arg - 1.0) */
  619. Iop_RoundF128toInt, /* F128 value to nearest integral value (still
  620. as F128) */
  621. Iop_RoundF64toInt, /* F64 value to nearest integral value (still
  622. as F64) */
  623. Iop_RoundF32toInt, /* F32 value to nearest integral value (still
  624. as F32) */
  625. /* --- guest s390 specifics, not mandated by 754. --- */
  626. /* Fused multiply-add/sub */
  627. /* :: IRRoundingMode(I32) x F32 x F32 x F32 -> F32
  628. (computes arg2 * arg3 +/- arg4) */
  629. Iop_MAddF32, Iop_MSubF32,
  630. /* --- guest ppc32/64 specifics, not mandated by 754. --- */
  631. /* Ternary operations, with rounding. */
  632. /* Fused multiply-add/sub, with 112-bit intermediate
  633. precision for ppc.
  634. Also used to implement fused multiply-add/sub for s390. */
  635. /* :: IRRoundingMode(I32) x F64 x F64 x F64 -> F64
  636. (computes arg2 * arg3 +/- arg4) */
  637. Iop_MAddF64, Iop_MSubF64,
  638. /* Variants of the above which produce a 64-bit result but which
  639. round their result to a IEEE float range first. */
  640. /* :: IRRoundingMode(I32) x F64 x F64 x F64 -> F64 */
  641. Iop_MAddF64r32, Iop_MSubF64r32,
  642. /* :: F64 -> F64 */
  643. Iop_RSqrtEst5GoodF64, /* reciprocal square root estimate, 5 good bits */
  644. Iop_RoundF64toF64_NEAREST, /* frin */
  645. Iop_RoundF64toF64_NegINF, /* frim */
  646. Iop_RoundF64toF64_PosINF, /* frip */
  647. Iop_RoundF64toF64_ZERO, /* friz */
  648. /* :: F64 -> F32 */
  649. Iop_TruncF64asF32, /* do F64->F32 truncation as per 'fsts' */
  650. /* :: IRRoundingMode(I32) x F64 -> F64 */
  651. Iop_RoundF64toF32, /* round F64 to nearest F32 value (still as F64) */
  652. /* NB: pretty much the same as Iop_F64toF32, except no change
  653. of type. */
  654. /* --- guest arm64 specifics, not mandated by 754. --- */
  655. Iop_RecpExpF64, /* FRECPX d :: IRRoundingMode(I32) x F64 -> F64 */
  656. Iop_RecpExpF32, /* FRECPX s :: IRRoundingMode(I32) x F32 -> F32 */
  657. /* --------- Possibly required by IEEE 754-2008. --------- */
  658. Iop_MaxNumF64, /* max, F64, numerical operand if other is a qNaN */
  659. Iop_MinNumF64, /* min, F64, ditto */
  660. Iop_MaxNumF32, /* max, F32, ditto */
  661. Iop_MinNumF32, /* min, F32, ditto */
  662. /* ------------------ 16-bit scalar FP ------------------ */
  663. Iop_F16toF64, /* F16 -> F64 */
  664. Iop_F64toF16, /* IRRoundingMode(I32) x F64 -> F16 */
  665. Iop_F16toF32, /* F16 -> F32 */
  666. Iop_F32toF16, /* IRRoundingMode(I32) x F32 -> F16 */
  667. /* ------------------ 32-bit SIMD Integer ------------------ */
  668. /* 32x1 saturating add/sub (ok, well, not really SIMD :) */
  669. Iop_QAdd32S,
  670. Iop_QSub32S,
  671. /* 16x2 add/sub, also signed/unsigned saturating variants */
  672. Iop_Add16x2, Iop_Sub16x2,
  673. Iop_QAdd16Sx2, Iop_QAdd16Ux2,
  674. Iop_QSub16Sx2, Iop_QSub16Ux2,
  675. /* 16x2 signed/unsigned halving add/sub. For each lane, these
  676. compute bits 16:1 of (eg) sx(argL) + sx(argR),
  677. or zx(argL) - zx(argR) etc. */
  678. Iop_HAdd16Ux2, Iop_HAdd16Sx2,
  679. Iop_HSub16Ux2, Iop_HSub16Sx2,
  680. /* 8x4 add/sub, also signed/unsigned saturating variants */
  681. Iop_Add8x4, Iop_Sub8x4,
  682. Iop_QAdd8Sx4, Iop_QAdd8Ux4,
  683. Iop_QSub8Sx4, Iop_QSub8Ux4,
  684. /* 8x4 signed/unsigned halving add/sub. For each lane, these
  685. compute bits 8:1 of (eg) sx(argL) + sx(argR),
  686. or zx(argL) - zx(argR) etc. */
  687. Iop_HAdd8Ux4, Iop_HAdd8Sx4,
  688. Iop_HSub8Ux4, Iop_HSub8Sx4,
  689. /* 8x4 sum of absolute unsigned differences. */
  690. Iop_Sad8Ux4,
  691. /* MISC (vector integer cmp != 0) */
  692. Iop_CmpNEZ16x2, Iop_CmpNEZ8x4,
  693. /* Byte swap in a 32-bit word */
  694. Iop_Reverse8sIn32_x1,
  695. /* ------------------ 64-bit SIMD FP ------------------------ */
  696. /* Conversion to/from int */
  697. // Deprecated: these don't specify a rounding mode
  698. Iop_I32UtoF32x2_DEP, Iop_I32StoF32x2_DEP, /* I32x2 -> F32x2 */
  699. Iop_F32toI32Ux2_RZ, Iop_F32toI32Sx2_RZ, /* F32x2 -> I32x2 */
  700. /* Fixed32 format is floating-point number with fixed number of fraction
  701. bits. The number of fraction bits is passed as a second argument of
  702. type I8. */
  703. Iop_F32ToFixed32Ux2_RZ, Iop_F32ToFixed32Sx2_RZ, /* fp -> fixed-point */
  704. Iop_Fixed32UToF32x2_RN, Iop_Fixed32SToF32x2_RN, /* fixed-point -> fp */
  705. /* Binary operations */
  706. Iop_Max32Fx2, Iop_Min32Fx2,
  707. /* Pairwise Min and Max. See integer pairwise operations for more
  708. details. */
  709. Iop_PwMax32Fx2, Iop_PwMin32Fx2,
  710. /* Note: For the following compares, the arm front-end assumes a
  711. nan in a lane of either argument returns zero for that lane. */
  712. Iop_CmpEQ32Fx2, Iop_CmpGT32Fx2, Iop_CmpGE32Fx2,
  713. /* Vector Reciprocal Estimate finds an approximate reciprocal of each
  714. element in the operand vector, and places the results in the destination
  715. vector. */
  716. Iop_RecipEst32Fx2,
  717. /* Vector Reciprocal Step computes (2.0 - arg1 * arg2).
  718. Note, that if one of the arguments is zero and another one is infinity
  719. of arbitrary sign the result of the operation is 2.0. */
  720. Iop_RecipStep32Fx2,
  721. /* Vector Reciprocal Square Root Estimate finds an approximate reciprocal
  722. square root of each element in the operand vector. */
  723. Iop_RSqrtEst32Fx2,
  724. /* Vector Reciprocal Square Root Step computes (3.0 - arg1 * arg2) / 2.0.
  725. Note, that of one of the arguments is zero and another one is infiinty
  726. of arbitrary sign the result of the operation is 1.5. */
  727. Iop_RSqrtStep32Fx2,
  728. /* Unary */
  729. Iop_Neg32Fx2, Iop_Abs32Fx2,
  730. /* ------------------ 64-bit SIMD Integer. ------------------ */
  731. /* MISC (vector integer cmp != 0) */
  732. Iop_CmpNEZ8x8, Iop_CmpNEZ16x4, Iop_CmpNEZ32x2,
  733. /* ADDITION (normal / unsigned sat / signed sat) */
  734. Iop_Add8x8, Iop_Add16x4, Iop_Add32x2,
  735. Iop_QAdd8Ux8, Iop_QAdd16Ux4, Iop_QAdd32Ux2, Iop_QAdd64Ux1,
  736. Iop_QAdd8Sx8, Iop_QAdd16Sx4, Iop_QAdd32Sx2, Iop_QAdd64Sx1,
  737. /* PAIRWISE operations */
  738. /* Iop_PwFoo16x4( [a,b,c,d], [e,f,g,h] ) =
  739. [Foo16(a,b), Foo16(c,d), Foo16(e,f), Foo16(g,h)] */
  740. Iop_PwAdd8x8, Iop_PwAdd16x4, Iop_PwAdd32x2,
  741. Iop_PwMax8Sx8, Iop_PwMax16Sx4, Iop_PwMax32Sx2,
  742. Iop_PwMax8Ux8, Iop_PwMax16Ux4, Iop_PwMax32Ux2,
  743. Iop_PwMin8Sx8, Iop_PwMin16Sx4, Iop_PwMin32Sx2,
  744. Iop_PwMin8Ux8, Iop_PwMin16Ux4, Iop_PwMin32Ux2,
  745. /* Longening variant is unary. The resulting vector contains two times
  746. less elements than operand, but they are two times wider.
  747. Example:
  748. Iop_PAddL16Ux4( [a,b,c,d] ) = [a+b,c+d]
  749. where a+b and c+d are unsigned 32-bit values. */
  750. Iop_PwAddL8Ux8, Iop_PwAddL16Ux4, Iop_PwAddL32Ux2,
  751. Iop_PwAddL8Sx8, Iop_PwAddL16Sx4, Iop_PwAddL32Sx2,
  752. /* SUBTRACTION (normal / unsigned sat / signed sat) */
  753. Iop_Sub8x8, Iop_Sub16x4, Iop_Sub32x2,
  754. Iop_QSub8Ux8, Iop_QSub16Ux4, Iop_QSub32Ux2, Iop_QSub64Ux1,
  755. Iop_QSub8Sx8, Iop_QSub16Sx4, Iop_QSub32Sx2, Iop_QSub64Sx1,
  756. /* ABSOLUTE VALUE */
  757. Iop_Abs8x8, Iop_Abs16x4, Iop_Abs32x2,
  758. /* MULTIPLICATION (normal / high half of signed/unsigned / plynomial ) */
  759. Iop_Mul8x8, Iop_Mul16x4, Iop_Mul32x2,
  760. Iop_Mul32Fx2,
  761. Iop_MulHi16Ux4,
  762. Iop_MulHi16Sx4,
  763. /* Plynomial multiplication treats it's arguments as coefficients of
  764. polynoms over {0, 1}. */
  765. Iop_PolynomialMul8x8,
  766. /* Vector Saturating Doubling Multiply Returning High Half and
  767. Vector Saturating Rounding Doubling Multiply Returning High Half */
  768. /* These IROp's multiply corresponding elements in two vectors, double
  769. the results, and place the most significant half of the final results
  770. in the destination vector. The results are truncated or rounded. If
  771. any of the results overflow, they are saturated. */
  772. Iop_QDMulHi16Sx4, Iop_QDMulHi32Sx2,
  773. Iop_QRDMulHi16Sx4, Iop_QRDMulHi32Sx2,
  774. /* AVERAGING: note: (arg1 + arg2 + 1) >>u 1 */
  775. Iop_Avg8Ux8,
  776. Iop_Avg16Ux4,
  777. /* MIN/MAX */
  778. Iop_Max8Sx8, Iop_Max16Sx4, Iop_Max32Sx2,
  779. Iop_Max8Ux8, Iop_Max16Ux4, Iop_Max32Ux2,
  780. Iop_Min8Sx8, Iop_Min16Sx4, Iop_Min32Sx2,
  781. Iop_Min8Ux8, Iop_Min16Ux4, Iop_Min32Ux2,
  782. /* COMPARISON */
  783. Iop_CmpEQ8x8, Iop_CmpEQ16x4, Iop_CmpEQ32x2,
  784. Iop_CmpGT8Ux8, Iop_CmpGT16Ux4, Iop_CmpGT32Ux2,
  785. Iop_CmpGT8Sx8, Iop_CmpGT16Sx4, Iop_CmpGT32Sx2,
  786. /* COUNT ones / leading zeroes / leading sign bits (not including topmost
  787. bit) */
  788. Iop_Cnt8x8,
  789. Iop_Clz8x8, Iop_Clz16x4, Iop_Clz32x2,
  790. Iop_Cls8x8, Iop_Cls16x4, Iop_Cls32x2,
  791. Iop_Clz64x2,
  792. /*Vector COUNT trailing zeros */
  793. Iop_Ctz8x16, Iop_Ctz16x8, Iop_Ctz32x4, Iop_Ctz64x2,
  794. /* VECTOR x VECTOR SHIFT / ROTATE */
  795. Iop_Shl8x8, Iop_Shl16x4, Iop_Shl32x2,
  796. Iop_Shr8x8, Iop_Shr16x4, Iop_Shr32x2,
  797. Iop_Sar8x8, Iop_Sar16x4, Iop_Sar32x2,
  798. Iop_Sal8x8, Iop_Sal16x4, Iop_Sal32x2, Iop_Sal64x1,
  799. /* VECTOR x SCALAR SHIFT (shift amt :: Ity_I8) */
  800. Iop_ShlN8x8, Iop_ShlN16x4, Iop_ShlN32x2,
  801. Iop_ShrN8x8, Iop_ShrN16x4, Iop_ShrN32x2,
  802. Iop_SarN8x8, Iop_SarN16x4, Iop_SarN32x2,
  803. /* VECTOR x VECTOR SATURATING SHIFT */
  804. Iop_QShl8x8, Iop_QShl16x4, Iop_QShl32x2, Iop_QShl64x1,
  805. Iop_QSal8x8, Iop_QSal16x4, Iop_QSal32x2, Iop_QSal64x1,
  806. /* VECTOR x INTEGER SATURATING SHIFT */
  807. Iop_QShlNsatSU8x8, Iop_QShlNsatSU16x4,
  808. Iop_QShlNsatSU32x2, Iop_QShlNsatSU64x1,
  809. Iop_QShlNsatUU8x8, Iop_QShlNsatUU16x4,
  810. Iop_QShlNsatUU32x2, Iop_QShlNsatUU64x1,
  811. Iop_QShlNsatSS8x8, Iop_QShlNsatSS16x4,
  812. Iop_QShlNsatSS32x2, Iop_QShlNsatSS64x1,
  813. /* NARROWING (binary)
  814. -- narrow 2xI64 into 1xI64, hi half from left arg */
  815. /* For saturated narrowing, I believe there are 4 variants of
  816. the basic arithmetic operation, depending on the signedness
  817. of argument and result. Here are examples that exemplify
  818. what I mean:
  819. QNarrow16Uto8U ( UShort x ) if (x >u 255) x = 255;
  820. return x[7:0];
  821. QNarrow16Sto8S ( Short x ) if (x <s -128) x = -128;
  822. if (x >s 127) x = 127;
  823. return x[7:0];
  824. QNarrow16Uto8S ( UShort x ) if (x >u 127) x = 127;
  825. return x[7:0];
  826. QNarrow16Sto8U ( Short x ) if (x <s 0) x = 0;
  827. if (x >s 255) x = 255;
  828. return x[7:0];
  829. */
  830. Iop_QNarrowBin16Sto8Ux8,
  831. Iop_QNarrowBin16Sto8Sx8, Iop_QNarrowBin32Sto16Sx4,
  832. Iop_NarrowBin16to8x8, Iop_NarrowBin32to16x4,
  833. /* INTERLEAVING */
  834. /* Interleave lanes from low or high halves of
  835. operands. Most-significant result lane is from the left
  836. arg. */
  837. Iop_InterleaveHI8x8, Iop_InterleaveHI16x4, Iop_InterleaveHI32x2,
  838. Iop_InterleaveLO8x8, Iop_InterleaveLO16x4, Iop_InterleaveLO32x2,
  839. /* Interleave odd/even lanes of operands. Most-significant result lane
  840. is from the left arg. Note that Interleave{Odd,Even}Lanes32x2 are
  841. identical to Interleave{HI,LO}32x2 and so are omitted.*/
  842. Iop_InterleaveOddLanes8x8, Iop_InterleaveEvenLanes8x8,
  843. Iop_InterleaveOddLanes16x4, Iop_InterleaveEvenLanes16x4,
  844. /* CONCATENATION -- build a new value by concatenating either
  845. the even or odd lanes of both operands. Note that
  846. Cat{Odd,Even}Lanes32x2 are identical to Interleave{HI,LO}32x2
  847. and so are omitted. */
  848. Iop_CatOddLanes8x8, Iop_CatOddLanes16x4,
  849. Iop_CatEvenLanes8x8, Iop_CatEvenLanes16x4,
  850. /* GET / SET elements of VECTOR
  851. GET is binop (I64, I8) -> I<elem_size>
  852. SET is triop (I64, I8, I<elem_size>) -> I64 */
  853. /* Note: the arm back-end handles only constant second argument */
  854. Iop_GetElem8x8, Iop_GetElem16x4, Iop_GetElem32x2,
  855. Iop_SetElem8x8, Iop_SetElem16x4, Iop_SetElem32x2,
  856. /* DUPLICATING -- copy value to all lanes */
  857. Iop_Dup8x8, Iop_Dup16x4, Iop_Dup32x2,
  858. /* SLICE -- produces the lowest 64 bits of (arg1:arg2) >> (8 * arg3).
  859. arg3 is a shift amount in bytes and may be between 0 and 8
  860. inclusive. When 0, the result is arg2; when 8, the result is arg1.
  861. Not all back ends handle all values. The arm32 and arm64 back
  862. ends handle only immediate arg3 values. */
  863. Iop_Slice64, // (I64, I64, I8) -> I64
  864. /* REVERSE the order of chunks in vector lanes. Chunks must be
  865. smaller than the vector lanes (obviously) and so may be 8-, 16- and
  866. 32-bit in size. Note that the degenerate case,
  867. Iop_Reverse8sIn64_x1, is a simply a vanilla byte-swap. */
  868. /* Examples:
  869. Reverse8sIn16_x4([a,b,c,d,e,f,g,h]) = [b,a,d,c,f,e,h,g]
  870. Reverse8sIn32_x2([a,b,c,d,e,f,g,h]) = [d,c,b,a,h,g,f,e]
  871. Reverse8sIn64_x1([a,b,c,d,e,f,g,h]) = [h,g,f,e,d,c,b,a] */
  872. Iop_Reverse8sIn16_x4,
  873. Iop_Reverse8sIn32_x2, Iop_Reverse16sIn32_x2,
  874. Iop_Reverse8sIn64_x1, Iop_Reverse16sIn64_x1, Iop_Reverse32sIn64_x1,
  875. /* PERMUTING -- copy src bytes to dst,
  876. as indexed by control vector bytes:
  877. for i in 0 .. 7 . result[i] = argL[ argR[i] ]
  878. argR[i] values may only be in the range 0 .. 7, else behaviour
  879. is undefined. That is, argR[i][7:3] must be zero. */
  880. Iop_Perm8x8,
  881. /* PERMUTING with optional zeroing:
  882. for i in 0 .. 7 . result[i] = if argR[i] bit 7 is set
  883. then zero else argL[ argR[i] ]
  884. argR[i][6:3] must be zero, else behaviour is undefined.
  885. */
  886. Iop_PermOrZero8x8,
  887. /* MISC CONVERSION -- get high bits of each byte lane, a la
  888. x86/amd64 pmovmskb */
  889. Iop_GetMSBs8x8, /* I64 -> I8 */
  890. /* Vector Reciprocal Estimate and Vector Reciprocal Square Root Estimate
  891. See floating-point equivalents for details. */
  892. Iop_RecipEst32Ux2, Iop_RSqrtEst32Ux2,
  893. /* ------------------ Decimal Floating Point ------------------ */
  894. /* ARITHMETIC INSTRUCTIONS 64-bit
  895. ----------------------------------
  896. IRRoundingMode(I32) X D64 X D64 -> D64
  897. */
  898. Iop_AddD64, Iop_SubD64, Iop_MulD64, Iop_DivD64,
  899. /* ARITHMETIC INSTRUCTIONS 128-bit
  900. ----------------------------------
  901. IRRoundingMode(I32) X D128 X D128 -> D128
  902. */
  903. Iop_AddD128, Iop_SubD128, Iop_MulD128, Iop_DivD128,
  904. /* SHIFT SIGNIFICAND INSTRUCTIONS
  905. * The DFP significand is shifted by the number of digits specified
  906. * by the U8 operand. Digits shifted out of the leftmost digit are
  907. * lost. Zeros are supplied to the vacated positions on the right.
  908. * The sign of the result is the same as the sign of the original
  909. * operand.
  910. *
  911. * D64 x U8 -> D64 left shift and right shift respectively */
  912. Iop_ShlD64, Iop_ShrD64,
  913. /* D128 x U8 -> D128 left shift and right shift respectively */
  914. Iop_ShlD128, Iop_ShrD128,
  915. /* FORMAT CONVERSION INSTRUCTIONS
  916. * D32 -> D64
  917. */
  918. Iop_D32toD64,
  919. /* D64 -> D128 */
  920. Iop_D64toD128,
  921. /* I32S -> D128 */
  922. Iop_I32StoD128,
  923. /* I32U -> D128 */
  924. Iop_I32UtoD128,
  925. /* I64S -> D128 */
  926. Iop_I64StoD128,
  927. /* I64U -> D128 */
  928. Iop_I64UtoD128,
  929. /* IRRoundingMode(I32) x D64 -> D32 */
  930. Iop_D64toD32,
  931. /* IRRoundingMode(I32) x D128 -> D64 */
  932. Iop_D128toD64,
  933. /* I32S -> D64 */
  934. Iop_I32StoD64,
  935. /* I32U -> D64 */
  936. Iop_I32UtoD64,
  937. /* IRRoundingMode(I32) x I64 -> D64 */
  938. Iop_I64StoD64,
  939. /* IRRoundingMode(I32) x I64 -> D64 */
  940. Iop_I64UtoD64,
  941. /* IRRoundingMode(I32) x D64 -> I32 */
  942. Iop_D64toI32S,
  943. /* IRRoundingMode(I32) x D64 -> I32 */
  944. Iop_D64toI32U,
  945. /* IRRoundingMode(I32) x D64 -> I64 */
  946. Iop_D64toI64S,
  947. /* IRRoundingMode(I32) x D64 -> I64 */
  948. Iop_D64toI64U,
  949. /* IRRoundingMode(I32) x D128 -> I32 */
  950. Iop_D128toI32S,
  951. /* IRRoundingMode(I32) x D128 -> I32 */
  952. Iop_D128toI32U,
  953. /* IRRoundingMode(I32) x D128 -> I64 */
  954. Iop_D128toI64S,
  955. /* IRRoundingMode(I32) x D128 -> I64 */
  956. Iop_D128toI64U,
  957. /* IRRoundingMode(I32) x F32 -> D32 */
  958. Iop_F32toD32,
  959. /* IRRoundingMode(I32) x F32 -> D64 */
  960. Iop_F32toD64,
  961. /* IRRoundingMode(I32) x F32 -> D128 */
  962. Iop_F32toD128,
  963. /* IRRoundingMode(I32) x F64 -> D32 */
  964. Iop_F64toD32,
  965. /* IRRoundingMode(I32) x F64 -> D64 */
  966. Iop_F64toD64,
  967. /* IRRoundingMode(I32) x F64 -> D128 */
  968. Iop_F64toD128,
  969. /* IRRoundingMode(I32) x F128 -> D32 */
  970. Iop_F128toD32,
  971. /* IRRoundingMode(I32) x F128 -> D64 */
  972. Iop_F128toD64,
  973. /* IRRoundingMode(I32) x F128 -> D128 */
  974. Iop_F128toD128,
  975. /* IRRoundingMode(I32) x D32 -> F32 */
  976. Iop_D32toF32,
  977. /* IRRoundingMode(I32) x D32 -> F64 */
  978. Iop_D32toF64,
  979. /* IRRoundingMode(I32) x D32 -> F128 */
  980. Iop_D32toF128,
  981. /* IRRoundingMode(I32) x D64 -> F32 */
  982. Iop_D64toF32,
  983. /* IRRoundingMode(I32) x D64 -> F64 */
  984. Iop_D64toF64,
  985. /* IRRoundingMode(I32) x D64 -> F128 */
  986. Iop_D64toF128,
  987. /* IRRoundingMode(I32) x D128 -> F32 */
  988. Iop_D128toF32,
  989. /* IRRoundingMode(I32) x D128 -> F64 */
  990. Iop_D128toF64,
  991. /* IRRoundingMode(I32) x D128 -> F128 */
  992. Iop_D128toF128,
  993. /* ROUNDING INSTRUCTIONS
  994. * IRRoundingMode(I32) x D64 -> D64
  995. * The D64 operand, if a finite number, it is rounded to a
  996. * floating point integer value, i.e. no fractional part.
  997. */
  998. Iop_RoundD64toInt,
  999. /* IRRoundingMode(I32) x D128 -> D128 */
  1000. Iop_RoundD128toInt,
  1001. /* COMPARE INSTRUCTIONS
  1002. * D64 x D64 -> IRCmpD64Result(I32) */
  1003. Iop_CmpD64,
  1004. /* D128 x D128 -> IRCmpD128Result(I32) */
  1005. Iop_CmpD128,
  1006. /* COMPARE BIASED EXPONENET INSTRUCTIONS
  1007. * D64 x D64 -> IRCmpD64Result(I32) */
  1008. Iop_CmpExpD64,
  1009. /* D128 x D128 -> IRCmpD128Result(I32) */
  1010. Iop_CmpExpD128,
  1011. /* QUANTIZE AND ROUND INSTRUCTIONS
  1012. * The source operand is converted and rounded to the form with the
  1013. * immediate exponent specified by the rounding and exponent parameter.
  1014. *
  1015. * The second operand is converted and rounded to the form
  1016. * of the first operand's exponent and the rounded based on the specified
  1017. * rounding mode parameter.
  1018. *
  1019. * IRRoundingMode(I32) x D64 x D64-> D64 */
  1020. Iop_QuantizeD64,
  1021. /* IRRoundingMode(I32) x D128 x D128 -> D128 */
  1022. Iop_QuantizeD128,
  1023. /* IRRoundingMode(I32) x I8 x D64 -> D64
  1024. * The Decimal Floating point operand is rounded to the requested
  1025. * significance given by the I8 operand as specified by the rounding
  1026. * mode.
  1027. */
  1028. Iop_SignificanceRoundD64,
  1029. /* IRRoundingMode(I32) x I8 x D128 -> D128 */
  1030. Iop_SignificanceRoundD128,
  1031. /* EXTRACT AND INSERT INSTRUCTIONS
  1032. * D64 -> I64
  1033. * The exponent of the D32 or D64 operand is extracted. The
  1034. * extracted exponent is converted to a 64-bit signed binary integer.
  1035. */
  1036. Iop_ExtractExpD64,
  1037. /* D128 -> I64 */
  1038. Iop_ExtractExpD128,
  1039. /* D64 -> I64
  1040. * The number of significand digits of the D64 operand is extracted.
  1041. * The number is stored as a 64-bit signed binary integer.
  1042. */
  1043. Iop_ExtractSigD64,
  1044. /* D128 -> I64 */
  1045. Iop_ExtractSigD128,
  1046. /* I64 x D64 -> D64
  1047. * The exponent is specified by the first I64 operand the signed
  1048. * significand is given by the second I64 value. The result is a D64
  1049. * value consisting of the specified significand and exponent whose
  1050. * sign is that of the specified significand.
  1051. */
  1052. Iop_InsertExpD64,
  1053. /* I64 x D128 -> D128 */
  1054. Iop_InsertExpD128,
  1055. /* Support for 128-bit DFP type */
  1056. Iop_D64HLtoD128, Iop_D128HItoD64, Iop_D128LOtoD64,
  1057. /* I64 -> I64
  1058. * Convert 50-bit densely packed BCD string to 60 bit BCD string
  1059. */
  1060. Iop_DPBtoBCD,
  1061. /* I64 -> I64
  1062. * Convert 60 bit BCD string to 50-bit densely packed BCD string
  1063. */
  1064. Iop_BCDtoDPB,
  1065. /* BCD arithmetic instructions, (V128, V128) -> V128
  1066. * The BCD format is the same as that used in the BCD<->DPB conversion
  1067. * routines, except using 124 digits (vs 60) plus the trailing 4-bit
  1068. * signed code. */
  1069. Iop_BCDAdd, Iop_BCDSub,
  1070. /* Conversion signed 128-bit integer to signed BCD 128-bit */
  1071. Iop_I128StoBCD128,
  1072. /* Conversion signed BCD 128-bit to 128-bit integer */
  1073. Iop_BCD128toI128S,
  1074. /* Conversion I64 -> D64 */
  1075. Iop_ReinterpI64asD64,
  1076. /* Conversion D64 -> I64 */
  1077. Iop_ReinterpD64asI64,
  1078. /* ------------------ 128-bit SIMD FP. ------------------ */
  1079. /* --- 32x4 vector FP --- */
  1080. /* ternary :: IRRoundingMode(I32) x V128 x V128 -> V128 */
  1081. Iop_Add32Fx4, Iop_Sub32Fx4, Iop_Mul32Fx4, Iop_Div32Fx4,
  1082. /* binary */
  1083. Iop_Max32Fx4, Iop_Min32Fx4,
  1084. Iop_Add32Fx2, Iop_Sub32Fx2,
  1085. /* Note: For the following compares, the ppc and arm front-ends assume a
  1086. nan in a lane of either argument returns zero for that lane. */
  1087. Iop_CmpEQ32Fx4, Iop_CmpLT32Fx4, Iop_CmpLE32Fx4, Iop_CmpUN32Fx4,
  1088. Iop_CmpGT32Fx4, Iop_CmpGE32Fx4,
  1089. /* Pairwise Max and Min. See integer pairwise operations for details. */
  1090. Iop_PwMax32Fx4, Iop_PwMin32Fx4,
  1091. /* unary */
  1092. Iop_Abs32Fx4,
  1093. Iop_Neg32Fx4,
  1094. /* binary :: IRRoundingMode(I32) x V128 -> V128 */
  1095. Iop_Sqrt32Fx4,
  1096. /* Vector Reciprocal Estimate finds an approximate reciprocal of each
  1097. element in the operand vector, and places the results in the
  1098. destination vector. */
  1099. Iop_RecipEst32Fx4,
  1100. /* Vector Reciprocal Step computes (2.0 - arg1 * arg2).
  1101. Note, that if one of the arguments is zero and another one is infinity
  1102. of arbitrary sign the result of the operation is 2.0. */
  1103. Iop_RecipStep32Fx4,
  1104. /* Vector Reciprocal Square Root Estimate finds an approximate reciprocal
  1105. square root of each element in the operand vector. */
  1106. Iop_RSqrtEst32Fx4,
  1107. /* Scaling of vector with a power of 2 (wd[i] <- ws[i] * 2^wt[i]) */
  1108. Iop_Scale2_32Fx4,
  1109. /* Vector floating-point base 2 logarithm */
  1110. Iop_Log2_32Fx4,
  1111. /* Vector Reciprocal Square Root Step computes (3.0 - arg1 * arg2) / 2.0.
  1112. Note, that of one of the arguments is zero and another one is infiinty
  1113. of arbitrary sign the result of the operation is 1.5. */
  1114. Iop_RSqrtStep32Fx4,
  1115. /* --- Int to/from FP conversion --- */
  1116. /* Unlike the standard fp conversions, these irops take no
  1117. rounding mode argument. Instead the irop trailers _R{M,P,N,Z}
  1118. indicate the mode: {-inf, +inf, nearest, zero} respectively. */
  1119. // These carry no rounding mode and are therefore deprecated
  1120. Iop_I32UtoF32x4_DEP, Iop_I32StoF32x4_DEP, /* I32x4 -> F32x4 */
  1121. Iop_I32StoF32x4, /* IRRoundingMode(I32) x V128 -> V128 */
  1122. Iop_F32toI32Sx4, /* IRRoundingMode(I32) x V128 -> V128 */
  1123. Iop_F32toI32Ux4_RZ, Iop_F32toI32Sx4_RZ, /* F32x4 -> I32x4 */
  1124. Iop_QF32toI32Ux4_RZ, Iop_QF32toI32Sx4_RZ, /* F32x4 -> I32x4 (saturating) */
  1125. Iop_RoundF32x4_RM, Iop_RoundF32x4_RP, /* round to fp integer */
  1126. Iop_RoundF32x4_RN, Iop_RoundF32x4_RZ, /* round to fp integer */
  1127. /* Fixed32 format is floating-point number with fixed number of fraction
  1128. bits. The number of fraction bits is passed as a second argument of
  1129. type I8. */
  1130. Iop_F32ToFixed32Ux4_RZ, Iop_F32ToFixed32Sx4_RZ, /* fp -> fixed-point */
  1131. Iop_Fixed32UToF32x4_RN, Iop_Fixed32SToF32x4_RN, /* fixed-point -> fp */
  1132. /* --- Single to/from half conversion --- */
  1133. /* FIXME: what kind of rounding in F32x4 -> F16x4 case? */
  1134. // FIXME these carry no rounding mode
  1135. Iop_F32toF16x4_DEP, /* F32x4(==V128) -> F16x4(==I64), NO ROUNDING MODE */
  1136. Iop_F32toF16x4, /* IRRoundingMode(I32) x V128 -> I64 */
  1137. Iop_F16toF32x4, /* F16x4 -> F32x4 */
  1138. /* -- Double to/from half conversion -- */
  1139. Iop_F64toF16x2_DEP, // F64x2 -> F16x2, NO ROUNDING MODE
  1140. Iop_F16toF64x2,
  1141. /* Values from two registers converted in smaller type and put in one
  1142. IRRoundingMode(I32) x (F32x4 | F32x4) -> Q16x8 */
  1143. Iop_F32x4_2toQ16x8,
  1144. /* --- 32x4 lowest-lane-only scalar FP --- */
  1145. /* In binary cases, upper 3/4 is copied from first operand. In
  1146. unary cases, upper 3/4 is copied from the operand. */
  1147. /* binary */
  1148. Iop_Add32F0x4, Iop_Sub32F0x4, Iop_Mul32F0x4, Iop_Div32F0x4,
  1149. Iop_Max32F0x4, Iop_Min32F0x4,
  1150. Iop_CmpEQ32F0x4, Iop_CmpLT32F0x4, Iop_CmpLE32F0x4, Iop_CmpUN32F0x4,
  1151. /* unary */
  1152. Iop_RecipEst32F0x4, Iop_Sqrt32F0x4, Iop_RSqrtEst32F0x4,
  1153. /* --- 64x2 vector FP --- */
  1154. /* ternary :: IRRoundingMode(I32) x V128 x V128 -> V128 */
  1155. Iop_Add64Fx2, Iop_Sub64Fx2, Iop_Mul64Fx2, Iop_Div64Fx2,
  1156. /* binary */
  1157. Iop_Max64Fx2, Iop_Min64Fx2,
  1158. Iop_CmpEQ64Fx2, Iop_CmpLT64Fx2, Iop_CmpLE64Fx2, Iop_CmpUN64Fx2,
  1159. /* unary */
  1160. Iop_Abs64Fx2,
  1161. Iop_Neg64Fx2,
  1162. /* binary :: IRRoundingMode(I32) x V128 -> V128 */
  1163. Iop_Sqrt64Fx2,
  1164. /* Scaling of vector with a power of 2 (wd[i] <- ws[i] * 2^wt[i]) */
  1165. Iop_Scale2_64Fx2,
  1166. /* Vector floating-point base 2 logarithm */
  1167. Iop_Log2_64Fx2,
  1168. /* see 32Fx4 variants for description */
  1169. Iop_RecipEst64Fx2, // unary
  1170. Iop_RecipStep64Fx2, // binary
  1171. Iop_RSqrtEst64Fx2, // unary
  1172. Iop_RSqrtStep64Fx2, // binary
  1173. /* Values from two registers converted in smaller type and put in one
  1174. IRRoundingMode(I32) x (F64x2 | F64x2) -> Q32x4 */
  1175. Iop_F64x2_2toQ32x4,
  1176. /* --- 64x2 lowest-lane-only scalar FP --- */
  1177. /* In binary cases, upper half is copied from first operand. In
  1178. unary cases, upper half is copied from the operand. */
  1179. /* binary */
  1180. Iop_Add64F0x2, Iop_Sub64F0x2, Iop_Mul64F0x2, Iop_Div64F0x2,
  1181. Iop_Max64F0x2, Iop_Min64F0x2,
  1182. Iop_CmpEQ64F0x2, Iop_CmpLT64F0x2, Iop_CmpLE64F0x2, Iop_CmpUN64F0x2,
  1183. /* unary */
  1184. Iop_Sqrt64F0x2,
  1185. /* --- pack / unpack --- */
  1186. /* 64 <-> 128 bit vector */
  1187. Iop_V128to64, // :: V128 -> I64, low half
  1188. Iop_V128HIto64, // :: V128 -> I64, high half
  1189. Iop_64HLtoV128, // :: (I64,I64) -> V128
  1190. Iop_64UtoV128,
  1191. Iop_SetV128lo64,
  1192. /* Copies lower 64/32/16/8 bits, zeroes out the rest. */
  1193. Iop_ZeroHI64ofV128, // :: V128 -> V128
  1194. Iop_ZeroHI96ofV128, // :: V128 -> V128
  1195. Iop_ZeroHI112ofV128, // :: V128 -> V128
  1196. Iop_ZeroHI120ofV128, // :: V128 -> V128
  1197. /* 32 <-> 128 bit vector */
  1198. Iop_32UtoV128,
  1199. Iop_V128to32, // :: V128 -> I32, lowest lane
  1200. Iop_SetV128lo32, // :: (V128,I32) -> V128
  1201. /* ------------------ 128-bit SIMD Integer. ------------------ */
  1202. /* BITWISE OPS */
  1203. Iop_NotV128,
  1204. Iop_AndV128, Iop_OrV128, Iop_XorV128,
  1205. /* VECTOR SHIFT (shift amt :: Ity_I8) */
  1206. Iop_ShlV128, Iop_ShrV128, Iop_SarV128,
  1207. /* MISC (vector integer cmp != 0) */
  1208. Iop_CmpNEZ8x16, Iop_CmpNEZ16x8, Iop_CmpNEZ32x4, Iop_CmpNEZ64x2,
  1209. Iop_CmpNEZ128x1,
  1210. /* ADDITION (normal / U->U sat / S->S sat) */
  1211. Iop_Add8x16, Iop_Add16x8, Iop_Add32x4, Iop_Add64x2, Iop_Add128x1,
  1212. Iop_QAdd8Ux16, Iop_QAdd16Ux8, Iop_QAdd32Ux4, Iop_QAdd64Ux2,
  1213. Iop_QAdd8Sx16, Iop_QAdd16Sx8, Iop_QAdd32Sx4, Iop_QAdd64Sx2,
  1214. /* ADDITION, ARM64 specific saturating variants. */
  1215. /* Unsigned widen left arg, signed widen right arg, add, saturate S->S.
  1216. This corresponds to SUQADD. */
  1217. Iop_QAddExtUSsatSS8x16, Iop_QAddExtUSsatSS16x8,
  1218. Iop_QAddExtUSsatSS32x4, Iop_QAddExtUSsatSS64x2,
  1219. /* Signed widen left arg, unsigned widen right arg, add, saturate U->U.
  1220. This corresponds to USQADD. */
  1221. Iop_QAddExtSUsatUU8x16, Iop_QAddExtSUsatUU16x8,
  1222. Iop_QAddExtSUsatUU32x4, Iop_QAddExtSUsatUU64x2,
  1223. /* SUBTRACTION (normal / unsigned sat / signed sat) */
  1224. Iop_Sub8x16, Iop_Sub16x8, Iop_Sub32x4, Iop_Sub64x2, Iop_Sub128x1,
  1225. Iop_QSub8Ux16, Iop_QSub16Ux8, Iop_QSub32Ux4, Iop_QSub64Ux2,
  1226. Iop_QSub8Sx16, Iop_QSub16Sx8, Iop_QSub32Sx4, Iop_QSub64Sx2,
  1227. /* MULTIPLICATION (normal / high half of signed/unsigned) */
  1228. Iop_Mul8x16, Iop_Mul16x8, Iop_Mul32x4,
  1229. Iop_MulHi8Ux16, Iop_MulHi16Ux8, Iop_MulHi32Ux4,
  1230. Iop_MulHi8Sx16, Iop_MulHi16Sx8, Iop_MulHi32Sx4,
  1231. /* (widening signed/unsigned of even lanes, with lowest lane=zero) */
  1232. Iop_MullEven8Ux16, Iop_MullEven16Ux8, Iop_MullEven32Ux4,
  1233. Iop_MullEven8Sx16, Iop_MullEven16Sx8, Iop_MullEven32Sx4,
  1234. /* Widening multiplies, all of the form (I64, I64) -> V128 */
  1235. Iop_Mull8Ux8, Iop_Mull8Sx8,
  1236. Iop_Mull16Ux4, Iop_Mull16Sx4,
  1237. Iop_Mull32Ux2, Iop_Mull32Sx2,
  1238. /* Signed doubling saturating widening multiplies, (I64, I64) -> V128 */
  1239. Iop_QDMull16Sx4, Iop_QDMull32Sx2,
  1240. /* Vector Saturating Doubling Multiply Returning High Half and
  1241. Vector Saturating Rounding Doubling Multiply Returning High Half.
  1242. These IROps multiply corresponding elements in two vectors, double
  1243. the results, and place the most significant half of the final results
  1244. in the destination vector. The results are truncated or rounded. If
  1245. any of the results overflow, they are saturated. To be more precise,
  1246. for each lane, the computed result is:
  1247. QDMulHi:
  1248. hi-half( sign-extend(laneL) *q sign-extend(laneR) *q 2 )
  1249. QRDMulHi:
  1250. hi-half( sign-extend(laneL) *q sign-extend(laneR) *q 2
  1251. +q (1 << (lane-width-in-bits - 1)) )
  1252. */
  1253. Iop_QDMulHi16Sx8, Iop_QDMulHi32Sx4, /* (V128, V128) -> V128 */
  1254. Iop_QRDMulHi16Sx8, Iop_QRDMulHi32Sx4, /* (V128, V128) -> V128 */
  1255. /* Polynomial multiplication treats its arguments as
  1256. coefficients of polynomials over {0, 1}. */
  1257. Iop_PolynomialMul8x16, /* (V128, V128) -> V128 */
  1258. Iop_PolynomialMull8x8, /* (I64, I64) -> V128 */
  1259. /* Vector Polynomial multiplication add. (V128, V128) -> V128
  1260. *** Below is the algorithm for the instructions. These Iops could
  1261. be emulated to get this functionality, but the emulation would
  1262. be long and messy.
  1263. Example for polynomial multiply add for vector of bytes
  1264. do i = 0 to 15
  1265. prod[i].bit[0:14] <- 0
  1266. srcA <- VR[argL].byte[i]
  1267. srcB <- VR[argR].byte[i]
  1268. do j = 0 to 7
  1269. do k = 0 to j
  1270. gbit <- srcA.bit[k] & srcB.bit[j-k]
  1271. prod[i].bit[j] <- prod[i].bit[j] ^ gbit
  1272. end
  1273. end
  1274. do j = 8 to 14
  1275. do k = j-7 to 7
  1276. gbit <- (srcA.bit[k] & srcB.bit[j-k])
  1277. prod[i].bit[j] <- prod[i].bit[j] ^ gbit
  1278. end
  1279. end
  1280. end
  1281. do i = 0 to 7
  1282. VR[dst].hword[i] <- 0b0 || (prod[2×i] ^ prod[2×i+1])
  1283. end
  1284. */
  1285. Iop_PolynomialMulAdd8x16, Iop_PolynomialMulAdd16x8,
  1286. Iop_PolynomialMulAdd32x4, Iop_PolynomialMulAdd64x2,
  1287. /* PAIRWISE operations */
  1288. /* Iop_PwFoo16x4( [a,b,c,d], [e,f,g,h] ) =
  1289. [Foo16(a,b), Foo16(c,d), Foo16(e,f), Foo16(g,h)] */
  1290. Iop_PwAdd8x16, Iop_PwAdd16x8, Iop_PwAdd32x4,
  1291. Iop_PwAdd32Fx2,
  1292. /* Longening variant is unary. The resulting vector contains two times
  1293. less elements than operand, but they are two times wider.
  1294. Example:
  1295. Iop_PwAddL16Ux4( [a,b,c,d] ) = [a+b,c+d]
  1296. where a+b and c+d are unsigned 32-bit values. */
  1297. Iop_PwAddL8Ux16, Iop_PwAddL16Ux8, Iop_PwAddL32Ux4, Iop_PwAddL64Ux2,
  1298. Iop_PwAddL8Sx16, Iop_PwAddL16Sx8, Iop_PwAddL32Sx4,
  1299. /* This is amd64 PMADDUBSW, (V128, V128) -> V128. For each adjacent pair
  1300. of bytes [a,b] in the first arg and [c,d] in the second, computes:
  1301. signed/signed sat to 16 bits ( zxTo16(a) * sxTo16(b)
  1302. + zxTo16(c) * sxTo16(d) )
  1303. This exists because it's frequently used and there's no reasonably
  1304. concise way to express it using other IROps.
  1305. */
  1306. Iop_PwExtUSMulQAdd8x16,
  1307. /* Other unary pairwise ops */
  1308. /* Vector bit matrix transpose. (V128) -> V128 */
  1309. /* For each doubleword element of the source vector, an 8-bit x 8-bit
  1310. * matrix transpose is performed. */
  1311. Iop_PwBitMtxXpose64x2,
  1312. /* ABSOLUTE VALUE */
  1313. Iop_Abs8x16, Iop_Abs16x8, Iop_Abs32x4, Iop_Abs64x2,
  1314. /* AVERAGING: note: (arg1 + arg2 + 1) >>u 1 */
  1315. Iop_Avg8Ux16, Iop_Avg16Ux8, Iop_Avg32Ux4, Iop_Avg64Ux2,
  1316. Iop_Avg8Sx16, Iop_Avg16Sx8, Iop_Avg32Sx4, Iop_Avg64Sx2,
  1317. /* MIN/MAX */
  1318. Iop_Max8Sx16, Iop_Max16Sx8, Iop_Max32Sx4, Iop_Max64Sx2,
  1319. Iop_Max8Ux16, Iop_Max16Ux8, Iop_Max32Ux4, Iop_Max64Ux2,
  1320. Iop_Min8Sx16, Iop_Min16Sx8, Iop_Min32Sx4, Iop_Min64Sx2,
  1321. Iop_Min8Ux16, Iop_Min16Ux8, Iop_Min32Ux4, Iop_Min64Ux2,
  1322. /* COMPARISON */
  1323. Iop_CmpEQ8x16, Iop_CmpEQ16x8, Iop_CmpEQ32x4, Iop_CmpEQ64x2,
  1324. Iop_CmpGT8Sx16, Iop_CmpGT16Sx8, Iop_CmpGT32Sx4, Iop_CmpGT64Sx2,
  1325. Iop_CmpGT8Ux16, Iop_CmpGT16Ux8, Iop_CmpGT32Ux4, Iop_CmpGT64Ux2,
  1326. /* COUNT ones / leading zeroes / leading sign bits (not including topmost
  1327. bit) */
  1328. Iop_Cnt8x16,
  1329. Iop_Clz8x16, Iop_Clz16x8, Iop_Clz32x4,
  1330. Iop_Cls8x16, Iop_Cls16x8, Iop_Cls32x4,
  1331. /* VECTOR x SCALAR SHIFT (shift amt :: Ity_I8) */
  1332. Iop_ShlN8x16, Iop_ShlN16x8, Iop_ShlN32x4, Iop_ShlN64x2,
  1333. Iop_ShrN8x16, Iop_ShrN16x8, Iop_ShrN32x4, Iop_ShrN64x2,
  1334. Iop_SarN8x16, Iop_SarN16x8, Iop_SarN32x4, Iop_SarN64x2,
  1335. /* VECTOR x VECTOR SHIFT / ROTATE */
  1336. /* FIXME: I'm pretty sure the ARM32 front/back ends interpret these
  1337. differently from all other targets. The intention is that
  1338. the shift amount (2nd arg) is interpreted as unsigned and
  1339. only the lowest log2(lane-bits) bits are relevant. But the
  1340. ARM32 versions treat the shift amount as an 8 bit signed
  1341. number. The ARM32 uses should be replaced by the relevant
  1342. vector x vector bidirectional shifts instead. */
  1343. Iop_Shl8x16, Iop_Shl16x8, Iop_Shl32x4, Iop_Shl64x2,
  1344. Iop_Shr8x16, Iop_Shr16x8, Iop_Shr32x4, Iop_Shr64x2,
  1345. Iop_Sar8x16, Iop_Sar16x8, Iop_Sar32x4, Iop_Sar64x2,
  1346. Iop_Sal8x16, Iop_Sal16x8, Iop_Sal32x4, Iop_Sal64x2,
  1347. Iop_Rol8x16, Iop_Rol16x8, Iop_Rol32x4, Iop_Rol64x2,
  1348. /* VECTOR x VECTOR SATURATING SHIFT */
  1349. Iop_QShl8x16, Iop_QShl16x8, Iop_QShl32x4, Iop_QShl64x2,
  1350. Iop_QSal8x16, Iop_QSal16x8, Iop_QSal32x4, Iop_QSal64x2,
  1351. /* VECTOR x INTEGER SATURATING SHIFT */
  1352. Iop_QShlNsatSU8x16, Iop_QShlNsatSU16x8,
  1353. Iop_QShlNsatSU32x4, Iop_QShlNsatSU64x2,
  1354. Iop_QShlNsatUU8x16, Iop_QShlNsatUU16x8,
  1355. Iop_QShlNsatUU32x4, Iop_QShlNsatUU64x2,
  1356. Iop_QShlNsatSS8x16, Iop_QShlNsatSS16x8,
  1357. Iop_QShlNsatSS32x4, Iop_QShlNsatSS64x2,
  1358. /* VECTOR x VECTOR BIDIRECTIONAL SATURATING (& MAYBE ROUNDING) SHIFT */
  1359. /* All of type (V128, V128) -> V256. */
  1360. /* The least significant 8 bits of each lane of the second
  1361. operand are used as the shift amount, and interpreted signedly.
  1362. Positive values mean a shift left, negative a shift right. The
  1363. result is signedly or unsignedly saturated. There are also
  1364. rounding variants, which add 2^(shift_amount-1) to the value before
  1365. shifting, but only in the shift-right case. Vacated positions
  1366. are filled with zeroes. IOW, it's either SHR or SHL, but not SAR.
  1367. These operations return 129 bits: one bit ("Q") indicating whether
  1368. saturation occurred, and the shift result. The result type is V256,
  1369. of which the lower V128 is the shift result, and Q occupies the
  1370. least significant bit of the upper V128. All other bits of the
  1371. upper V128 are zero. */
  1372. // Unsigned saturation, no rounding
  1373. Iop_QandUQsh8x16, Iop_QandUQsh16x8,
  1374. Iop_QandUQsh32x4, Iop_QandUQsh64x2,
  1375. // Signed saturation, no rounding
  1376. Iop_QandSQsh8x16, Iop_QandSQsh16x8,
  1377. Iop_QandSQsh32x4, Iop_QandSQsh64x2,
  1378. // Unsigned saturation, rounding
  1379. Iop_QandUQRsh8x16, Iop_QandUQRsh16x8,
  1380. Iop_QandUQRsh32x4, Iop_QandUQRsh64x2,
  1381. // Signed saturation, rounding
  1382. Iop_QandSQRsh8x16, Iop_QandSQRsh16x8,
  1383. Iop_QandSQRsh32x4, Iop_QandSQRsh64x2,
  1384. /* VECTOR x VECTOR BIDIRECTIONAL (& MAYBE ROUNDING) SHIFT */
  1385. /* All of type (V128, V128) -> V128 */
  1386. /* The least significant 8 bits of each lane of the second
  1387. operand are used as the shift amount, and interpreted signedly.
  1388. Positive values mean a shift left, negative a shift right.
  1389. There are also rounding variants, which add 2^(shift_amount-1)
  1390. to the value before shifting, but only in the shift-right case.
  1391. For left shifts, the vacated places are filled with zeroes.
  1392. For right shifts, the vacated places are filled with zeroes
  1393. for the U variants and sign bits for the S variants. */
  1394. // Signed and unsigned, non-rounding
  1395. Iop_Sh8Sx16, Iop_Sh16Sx8, Iop_Sh32Sx4, Iop_Sh64Sx2,
  1396. Iop_Sh8Ux16, Iop_Sh16Ux8, Iop_Sh32Ux4, Iop_Sh64Ux2,
  1397. // Signed and unsigned, rounding
  1398. Iop_Rsh8Sx16, Iop_Rsh16Sx8, Iop_Rsh32Sx4, Iop_Rsh64Sx2,
  1399. Iop_Rsh8Ux16, Iop_Rsh16Ux8, Iop_Rsh32Ux4, Iop_Rsh64Ux2,
  1400. /* The least significant 8 bits of each lane of the second
  1401. operand are used as the shift amount, and interpreted signedly.
  1402. Positive values mean a shift left, negative a shift right. The
  1403. result is signedly or unsignedly saturated. There are also
  1404. rounding variants, which add 2^(shift_amount-1) to the value before
  1405. shifting, but only in the shift-right case. Vacated positions
  1406. are filled with zeroes. IOW, it's either SHR or SHL, but not SAR.
  1407. */
  1408. /* VECTOR x SCALAR SATURATING (& MAYBE ROUNDING) NARROWING SHIFT RIGHT */
  1409. /* All of type (V128, I8) -> V128 */
  1410. /* The first argument is shifted right, then narrowed to half the width
  1411. by saturating it. The second argument is a scalar shift amount that
  1412. applies to all lanes, and must be a value in the range 1 to lane_width.
  1413. The shift may be done signedly (Sar variants) or unsignedly (Shr
  1414. variants). The saturation is done according to the two signedness
  1415. indicators at the end of the name. For example 64Sto32U means a
  1416. signed 64 bit value is saturated into an unsigned 32 bit value.
  1417. Additionally, the QRS variants do rounding, that is, they add the
  1418. value (1 << (shift_amount-1)) to each source lane before shifting.
  1419. These operations return 65 bits: one bit ("Q") indicating whether
  1420. saturation occurred, and the shift result. The result type is V128,
  1421. of which the lower half is the shift result, and Q occupies the
  1422. least significant bit of the upper half. All other bits of the
  1423. upper half are zero. */
  1424. // No rounding, sat U->U
  1425. Iop_QandQShrNnarrow16Uto8Ux8,
  1426. Iop_QandQShrNnarrow32Uto16Ux4, Iop_QandQShrNnarrow64Uto32Ux2,
  1427. // No rounding, sat S->S
  1428. Iop_QandQSarNnarrow16Sto8Sx8,
  1429. Iop_QandQSarNnarrow32Sto16Sx4, Iop_QandQSarNnarrow64Sto32Sx2,
  1430. // No rounding, sat S->U
  1431. Iop_QandQSarNnarrow16Sto8Ux8,
  1432. Iop_QandQSarNnarrow32Sto16Ux4, Iop_QandQSarNnarrow64Sto32Ux2,
  1433. // Rounding, sat U->U
  1434. Iop_QandQRShrNnarrow16Uto8Ux8,
  1435. Iop_QandQRShrNnarrow32Uto16Ux4, Iop_QandQRShrNnarrow64Uto32Ux2,
  1436. // Rounding, sat S->S
  1437. Iop_QandQRSarNnarrow16Sto8Sx8,
  1438. Iop_QandQRSarNnarrow32Sto16Sx4, Iop_QandQRSarNnarrow64Sto32Sx2,
  1439. // Rounding, sat S->U
  1440. Iop_QandQRSarNnarrow16Sto8Ux8,
  1441. Iop_QandQRSarNnarrow32Sto16Ux4, Iop_QandQRSarNnarrow64Sto32Ux2,
  1442. /* NARROWING (binary)
  1443. -- narrow 2xV128 into 1xV128, hi half from left arg */
  1444. /* See comments above w.r.t. U vs S issues in saturated narrowing. */
  1445. Iop_QNarrowBin16Sto8Ux16, Iop_QNarrowBin32Sto16Ux8,
  1446. Iop_QNarrowBin16Sto8Sx16, Iop_QNarrowBin32Sto16Sx8,
  1447. Iop_QNarrowBin16Uto8Ux16, Iop_QNarrowBin32Uto16Ux8,
  1448. Iop_NarrowBin16to8x16, Iop_NarrowBin32to16x8,
  1449. Iop_QNarrowBin64Sto32Sx4, Iop_QNarrowBin64Uto32Ux4,
  1450. Iop_NarrowBin64to32x4,
  1451. /* NARROWING (unary) -- narrow V128 into I64 */
  1452. Iop_NarrowUn16to8x8, Iop_NarrowUn32to16x4, Iop_NarrowUn64to32x2,
  1453. /* Saturating narrowing from signed source to signed/unsigned
  1454. destination */
  1455. Iop_QNarrowUn16Sto8Sx8, Iop_QNarrowUn32Sto16Sx4, Iop_QNarrowUn64Sto32Sx2,
  1456. Iop_QNarrowUn16Sto8Ux8, Iop_QNarrowUn32Sto16Ux4, Iop_QNarrowUn64Sto32Ux2,
  1457. /* Saturating narrowing from unsigned source to unsigned destination */
  1458. Iop_QNarrowUn16Uto8Ux8, Iop_QNarrowUn32Uto16Ux4, Iop_QNarrowUn64Uto32Ux2,
  1459. /* WIDENING -- sign or zero extend each element of the argument
  1460. vector to the twice original size. The resulting vector consists of
  1461. the same number of elements but each element and the vector itself
  1462. are twice as wide.
  1463. All operations are I64->V128.
  1464. Example
  1465. Iop_Widen32Sto64x2( [a, b] ) = [c, d]
  1466. where c = Iop_32Sto64(a) and d = Iop_32Sto64(b) */
  1467. Iop_Widen8Uto16x8, Iop_Widen16Uto32x4, Iop_Widen32Uto64x2,
  1468. Iop_Widen8Sto16x8, Iop_Widen16Sto32x4, Iop_Widen32Sto64x2,
  1469. /* INTERLEAVING */
  1470. /* Interleave lanes from low or high halves of
  1471. operands. Most-significant result lane is from the left
  1472. arg. */
  1473. Iop_InterleaveHI8x16, Iop_InterleaveHI16x8,
  1474. Iop_InterleaveHI32x4, Iop_InterleaveHI64x2,
  1475. Iop_InterleaveLO8x16, Iop_InterleaveLO16x8,
  1476. Iop_InterleaveLO32x4, Iop_InterleaveLO64x2,
  1477. /* Interleave odd/even lanes of operands. Most-significant result lane
  1478. is from the left arg. */
  1479. Iop_InterleaveOddLanes8x16, Iop_InterleaveEvenLanes8x16,
  1480. Iop_InterleaveOddLanes16x8, Iop_InterleaveEvenLanes16x8,
  1481. Iop_InterleaveOddLanes32x4, Iop_InterleaveEvenLanes32x4,
  1482. /* Pack even/odd lanes. */
  1483. Iop_PackOddLanes8x16, Iop_PackEvenLanes8x16,
  1484. Iop_PackOddLanes16x8, Iop_PackEvenLanes16x8,
  1485. Iop_PackOddLanes32x4, Iop_PackEvenLanes32x4,
  1486. /* CONCATENATION -- build a new value by concatenating either
  1487. the even or odd lanes of both operands. Note that
  1488. Cat{Odd,Even}Lanes64x2 are identical to Interleave{HI,LO}64x2
  1489. and so are omitted. */
  1490. Iop_CatOddLanes8x16, Iop_CatOddLanes16x8, Iop_CatOddLanes32x4,
  1491. Iop_CatEvenLanes8x16, Iop_CatEvenLanes16x8, Iop_CatEvenLanes32x4,
  1492. /* GET elements of VECTOR
  1493. GET is binop (V128, I8) -> I<elem_size>
  1494. SET is triop (V128, I8, I<elem_size>) -> V128 */
  1495. /* Note: the arm back-end handles only constant second argument. */
  1496. Iop_GetElem8x16, Iop_GetElem16x8, Iop_GetElem32x4, Iop_GetElem64x2,
  1497. Iop_SetElem8x16, Iop_SetElem16x8, Iop_SetElem32x4, Iop_SetElem64x2,
  1498. /* DUPLICATING -- copy value to all lanes */
  1499. Iop_Dup8x16, Iop_Dup16x8, Iop_Dup32x4,
  1500. /* SLICE -- produces the lowest 128 bits of (arg1:arg2) >> (8 * arg3).
  1501. arg3 is a shift amount in bytes and may be between 0 and 16
  1502. inclusive. When 0, the result is arg2; when 16, the result is arg1.
  1503. Not all back ends handle all values. The arm64 back
  1504. end handles only immediate arg3 values. */
  1505. Iop_SliceV128, // (V128, V128, I8) -> V128
  1506. /* REVERSE the order of chunks in vector lanes. Chunks must be
  1507. smaller than the vector lanes (obviously) and so may be 8-,
  1508. 16- and 32-bit in size. See definitions of 64-bit SIMD
  1509. versions above for examples. */
  1510. Iop_Reverse8sIn16_x8,
  1511. Iop_Reverse8sIn32_x4, Iop_Reverse16sIn32_x4,
  1512. Iop_Reverse8sIn64_x2, Iop_Reverse16sIn64_x2, Iop_Reverse32sIn64_x2,
  1513. Iop_Reverse1sIn8_x16, /* Reverse bits in each byte lane. */
  1514. /* PERMUTING -- copy src bytes to dst,
  1515. as indexed by control vector bytes:
  1516. for i in 0 .. 15 . result[i] = argL[ argR[i] ]
  1517. argR[i] values may only be in the range 0 .. 15, else behaviour
  1518. is undefined. That is, argR[i][7:4] must be zero. */
  1519. Iop_Perm8x16,
  1520. Iop_Perm32x4, /* ditto, except argR values are restricted to 0 .. 3 */
  1521. /* PERMUTING with optional zeroing:
  1522. for i in 0 .. 15 . result[i] = if argR[i] bit 7 is set
  1523. then zero else argL[ argR[i] ]
  1524. argR[i][6:4] must be zero, else behaviour is undefined.
  1525. */
  1526. Iop_PermOrZero8x16,
  1527. /* same, but Triop (argL consists of two 128-bit parts) */
  1528. /* correct range for argR values is 0..31 */
  1529. /* (V128, V128, V128) -> V128 */
  1530. /* (ArgL_first, ArgL_second, ArgR) -> result */
  1531. Iop_Perm8x16x2,
  1532. /* MISC CONVERSION -- get high bits of each byte lane, a la
  1533. x86/amd64 pmovmskb */
  1534. Iop_GetMSBs8x16, /* V128 -> I16 */
  1535. /* Vector Reciprocal Estimate and Vector Reciprocal Square Root Estimate
  1536. See floating-point equivalents for details. */
  1537. Iop_RecipEst32Ux4, Iop_RSqrtEst32Ux4,
  1538. /* 128-bit multipy by 10 instruction, result is lower 128-bits */
  1539. Iop_MulI128by10,
  1540. /* 128-bit multipy by 10 instruction, result is carry out from the MSB */
  1541. Iop_MulI128by10Carry,
  1542. /* 128-bit multipy by 10 instruction, result is lower 128-bits of the
  1543. * source times 10 plus the carry in
  1544. */
  1545. Iop_MulI128by10E,
  1546. /* 128-bit multipy by 10 instruction, result is carry out from the MSB
  1547. * of the source times 10 plus the carry in
  1548. */
  1549. Iop_MulI128by10ECarry,
  1550. /* ------------------ 256-bit SIMD Integer. ------------------ */
  1551. /* Pack/unpack */
  1552. Iop_V256to64_0, // V256 -> I64, extract least significant lane
  1553. Iop_V256to64_1,
  1554. Iop_V256to64_2,
  1555. Iop_V256to64_3, // V256 -> I64, extract most significant lane
  1556. Iop_64x4toV256, // (I64,I64,I64,I64)->V256
  1557. // first arg is most significant lane
  1558. Iop_V256toV128_0, // V256 -> V128, less significant lane
  1559. Iop_V256toV128_1, // V256 -> V128, more significant lane
  1560. Iop_V128HLtoV256, // (V128,V128)->V256, first arg is most signif
  1561. Iop_AndV256,
  1562. Iop_OrV256,
  1563. Iop_XorV256,
  1564. Iop_NotV256,
  1565. /* MISC (vector integer cmp != 0) */
  1566. Iop_CmpNEZ8x32, Iop_CmpNEZ16x16, Iop_CmpNEZ32x8, Iop_CmpNEZ64x4,
  1567. Iop_Add8x32, Iop_Add16x16, Iop_Add32x8, Iop_Add64x4,
  1568. Iop_Sub8x32, Iop_Sub16x16, Iop_Sub32x8, Iop_Sub64x4,
  1569. Iop_CmpEQ8x32, Iop_CmpEQ16x16, Iop_CmpEQ32x8, Iop_CmpEQ64x4,
  1570. Iop_CmpGT8Sx32, Iop_CmpGT16Sx16, Iop_CmpGT32Sx8, Iop_CmpGT64Sx4,
  1571. Iop_ShlN16x16, Iop_ShlN32x8, Iop_ShlN64x4,
  1572. Iop_ShrN16x16, Iop_ShrN32x8, Iop_ShrN64x4,
  1573. Iop_SarN16x16, Iop_SarN32x8,
  1574. Iop_Max8Sx32, Iop_Max16Sx16, Iop_Max32Sx8,
  1575. Iop_Max8Ux32, Iop_Max16Ux16, Iop_Max32Ux8,
  1576. Iop_Min8Sx32, Iop_Min16Sx16, Iop_Min32Sx8,
  1577. Iop_Min8Ux32, Iop_Min16Ux16, Iop_Min32Ux8,
  1578. Iop_Mul16x16, Iop_Mul32x8,
  1579. Iop_MulHi16Ux16, Iop_MulHi16Sx16,
  1580. Iop_QAdd8Ux32, Iop_QAdd16Ux16,
  1581. Iop_QAdd8Sx32, Iop_QAdd16Sx16,
  1582. Iop_QSub8Ux32, Iop_QSub16Ux16,
  1583. Iop_QSub8Sx32, Iop_QSub16Sx16,
  1584. Iop_Avg8Ux32, Iop_Avg16Ux16,
  1585. Iop_Perm32x8,
  1586. /* (V128, V128) -> V128 */
  1587. Iop_CipherV128, Iop_CipherLV128, Iop_CipherSV128,
  1588. Iop_NCipherV128, Iop_NCipherLV128,
  1589. /* Hash instructions, Federal Information Processing Standards
  1590. * Publication 180-3 Secure Hash Standard. */
  1591. /* (V128, I8) -> V128; The I8 input arg is (ST | SIX), where ST and
  1592. * SIX are fields from the insn. See ISA 2.07 description of
  1593. * vshasigmad and vshasigmaw insns.*/
  1594. Iop_SHA512, Iop_SHA256,
  1595. /* ------------------ 256-bit SIMD FP. ------------------ */
  1596. /* ternary :: IRRoundingMode(I32) x V256 x V256 -> V256 */
  1597. Iop_Add64Fx4, Iop_Sub64Fx4, Iop_Mul64Fx4, Iop_Div64Fx4,
  1598. Iop_Add32Fx8, Iop_Sub32Fx8, Iop_Mul32Fx8, Iop_Div32Fx8,
  1599. Iop_I32StoF32x8, /* IRRoundingMode(I32) x V256 -> V256 */
  1600. Iop_F32toI32Sx8, /* IRRoundingMode(I32) x V256 -> V256 */
  1601. Iop_F32toF16x8, /* IRRoundingMode(I32) x V256 -> V128 */
  1602. Iop_F16toF32x8, /* F16x8(==V128) -> F32x8(==V256) */
  1603. Iop_Sqrt32Fx8,
  1604. Iop_Sqrt64Fx4,
  1605. Iop_RSqrtEst32Fx8,
  1606. Iop_RecipEst32Fx8,
  1607. Iop_Max32Fx8, Iop_Min32Fx8,
  1608. Iop_Max64Fx4, Iop_Min64Fx4,
  1609. Iop_Rotx32, Iop_Rotx64,
  1610. Iop_LAST /* must be the last enumerator */
  1611. }
  1612. IROp;
  1613. /* Pretty-print an op. */
  1614. extern void ppIROp ( IROp );
  1615. /* For a given operand return the types of its arguments and its result. */
  1616. extern void typeOfPrimop ( IROp op,
  1617. /*OUTs*/ IRType* t_dst, IRType* t_arg1,
  1618. IRType* t_arg2, IRType* t_arg3, IRType* t_arg4 );
  1619. /* Encoding of IEEE754-specified rounding modes.
  1620. Note, various front and back ends rely on the actual numerical
  1621. values of these, so do not change them. */
  1622. typedef
  1623. enum {
  1624. Irrm_NEAREST = 0, // Round to nearest, ties to even
  1625. Irrm_NegINF = 1, // Round to negative infinity
  1626. Irrm_PosINF = 2, // Round to positive infinity
  1627. Irrm_ZERO = 3, // Round toward zero
  1628. Irrm_NEAREST_TIE_AWAY_0 = 4, // Round to nearest, ties away from 0
  1629. Irrm_PREPARE_SHORTER = 5, // Round to prepare for shorter
  1630. // precision
  1631. Irrm_AWAY_FROM_ZERO = 6, // Round to away from 0
  1632. Irrm_NEAREST_TIE_TOWARD_0 = 7 // Round to nearest, ties towards 0
  1633. }
  1634. IRRoundingMode;
  1635. /* Binary floating point comparison result values.
  1636. This is also derived from what IA32 does. */
  1637. typedef
  1638. enum {
  1639. Ircr_UN = 0x45,
  1640. Ircr_LT = 0x01,
  1641. Ircr_GT = 0x00,
  1642. Ircr_EQ = 0x40
  1643. }
  1644. IRCmpFResult;
  1645. typedef IRCmpFResult IRCmpF32Result;
  1646. typedef IRCmpFResult IRCmpF64Result;
  1647. typedef IRCmpFResult IRCmpF128Result;
  1648. /* Decimal floating point result values. */
  1649. typedef IRCmpFResult IRCmpDResult;
  1650. typedef IRCmpDResult IRCmpD64Result;
  1651. typedef IRCmpDResult IRCmpD128Result;
  1652. /* ------------------ Expressions ------------------ */
  1653. typedef struct _IRQop IRQop; /* forward declaration */
  1654. typedef struct _IRTriop IRTriop; /* forward declaration */
  1655. /* The different kinds of expressions. Their meaning is explained below
  1656. in the comments for IRExpr. */
  1657. typedef
  1658. enum {
  1659. Iex_Binder=0x1900,
  1660. Iex_Get,
  1661. Iex_GetI,
  1662. Iex_RdTmp,
  1663. Iex_Qop,
  1664. Iex_Triop,
  1665. Iex_Binop,
  1666. Iex_Unop,
  1667. Iex_Load,
  1668. Iex_Const,
  1669. Iex_ITE,
  1670. Iex_CCall,
  1671. Iex_VECRET,
  1672. Iex_GSPTR
  1673. }
  1674. IRExprTag;
  1675. /* An expression. Stored as a tagged union. 'tag' indicates what kind
  1676. of expression this is. 'Iex' is the union that holds the fields. If
  1677. an IRExpr 'e' has e.tag equal to Iex_Load, then it's a load
  1678. expression, and the fields can be accessed with
  1679. 'e.Iex.Load.<fieldname>'.
  1680. For each kind of expression, we show what it looks like when
  1681. pretty-printed with ppIRExpr().
  1682. */
  1683. typedef
  1684. struct _IRExpr
  1685. IRExpr;
  1686. struct _IRExpr {
  1687. IRExprTag tag;
  1688. union {
  1689. /* Used only in pattern matching within Vex. Should not be seen
  1690. outside of Vex. */
  1691. struct {
  1692. Int binder;
  1693. } Binder;
  1694. /* Read a guest register, at a fixed offset in the guest state.
  1695. ppIRExpr output: GET:<ty>(<offset>), eg. GET:I32(0)
  1696. */
  1697. struct {
  1698. Int offset; /* Offset into the guest state */
  1699. IRType ty; /* Type of the value being read */
  1700. } Get;
  1701. /* Read a guest register at a non-fixed offset in the guest
  1702. state. This allows circular indexing into parts of the guest
  1703. state, which is essential for modelling situations where the
  1704. identity of guest registers is not known until run time. One
  1705. example is the x87 FP register stack.
  1706. The part of the guest state to be treated as a circular array
  1707. is described in the IRRegArray 'descr' field. It holds the
  1708. offset of the first element in the array, the type of each
  1709. element, and the number of elements.
  1710. The array index is indicated rather indirectly, in a way
  1711. which makes optimisation easy: as the sum of variable part
  1712. (the 'ix' field) and a constant offset (the 'bias' field).
  1713. Since the indexing is circular, the actual array index to use
  1714. is computed as (ix + bias) % num-of-elems-in-the-array.
  1715. Here's an example. The description
  1716. (96:8xF64)[t39,-7]
  1717. describes an array of 8 F64-typed values, the
  1718. guest-state-offset of the first being 96. This array is
  1719. being indexed at (t39 - 7) % 8.
  1720. It is important to get the array size/type exactly correct
  1721. since IR optimisation looks closely at such info in order to
  1722. establish aliasing/non-aliasing between seperate GetI and
  1723. PutI events, which is used to establish when they can be
  1724. reordered, etc. Putting incorrect info in will lead to
  1725. obscure IR optimisation bugs.
  1726. ppIRExpr output: GETI<descr>[<ix>,<bias]
  1727. eg. GETI(128:8xI8)[t1,0]
  1728. */
  1729. struct {
  1730. IRRegArray* descr; /* Part of guest state treated as circular */
  1731. IRExpr* ix; /* Variable part of index into array */
  1732. Int bias; /* Constant offset part of index into array */
  1733. } GetI;
  1734. /* The value held by a temporary.
  1735. ppIRExpr output: t<tmp>, eg. t1
  1736. */
  1737. struct {
  1738. IRTemp tmp; /* The temporary number */
  1739. } RdTmp;
  1740. /* A quaternary operation.
  1741. ppIRExpr output: <op>(<arg1>, <arg2>, <arg3>, <arg4>),
  1742. eg. MAddF64r32(t1, t2, t3, t4)
  1743. */
  1744. struct {
  1745. IRQop* details;
  1746. } Qop;
  1747. /* A ternary operation.
  1748. ppIRExpr output: <op>(<arg1>, <arg2>, <arg3>),
  1749. eg. MulF64(1, 2.0, 3.0)
  1750. */
  1751. struct {
  1752. IRTriop* details;
  1753. } Triop;
  1754. /* A binary operation.
  1755. ppIRExpr output: <op>(<arg1>, <arg2>), eg. Add32(t1,t2)
  1756. */
  1757. struct {
  1758. IROp op; /* op-code */
  1759. IRExpr* arg1; /* operand 1 */
  1760. IRExpr* arg2; /* operand 2 */
  1761. } Binop;
  1762. /* A unary operation.
  1763. ppIRExpr output: <op>(<arg>), eg. Neg8(t1)
  1764. */
  1765. struct {
  1766. IROp op; /* op-code */
  1767. IRExpr* arg; /* operand */
  1768. } Unop;
  1769. /* A load from memory -- a normal load, not a load-linked.
  1770. Load-Linkeds (and Store-Conditionals) are instead represented
  1771. by IRStmt.LLSC since Load-Linkeds have side effects and so
  1772. are not semantically valid IRExpr's.
  1773. ppIRExpr output: LD<end>:<ty>(<addr>), eg. LDle:I32(t1)
  1774. */
  1775. struct {
  1776. IREndness end; /* Endian-ness of the load */
  1777. IRType ty; /* Type of the loaded value */
  1778. IRExpr* addr; /* Address being loaded from */
  1779. } Load;
  1780. /* A constant-valued expression.
  1781. ppIRExpr output: <con>, eg. 0x4:I32
  1782. */
  1783. struct {
  1784. IRConst* con; /* The constant itself */
  1785. } Const;
  1786. /* A call to a pure (no side-effects) helper C function.
  1787. With the 'cee' field, 'name' is the function's name. It is
  1788. only used for pretty-printing purposes. The address to call
  1789. (host address, of course) is stored in the 'addr' field
  1790. inside 'cee'.
  1791. The 'args' field is a NULL-terminated array of arguments.
  1792. The stated return IRType, and the implied argument types,
  1793. must match that of the function being called well enough so
  1794. that the back end can actually generate correct code for the
  1795. call.
  1796. The called function **must** satisfy the following:
  1797. * no side effects -- must be a pure function, the result of
  1798. which depends only on the passed parameters.
  1799. * it may not look at, nor modify, any of the guest state
  1800. since that would hide guest state transitions from
  1801. instrumenters
  1802. * it may not access guest memory, since that would hide
  1803. guest memory transactions from the instrumenters
  1804. * it must not assume that arguments are being evaluated in a
  1805. particular order. The oder of evaluation is unspecified.
  1806. This is restrictive, but makes the semantics clean, and does
  1807. not interfere with IR optimisation.
  1808. If you want to call a helper which can mess with guest state
  1809. and/or memory, instead use Ist_Dirty. This is a lot more
  1810. flexible, but you have to give a bunch of details about what
  1811. the helper does (and you better be telling the truth,
  1812. otherwise any derived instrumentation will be wrong). Also
  1813. Ist_Dirty inhibits various IR optimisations and so can cause
  1814. quite poor code to be generated. Try to avoid it.
  1815. In principle it would be allowable to have the arg vector
  1816. contain an IRExpr_VECRET(), although not IRExpr_GSPTR(). However,
  1817. at the moment there is no requirement for clean helper calls to
  1818. be able to return V128 or V256 values. Hence this is not allowed.
  1819. ppIRExpr output: <cee>(<args>):<retty>
  1820. eg. foo{0x80489304}(t1, t2):I32
  1821. */
  1822. struct {
  1823. IRCallee* cee; /* Function to call. */
  1824. IRType retty; /* Type of return value. */
  1825. IRExpr** args; /* Vector of argument expressions. */
  1826. } CCall;
  1827. /* A ternary if-then-else operator. It returns iftrue if cond is
  1828. nonzero, iffalse otherwise. Note that it is STRICT, ie. both
  1829. iftrue and iffalse are evaluated in all cases.
  1830. ppIRExpr output: ITE(<cond>,<iftrue>,<iffalse>),
  1831. eg. ITE(t6,t7,t8)
  1832. */
  1833. struct {
  1834. IRExpr* cond; /* Condition */
  1835. IRExpr* iftrue; /* True expression */
  1836. IRExpr* iffalse; /* False expression */
  1837. } ITE;
  1838. } Iex;
  1839. };
  1840. /* Expression auxiliaries: a ternary expression. */
  1841. struct _IRTriop {
  1842. IROp op; /* op-code */
  1843. IRExpr* arg1; /* operand 1 */
  1844. IRExpr* arg2; /* operand 2 */
  1845. IRExpr* arg3; /* operand 3 */
  1846. };
  1847. /* Expression auxiliaries: a quarternary expression. */
  1848. struct _IRQop {
  1849. IROp op; /* op-code */
  1850. IRExpr* arg1; /* operand 1 */
  1851. IRExpr* arg2; /* operand 2 */
  1852. IRExpr* arg3; /* operand 3 */
  1853. IRExpr* arg4; /* operand 4 */
  1854. };
  1855. /* Two special kinds of IRExpr, which can ONLY be used in
  1856. argument lists for dirty helper calls (IRDirty.args) and in NO
  1857. OTHER PLACES. And then only in very limited ways. */
  1858. /* Denotes an argument which (in the helper) takes a pointer to a
  1859. (naturally aligned) V128 or V256, into which the helper is expected
  1860. to write its result. Use of IRExpr_VECRET() is strictly
  1861. controlled. If the helper returns a V128 or V256 value then
  1862. IRExpr_VECRET() must appear exactly once in the arg list, although
  1863. it can appear anywhere, and the helper must have a C 'void' return
  1864. type. If the helper returns any other type, IRExpr_VECRET() may
  1865. not appear in the argument list. */
  1866. /* Denotes an void* argument which is passed to the helper, which at
  1867. run time will point to the thread's guest state area. This can
  1868. only appear at most once in an argument list, and it may not appear
  1869. at all in argument lists for clean helper calls. */
  1870. static inline Bool is_IRExpr_VECRET_or_GSPTR ( const IRExpr* e ) {
  1871. return e->tag == Iex_VECRET || e->tag == Iex_GSPTR;
  1872. }
  1873. /* Expression constructors. */
  1874. extern IRExpr* IRExpr_Binder ( Int binder );
  1875. extern IRExpr* IRExpr_Get ( Int off, IRType ty );
  1876. extern IRExpr* IRExpr_GetI ( IRRegArray* descr, IRExpr* ix, Int bias );
  1877. extern IRExpr* IRExpr_RdTmp ( IRTemp tmp );
  1878. extern IRExpr* IRExpr_Qop ( IROp op, IRExpr* arg1, IRExpr* arg2,
  1879. IRExpr* arg3, IRExpr* arg4 );
  1880. extern IRExpr* IRExpr_Triop ( IROp op, IRExpr* arg1,
  1881. IRExpr* arg2, IRExpr* arg3 );
  1882. extern IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 );
  1883. extern IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg );
  1884. extern IRExpr* IRExpr_Load ( IREndness end, IRType ty, IRExpr* addr );
  1885. extern IRExpr* IRExpr_Const ( IRConst* con );
  1886. extern IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args );
  1887. extern IRExpr* IRExpr_ITE ( IRExpr* cond, IRExpr* iftrue, IRExpr* iffalse );
  1888. extern IRExpr* IRExpr_VECRET ( void );
  1889. extern IRExpr* IRExpr_GSPTR ( void );
  1890. /* Deep-copy an IRExpr. */
  1891. extern IRExpr* deepCopyIRExpr ( const IRExpr* );
  1892. /* Pretty-print an IRExpr. */
  1893. extern void ppIRExpr ( const IRExpr* );
  1894. /* NULL-terminated IRExpr vector constructors, suitable for
  1895. use as arg lists in clean/dirty helper calls. */
  1896. extern IRExpr** mkIRExprVec_0 ( void );
  1897. extern IRExpr** mkIRExprVec_1 ( IRExpr* );
  1898. extern IRExpr** mkIRExprVec_2 ( IRExpr*, IRExpr* );
  1899. extern IRExpr** mkIRExprVec_3 ( IRExpr*, IRExpr*, IRExpr* );
  1900. extern IRExpr** mkIRExprVec_4 ( IRExpr*, IRExpr*, IRExpr*, IRExpr* );
  1901. extern IRExpr** mkIRExprVec_5 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1902. IRExpr* );
  1903. extern IRExpr** mkIRExprVec_6 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1904. IRExpr*, IRExpr* );
  1905. extern IRExpr** mkIRExprVec_7 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1906. IRExpr*, IRExpr*, IRExpr* );
  1907. extern IRExpr** mkIRExprVec_8 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1908. IRExpr*, IRExpr*, IRExpr*, IRExpr* );
  1909. extern IRExpr** mkIRExprVec_9 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1910. IRExpr*, IRExpr*, IRExpr*, IRExpr*, IRExpr* );
  1911. extern IRExpr** mkIRExprVec_13 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1912. IRExpr*, IRExpr*, IRExpr*, IRExpr*,
  1913. IRExpr*, IRExpr*, IRExpr*, IRExpr*, IRExpr* );
  1914. /* IRExpr copiers:
  1915. - shallowCopy: shallow-copy (ie. create a new vector that shares the
  1916. elements with the original).
  1917. - deepCopy: deep-copy (ie. create a completely new vector). */
  1918. extern IRExpr** shallowCopyIRExprVec ( IRExpr** );
  1919. extern IRExpr** deepCopyIRExprVec ( IRExpr *const * );
  1920. /* Make a constant expression from the given host word taking into
  1921. account (of course) the host word size. */
  1922. extern IRExpr* mkIRExpr_HWord ( HWord );
  1923. /* Convenience function for constructing clean helper calls. */
  1924. extern
  1925. IRExpr* mkIRExprCCall ( IRType retty,
  1926. Int regparms, const HChar* name, void* addr,
  1927. IRExpr** args );
  1928. /* Convenience functions for atoms (IRExprs which are either Iex_Tmp or
  1929. * Iex_Const). */
  1930. static inline Bool isIRAtom ( const IRExpr* e ) {
  1931. return toBool(e->tag == Iex_RdTmp || e->tag == Iex_Const);
  1932. }
  1933. /* Are these two IR atoms identical? Causes an assertion
  1934. failure if they are passed non-atoms. */
  1935. extern Bool eqIRAtom ( const IRExpr*, const IRExpr* );
  1936. /* ------------------ Jump kinds ------------------ */
  1937. /* This describes hints which can be passed to the dispatcher at guest
  1938. control-flow transfer points.
  1939. Re Ijk_InvalICache and Ijk_FlushDCache: the guest state _must_ have
  1940. two pseudo-registers, guest_CMSTART and guest_CMLEN, which specify
  1941. the start and length of the region to be invalidated. CM stands
  1942. for "Cache Management". These are both the size of a guest word.
  1943. It is the responsibility of the relevant toIR.c to ensure that
  1944. these are filled in with suitable values before issuing a jump of
  1945. kind Ijk_InvalICache or Ijk_FlushDCache.
  1946. Ijk_InvalICache requests invalidation of translations taken from
  1947. the requested range. Ijk_FlushDCache requests flushing of the D
  1948. cache for the specified range.
  1949. Re Ijk_EmWarn and Ijk_EmFail: the guest state must have a
  1950. pseudo-register guest_EMNOTE, which is 32-bits regardless of the
  1951. host or guest word size. That register should be made to hold a
  1952. VexEmNote value to indicate the reason for the exit.
  1953. In the case of Ijk_EmFail, the exit is fatal (Vex-generated code
  1954. cannot continue) and so the jump destination can be anything.
  1955. Re Ijk_Sys_ (syscall jumps): the guest state must have a
  1956. pseudo-register guest_IP_AT_SYSCALL, which is the size of a guest
  1957. word. Front ends should set this to be the IP at the most recently
  1958. executed kernel-entering (system call) instruction. This makes it
  1959. very much easier (viz, actually possible at all) to back up the
  1960. guest to restart a syscall that has been interrupted by a signal.
  1961. */
  1962. typedef
  1963. enum {
  1964. Ijk_INVALID=0x1A00,
  1965. Ijk_Boring, /* not interesting; just goto next */
  1966. Ijk_Call, /* guest is doing a call */
  1967. Ijk_Ret, /* guest is doing a return */
  1968. Ijk_ClientReq, /* do guest client req before continuing */
  1969. Ijk_Yield, /* client is yielding to thread scheduler */
  1970. Ijk_EmWarn, /* report emulation warning before continuing */
  1971. Ijk_EmFail, /* emulation critical (FATAL) error; give up */
  1972. Ijk_NoDecode, /* current instruction cannot be decoded */
  1973. Ijk_MapFail, /* Vex-provided address translation failed */
  1974. Ijk_InvalICache, /* Inval icache for range [CMSTART, +CMLEN) */
  1975. Ijk_FlushDCache, /* Flush dcache for range [CMSTART, +CMLEN) */
  1976. Ijk_NoRedir, /* Jump to un-redirected guest addr */
  1977. Ijk_SigILL, /* current instruction synths SIGILL */
  1978. Ijk_SigTRAP, /* current instruction synths SIGTRAP */
  1979. Ijk_SigSEGV, /* current instruction synths SIGSEGV */
  1980. Ijk_SigBUS, /* current instruction synths SIGBUS */
  1981. Ijk_SigFPE, /* current instruction synths generic SIGFPE */
  1982. Ijk_SigFPE_IntDiv, /* current instruction synths SIGFPE - IntDiv */
  1983. Ijk_SigFPE_IntOvf, /* current instruction synths SIGFPE - IntOvf */
  1984. /* Unfortunately, various guest-dependent syscall kinds. They
  1985. all mean: do a syscall before continuing. */
  1986. Ijk_Sys_syscall, /* amd64/x86 'syscall', ppc 'sc', arm 'svc #0' */
  1987. Ijk_Sys_int32, /* amd64/x86 'int $0x20' */
  1988. Ijk_Sys_int128, /* amd64/x86 'int $0x80' */
  1989. Ijk_Sys_int129, /* amd64/x86 'int $0x81' */
  1990. Ijk_Sys_int130, /* amd64/x86 'int $0x82' */
  1991. Ijk_Sys_int145, /* amd64/x86 'int $0x91' */
  1992. Ijk_Sys_int210, /* amd64/x86 'int $0xD2' */
  1993. Ijk_Sys_sysenter /* x86 'sysenter'. guest_EIP becomes
  1994. invalid at the point this happens. */
  1995. }
  1996. IRJumpKind;
  1997. extern void ppIRJumpKind ( IRJumpKind );
  1998. /* ------------------ Dirty helper calls ------------------ */
  1999. /* A dirty call is a flexible mechanism for calling (possibly
  2000. conditionally) a helper function or procedure. The helper function
  2001. may read, write or modify client memory, and may read, write or
  2002. modify client state. It can take arguments and optionally return a
  2003. value. It may return different results and/or do different things
  2004. when called repeatedly with the same arguments, by means of storing
  2005. private state.
  2006. If a value is returned, it is assigned to the nominated return
  2007. temporary.
  2008. Dirty calls are statements rather than expressions for obvious
  2009. reasons. If a dirty call is marked as writing guest state, any
  2010. pre-existing values derived from the written parts of the guest
  2011. state are invalid. Similarly, if the dirty call is stated as
  2012. writing memory, any pre-existing loaded values are invalidated by
  2013. it.
  2014. In order that instrumentation is possible, the call must state, and
  2015. state correctly:
  2016. * Whether it reads, writes or modifies memory, and if so where.
  2017. * Whether it reads, writes or modifies guest state, and if so which
  2018. pieces. Several pieces may be stated, and their extents must be
  2019. known at translation-time. Each piece is allowed to repeat some
  2020. number of times at a fixed interval, if required.
  2021. Normally, code is generated to pass just the args to the helper.
  2022. However, if IRExpr_GSPTR() is present in the argument list (at most
  2023. one instance is allowed), then the guest state pointer is passed for
  2024. that arg, so that the callee can access the guest state. It is
  2025. invalid for .nFxState to be zero but IRExpr_GSPTR() to be present,
  2026. since .nFxState==0 is a claim that the call does not access guest
  2027. state.
  2028. IMPORTANT NOTE re GUARDS: Dirty calls are strict, very strict. The
  2029. arguments and 'mFx' are evaluated REGARDLESS of the guard value.
  2030. The order of argument evaluation is unspecified. The guard
  2031. expression is evaluated AFTER the arguments and 'mFx' have been
  2032. evaluated. 'mFx' is expected (by Memcheck) to be a defined value
  2033. even if the guard evaluates to false.
  2034. */
  2035. #define VEX_N_FXSTATE 7 /* enough for FXSAVE/FXRSTOR on x86 */
  2036. /* Effects on resources (eg. registers, memory locations) */
  2037. typedef
  2038. enum {
  2039. Ifx_None=0x1B00, /* no effect */
  2040. Ifx_Read, /* reads the resource */
  2041. Ifx_Write, /* writes the resource */
  2042. Ifx_Modify, /* modifies the resource */
  2043. }
  2044. IREffect;
  2045. /* Pretty-print an IREffect */
  2046. extern void ppIREffect ( IREffect );
  2047. typedef
  2048. struct _IRDirty {
  2049. /* What to call, and details of args/results. .guard must be
  2050. non-NULL. If .tmp is not IRTemp_INVALID, then the call
  2051. returns a result which is placed in .tmp. If at runtime the
  2052. guard evaluates to false, .tmp has an 0x555..555 bit pattern
  2053. written to it. Hence conditional calls that assign .tmp are
  2054. allowed. */
  2055. IRCallee* cee; /* where to call */
  2056. IRExpr* guard; /* :: Ity_Bit. Controls whether call happens */
  2057. /* The args vector may contain IRExpr_GSPTR() and/or
  2058. IRExpr_VECRET(), in both cases, at most once. */
  2059. IRExpr** args; /* arg vector, ends in NULL. */
  2060. IRTemp tmp; /* to assign result to, or IRTemp_INVALID if none */
  2061. /* Mem effects; we allow only one R/W/M region to be stated */
  2062. IREffect mFx; /* indicates memory effects, if any */
  2063. IRExpr* mAddr; /* of access, or NULL if mFx==Ifx_None */
  2064. Int mSize; /* of access, or zero if mFx==Ifx_None */
  2065. /* Guest state effects; up to N allowed */
  2066. Int nFxState; /* must be 0 .. VEX_N_FXSTATE */
  2067. struct {
  2068. IREffect fx:16; /* read, write or modify? Ifx_None is invalid. */
  2069. UShort offset;
  2070. UShort size;
  2071. UChar nRepeats;
  2072. UChar repeatLen;
  2073. } fxState[VEX_N_FXSTATE];
  2074. /* The access can be repeated, as specified by nRepeats and
  2075. repeatLen. To describe only a single access, nRepeats and
  2076. repeatLen should be zero. Otherwise, repeatLen must be a
  2077. multiple of size and greater than size. */
  2078. /* Overall, the parts of the guest state denoted by (offset,
  2079. size, nRepeats, repeatLen) is
  2080. [offset, +size)
  2081. and, if nRepeats > 0,
  2082. for (i = 1; i <= nRepeats; i++)
  2083. [offset + i * repeatLen, +size)
  2084. A convenient way to enumerate all segments is therefore
  2085. for (i = 0; i < 1 + nRepeats; i++)
  2086. [offset + i * repeatLen, +size)
  2087. */
  2088. }
  2089. IRDirty;
  2090. /* Pretty-print a dirty call */
  2091. extern void ppIRDirty ( const IRDirty* );
  2092. /* Allocate an uninitialised dirty call */
  2093. extern IRDirty* emptyIRDirty ( void );
  2094. /* Deep-copy a dirty call */
  2095. extern IRDirty* deepCopyIRDirty ( const IRDirty* );
  2096. /* A handy function which takes some of the tedium out of constructing
  2097. dirty helper calls. The called function impliedly does not return
  2098. any value and has a constant-True guard. The call is marked as
  2099. accessing neither guest state nor memory (hence the "unsafe"
  2100. designation) -- you can change this marking later if need be. A
  2101. suitable IRCallee is constructed from the supplied bits. */
  2102. extern
  2103. IRDirty* unsafeIRDirty_0_N ( Int regparms, const HChar* name, void* addr,
  2104. IRExpr** args );
  2105. /* Similarly, make a zero-annotation dirty call which returns a value,
  2106. and assign that to the given temp. */
  2107. extern
  2108. IRDirty* unsafeIRDirty_1_N ( IRTemp dst,
  2109. Int regparms, const HChar* name, void* addr,
  2110. IRExpr** args );
  2111. /* --------------- Memory Bus Events --------------- */
  2112. typedef
  2113. enum {
  2114. Imbe_Fence=0x1C00,
  2115. /* Needed only on ARM. It cancels a reservation made by a
  2116. preceding Linked-Load, and needs to be handed through to the
  2117. back end, just as LL and SC themselves are. */
  2118. Imbe_CancelReservation
  2119. }
  2120. IRMBusEvent;
  2121. extern void ppIRMBusEvent ( IRMBusEvent );
  2122. /* --------------- Compare and Swap --------------- */
  2123. /* This denotes an atomic compare and swap operation, either
  2124. a single-element one or a double-element one.
  2125. In the single-element case:
  2126. .addr is the memory address.
  2127. .end is the endianness with which memory is accessed
  2128. If .addr contains the same value as .expdLo, then .dataLo is
  2129. written there, else there is no write. In both cases, the
  2130. original value at .addr is copied into .oldLo.
  2131. Types: .expdLo, .dataLo and .oldLo must all have the same type.
  2132. It may be any integral type, viz: I8, I16, I32 or, for 64-bit
  2133. guests, I64.
  2134. .oldHi must be IRTemp_INVALID, and .expdHi and .dataHi must
  2135. be NULL.
  2136. In the double-element case:
  2137. .addr is the memory address.
  2138. .end is the endianness with which memory is accessed
  2139. The operation is the same:
  2140. If .addr contains the same value as .expdHi:.expdLo, then
  2141. .dataHi:.dataLo is written there, else there is no write. In
  2142. both cases the original value at .addr is copied into
  2143. .oldHi:.oldLo.
  2144. Types: .expdHi, .expdLo, .dataHi, .dataLo, .oldHi, .oldLo must
  2145. all have the same type, which may be any integral type, viz: I8,
  2146. I16, I32 or, for 64-bit guests, I64.
  2147. The double-element case is complicated by the issue of
  2148. endianness. In all cases, the two elements are understood to be
  2149. located adjacently in memory, starting at the address .addr.
  2150. If .end is Iend_LE, then the .xxxLo component is at the lower
  2151. address and the .xxxHi component is at the higher address, and
  2152. each component is itself stored little-endianly.
  2153. If .end is Iend_BE, then the .xxxHi component is at the lower
  2154. address and the .xxxLo component is at the higher address, and
  2155. each component is itself stored big-endianly.
  2156. This allows representing more cases than most architectures can
  2157. handle. For example, x86 cannot do DCAS on 8- or 16-bit elements.
  2158. How to know if the CAS succeeded?
  2159. * if .oldLo == .expdLo (resp. .oldHi:.oldLo == .expdHi:.expdLo),
  2160. then the CAS succeeded, .dataLo (resp. .dataHi:.dataLo) is now
  2161. stored at .addr, and the original value there was .oldLo (resp
  2162. .oldHi:.oldLo).
  2163. * if .oldLo != .expdLo (resp. .oldHi:.oldLo != .expdHi:.expdLo),
  2164. then the CAS failed, and the original value at .addr was .oldLo
  2165. (resp. .oldHi:.oldLo).
  2166. Hence it is easy to know whether or not the CAS succeeded.
  2167. */
  2168. typedef
  2169. struct {
  2170. IRTemp oldHi; /* old value of *addr is written here */
  2171. IRTemp oldLo;
  2172. IREndness end; /* endianness of the data in memory */
  2173. IRExpr* addr; /* store address */
  2174. IRExpr* expdHi; /* expected old value at *addr */
  2175. IRExpr* expdLo;
  2176. IRExpr* dataHi; /* new value for *addr */
  2177. IRExpr* dataLo;
  2178. }
  2179. IRCAS;
  2180. extern void ppIRCAS ( const IRCAS* cas );
  2181. extern IRCAS* mkIRCAS ( IRTemp oldHi, IRTemp oldLo,
  2182. IREndness end, IRExpr* addr,
  2183. IRExpr* expdHi, IRExpr* expdLo,
  2184. IRExpr* dataHi, IRExpr* dataLo );
  2185. extern IRCAS* deepCopyIRCAS ( const IRCAS* );
  2186. /* ------------------ Circular Array Put ------------------ */
  2187. typedef
  2188. struct {
  2189. IRRegArray* descr; /* Part of guest state treated as circular */
  2190. IRExpr* ix; /* Variable part of index into array */
  2191. Int bias; /* Constant offset part of index into array */
  2192. IRExpr* data; /* The value to write */
  2193. } IRPutI;
  2194. extern void ppIRPutI ( const IRPutI* puti );
  2195. extern IRPutI* mkIRPutI ( IRRegArray* descr, IRExpr* ix,
  2196. Int bias, IRExpr* data );
  2197. extern IRPutI* deepCopyIRPutI ( const IRPutI* );
  2198. /* --------------- Guarded loads and stores --------------- */
  2199. /* Conditional stores are straightforward. They are the same as
  2200. normal stores, with an extra 'guard' field :: Ity_I1 that
  2201. determines whether or not the store actually happens. If not,
  2202. memory is unmodified.
  2203. The semantics of this is that 'addr' and 'data' are fully evaluated
  2204. even in the case where 'guard' evaluates to zero (false).
  2205. */
  2206. typedef
  2207. struct {
  2208. IREndness end; /* Endianness of the store */
  2209. IRExpr* addr; /* store address */
  2210. IRExpr* data; /* value to write */
  2211. IRExpr* guard; /* Guarding value */
  2212. }
  2213. IRStoreG;
  2214. /* Conditional loads are a little more complex. 'addr' is the
  2215. address, 'guard' is the guarding condition. If the load takes
  2216. place, the loaded value is placed in 'dst'. If it does not take
  2217. place, 'alt' is copied to 'dst'. However, the loaded value is not
  2218. placed directly in 'dst' -- it is first subjected to the conversion
  2219. specified by 'cvt'.
  2220. For example, imagine doing a conditional 8-bit load, in which the
  2221. loaded value is zero extended to 32 bits. Hence:
  2222. * 'dst' and 'alt' must have type I32
  2223. * 'cvt' must be a unary op which converts I8 to I32. In this
  2224. example, it would be ILGop_8Uto32.
  2225. There is no explicit indication of the type at which the load is
  2226. done, since that is inferrable from the arg type of 'cvt'. Note
  2227. that the types of 'alt' and 'dst' and the result type of 'cvt' must
  2228. all be the same.
  2229. Semantically, 'addr' is evaluated even in the case where 'guard'
  2230. evaluates to zero (false), and 'alt' is evaluated even when 'guard'
  2231. evaluates to one (true). That is, 'addr' and 'alt' are always
  2232. evaluated.
  2233. */
  2234. typedef
  2235. enum {
  2236. ILGop_INVALID=0x1D00,
  2237. ILGop_IdentV128, /* 128 bit vector, no conversion */
  2238. ILGop_Ident64, /* 64 bit, no conversion */
  2239. ILGop_Ident32, /* 32 bit, no conversion */
  2240. ILGop_16Uto32, /* 16 bit load, Z-widen to 32 */
  2241. ILGop_16Sto32, /* 16 bit load, S-widen to 32 */
  2242. ILGop_8Uto32, /* 8 bit load, Z-widen to 32 */
  2243. ILGop_8Sto32 /* 8 bit load, S-widen to 32 */
  2244. }
  2245. IRLoadGOp;
  2246. typedef
  2247. struct {
  2248. IREndness end; /* Endianness of the load */
  2249. IRLoadGOp cvt; /* Conversion to apply to the loaded value */
  2250. IRTemp dst; /* Destination (LHS) of assignment */
  2251. IRExpr* addr; /* Address being loaded from */
  2252. IRExpr* alt; /* Value if load is not done. */
  2253. IRExpr* guard; /* Guarding value */
  2254. }
  2255. IRLoadG;
  2256. extern void ppIRStoreG ( const IRStoreG* sg );
  2257. extern void ppIRLoadGOp ( IRLoadGOp cvt );
  2258. extern void ppIRLoadG ( const IRLoadG* lg );
  2259. extern IRStoreG* mkIRStoreG ( IREndness end,
  2260. IRExpr* addr, IRExpr* data,
  2261. IRExpr* guard );
  2262. extern IRLoadG* mkIRLoadG ( IREndness end, IRLoadGOp cvt,
  2263. IRTemp dst, IRExpr* addr, IRExpr* alt,
  2264. IRExpr* guard );
  2265. /* ------------------ Statements ------------------ */
  2266. /* The different kinds of statements. Their meaning is explained
  2267. below in the comments for IRStmt.
  2268. Those marked META do not represent code, but rather extra
  2269. information about the code. These statements can be removed
  2270. without affecting the functional behaviour of the code, however
  2271. they are required by some IR consumers such as tools that
  2272. instrument the code.
  2273. */
  2274. typedef
  2275. enum {
  2276. Ist_NoOp=0x1E00,
  2277. Ist_IMark, /* META */
  2278. Ist_AbiHint, /* META */
  2279. Ist_Put,
  2280. Ist_PutI,
  2281. Ist_WrTmp,
  2282. Ist_Store,
  2283. Ist_LoadG,
  2284. Ist_StoreG,
  2285. Ist_CAS,
  2286. Ist_LLSC,
  2287. Ist_Dirty,
  2288. Ist_MBE,
  2289. Ist_Exit
  2290. }
  2291. IRStmtTag;
  2292. /* A statement. Stored as a tagged union. 'tag' indicates what kind
  2293. of expression this is. 'Ist' is the union that holds the fields.
  2294. If an IRStmt 'st' has st.tag equal to Iex_Store, then it's a store
  2295. statement, and the fields can be accessed with
  2296. 'st.Ist.Store.<fieldname>'.
  2297. For each kind of statement, we show what it looks like when
  2298. pretty-printed with ppIRStmt().
  2299. */
  2300. typedef
  2301. struct _IRStmt {
  2302. IRStmtTag tag;
  2303. union {
  2304. /* A no-op (usually resulting from IR optimisation). Can be
  2305. omitted without any effect.
  2306. ppIRStmt output: IR-NoOp
  2307. */
  2308. struct {
  2309. } NoOp;
  2310. /* META: instruction mark. Marks the start of the statements
  2311. that represent a single machine instruction (the end of
  2312. those statements is marked by the next IMark or the end of
  2313. the IRSB). Contains the address and length of the
  2314. instruction.
  2315. It also contains a delta value. The delta must be
  2316. subtracted from a guest program counter value before
  2317. attempting to establish, by comparison with the address
  2318. and length values, whether or not that program counter
  2319. value refers to this instruction. For x86, amd64, ppc32,
  2320. ppc64 and arm, the delta value is zero. For Thumb
  2321. instructions, the delta value is one. This is because, on
  2322. Thumb, guest PC values (guest_R15T) are encoded using the
  2323. top 31 bits of the instruction address and a 1 in the lsb;
  2324. hence they appear to be (numerically) 1 past the start of
  2325. the instruction they refer to. IOW, guest_R15T on ARM
  2326. holds a standard ARM interworking address.
  2327. ppIRStmt output: ------ IMark(<addr>, <len>, <delta>) ------,
  2328. eg. ------ IMark(0x4000792, 5, 0) ------,
  2329. */
  2330. struct {
  2331. Addr addr; /* instruction address */
  2332. UInt len; /* instruction length */
  2333. UChar delta; /* addr = program counter as encoded in guest state
  2334. - delta */
  2335. } IMark;
  2336. /* META: An ABI hint, which says something about this
  2337. platform's ABI.
  2338. At the moment, the only AbiHint is one which indicates
  2339. that a given chunk of address space, [base .. base+len-1],
  2340. has become undefined. This is used on amd64-linux and
  2341. some ppc variants to pass stack-redzoning hints to whoever
  2342. wants to see them. It also indicates the address of the
  2343. next (dynamic) instruction that will be executed. This is
  2344. to help Memcheck to origin tracking.
  2345. ppIRStmt output: ====== AbiHint(<base>, <len>, <nia>) ======
  2346. eg. ====== AbiHint(t1, 16, t2) ======
  2347. */
  2348. struct {
  2349. IRExpr* base; /* Start of undefined chunk */
  2350. Int len; /* Length of undefined chunk */
  2351. IRExpr* nia; /* Address of next (guest) insn */
  2352. } AbiHint;
  2353. /* Write a guest register, at a fixed offset in the guest state.
  2354. ppIRStmt output: PUT(<offset>) = <data>, eg. PUT(60) = t1
  2355. */
  2356. struct {
  2357. Int offset; /* Offset into the guest state */
  2358. IRExpr* data; /* The value to write */
  2359. } Put;
  2360. /* Write a guest register, at a non-fixed offset in the guest
  2361. state. See the comment for GetI expressions for more
  2362. information.
  2363. ppIRStmt output: PUTI<descr>[<ix>,<bias>] = <data>,
  2364. eg. PUTI(64:8xF64)[t5,0] = t1
  2365. */
  2366. struct {
  2367. IRPutI* details;
  2368. } PutI;
  2369. /* Assign a value to a temporary. Note that SSA rules require
  2370. each tmp is only assigned to once. IR sanity checking will
  2371. reject any block containing a temporary which is not assigned
  2372. to exactly once.
  2373. ppIRStmt output: t<tmp> = <data>, eg. t1 = 3
  2374. */
  2375. struct {
  2376. IRTemp tmp; /* Temporary (LHS of assignment) */
  2377. IRExpr* data; /* Expression (RHS of assignment) */
  2378. } WrTmp;
  2379. /* Write a value to memory. This is a normal store, not a
  2380. Store-Conditional. To represent a Store-Conditional,
  2381. instead use IRStmt.LLSC.
  2382. ppIRStmt output: ST<end>(<addr>) = <data>, eg. STle(t1) = t2
  2383. */
  2384. struct {
  2385. IREndness end; /* Endianness of the store */
  2386. IRExpr* addr; /* store address */
  2387. IRExpr* data; /* value to write */
  2388. } Store;
  2389. /* Guarded store. Note that this is defined to evaluate all
  2390. expression fields (addr, data) even if the guard evaluates
  2391. to false.
  2392. ppIRStmt output:
  2393. if (<guard>) ST<end>(<addr>) = <data> */
  2394. struct {
  2395. IRStoreG* details;
  2396. } StoreG;
  2397. /* Guarded load. Note that this is defined to evaluate all
  2398. expression fields (addr, alt) even if the guard evaluates
  2399. to false.
  2400. ppIRStmt output:
  2401. t<tmp> = if (<guard>) <cvt>(LD<end>(<addr>)) else <alt> */
  2402. struct {
  2403. IRLoadG* details;
  2404. } LoadG;
  2405. /* Do an atomic compare-and-swap operation. Semantics are
  2406. described above on a comment at the definition of IRCAS.
  2407. ppIRStmt output:
  2408. t<tmp> = CAS<end>(<addr> :: <expected> -> <new>)
  2409. eg
  2410. t1 = CASle(t2 :: t3->Add32(t3,1))
  2411. which denotes a 32-bit atomic increment
  2412. of a value at address t2
  2413. A double-element CAS may also be denoted, in which case <tmp>,
  2414. <expected> and <new> are all pairs of items, separated by
  2415. commas.
  2416. */
  2417. struct {
  2418. IRCAS* details;
  2419. } CAS;
  2420. /* Either Load-Linked or Store-Conditional, depending on
  2421. STOREDATA.
  2422. If STOREDATA is NULL then this is a Load-Linked, meaning
  2423. that data is loaded from memory as normal, but a
  2424. 'reservation' for the address is also lodged in the
  2425. hardware.
  2426. result = Load-Linked(addr, end)
  2427. The data transfer type is the type of RESULT (I32, I64,
  2428. etc). ppIRStmt output:
  2429. result = LD<end>-Linked(<addr>), eg. LDbe-Linked(t1)
  2430. If STOREDATA is not NULL then this is a Store-Conditional,
  2431. hence:
  2432. result = Store-Conditional(addr, storedata, end)
  2433. The data transfer type is the type of STOREDATA and RESULT
  2434. has type Ity_I1. The store may fail or succeed depending
  2435. on the state of a previously lodged reservation on this
  2436. address. RESULT is written 1 if the store succeeds and 0
  2437. if it fails. eg ppIRStmt output:
  2438. result = ( ST<end>-Cond(<addr>) = <storedata> )
  2439. eg t3 = ( STbe-Cond(t1, t2) )
  2440. In all cases, the address must be naturally aligned for
  2441. the transfer type -- any misaligned addresses should be
  2442. caught by a dominating IR check and side exit. This
  2443. alignment restriction exists because on at least some
  2444. LL/SC platforms (ppc), stwcx. etc will trap w/ SIGBUS on
  2445. misaligned addresses, and we have to actually generate
  2446. stwcx. on the host, and we don't want it trapping on the
  2447. host.
  2448. Summary of rules for transfer type:
  2449. STOREDATA == NULL (LL):
  2450. transfer type = type of RESULT
  2451. STOREDATA != NULL (SC):
  2452. transfer type = type of STOREDATA, and RESULT :: Ity_I1
  2453. */
  2454. struct {
  2455. IREndness end;
  2456. IRTemp result;
  2457. IRExpr* addr;
  2458. IRExpr* storedata; /* NULL => LL, non-NULL => SC */
  2459. } LLSC;
  2460. /* Call (possibly conditionally) a C function that has side
  2461. effects (ie. is "dirty"). See the comments above the
  2462. IRDirty type declaration for more information.
  2463. ppIRStmt output:
  2464. t<tmp> = DIRTY <guard> <effects>
  2465. ::: <callee>(<args>)
  2466. eg.
  2467. t1 = DIRTY t27 RdFX-gst(16,4) RdFX-gst(60,4)
  2468. ::: foo{0x380035f4}(t2)
  2469. */
  2470. struct {
  2471. IRDirty* details;
  2472. } Dirty;
  2473. /* A memory bus event - a fence, or acquisition/release of the
  2474. hardware bus lock. IR optimisation treats all these as fences
  2475. across which no memory references may be moved.
  2476. ppIRStmt output: MBusEvent-Fence,
  2477. MBusEvent-BusLock, MBusEvent-BusUnlock.
  2478. */
  2479. struct {
  2480. IRMBusEvent event;
  2481. } MBE;
  2482. /* Conditional exit from the middle of an IRSB.
  2483. ppIRStmt output: if (<guard>) goto {<jk>} <dst>
  2484. eg. if (t69) goto {Boring} 0x4000AAA:I32
  2485. If <guard> is true, the guest state is also updated by
  2486. PUT-ing <dst> at <offsIP>. This is done because a
  2487. taken exit must update the guest program counter.
  2488. */
  2489. struct {
  2490. IRExpr* guard; /* Conditional expression */
  2491. IRConst* dst; /* Jump target (constant only) */
  2492. IRJumpKind jk; /* Jump kind */
  2493. Int offsIP; /* Guest state offset for IP */
  2494. } Exit;
  2495. } Ist;
  2496. }
  2497. IRStmt;
  2498. /* Statement constructors. */
  2499. extern IRStmt* IRStmt_NoOp ( void );
  2500. extern IRStmt* IRStmt_IMark ( Addr addr, UInt len, UChar delta );
  2501. extern IRStmt* IRStmt_AbiHint ( IRExpr* base, Int len, IRExpr* nia );
  2502. extern IRStmt* IRStmt_Put ( Int off, IRExpr* data );
  2503. extern IRStmt* IRStmt_PutI ( IRPutI* details );
  2504. extern IRStmt* IRStmt_WrTmp ( IRTemp tmp, IRExpr* data );
  2505. extern IRStmt* IRStmt_Store ( IREndness end, IRExpr* addr, IRExpr* data );
  2506. extern IRStmt* IRStmt_StoreG ( IREndness end, IRExpr* addr, IRExpr* data,
  2507. IRExpr* guard );
  2508. extern IRStmt* IRStmt_LoadG ( IREndness end, IRLoadGOp cvt, IRTemp dst,
  2509. IRExpr* addr, IRExpr* alt, IRExpr* guard );
  2510. extern IRStmt* IRStmt_CAS ( IRCAS* details );
  2511. extern IRStmt* IRStmt_LLSC ( IREndness end, IRTemp result,
  2512. IRExpr* addr, IRExpr* storedata );
  2513. extern IRStmt* IRStmt_Dirty ( IRDirty* details );
  2514. extern IRStmt* IRStmt_MBE ( IRMBusEvent event );
  2515. extern IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst,
  2516. Int offsIP );
  2517. /* Deep-copy an IRStmt. */
  2518. extern IRStmt* deepCopyIRStmt ( const IRStmt* );
  2519. /* Pretty-print an IRStmt. */
  2520. extern void ppIRStmt ( const IRStmt* );
  2521. /* ------------------ Basic Blocks ------------------ */
  2522. /* Type environments: a bunch of statements, expressions, etc, are
  2523. incomplete without an environment indicating the type of each
  2524. IRTemp. So this provides one. IR temporaries are really just
  2525. unsigned ints and so this provides an array, 0 .. n_types_used-1 of
  2526. them.
  2527. */
  2528. typedef
  2529. struct {
  2530. IRType* types;
  2531. Int types_size;
  2532. Int types_used;
  2533. }
  2534. IRTypeEnv;
  2535. /* Obtain a new IRTemp */
  2536. extern IRTemp newIRTemp ( IRTypeEnv*, IRType );
  2537. /* Deep-copy a type environment */
  2538. extern IRTypeEnv* deepCopyIRTypeEnv ( const IRTypeEnv* );
  2539. /* Pretty-print a type environment */
  2540. extern void ppIRTypeEnv ( const IRTypeEnv* );
  2541. /* Code blocks, which in proper compiler terminology are superblocks
  2542. (single entry, multiple exit code sequences) contain:
  2543. - A table giving a type for each temp (the "type environment")
  2544. - An expandable array of statements
  2545. - An expression of type 32 or 64 bits, depending on the
  2546. guest's word size, indicating the next destination if the block
  2547. executes all the way to the end, without a side exit
  2548. - An indication of any special actions (JumpKind) needed
  2549. for this final jump.
  2550. - Offset of the IP field in the guest state. This will be
  2551. updated before the final jump is done.
  2552. "IRSB" stands for "IR Super Block".
  2553. */
  2554. typedef
  2555. struct {
  2556. IRTypeEnv* tyenv;
  2557. IRStmt** stmts;
  2558. Int stmts_size;
  2559. Int stmts_used;
  2560. IRExpr* next;
  2561. IRJumpKind jumpkind;
  2562. Int offsIP;
  2563. }
  2564. IRSB;
  2565. /* Allocate a new, uninitialised IRSB */
  2566. extern IRSB* emptyIRSB ( void );
  2567. /* Deep-copy an IRSB */
  2568. extern IRSB* deepCopyIRSB ( const IRSB* );
  2569. /* Deep-copy an IRSB, except for the statements list, which set to be
  2570. a new, empty, list of statements. */
  2571. extern IRSB* deepCopyIRSBExceptStmts ( const IRSB* );
  2572. /* Pretty-print an IRSB */
  2573. extern void ppIRSB ( const IRSB* );
  2574. /* Append an IRStmt to an IRSB */
  2575. extern void addStmtToIRSB ( IRSB*, IRStmt* );
  2576. /*---------------------------------------------------------------*/
  2577. /*--- Helper functions for the IR ---*/
  2578. /*---------------------------------------------------------------*/
  2579. /* For messing with IR type environments */
  2580. extern IRTypeEnv* emptyIRTypeEnv ( void );
  2581. /* What is the type of this expression? */
  2582. extern IRType typeOfIRConst ( const IRConst* );
  2583. extern IRType typeOfIRTemp ( const IRTypeEnv*, IRTemp );
  2584. extern IRType typeOfIRExpr ( const IRTypeEnv*, const IRExpr* );
  2585. /* What are the arg and result type for this IRLoadGOp? */
  2586. extern void typeOfIRLoadGOp ( IRLoadGOp cvt,
  2587. /*OUT*/IRType* t_res,
  2588. /*OUT*/IRType* t_arg );
  2589. /* Sanity check a BB of IR */
  2590. extern void sanityCheckIRSB ( const IRSB* bb,
  2591. const HChar* caller,
  2592. Bool require_flatness,
  2593. IRType guest_word_size );
  2594. extern Bool isFlatIRStmt ( const IRStmt* );
  2595. /* Is this any value actually in the enumeration 'IRType' ? */
  2596. extern Bool isPlausibleIRType ( IRType ty );
  2597. /*---------------------------------------------------------------*/
  2598. /*--- IR injection ---*/
  2599. /*---------------------------------------------------------------*/
  2600. void vex_inject_ir(IRSB *, IREndness);
  2601. #endif /* ndef __LIBVEX_IR_H */
  2602. /*---------------------------------------------------------------*/
  2603. /*--- libvex_ir.h ---*/
  2604. /*---------------------------------------------------------------*/