pyvex 9.2.189__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyvex might be problematic. Click here for more details.

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