sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin libvex_ir.h ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | |
sewardj | e6c53e0 | 2011-10-23 07:33:43 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2011 OpenWorks LLP |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 11 | info@open-works.net |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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 |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 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. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 36 | #ifndef __LIBVEX_IR_H |
| 37 | #define __LIBVEX_IR_H |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 38 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 39 | #include "libvex_basictypes.h" |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 40 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 41 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 42 | /*---------------------------------------------------------------*/ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 | ~~~~~~~~~~~ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 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: |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 57 | - a type environment, which indicates the type of each temporary |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 58 | value present in the IRSB |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 59 | - a list of statements, which represent code |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 60 | - a jump that exits from the end the IRSB |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 61 | Because the blocks are multiple-exit, there can be additional |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 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). |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 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. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 | |
sewardj | 2f10aa6 | 2011-05-27 13:20:56 +0000 | [diff] [blame] | 107 | ------ IMark(0x24F275, 7, 0) ------ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 | |
sewardj | 2f10aa6 | 2011-05-27 13:20:56 +0000 | [diff] [blame] | 150 | ------ IMark(0x4000ABA, 3, 0) ------ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 | ~~~~~~~~~~~~~~~~~~ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 170 | The IR is fully typed. For every IRSB (IR block) it is possible to |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 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 | /*---------------------------------------------------------------*/ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 188 | /*--- Type definitions for the IR ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 189 | /*---------------------------------------------------------------*/ |
| 190 | |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 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 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 204 | - deepCopyIRFoo is a deep copy constructor for IRFoos. |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 205 | It recursively traverses the entire argument tree and |
sewardj | f6c8ebf | 2007-02-06 01:52:52 +0000 | [diff] [blame] | 206 | produces a complete new tree. All types have a deep copy |
| 207 | constructor. |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 208 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 209 | - shallowCopyIRFoo is the shallow copy constructor for IRFoos. |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 210 | It creates a new top-level copy of the supplied object, |
sewardj | f6c8ebf | 2007-02-06 01:52:52 +0000 | [diff] [blame] | 211 | but does not copy any sub-objects. Only some types have a |
| 212 | shallow copy constructor. |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 213 | */ |
| 214 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 215 | /* ------------------ Types ------------------ */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 216 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 217 | /* A type indicates the size of a value, and whether it's an integer, a |
| 218 | float, or a vector (SIMD) value. */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 219 | typedef |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 220 | enum { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 221 | Ity_INVALID=0x11000, |
| 222 | Ity_I1, |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 223 | Ity_I8, |
| 224 | Ity_I16, |
| 225 | Ity_I32, |
| 226 | Ity_I64, |
sewardj | 9b96767 | 2005-02-08 11:13:09 +0000 | [diff] [blame] | 227 | Ity_I128, /* 128-bit scalar */ |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 228 | Ity_F32, /* IEEE 754 float */ |
| 229 | Ity_F64, /* IEEE 754 double */ |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 230 | Ity_D32, /* 32-bit Decimal floating point */ |
| 231 | Ity_D64, /* 64-bit Decimal floating point */ |
| 232 | Ity_D128, /* 128-bit Decimal floating point */ |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 233 | Ity_F128, /* 128-bit floating point; implementation defined */ |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 234 | Ity_V128, /* 128-bit SIMD */ |
| 235 | Ity_V256 /* 256-bit SIMD */ |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 236 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 237 | IRType; |
| 238 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 239 | /* Pretty-print an IRType */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 240 | extern void ppIRType ( IRType ); |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 241 | |
| 242 | /* Get the size (in bytes) of an IRType */ |
| 243 | extern Int sizeofIRType ( IRType ); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 244 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 245 | |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 246 | /* ------------------ Endianness ------------------ */ |
| 247 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 248 | /* IREndness is used in load IRExprs and store IRStmts. */ |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 249 | typedef |
| 250 | enum { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 251 | Iend_LE=0x12000, /* little endian */ |
| 252 | Iend_BE /* big endian */ |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 253 | } |
| 254 | IREndness; |
| 255 | |
| 256 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 257 | /* ------------------ Constants ------------------ */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 258 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 259 | /* IRConsts are used within 'Const' and 'Exit' IRExprs. */ |
| 260 | |
| 261 | /* The various kinds of constant. */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 262 | typedef |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 263 | enum { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 264 | Ico_U1=0x13000, |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 265 | Ico_U8, |
| 266 | Ico_U16, |
| 267 | Ico_U32, |
| 268 | Ico_U64, |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 269 | Ico_F32, /* 32-bit IEEE754 floating */ |
| 270 | Ico_F32i, /* 32-bit unsigned int to be interpreted literally |
| 271 | as a IEEE754 single value. */ |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 272 | Ico_F64, /* 64-bit IEEE754 floating */ |
| 273 | Ico_F64i, /* 64-bit unsigned int to be interpreted literally |
| 274 | as a IEEE754 double value. */ |
sewardj | 37a505b | 2012-06-29 15:28:24 +0000 | [diff] [blame^] | 275 | Ico_V128, /* 128-bit restricted vector constant, with 1 bit |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 276 | (repeated 8 times) for each of the 16 x 1-byte lanes */ |
sewardj | 37a505b | 2012-06-29 15:28:24 +0000 | [diff] [blame^] | 277 | Ico_V256 /* 256-bit restricted vector constant, with 1 bit |
| 278 | (repeated 8 times) for each of the 32 x 1-byte lanes */ |
sewardj | 207557a | 2004-08-27 12:00:18 +0000 | [diff] [blame] | 279 | } |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 280 | IRConstTag; |
| 281 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 282 | /* A constant. Stored as a tagged union. 'tag' indicates what kind of |
| 283 | constant this is. 'Ico' is the union that holds the fields. If an |
| 284 | IRConst 'c' has c.tag equal to Ico_U32, then it's a 32-bit constant, |
| 285 | and its value can be accessed with 'c.Ico.U32'. */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 286 | typedef |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 287 | struct _IRConst { |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 288 | IRConstTag tag; |
| 289 | union { |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 290 | Bool U1; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 291 | UChar U8; |
| 292 | UShort U16; |
| 293 | UInt U32; |
| 294 | ULong U64; |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 295 | Float F32; |
| 296 | UInt F32i; |
sewardj | a58ea66 | 2004-08-15 03:12:41 +0000 | [diff] [blame] | 297 | Double F64; |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 298 | ULong F64i; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 299 | UShort V128; /* 16-bit value; see Ico_V128 comment above */ |
sewardj | 37a505b | 2012-06-29 15:28:24 +0000 | [diff] [blame^] | 300 | UInt V256; /* 32-bit value; see Ico_V256 comment above */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 301 | } Ico; |
| 302 | } |
| 303 | IRConst; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 304 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 305 | /* IRConst constructors */ |
sewardj | ba99931 | 2004-11-15 15:21:17 +0000 | [diff] [blame] | 306 | extern IRConst* IRConst_U1 ( Bool ); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 307 | extern IRConst* IRConst_U8 ( UChar ); |
| 308 | extern IRConst* IRConst_U16 ( UShort ); |
| 309 | extern IRConst* IRConst_U32 ( UInt ); |
| 310 | extern IRConst* IRConst_U64 ( ULong ); |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 311 | extern IRConst* IRConst_F32 ( Float ); |
| 312 | extern IRConst* IRConst_F32i ( UInt ); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 313 | extern IRConst* IRConst_F64 ( Double ); |
| 314 | extern IRConst* IRConst_F64i ( ULong ); |
sewardj | 1e6ad74 | 2004-12-02 16:16:11 +0000 | [diff] [blame] | 315 | extern IRConst* IRConst_V128 ( UShort ); |
sewardj | 37a505b | 2012-06-29 15:28:24 +0000 | [diff] [blame^] | 316 | extern IRConst* IRConst_V256 ( UInt ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 317 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 318 | /* Deep-copy an IRConst */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 319 | extern IRConst* deepCopyIRConst ( IRConst* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 320 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 321 | /* Pretty-print an IRConst */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 322 | extern void ppIRConst ( IRConst* ); |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 323 | |
| 324 | /* Compare two IRConsts for equality */ |
sewardj | 4345f7a | 2004-09-22 19:49:27 +0000 | [diff] [blame] | 325 | extern Bool eqIRConst ( IRConst*, IRConst* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 326 | |
| 327 | |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 328 | /* ------------------ Call targets ------------------ */ |
| 329 | |
| 330 | /* Describes a helper function to call. The name part is purely for |
sewardj | 7735254 | 2004-10-30 20:39:01 +0000 | [diff] [blame] | 331 | pretty printing and not actually used. regparms=n tells the back |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 332 | end that the callee has been declared |
sewardj | 03d9114 | 2011-03-14 12:35:18 +0000 | [diff] [blame] | 333 | "__attribute__((regparm(n)))", although indirectly using the |
| 334 | VEX_REGPARM(n) macro. On some targets (x86) the back end will need |
| 335 | to construct a non-standard sequence to call a function declared |
| 336 | like this. |
sewardj | 43c5646 | 2004-11-06 12:17:57 +0000 | [diff] [blame] | 337 | |
| 338 | mcx_mask is a sop to Memcheck. It indicates which args should be |
| 339 | considered 'always defined' when lazily computing definedness of |
| 340 | the result. Bit 0 of mcx_mask corresponds to args[0], bit 1 to |
| 341 | args[1], etc. If a bit is set, the corresponding arg is excluded |
| 342 | (hence "x" in "mcx") from definedness checking. |
| 343 | */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 344 | |
| 345 | typedef |
| 346 | struct { |
sewardj | 2d49b43 | 2005-02-01 00:37:06 +0000 | [diff] [blame] | 347 | Int regparms; |
| 348 | HChar* name; |
| 349 | void* addr; |
| 350 | UInt mcx_mask; |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 351 | } |
| 352 | IRCallee; |
| 353 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 354 | /* Create an IRCallee. */ |
sewardj | 2d49b43 | 2005-02-01 00:37:06 +0000 | [diff] [blame] | 355 | extern IRCallee* mkIRCallee ( Int regparms, HChar* name, void* addr ); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 356 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 357 | /* Deep-copy an IRCallee. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 358 | extern IRCallee* deepCopyIRCallee ( IRCallee* ); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 359 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 360 | /* Pretty-print an IRCallee. */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 361 | extern void ppIRCallee ( IRCallee* ); |
| 362 | |
| 363 | |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 364 | /* ------------------ Guest state arrays ------------------ */ |
| 365 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 366 | /* This describes a section of the guest state that we want to |
| 367 | be able to index at run time, so as to be able to describe |
| 368 | indexed or rotating register files on the guest. */ |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 369 | typedef |
| 370 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 371 | Int base; /* guest state offset of start of indexed area */ |
| 372 | IRType elemTy; /* type of each element in the indexed area */ |
| 373 | Int nElems; /* number of elements in the indexed area */ |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 374 | } |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 375 | IRRegArray; |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 376 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 377 | extern IRRegArray* mkIRRegArray ( Int, IRType, Int ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 378 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 379 | extern IRRegArray* deepCopyIRRegArray ( IRRegArray* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 380 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 381 | extern void ppIRRegArray ( IRRegArray* ); |
| 382 | extern Bool eqIRRegArray ( IRRegArray*, IRRegArray* ); |
sewardj | 2d3f77c | 2004-09-22 23:49:09 +0000 | [diff] [blame] | 383 | |
| 384 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 385 | /* ------------------ Temporaries ------------------ */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 386 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 387 | /* This represents a temporary, eg. t1. The IR optimiser relies on the |
| 388 | fact that IRTemps are 32-bit ints. Do not change them to be ints of |
| 389 | any other size. */ |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 390 | typedef UInt IRTemp; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 391 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 392 | /* Pretty-print an IRTemp. */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 393 | extern void ppIRTemp ( IRTemp ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 394 | |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 395 | #define IRTemp_INVALID ((IRTemp)0xFFFFFFFF) |
sewardj | fbcaf33 | 2004-07-08 01:46:01 +0000 | [diff] [blame] | 396 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 397 | |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 398 | /* --------------- Primops (arity 1,2,3 and 4) --------------- */ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 399 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 400 | /* Primitive operations that are used in Unop, Binop, Triop and Qop |
| 401 | IRExprs. Once we take into account integer, floating point and SIMD |
| 402 | operations of all the different sizes, there are quite a lot of them. |
| 403 | Most instructions supported by the architectures that Vex supports |
| 404 | (x86, PPC, etc) are represented. Some more obscure ones (eg. cpuid) |
| 405 | are not; they are instead handled with dirty helpers that emulate |
| 406 | their functionality. Such obscure ones are thus not directly visible |
| 407 | in the IR, but their effects on guest state (memory and registers) |
| 408 | are made visible via the annotations in IRDirty structures. |
| 409 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 410 | typedef |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 411 | enum { |
sewardj | 71a35e7 | 2005-05-03 12:20:15 +0000 | [diff] [blame] | 412 | /* -- Do not change this ordering. The IR generators rely on |
| 413 | (eg) Iop_Add64 == IopAdd8 + 3. -- */ |
| 414 | |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 415 | Iop_INVALID=0x14000, |
sewardj | 66de227 | 2004-07-16 21:19:05 +0000 | [diff] [blame] | 416 | Iop_Add8, Iop_Add16, Iop_Add32, Iop_Add64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 417 | Iop_Sub8, Iop_Sub16, Iop_Sub32, Iop_Sub64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 418 | /* Signless mul. MullS/MullU is elsewhere. */ |
| 419 | Iop_Mul8, Iop_Mul16, Iop_Mul32, Iop_Mul64, |
| 420 | Iop_Or8, Iop_Or16, Iop_Or32, Iop_Or64, |
| 421 | Iop_And8, Iop_And16, Iop_And32, Iop_And64, |
| 422 | Iop_Xor8, Iop_Xor16, Iop_Xor32, Iop_Xor64, |
| 423 | Iop_Shl8, Iop_Shl16, Iop_Shl32, Iop_Shl64, |
| 424 | Iop_Shr8, Iop_Shr16, Iop_Shr32, Iop_Shr64, |
| 425 | Iop_Sar8, Iop_Sar16, Iop_Sar32, Iop_Sar64, |
sewardj | e90ad6a | 2004-07-10 19:02:10 +0000 | [diff] [blame] | 426 | /* Integer comparisons. */ |
| 427 | Iop_CmpEQ8, Iop_CmpEQ16, Iop_CmpEQ32, Iop_CmpEQ64, |
| 428 | Iop_CmpNE8, Iop_CmpNE16, Iop_CmpNE32, Iop_CmpNE64, |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 429 | /* Tags for unary ops */ |
| 430 | Iop_Not8, Iop_Not16, Iop_Not32, Iop_Not64, |
sewardj | 71a35e7 | 2005-05-03 12:20:15 +0000 | [diff] [blame] | 431 | |
sewardj | 1fb8c92 | 2009-07-12 12:56:53 +0000 | [diff] [blame] | 432 | /* Exactly like CmpEQ8/16/32/64, but carrying the additional |
| 433 | hint that these compute the success/failure of a CAS |
| 434 | operation, and hence are almost certainly applied to two |
| 435 | copies of the same value, which in turn has implications for |
| 436 | Memcheck's instrumentation. */ |
| 437 | Iop_CasCmpEQ8, Iop_CasCmpEQ16, Iop_CasCmpEQ32, Iop_CasCmpEQ64, |
| 438 | Iop_CasCmpNE8, Iop_CasCmpNE16, Iop_CasCmpNE32, Iop_CasCmpNE64, |
| 439 | |
sewardj | 71a35e7 | 2005-05-03 12:20:15 +0000 | [diff] [blame] | 440 | /* -- Ordering not important after here. -- */ |
| 441 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 442 | /* Widening multiplies */ |
sewardj | 9b96767 | 2005-02-08 11:13:09 +0000 | [diff] [blame] | 443 | Iop_MullS8, Iop_MullS16, Iop_MullS32, Iop_MullS64, |
| 444 | Iop_MullU8, Iop_MullU16, Iop_MullU32, Iop_MullU64, |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 445 | |
sewardj | ce646f2 | 2004-08-31 23:55:54 +0000 | [diff] [blame] | 446 | /* Wierdo integer stuff */ |
sewardj | f53b735 | 2005-04-06 20:01:56 +0000 | [diff] [blame] | 447 | Iop_Clz64, Iop_Clz32, /* count leading zeroes */ |
| 448 | Iop_Ctz64, Iop_Ctz32, /* count trailing zeros */ |
| 449 | /* Ctz64/Ctz32/Clz64/Clz32 are UNDEFINED when given arguments of |
| 450 | zero. You must ensure they are never given a zero argument. |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 451 | */ |
| 452 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 453 | /* Standard integer comparisons */ |
sewardj | 9854007 | 2005-04-26 01:52:01 +0000 | [diff] [blame] | 454 | Iop_CmpLT32S, Iop_CmpLT64S, |
| 455 | Iop_CmpLE32S, Iop_CmpLE64S, |
| 456 | Iop_CmpLT32U, Iop_CmpLT64U, |
| 457 | Iop_CmpLE32U, Iop_CmpLE64U, |
sewardj | 343b9d0 | 2005-01-31 18:08:45 +0000 | [diff] [blame] | 458 | |
sewardj | 0033ddc | 2005-04-26 23:34:34 +0000 | [diff] [blame] | 459 | /* As a sop to Valgrind-Memcheck, the following are useful. */ |
| 460 | Iop_CmpNEZ8, Iop_CmpNEZ16, Iop_CmpNEZ32, Iop_CmpNEZ64, |
sewardj | eb17e49 | 2007-08-25 23:07:44 +0000 | [diff] [blame] | 461 | Iop_CmpwNEZ32, Iop_CmpwNEZ64, /* all-0s -> all-Os; other -> all-1s */ |
| 462 | Iop_Left8, Iop_Left16, Iop_Left32, Iop_Left64, /* \x -> x | -x */ |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 463 | Iop_Max32U, /* unsigned max */ |
sewardj | 0033ddc | 2005-04-26 23:34:34 +0000 | [diff] [blame] | 464 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 465 | /* PowerPC-style 3-way integer comparisons. Without them it is |
| 466 | difficult to simulate PPC efficiently. |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 467 | op(x,y) | x < y = 0x8 else |
| 468 | | x > y = 0x4 else |
| 469 | | x == y = 0x2 |
| 470 | */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 471 | Iop_CmpORD32U, Iop_CmpORD64U, |
| 472 | Iop_CmpORD32S, Iop_CmpORD64S, |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 473 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 474 | /* Division */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 475 | /* TODO: clarify semantics wrt rounding, negative values, whatever */ |
cerion | 5c8a0cb | 2005-02-03 13:59:46 +0000 | [diff] [blame] | 476 | Iop_DivU32, // :: I32,I32 -> I32 (simple div, no mod) |
| 477 | Iop_DivS32, // ditto, signed |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 478 | Iop_DivU64, // :: I64,I64 -> I64 (simple div, no mod) |
| 479 | Iop_DivS64, // ditto, signed |
sewardj | e71e56a | 2011-09-05 12:11:06 +0000 | [diff] [blame] | 480 | Iop_DivU64E, // :: I64,I64 -> I64 (dividend is 64-bit arg (hi) concat with 64 0's (low)) |
| 481 | Iop_DivS64E, // ditto, signed |
sewardj | 4aa412a | 2011-07-24 14:13:21 +0000 | [diff] [blame] | 482 | Iop_DivU32E, // :: I32,I32 -> I32 (dividend is 32-bit arg (hi) concat with 32 0's (low)) |
sewardj | e71e56a | 2011-09-05 12:11:06 +0000 | [diff] [blame] | 483 | Iop_DivS32E, // ditto, signed |
cerion | 5c8a0cb | 2005-02-03 13:59:46 +0000 | [diff] [blame] | 484 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 485 | Iop_DivModU64to32, // :: I64,I32 -> I64 |
| 486 | // of which lo half is div and hi half is mod |
| 487 | Iop_DivModS64to32, // ditto, signed |
sewardj | 89d4e98 | 2004-09-12 19:14:46 +0000 | [diff] [blame] | 488 | |
sewardj | 343b9d0 | 2005-01-31 18:08:45 +0000 | [diff] [blame] | 489 | Iop_DivModU128to64, // :: V128,I64 -> V128 |
| 490 | // of which lo half is div and hi half is mod |
| 491 | Iop_DivModS128to64, // ditto, signed |
| 492 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 493 | Iop_DivModS64to64, // :: I64,I64 -> I128 |
| 494 | // of which lo half is div and hi half is mod |
| 495 | |
sewardj | 0033ddc | 2005-04-26 23:34:34 +0000 | [diff] [blame] | 496 | /* Integer conversions. Some of these are redundant (eg |
| 497 | Iop_64to8 is the same as Iop_64to32 and then Iop_32to8), but |
| 498 | having a complete set reduces the typical dynamic size of IR |
| 499 | and makes the instruction selectors easier to write. */ |
| 500 | |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 501 | /* Widening conversions */ |
sewardj | 0033ddc | 2005-04-26 23:34:34 +0000 | [diff] [blame] | 502 | Iop_8Uto16, Iop_8Uto32, Iop_8Uto64, |
| 503 | Iop_16Uto32, Iop_16Uto64, |
| 504 | Iop_32Uto64, |
| 505 | Iop_8Sto16, Iop_8Sto32, Iop_8Sto64, |
| 506 | Iop_16Sto32, Iop_16Sto64, |
| 507 | Iop_32Sto64, |
| 508 | |
sewardj | a238471 | 2004-07-29 14:36:40 +0000 | [diff] [blame] | 509 | /* Narrowing conversions */ |
sewardj | 0033ddc | 2005-04-26 23:34:34 +0000 | [diff] [blame] | 510 | Iop_64to8, Iop_32to8, Iop_64to16, |
sewardj | b81f8b3 | 2004-07-30 10:17:50 +0000 | [diff] [blame] | 511 | /* 8 <-> 16 bit conversions */ |
| 512 | Iop_16to8, // :: I16 -> I8, low half |
| 513 | Iop_16HIto8, // :: I16 -> I8, high half |
| 514 | Iop_8HLto16, // :: (I8,I8) -> I16 |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 515 | /* 16 <-> 32 bit conversions */ |
| 516 | Iop_32to16, // :: I32 -> I16, low half |
| 517 | Iop_32HIto16, // :: I32 -> I16, high half |
| 518 | Iop_16HLto32, // :: (I16,I16) -> I32 |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 519 | /* 32 <-> 64 bit conversions */ |
sewardj | 8c7f1ab | 2004-07-29 20:31:09 +0000 | [diff] [blame] | 520 | Iop_64to32, // :: I64 -> I32, low half |
sewardj | 9690d92 | 2004-07-14 01:39:17 +0000 | [diff] [blame] | 521 | Iop_64HIto32, // :: I64 -> I32, high half |
| 522 | Iop_32HLto64, // :: (I32,I32) -> I64 |
sewardj | 9b96767 | 2005-02-08 11:13:09 +0000 | [diff] [blame] | 523 | /* 64 <-> 128 bit conversions */ |
| 524 | Iop_128to64, // :: I128 -> I64, low half |
| 525 | Iop_128HIto64, // :: I128 -> I64, high half |
| 526 | Iop_64HLto128, // :: (I64,I64) -> I128 |
sewardj | cf780b4 | 2004-07-13 18:42:17 +0000 | [diff] [blame] | 527 | /* 1-bit stuff */ |
sewardj | 6e797c5 | 2004-10-13 15:20:17 +0000 | [diff] [blame] | 528 | Iop_Not1, /* :: Ity_Bit -> Ity_Bit */ |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 529 | Iop_32to1, /* :: Ity_I32 -> Ity_Bit, just select bit[0] */ |
sewardj | 291a7e8 | 2005-04-27 11:42:44 +0000 | [diff] [blame] | 530 | Iop_64to1, /* :: Ity_I64 -> Ity_Bit, just select bit[0] */ |
| 531 | Iop_1Uto8, /* :: Ity_Bit -> Ity_I8, unsigned widen */ |
sewardj | 84ff065 | 2004-08-23 16:16:08 +0000 | [diff] [blame] | 532 | Iop_1Uto32, /* :: Ity_Bit -> Ity_I32, unsigned widen */ |
sewardj | 291a7e8 | 2005-04-27 11:42:44 +0000 | [diff] [blame] | 533 | Iop_1Uto64, /* :: Ity_Bit -> Ity_I64, unsigned widen */ |
sewardj | fd33277 | 2004-11-09 16:01:40 +0000 | [diff] [blame] | 534 | Iop_1Sto8, /* :: Ity_Bit -> Ity_I8, signed widen */ |
sewardj | 8eda630 | 2004-11-05 01:55:46 +0000 | [diff] [blame] | 535 | Iop_1Sto16, /* :: Ity_Bit -> Ity_I16, signed widen */ |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 536 | Iop_1Sto32, /* :: Ity_Bit -> Ity_I32, signed widen */ |
sewardj | b5874aa | 2004-11-04 16:57:50 +0000 | [diff] [blame] | 537 | Iop_1Sto64, /* :: Ity_Bit -> Ity_I64, signed widen */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 538 | |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 539 | /* ------ Floating point. We try to be IEEE754 compliant. ------ */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 540 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 541 | /* --- Simple stuff as mandated by 754. --- */ |
sewardj | cfded9a | 2004-09-09 11:44:16 +0000 | [diff] [blame] | 542 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 543 | /* Binary operations, with rounding. */ |
| 544 | /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */ |
| 545 | Iop_AddF64, Iop_SubF64, Iop_MulF64, Iop_DivF64, |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 546 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 547 | /* :: IRRoundingMode(I32) x F32 x F32 -> F32 */ |
| 548 | Iop_AddF32, Iop_SubF32, Iop_MulF32, Iop_DivF32, |
| 549 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 550 | /* Variants of the above which produce a 64-bit result but which |
| 551 | round their result to a IEEE float range first. */ |
| 552 | /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */ |
| 553 | Iop_AddF64r32, Iop_SubF64r32, Iop_MulF64r32, Iop_DivF64r32, |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 554 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 555 | /* Unary operations, without rounding. */ |
| 556 | /* :: F64 -> F64 */ |
| 557 | Iop_NegF64, Iop_AbsF64, |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 558 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 559 | /* :: F32 -> F32 */ |
| 560 | Iop_NegF32, Iop_AbsF32, |
| 561 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 562 | /* Unary operations, with rounding. */ |
| 563 | /* :: IRRoundingMode(I32) x F64 -> F64 */ |
| 564 | Iop_SqrtF64, Iop_SqrtF64r32, |
sewardj | baf971a | 2006-01-27 15:09:35 +0000 | [diff] [blame] | 565 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 566 | /* :: IRRoundingMode(I32) x F32 -> F32 */ |
| 567 | Iop_SqrtF32, |
| 568 | |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 569 | /* Comparison, yielding GT/LT/EQ/UN(ordered), as per the following: |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 570 | 0x45 Unordered |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 571 | 0x01 LT |
| 572 | 0x00 GT |
sewardj | 883b00b | 2004-09-11 09:30:24 +0000 | [diff] [blame] | 573 | 0x40 EQ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 574 | This just happens to be the Intel encoding. The values |
| 575 | are recorded in the type IRCmpF64Result. |
| 576 | */ |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 577 | /* :: F64 x F64 -> IRCmpF64Result(I32) */ |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 578 | Iop_CmpF64, |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 579 | Iop_CmpF32, |
| 580 | Iop_CmpF128, |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 581 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 582 | /* --- Int to/from FP conversions. --- */ |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 583 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 584 | /* For the most part, these take a first argument :: Ity_I32 (as |
| 585 | IRRoundingMode) which is an indication of the rounding mode |
| 586 | to use, as per the following encoding ("the standard |
| 587 | encoding"): |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 588 | 00b to nearest (the default) |
| 589 | 01b to -infinity |
| 590 | 10b to +infinity |
| 591 | 11b to zero |
| 592 | This just happens to be the Intel encoding. For reference only, |
| 593 | the PPC encoding is: |
| 594 | 00b to nearest (the default) |
| 595 | 01b to zero |
| 596 | 10b to +infinity |
| 597 | 11b to -infinity |
| 598 | Any PPC -> IR front end will have to translate these PPC |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 599 | encodings, as encoded in the guest state, to the standard |
| 600 | encodings, to pass to the primops. |
| 601 | For reference only, the ARM VFP encoding is: |
| 602 | 00b to nearest |
| 603 | 01b to +infinity |
| 604 | 10b to -infinity |
| 605 | 11b to zero |
| 606 | Again, this will have to be converted to the standard encoding |
| 607 | to pass to primops. |
sewardj | 8f3debf | 2004-09-08 23:42:23 +0000 | [diff] [blame] | 608 | |
| 609 | If one of these conversions gets an out-of-range condition, |
| 610 | or a NaN, as an argument, the result is host-defined. On x86 |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 611 | the "integer indefinite" value 0x80..00 is produced. On PPC |
| 612 | it is either 0x80..00 or 0x7F..FF depending on the sign of |
| 613 | the argument. |
| 614 | |
| 615 | On ARMvfp, when converting to a signed integer result, the |
| 616 | overflow result is 0x80..00 for negative args and 0x7F..FF |
| 617 | for positive args. For unsigned integer results it is |
| 618 | 0x00..00 and 0xFF..FF respectively. |
sewardj | 52ace3e | 2004-09-11 17:10:08 +0000 | [diff] [blame] | 619 | |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 620 | Rounding is required whenever the destination type cannot |
| 621 | represent exactly all values of the source type. |
| 622 | */ |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 623 | Iop_F64toI16S, /* IRRoundingMode(I32) x F64 -> signed I16 */ |
| 624 | Iop_F64toI32S, /* IRRoundingMode(I32) x F64 -> signed I32 */ |
| 625 | Iop_F64toI64S, /* IRRoundingMode(I32) x F64 -> signed I64 */ |
sewardj | 4aa412a | 2011-07-24 14:13:21 +0000 | [diff] [blame] | 626 | Iop_F64toI64U, /* IRRoundingMode(I32) x F64 -> unsigned I64 */ |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 627 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 628 | Iop_F64toI32U, /* IRRoundingMode(I32) x F64 -> unsigned I32 */ |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 629 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 630 | Iop_I16StoF64, /* signed I16 -> F64 */ |
| 631 | Iop_I32StoF64, /* signed I32 -> F64 */ |
| 632 | Iop_I64StoF64, /* IRRoundingMode(I32) x signed I64 -> F64 */ |
sewardj | 66d5ef2 | 2011-04-15 11:55:00 +0000 | [diff] [blame] | 633 | Iop_I64UtoF64, /* IRRoundingMode(I32) x unsigned I64 -> F64 */ |
| 634 | Iop_I64UtoF32, /* IRRoundingMode(I32) x unsigned I64 -> F32 */ |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 635 | |
| 636 | Iop_I32UtoF64, /* unsigned I32 -> F64 */ |
| 637 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 638 | Iop_F32toI16S, /* IRRoundingMode(I32) x F32 -> signed I16 */ |
| 639 | Iop_F32toI32S, /* IRRoundingMode(I32) x F32 -> signed I32 */ |
| 640 | Iop_F32toI64S, /* IRRoundingMode(I32) x F32 -> signed I64 */ |
| 641 | |
| 642 | Iop_I16StoF32, /* signed I16 -> F32 */ |
| 643 | Iop_I32StoF32, /* IRRoundingMode(I32) x signed I32 -> F32 */ |
| 644 | Iop_I64StoF32, /* IRRoundingMode(I32) x signed I64 -> F32 */ |
| 645 | |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 646 | /* Conversion between floating point formats */ |
sewardj | 3bca906 | 2004-12-04 14:36:09 +0000 | [diff] [blame] | 647 | Iop_F32toF64, /* F32 -> F64 */ |
| 648 | Iop_F64toF32, /* IRRoundingMode(I32) x F64 -> F32 */ |
sewardj | 4cb918d | 2004-12-03 19:43:31 +0000 | [diff] [blame] | 649 | |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 650 | /* Reinterpretation. Take an F64 and produce an I64 with |
| 651 | the same bit pattern, or vice versa. */ |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 652 | Iop_ReinterpF64asI64, Iop_ReinterpI64asF64, |
sewardj | fc1b541 | 2007-01-09 15:20:07 +0000 | [diff] [blame] | 653 | Iop_ReinterpF32asI32, Iop_ReinterpI32asF32, |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 654 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 655 | /* Support for 128-bit floating point */ |
| 656 | Iop_F64HLtoF128,/* (high half of F128,low half of F128) -> F128 */ |
| 657 | Iop_F128HItoF64,/* F128 -> high half of F128 into a F64 register */ |
| 658 | Iop_F128LOtoF64,/* F128 -> low half of F128 into a F64 register */ |
| 659 | |
| 660 | /* :: IRRoundingMode(I32) x F128 x F128 -> F128 */ |
| 661 | Iop_AddF128, Iop_SubF128, Iop_MulF128, Iop_DivF128, |
| 662 | |
| 663 | /* :: F128 -> F128 */ |
| 664 | Iop_NegF128, Iop_AbsF128, |
| 665 | |
| 666 | /* :: IRRoundingMode(I32) x F128 -> F128 */ |
| 667 | Iop_SqrtF128, |
| 668 | |
| 669 | Iop_I32StoF128, /* signed I32 -> F128 */ |
| 670 | Iop_I64StoF128, /* signed I64 -> F128 */ |
| 671 | Iop_F32toF128, /* F32 -> F128 */ |
| 672 | Iop_F64toF128, /* F64 -> F128 */ |
| 673 | |
| 674 | Iop_F128toI32S, /* IRRoundingMode(I32) x F128 -> signed I32 */ |
| 675 | Iop_F128toI64S, /* IRRoundingMode(I32) x F128 -> signed I64 */ |
| 676 | Iop_F128toF64, /* IRRoundingMode(I32) x F128 -> F64 */ |
| 677 | Iop_F128toF32, /* IRRoundingMode(I32) x F128 -> F32 */ |
| 678 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 679 | /* --- guest x86/amd64 specifics, not mandated by 754. --- */ |
| 680 | |
| 681 | /* Binary ops, with rounding. */ |
| 682 | /* :: IRRoundingMode(I32) x F64 x F64 -> F64 */ |
| 683 | Iop_AtanF64, /* FPATAN, arctan(arg1/arg2) */ |
| 684 | Iop_Yl2xF64, /* FYL2X, arg1 * log2(arg2) */ |
| 685 | Iop_Yl2xp1F64, /* FYL2XP1, arg1 * log2(arg2+1.0) */ |
| 686 | Iop_PRemF64, /* FPREM, non-IEEE remainder(arg1/arg2) */ |
| 687 | Iop_PRemC3210F64, /* C3210 flags resulting from FPREM, :: I32 */ |
| 688 | Iop_PRem1F64, /* FPREM1, IEEE remainder(arg1/arg2) */ |
| 689 | Iop_PRem1C3210F64, /* C3210 flags resulting from FPREM1, :: I32 */ |
| 690 | Iop_ScaleF64, /* FSCALE, arg1 * (2^RoundTowardsZero(arg2)) */ |
| 691 | /* Note that on x86 guest, PRem1{C3210} has the same behaviour |
| 692 | as the IEEE mandated RemF64, except it is limited in the |
| 693 | range of its operand. Hence the partialness. */ |
| 694 | |
| 695 | /* Unary ops, with rounding. */ |
| 696 | /* :: IRRoundingMode(I32) x F64 -> F64 */ |
| 697 | Iop_SinF64, /* FSIN */ |
| 698 | Iop_CosF64, /* FCOS */ |
| 699 | Iop_TanF64, /* FTAN */ |
| 700 | Iop_2xm1F64, /* (2^arg - 1.0) */ |
| 701 | Iop_RoundF64toInt, /* F64 value to nearest integral value (still |
| 702 | as F64) */ |
sewardj | d15b597 | 2010-06-27 09:06:34 +0000 | [diff] [blame] | 703 | Iop_RoundF32toInt, /* F32 value to nearest integral value (still |
| 704 | as F32) */ |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 705 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 706 | /* --- guest s390 specifics, not mandated by 754. --- */ |
| 707 | |
| 708 | /* Fused multiply-add/sub */ |
| 709 | /* :: IRRoundingMode(I32) x F32 x F32 x F32 -> F32 |
| 710 | (computes op3 * op2 +/- op1 */ |
| 711 | Iop_MAddF32, Iop_MSubF32, |
| 712 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 713 | /* --- guest ppc32/64 specifics, not mandated by 754. --- */ |
| 714 | |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 715 | /* Ternary operations, with rounding. */ |
| 716 | /* Fused multiply-add/sub, with 112-bit intermediate |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 717 | precision for ppc. |
| 718 | Also used to implement fused multiply-add/sub for s390. */ |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 719 | /* :: IRRoundingMode(I32) x F64 x F64 x F64 -> F64 |
| 720 | (computes arg2 * arg3 +/- arg4) */ |
| 721 | Iop_MAddF64, Iop_MSubF64, |
| 722 | |
| 723 | /* Variants of the above which produce a 64-bit result but which |
| 724 | round their result to a IEEE float range first. */ |
| 725 | /* :: IRRoundingMode(I32) x F64 x F64 x F64 -> F64 */ |
| 726 | Iop_MAddF64r32, Iop_MSubF64r32, |
| 727 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 728 | /* :: F64 -> F64 */ |
| 729 | Iop_Est5FRSqrt, /* reciprocal square root estimate, 5 good bits */ |
sewardj | 0f1ef86 | 2008-08-08 08:37:06 +0000 | [diff] [blame] | 730 | Iop_RoundF64toF64_NEAREST, /* frin */ |
| 731 | Iop_RoundF64toF64_NegINF, /* frim */ |
| 732 | Iop_RoundF64toF64_PosINF, /* frip */ |
| 733 | Iop_RoundF64toF64_ZERO, /* friz */ |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 734 | |
| 735 | /* :: F64 -> F32 */ |
| 736 | Iop_TruncF64asF32, /* do F64->F32 truncation as per 'fsts' */ |
| 737 | |
| 738 | /* :: IRRoundingMode(I32) x F64 -> F64 */ |
| 739 | Iop_RoundF64toF32, /* round F64 to nearest F32 value (still as F64) */ |
| 740 | /* NB: pretty much the same as Iop_F64toF32, except no change |
| 741 | of type. */ |
| 742 | |
| 743 | /* :: F64 -> I32 */ |
| 744 | Iop_CalcFPRF, /* Calc 5 fpscr[FPRF] bits (Class, <, =, >, Unord) |
| 745 | from FP result */ |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 746 | |
sewardj | e2ea176 | 2010-09-22 00:56:37 +0000 | [diff] [blame] | 747 | /* ------------------ 32-bit SIMD Integer ------------------ */ |
| 748 | |
| 749 | /* 16x2 add/sub, also signed/unsigned saturating variants */ |
| 750 | Iop_Add16x2, Iop_Sub16x2, |
| 751 | Iop_QAdd16Sx2, Iop_QAdd16Ux2, |
| 752 | Iop_QSub16Sx2, Iop_QSub16Ux2, |
| 753 | |
| 754 | /* 16x2 signed/unsigned halving add/sub. For each lane, these |
| 755 | compute bits 16:1 of (eg) sx(argL) + sx(argR), |
| 756 | or zx(argL) - zx(argR) etc. */ |
| 757 | Iop_HAdd16Ux2, Iop_HAdd16Sx2, |
| 758 | Iop_HSub16Ux2, Iop_HSub16Sx2, |
| 759 | |
| 760 | /* 8x4 add/sub, also signed/unsigned saturating variants */ |
| 761 | Iop_Add8x4, Iop_Sub8x4, |
| 762 | Iop_QAdd8Sx4, Iop_QAdd8Ux4, |
| 763 | Iop_QSub8Sx4, Iop_QSub8Ux4, |
| 764 | |
| 765 | /* 8x4 signed/unsigned halving add/sub. For each lane, these |
| 766 | compute bits 8:1 of (eg) sx(argL) + sx(argR), |
| 767 | or zx(argL) - zx(argR) etc. */ |
| 768 | Iop_HAdd8Ux4, Iop_HAdd8Sx4, |
| 769 | Iop_HSub8Ux4, Iop_HSub8Sx4, |
| 770 | |
sewardj | 310d6b2 | 2010-10-18 16:29:40 +0000 | [diff] [blame] | 771 | /* 8x4 sum of absolute unsigned differences. */ |
| 772 | Iop_Sad8Ux4, |
| 773 | |
sewardj | e2ea176 | 2010-09-22 00:56:37 +0000 | [diff] [blame] | 774 | /* MISC (vector integer cmp != 0) */ |
| 775 | Iop_CmpNEZ16x2, Iop_CmpNEZ8x4, |
| 776 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 777 | /* ------------------ 64-bit SIMD FP ------------------------ */ |
| 778 | |
| 779 | /* Convertion to/from int */ |
| 780 | Iop_I32UtoFx2, Iop_I32StoFx2, /* I32x4 -> F32x4 */ |
| 781 | Iop_FtoI32Ux2_RZ, Iop_FtoI32Sx2_RZ, /* F32x4 -> I32x4 */ |
| 782 | /* Fixed32 format is floating-point number with fixed number of fraction |
| 783 | bits. The number of fraction bits is passed as a second argument of |
| 784 | type I8. */ |
| 785 | Iop_F32ToFixed32Ux2_RZ, Iop_F32ToFixed32Sx2_RZ, /* fp -> fixed-point */ |
| 786 | Iop_Fixed32UToF32x2_RN, Iop_Fixed32SToF32x2_RN, /* fixed-point -> fp */ |
| 787 | |
| 788 | /* Binary operations */ |
| 789 | Iop_Max32Fx2, Iop_Min32Fx2, |
| 790 | /* Pairwise Min and Max. See integer pairwise operations for more |
| 791 | details. */ |
| 792 | Iop_PwMax32Fx2, Iop_PwMin32Fx2, |
| 793 | /* Note: For the following compares, the arm front-end assumes a |
| 794 | nan in a lane of either argument returns zero for that lane. */ |
| 795 | Iop_CmpEQ32Fx2, Iop_CmpGT32Fx2, Iop_CmpGE32Fx2, |
| 796 | |
| 797 | /* Vector Reciprocal Estimate finds an approximate reciprocal of each |
| 798 | element in the operand vector, and places the results in the destination |
| 799 | vector. */ |
| 800 | Iop_Recip32Fx2, |
| 801 | |
| 802 | /* Vector Reciprocal Step computes (2.0 - arg1 * arg2). |
| 803 | Note, that if one of the arguments is zero and another one is infinity |
| 804 | of arbitrary sign the result of the operation is 2.0. */ |
| 805 | Iop_Recps32Fx2, |
| 806 | |
| 807 | /* Vector Reciprocal Square Root Estimate finds an approximate reciprocal |
| 808 | square root of each element in the operand vector. */ |
| 809 | Iop_Rsqrte32Fx2, |
| 810 | |
| 811 | /* Vector Reciprocal Square Root Step computes (3.0 - arg1 * arg2) / 2.0. |
| 812 | Note, that of one of the arguments is zero and another one is infiinty |
| 813 | of arbitrary sign the result of the operation is 1.5. */ |
| 814 | Iop_Rsqrts32Fx2, |
| 815 | |
| 816 | /* Unary */ |
| 817 | Iop_Neg32Fx2, Iop_Abs32Fx2, |
| 818 | |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 819 | /* ------------------ 64-bit SIMD Integer. ------------------ */ |
| 820 | |
| 821 | /* MISC (vector integer cmp != 0) */ |
sewardj | 1806918 | 2005-01-13 19:16:04 +0000 | [diff] [blame] | 822 | Iop_CmpNEZ8x8, Iop_CmpNEZ16x4, Iop_CmpNEZ32x2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 823 | |
| 824 | /* ADDITION (normal / unsigned sat / signed sat) */ |
| 825 | Iop_Add8x8, Iop_Add16x4, Iop_Add32x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 826 | Iop_QAdd8Ux8, Iop_QAdd16Ux4, Iop_QAdd32Ux2, Iop_QAdd64Ux1, |
| 827 | Iop_QAdd8Sx8, Iop_QAdd16Sx4, Iop_QAdd32Sx2, Iop_QAdd64Sx1, |
| 828 | |
| 829 | /* PAIRWISE operations */ |
| 830 | /* Iop_PwFoo16x4( [a,b,c,d], [e,f,g,h] ) = |
| 831 | [Foo16(a,b), Foo16(c,d), Foo16(e,f), Foo16(g,h)] */ |
| 832 | Iop_PwAdd8x8, Iop_PwAdd16x4, Iop_PwAdd32x2, |
| 833 | Iop_PwMax8Sx8, Iop_PwMax16Sx4, Iop_PwMax32Sx2, |
| 834 | Iop_PwMax8Ux8, Iop_PwMax16Ux4, Iop_PwMax32Ux2, |
| 835 | Iop_PwMin8Sx8, Iop_PwMin16Sx4, Iop_PwMin32Sx2, |
| 836 | Iop_PwMin8Ux8, Iop_PwMin16Ux4, Iop_PwMin32Ux2, |
| 837 | /* Longening variant is unary. The resulting vector contains two times |
| 838 | less elements than operand, but they are two times wider. |
| 839 | Example: |
| 840 | Iop_PAddL16Ux4( [a,b,c,d] ) = [a+b,c+d] |
| 841 | where a+b and c+d are unsigned 32-bit values. */ |
| 842 | Iop_PwAddL8Ux8, Iop_PwAddL16Ux4, Iop_PwAddL32Ux2, |
| 843 | Iop_PwAddL8Sx8, Iop_PwAddL16Sx4, Iop_PwAddL32Sx2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 844 | |
| 845 | /* SUBTRACTION (normal / unsigned sat / signed sat) */ |
| 846 | Iop_Sub8x8, Iop_Sub16x4, Iop_Sub32x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 847 | Iop_QSub8Ux8, Iop_QSub16Ux4, Iop_QSub32Ux2, Iop_QSub64Ux1, |
| 848 | Iop_QSub8Sx8, Iop_QSub16Sx4, Iop_QSub32Sx2, Iop_QSub64Sx1, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 849 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 850 | /* ABSOLUTE VALUE */ |
| 851 | Iop_Abs8x8, Iop_Abs16x4, Iop_Abs32x2, |
| 852 | |
| 853 | /* MULTIPLICATION (normal / high half of signed/unsigned / plynomial ) */ |
| 854 | Iop_Mul8x8, Iop_Mul16x4, Iop_Mul32x2, |
| 855 | Iop_Mul32Fx2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 856 | Iop_MulHi16Ux4, |
| 857 | Iop_MulHi16Sx4, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 858 | /* Plynomial multiplication treats it's arguments as coefficients of |
| 859 | polynoms over {0, 1}. */ |
| 860 | Iop_PolynomialMul8x8, |
| 861 | |
| 862 | /* Vector Saturating Doubling Multiply Returning High Half and |
| 863 | Vector Saturating Rounding Doubling Multiply Returning High Half */ |
| 864 | /* These IROp's multiply corresponding elements in two vectors, double |
| 865 | the results, and place the most significant half of the final results |
| 866 | in the destination vector. The results are truncated or rounded. If |
| 867 | any of the results overflow, they are saturated. */ |
| 868 | Iop_QDMulHi16Sx4, Iop_QDMulHi32Sx2, |
| 869 | Iop_QRDMulHi16Sx4, Iop_QRDMulHi32Sx2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 870 | |
sewardj | 5ce5fd6 | 2005-04-19 23:06:11 +0000 | [diff] [blame] | 871 | /* AVERAGING: note: (arg1 + arg2 + 1) >>u 1 */ |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 872 | Iop_Avg8Ux8, |
| 873 | Iop_Avg16Ux4, |
| 874 | |
| 875 | /* MIN/MAX */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 876 | Iop_Max8Sx8, Iop_Max16Sx4, Iop_Max32Sx2, |
| 877 | Iop_Max8Ux8, Iop_Max16Ux4, Iop_Max32Ux2, |
| 878 | Iop_Min8Sx8, Iop_Min16Sx4, Iop_Min32Sx2, |
| 879 | Iop_Min8Ux8, Iop_Min16Ux4, Iop_Min32Ux2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 880 | |
| 881 | /* COMPARISON */ |
| 882 | Iop_CmpEQ8x8, Iop_CmpEQ16x4, Iop_CmpEQ32x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 883 | Iop_CmpGT8Ux8, Iop_CmpGT16Ux4, Iop_CmpGT32Ux2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 884 | Iop_CmpGT8Sx8, Iop_CmpGT16Sx4, Iop_CmpGT32Sx2, |
| 885 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 886 | /* COUNT ones / leading zeroes / leading sign bits (not including topmost |
| 887 | bit) */ |
| 888 | Iop_Cnt8x8, |
| 889 | Iop_Clz8Sx8, Iop_Clz16Sx4, Iop_Clz32Sx2, |
| 890 | Iop_Cls8Sx8, Iop_Cls16Sx4, Iop_Cls32Sx2, |
| 891 | |
| 892 | /* VECTOR x VECTOR SHIFT / ROTATE */ |
| 893 | Iop_Shl8x8, Iop_Shl16x4, Iop_Shl32x2, |
| 894 | Iop_Shr8x8, Iop_Shr16x4, Iop_Shr32x2, |
| 895 | Iop_Sar8x8, Iop_Sar16x4, Iop_Sar32x2, |
| 896 | Iop_Sal8x8, Iop_Sal16x4, Iop_Sal32x2, Iop_Sal64x1, |
| 897 | |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 898 | /* VECTOR x SCALAR SHIFT (shift amt :: Ity_I8) */ |
sewardj | d166e28 | 2008-02-06 11:42:45 +0000 | [diff] [blame] | 899 | Iop_ShlN8x8, Iop_ShlN16x4, Iop_ShlN32x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 900 | Iop_ShrN8x8, Iop_ShrN16x4, Iop_ShrN32x2, |
sewardj | d71ba83 | 2006-12-27 01:15:29 +0000 | [diff] [blame] | 901 | Iop_SarN8x8, Iop_SarN16x4, Iop_SarN32x2, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 902 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 903 | /* VECTOR x VECTOR SATURATING SHIFT */ |
| 904 | Iop_QShl8x8, Iop_QShl16x4, Iop_QShl32x2, Iop_QShl64x1, |
| 905 | Iop_QSal8x8, Iop_QSal16x4, Iop_QSal32x2, Iop_QSal64x1, |
| 906 | /* VECTOR x INTEGER SATURATING SHIFT */ |
| 907 | Iop_QShlN8Sx8, Iop_QShlN16Sx4, Iop_QShlN32Sx2, Iop_QShlN64Sx1, |
| 908 | Iop_QShlN8x8, Iop_QShlN16x4, Iop_QShlN32x2, Iop_QShlN64x1, |
| 909 | Iop_QSalN8x8, Iop_QSalN16x4, Iop_QSalN32x2, Iop_QSalN64x1, |
| 910 | |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 911 | /* NARROWING (binary) |
| 912 | -- narrow 2xI64 into 1xI64, hi half from left arg */ |
sewardj | c9bff7d | 2011-06-15 15:09:37 +0000 | [diff] [blame] | 913 | /* For saturated narrowing, I believe there are 4 variants of |
| 914 | the basic arithmetic operation, depending on the signedness |
| 915 | of argument and result. Here are examples that exemplify |
| 916 | what I mean: |
| 917 | |
| 918 | QNarrow16Uto8U ( UShort x ) if (x >u 255) x = 255; |
| 919 | return x[7:0]; |
| 920 | |
| 921 | QNarrow16Sto8S ( Short x ) if (x <s -128) x = -128; |
| 922 | if (x >s 127) x = 127; |
| 923 | return x[7:0]; |
| 924 | |
| 925 | QNarrow16Uto8S ( UShort x ) if (x >u 127) x = 127; |
| 926 | return x[7:0]; |
| 927 | |
| 928 | QNarrow16Sto8U ( Short x ) if (x <s 0) x = 0; |
| 929 | if (x >s 255) x = 255; |
| 930 | return x[7:0]; |
| 931 | */ |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 932 | Iop_QNarrowBin16Sto8Ux8, |
| 933 | Iop_QNarrowBin16Sto8Sx8, Iop_QNarrowBin32Sto16Sx4, |
sewardj | ad2c9ea | 2011-10-22 09:32:16 +0000 | [diff] [blame] | 934 | Iop_NarrowBin16to8x8, Iop_NarrowBin32to16x4, |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 935 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 936 | /* INTERLEAVING */ |
| 937 | /* Interleave lanes from low or high halves of |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 938 | operands. Most-significant result lane is from the left |
| 939 | arg. */ |
| 940 | Iop_InterleaveHI8x8, Iop_InterleaveHI16x4, Iop_InterleaveHI32x2, |
| 941 | Iop_InterleaveLO8x8, Iop_InterleaveLO16x4, Iop_InterleaveLO32x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 942 | /* Interleave odd/even lanes of operands. Most-significant result lane |
| 943 | is from the left arg. Note that Interleave{Odd,Even}Lanes32x2 are |
| 944 | identical to Interleave{HI,LO}32x2 and so are omitted.*/ |
| 945 | Iop_InterleaveOddLanes8x8, Iop_InterleaveEvenLanes8x8, |
| 946 | Iop_InterleaveOddLanes16x4, Iop_InterleaveEvenLanes16x4, |
| 947 | |
sewardj | 38a3f86 | 2005-01-13 15:06:51 +0000 | [diff] [blame] | 948 | |
sewardj | d166e28 | 2008-02-06 11:42:45 +0000 | [diff] [blame] | 949 | /* CONCATENATION -- build a new value by concatenating either |
| 950 | the even or odd lanes of both operands. Note that |
| 951 | Cat{Odd,Even}Lanes32x2 are identical to Interleave{HI,LO}32x2 |
| 952 | and so are omitted. */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 953 | Iop_CatOddLanes8x8, Iop_CatOddLanes16x4, |
| 954 | Iop_CatEvenLanes8x8, Iop_CatEvenLanes16x4, |
| 955 | |
| 956 | /* GET / SET elements of VECTOR |
| 957 | GET is binop (I64, I8) -> I<elem_size> |
| 958 | SET is triop (I64, I8, I<elem_size>) -> I64 */ |
| 959 | /* Note: the arm back-end handles only constant second argument */ |
| 960 | Iop_GetElem8x8, Iop_GetElem16x4, Iop_GetElem32x2, |
| 961 | Iop_SetElem8x8, Iop_SetElem16x4, Iop_SetElem32x2, |
| 962 | |
| 963 | /* DUPLICATING -- copy value to all lanes */ |
| 964 | Iop_Dup8x8, Iop_Dup16x4, Iop_Dup32x2, |
| 965 | |
| 966 | /* EXTRACT -- copy 8-arg3 highest bytes from arg1 to 8-arg3 lowest bytes |
| 967 | of result and arg3 lowest bytes of arg2 to arg3 highest bytes of |
| 968 | result. |
| 969 | It is a triop: (I64, I64, I8) -> I64 */ |
| 970 | /* Note: the arm back-end handles only constant third argumnet. */ |
| 971 | Iop_Extract64, |
| 972 | |
| 973 | /* REVERSE the order of elements in each Half-words, Words, |
| 974 | Double-words */ |
| 975 | /* Examples: |
| 976 | Reverse16_8x8([a,b,c,d,e,f,g,h]) = [b,a,d,c,f,e,h,g] |
| 977 | Reverse32_8x8([a,b,c,d,e,f,g,h]) = [d,c,b,a,h,g,f,e] |
| 978 | Reverse64_8x8([a,b,c,d,e,f,g,h]) = [h,g,f,e,d,c,b,a] */ |
| 979 | Iop_Reverse16_8x8, |
| 980 | Iop_Reverse32_8x8, Iop_Reverse32_16x4, |
| 981 | Iop_Reverse64_8x8, Iop_Reverse64_16x4, Iop_Reverse64_32x2, |
sewardj | d166e28 | 2008-02-06 11:42:45 +0000 | [diff] [blame] | 982 | |
| 983 | /* PERMUTING -- copy src bytes to dst, |
| 984 | as indexed by control vector bytes: |
| 985 | for i in 0 .. 7 . result[i] = argL[ argR[i] ] |
| 986 | argR[i] values may only be in the range 0 .. 7, else behaviour |
| 987 | is undefined. */ |
| 988 | Iop_Perm8x8, |
| 989 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 990 | /* Vector Reciprocal Estimate and Vector Reciprocal Square Root Estimate |
| 991 | See floating-point equiwalents for details. */ |
| 992 | Iop_Recip32x2, Iop_Rsqrte32x2, |
| 993 | |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 994 | /* ------------------ Decimal Floating Point ------------------ */ |
| 995 | |
| 996 | /* ARITHMETIC INSTRUCTIONS 64-bit |
| 997 | ---------------------------------- |
| 998 | IRRoundingModeDFP(I32) X D64 X D64 -> D64 |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 999 | */ |
| 1000 | Iop_AddD64, Iop_SubD64, Iop_MulD64, Iop_DivD64, |
| 1001 | |
| 1002 | /* ARITHMETIC INSTRUCTIONS 128-bit |
| 1003 | ---------------------------------- |
| 1004 | IRRoundingModeDFP(I32) X D128 X D128 -> D128 |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 1005 | */ |
| 1006 | Iop_AddD128, Iop_SubD128, Iop_MulD128, Iop_DivD128, |
| 1007 | |
sewardj | 26217b0 | 2012-04-12 17:19:48 +0000 | [diff] [blame] | 1008 | /* SHIFT SIGNIFICAND INSTRUCTIONS |
| 1009 | * The DFP significand is shifted by the number of digits specified |
| 1010 | * by the U8 operand. Digits shifted out of the leftmost digit are |
| 1011 | * lost. Zeros are supplied to the vacated positions on the right. |
| 1012 | * The sign of the result is the same as the sign of the original |
| 1013 | * operand. |
sewardj | cdc376d | 2012-04-23 11:21:12 +0000 | [diff] [blame] | 1014 | * |
| 1015 | * D64 x U8 -> D64 left shift and right shift respectively */ |
sewardj | 26217b0 | 2012-04-12 17:19:48 +0000 | [diff] [blame] | 1016 | Iop_ShlD64, Iop_ShrD64, |
| 1017 | |
| 1018 | /* D128 x U8 -> D128 left shift and right shift respectively */ |
| 1019 | Iop_ShlD128, Iop_ShrD128, |
| 1020 | |
| 1021 | |
| 1022 | /* FORMAT CONVERSION INSTRUCTIONS |
| 1023 | * D32 -> D64 |
| 1024 | */ |
| 1025 | Iop_D32toD64, |
| 1026 | |
| 1027 | /* D64 -> D128 */ |
| 1028 | Iop_D64toD128, |
| 1029 | |
| 1030 | /* I64S -> D128 */ |
| 1031 | Iop_I64StoD128, |
| 1032 | |
| 1033 | /* IRRoundingModeDFP(I32) x D64 -> D32 */ |
| 1034 | Iop_D64toD32, |
| 1035 | |
| 1036 | /* IRRoundingModeDFP(I32) x D128 -> D64 */ |
| 1037 | Iop_D128toD64, |
| 1038 | |
| 1039 | /* IRRoundingModeDFP(I32) x I64 -> D64 */ |
| 1040 | Iop_I64StoD64, |
| 1041 | |
| 1042 | /* IRRoundingModeDFP(I32) x D64 -> I64 */ |
| 1043 | Iop_D64toI64S, |
| 1044 | |
| 1045 | /* IRRoundingModeDFP(I32) x D128 -> I64 */ |
| 1046 | Iop_D128toI64S, |
| 1047 | |
sewardj | cdc376d | 2012-04-23 11:21:12 +0000 | [diff] [blame] | 1048 | /* ROUNDING INSTRUCTIONS |
| 1049 | * IRRoundingMode(I32) x D64 -> D64 |
| 1050 | * The D64 operand, if a finite number, is rounded to an integer value. |
| 1051 | */ |
| 1052 | Iop_RoundD64toInt, |
| 1053 | |
| 1054 | /* IRRoundingMode(I32) x D128 -> D128 */ |
| 1055 | Iop_RoundD128toInt, |
| 1056 | |
| 1057 | /* COMPARE INSTRUCTIONS |
| 1058 | * D64 x D64 -> IRCmpD64Result(I32) */ |
| 1059 | Iop_CmpD64, |
| 1060 | |
| 1061 | /* D128 x D128 -> IRCmpD64Result(I32) */ |
| 1062 | Iop_CmpD128, |
| 1063 | |
| 1064 | /* QUANTIZE AND ROUND INSTRUCTIONS |
| 1065 | * The source operand is converted and rounded to the form with the |
| 1066 | * immediate exponent specified by the rounding and exponent parameter. |
| 1067 | * |
| 1068 | * The second operand is converted and rounded to the form |
| 1069 | * of the first operand's exponent and the rounded based on the specified |
| 1070 | * rounding mode parameter. |
| 1071 | * |
| 1072 | * IRRoundingModeDFP(I32) x D64 x D64-> D64 */ |
| 1073 | Iop_QuantizeD64, |
| 1074 | |
| 1075 | /* IRRoundingModeDFP(I32) x D128 x D128 -> D128 */ |
| 1076 | Iop_QuantizeD128, |
| 1077 | |
| 1078 | /* IRRoundingModeDFP(I32) x I8 x D64 -> D64 |
| 1079 | * The Decimal Floating point operand is rounded to the requested |
| 1080 | * significance given by the I8 operand as specified by the rounding |
| 1081 | * mode. |
| 1082 | */ |
| 1083 | Iop_SignificanceRoundD64, |
| 1084 | |
| 1085 | /* IRRoundingModeDFP(I32) x I8 x D128 -> D128 */ |
| 1086 | Iop_SignificanceRoundD128, |
| 1087 | |
| 1088 | /* EXTRACT AND INSERT INSTRUCTIONS |
| 1089 | * D64 -> I64 |
| 1090 | * The exponent of the D32 or D64 operand is extracted. The |
| 1091 | * extracted exponent is converted to a 64-bit signed binary integer. |
| 1092 | */ |
| 1093 | Iop_ExtractExpD64, |
| 1094 | |
| 1095 | /* D128 -> I64 */ |
| 1096 | Iop_ExtractExpD128, |
| 1097 | |
| 1098 | /* I64 x I64 -> D64 |
| 1099 | * The exponent is specified by the first I64 operand the signed |
| 1100 | * significand is given by the second I64 value. The result is a D64 |
| 1101 | * value consisting of the specified significand and exponent whose |
| 1102 | * sign is that of the specified significand. |
| 1103 | */ |
| 1104 | Iop_InsertExpD64, |
| 1105 | |
| 1106 | /* I64 x I128 -> D128 */ |
| 1107 | Iop_InsertExpD128, |
| 1108 | |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 1109 | /* Support for 128-bit DFP type */ |
| 1110 | Iop_D64HLtoD128, Iop_D128HItoD64, Iop_D128LOtoD64, |
| 1111 | |
sewardj | 4c96e61 | 2012-06-02 23:47:02 +0000 | [diff] [blame] | 1112 | /* I64 -> I64 |
| 1113 | * Convert 50-bit densely packed BCD string to 60 bit BCD string |
| 1114 | */ |
| 1115 | Iop_DPBtoBCD, |
| 1116 | |
| 1117 | /* I64 -> I64 |
| 1118 | * Convert 60 bit BCD string to 50-bit densely packed BCD string |
| 1119 | */ |
| 1120 | Iop_BCDtoDPB, |
| 1121 | |
sewardj | cdc376d | 2012-04-23 11:21:12 +0000 | [diff] [blame] | 1122 | /* Conversion I64 -> D64 */ |
| 1123 | Iop_ReinterpI64asD64, |
| 1124 | |
sewardj | 5eff1c5 | 2012-04-29 20:19:17 +0000 | [diff] [blame] | 1125 | /* Conversion D64 -> I64 */ |
| 1126 | Iop_ReinterpD64asI64, |
| 1127 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1128 | /* ------------------ 128-bit SIMD FP. ------------------ */ |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1129 | |
| 1130 | /* --- 32x4 vector FP --- */ |
| 1131 | |
| 1132 | /* binary */ |
| 1133 | Iop_Add32Fx4, Iop_Sub32Fx4, Iop_Mul32Fx4, Iop_Div32Fx4, |
| 1134 | Iop_Max32Fx4, Iop_Min32Fx4, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1135 | Iop_Add32Fx2, Iop_Sub32Fx2, |
| 1136 | /* Note: For the following compares, the ppc and arm front-ends assume a |
cerion | f294eb3 | 2005-11-16 17:21:10 +0000 | [diff] [blame] | 1137 | nan in a lane of either argument returns zero for that lane. */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1138 | Iop_CmpEQ32Fx4, Iop_CmpLT32Fx4, Iop_CmpLE32Fx4, Iop_CmpUN32Fx4, |
cerion | 206c364 | 2005-11-14 00:35:59 +0000 | [diff] [blame] | 1139 | Iop_CmpGT32Fx4, Iop_CmpGE32Fx4, |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1140 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1141 | /* Vector Absolute */ |
| 1142 | Iop_Abs32Fx4, |
| 1143 | |
| 1144 | /* Pairwise Max and Min. See integer pairwise operations for details. */ |
| 1145 | Iop_PwMax32Fx4, Iop_PwMin32Fx4, |
| 1146 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1147 | /* unary */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1148 | Iop_Sqrt32Fx4, Iop_RSqrt32Fx4, |
| 1149 | Iop_Neg32Fx4, |
| 1150 | |
| 1151 | /* Vector Reciprocal Estimate finds an approximate reciprocal of each |
| 1152 | element in the operand vector, and places the results in the destination |
| 1153 | vector. */ |
| 1154 | Iop_Recip32Fx4, |
| 1155 | |
| 1156 | /* Vector Reciprocal Step computes (2.0 - arg1 * arg2). |
| 1157 | Note, that if one of the arguments is zero and another one is infinity |
| 1158 | of arbitrary sign the result of the operation is 2.0. */ |
| 1159 | Iop_Recps32Fx4, |
| 1160 | |
| 1161 | /* Vector Reciprocal Square Root Estimate finds an approximate reciprocal |
| 1162 | square root of each element in the operand vector. */ |
| 1163 | Iop_Rsqrte32Fx4, |
| 1164 | |
| 1165 | /* Vector Reciprocal Square Root Step computes (3.0 - arg1 * arg2) / 2.0. |
| 1166 | Note, that of one of the arguments is zero and another one is infiinty |
| 1167 | of arbitrary sign the result of the operation is 1.5. */ |
| 1168 | Iop_Rsqrts32Fx4, |
| 1169 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1170 | |
cerion | f294eb3 | 2005-11-16 17:21:10 +0000 | [diff] [blame] | 1171 | /* --- Int to/from FP conversion --- */ |
| 1172 | /* Unlike the standard fp conversions, these irops take no |
| 1173 | rounding mode argument. Instead the irop trailers _R{M,P,N,Z} |
| 1174 | indicate the mode: {-inf, +inf, nearest, zero} respectively. */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1175 | Iop_I32UtoFx4, Iop_I32StoFx4, /* I32x4 -> F32x4 */ |
| 1176 | Iop_FtoI32Ux4_RZ, Iop_FtoI32Sx4_RZ, /* F32x4 -> I32x4 */ |
| 1177 | Iop_QFtoI32Ux4_RZ, Iop_QFtoI32Sx4_RZ, /* F32x4 -> I32x4 (with saturation) */ |
cerion | f294eb3 | 2005-11-16 17:21:10 +0000 | [diff] [blame] | 1178 | Iop_RoundF32x4_RM, Iop_RoundF32x4_RP, /* round to fp integer */ |
| 1179 | Iop_RoundF32x4_RN, Iop_RoundF32x4_RZ, /* round to fp integer */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1180 | /* Fixed32 format is floating-point number with fixed number of fraction |
| 1181 | bits. The number of fraction bits is passed as a second argument of |
| 1182 | type I8. */ |
| 1183 | Iop_F32ToFixed32Ux4_RZ, Iop_F32ToFixed32Sx4_RZ, /* fp -> fixed-point */ |
| 1184 | Iop_Fixed32UToF32x4_RN, Iop_Fixed32SToF32x4_RN, /* fixed-point -> fp */ |
| 1185 | |
| 1186 | /* --- Single to/from half conversion --- */ |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1187 | /* FIXME: what kind of rounding in F32x4 -> F16x4 case? */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1188 | Iop_F32toF16x4, Iop_F16toF32x4, /* F32x4 <-> F16x4 */ |
cerion | f294eb3 | 2005-11-16 17:21:10 +0000 | [diff] [blame] | 1189 | |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1190 | /* --- 32x4 lowest-lane-only scalar FP --- */ |
| 1191 | |
| 1192 | /* In binary cases, upper 3/4 is copied from first operand. In |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 1193 | unary cases, upper 3/4 is copied from the operand. */ |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1194 | |
| 1195 | /* binary */ |
| 1196 | Iop_Add32F0x4, Iop_Sub32F0x4, Iop_Mul32F0x4, Iop_Div32F0x4, |
| 1197 | Iop_Max32F0x4, Iop_Min32F0x4, |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1198 | Iop_CmpEQ32F0x4, Iop_CmpLT32F0x4, Iop_CmpLE32F0x4, Iop_CmpUN32F0x4, |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1199 | |
| 1200 | /* unary */ |
| 1201 | Iop_Recip32F0x4, Iop_Sqrt32F0x4, Iop_RSqrt32F0x4, |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1202 | |
| 1203 | /* --- 64x2 vector FP --- */ |
| 1204 | |
| 1205 | /* binary */ |
| 1206 | Iop_Add64Fx2, Iop_Sub64Fx2, Iop_Mul64Fx2, Iop_Div64Fx2, |
| 1207 | Iop_Max64Fx2, Iop_Min64Fx2, |
| 1208 | Iop_CmpEQ64Fx2, Iop_CmpLT64Fx2, Iop_CmpLE64Fx2, Iop_CmpUN64Fx2, |
| 1209 | |
| 1210 | /* unary */ |
| 1211 | Iop_Recip64Fx2, Iop_Sqrt64Fx2, Iop_RSqrt64Fx2, |
| 1212 | |
| 1213 | /* --- 64x2 lowest-lane-only scalar FP --- */ |
| 1214 | |
| 1215 | /* In binary cases, upper half is copied from first operand. In |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 1216 | unary cases, upper half is copied from the operand. */ |
sewardj | 636ad76 | 2004-12-07 11:16:04 +0000 | [diff] [blame] | 1217 | |
| 1218 | /* binary */ |
| 1219 | Iop_Add64F0x2, Iop_Sub64F0x2, Iop_Mul64F0x2, Iop_Div64F0x2, |
| 1220 | Iop_Max64F0x2, Iop_Min64F0x2, |
| 1221 | Iop_CmpEQ64F0x2, Iop_CmpLT64F0x2, Iop_CmpLE64F0x2, Iop_CmpUN64F0x2, |
| 1222 | |
| 1223 | /* unary */ |
| 1224 | Iop_Recip64F0x2, Iop_Sqrt64F0x2, Iop_RSqrt64F0x2, |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1225 | |
| 1226 | /* --- pack / unpack --- */ |
| 1227 | |
sewardj | f0c1c58 | 2005-02-07 23:47:38 +0000 | [diff] [blame] | 1228 | /* 64 <-> 128 bit vector */ |
| 1229 | Iop_V128to64, // :: V128 -> I64, low half |
| 1230 | Iop_V128HIto64, // :: V128 -> I64, high half |
| 1231 | Iop_64HLtoV128, // :: (I64,I64) -> V128 |
sewardj | c9a4366 | 2004-11-30 18:51:59 +0000 | [diff] [blame] | 1232 | |
sewardj | f0c1c58 | 2005-02-07 23:47:38 +0000 | [diff] [blame] | 1233 | Iop_64UtoV128, |
| 1234 | Iop_SetV128lo64, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1235 | |
sewardj | f0c1c58 | 2005-02-07 23:47:38 +0000 | [diff] [blame] | 1236 | /* 32 <-> 128 bit vector */ |
| 1237 | Iop_32UtoV128, |
| 1238 | Iop_V128to32, // :: V128 -> I32, lowest lane |
| 1239 | Iop_SetV128lo32, // :: (V128,I32) -> V128 |
sewardj | 70f676d | 2004-12-10 14:59:57 +0000 | [diff] [blame] | 1240 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1241 | /* ------------------ 128-bit SIMD Integer. ------------------ */ |
| 1242 | |
| 1243 | /* BITWISE OPS */ |
sewardj | f0c1c58 | 2005-02-07 23:47:38 +0000 | [diff] [blame] | 1244 | Iop_NotV128, |
| 1245 | Iop_AndV128, Iop_OrV128, Iop_XorV128, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1246 | |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1247 | /* VECTOR SHIFT (shift amt :: Ity_I8) */ |
| 1248 | Iop_ShlV128, Iop_ShrV128, |
| 1249 | |
sewardj | 2e38386 | 2004-12-12 16:46:47 +0000 | [diff] [blame] | 1250 | /* MISC (vector integer cmp != 0) */ |
| 1251 | Iop_CmpNEZ8x16, Iop_CmpNEZ16x8, Iop_CmpNEZ32x4, Iop_CmpNEZ64x2, |
sewardj | 70f676d | 2004-12-10 14:59:57 +0000 | [diff] [blame] | 1252 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1253 | /* ADDITION (normal / unsigned sat / signed sat) */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1254 | Iop_Add8x16, Iop_Add16x8, Iop_Add32x4, Iop_Add64x2, |
| 1255 | Iop_QAdd8Ux16, Iop_QAdd16Ux8, Iop_QAdd32Ux4, Iop_QAdd64Ux2, |
| 1256 | Iop_QAdd8Sx16, Iop_QAdd16Sx8, Iop_QAdd32Sx4, Iop_QAdd64Sx2, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1257 | |
| 1258 | /* SUBTRACTION (normal / unsigned sat / signed sat) */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1259 | Iop_Sub8x16, Iop_Sub16x8, Iop_Sub32x4, Iop_Sub64x2, |
| 1260 | Iop_QSub8Ux16, Iop_QSub16Ux8, Iop_QSub32Ux4, Iop_QSub64Ux2, |
| 1261 | Iop_QSub8Sx16, Iop_QSub16Sx8, Iop_QSub32Sx4, Iop_QSub64Sx2, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1262 | |
| 1263 | /* MULTIPLICATION (normal / high half of signed/unsigned) */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1264 | Iop_Mul8x16, Iop_Mul16x8, Iop_Mul32x4, |
| 1265 | Iop_MulHi16Ux8, Iop_MulHi32Ux4, |
| 1266 | Iop_MulHi16Sx8, Iop_MulHi32Sx4, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 1267 | /* (widening signed/unsigned of even lanes, with lowest lane=zero) */ |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 1268 | Iop_MullEven8Ux16, Iop_MullEven16Ux8, |
| 1269 | Iop_MullEven8Sx16, Iop_MullEven16Sx8, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1270 | /* FIXME: document these */ |
| 1271 | Iop_Mull8Ux8, Iop_Mull8Sx8, |
| 1272 | Iop_Mull16Ux4, Iop_Mull16Sx4, |
| 1273 | Iop_Mull32Ux2, Iop_Mull32Sx2, |
| 1274 | /* Vector Saturating Doubling Multiply Returning High Half and |
| 1275 | Vector Saturating Rounding Doubling Multiply Returning High Half */ |
| 1276 | /* These IROp's multiply corresponding elements in two vectors, double |
| 1277 | the results, and place the most significant half of the final results |
| 1278 | in the destination vector. The results are truncated or rounded. If |
| 1279 | any of the results overflow, they are saturated. */ |
| 1280 | Iop_QDMulHi16Sx8, Iop_QDMulHi32Sx4, |
| 1281 | Iop_QRDMulHi16Sx8, Iop_QRDMulHi32Sx4, |
| 1282 | /* Doubling saturating multiplication (long) (I64, I64) -> V128 */ |
| 1283 | Iop_QDMulLong16Sx4, Iop_QDMulLong32Sx2, |
| 1284 | /* Plynomial multiplication treats it's arguments as coefficients of |
| 1285 | polynoms over {0, 1}. */ |
| 1286 | Iop_PolynomialMul8x16, /* (V128, V128) -> V128 */ |
| 1287 | Iop_PolynomialMull8x8, /* (I64, I64) -> V128 */ |
| 1288 | |
| 1289 | /* PAIRWISE operations */ |
| 1290 | /* Iop_PwFoo16x4( [a,b,c,d], [e,f,g,h] ) = |
| 1291 | [Foo16(a,b), Foo16(c,d), Foo16(e,f), Foo16(g,h)] */ |
| 1292 | Iop_PwAdd8x16, Iop_PwAdd16x8, Iop_PwAdd32x4, |
| 1293 | Iop_PwAdd32Fx2, |
| 1294 | /* Longening variant is unary. The resulting vector contains two times |
| 1295 | less elements than operand, but they are two times wider. |
| 1296 | Example: |
| 1297 | Iop_PwAddL16Ux4( [a,b,c,d] ) = [a+b,c+d] |
| 1298 | where a+b and c+d are unsigned 32-bit values. */ |
| 1299 | Iop_PwAddL8Ux16, Iop_PwAddL16Ux8, Iop_PwAddL32Ux4, |
| 1300 | Iop_PwAddL8Sx16, Iop_PwAddL16Sx8, Iop_PwAddL32Sx4, |
| 1301 | |
| 1302 | /* ABSOLUTE VALUE */ |
| 1303 | Iop_Abs8x16, Iop_Abs16x8, Iop_Abs32x4, |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 1304 | |
sewardj | 5ce5fd6 | 2005-04-19 23:06:11 +0000 | [diff] [blame] | 1305 | /* AVERAGING: note: (arg1 + arg2 + 1) >>u 1 */ |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1306 | Iop_Avg8Ux16, Iop_Avg16Ux8, Iop_Avg32Ux4, |
| 1307 | Iop_Avg8Sx16, Iop_Avg16Sx8, Iop_Avg32Sx4, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1308 | |
| 1309 | /* MIN/MAX */ |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1310 | Iop_Max8Sx16, Iop_Max16Sx8, Iop_Max32Sx4, |
| 1311 | Iop_Max8Ux16, Iop_Max16Ux8, Iop_Max32Ux4, |
| 1312 | Iop_Min8Sx16, Iop_Min16Sx8, Iop_Min32Sx4, |
| 1313 | Iop_Min8Ux16, Iop_Min16Ux8, Iop_Min32Ux4, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1314 | |
| 1315 | /* COMPARISON */ |
sewardj | d881562 | 2011-10-19 15:24:01 +0000 | [diff] [blame] | 1316 | Iop_CmpEQ8x16, Iop_CmpEQ16x8, Iop_CmpEQ32x4, Iop_CmpEQ64x2, |
sewardj | 69d98e3 | 2010-06-18 08:17:41 +0000 | [diff] [blame] | 1317 | Iop_CmpGT8Sx16, Iop_CmpGT16Sx8, Iop_CmpGT32Sx4, Iop_CmpGT64Sx2, |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1318 | Iop_CmpGT8Ux16, Iop_CmpGT16Ux8, Iop_CmpGT32Ux4, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1319 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1320 | /* COUNT ones / leading zeroes / leading sign bits (not including topmost |
| 1321 | bit) */ |
| 1322 | Iop_Cnt8x16, |
| 1323 | Iop_Clz8Sx16, Iop_Clz16Sx8, Iop_Clz32Sx4, |
| 1324 | Iop_Cls8Sx16, Iop_Cls16Sx8, Iop_Cls32Sx4, |
| 1325 | |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1326 | /* VECTOR x SCALAR SHIFT (shift amt :: Ity_I8) */ |
cerion | 2a4b845 | 2005-09-15 16:28:36 +0000 | [diff] [blame] | 1327 | Iop_ShlN8x16, Iop_ShlN16x8, Iop_ShlN32x4, Iop_ShlN64x2, |
| 1328 | Iop_ShrN8x16, Iop_ShrN16x8, Iop_ShrN32x4, Iop_ShrN64x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1329 | Iop_SarN8x16, Iop_SarN16x8, Iop_SarN32x4, Iop_SarN64x2, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1330 | |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1331 | /* VECTOR x VECTOR SHIFT / ROTATE */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1332 | Iop_Shl8x16, Iop_Shl16x8, Iop_Shl32x4, Iop_Shl64x2, |
| 1333 | Iop_Shr8x16, Iop_Shr16x8, Iop_Shr32x4, Iop_Shr64x2, |
| 1334 | Iop_Sar8x16, Iop_Sar16x8, Iop_Sar32x4, Iop_Sar64x2, |
| 1335 | Iop_Sal8x16, Iop_Sal16x8, Iop_Sal32x4, Iop_Sal64x2, |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 1336 | Iop_Rol8x16, Iop_Rol16x8, Iop_Rol32x4, |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1337 | |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1338 | /* VECTOR x VECTOR SATURATING SHIFT */ |
| 1339 | Iop_QShl8x16, Iop_QShl16x8, Iop_QShl32x4, Iop_QShl64x2, |
| 1340 | Iop_QSal8x16, Iop_QSal16x8, Iop_QSal32x4, Iop_QSal64x2, |
| 1341 | /* VECTOR x INTEGER SATURATING SHIFT */ |
| 1342 | Iop_QShlN8Sx16, Iop_QShlN16Sx8, Iop_QShlN32Sx4, Iop_QShlN64Sx2, |
| 1343 | Iop_QShlN8x16, Iop_QShlN16x8, Iop_QShlN32x4, Iop_QShlN64x2, |
| 1344 | Iop_QSalN8x16, Iop_QSalN16x8, Iop_QSalN32x4, Iop_QSalN64x2, |
| 1345 | |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1346 | /* NARROWING (binary) |
| 1347 | -- narrow 2xV128 into 1xV128, hi half from left arg */ |
sewardj | c9bff7d | 2011-06-15 15:09:37 +0000 | [diff] [blame] | 1348 | /* See comments above w.r.t. U vs S issues in saturated narrowing. */ |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1349 | Iop_QNarrowBin16Sto8Ux16, Iop_QNarrowBin32Sto16Ux8, |
| 1350 | Iop_QNarrowBin16Sto8Sx16, Iop_QNarrowBin32Sto16Sx8, |
| 1351 | Iop_QNarrowBin16Uto8Ux16, Iop_QNarrowBin32Uto16Ux8, |
| 1352 | Iop_NarrowBin16to8x16, Iop_NarrowBin32to16x8, |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1353 | |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1354 | /* NARROWING (unary) -- narrow V128 into I64 */ |
| 1355 | Iop_NarrowUn16to8x8, Iop_NarrowUn32to16x4, Iop_NarrowUn64to32x2, |
| 1356 | /* Saturating narrowing from signed source to signed/unsigned destination */ |
| 1357 | Iop_QNarrowUn16Sto8Sx8, Iop_QNarrowUn32Sto16Sx4, Iop_QNarrowUn64Sto32Sx2, |
| 1358 | Iop_QNarrowUn16Sto8Ux8, Iop_QNarrowUn32Sto16Ux4, Iop_QNarrowUn64Sto32Ux2, |
| 1359 | /* Saturating narrowing from unsigned source to unsigned destination */ |
| 1360 | Iop_QNarrowUn16Uto8Ux8, Iop_QNarrowUn32Uto16Ux4, Iop_QNarrowUn64Uto32Ux2, |
| 1361 | |
| 1362 | /* WIDENING -- sign or zero extend each element of the argument |
| 1363 | vector to the twice original size. The resulting vector consists of |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1364 | the same number of elements but each element and the vector itself |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1365 | are twice as wide. |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1366 | All operations are I64->V128. |
| 1367 | Example |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1368 | Iop_Widen32Sto64x2( [a, b] ) = [c, d] |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1369 | where c = Iop_32Sto64(a) and d = Iop_32Sto64(b) */ |
sewardj | 5f438dd | 2011-06-16 11:36:23 +0000 | [diff] [blame] | 1370 | Iop_Widen8Uto16x8, Iop_Widen16Uto32x4, Iop_Widen32Uto64x2, |
| 1371 | Iop_Widen8Sto16x8, Iop_Widen16Sto32x4, Iop_Widen32Sto64x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1372 | |
| 1373 | /* INTERLEAVING */ |
| 1374 | /* Interleave lanes from low or high halves of |
sewardj | 164f927 | 2004-12-09 00:39:32 +0000 | [diff] [blame] | 1375 | operands. Most-significant result lane is from the left |
| 1376 | arg. */ |
| 1377 | Iop_InterleaveHI8x16, Iop_InterleaveHI16x8, |
| 1378 | Iop_InterleaveHI32x4, Iop_InterleaveHI64x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1379 | Iop_InterleaveLO8x16, Iop_InterleaveLO16x8, |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1380 | Iop_InterleaveLO32x4, Iop_InterleaveLO64x2, |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1381 | /* Interleave odd/even lanes of operands. Most-significant result lane |
| 1382 | is from the left arg. */ |
| 1383 | Iop_InterleaveOddLanes8x16, Iop_InterleaveEvenLanes8x16, |
| 1384 | Iop_InterleaveOddLanes16x8, Iop_InterleaveEvenLanes16x8, |
| 1385 | Iop_InterleaveOddLanes32x4, Iop_InterleaveEvenLanes32x4, |
| 1386 | |
| 1387 | /* CONCATENATION -- build a new value by concatenating either |
| 1388 | the even or odd lanes of both operands. */ |
| 1389 | Iop_CatOddLanes8x16, Iop_CatOddLanes16x8, Iop_CatOddLanes32x4, |
| 1390 | Iop_CatEvenLanes8x16, Iop_CatEvenLanes16x8, Iop_CatEvenLanes32x4, |
| 1391 | |
| 1392 | /* GET elements of VECTOR |
| 1393 | GET is binop (V128, I8) -> I<elem_size> */ |
| 1394 | /* Note: the arm back-end handles only constant second argument. */ |
| 1395 | Iop_GetElem8x16, Iop_GetElem16x8, Iop_GetElem32x4, Iop_GetElem64x2, |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1396 | |
| 1397 | /* DUPLICATING -- copy value to all lanes */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1398 | Iop_Dup8x16, Iop_Dup16x8, Iop_Dup32x4, |
| 1399 | |
| 1400 | /* EXTRACT -- copy 16-arg3 highest bytes from arg1 to 16-arg3 lowest bytes |
| 1401 | of result and arg3 lowest bytes of arg2 to arg3 highest bytes of |
| 1402 | result. |
| 1403 | It is a triop: (V128, V128, I8) -> V128 */ |
| 1404 | /* Note: the ARM back end handles only constant arg3 in this operation. */ |
| 1405 | Iop_ExtractV128, |
| 1406 | |
| 1407 | /* REVERSE the order of elements in each Half-words, Words, |
| 1408 | Double-words */ |
| 1409 | /* Examples: |
| 1410 | Reverse32_16x8([a,b,c,d,e,f,g,h]) = [b,a,d,c,f,e,h,g] |
| 1411 | Reverse64_16x8([a,b,c,d,e,f,g,h]) = [d,c,b,a,h,g,f,e] */ |
| 1412 | Iop_Reverse16_8x16, |
| 1413 | Iop_Reverse32_8x16, Iop_Reverse32_16x8, |
| 1414 | Iop_Reverse64_8x16, Iop_Reverse64_16x8, Iop_Reverse64_32x4, |
cerion | f887b3e | 2005-09-13 16:34:28 +0000 | [diff] [blame] | 1415 | |
| 1416 | /* PERMUTING -- copy src bytes to dst, |
sewardj | dc1f913 | 2005-10-22 12:49:49 +0000 | [diff] [blame] | 1417 | as indexed by control vector bytes: |
| 1418 | for i in 0 .. 15 . result[i] = argL[ argR[i] ] |
| 1419 | argR[i] values may only be in the range 0 .. 15, else behaviour |
| 1420 | is undefined. */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1421 | Iop_Perm8x16, |
sewardj | d8bca7e | 2012-06-20 11:46:19 +0000 | [diff] [blame] | 1422 | Iop_Perm32x4, /* ditto, except argR values are restricted to 0 .. 3 */ |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1423 | |
| 1424 | /* Vector Reciprocal Estimate and Vector Reciprocal Square Root Estimate |
| 1425 | See floating-point equiwalents for details. */ |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 1426 | Iop_Recip32x4, Iop_Rsqrte32x4, |
| 1427 | |
| 1428 | /* ------------------ 256-bit SIMD Integer. ------------------ */ |
| 1429 | |
| 1430 | /* Pack/unpack */ |
sewardj | 4b1cc83 | 2012-06-13 11:10:20 +0000 | [diff] [blame] | 1431 | Iop_V256to64_0, // V256 -> I64, extract least significant lane |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 1432 | Iop_V256to64_1, |
| 1433 | Iop_V256to64_2, |
sewardj | 4b1cc83 | 2012-06-13 11:10:20 +0000 | [diff] [blame] | 1434 | Iop_V256to64_3, // V256 -> I64, extract most significant lane |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 1435 | |
sewardj | 56c3031 | 2012-06-12 08:45:39 +0000 | [diff] [blame] | 1436 | Iop_64x4toV256, // (I64,I64,I64,I64)->V256 |
sewardj | c4530ae | 2012-05-21 10:18:49 +0000 | [diff] [blame] | 1437 | // first arg is most significant lane |
sewardj | 56c3031 | 2012-06-12 08:45:39 +0000 | [diff] [blame] | 1438 | |
sewardj | 4b1cc83 | 2012-06-13 11:10:20 +0000 | [diff] [blame] | 1439 | Iop_V256toV128_0, // V256 -> V128, less significant lane |
| 1440 | Iop_V256toV128_1, // V256 -> V128, more significant lane |
| 1441 | Iop_V128HLtoV256, // (V128,V128)->V256, first arg is most signif |
| 1442 | |
| 1443 | Iop_AndV256, |
sewardj | 2a2bda9 | 2012-06-14 23:32:02 +0000 | [diff] [blame] | 1444 | Iop_OrV256, |
sewardj | 4b1cc83 | 2012-06-13 11:10:20 +0000 | [diff] [blame] | 1445 | Iop_XorV256, |
sewardj | 2a2bda9 | 2012-06-14 23:32:02 +0000 | [diff] [blame] | 1446 | Iop_NotV256, |
sewardj | 4b1cc83 | 2012-06-13 11:10:20 +0000 | [diff] [blame] | 1447 | |
sewardj | 23db8a0 | 2012-06-25 07:46:18 +0000 | [diff] [blame] | 1448 | /* MISC (vector integer cmp != 0) */ |
| 1449 | Iop_CmpNEZ32x8, Iop_CmpNEZ64x4, |
| 1450 | |
sewardj | 56c3031 | 2012-06-12 08:45:39 +0000 | [diff] [blame] | 1451 | /* ------------------ 256-bit SIMD FP. ------------------ */ |
| 1452 | Iop_Add64Fx4, |
| 1453 | Iop_Sub64Fx4, |
| 1454 | Iop_Mul64Fx4, |
| 1455 | Iop_Div64Fx4, |
| 1456 | Iop_Add32Fx8, |
| 1457 | Iop_Sub32Fx8, |
| 1458 | Iop_Mul32Fx8, |
sewardj | f0ad4f8 | 2012-06-19 06:57:59 +0000 | [diff] [blame] | 1459 | Iop_Div32Fx8, |
| 1460 | |
| 1461 | Iop_Sqrt32Fx8, |
| 1462 | Iop_Sqrt64Fx4, |
sewardj | 8eb7ae8 | 2012-06-24 14:00:27 +0000 | [diff] [blame] | 1463 | Iop_RSqrt32Fx8, |
sewardj | 8209692 | 2012-06-24 14:57:59 +0000 | [diff] [blame] | 1464 | Iop_Recip32Fx8, |
sewardj | 8eb7ae8 | 2012-06-24 14:00:27 +0000 | [diff] [blame] | 1465 | |
| 1466 | Iop_Max32Fx8, Iop_Min32Fx8, |
| 1467 | Iop_Max64Fx4, Iop_Min64Fx4 |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 1468 | } |
| 1469 | IROp; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1470 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1471 | /* Pretty-print an op. */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1472 | extern void ppIROp ( IROp ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1473 | |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1474 | |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 1475 | /* Encoding of IEEE754-specified rounding modes. This is the same as |
sewardj | f1b5b1a | 2006-02-03 22:54:17 +0000 | [diff] [blame] | 1476 | the encoding used by Intel IA32 to indicate x87 rounding mode. |
| 1477 | Note, various front and back ends rely on the actual numerical |
| 1478 | values of these, so do not change them. */ |
sewardj | c9868d7 | 2004-09-12 19:19:17 +0000 | [diff] [blame] | 1479 | typedef |
sewardj | f1b5b1a | 2006-02-03 22:54:17 +0000 | [diff] [blame] | 1480 | enum { |
| 1481 | Irrm_NEAREST = 0, |
| 1482 | Irrm_NegINF = 1, |
| 1483 | Irrm_PosINF = 2, |
| 1484 | Irrm_ZERO = 3 |
| 1485 | } |
sewardj | c9868d7 | 2004-09-12 19:19:17 +0000 | [diff] [blame] | 1486 | IRRoundingMode; |
| 1487 | |
sewardj | c6bbd47 | 2012-04-02 10:20:48 +0000 | [diff] [blame] | 1488 | /* DFP encoding of IEEE754 2008 specified rounding modes extends the two bit |
| 1489 | * binary floating point rounding mode (IRRoundingMode) to three bits. The |
| 1490 | * DFP rounding modes are a super set of the binary rounding modes. The |
| 1491 | * encoding was chosen such that the mapping of the least significant two bits |
| 1492 | * of the IR to POWER encodings is same. The upper IR encoding bit is just |
| 1493 | * a logical OR of the upper rounding mode bit from the POWER encoding. |
| 1494 | */ |
| 1495 | typedef |
| 1496 | enum { |
| 1497 | Irrm_DFP_NEAREST = 0, // Round to nearest, ties to even |
| 1498 | Irrm_DFP_NegINF = 1, // Round to negative infinity |
| 1499 | Irrm_DFP_PosINF = 2, // Round to posative infinity |
| 1500 | Irrm_DFP_ZERO = 3, // Round toward zero |
| 1501 | Irrm_DFP_NEAREST_TIE_AWAY_0 = 4, // Round to nearest, ties away from 0 |
| 1502 | Irrm_DFP_PREPARE_SHORTER = 5, // Round to prepare for storter |
| 1503 | // precision |
| 1504 | Irrm_DFP_AWAY_FROM_ZERO = 6, // Round to away from 0 |
| 1505 | Irrm_DFP_NEAREST_TIE_TOWARD_0 = 7 // Round to nearest, ties towards 0 |
| 1506 | } |
| 1507 | IRRoundingModeDFP; |
| 1508 | |
sewardj | c9868d7 | 2004-09-12 19:19:17 +0000 | [diff] [blame] | 1509 | /* Floating point comparison result values, as created by Iop_CmpF64. |
| 1510 | This is also derived from what IA32 does. */ |
| 1511 | typedef |
| 1512 | enum { |
| 1513 | Ircr_UN = 0x45, |
| 1514 | Ircr_LT = 0x01, |
| 1515 | Ircr_GT = 0x00, |
| 1516 | Ircr_EQ = 0x40 |
| 1517 | } |
| 1518 | IRCmpF64Result; |
| 1519 | |
sewardj | 2019a97 | 2011-03-07 16:04:07 +0000 | [diff] [blame] | 1520 | typedef IRCmpF64Result IRCmpF32Result; |
| 1521 | typedef IRCmpF64Result IRCmpF128Result; |
sewardj | c9868d7 | 2004-09-12 19:19:17 +0000 | [diff] [blame] | 1522 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1523 | /* ------------------ Expressions ------------------ */ |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 1524 | |
florian | eadea2e | 2012-06-06 12:53:14 +0000 | [diff] [blame] | 1525 | typedef struct _IRQop IRQop; /* forward declaration */ |
| 1526 | typedef struct _IRTriop IRTriop; /* forward declaration */ |
florian | 96d7cc3 | 2012-06-01 20:41:24 +0000 | [diff] [blame] | 1527 | |
| 1528 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1529 | /* The different kinds of expressions. Their meaning is explained below |
| 1530 | in the comments for IRExpr. */ |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1531 | typedef |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1532 | enum { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 1533 | Iex_Binder=0x15000, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1534 | Iex_Get, |
| 1535 | Iex_GetI, |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1536 | Iex_RdTmp, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1537 | Iex_Qop, |
| 1538 | Iex_Triop, |
| 1539 | Iex_Binop, |
| 1540 | Iex_Unop, |
| 1541 | Iex_Load, |
| 1542 | Iex_Const, |
| 1543 | Iex_Mux0X, |
| 1544 | Iex_CCall |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1545 | } |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1546 | IRExprTag; |
| 1547 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1548 | /* An expression. Stored as a tagged union. 'tag' indicates what kind |
| 1549 | of expression this is. 'Iex' is the union that holds the fields. If |
| 1550 | an IRExpr 'e' has e.tag equal to Iex_Load, then it's a load |
| 1551 | expression, and the fields can be accessed with |
| 1552 | 'e.Iex.Load.<fieldname>'. |
| 1553 | |
| 1554 | For each kind of expression, we show what it looks like when |
| 1555 | pretty-printed with ppIRExpr(). |
| 1556 | */ |
| 1557 | typedef |
| 1558 | struct _IRExpr |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1559 | IRExpr; |
| 1560 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1561 | struct _IRExpr { |
| 1562 | IRExprTag tag; |
| 1563 | union { |
| 1564 | /* Used only in pattern matching within Vex. Should not be seen |
| 1565 | outside of Vex. */ |
| 1566 | struct { |
| 1567 | Int binder; |
| 1568 | } Binder; |
| 1569 | |
| 1570 | /* Read a guest register, at a fixed offset in the guest state. |
| 1571 | ppIRExpr output: GET:<ty>(<offset>), eg. GET:I32(0) |
| 1572 | */ |
| 1573 | struct { |
| 1574 | Int offset; /* Offset into the guest state */ |
| 1575 | IRType ty; /* Type of the value being read */ |
| 1576 | } Get; |
| 1577 | |
| 1578 | /* Read a guest register at a non-fixed offset in the guest |
| 1579 | state. This allows circular indexing into parts of the guest |
| 1580 | state, which is essential for modelling situations where the |
| 1581 | identity of guest registers is not known until run time. One |
| 1582 | example is the x87 FP register stack. |
| 1583 | |
| 1584 | The part of the guest state to be treated as a circular array |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1585 | is described in the IRRegArray 'descr' field. It holds the |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1586 | offset of the first element in the array, the type of each |
| 1587 | element, and the number of elements. |
| 1588 | |
| 1589 | The array index is indicated rather indirectly, in a way |
| 1590 | which makes optimisation easy: as the sum of variable part |
| 1591 | (the 'ix' field) and a constant offset (the 'bias' field). |
| 1592 | |
| 1593 | Since the indexing is circular, the actual array index to use |
| 1594 | is computed as (ix + bias) % num-of-elems-in-the-array. |
| 1595 | |
| 1596 | Here's an example. The description |
| 1597 | |
| 1598 | (96:8xF64)[t39,-7] |
| 1599 | |
| 1600 | describes an array of 8 F64-typed values, the |
| 1601 | guest-state-offset of the first being 96. This array is |
| 1602 | being indexed at (t39 - 7) % 8. |
| 1603 | |
| 1604 | It is important to get the array size/type exactly correct |
| 1605 | since IR optimisation looks closely at such info in order to |
| 1606 | establish aliasing/non-aliasing between seperate GetI and |
| 1607 | PutI events, which is used to establish when they can be |
| 1608 | reordered, etc. Putting incorrect info in will lead to |
| 1609 | obscure IR optimisation bugs. |
| 1610 | |
| 1611 | ppIRExpr output: GETI<descr>[<ix>,<bias] |
| 1612 | eg. GETI(128:8xI8)[t1,0] |
| 1613 | */ |
| 1614 | struct { |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1615 | IRRegArray* descr; /* Part of guest state treated as circular */ |
| 1616 | IRExpr* ix; /* Variable part of index into array */ |
| 1617 | Int bias; /* Constant offset part of index into array */ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1618 | } GetI; |
| 1619 | |
| 1620 | /* The value held by a temporary. |
| 1621 | ppIRExpr output: t<tmp>, eg. t1 |
| 1622 | */ |
| 1623 | struct { |
| 1624 | IRTemp tmp; /* The temporary number */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1625 | } RdTmp; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1626 | |
| 1627 | /* A quaternary operation. |
| 1628 | ppIRExpr output: <op>(<arg1>, <arg2>, <arg3>, <arg4>), |
| 1629 | eg. MAddF64r32(t1, t2, t3, t4) |
| 1630 | */ |
| 1631 | struct { |
florian | 96d7cc3 | 2012-06-01 20:41:24 +0000 | [diff] [blame] | 1632 | IRQop* details; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1633 | } Qop; |
| 1634 | |
| 1635 | /* A ternary operation. |
| 1636 | ppIRExpr output: <op>(<arg1>, <arg2>, <arg3>), |
| 1637 | eg. MulF64(1, 2.0, 3.0) |
| 1638 | */ |
| 1639 | struct { |
florian | 420bfa9 | 2012-06-02 20:29:22 +0000 | [diff] [blame] | 1640 | IRTriop* details; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1641 | } Triop; |
| 1642 | |
| 1643 | /* A binary operation. |
| 1644 | ppIRExpr output: <op>(<arg1>, <arg2>), eg. Add32(t1,t2) |
| 1645 | */ |
| 1646 | struct { |
| 1647 | IROp op; /* op-code */ |
| 1648 | IRExpr* arg1; /* operand 1 */ |
| 1649 | IRExpr* arg2; /* operand 2 */ |
| 1650 | } Binop; |
| 1651 | |
| 1652 | /* A unary operation. |
| 1653 | ppIRExpr output: <op>(<arg>), eg. Neg8(t1) |
| 1654 | */ |
| 1655 | struct { |
| 1656 | IROp op; /* op-code */ |
| 1657 | IRExpr* arg; /* operand */ |
| 1658 | } Unop; |
| 1659 | |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 1660 | /* A load from memory -- a normal load, not a load-linked. |
| 1661 | Load-Linkeds (and Store-Conditionals) are instead represented |
| 1662 | by IRStmt.LLSC since Load-Linkeds have side effects and so |
| 1663 | are not semantically valid IRExpr's. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1664 | ppIRExpr output: LD<end>:<ty>(<addr>), eg. LDle:I32(t1) |
| 1665 | */ |
| 1666 | struct { |
| 1667 | IREndness end; /* Endian-ness of the load */ |
| 1668 | IRType ty; /* Type of the loaded value */ |
| 1669 | IRExpr* addr; /* Address being loaded from */ |
| 1670 | } Load; |
| 1671 | |
| 1672 | /* A constant-valued expression. |
| 1673 | ppIRExpr output: <con>, eg. 0x4:I32 |
| 1674 | */ |
| 1675 | struct { |
| 1676 | IRConst* con; /* The constant itself */ |
| 1677 | } Const; |
| 1678 | |
| 1679 | /* A call to a pure (no side-effects) helper C function. |
| 1680 | |
| 1681 | With the 'cee' field, 'name' is the function's name. It is |
| 1682 | only used for pretty-printing purposes. The address to call |
| 1683 | (host address, of course) is stored in the 'addr' field |
| 1684 | inside 'cee'. |
| 1685 | |
| 1686 | The 'args' field is a NULL-terminated array of arguments. |
| 1687 | The stated return IRType, and the implied argument types, |
| 1688 | must match that of the function being called well enough so |
| 1689 | that the back end can actually generate correct code for the |
| 1690 | call. |
| 1691 | |
| 1692 | The called function **must** satisfy the following: |
| 1693 | |
| 1694 | * no side effects -- must be a pure function, the result of |
| 1695 | which depends only on the passed parameters. |
| 1696 | |
| 1697 | * it may not look at, nor modify, any of the guest state |
| 1698 | since that would hide guest state transitions from |
| 1699 | instrumenters |
| 1700 | |
| 1701 | * it may not access guest memory, since that would hide |
| 1702 | guest memory transactions from the instrumenters |
| 1703 | |
florian | 52af7bc | 2012-05-12 03:44:49 +0000 | [diff] [blame] | 1704 | * it must not assume that arguments are being evaluated in a |
| 1705 | particular order. The oder of evaluation is unspecified. |
| 1706 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1707 | This is restrictive, but makes the semantics clean, and does |
| 1708 | not interfere with IR optimisation. |
| 1709 | |
| 1710 | If you want to call a helper which can mess with guest state |
| 1711 | and/or memory, instead use Ist_Dirty. This is a lot more |
| 1712 | flexible, but you have to give a bunch of details about what |
| 1713 | the helper does (and you better be telling the truth, |
| 1714 | otherwise any derived instrumentation will be wrong). Also |
| 1715 | Ist_Dirty inhibits various IR optimisations and so can cause |
| 1716 | quite poor code to be generated. Try to avoid it. |
| 1717 | |
| 1718 | ppIRExpr output: <cee>(<args>):<retty> |
| 1719 | eg. foo{0x80489304}(t1, t2):I32 |
| 1720 | */ |
| 1721 | struct { |
| 1722 | IRCallee* cee; /* Function to call. */ |
| 1723 | IRType retty; /* Type of return value. */ |
| 1724 | IRExpr** args; /* Vector of argument expressions. */ |
| 1725 | } CCall; |
| 1726 | |
| 1727 | /* A ternary if-then-else operator. It returns expr0 if cond is |
| 1728 | zero, exprX otherwise. Note that it is STRICT, ie. both |
| 1729 | expr0 and exprX are evaluated in all cases. |
| 1730 | |
| 1731 | ppIRExpr output: Mux0X(<cond>,<expr0>,<exprX>), |
| 1732 | eg. Mux0X(t6,t7,t8) |
| 1733 | */ |
| 1734 | struct { |
| 1735 | IRExpr* cond; /* Condition */ |
| 1736 | IRExpr* expr0; /* True expression */ |
| 1737 | IRExpr* exprX; /* False expression */ |
| 1738 | } Mux0X; |
| 1739 | } Iex; |
| 1740 | }; |
| 1741 | |
florian | 420bfa9 | 2012-06-02 20:29:22 +0000 | [diff] [blame] | 1742 | /* ------------------ A ternary expression ---------------------- */ |
| 1743 | struct _IRTriop { |
| 1744 | IROp op; /* op-code */ |
| 1745 | IRExpr* arg1; /* operand 1 */ |
| 1746 | IRExpr* arg2; /* operand 2 */ |
| 1747 | IRExpr* arg3; /* operand 3 */ |
| 1748 | }; |
| 1749 | |
florian | 96d7cc3 | 2012-06-01 20:41:24 +0000 | [diff] [blame] | 1750 | /* ------------------ A quarternary expression ------------------ */ |
| 1751 | struct _IRQop { |
| 1752 | IROp op; /* op-code */ |
| 1753 | IRExpr* arg1; /* operand 1 */ |
| 1754 | IRExpr* arg2; /* operand 2 */ |
| 1755 | IRExpr* arg3; /* operand 3 */ |
| 1756 | IRExpr* arg4; /* operand 4 */ |
| 1757 | }; |
| 1758 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1759 | /* Expression constructors. */ |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 1760 | extern IRExpr* IRExpr_Binder ( Int binder ); |
| 1761 | extern IRExpr* IRExpr_Get ( Int off, IRType ty ); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1762 | extern IRExpr* IRExpr_GetI ( IRRegArray* descr, IRExpr* ix, Int bias ); |
| 1763 | extern IRExpr* IRExpr_RdTmp ( IRTemp tmp ); |
sewardj | 40c8026 | 2006-02-08 19:30:46 +0000 | [diff] [blame] | 1764 | extern IRExpr* IRExpr_Qop ( IROp op, IRExpr* arg1, IRExpr* arg2, |
| 1765 | IRExpr* arg3, IRExpr* arg4 ); |
sewardj | b183b85 | 2006-02-03 16:08:03 +0000 | [diff] [blame] | 1766 | extern IRExpr* IRExpr_Triop ( IROp op, IRExpr* arg1, |
| 1767 | IRExpr* arg2, IRExpr* arg3 ); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 1768 | extern IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 ); |
| 1769 | extern IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg ); |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 1770 | extern IRExpr* IRExpr_Load ( IREndness end, IRType ty, IRExpr* addr ); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 1771 | extern IRExpr* IRExpr_Const ( IRConst* con ); |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1772 | extern IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args ); |
sewardj | 443cd9d | 2004-07-18 23:06:45 +0000 | [diff] [blame] | 1773 | extern IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX ); |
sewardj | e3d0d2e | 2004-06-27 10:42:44 +0000 | [diff] [blame] | 1774 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1775 | /* Deep-copy an IRExpr. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1776 | extern IRExpr* deepCopyIRExpr ( IRExpr* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1777 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1778 | /* Pretty-print an IRExpr. */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 1779 | extern void ppIRExpr ( IRExpr* ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 1780 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1781 | /* NULL-terminated IRExpr vector constructors, suitable for |
| 1782 | use as arg lists in clean/dirty helper calls. */ |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1783 | extern IRExpr** mkIRExprVec_0 ( void ); |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1784 | extern IRExpr** mkIRExprVec_1 ( IRExpr* ); |
| 1785 | extern IRExpr** mkIRExprVec_2 ( IRExpr*, IRExpr* ); |
| 1786 | extern IRExpr** mkIRExprVec_3 ( IRExpr*, IRExpr*, IRExpr* ); |
| 1787 | extern IRExpr** mkIRExprVec_4 ( IRExpr*, IRExpr*, IRExpr*, IRExpr* ); |
sewardj | 78ec32b | 2007-01-08 05:09:55 +0000 | [diff] [blame] | 1788 | extern IRExpr** mkIRExprVec_5 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*, |
| 1789 | IRExpr* ); |
| 1790 | extern IRExpr** mkIRExprVec_6 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*, |
| 1791 | IRExpr*, IRExpr* ); |
| 1792 | extern IRExpr** mkIRExprVec_7 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*, |
sewardj | f32c67d | 2004-11-08 13:10:44 +0000 | [diff] [blame] | 1793 | IRExpr*, IRExpr*, IRExpr* ); |
sewardj | 2fdd416 | 2010-08-22 12:59:02 +0000 | [diff] [blame] | 1794 | extern IRExpr** mkIRExprVec_8 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*, |
| 1795 | IRExpr*, IRExpr*, IRExpr*, IRExpr*); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1796 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1797 | /* IRExpr copiers: |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1798 | - shallowCopy: shallow-copy (ie. create a new vector that shares the |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1799 | elements with the original). |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1800 | - deepCopy: deep-copy (ie. create a completely new vector). */ |
| 1801 | extern IRExpr** shallowCopyIRExprVec ( IRExpr** ); |
| 1802 | extern IRExpr** deepCopyIRExprVec ( IRExpr** ); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1803 | |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1804 | /* Make a constant expression from the given host word taking into |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1805 | account (of course) the host word size. */ |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1806 | extern IRExpr* mkIRExpr_HWord ( HWord ); |
| 1807 | |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1808 | /* Convenience function for constructing clean helper calls. */ |
| 1809 | extern |
| 1810 | IRExpr* mkIRExprCCall ( IRType retty, |
sewardj | 2d49b43 | 2005-02-01 00:37:06 +0000 | [diff] [blame] | 1811 | Int regparms, HChar* name, void* addr, |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1812 | IRExpr** args ); |
| 1813 | |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1814 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1815 | /* Convenience functions for atoms (IRExprs which are either Iex_Tmp or |
| 1816 | * Iex_Const). */ |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 1817 | static inline Bool isIRAtom ( IRExpr* e ) { |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1818 | return toBool(e->tag == Iex_RdTmp || e->tag == Iex_Const); |
sewardj | 49651f4 | 2004-10-28 22:11:04 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 1821 | /* Are these two IR atoms identical? Causes an assertion |
| 1822 | failure if they are passed non-atoms. */ |
| 1823 | extern Bool eqIRAtom ( IRExpr*, IRExpr* ); |
| 1824 | |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 1825 | |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1826 | /* ------------------ Jump kinds ------------------ */ |
| 1827 | |
| 1828 | /* This describes hints which can be passed to the dispatcher at guest |
| 1829 | control-flow transfer points. |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 1830 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1831 | Re Ijk_TInval: the guest state _must_ have two pseudo-registers, |
| 1832 | guest_TISTART and guest_TILEN, which specify the start and length |
| 1833 | of the region to be invalidated. These are both the size of a |
| 1834 | guest word. It is the responsibility of the relevant toIR.c to |
| 1835 | ensure that these are filled in with suitable values before issuing |
| 1836 | a jump of kind Ijk_TInval. |
sewardj | 9dd9cf1 | 2006-01-20 14:13:55 +0000 | [diff] [blame] | 1837 | |
| 1838 | Re Ijk_EmWarn and Ijk_EmFail: the guest state must have a |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1839 | pseudo-register guest_EMWARN, which is 32-bits regardless of the |
| 1840 | host or guest word size. That register should be made to hold an |
| 1841 | EmWarn_* value to indicate the reason for the exit. |
sewardj | 9dd9cf1 | 2006-01-20 14:13:55 +0000 | [diff] [blame] | 1842 | |
| 1843 | In the case of Ijk_EmFail, the exit is fatal (Vex-generated code |
| 1844 | cannot continue) and so the jump destination can be anything. |
sewardj | e86310f | 2009-03-19 22:21:40 +0000 | [diff] [blame] | 1845 | |
| 1846 | Re Ijk_Sys_ (syscall jumps): the guest state must have a |
| 1847 | pseudo-register guest_IP_AT_SYSCALL, which is the size of a guest |
| 1848 | word. Front ends should set this to be the IP at the most recently |
| 1849 | executed kernel-entering (system call) instruction. This makes it |
| 1850 | very much easier (viz, actually possible at all) to back up the |
| 1851 | guest to restart a syscall that has been interrupted by a signal. |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1852 | */ |
| 1853 | typedef |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 1854 | enum { |
| 1855 | Ijk_INVALID=0x16000, |
| 1856 | Ijk_Boring, /* not interesting; just goto next */ |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1857 | Ijk_Call, /* guest is doing a call */ |
| 1858 | Ijk_Ret, /* guest is doing a return */ |
| 1859 | Ijk_ClientReq, /* do guest client req before continuing */ |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1860 | Ijk_Yield, /* client is yielding to thread scheduler */ |
sewardj | 52444cb | 2004-12-13 14:09:01 +0000 | [diff] [blame] | 1861 | Ijk_EmWarn, /* report emulation warning before continuing */ |
sewardj | 9dd9cf1 | 2006-01-20 14:13:55 +0000 | [diff] [blame] | 1862 | Ijk_EmFail, /* emulation critical (FATAL) error; give up */ |
sewardj | 52444cb | 2004-12-13 14:09:01 +0000 | [diff] [blame] | 1863 | Ijk_NoDecode, /* next instruction cannot be decoded */ |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 1864 | Ijk_MapFail, /* Vex-provided address translation failed */ |
sewardj | f07ed03 | 2005-08-07 14:48:03 +0000 | [diff] [blame] | 1865 | Ijk_TInval, /* Invalidate translations before continuing. */ |
sewardj | ce02aa7 | 2006-01-12 12:27:58 +0000 | [diff] [blame] | 1866 | Ijk_NoRedir, /* Jump to un-redirected guest addr */ |
sewardj | 0f50004 | 2007-08-29 09:09:17 +0000 | [diff] [blame] | 1867 | Ijk_SigTRAP, /* current instruction synths SIGTRAP */ |
| 1868 | Ijk_SigSEGV, /* current instruction synths SIGSEGV */ |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 1869 | Ijk_SigBUS, /* current instruction synths SIGBUS */ |
sewardj | 4fa325a | 2005-11-03 13:27:24 +0000 | [diff] [blame] | 1870 | /* Unfortunately, various guest-dependent syscall kinds. They |
| 1871 | all mean: do a syscall before continuing. */ |
sewardj | 6c299f3 | 2009-12-31 18:00:12 +0000 | [diff] [blame] | 1872 | Ijk_Sys_syscall, /* amd64 'syscall', ppc 'sc', arm 'svc #0' */ |
sewardj | 4fa325a | 2005-11-03 13:27:24 +0000 | [diff] [blame] | 1873 | Ijk_Sys_int32, /* amd64/x86 'int $0x20' */ |
| 1874 | Ijk_Sys_int128, /* amd64/x86 'int $0x80' */ |
sewardj | d660d41 | 2008-12-03 21:29:59 +0000 | [diff] [blame] | 1875 | Ijk_Sys_int129, /* amd64/x86 'int $0x81' */ |
| 1876 | Ijk_Sys_int130, /* amd64/x86 'int $0x82' */ |
sewardj | 4fa325a | 2005-11-03 13:27:24 +0000 | [diff] [blame] | 1877 | Ijk_Sys_sysenter /* x86 'sysenter'. guest_EIP becomes |
| 1878 | invalid at the point this happens. */ |
sewardj | 893aada | 2004-11-29 19:57:54 +0000 | [diff] [blame] | 1879 | } |
| 1880 | IRJumpKind; |
| 1881 | |
| 1882 | extern void ppIRJumpKind ( IRJumpKind ); |
| 1883 | |
| 1884 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1885 | /* ------------------ Dirty helper calls ------------------ */ |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 1886 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1887 | /* A dirty call is a flexible mechanism for calling (possibly |
| 1888 | conditionally) a helper function or procedure. The helper function |
| 1889 | may read, write or modify client memory, and may read, write or |
| 1890 | modify client state. It can take arguments and optionally return a |
| 1891 | value. It may return different results and/or do different things |
| 1892 | when called repeatedly with the same arguments, by means of storing |
| 1893 | private state. |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 1894 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1895 | If a value is returned, it is assigned to the nominated return |
| 1896 | temporary. |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1897 | |
| 1898 | Dirty calls are statements rather than expressions for obvious |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1899 | reasons. If a dirty call is marked as writing guest state, any |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1900 | values derived from the written parts of the guest state are |
| 1901 | invalid. Similarly, if the dirty call is stated as writing |
| 1902 | memory, any loaded values are invalidated by it. |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1903 | |
| 1904 | In order that instrumentation is possible, the call must state, and |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1905 | state correctly: |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1906 | |
| 1907 | * whether it reads, writes or modifies memory, and if so where |
| 1908 | (only one chunk can be stated) |
| 1909 | |
| 1910 | * whether it reads, writes or modifies guest state, and if so which |
| 1911 | pieces (several pieces may be stated, and currently their extents |
| 1912 | must be known at translation-time). |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1913 | |
| 1914 | Normally, code is generated to pass just the args to the helper. |
| 1915 | However, if .needsBBP is set, then an extra first argument is |
| 1916 | passed, which is the baseblock pointer, so that the callee can |
| 1917 | access the guest state. It is invalid for .nFxState to be zero |
| 1918 | but .needsBBP to be True, since .nFxState==0 is a claim that the |
| 1919 | call does not access guest state. |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1920 | |
| 1921 | IMPORTANT NOTE re GUARDS: Dirty calls are strict, very strict. The |
florian | 52af7bc | 2012-05-12 03:44:49 +0000 | [diff] [blame] | 1922 | arguments are evaluated REGARDLESS of the guard value. The order of |
| 1923 | argument evaluation is unspecified. The guard expression is evaluated |
| 1924 | AFTER the arguments have been evaluated. |
sewardj | e87b484 | 2004-07-10 12:23:30 +0000 | [diff] [blame] | 1925 | */ |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 1926 | |
sewardj | a0e83b0 | 2005-01-06 12:36:38 +0000 | [diff] [blame] | 1927 | #define VEX_N_FXSTATE 7 /* enough for FXSAVE/FXRSTOR on x86 */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1928 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1929 | /* Effects on resources (eg. registers, memory locations) */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1930 | typedef |
| 1931 | enum { |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 1932 | Ifx_None = 0x1700, /* no effect */ |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 1933 | Ifx_Read, /* reads the resource */ |
| 1934 | Ifx_Write, /* writes the resource */ |
| 1935 | Ifx_Modify, /* modifies the resource */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1936 | } |
| 1937 | IREffect; |
| 1938 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1939 | /* Pretty-print an IREffect */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1940 | extern void ppIREffect ( IREffect ); |
| 1941 | |
| 1942 | |
| 1943 | typedef |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 1944 | struct _IRDirty { |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1945 | /* What to call, and details of args/results */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1946 | IRCallee* cee; /* where to call */ |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1947 | IRExpr* guard; /* :: Ity_Bit. Controls whether call happens */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1948 | IRExpr** args; /* arg list, ends in NULL */ |
sewardj | 92d168d | 2004-11-15 14:22:12 +0000 | [diff] [blame] | 1949 | IRTemp tmp; /* to assign result to, or IRTemp_INVALID if none */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1950 | |
| 1951 | /* Mem effects; we allow only one R/W/M region to be stated */ |
sewardj | 8ea867b | 2004-10-30 19:03:02 +0000 | [diff] [blame] | 1952 | IREffect mFx; /* indicates memory effects, if any */ |
| 1953 | IRExpr* mAddr; /* of access, or NULL if mFx==Ifx_None */ |
| 1954 | Int mSize; /* of access, or zero if mFx==Ifx_None */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1955 | |
| 1956 | /* Guest state effects; up to N allowed */ |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1957 | Bool needsBBP; /* True => also pass guest state ptr to callee */ |
| 1958 | Int nFxState; /* must be 0 .. VEX_N_FXSTATE */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1959 | struct { |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 1960 | IREffect fx:16; /* read, write or modify? Ifx_None is invalid. */ |
| 1961 | UShort offset; |
| 1962 | UShort size; |
| 1963 | UChar nRepeats; |
| 1964 | UChar repeatLen; |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1965 | } fxState[VEX_N_FXSTATE]; |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 1966 | /* The access can be repeated, as specified by nRepeats and |
| 1967 | repeatLen. To describe only a single access, nRepeats and |
| 1968 | repeatLen should be zero. Otherwise, repeatLen must be a |
| 1969 | multiple of size and greater than size. */ |
| 1970 | /* Overall, the parts of the guest state denoted by (offset, |
| 1971 | size, nRepeats, repeatLen) is |
| 1972 | [offset, +size) |
| 1973 | and, if nRepeats > 0, |
| 1974 | for (i = 1; i <= nRepeats; i++) |
| 1975 | [offset + i * repeatLen, +size) |
| 1976 | A convenient way to enumerate all segments is therefore |
| 1977 | for (i = 0; i < 1 + nRepeats; i++) |
| 1978 | [offset + i * repeatLen, +size) |
| 1979 | */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1980 | } |
| 1981 | IRDirty; |
| 1982 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1983 | /* Pretty-print a dirty call */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1984 | extern void ppIRDirty ( IRDirty* ); |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1985 | |
| 1986 | /* Allocate an uninitialised dirty call */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 1987 | extern IRDirty* emptyIRDirty ( void ); |
| 1988 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1989 | /* Deep-copy a dirty call */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 1990 | extern IRDirty* deepCopyIRDirty ( IRDirty* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 1991 | |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 1992 | /* A handy function which takes some of the tedium out of constructing |
| 1993 | dirty helper calls. The called function impliedly does not return |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1994 | any value and has a constant-True guard. The call is marked as |
| 1995 | accessing neither guest state nor memory (hence the "unsafe" |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 1996 | designation) -- you can change this marking later if need be. A |
sewardj | b8385d8 | 2004-11-02 01:34:15 +0000 | [diff] [blame] | 1997 | suitable IRCallee is constructed from the supplied bits. */ |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 1998 | extern |
sewardj | 2d49b43 | 2005-02-01 00:37:06 +0000 | [diff] [blame] | 1999 | IRDirty* unsafeIRDirty_0_N ( Int regparms, HChar* name, void* addr, |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 2000 | IRExpr** args ); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 2001 | |
| 2002 | /* Similarly, make a zero-annotation dirty call which returns a value, |
| 2003 | and assign that to the given temp. */ |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 2004 | extern |
| 2005 | IRDirty* unsafeIRDirty_1_N ( IRTemp dst, |
sewardj | 2d49b43 | 2005-02-01 00:37:06 +0000 | [diff] [blame] | 2006 | Int regparms, HChar* name, void* addr, |
sewardj | f965526 | 2004-10-31 20:02:16 +0000 | [diff] [blame] | 2007 | IRExpr** args ); |
sewardj | c5fc7aa | 2004-10-27 23:00:55 +0000 | [diff] [blame] | 2008 | |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 2009 | |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2010 | /* --------------- Memory Bus Events --------------- */ |
| 2011 | |
| 2012 | typedef |
| 2013 | enum { |
| 2014 | Imbe_Fence=0x18000, |
sewardj | 6d615ba | 2011-09-26 16:19:43 +0000 | [diff] [blame] | 2015 | /* Needed only on ARM. It cancels a reservation made by a |
| 2016 | preceding Linked-Load, and needs to be handed through to the |
| 2017 | back end, just as LL and SC themselves are. */ |
| 2018 | Imbe_CancelReservation |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2019 | } |
| 2020 | IRMBusEvent; |
| 2021 | |
| 2022 | extern void ppIRMBusEvent ( IRMBusEvent ); |
| 2023 | |
| 2024 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2025 | /* --------------- Compare and Swap --------------- */ |
| 2026 | |
| 2027 | /* This denotes an atomic compare and swap operation, either |
| 2028 | a single-element one or a double-element one. |
| 2029 | |
| 2030 | In the single-element case: |
| 2031 | |
| 2032 | .addr is the memory address. |
| 2033 | .end is the endianness with which memory is accessed |
| 2034 | |
| 2035 | If .addr contains the same value as .expdLo, then .dataLo is |
| 2036 | written there, else there is no write. In both cases, the |
| 2037 | original value at .addr is copied into .oldLo. |
| 2038 | |
| 2039 | Types: .expdLo, .dataLo and .oldLo must all have the same type. |
| 2040 | It may be any integral type, viz: I8, I16, I32 or, for 64-bit |
| 2041 | guests, I64. |
| 2042 | |
| 2043 | .oldHi must be IRTemp_INVALID, and .expdHi and .dataHi must |
| 2044 | be NULL. |
| 2045 | |
| 2046 | In the double-element case: |
| 2047 | |
| 2048 | .addr is the memory address. |
| 2049 | .end is the endianness with which memory is accessed |
| 2050 | |
| 2051 | The operation is the same: |
| 2052 | |
| 2053 | If .addr contains the same value as .expdHi:.expdLo, then |
| 2054 | .dataHi:.dataLo is written there, else there is no write. In |
| 2055 | both cases the original value at .addr is copied into |
| 2056 | .oldHi:.oldLo. |
| 2057 | |
| 2058 | Types: .expdHi, .expdLo, .dataHi, .dataLo, .oldHi, .oldLo must |
| 2059 | all have the same type, which may be any integral type, viz: I8, |
| 2060 | I16, I32 or, for 64-bit guests, I64. |
| 2061 | |
| 2062 | The double-element case is complicated by the issue of |
| 2063 | endianness. In all cases, the two elements are understood to be |
| 2064 | located adjacently in memory, starting at the address .addr. |
| 2065 | |
| 2066 | If .end is Iend_LE, then the .xxxLo component is at the lower |
| 2067 | address and the .xxxHi component is at the higher address, and |
| 2068 | each component is itself stored little-endianly. |
| 2069 | |
| 2070 | If .end is Iend_BE, then the .xxxHi component is at the lower |
| 2071 | address and the .xxxLo component is at the higher address, and |
| 2072 | each component is itself stored big-endianly. |
| 2073 | |
| 2074 | This allows representing more cases than most architectures can |
| 2075 | handle. For example, x86 cannot do DCAS on 8- or 16-bit elements. |
| 2076 | |
| 2077 | How to know if the CAS succeeded? |
| 2078 | |
| 2079 | * if .oldLo == .expdLo (resp. .oldHi:.oldLo == .expdHi:.expdLo), |
| 2080 | then the CAS succeeded, .dataLo (resp. .dataHi:.dataLo) is now |
| 2081 | stored at .addr, and the original value there was .oldLo (resp |
| 2082 | .oldHi:.oldLo). |
| 2083 | |
| 2084 | * if .oldLo != .expdLo (resp. .oldHi:.oldLo != .expdHi:.expdLo), |
| 2085 | then the CAS failed, and the original value at .addr was .oldLo |
| 2086 | (resp. .oldHi:.oldLo). |
| 2087 | |
| 2088 | Hence it is easy to know whether or not the CAS succeeded. |
| 2089 | */ |
| 2090 | typedef |
| 2091 | struct { |
| 2092 | IRTemp oldHi; /* old value of *addr is written here */ |
| 2093 | IRTemp oldLo; |
| 2094 | IREndness end; /* endianness of the data in memory */ |
| 2095 | IRExpr* addr; /* store address */ |
| 2096 | IRExpr* expdHi; /* expected old value at *addr */ |
| 2097 | IRExpr* expdLo; |
| 2098 | IRExpr* dataHi; /* new value for *addr */ |
| 2099 | IRExpr* dataLo; |
| 2100 | } |
| 2101 | IRCAS; |
| 2102 | |
| 2103 | extern void ppIRCAS ( IRCAS* cas ); |
| 2104 | |
| 2105 | extern IRCAS* mkIRCAS ( IRTemp oldHi, IRTemp oldLo, |
| 2106 | IREndness end, IRExpr* addr, |
| 2107 | IRExpr* expdHi, IRExpr* expdLo, |
| 2108 | IRExpr* dataHi, IRExpr* dataLo ); |
| 2109 | |
| 2110 | extern IRCAS* deepCopyIRCAS ( IRCAS* ); |
| 2111 | |
florian | d6f38b3 | 2012-05-31 15:46:18 +0000 | [diff] [blame] | 2112 | |
| 2113 | /* ------------------ Circular Array Put ------------------ */ |
| 2114 | typedef |
| 2115 | struct { |
| 2116 | IRRegArray* descr; /* Part of guest state treated as circular */ |
| 2117 | IRExpr* ix; /* Variable part of index into array */ |
| 2118 | Int bias; /* Constant offset part of index into array */ |
| 2119 | IRExpr* data; /* The value to write */ |
| 2120 | } IRPutI; |
| 2121 | |
| 2122 | extern void ppIRPutI ( IRPutI* puti ); |
| 2123 | |
| 2124 | extern IRPutI* mkIRPutI ( IRRegArray* descr, IRExpr* ix, |
| 2125 | Int bias, IRExpr* data ); |
| 2126 | |
| 2127 | extern IRPutI* deepCopyIRPutI ( IRPutI* ); |
| 2128 | |
sewardj | c9069f2 | 2012-06-01 16:09:50 +0000 | [diff] [blame] | 2129 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2130 | /* ------------------ Statements ------------------ */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 2131 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2132 | /* The different kinds of statements. Their meaning is explained |
| 2133 | below in the comments for IRStmt. |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2134 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2135 | Those marked META do not represent code, but rather extra |
| 2136 | information about the code. These statements can be removed |
| 2137 | without affecting the functional behaviour of the code, however |
| 2138 | they are required by some IR consumers such as tools that |
| 2139 | instrument the code. |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2140 | */ |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2141 | |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2142 | typedef |
sewardj | d2445f6 | 2005-03-21 00:15:53 +0000 | [diff] [blame] | 2143 | enum { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2144 | Ist_NoOp=0x19000, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2145 | Ist_IMark, /* META */ |
| 2146 | Ist_AbiHint, /* META */ |
| 2147 | Ist_Put, |
| 2148 | Ist_PutI, |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2149 | Ist_WrTmp, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2150 | Ist_Store, |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2151 | Ist_CAS, |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 2152 | Ist_LLSC, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2153 | Ist_Dirty, |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2154 | Ist_MBE, /* META (maybe) */ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2155 | Ist_Exit |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 2156 | } |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2157 | IRStmtTag; |
| 2158 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2159 | /* A statement. Stored as a tagged union. 'tag' indicates what kind |
| 2160 | of expression this is. 'Ist' is the union that holds the fields. |
| 2161 | If an IRStmt 'st' has st.tag equal to Iex_Store, then it's a store |
| 2162 | statement, and the fields can be accessed with |
| 2163 | 'st.Ist.Store.<fieldname>'. |
| 2164 | |
| 2165 | For each kind of statement, we show what it looks like when |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2166 | pretty-printed with ppIRStmt(). |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2167 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2168 | typedef |
| 2169 | struct _IRStmt { |
| 2170 | IRStmtTag tag; |
| 2171 | union { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2172 | /* A no-op (usually resulting from IR optimisation). Can be |
| 2173 | omitted without any effect. |
| 2174 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2175 | ppIRStmt output: IR-NoOp |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2176 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2177 | struct { |
sewardj | d2445f6 | 2005-03-21 00:15:53 +0000 | [diff] [blame] | 2178 | } NoOp; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2179 | |
| 2180 | /* META: instruction mark. Marks the start of the statements |
| 2181 | that represent a single machine instruction (the end of |
| 2182 | those statements is marked by the next IMark or the end of |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2183 | the IRSB). Contains the address and length of the |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2184 | instruction. |
| 2185 | |
sewardj | 2f10aa6 | 2011-05-27 13:20:56 +0000 | [diff] [blame] | 2186 | It also contains a delta value. The delta must be |
| 2187 | subtracted from a guest program counter value before |
| 2188 | attempting to establish, by comparison with the address |
| 2189 | and length values, whether or not that program counter |
| 2190 | value refers to this instruction. For x86, amd64, ppc32, |
| 2191 | ppc64 and arm, the delta value is zero. For Thumb |
| 2192 | instructions, the delta value is one. This is because, on |
| 2193 | Thumb, guest PC values (guest_R15T) are encoded using the |
| 2194 | top 31 bits of the instruction address and a 1 in the lsb; |
| 2195 | hence they appear to be (numerically) 1 past the start of |
| 2196 | the instruction they refer to. IOW, guest_R15T on ARM |
| 2197 | holds a standard ARM interworking address. |
| 2198 | |
| 2199 | ppIRStmt output: ------ IMark(<addr>, <len>, <delta>) ------, |
| 2200 | eg. ------ IMark(0x4000792, 5, 0) ------, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2201 | */ |
sewardj | d2445f6 | 2005-03-21 00:15:53 +0000 | [diff] [blame] | 2202 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2203 | Addr64 addr; /* instruction address */ |
| 2204 | Int len; /* instruction length */ |
sewardj | 2f10aa6 | 2011-05-27 13:20:56 +0000 | [diff] [blame] | 2205 | UChar delta; /* addr = program counter as encoded in guest state |
| 2206 | - delta */ |
sewardj | f168931 | 2005-03-16 18:19:10 +0000 | [diff] [blame] | 2207 | } IMark; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2208 | |
| 2209 | /* META: An ABI hint, which says something about this |
| 2210 | platform's ABI. |
| 2211 | |
| 2212 | At the moment, the only AbiHint is one which indicates |
| 2213 | that a given chunk of address space, [base .. base+len-1], |
| 2214 | has become undefined. This is used on amd64-linux and |
| 2215 | some ppc variants to pass stack-redzoning hints to whoever |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 2216 | wants to see them. It also indicates the address of the |
| 2217 | next (dynamic) instruction that will be executed. This is |
| 2218 | to help Memcheck to origin tracking. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2219 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2220 | ppIRStmt output: ====== AbiHint(<base>, <len>, <nia>) ====== |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 2221 | eg. ====== AbiHint(t1, 16, t2) ====== |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2222 | */ |
sewardj | f168931 | 2005-03-16 18:19:10 +0000 | [diff] [blame] | 2223 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2224 | IRExpr* base; /* Start of undefined chunk */ |
| 2225 | Int len; /* Length of undefined chunk */ |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 2226 | IRExpr* nia; /* Address of next (guest) insn */ |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2227 | } AbiHint; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2228 | |
| 2229 | /* Write a guest register, at a fixed offset in the guest state. |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2230 | ppIRStmt output: PUT(<offset>) = <data>, eg. PUT(60) = t1 |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2231 | */ |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2232 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2233 | Int offset; /* Offset into the guest state */ |
| 2234 | IRExpr* data; /* The value to write */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2235 | } Put; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2236 | |
| 2237 | /* Write a guest register, at a non-fixed offset in the guest |
| 2238 | state. See the comment for GetI expressions for more |
| 2239 | information. |
| 2240 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2241 | ppIRStmt output: PUTI<descr>[<ix>,<bias>] = <data>, |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2242 | eg. PUTI(64:8xF64)[t5,0] = t1 |
| 2243 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2244 | struct { |
florian | d6f38b3 | 2012-05-31 15:46:18 +0000 | [diff] [blame] | 2245 | IRPutI* details; |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 2246 | } PutI; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2247 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2248 | /* Assign a value to a temporary. Note that SSA rules require |
| 2249 | each tmp is only assigned to once. IR sanity checking will |
| 2250 | reject any block containing a temporary which is not assigned |
| 2251 | to exactly once. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2252 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2253 | ppIRStmt output: t<tmp> = <data>, eg. t1 = 3 |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2254 | */ |
sewardj | d1725d1 | 2004-08-12 20:46:53 +0000 | [diff] [blame] | 2255 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2256 | IRTemp tmp; /* Temporary (LHS of assignment) */ |
| 2257 | IRExpr* data; /* Expression (RHS of assignment) */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2258 | } WrTmp; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2259 | |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 2260 | /* Write a value to memory. This is a normal store, not a |
| 2261 | Store-Conditional. To represent a Store-Conditional, |
| 2262 | instead use IRStmt.LLSC. |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2263 | ppIRStmt output: ST<end>(<addr>) = <data>, eg. STle(t1) = t2 |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2264 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2265 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2266 | IREndness end; /* Endianness of the store */ |
| 2267 | IRExpr* addr; /* store address */ |
| 2268 | IRExpr* data; /* value to write */ |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 2269 | } Store; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2270 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2271 | /* Do an atomic compare-and-swap operation. Semantics are |
| 2272 | described above on a comment at the definition of IRCAS. |
| 2273 | |
| 2274 | ppIRStmt output: |
| 2275 | t<tmp> = CAS<end>(<addr> :: <expected> -> <new>) |
| 2276 | eg |
| 2277 | t1 = CASle(t2 :: t3->Add32(t3,1)) |
| 2278 | which denotes a 32-bit atomic increment |
| 2279 | of a value at address t2 |
| 2280 | |
| 2281 | A double-element CAS may also be denoted, in which case <tmp>, |
| 2282 | <expected> and <new> are all pairs of items, separated by |
| 2283 | commas. |
| 2284 | */ |
| 2285 | struct { |
| 2286 | IRCAS* details; |
| 2287 | } CAS; |
| 2288 | |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 2289 | /* Either Load-Linked or Store-Conditional, depending on |
| 2290 | STOREDATA. |
| 2291 | |
| 2292 | If STOREDATA is NULL then this is a Load-Linked, meaning |
| 2293 | that data is loaded from memory as normal, but a |
| 2294 | 'reservation' for the address is also lodged in the |
| 2295 | hardware. |
| 2296 | |
| 2297 | result = Load-Linked(addr, end) |
| 2298 | |
| 2299 | The data transfer type is the type of RESULT (I32, I64, |
| 2300 | etc). ppIRStmt output: |
| 2301 | |
| 2302 | result = LD<end>-Linked(<addr>), eg. LDbe-Linked(t1) |
| 2303 | |
| 2304 | If STOREDATA is not NULL then this is a Store-Conditional, |
| 2305 | hence: |
| 2306 | |
| 2307 | result = Store-Conditional(addr, storedata, end) |
| 2308 | |
| 2309 | The data transfer type is the type of STOREDATA and RESULT |
| 2310 | has type Ity_I1. The store may fail or succeed depending |
| 2311 | on the state of a previously lodged reservation on this |
| 2312 | address. RESULT is written 1 if the store succeeds and 0 |
| 2313 | if it fails. eg ppIRStmt output: |
| 2314 | |
| 2315 | result = ( ST<end>-Cond(<addr>) = <storedata> ) |
| 2316 | eg t3 = ( STbe-Cond(t1, t2) ) |
| 2317 | |
| 2318 | In all cases, the address must be naturally aligned for |
| 2319 | the transfer type -- any misaligned addresses should be |
| 2320 | caught by a dominating IR check and side exit. This |
| 2321 | alignment restriction exists because on at least some |
| 2322 | LL/SC platforms (ppc), stwcx. etc will trap w/ SIGBUS on |
| 2323 | misaligned addresses, and we have to actually generate |
| 2324 | stwcx. on the host, and we don't want it trapping on the |
| 2325 | host. |
| 2326 | |
| 2327 | Summary of rules for transfer type: |
| 2328 | STOREDATA == NULL (LL): |
| 2329 | transfer type = type of RESULT |
| 2330 | STOREDATA != NULL (SC): |
| 2331 | transfer type = type of STOREDATA, and RESULT :: Ity_I1 |
| 2332 | */ |
| 2333 | struct { |
| 2334 | IREndness end; |
| 2335 | IRTemp result; |
| 2336 | IRExpr* addr; |
| 2337 | IRExpr* storedata; /* NULL => LL, non-NULL => SC */ |
| 2338 | } LLSC; |
| 2339 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2340 | /* Call (possibly conditionally) a C function that has side |
| 2341 | effects (ie. is "dirty"). See the comments above the |
| 2342 | IRDirty type declaration for more information. |
| 2343 | |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2344 | ppIRStmt output: |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2345 | t<tmp> = DIRTY <guard> <effects> |
| 2346 | ::: <callee>(<args>) |
| 2347 | eg. |
| 2348 | t1 = DIRTY t27 RdFX-gst(16,4) RdFX-gst(60,4) |
| 2349 | ::: foo{0x380035f4}(t2) |
| 2350 | */ |
sewardj | 64e1d65 | 2004-07-12 14:00:46 +0000 | [diff] [blame] | 2351 | struct { |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 2352 | IRDirty* details; |
| 2353 | } Dirty; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2354 | |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2355 | /* A memory bus event - a fence, or acquisition/release of the |
| 2356 | hardware bus lock. IR optimisation treats all these as fences |
| 2357 | across which no memory references may be moved. |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2358 | ppIRStmt output: MBusEvent-Fence, |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2359 | MBusEvent-BusLock, MBusEvent-BusUnlock. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2360 | */ |
sewardj | b3bce0e | 2004-09-14 23:20:10 +0000 | [diff] [blame] | 2361 | struct { |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2362 | IRMBusEvent event; |
| 2363 | } MBE; |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2364 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2365 | /* Conditional exit from the middle of an IRSB. |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2366 | ppIRStmt output: if (<guard>) goto {<jk>} <dst> |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2367 | eg. if (t69) goto {Boring} 0x4000AAA:I32 |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 2368 | If <guard> is true, the guest state is also updated by |
| 2369 | PUT-ing <dst> at <offsIP>. This is done because a |
| 2370 | taken exit must update the guest program counter. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2371 | */ |
sewardj | 3e83893 | 2005-01-07 12:09:15 +0000 | [diff] [blame] | 2372 | struct { |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2373 | IRExpr* guard; /* Conditional expression */ |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2374 | IRConst* dst; /* Jump target (constant only) */ |
florian | d6f38b3 | 2012-05-31 15:46:18 +0000 | [diff] [blame] | 2375 | IRJumpKind jk; /* Jump kind */ |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 2376 | Int offsIP; /* Guest state offset for IP */ |
sewardj | 64e1d65 | 2004-07-12 14:00:46 +0000 | [diff] [blame] | 2377 | } Exit; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2378 | } Ist; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2379 | } |
| 2380 | IRStmt; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2381 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2382 | /* Statement constructors. */ |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2383 | extern IRStmt* IRStmt_NoOp ( void ); |
sewardj | 2f10aa6 | 2011-05-27 13:20:56 +0000 | [diff] [blame] | 2384 | extern IRStmt* IRStmt_IMark ( Addr64 addr, Int len, UChar delta ); |
sewardj | 478646f | 2008-05-01 20:13:04 +0000 | [diff] [blame] | 2385 | extern IRStmt* IRStmt_AbiHint ( IRExpr* base, Int len, IRExpr* nia ); |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2386 | extern IRStmt* IRStmt_Put ( Int off, IRExpr* data ); |
florian | d6f38b3 | 2012-05-31 15:46:18 +0000 | [diff] [blame] | 2387 | extern IRStmt* IRStmt_PutI ( IRPutI* details ); |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2388 | extern IRStmt* IRStmt_WrTmp ( IRTemp tmp, IRExpr* data ); |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 2389 | extern IRStmt* IRStmt_Store ( IREndness end, IRExpr* addr, IRExpr* data ); |
sewardj | e9d8a26 | 2009-07-01 08:06:34 +0000 | [diff] [blame] | 2390 | extern IRStmt* IRStmt_CAS ( IRCAS* details ); |
sewardj | e768e92 | 2009-11-26 17:17:37 +0000 | [diff] [blame] | 2391 | extern IRStmt* IRStmt_LLSC ( IREndness end, IRTemp result, |
| 2392 | IRExpr* addr, IRExpr* storedata ); |
sewardj | 5a9ffab | 2005-05-12 17:55:01 +0000 | [diff] [blame] | 2393 | extern IRStmt* IRStmt_Dirty ( IRDirty* details ); |
sewardj | c4356f0 | 2007-11-09 21:15:04 +0000 | [diff] [blame] | 2394 | extern IRStmt* IRStmt_MBE ( IRMBusEvent event ); |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 2395 | extern IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst, |
| 2396 | Int offsIP ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2397 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2398 | /* Deep-copy an IRStmt. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2399 | extern IRStmt* deepCopyIRStmt ( IRStmt* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 2400 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2401 | /* Pretty-print an IRStmt. */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 2402 | extern void ppIRStmt ( IRStmt* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2403 | |
| 2404 | |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 2405 | /* ------------------ Basic Blocks ------------------ */ |
sewardj | 78c19df | 2004-07-12 22:49:27 +0000 | [diff] [blame] | 2406 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2407 | /* Type environments: a bunch of statements, expressions, etc, are |
| 2408 | incomplete without an environment indicating the type of each |
| 2409 | IRTemp. So this provides one. IR temporaries are really just |
| 2410 | unsigned ints and so this provides an array, 0 .. n_types_used-1 of |
| 2411 | them. |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2412 | */ |
| 2413 | typedef |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2414 | struct { |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 2415 | IRType* types; |
| 2416 | Int types_size; |
| 2417 | Int types_used; |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2418 | } |
| 2419 | IRTypeEnv; |
| 2420 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2421 | /* Obtain a new IRTemp */ |
| 2422 | extern IRTemp newIRTemp ( IRTypeEnv*, IRType ); |
| 2423 | |
| 2424 | /* Deep-copy a type environment */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2425 | extern IRTypeEnv* deepCopyIRTypeEnv ( IRTypeEnv* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 2426 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2427 | /* Pretty-print a type environment */ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 2428 | extern void ppIRTypeEnv ( IRTypeEnv* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2429 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2430 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2431 | /* Code blocks, which in proper compiler terminology are superblocks |
| 2432 | (single entry, multiple exit code sequences) contain: |
| 2433 | |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2434 | - A table giving a type for each temp (the "type environment") |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 2435 | - An expandable array of statements |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 2436 | - An expression of type 32 or 64 bits, depending on the |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2437 | guest's word size, indicating the next destination if the block |
| 2438 | executes all the way to the end, without a side exit |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 2439 | - An indication of any special actions (JumpKind) needed |
| 2440 | for this final jump. |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 2441 | - Offset of the IP field in the guest state. This will be |
| 2442 | updated before the final jump is done. |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2443 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2444 | "IRSB" stands for "IR Super Block". |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2445 | */ |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2446 | typedef |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2447 | struct { |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2448 | IRTypeEnv* tyenv; |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 2449 | IRStmt** stmts; |
| 2450 | Int stmts_size; |
| 2451 | Int stmts_used; |
sewardj | e539a40 | 2004-07-14 18:24:17 +0000 | [diff] [blame] | 2452 | IRExpr* next; |
| 2453 | IRJumpKind jumpkind; |
sewardj | c6f970f | 2012-04-02 21:54:49 +0000 | [diff] [blame] | 2454 | Int offsIP; |
sewardj | ac6b712 | 2004-06-27 01:03:57 +0000 | [diff] [blame] | 2455 | } |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2456 | IRSB; |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2457 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2458 | /* Allocate a new, uninitialised IRSB */ |
| 2459 | extern IRSB* emptyIRSB ( void ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 2460 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2461 | /* Deep-copy an IRSB */ |
| 2462 | extern IRSB* deepCopyIRSB ( IRSB* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2463 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2464 | /* Deep-copy an IRSB, except for the statements list, which set to be |
sewardj | 6f2f283 | 2006-11-24 23:32:55 +0000 | [diff] [blame] | 2465 | a new, empty, list of statements. */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2466 | extern IRSB* deepCopyIRSBExceptStmts ( IRSB* ); |
sewardj | 57c10c8 | 2006-11-15 02:57:05 +0000 | [diff] [blame] | 2467 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2468 | /* Pretty-print an IRSB */ |
| 2469 | extern void ppIRSB ( IRSB* ); |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2470 | |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2471 | /* Append an IRStmt to an IRSB */ |
| 2472 | extern void addStmtToIRSB ( IRSB*, IRStmt* ); |
sewardj | 695cff9 | 2004-10-13 14:50:14 +0000 | [diff] [blame] | 2473 | |
| 2474 | |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2475 | /*---------------------------------------------------------------*/ |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2476 | /*--- Helper functions for the IR ---*/ |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2477 | /*---------------------------------------------------------------*/ |
| 2478 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2479 | /* For messing with IR type environments */ |
sewardj | d7cb853 | 2004-08-17 23:59:23 +0000 | [diff] [blame] | 2480 | extern IRTypeEnv* emptyIRTypeEnv ( void ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2481 | |
sewardj | c97096c | 2004-06-30 09:28:04 +0000 | [diff] [blame] | 2482 | /* What is the type of this expression? */ |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 2483 | extern IRType typeOfIRConst ( IRConst* ); |
sewardj | 17442fe | 2004-09-20 14:54:28 +0000 | [diff] [blame] | 2484 | extern IRType typeOfIRTemp ( IRTypeEnv*, IRTemp ); |
sewardj | 6efd4a1 | 2004-07-15 03:54:23 +0000 | [diff] [blame] | 2485 | extern IRType typeOfIRExpr ( IRTypeEnv*, IRExpr* ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2486 | |
sewardj | 3543921 | 2004-07-14 22:36:10 +0000 | [diff] [blame] | 2487 | /* Sanity check a BB of IR */ |
sewardj | dd40fdf | 2006-12-24 02:20:24 +0000 | [diff] [blame] | 2488 | extern void sanityCheckIRSB ( IRSB* bb, |
sewardj | b923075 | 2004-12-29 19:25:06 +0000 | [diff] [blame] | 2489 | HChar* caller, |
| 2490 | Bool require_flatness, |
| 2491 | IRType guest_word_size ); |
sewardj | cf78790 | 2004-11-03 09:08:33 +0000 | [diff] [blame] | 2492 | extern Bool isFlatIRStmt ( IRStmt* ); |
sewardj | ec6ad59 | 2004-06-20 12:26:53 +0000 | [diff] [blame] | 2493 | |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 2494 | /* Is this any value actually in the enumeration 'IRType' ? */ |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 2495 | extern Bool isPlausibleIRType ( IRType ty ); |
sewardj | 6d2638e | 2004-07-15 09:38:27 +0000 | [diff] [blame] | 2496 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 2497 | #endif /* ndef __LIBVEX_IR_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 2498 | |
| 2499 | |
| 2500 | /*---------------------------------------------------------------*/ |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 2501 | /*--- libvex_ir.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 2502 | /*---------------------------------------------------------------*/ |