nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 1 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | /*--------------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3 | /*--- Instrument IR to perform memory checking operations. ---*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 4 | /*--- mc_translate.c ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5 | /*--------------------------------------------------------------------*/ |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 6 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 7 | /* |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 8 | This file is part of MemCheck, a heavyweight Valgrind tool for |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 9 | detecting memory errors. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | |
sewardj | 0f157dd | 2013-10-18 14:27:36 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2013 Julian Seward |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 12 | jseward@acm.org |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
| 29 | The GNU General Public License is contained in the file COPYING. |
| 30 | */ |
| 31 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 32 | #include "pub_tool_basics.h" |
philippe | 6643e96 | 2012-01-17 21:16:30 +0000 | [diff] [blame] | 33 | #include "pub_tool_poolalloc.h" // For mc_include.h |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 34 | #include "pub_tool_hashtable.h" // For mc_include.h |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 35 | #include "pub_tool_libcassert.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 36 | #include "pub_tool_libcprint.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 37 | #include "pub_tool_tooliface.h" |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 38 | #include "pub_tool_machine.h" // VG_(fnptr_to_fnentry) |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 39 | #include "pub_tool_xarray.h" |
| 40 | #include "pub_tool_mallocfree.h" |
| 41 | #include "pub_tool_libcbase.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 42 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 43 | #include "mc_include.h" |
| 44 | |
| 45 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 46 | /* FIXMEs JRS 2011-June-16. |
| 47 | |
| 48 | Check the interpretation for vector narrowing and widening ops, |
| 49 | particularly the saturating ones. I suspect they are either overly |
| 50 | pessimistic and/or wrong. |
| 51 | */ |
| 52 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 53 | /* This file implements the Memcheck instrumentation, and in |
| 54 | particular contains the core of its undefined value detection |
| 55 | machinery. For a comprehensive background of the terminology, |
| 56 | algorithms and rationale used herein, read: |
| 57 | |
| 58 | Using Valgrind to detect undefined value errors with |
| 59 | bit-precision |
| 60 | |
| 61 | Julian Seward and Nicholas Nethercote |
| 62 | |
| 63 | 2005 USENIX Annual Technical Conference (General Track), |
| 64 | Anaheim, CA, USA, April 10-15, 2005. |
njn | 6665ea2 | 2007-05-24 23:14:41 +0000 | [diff] [blame] | 65 | |
| 66 | ---- |
| 67 | |
| 68 | Here is as good a place as any to record exactly when V bits are and |
| 69 | should be checked, why, and what function is responsible. |
| 70 | |
| 71 | |
| 72 | Memcheck complains when an undefined value is used: |
| 73 | |
| 74 | 1. In the condition of a conditional branch. Because it could cause |
| 75 | incorrect control flow, and thus cause incorrect externally-visible |
| 76 | behaviour. [mc_translate.c:complainIfUndefined] |
| 77 | |
| 78 | 2. As an argument to a system call, or as the value that specifies |
| 79 | the system call number. Because it could cause an incorrect |
| 80 | externally-visible side effect. [mc_translate.c:mc_pre_reg_read] |
| 81 | |
| 82 | 3. As the address in a load or store. Because it could cause an |
| 83 | incorrect value to be used later, which could cause externally-visible |
| 84 | behaviour (eg. via incorrect control flow or an incorrect system call |
| 85 | argument) [complainIfUndefined] |
| 86 | |
| 87 | 4. As the target address of a branch. Because it could cause incorrect |
| 88 | control flow. [complainIfUndefined] |
| 89 | |
| 90 | 5. As an argument to setenv, unsetenv, or putenv. Because it could put |
| 91 | an incorrect value into the external environment. |
| 92 | [mc_replace_strmem.c:VG_WRAP_FUNCTION_ZU(*, *env)] |
| 93 | |
| 94 | 6. As the index in a GETI or PUTI operation. I'm not sure why... (njn). |
| 95 | [complainIfUndefined] |
| 96 | |
| 97 | 7. As an argument to the VALGRIND_CHECK_MEM_IS_DEFINED and |
| 98 | VALGRIND_CHECK_VALUE_IS_DEFINED client requests. Because the user |
| 99 | requested it. [in memcheck.h] |
| 100 | |
| 101 | |
| 102 | Memcheck also complains, but should not, when an undefined value is used: |
| 103 | |
| 104 | 8. As the shift value in certain SIMD shift operations (but not in the |
| 105 | standard integer shift operations). This inconsistency is due to |
| 106 | historical reasons.) [complainIfUndefined] |
| 107 | |
| 108 | |
| 109 | Memcheck does not complain, but should, when an undefined value is used: |
| 110 | |
| 111 | 9. As an input to a client request. Because the client request may |
| 112 | affect the visible behaviour -- see bug #144362 for an example |
| 113 | involving the malloc replacements in vg_replace_malloc.c and |
| 114 | VALGRIND_NON_SIMD_CALL* requests, where an uninitialised argument |
| 115 | isn't identified. That bug report also has some info on how to solve |
| 116 | the problem. [valgrind.h:VALGRIND_DO_CLIENT_REQUEST] |
| 117 | |
| 118 | |
| 119 | In practice, 1 and 2 account for the vast majority of cases. |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 120 | */ |
| 121 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 122 | /* Generation of addr-definedness, addr-validity and |
| 123 | guard-definedness checks pertaining to loads and stores (Iex_Load, |
| 124 | Ist_Store, IRLoadG, IRStoreG, LLSC, CAS and Dirty memory |
| 125 | loads/stores) was re-checked 11 May 2013. */ |
| 126 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 127 | /*------------------------------------------------------------*/ |
| 128 | /*--- Forward decls ---*/ |
| 129 | /*------------------------------------------------------------*/ |
| 130 | |
| 131 | struct _MCEnv; |
| 132 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 133 | static IRType shadowTypeV ( IRType ty ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 134 | static IRExpr* expr2vbits ( struct _MCEnv* mce, IRExpr* e ); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 135 | static IRTemp findShadowTmpB ( struct _MCEnv* mce, IRTemp orig ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 136 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 137 | static IRExpr *i128_const_zero(void); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 138 | |
| 139 | /*------------------------------------------------------------*/ |
| 140 | /*--- Memcheck running state, and tmp management. ---*/ |
| 141 | /*------------------------------------------------------------*/ |
| 142 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 143 | /* Carries info about a particular tmp. The tmp's number is not |
| 144 | recorded, as this is implied by (equal to) its index in the tmpMap |
| 145 | in MCEnv. The tmp's type is also not recorded, as this is present |
| 146 | in MCEnv.sb->tyenv. |
| 147 | |
| 148 | When .kind is Orig, .shadowV and .shadowB may give the identities |
| 149 | of the temps currently holding the associated definedness (shadowV) |
| 150 | and origin (shadowB) values, or these may be IRTemp_INVALID if code |
| 151 | to compute such values has not yet been emitted. |
| 152 | |
| 153 | When .kind is VSh or BSh then the tmp is holds a V- or B- value, |
| 154 | and so .shadowV and .shadowB must be IRTemp_INVALID, since it is |
| 155 | illogical for a shadow tmp itself to be shadowed. |
| 156 | */ |
| 157 | typedef |
| 158 | enum { Orig=1, VSh=2, BSh=3 } |
| 159 | TempKind; |
| 160 | |
| 161 | typedef |
| 162 | struct { |
| 163 | TempKind kind; |
| 164 | IRTemp shadowV; |
| 165 | IRTemp shadowB; |
| 166 | } |
| 167 | TempMapEnt; |
| 168 | |
| 169 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 170 | /* Carries around state during memcheck instrumentation. */ |
| 171 | typedef |
| 172 | struct _MCEnv { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 173 | /* MODIFIED: the superblock being constructed. IRStmts are |
| 174 | added. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 175 | IRSB* sb; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 176 | Bool trace; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 177 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 178 | /* MODIFIED: a table [0 .. #temps_in_sb-1] which gives the |
| 179 | current kind and possibly shadow temps for each temp in the |
| 180 | IRSB being constructed. Note that it does not contain the |
| 181 | type of each tmp. If you want to know the type, look at the |
| 182 | relevant entry in sb->tyenv. It follows that at all times |
| 183 | during the instrumentation process, the valid indices for |
| 184 | tmpMap and sb->tyenv are identical, being 0 .. N-1 where N is |
| 185 | total number of Orig, V- and B- temps allocated so far. |
| 186 | |
| 187 | The reason for this strange split (types in one place, all |
| 188 | other info in another) is that we need the types to be |
| 189 | attached to sb so as to make it possible to do |
| 190 | "typeOfIRExpr(mce->bb->tyenv, ...)" at various places in the |
| 191 | instrumentation process. */ |
| 192 | XArray* /* of TempMapEnt */ tmpMap; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 193 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 194 | /* MODIFIED: indicates whether "bogus" literals have so far been |
| 195 | found. Starts off False, and may change to True. */ |
sewardj | 54eac25 | 2012-03-27 10:19:39 +0000 | [diff] [blame] | 196 | Bool bogusLiterals; |
| 197 | |
| 198 | /* READONLY: indicates whether we should use expensive |
| 199 | interpretations of integer adds, since unfortunately LLVM |
| 200 | uses them to do ORs in some circumstances. Defaulted to True |
| 201 | on MacOS and False everywhere else. */ |
| 202 | Bool useLLVMworkarounds; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 203 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 204 | /* READONLY: the guest layout. This indicates which parts of |
| 205 | the guest state should be regarded as 'always defined'. */ |
| 206 | VexGuestLayout* layout; |
sewardj | 634ba77 | 2006-10-15 12:47:37 +0000 | [diff] [blame] | 207 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 208 | /* READONLY: the host word type. Needed for constructing |
| 209 | arguments of type 'HWord' to be passed to helper functions. |
| 210 | Ity_I32 or Ity_I64 only. */ |
| 211 | IRType hWordTy; |
| 212 | } |
| 213 | MCEnv; |
| 214 | |
| 215 | /* SHADOW TMP MANAGEMENT. Shadow tmps are allocated lazily (on |
| 216 | demand), as they are encountered. This is for two reasons. |
| 217 | |
| 218 | (1) (less important reason): Many original tmps are unused due to |
| 219 | initial IR optimisation, and we do not want to spaces in tables |
| 220 | tracking them. |
| 221 | |
| 222 | Shadow IRTemps are therefore allocated on demand. mce.tmpMap is a |
| 223 | table indexed [0 .. n_types-1], which gives the current shadow for |
| 224 | each original tmp, or INVALID_IRTEMP if none is so far assigned. |
| 225 | It is necessary to support making multiple assignments to a shadow |
| 226 | -- specifically, after testing a shadow for definedness, it needs |
| 227 | to be made defined. But IR's SSA property disallows this. |
| 228 | |
| 229 | (2) (more important reason): Therefore, when a shadow needs to get |
| 230 | a new value, a new temporary is created, the value is assigned to |
| 231 | that, and the tmpMap is updated to reflect the new binding. |
| 232 | |
| 233 | A corollary is that if the tmpMap maps a given tmp to |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 234 | IRTemp_INVALID and we are hoping to read that shadow tmp, it means |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 235 | there's a read-before-write error in the original tmps. The IR |
| 236 | sanity checker should catch all such anomalies, however. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 237 | */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 238 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 239 | /* Create a new IRTemp of type 'ty' and kind 'kind', and add it to |
| 240 | both the table in mce->sb and to our auxiliary mapping. Note that |
| 241 | newTemp may cause mce->tmpMap to resize, hence previous results |
| 242 | from VG_(indexXA)(mce->tmpMap) are invalidated. */ |
| 243 | static IRTemp newTemp ( MCEnv* mce, IRType ty, TempKind kind ) |
| 244 | { |
| 245 | Word newIx; |
| 246 | TempMapEnt ent; |
| 247 | IRTemp tmp = newIRTemp(mce->sb->tyenv, ty); |
| 248 | ent.kind = kind; |
| 249 | ent.shadowV = IRTemp_INVALID; |
| 250 | ent.shadowB = IRTemp_INVALID; |
| 251 | newIx = VG_(addToXA)( mce->tmpMap, &ent ); |
| 252 | tl_assert(newIx == (Word)tmp); |
| 253 | return tmp; |
| 254 | } |
| 255 | |
| 256 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 257 | /* Find the tmp currently shadowing the given original tmp. If none |
| 258 | so far exists, allocate one. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 259 | static IRTemp findShadowTmpV ( MCEnv* mce, IRTemp orig ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 260 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 261 | TempMapEnt* ent; |
| 262 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 263 | here. */ |
| 264 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 265 | tl_assert(ent->kind == Orig); |
| 266 | if (ent->shadowV == IRTemp_INVALID) { |
| 267 | IRTemp tmpV |
| 268 | = newTemp( mce, shadowTypeV(mce->sb->tyenv->types[orig]), VSh ); |
| 269 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 270 | from VG_(indexXA) are invalid. */ |
| 271 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 272 | tl_assert(ent->kind == Orig); |
| 273 | tl_assert(ent->shadowV == IRTemp_INVALID); |
| 274 | ent->shadowV = tmpV; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 275 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 276 | return ent->shadowV; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 277 | } |
| 278 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 279 | /* Allocate a new shadow for the given original tmp. This means any |
| 280 | previous shadow is abandoned. This is needed because it is |
| 281 | necessary to give a new value to a shadow once it has been tested |
| 282 | for undefinedness, but unfortunately IR's SSA property disallows |
| 283 | this. Instead we must abandon the old shadow, allocate a new one |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 284 | and use that instead. |
| 285 | |
| 286 | This is the same as findShadowTmpV, except we don't bother to see |
| 287 | if a shadow temp already existed -- we simply allocate a new one |
| 288 | regardless. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 289 | static void newShadowTmpV ( MCEnv* mce, IRTemp orig ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 290 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 291 | TempMapEnt* ent; |
| 292 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 293 | here. */ |
| 294 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 295 | tl_assert(ent->kind == Orig); |
| 296 | if (1) { |
| 297 | IRTemp tmpV |
| 298 | = newTemp( mce, shadowTypeV(mce->sb->tyenv->types[orig]), VSh ); |
| 299 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 300 | from VG_(indexXA) are invalid. */ |
| 301 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 302 | tl_assert(ent->kind == Orig); |
| 303 | ent->shadowV = tmpV; |
| 304 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
| 308 | /*------------------------------------------------------------*/ |
| 309 | /*--- IRAtoms -- a subset of IRExprs ---*/ |
| 310 | /*------------------------------------------------------------*/ |
| 311 | |
| 312 | /* An atom is either an IRExpr_Const or an IRExpr_Tmp, as defined by |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 313 | isIRAtom() in libvex_ir.h. Because this instrumenter expects flat |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 314 | input, most of this code deals in atoms. Usefully, a value atom |
| 315 | always has a V-value which is also an atom: constants are shadowed |
| 316 | by constants, and temps are shadowed by the corresponding shadow |
| 317 | temporary. */ |
| 318 | |
| 319 | typedef IRExpr IRAtom; |
| 320 | |
| 321 | /* (used for sanity checks only): is this an atom which looks |
| 322 | like it's from original code? */ |
| 323 | static Bool isOriginalAtom ( MCEnv* mce, IRAtom* a1 ) |
| 324 | { |
| 325 | if (a1->tag == Iex_Const) |
| 326 | return True; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 327 | if (a1->tag == Iex_RdTmp) { |
| 328 | TempMapEnt* ent = VG_(indexXA)( mce->tmpMap, a1->Iex.RdTmp.tmp ); |
| 329 | return ent->kind == Orig; |
| 330 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 331 | return False; |
| 332 | } |
| 333 | |
| 334 | /* (used for sanity checks only): is this an atom which looks |
| 335 | like it's from shadow code? */ |
| 336 | static Bool isShadowAtom ( MCEnv* mce, IRAtom* a1 ) |
| 337 | { |
| 338 | if (a1->tag == Iex_Const) |
| 339 | return True; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 340 | if (a1->tag == Iex_RdTmp) { |
| 341 | TempMapEnt* ent = VG_(indexXA)( mce->tmpMap, a1->Iex.RdTmp.tmp ); |
| 342 | return ent->kind == VSh || ent->kind == BSh; |
| 343 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 344 | return False; |
| 345 | } |
| 346 | |
| 347 | /* (used for sanity checks only): check that both args are atoms and |
| 348 | are identically-kinded. */ |
| 349 | static Bool sameKindedAtoms ( IRAtom* a1, IRAtom* a2 ) |
| 350 | { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 351 | if (a1->tag == Iex_RdTmp && a2->tag == Iex_RdTmp) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 352 | return True; |
sewardj | bef552a | 2005-08-30 12:54:36 +0000 | [diff] [blame] | 353 | if (a1->tag == Iex_Const && a2->tag == Iex_Const) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 354 | return True; |
| 355 | return False; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /*------------------------------------------------------------*/ |
| 360 | /*--- Type management ---*/ |
| 361 | /*------------------------------------------------------------*/ |
| 362 | |
| 363 | /* Shadow state is always accessed using integer types. This returns |
| 364 | an integer type with the same size (as per sizeofIRType) as the |
| 365 | given type. The only valid shadow types are Bit, I8, I16, I32, |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 366 | I64, I128, V128, V256. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 367 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 368 | static IRType shadowTypeV ( IRType ty ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 369 | { |
| 370 | switch (ty) { |
| 371 | case Ity_I1: |
| 372 | case Ity_I8: |
| 373 | case Ity_I16: |
| 374 | case Ity_I32: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 375 | case Ity_I64: |
| 376 | case Ity_I128: return ty; |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 377 | case Ity_F32: return Ity_I32; |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 378 | case Ity_D32: return Ity_I32; |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 379 | case Ity_F64: return Ity_I64; |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 380 | case Ity_D64: return Ity_I64; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 381 | case Ity_F128: return Ity_I128; |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 382 | case Ity_D128: return Ity_I128; |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 383 | case Ity_V128: return Ity_V128; |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 384 | case Ity_V256: return Ity_V256; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 385 | default: ppIRType(ty); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 386 | VG_(tool_panic)("memcheck:shadowTypeV"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
| 390 | /* Produce a 'defined' value of the given shadow type. Should only be |
| 391 | supplied shadow types (Bit/I8/I16/I32/UI64). */ |
| 392 | static IRExpr* definedOfType ( IRType ty ) { |
| 393 | switch (ty) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 394 | case Ity_I1: return IRExpr_Const(IRConst_U1(False)); |
| 395 | case Ity_I8: return IRExpr_Const(IRConst_U8(0)); |
| 396 | case Ity_I16: return IRExpr_Const(IRConst_U16(0)); |
| 397 | case Ity_I32: return IRExpr_Const(IRConst_U32(0)); |
| 398 | case Ity_I64: return IRExpr_Const(IRConst_U64(0)); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 399 | case Ity_I128: return i128_const_zero(); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 400 | case Ity_V128: return IRExpr_Const(IRConst_V128(0x0000)); |
sewardj | 1eb272f | 2014-01-26 18:36:52 +0000 | [diff] [blame] | 401 | case Ity_V256: return IRExpr_Const(IRConst_V256(0x00000000)); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 402 | default: VG_(tool_panic)("memcheck:definedOfType"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
| 406 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 407 | /*------------------------------------------------------------*/ |
| 408 | /*--- Constructing IR fragments ---*/ |
| 409 | /*------------------------------------------------------------*/ |
| 410 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 411 | /* add stmt to a bb */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 412 | static inline void stmt ( HChar cat, MCEnv* mce, IRStmt* st ) { |
| 413 | if (mce->trace) { |
| 414 | VG_(printf)(" %c: ", cat); |
| 415 | ppIRStmt(st); |
| 416 | VG_(printf)("\n"); |
| 417 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 418 | addStmtToIRSB(mce->sb, st); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /* assign value to tmp */ |
| 422 | static inline |
| 423 | void assign ( HChar cat, MCEnv* mce, IRTemp tmp, IRExpr* expr ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 424 | stmt(cat, mce, IRStmt_WrTmp(tmp,expr)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 425 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 426 | |
| 427 | /* build various kinds of expressions */ |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 428 | #define triop(_op, _arg1, _arg2, _arg3) \ |
| 429 | IRExpr_Triop((_op),(_arg1),(_arg2),(_arg3)) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 430 | #define binop(_op, _arg1, _arg2) IRExpr_Binop((_op),(_arg1),(_arg2)) |
| 431 | #define unop(_op, _arg) IRExpr_Unop((_op),(_arg)) |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 432 | #define mkU1(_n) IRExpr_Const(IRConst_U1(_n)) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 433 | #define mkU8(_n) IRExpr_Const(IRConst_U8(_n)) |
| 434 | #define mkU16(_n) IRExpr_Const(IRConst_U16(_n)) |
| 435 | #define mkU32(_n) IRExpr_Const(IRConst_U32(_n)) |
| 436 | #define mkU64(_n) IRExpr_Const(IRConst_U64(_n)) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 437 | #define mkV128(_n) IRExpr_Const(IRConst_V128(_n)) |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 438 | #define mkexpr(_tmp) IRExpr_RdTmp((_tmp)) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 439 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 440 | /* Bind the given expression to a new temporary, and return the |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 441 | temporary. This effectively converts an arbitrary expression into |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 442 | an atom. |
| 443 | |
| 444 | 'ty' is the type of 'e' and hence the type that the new temporary |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 445 | needs to be. But passing it in is redundant, since we can deduce |
| 446 | the type merely by inspecting 'e'. So at least use that fact to |
| 447 | assert that the two types agree. */ |
| 448 | static IRAtom* assignNew ( HChar cat, MCEnv* mce, IRType ty, IRExpr* e ) |
| 449 | { |
| 450 | TempKind k; |
| 451 | IRTemp t; |
| 452 | IRType tyE = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 453 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 454 | tl_assert(tyE == ty); /* so 'ty' is redundant (!) */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 455 | switch (cat) { |
| 456 | case 'V': k = VSh; break; |
| 457 | case 'B': k = BSh; break; |
| 458 | case 'C': k = Orig; break; |
| 459 | /* happens when we are making up new "orig" |
| 460 | expressions, for IRCAS handling */ |
| 461 | default: tl_assert(0); |
| 462 | } |
| 463 | t = newTemp(mce, ty, k); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 464 | assign(cat, mce, t, e); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 465 | return mkexpr(t); |
| 466 | } |
| 467 | |
| 468 | |
| 469 | /*------------------------------------------------------------*/ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 470 | /*--- Helper functions for 128-bit ops ---*/ |
| 471 | /*------------------------------------------------------------*/ |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 472 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 473 | static IRExpr *i128_const_zero(void) |
| 474 | { |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 475 | IRAtom* z64 = IRExpr_Const(IRConst_U64(0)); |
| 476 | return binop(Iop_64HLto128, z64, z64); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 477 | } |
| 478 | |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 479 | /* There are no I128-bit loads and/or stores [as generated by any |
| 480 | current front ends]. So we do not need to worry about that in |
| 481 | expr2vbits_Load */ |
| 482 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 483 | |
| 484 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 485 | /*--- Constructing definedness primitive ops ---*/ |
| 486 | /*------------------------------------------------------------*/ |
| 487 | |
| 488 | /* --------- Defined-if-either-defined --------- */ |
| 489 | |
| 490 | static IRAtom* mkDifD8 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 491 | tl_assert(isShadowAtom(mce,a1)); |
| 492 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 493 | return assignNew('V', mce, Ity_I8, binop(Iop_And8, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static IRAtom* mkDifD16 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 497 | tl_assert(isShadowAtom(mce,a1)); |
| 498 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 499 | return assignNew('V', mce, Ity_I16, binop(Iop_And16, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | static IRAtom* mkDifD32 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 503 | tl_assert(isShadowAtom(mce,a1)); |
| 504 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 505 | return assignNew('V', mce, Ity_I32, binop(Iop_And32, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 506 | } |
| 507 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 508 | static IRAtom* mkDifD64 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 509 | tl_assert(isShadowAtom(mce,a1)); |
| 510 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 511 | return assignNew('V', mce, Ity_I64, binop(Iop_And64, a1, a2)); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 512 | } |
| 513 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 514 | static IRAtom* mkDifDV128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 515 | tl_assert(isShadowAtom(mce,a1)); |
| 516 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 517 | return assignNew('V', mce, Ity_V128, binop(Iop_AndV128, a1, a2)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 518 | } |
| 519 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 520 | static IRAtom* mkDifDV256 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 521 | tl_assert(isShadowAtom(mce,a1)); |
| 522 | tl_assert(isShadowAtom(mce,a2)); |
| 523 | return assignNew('V', mce, Ity_V256, binop(Iop_AndV256, a1, a2)); |
| 524 | } |
| 525 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 526 | /* --------- Undefined-if-either-undefined --------- */ |
| 527 | |
| 528 | static IRAtom* mkUifU8 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 529 | tl_assert(isShadowAtom(mce,a1)); |
| 530 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 531 | return assignNew('V', mce, Ity_I8, binop(Iop_Or8, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static IRAtom* mkUifU16 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 535 | tl_assert(isShadowAtom(mce,a1)); |
| 536 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 537 | return assignNew('V', mce, Ity_I16, binop(Iop_Or16, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | static IRAtom* mkUifU32 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 541 | tl_assert(isShadowAtom(mce,a1)); |
| 542 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 543 | return assignNew('V', mce, Ity_I32, binop(Iop_Or32, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static IRAtom* mkUifU64 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 547 | tl_assert(isShadowAtom(mce,a1)); |
| 548 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 549 | return assignNew('V', mce, Ity_I64, binop(Iop_Or64, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 550 | } |
| 551 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 552 | static IRAtom* mkUifU128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 553 | IRAtom *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6; |
| 554 | tl_assert(isShadowAtom(mce,a1)); |
| 555 | tl_assert(isShadowAtom(mce,a2)); |
| 556 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, a1)); |
| 557 | tmp2 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, a1)); |
| 558 | tmp3 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, a2)); |
| 559 | tmp4 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, a2)); |
| 560 | tmp5 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp1, tmp3)); |
| 561 | tmp6 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp2, tmp4)); |
| 562 | |
| 563 | return assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, tmp6, tmp5)); |
| 564 | } |
| 565 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 566 | static IRAtom* mkUifUV128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 567 | tl_assert(isShadowAtom(mce,a1)); |
| 568 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 569 | return assignNew('V', mce, Ity_V128, binop(Iop_OrV128, a1, a2)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 570 | } |
| 571 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 572 | static IRAtom* mkUifUV256 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 573 | tl_assert(isShadowAtom(mce,a1)); |
| 574 | tl_assert(isShadowAtom(mce,a2)); |
| 575 | return assignNew('V', mce, Ity_V256, binop(Iop_OrV256, a1, a2)); |
| 576 | } |
| 577 | |
sewardj | e50a1b1 | 2004-12-17 01:24:54 +0000 | [diff] [blame] | 578 | static IRAtom* mkUifU ( MCEnv* mce, IRType vty, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 579 | switch (vty) { |
sewardj | e50a1b1 | 2004-12-17 01:24:54 +0000 | [diff] [blame] | 580 | case Ity_I8: return mkUifU8(mce, a1, a2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 581 | case Ity_I16: return mkUifU16(mce, a1, a2); |
| 582 | case Ity_I32: return mkUifU32(mce, a1, a2); |
| 583 | case Ity_I64: return mkUifU64(mce, a1, a2); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 584 | case Ity_I128: return mkUifU128(mce, a1, a2); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 585 | case Ity_V128: return mkUifUV128(mce, a1, a2); |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 586 | case Ity_V256: return mkUifUV256(mce, a1, a2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 587 | default: |
| 588 | VG_(printf)("\n"); ppIRType(vty); VG_(printf)("\n"); |
| 589 | VG_(tool_panic)("memcheck:mkUifU"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 593 | /* --------- The Left-family of operations. --------- */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 594 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 595 | static IRAtom* mkLeft8 ( MCEnv* mce, IRAtom* a1 ) { |
| 596 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 597 | return assignNew('V', mce, Ity_I8, unop(Iop_Left8, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static IRAtom* mkLeft16 ( MCEnv* mce, IRAtom* a1 ) { |
| 601 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 602 | return assignNew('V', mce, Ity_I16, unop(Iop_Left16, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static IRAtom* mkLeft32 ( MCEnv* mce, IRAtom* a1 ) { |
| 606 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 607 | return assignNew('V', mce, Ity_I32, unop(Iop_Left32, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 608 | } |
| 609 | |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 610 | static IRAtom* mkLeft64 ( MCEnv* mce, IRAtom* a1 ) { |
| 611 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 612 | return assignNew('V', mce, Ity_I64, unop(Iop_Left64, a1)); |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 613 | } |
| 614 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 615 | /* --------- 'Improvement' functions for AND/OR. --------- */ |
| 616 | |
| 617 | /* ImproveAND(data, vbits) = data OR vbits. Defined (0) data 0s give |
| 618 | defined (0); all other -> undefined (1). |
| 619 | */ |
| 620 | static IRAtom* mkImproveAND8 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 621 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 622 | tl_assert(isOriginalAtom(mce, data)); |
| 623 | tl_assert(isShadowAtom(mce, vbits)); |
| 624 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 625 | return assignNew('V', mce, Ity_I8, binop(Iop_Or8, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 626 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 627 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 628 | static IRAtom* mkImproveAND16 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 629 | { |
| 630 | tl_assert(isOriginalAtom(mce, data)); |
| 631 | tl_assert(isShadowAtom(mce, vbits)); |
| 632 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 633 | return assignNew('V', mce, Ity_I16, binop(Iop_Or16, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 634 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 635 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 636 | static IRAtom* mkImproveAND32 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 637 | { |
| 638 | tl_assert(isOriginalAtom(mce, data)); |
| 639 | tl_assert(isShadowAtom(mce, vbits)); |
| 640 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 641 | return assignNew('V', mce, Ity_I32, binop(Iop_Or32, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 642 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 643 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 644 | static IRAtom* mkImproveAND64 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 645 | { |
| 646 | tl_assert(isOriginalAtom(mce, data)); |
| 647 | tl_assert(isShadowAtom(mce, vbits)); |
| 648 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 649 | return assignNew('V', mce, Ity_I64, binop(Iop_Or64, data, vbits)); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 650 | } |
| 651 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 652 | static IRAtom* mkImproveANDV128 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 653 | { |
| 654 | tl_assert(isOriginalAtom(mce, data)); |
| 655 | tl_assert(isShadowAtom(mce, vbits)); |
| 656 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 657 | return assignNew('V', mce, Ity_V128, binop(Iop_OrV128, data, vbits)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 658 | } |
| 659 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 660 | static IRAtom* mkImproveANDV256 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 661 | { |
| 662 | tl_assert(isOriginalAtom(mce, data)); |
| 663 | tl_assert(isShadowAtom(mce, vbits)); |
| 664 | tl_assert(sameKindedAtoms(data, vbits)); |
| 665 | return assignNew('V', mce, Ity_V256, binop(Iop_OrV256, data, vbits)); |
| 666 | } |
| 667 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 668 | /* ImproveOR(data, vbits) = ~data OR vbits. Defined (0) data 1s give |
| 669 | defined (0); all other -> undefined (1). |
| 670 | */ |
| 671 | static IRAtom* mkImproveOR8 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 672 | { |
| 673 | tl_assert(isOriginalAtom(mce, data)); |
| 674 | tl_assert(isShadowAtom(mce, vbits)); |
| 675 | tl_assert(sameKindedAtoms(data, vbits)); |
| 676 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 677 | 'V', mce, Ity_I8, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 678 | binop(Iop_Or8, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 679 | assignNew('V', mce, Ity_I8, unop(Iop_Not8, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 680 | vbits) ); |
| 681 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 682 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 683 | static IRAtom* mkImproveOR16 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 684 | { |
| 685 | tl_assert(isOriginalAtom(mce, data)); |
| 686 | tl_assert(isShadowAtom(mce, vbits)); |
| 687 | tl_assert(sameKindedAtoms(data, vbits)); |
| 688 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 689 | 'V', mce, Ity_I16, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 690 | binop(Iop_Or16, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 691 | assignNew('V', mce, Ity_I16, unop(Iop_Not16, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 692 | vbits) ); |
| 693 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 694 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 695 | static IRAtom* mkImproveOR32 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 696 | { |
| 697 | tl_assert(isOriginalAtom(mce, data)); |
| 698 | tl_assert(isShadowAtom(mce, vbits)); |
| 699 | tl_assert(sameKindedAtoms(data, vbits)); |
| 700 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 701 | 'V', mce, Ity_I32, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 702 | binop(Iop_Or32, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 703 | assignNew('V', mce, Ity_I32, unop(Iop_Not32, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 704 | vbits) ); |
| 705 | } |
| 706 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 707 | static IRAtom* mkImproveOR64 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 708 | { |
| 709 | tl_assert(isOriginalAtom(mce, data)); |
| 710 | tl_assert(isShadowAtom(mce, vbits)); |
| 711 | tl_assert(sameKindedAtoms(data, vbits)); |
| 712 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 713 | 'V', mce, Ity_I64, |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 714 | binop(Iop_Or64, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 715 | assignNew('V', mce, Ity_I64, unop(Iop_Not64, data)), |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 716 | vbits) ); |
| 717 | } |
| 718 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 719 | static IRAtom* mkImproveORV128 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 720 | { |
| 721 | tl_assert(isOriginalAtom(mce, data)); |
| 722 | tl_assert(isShadowAtom(mce, vbits)); |
| 723 | tl_assert(sameKindedAtoms(data, vbits)); |
| 724 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 725 | 'V', mce, Ity_V128, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 726 | binop(Iop_OrV128, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 727 | assignNew('V', mce, Ity_V128, unop(Iop_NotV128, data)), |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 728 | vbits) ); |
| 729 | } |
| 730 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 731 | static IRAtom* mkImproveORV256 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 732 | { |
| 733 | tl_assert(isOriginalAtom(mce, data)); |
| 734 | tl_assert(isShadowAtom(mce, vbits)); |
| 735 | tl_assert(sameKindedAtoms(data, vbits)); |
| 736 | return assignNew( |
| 737 | 'V', mce, Ity_V256, |
| 738 | binop(Iop_OrV256, |
| 739 | assignNew('V', mce, Ity_V256, unop(Iop_NotV256, data)), |
| 740 | vbits) ); |
| 741 | } |
| 742 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 743 | /* --------- Pessimising casts. --------- */ |
| 744 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 745 | /* The function returns an expression of type DST_TY. If any of the VBITS |
| 746 | is undefined (value == 1) the resulting expression has all bits set to |
| 747 | 1. Otherwise, all bits are 0. */ |
| 748 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 749 | static IRAtom* mkPCastTo( MCEnv* mce, IRType dst_ty, IRAtom* vbits ) |
| 750 | { |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 751 | IRType src_ty; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 752 | IRAtom* tmp1; |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 753 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 754 | /* Note, dst_ty is a shadow type, not an original type. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 755 | tl_assert(isShadowAtom(mce,vbits)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 756 | src_ty = typeOfIRExpr(mce->sb->tyenv, vbits); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 757 | |
| 758 | /* Fast-track some common cases */ |
| 759 | if (src_ty == Ity_I32 && dst_ty == Ity_I32) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 760 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 761 | |
| 762 | if (src_ty == Ity_I64 && dst_ty == Ity_I64) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 763 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpwNEZ64, vbits)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 764 | |
| 765 | if (src_ty == Ity_I32 && dst_ty == Ity_I64) { |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 766 | /* PCast the arg, then clone it. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 767 | IRAtom* tmp = assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
| 768 | return assignNew('V', mce, Ity_I64, binop(Iop_32HLto64, tmp, tmp)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 769 | } |
| 770 | |
sewardj | 1eb272f | 2014-01-26 18:36:52 +0000 | [diff] [blame] | 771 | if (src_ty == Ity_I32 && dst_ty == Ity_V128) { |
| 772 | /* PCast the arg, then clone it 4 times. */ |
| 773 | IRAtom* tmp = assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
| 774 | tmp = assignNew('V', mce, Ity_I64, binop(Iop_32HLto64, tmp, tmp)); |
| 775 | return assignNew('V', mce, Ity_V128, binop(Iop_64HLtoV128, tmp, tmp)); |
| 776 | } |
| 777 | |
| 778 | if (src_ty == Ity_I32 && dst_ty == Ity_V256) { |
| 779 | /* PCast the arg, then clone it 8 times. */ |
| 780 | IRAtom* tmp = assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
| 781 | tmp = assignNew('V', mce, Ity_I64, binop(Iop_32HLto64, tmp, tmp)); |
| 782 | tmp = assignNew('V', mce, Ity_V128, binop(Iop_64HLtoV128, tmp, tmp)); |
| 783 | return assignNew('V', mce, Ity_V256, binop(Iop_V128HLtoV256, tmp, tmp)); |
| 784 | } |
| 785 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 786 | if (src_ty == Ity_I64 && dst_ty == Ity_I32) { |
| 787 | /* PCast the arg. This gives all 0s or all 1s. Then throw away |
| 788 | the top half. */ |
| 789 | IRAtom* tmp = assignNew('V', mce, Ity_I64, unop(Iop_CmpwNEZ64, vbits)); |
| 790 | return assignNew('V', mce, Ity_I32, unop(Iop_64to32, tmp)); |
| 791 | } |
| 792 | |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 793 | /* Else do it the slow way .. */ |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 794 | /* First of all, collapse vbits down to a single bit. */ |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 795 | tmp1 = NULL; |
| 796 | switch (src_ty) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 797 | case Ity_I1: |
| 798 | tmp1 = vbits; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 799 | break; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 800 | case Ity_I8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 801 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ8, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 802 | break; |
| 803 | case Ity_I16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 804 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ16, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 805 | break; |
| 806 | case Ity_I32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 807 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ32, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 808 | break; |
| 809 | case Ity_I64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 810 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ64, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 811 | break; |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 812 | case Ity_I128: { |
| 813 | /* Gah. Chop it in half, OR the halves together, and compare |
| 814 | that with zero. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 815 | IRAtom* tmp2 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, vbits)); |
| 816 | IRAtom* tmp3 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, vbits)); |
| 817 | IRAtom* tmp4 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp2, tmp3)); |
| 818 | tmp1 = assignNew('V', mce, Ity_I1, |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 819 | unop(Iop_CmpNEZ64, tmp4)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 820 | break; |
| 821 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 822 | default: |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 823 | ppIRType(src_ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 824 | VG_(tool_panic)("mkPCastTo(1)"); |
| 825 | } |
| 826 | tl_assert(tmp1); |
| 827 | /* Now widen up to the dst type. */ |
| 828 | switch (dst_ty) { |
| 829 | case Ity_I1: |
| 830 | return tmp1; |
| 831 | case Ity_I8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 832 | return assignNew('V', mce, Ity_I8, unop(Iop_1Sto8, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 833 | case Ity_I16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 834 | return assignNew('V', mce, Ity_I16, unop(Iop_1Sto16, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 835 | case Ity_I32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 836 | return assignNew('V', mce, Ity_I32, unop(Iop_1Sto32, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 837 | case Ity_I64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 838 | return assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 839 | case Ity_V128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 840 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
| 841 | tmp1 = assignNew('V', mce, Ity_V128, binop(Iop_64HLtoV128, tmp1, tmp1)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 842 | return tmp1; |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 843 | case Ity_I128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 844 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
| 845 | tmp1 = assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, tmp1, tmp1)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 846 | return tmp1; |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 847 | case Ity_V256: |
| 848 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
| 849 | tmp1 = assignNew('V', mce, Ity_V128, binop(Iop_64HLtoV128, |
| 850 | tmp1, tmp1)); |
| 851 | tmp1 = assignNew('V', mce, Ity_V256, binop(Iop_V128HLtoV256, |
| 852 | tmp1, tmp1)); |
| 853 | return tmp1; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 854 | default: |
| 855 | ppIRType(dst_ty); |
| 856 | VG_(tool_panic)("mkPCastTo(2)"); |
| 857 | } |
| 858 | } |
| 859 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 860 | /* --------- Accurate interpretation of CmpEQ/CmpNE. --------- */ |
| 861 | /* |
| 862 | Normally, we can do CmpEQ/CmpNE by doing UifU on the arguments, and |
| 863 | PCasting to Ity_U1. However, sometimes it is necessary to be more |
| 864 | accurate. The insight is that the result is defined if two |
| 865 | corresponding bits can be found, one from each argument, so that |
| 866 | both bits are defined but are different -- that makes EQ say "No" |
| 867 | and NE say "Yes". Hence, we compute an improvement term and DifD |
| 868 | it onto the "normal" (UifU) result. |
| 869 | |
| 870 | The result is: |
| 871 | |
| 872 | PCastTo<1> ( |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 873 | -- naive version |
| 874 | PCastTo<sz>( UifU<sz>(vxx, vyy) ) |
| 875 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 876 | `DifD<sz>` |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 877 | |
| 878 | -- improvement term |
| 879 | PCastTo<sz>( PCast<sz>( CmpEQ<sz> ( vec, 1...1 ) ) ) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 880 | ) |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 881 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 882 | where |
| 883 | vec contains 0 (defined) bits where the corresponding arg bits |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 884 | are defined but different, and 1 bits otherwise. |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 885 | |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 886 | vec = Or<sz>( vxx, // 0 iff bit defined |
| 887 | vyy, // 0 iff bit defined |
| 888 | Not<sz>(Xor<sz>( xx, yy )) // 0 iff bits different |
| 889 | ) |
| 890 | |
| 891 | If any bit of vec is 0, the result is defined and so the |
| 892 | improvement term should produce 0...0, else it should produce |
| 893 | 1...1. |
| 894 | |
| 895 | Hence require for the improvement term: |
| 896 | |
| 897 | if vec == 1...1 then 1...1 else 0...0 |
| 898 | -> |
| 899 | PCast<sz>( CmpEQ<sz> ( vec, 1...1 ) ) |
| 900 | |
| 901 | This was extensively re-analysed and checked on 6 July 05. |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 902 | */ |
| 903 | static IRAtom* expensiveCmpEQorNE ( MCEnv* mce, |
| 904 | IRType ty, |
| 905 | IRAtom* vxx, IRAtom* vyy, |
| 906 | IRAtom* xx, IRAtom* yy ) |
| 907 | { |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 908 | IRAtom *naive, *vec, *improvement_term; |
| 909 | IRAtom *improved, *final_cast, *top; |
| 910 | IROp opDIFD, opUIFU, opXOR, opNOT, opCMP, opOR; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 911 | |
| 912 | tl_assert(isShadowAtom(mce,vxx)); |
| 913 | tl_assert(isShadowAtom(mce,vyy)); |
| 914 | tl_assert(isOriginalAtom(mce,xx)); |
| 915 | tl_assert(isOriginalAtom(mce,yy)); |
| 916 | tl_assert(sameKindedAtoms(vxx,xx)); |
| 917 | tl_assert(sameKindedAtoms(vyy,yy)); |
| 918 | |
| 919 | switch (ty) { |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 920 | case Ity_I16: |
| 921 | opOR = Iop_Or16; |
| 922 | opDIFD = Iop_And16; |
| 923 | opUIFU = Iop_Or16; |
| 924 | opNOT = Iop_Not16; |
| 925 | opXOR = Iop_Xor16; |
| 926 | opCMP = Iop_CmpEQ16; |
| 927 | top = mkU16(0xFFFF); |
| 928 | break; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 929 | case Ity_I32: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 930 | opOR = Iop_Or32; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 931 | opDIFD = Iop_And32; |
| 932 | opUIFU = Iop_Or32; |
| 933 | opNOT = Iop_Not32; |
| 934 | opXOR = Iop_Xor32; |
| 935 | opCMP = Iop_CmpEQ32; |
| 936 | top = mkU32(0xFFFFFFFF); |
| 937 | break; |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 938 | case Ity_I64: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 939 | opOR = Iop_Or64; |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 940 | opDIFD = Iop_And64; |
| 941 | opUIFU = Iop_Or64; |
| 942 | opNOT = Iop_Not64; |
| 943 | opXOR = Iop_Xor64; |
| 944 | opCMP = Iop_CmpEQ64; |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 945 | top = mkU64(0xFFFFFFFFFFFFFFFFULL); |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 946 | break; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 947 | default: |
| 948 | VG_(tool_panic)("expensiveCmpEQorNE"); |
| 949 | } |
| 950 | |
| 951 | naive |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 952 | = mkPCastTo(mce,ty, |
| 953 | assignNew('V', mce, ty, binop(opUIFU, vxx, vyy))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 954 | |
| 955 | vec |
| 956 | = assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 957 | 'V', mce,ty, |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 958 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 959 | assignNew('V', mce,ty, binop(opOR, vxx, vyy)), |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 960 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 961 | 'V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 962 | unop( opNOT, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 963 | assignNew('V', mce,ty, binop(opXOR, xx, yy)))))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 964 | |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 965 | improvement_term |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 966 | = mkPCastTo( mce,ty, |
| 967 | assignNew('V', mce,Ity_I1, binop(opCMP, vec, top))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 968 | |
| 969 | improved |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 970 | = assignNew( 'V', mce,ty, binop(opDIFD, naive, improvement_term) ); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 971 | |
| 972 | final_cast |
| 973 | = mkPCastTo( mce, Ity_I1, improved ); |
| 974 | |
| 975 | return final_cast; |
| 976 | } |
| 977 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 978 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 979 | /* --------- Semi-accurate interpretation of CmpORD. --------- */ |
| 980 | |
| 981 | /* CmpORD32{S,U} does PowerPC-style 3-way comparisons: |
| 982 | |
| 983 | CmpORD32S(x,y) = 1<<3 if x <s y |
| 984 | = 1<<2 if x >s y |
| 985 | = 1<<1 if x == y |
| 986 | |
| 987 | and similarly the unsigned variant. The default interpretation is: |
| 988 | |
| 989 | CmpORD32{S,U}#(x,y,x#,y#) = PCast(x# `UifU` y#) |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 990 | & (7<<1) |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 991 | |
| 992 | The "& (7<<1)" reflects the fact that all result bits except 3,2,1 |
| 993 | are zero and therefore defined (viz, zero). |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 994 | |
| 995 | Also deal with a special case better: |
| 996 | |
| 997 | CmpORD32S(x,0) |
| 998 | |
| 999 | Here, bit 3 (LT) of the result is a copy of the top bit of x and |
| 1000 | will be defined even if the rest of x isn't. In which case we do: |
| 1001 | |
| 1002 | CmpORD32S#(x,x#,0,{impliedly 0}#) |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1003 | = PCast(x#) & (3<<1) -- standard interp for GT#,EQ# |
| 1004 | | (x# >>u 31) << 3 -- LT# = x#[31] |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1005 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1006 | Analogous handling for CmpORD64{S,U}. |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 1007 | */ |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1008 | static Bool isZeroU32 ( IRAtom* e ) |
| 1009 | { |
| 1010 | return |
| 1011 | toBool( e->tag == Iex_Const |
| 1012 | && e->Iex.Const.con->tag == Ico_U32 |
| 1013 | && e->Iex.Const.con->Ico.U32 == 0 ); |
| 1014 | } |
| 1015 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1016 | static Bool isZeroU64 ( IRAtom* e ) |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 1017 | { |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1018 | return |
| 1019 | toBool( e->tag == Iex_Const |
| 1020 | && e->Iex.Const.con->tag == Ico_U64 |
| 1021 | && e->Iex.Const.con->Ico.U64 == 0 ); |
| 1022 | } |
| 1023 | |
| 1024 | static IRAtom* doCmpORD ( MCEnv* mce, |
| 1025 | IROp cmp_op, |
| 1026 | IRAtom* xxhash, IRAtom* yyhash, |
| 1027 | IRAtom* xx, IRAtom* yy ) |
| 1028 | { |
| 1029 | Bool m64 = cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD64U; |
| 1030 | Bool syned = cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD32S; |
| 1031 | IROp opOR = m64 ? Iop_Or64 : Iop_Or32; |
| 1032 | IROp opAND = m64 ? Iop_And64 : Iop_And32; |
| 1033 | IROp opSHL = m64 ? Iop_Shl64 : Iop_Shl32; |
| 1034 | IROp opSHR = m64 ? Iop_Shr64 : Iop_Shr32; |
| 1035 | IRType ty = m64 ? Ity_I64 : Ity_I32; |
| 1036 | Int width = m64 ? 64 : 32; |
| 1037 | |
| 1038 | Bool (*isZero)(IRAtom*) = m64 ? isZeroU64 : isZeroU32; |
| 1039 | |
| 1040 | IRAtom* threeLeft1 = NULL; |
| 1041 | IRAtom* sevenLeft1 = NULL; |
| 1042 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 1043 | tl_assert(isShadowAtom(mce,xxhash)); |
| 1044 | tl_assert(isShadowAtom(mce,yyhash)); |
| 1045 | tl_assert(isOriginalAtom(mce,xx)); |
| 1046 | tl_assert(isOriginalAtom(mce,yy)); |
| 1047 | tl_assert(sameKindedAtoms(xxhash,xx)); |
| 1048 | tl_assert(sameKindedAtoms(yyhash,yy)); |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1049 | tl_assert(cmp_op == Iop_CmpORD32S || cmp_op == Iop_CmpORD32U |
| 1050 | || cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD64U); |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 1051 | |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1052 | if (0) { |
| 1053 | ppIROp(cmp_op); VG_(printf)(" "); |
| 1054 | ppIRExpr(xx); VG_(printf)(" "); ppIRExpr( yy ); VG_(printf)("\n"); |
| 1055 | } |
| 1056 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1057 | if (syned && isZero(yy)) { |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1058 | /* fancy interpretation */ |
| 1059 | /* if yy is zero, then it must be fully defined (zero#). */ |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1060 | tl_assert(isZero(yyhash)); |
| 1061 | threeLeft1 = m64 ? mkU64(3<<1) : mkU32(3<<1); |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1062 | return |
| 1063 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1064 | opOR, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1065 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1066 | 'V', mce,ty, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1067 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1068 | opAND, |
| 1069 | mkPCastTo(mce,ty, xxhash), |
| 1070 | threeLeft1 |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1071 | )), |
| 1072 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1073 | 'V', mce,ty, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1074 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1075 | opSHL, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1076 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1077 | 'V', mce,ty, |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1078 | binop(opSHR, xxhash, mkU8(width-1))), |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1079 | mkU8(3) |
| 1080 | )) |
| 1081 | ); |
| 1082 | } else { |
| 1083 | /* standard interpretation */ |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1084 | sevenLeft1 = m64 ? mkU64(7<<1) : mkU32(7<<1); |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1085 | return |
| 1086 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 1087 | opAND, |
| 1088 | mkPCastTo( mce,ty, |
| 1089 | mkUifU(mce,ty, xxhash,yyhash)), |
| 1090 | sevenLeft1 |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 1091 | ); |
| 1092 | } |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1096 | /*------------------------------------------------------------*/ |
| 1097 | /*--- Emit a test and complaint if something is undefined. ---*/ |
| 1098 | /*------------------------------------------------------------*/ |
| 1099 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1100 | static IRAtom* schemeE ( MCEnv* mce, IRExpr* e ); /* fwds */ |
| 1101 | |
| 1102 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1103 | /* Set the annotations on a dirty helper to indicate that the stack |
| 1104 | pointer and instruction pointers might be read. This is the |
| 1105 | behaviour of all 'emit-a-complaint' style functions we might |
| 1106 | call. */ |
| 1107 | |
| 1108 | static void setHelperAnns ( MCEnv* mce, IRDirty* di ) { |
| 1109 | di->nFxState = 2; |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 1110 | di->fxState[0].fx = Ifx_Read; |
| 1111 | di->fxState[0].offset = mce->layout->offset_SP; |
| 1112 | di->fxState[0].size = mce->layout->sizeof_SP; |
| 1113 | di->fxState[0].nRepeats = 0; |
| 1114 | di->fxState[0].repeatLen = 0; |
| 1115 | di->fxState[1].fx = Ifx_Read; |
| 1116 | di->fxState[1].offset = mce->layout->offset_IP; |
| 1117 | di->fxState[1].size = mce->layout->sizeof_IP; |
| 1118 | di->fxState[1].nRepeats = 0; |
| 1119 | di->fxState[1].repeatLen = 0; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 1123 | /* Check the supplied *original* |atom| for undefinedness, and emit a |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1124 | complaint if so. Once that happens, mark it as defined. This is |
| 1125 | possible because the atom is either a tmp or literal. If it's a |
| 1126 | tmp, it will be shadowed by a tmp, and so we can set the shadow to |
| 1127 | be defined. In fact as mentioned above, we will have to allocate a |
| 1128 | new tmp to carry the new 'defined' shadow value, and update the |
| 1129 | original->tmp mapping accordingly; we cannot simply assign a new |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 1130 | value to an existing shadow tmp as this breaks SSAness. |
| 1131 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1132 | The checks are performed, any resulting complaint emitted, and |
| 1133 | |atom|'s shadow temp set to 'defined', ONLY in the case that |
| 1134 | |guard| evaluates to True at run-time. If it evaluates to False |
| 1135 | then no action is performed. If |guard| is NULL (the usual case) |
| 1136 | then it is assumed to be always-true, and hence these actions are |
| 1137 | performed unconditionally. |
| 1138 | |
| 1139 | This routine does not generate code to check the definedness of |
| 1140 | |guard|. The caller is assumed to have taken care of that already. |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1141 | */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1142 | static void complainIfUndefined ( MCEnv* mce, IRAtom* atom, IRExpr *guard ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1143 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1144 | IRAtom* vatom; |
| 1145 | IRType ty; |
| 1146 | Int sz; |
| 1147 | IRDirty* di; |
| 1148 | IRAtom* cond; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1149 | IRAtom* origin; |
| 1150 | void* fn; |
florian | 6bd9dc1 | 2012-11-23 16:17:43 +0000 | [diff] [blame] | 1151 | const HChar* nm; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1152 | IRExpr** args; |
| 1153 | Int nargs; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1154 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1155 | // Don't do V bit tests if we're not reporting undefined value errors. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1156 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1157 | return; |
| 1158 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1159 | if (guard) |
| 1160 | tl_assert(isOriginalAtom(mce, guard)); |
| 1161 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1162 | /* Since the original expression is atomic, there's no duplicated |
| 1163 | work generated by making multiple V-expressions for it. So we |
| 1164 | don't really care about the possibility that someone else may |
| 1165 | also create a V-interpretion for it. */ |
| 1166 | tl_assert(isOriginalAtom(mce, atom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1167 | vatom = expr2vbits( mce, atom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1168 | tl_assert(isShadowAtom(mce, vatom)); |
| 1169 | tl_assert(sameKindedAtoms(atom, vatom)); |
| 1170 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1171 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1172 | |
| 1173 | /* sz is only used for constructing the error message */ |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1174 | sz = ty==Ity_I1 ? 0 : sizeofIRType(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1175 | |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1176 | cond = mkPCastTo( mce, Ity_I1, vatom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1177 | /* cond will be 0 if all defined, and 1 if any not defined. */ |
| 1178 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1179 | /* Get the origin info for the value we are about to check. At |
| 1180 | least, if we are doing origin tracking. If not, use a dummy |
| 1181 | zero origin. */ |
| 1182 | if (MC_(clo_mc_level) == 3) { |
| 1183 | origin = schemeE( mce, atom ); |
| 1184 | if (mce->hWordTy == Ity_I64) { |
| 1185 | origin = assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, origin) ); |
| 1186 | } |
| 1187 | } else { |
| 1188 | origin = NULL; |
| 1189 | } |
| 1190 | |
| 1191 | fn = NULL; |
| 1192 | nm = NULL; |
| 1193 | args = NULL; |
| 1194 | nargs = -1; |
| 1195 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1196 | switch (sz) { |
| 1197 | case 0: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1198 | if (origin) { |
| 1199 | fn = &MC_(helperc_value_check0_fail_w_o); |
| 1200 | nm = "MC_(helperc_value_check0_fail_w_o)"; |
| 1201 | args = mkIRExprVec_1(origin); |
| 1202 | nargs = 1; |
| 1203 | } else { |
| 1204 | fn = &MC_(helperc_value_check0_fail_no_o); |
| 1205 | nm = "MC_(helperc_value_check0_fail_no_o)"; |
| 1206 | args = mkIRExprVec_0(); |
| 1207 | nargs = 0; |
| 1208 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | case 1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1211 | if (origin) { |
| 1212 | fn = &MC_(helperc_value_check1_fail_w_o); |
| 1213 | nm = "MC_(helperc_value_check1_fail_w_o)"; |
| 1214 | args = mkIRExprVec_1(origin); |
| 1215 | nargs = 1; |
| 1216 | } else { |
| 1217 | fn = &MC_(helperc_value_check1_fail_no_o); |
| 1218 | nm = "MC_(helperc_value_check1_fail_no_o)"; |
| 1219 | args = mkIRExprVec_0(); |
| 1220 | nargs = 0; |
| 1221 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | case 4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1224 | if (origin) { |
| 1225 | fn = &MC_(helperc_value_check4_fail_w_o); |
| 1226 | nm = "MC_(helperc_value_check4_fail_w_o)"; |
| 1227 | args = mkIRExprVec_1(origin); |
| 1228 | nargs = 1; |
| 1229 | } else { |
| 1230 | fn = &MC_(helperc_value_check4_fail_no_o); |
| 1231 | nm = "MC_(helperc_value_check4_fail_no_o)"; |
| 1232 | args = mkIRExprVec_0(); |
| 1233 | nargs = 0; |
| 1234 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1235 | break; |
sewardj | 11bcc4e | 2005-04-23 22:38:38 +0000 | [diff] [blame] | 1236 | case 8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1237 | if (origin) { |
| 1238 | fn = &MC_(helperc_value_check8_fail_w_o); |
| 1239 | nm = "MC_(helperc_value_check8_fail_w_o)"; |
| 1240 | args = mkIRExprVec_1(origin); |
| 1241 | nargs = 1; |
| 1242 | } else { |
| 1243 | fn = &MC_(helperc_value_check8_fail_no_o); |
| 1244 | nm = "MC_(helperc_value_check8_fail_no_o)"; |
| 1245 | args = mkIRExprVec_0(); |
| 1246 | nargs = 0; |
| 1247 | } |
sewardj | 11bcc4e | 2005-04-23 22:38:38 +0000 | [diff] [blame] | 1248 | break; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 1249 | case 2: |
| 1250 | case 16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1251 | if (origin) { |
| 1252 | fn = &MC_(helperc_value_checkN_fail_w_o); |
| 1253 | nm = "MC_(helperc_value_checkN_fail_w_o)"; |
| 1254 | args = mkIRExprVec_2( mkIRExpr_HWord( sz ), origin); |
| 1255 | nargs = 2; |
| 1256 | } else { |
| 1257 | fn = &MC_(helperc_value_checkN_fail_no_o); |
| 1258 | nm = "MC_(helperc_value_checkN_fail_no_o)"; |
| 1259 | args = mkIRExprVec_1( mkIRExpr_HWord( sz ) ); |
| 1260 | nargs = 1; |
| 1261 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1262 | break; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 1263 | default: |
| 1264 | VG_(tool_panic)("unexpected szB"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1265 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1266 | |
| 1267 | tl_assert(fn); |
| 1268 | tl_assert(nm); |
| 1269 | tl_assert(args); |
| 1270 | tl_assert(nargs >= 0 && nargs <= 2); |
| 1271 | tl_assert( (MC_(clo_mc_level) == 3 && origin != NULL) |
| 1272 | || (MC_(clo_mc_level) == 2 && origin == NULL) ); |
| 1273 | |
| 1274 | di = unsafeIRDirty_0_N( nargs/*regparms*/, nm, |
| 1275 | VG_(fnptr_to_fnentry)( fn ), args ); |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1276 | di->guard = cond; // and cond is PCast-to-1(atom#) |
| 1277 | |
| 1278 | /* If the complaint is to be issued under a guard condition, AND |
| 1279 | that into the guard condition for the helper call. */ |
| 1280 | if (guard) { |
| 1281 | IRAtom *g1 = assignNew('V', mce, Ity_I32, unop(Iop_1Uto32, di->guard)); |
| 1282 | IRAtom *g2 = assignNew('V', mce, Ity_I32, unop(Iop_1Uto32, guard)); |
| 1283 | IRAtom *e = assignNew('V', mce, Ity_I32, binop(Iop_And32, g1, g2)); |
| 1284 | di->guard = assignNew('V', mce, Ity_I1, unop(Iop_32to1, e)); |
| 1285 | } |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1286 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1287 | setHelperAnns( mce, di ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1288 | stmt( 'V', mce, IRStmt_Dirty(di)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1289 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1290 | /* If |atom| is shadowed by an IRTemp, set the shadow tmp to be |
| 1291 | defined -- but only in the case where the guard evaluates to |
| 1292 | True at run-time. Do the update by setting the orig->shadow |
| 1293 | mapping for tmp to reflect the fact that this shadow is getting |
| 1294 | a new value. */ |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 1295 | tl_assert(isIRAtom(vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1296 | /* sameKindedAtoms ... */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1297 | if (vatom->tag == Iex_RdTmp) { |
| 1298 | tl_assert(atom->tag == Iex_RdTmp); |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1299 | if (guard == NULL) { |
| 1300 | // guard is 'always True', hence update unconditionally |
| 1301 | newShadowTmpV(mce, atom->Iex.RdTmp.tmp); |
| 1302 | assign('V', mce, findShadowTmpV(mce, atom->Iex.RdTmp.tmp), |
| 1303 | definedOfType(ty)); |
| 1304 | } else { |
| 1305 | // update the temp only conditionally. Do this by copying |
| 1306 | // its old value when the guard is False. |
| 1307 | // The old value .. |
| 1308 | IRTemp old_tmpV = findShadowTmpV(mce, atom->Iex.RdTmp.tmp); |
| 1309 | newShadowTmpV(mce, atom->Iex.RdTmp.tmp); |
| 1310 | IRAtom* new_tmpV |
| 1311 | = assignNew('V', mce, shadowTypeV(ty), |
| 1312 | IRExpr_ITE(guard, definedOfType(ty), |
| 1313 | mkexpr(old_tmpV))); |
| 1314 | assign('V', mce, findShadowTmpV(mce, atom->Iex.RdTmp.tmp), new_tmpV); |
| 1315 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | /*------------------------------------------------------------*/ |
| 1321 | /*--- Shadowing PUTs/GETs, and indexed variants thereof ---*/ |
| 1322 | /*------------------------------------------------------------*/ |
| 1323 | |
| 1324 | /* Examine the always-defined sections declared in layout to see if |
| 1325 | the (offset,size) section is within one. Note, is is an error to |
| 1326 | partially fall into such a region: (offset,size) should either be |
| 1327 | completely in such a region or completely not-in such a region. |
| 1328 | */ |
| 1329 | static Bool isAlwaysDefd ( MCEnv* mce, Int offset, Int size ) |
| 1330 | { |
| 1331 | Int minoffD, maxoffD, i; |
| 1332 | Int minoff = offset; |
| 1333 | Int maxoff = minoff + size - 1; |
| 1334 | tl_assert((minoff & ~0xFFFF) == 0); |
| 1335 | tl_assert((maxoff & ~0xFFFF) == 0); |
| 1336 | |
| 1337 | for (i = 0; i < mce->layout->n_alwaysDefd; i++) { |
| 1338 | minoffD = mce->layout->alwaysDefd[i].offset; |
| 1339 | maxoffD = minoffD + mce->layout->alwaysDefd[i].size - 1; |
| 1340 | tl_assert((minoffD & ~0xFFFF) == 0); |
| 1341 | tl_assert((maxoffD & ~0xFFFF) == 0); |
| 1342 | |
| 1343 | if (maxoff < minoffD || maxoffD < minoff) |
| 1344 | continue; /* no overlap */ |
| 1345 | if (minoff >= minoffD && maxoff <= maxoffD) |
| 1346 | return True; /* completely contained in an always-defd section */ |
| 1347 | |
| 1348 | VG_(tool_panic)("memcheck:isAlwaysDefd:partial overlap"); |
| 1349 | } |
| 1350 | return False; /* could not find any containing section */ |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | /* Generate into bb suitable actions to shadow this Put. If the state |
| 1355 | slice is marked 'always defined', do nothing. Otherwise, write the |
| 1356 | supplied V bits to the shadow state. We can pass in either an |
| 1357 | original atom or a V-atom, but not both. In the former case the |
| 1358 | relevant V-bits are then generated from the original. |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1359 | We assume here, that the definedness of GUARD has already been checked. |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1360 | */ |
| 1361 | static |
| 1362 | void do_shadow_PUT ( MCEnv* mce, Int offset, |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1363 | IRAtom* atom, IRAtom* vatom, IRExpr *guard ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1364 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1365 | IRType ty; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1366 | |
| 1367 | // Don't do shadow PUTs if we're not doing undefined value checking. |
| 1368 | // Their absence lets Vex's optimiser remove all the shadow computation |
| 1369 | // that they depend on, which includes GETs of the shadow registers. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1370 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1371 | return; |
| 1372 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1373 | if (atom) { |
| 1374 | tl_assert(!vatom); |
| 1375 | tl_assert(isOriginalAtom(mce, atom)); |
| 1376 | vatom = expr2vbits( mce, atom ); |
| 1377 | } else { |
| 1378 | tl_assert(vatom); |
| 1379 | tl_assert(isShadowAtom(mce, vatom)); |
| 1380 | } |
| 1381 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1382 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1383 | tl_assert(ty != Ity_I1); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1384 | tl_assert(ty != Ity_I128); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1385 | if (isAlwaysDefd(mce, offset, sizeofIRType(ty))) { |
| 1386 | /* later: no ... */ |
| 1387 | /* emit code to emit a complaint if any of the vbits are 1. */ |
| 1388 | /* complainIfUndefined(mce, atom); */ |
| 1389 | } else { |
| 1390 | /* Do a plain shadow Put. */ |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1391 | if (guard) { |
| 1392 | /* If the guard expression evaluates to false we simply Put the value |
| 1393 | that is already stored in the guest state slot */ |
| 1394 | IRAtom *cond, *iffalse; |
| 1395 | |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 1396 | cond = assignNew('V', mce, Ity_I1, guard); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1397 | iffalse = assignNew('V', mce, ty, |
| 1398 | IRExpr_Get(offset + mce->layout->total_sizeB, ty)); |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 1399 | vatom = assignNew('V', mce, ty, IRExpr_ITE(cond, vatom, iffalse)); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 1400 | } |
| 1401 | stmt( 'V', mce, IRStmt_Put( offset + mce->layout->total_sizeB, vatom )); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | /* Return an expression which contains the V bits corresponding to the |
| 1407 | given GETI (passed in in pieces). |
| 1408 | */ |
| 1409 | static |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 1410 | void do_shadow_PUTI ( MCEnv* mce, IRPutI *puti) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1411 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1412 | IRAtom* vatom; |
| 1413 | IRType ty, tyS; |
| 1414 | Int arrSize;; |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 1415 | IRRegArray* descr = puti->descr; |
| 1416 | IRAtom* ix = puti->ix; |
| 1417 | Int bias = puti->bias; |
| 1418 | IRAtom* atom = puti->data; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1419 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1420 | // Don't do shadow PUTIs if we're not doing undefined value checking. |
| 1421 | // Their absence lets Vex's optimiser remove all the shadow computation |
| 1422 | // that they depend on, which includes GETIs of the shadow registers. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1423 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1424 | return; |
| 1425 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1426 | tl_assert(isOriginalAtom(mce,atom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1427 | vatom = expr2vbits( mce, atom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1428 | tl_assert(sameKindedAtoms(atom, vatom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1429 | ty = descr->elemTy; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1430 | tyS = shadowTypeV(ty); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1431 | arrSize = descr->nElems * sizeofIRType(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1432 | tl_assert(ty != Ity_I1); |
| 1433 | tl_assert(isOriginalAtom(mce,ix)); |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1434 | complainIfUndefined(mce, ix, NULL); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1435 | if (isAlwaysDefd(mce, descr->base, arrSize)) { |
| 1436 | /* later: no ... */ |
| 1437 | /* emit code to emit a complaint if any of the vbits are 1. */ |
| 1438 | /* complainIfUndefined(mce, atom); */ |
| 1439 | } else { |
| 1440 | /* Do a cloned version of the Put that refers to the shadow |
| 1441 | area. */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1442 | IRRegArray* new_descr |
| 1443 | = mkIRRegArray( descr->base + mce->layout->total_sizeB, |
| 1444 | tyS, descr->nElems); |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 1445 | stmt( 'V', mce, IRStmt_PutI( mkIRPutI(new_descr, ix, bias, vatom) )); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
| 1450 | /* Return an expression which contains the V bits corresponding to the |
| 1451 | given GET (passed in in pieces). |
| 1452 | */ |
| 1453 | static |
| 1454 | IRExpr* shadow_GET ( MCEnv* mce, Int offset, IRType ty ) |
| 1455 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1456 | IRType tyS = shadowTypeV(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1457 | tl_assert(ty != Ity_I1); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1458 | tl_assert(ty != Ity_I128); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1459 | if (isAlwaysDefd(mce, offset, sizeofIRType(ty))) { |
| 1460 | /* Always defined, return all zeroes of the relevant type */ |
| 1461 | return definedOfType(tyS); |
| 1462 | } else { |
| 1463 | /* return a cloned version of the Get that refers to the shadow |
| 1464 | area. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1465 | /* FIXME: this isn't an atom! */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1466 | return IRExpr_Get( offset + mce->layout->total_sizeB, tyS ); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | |
| 1471 | /* Return an expression which contains the V bits corresponding to the |
| 1472 | given GETI (passed in in pieces). |
| 1473 | */ |
| 1474 | static |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1475 | IRExpr* shadow_GETI ( MCEnv* mce, |
| 1476 | IRRegArray* descr, IRAtom* ix, Int bias ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1477 | { |
| 1478 | IRType ty = descr->elemTy; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1479 | IRType tyS = shadowTypeV(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1480 | Int arrSize = descr->nElems * sizeofIRType(ty); |
| 1481 | tl_assert(ty != Ity_I1); |
| 1482 | tl_assert(isOriginalAtom(mce,ix)); |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 1483 | complainIfUndefined(mce, ix, NULL); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1484 | if (isAlwaysDefd(mce, descr->base, arrSize)) { |
| 1485 | /* Always defined, return all zeroes of the relevant type */ |
| 1486 | return definedOfType(tyS); |
| 1487 | } else { |
| 1488 | /* return a cloned version of the Get that refers to the shadow |
| 1489 | area. */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1490 | IRRegArray* new_descr |
| 1491 | = mkIRRegArray( descr->base + mce->layout->total_sizeB, |
| 1492 | tyS, descr->nElems); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1493 | return IRExpr_GetI( new_descr, ix, bias ); |
| 1494 | } |
| 1495 | } |
| 1496 | |
| 1497 | |
| 1498 | /*------------------------------------------------------------*/ |
| 1499 | /*--- Generating approximations for unknown operations, ---*/ |
| 1500 | /*--- using lazy-propagate semantics ---*/ |
| 1501 | /*------------------------------------------------------------*/ |
| 1502 | |
| 1503 | /* Lazy propagation of undefinedness from two values, resulting in the |
| 1504 | specified shadow type. |
| 1505 | */ |
| 1506 | static |
| 1507 | IRAtom* mkLazy2 ( MCEnv* mce, IRType finalVty, IRAtom* va1, IRAtom* va2 ) |
| 1508 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1509 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1510 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1511 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1512 | tl_assert(isShadowAtom(mce,va1)); |
| 1513 | tl_assert(isShadowAtom(mce,va2)); |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 1514 | |
| 1515 | /* The general case is inefficient because PCast is an expensive |
| 1516 | operation. Here are some special cases which use PCast only |
| 1517 | once rather than twice. */ |
| 1518 | |
| 1519 | /* I64 x I64 -> I64 */ |
| 1520 | if (t1 == Ity_I64 && t2 == Ity_I64 && finalVty == Ity_I64) { |
| 1521 | if (0) VG_(printf)("mkLazy2: I64 x I64 -> I64\n"); |
| 1522 | at = mkUifU(mce, Ity_I64, va1, va2); |
| 1523 | at = mkPCastTo(mce, Ity_I64, at); |
| 1524 | return at; |
| 1525 | } |
| 1526 | |
| 1527 | /* I64 x I64 -> I32 */ |
| 1528 | if (t1 == Ity_I64 && t2 == Ity_I64 && finalVty == Ity_I32) { |
| 1529 | if (0) VG_(printf)("mkLazy2: I64 x I64 -> I32\n"); |
| 1530 | at = mkUifU(mce, Ity_I64, va1, va2); |
| 1531 | at = mkPCastTo(mce, Ity_I32, at); |
| 1532 | return at; |
| 1533 | } |
| 1534 | |
| 1535 | if (0) { |
| 1536 | VG_(printf)("mkLazy2 "); |
| 1537 | ppIRType(t1); |
| 1538 | VG_(printf)("_"); |
| 1539 | ppIRType(t2); |
| 1540 | VG_(printf)("_"); |
| 1541 | ppIRType(finalVty); |
| 1542 | VG_(printf)("\n"); |
| 1543 | } |
| 1544 | |
| 1545 | /* General case: force everything via 32-bit intermediaries. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1546 | at = mkPCastTo(mce, Ity_I32, va1); |
| 1547 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va2)); |
| 1548 | at = mkPCastTo(mce, finalVty, at); |
| 1549 | return at; |
| 1550 | } |
| 1551 | |
| 1552 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1553 | /* 3-arg version of the above. */ |
| 1554 | static |
| 1555 | IRAtom* mkLazy3 ( MCEnv* mce, IRType finalVty, |
| 1556 | IRAtom* va1, IRAtom* va2, IRAtom* va3 ) |
| 1557 | { |
| 1558 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1559 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1560 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
| 1561 | IRType t3 = typeOfIRExpr(mce->sb->tyenv, va3); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1562 | tl_assert(isShadowAtom(mce,va1)); |
| 1563 | tl_assert(isShadowAtom(mce,va2)); |
| 1564 | tl_assert(isShadowAtom(mce,va3)); |
| 1565 | |
| 1566 | /* The general case is inefficient because PCast is an expensive |
| 1567 | operation. Here are some special cases which use PCast only |
| 1568 | twice rather than three times. */ |
| 1569 | |
| 1570 | /* I32 x I64 x I64 -> I64 */ |
| 1571 | /* Standard FP idiom: rm x FParg1 x FParg2 -> FPresult */ |
| 1572 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 |
| 1573 | && finalVty == Ity_I64) { |
| 1574 | if (0) VG_(printf)("mkLazy3: I32 x I64 x I64 -> I64\n"); |
| 1575 | /* Widen 1st arg to I64. Since 1st arg is typically a rounding |
| 1576 | mode indication which is fully defined, this should get |
| 1577 | folded out later. */ |
| 1578 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1579 | /* Now fold in 2nd and 3rd args. */ |
| 1580 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1581 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1582 | /* and PCast once again. */ |
| 1583 | at = mkPCastTo(mce, Ity_I64, at); |
| 1584 | return at; |
| 1585 | } |
| 1586 | |
carll | fb583cb | 2013-01-22 20:26:34 +0000 | [diff] [blame] | 1587 | /* I32 x I8 x I64 -> I64 */ |
| 1588 | if (t1 == Ity_I32 && t2 == Ity_I8 && t3 == Ity_I64 |
| 1589 | && finalVty == Ity_I64) { |
| 1590 | if (0) VG_(printf)("mkLazy3: I32 x I8 x I64 -> I64\n"); |
| 1591 | /* Widen 1st and 2nd args to I64. Since 1st arg is typically a |
| 1592 | * rounding mode indication which is fully defined, this should |
| 1593 | * get folded out later. |
| 1594 | */ |
| 1595 | IRAtom* at1 = mkPCastTo(mce, Ity_I64, va1); |
| 1596 | IRAtom* at2 = mkPCastTo(mce, Ity_I64, va2); |
| 1597 | at = mkUifU(mce, Ity_I64, at1, at2); // UifU(PCast(va1), PCast(va2)) |
| 1598 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1599 | /* and PCast once again. */ |
| 1600 | at = mkPCastTo(mce, Ity_I64, at); |
| 1601 | return at; |
| 1602 | } |
| 1603 | |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1604 | /* I32 x I64 x I64 -> I32 */ |
| 1605 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 |
| 1606 | && finalVty == Ity_I32) { |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1607 | if (0) VG_(printf)("mkLazy3: I32 x I64 x I64 -> I32\n"); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1608 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1609 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1610 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1611 | at = mkPCastTo(mce, Ity_I32, at); |
| 1612 | return at; |
| 1613 | } |
| 1614 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1615 | /* I32 x I32 x I32 -> I32 */ |
| 1616 | /* 32-bit FP idiom, as (eg) happens on ARM */ |
| 1617 | if (t1 == Ity_I32 && t2 == Ity_I32 && t3 == Ity_I32 |
| 1618 | && finalVty == Ity_I32) { |
| 1619 | if (0) VG_(printf)("mkLazy3: I32 x I32 x I32 -> I32\n"); |
| 1620 | at = va1; |
| 1621 | at = mkUifU(mce, Ity_I32, at, va2); |
| 1622 | at = mkUifU(mce, Ity_I32, at, va3); |
| 1623 | at = mkPCastTo(mce, Ity_I32, at); |
| 1624 | return at; |
| 1625 | } |
| 1626 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1627 | /* I32 x I128 x I128 -> I128 */ |
| 1628 | /* Standard FP idiom: rm x FParg1 x FParg2 -> FPresult */ |
| 1629 | if (t1 == Ity_I32 && t2 == Ity_I128 && t3 == Ity_I128 |
| 1630 | && finalVty == Ity_I128) { |
| 1631 | if (0) VG_(printf)("mkLazy3: I32 x I128 x I128 -> I128\n"); |
| 1632 | /* Widen 1st arg to I128. Since 1st arg is typically a rounding |
| 1633 | mode indication which is fully defined, this should get |
| 1634 | folded out later. */ |
| 1635 | at = mkPCastTo(mce, Ity_I128, va1); |
| 1636 | /* Now fold in 2nd and 3rd args. */ |
| 1637 | at = mkUifU(mce, Ity_I128, at, va2); |
| 1638 | at = mkUifU(mce, Ity_I128, at, va3); |
| 1639 | /* and PCast once again. */ |
| 1640 | at = mkPCastTo(mce, Ity_I128, at); |
| 1641 | return at; |
| 1642 | } |
carll | fb583cb | 2013-01-22 20:26:34 +0000 | [diff] [blame] | 1643 | |
| 1644 | /* I32 x I8 x I128 -> I128 */ |
| 1645 | /* Standard FP idiom: rm x FParg1 x FParg2 -> FPresult */ |
| 1646 | if (t1 == Ity_I32 && t2 == Ity_I8 && t3 == Ity_I128 |
| 1647 | && finalVty == Ity_I128) { |
| 1648 | if (0) VG_(printf)("mkLazy3: I32 x I8 x I128 -> I128\n"); |
sewardj | a28c43c | 2013-01-29 17:18:56 +0000 | [diff] [blame] | 1649 | /* Use I64 as an intermediate type, which means PCasting all 3 |
| 1650 | args to I64 to start with. 1st arg is typically a rounding |
| 1651 | mode indication which is fully defined, so we hope that it |
| 1652 | will get folded out later. */ |
carll | fb583cb | 2013-01-22 20:26:34 +0000 | [diff] [blame] | 1653 | IRAtom* at1 = mkPCastTo(mce, Ity_I64, va1); |
| 1654 | IRAtom* at2 = mkPCastTo(mce, Ity_I64, va2); |
sewardj | a28c43c | 2013-01-29 17:18:56 +0000 | [diff] [blame] | 1655 | IRAtom* at3 = mkPCastTo(mce, Ity_I64, va3); |
| 1656 | /* Now UifU all three together. */ |
carll | fb583cb | 2013-01-22 20:26:34 +0000 | [diff] [blame] | 1657 | at = mkUifU(mce, Ity_I64, at1, at2); // UifU(PCast(va1), PCast(va2)) |
sewardj | a28c43c | 2013-01-29 17:18:56 +0000 | [diff] [blame] | 1658 | at = mkUifU(mce, Ity_I64, at, at3); // ... `UifU` PCast(va3) |
carll | fb583cb | 2013-01-22 20:26:34 +0000 | [diff] [blame] | 1659 | /* and PCast once again. */ |
| 1660 | at = mkPCastTo(mce, Ity_I128, at); |
| 1661 | return at; |
| 1662 | } |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1663 | if (1) { |
| 1664 | VG_(printf)("mkLazy3: "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1665 | ppIRType(t1); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1666 | VG_(printf)(" x "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1667 | ppIRType(t2); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1668 | VG_(printf)(" x "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1669 | ppIRType(t3); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1670 | VG_(printf)(" -> "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1671 | ppIRType(finalVty); |
| 1672 | VG_(printf)("\n"); |
| 1673 | } |
| 1674 | |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1675 | tl_assert(0); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1676 | /* General case: force everything via 32-bit intermediaries. */ |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1677 | /* |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1678 | at = mkPCastTo(mce, Ity_I32, va1); |
| 1679 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va2)); |
| 1680 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va3)); |
| 1681 | at = mkPCastTo(mce, finalVty, at); |
| 1682 | return at; |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1683 | */ |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1687 | /* 4-arg version of the above. */ |
| 1688 | static |
| 1689 | IRAtom* mkLazy4 ( MCEnv* mce, IRType finalVty, |
| 1690 | IRAtom* va1, IRAtom* va2, IRAtom* va3, IRAtom* va4 ) |
| 1691 | { |
| 1692 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1693 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1694 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
| 1695 | IRType t3 = typeOfIRExpr(mce->sb->tyenv, va3); |
| 1696 | IRType t4 = typeOfIRExpr(mce->sb->tyenv, va4); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1697 | tl_assert(isShadowAtom(mce,va1)); |
| 1698 | tl_assert(isShadowAtom(mce,va2)); |
| 1699 | tl_assert(isShadowAtom(mce,va3)); |
| 1700 | tl_assert(isShadowAtom(mce,va4)); |
| 1701 | |
| 1702 | /* The general case is inefficient because PCast is an expensive |
| 1703 | operation. Here are some special cases which use PCast only |
| 1704 | twice rather than three times. */ |
| 1705 | |
| 1706 | /* I32 x I64 x I64 x I64 -> I64 */ |
| 1707 | /* Standard FP idiom: rm x FParg1 x FParg2 x FParg3 -> FPresult */ |
| 1708 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 && t4 == Ity_I64 |
| 1709 | && finalVty == Ity_I64) { |
| 1710 | if (0) VG_(printf)("mkLazy4: I32 x I64 x I64 x I64 -> I64\n"); |
| 1711 | /* Widen 1st arg to I64. Since 1st arg is typically a rounding |
| 1712 | mode indication which is fully defined, this should get |
| 1713 | folded out later. */ |
| 1714 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1715 | /* Now fold in 2nd, 3rd, 4th args. */ |
| 1716 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1717 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1718 | at = mkUifU(mce, Ity_I64, at, va4); |
| 1719 | /* and PCast once again. */ |
| 1720 | at = mkPCastTo(mce, Ity_I64, at); |
| 1721 | return at; |
| 1722 | } |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1723 | /* I32 x I32 x I32 x I32 -> I32 */ |
| 1724 | /* Standard FP idiom: rm x FParg1 x FParg2 x FParg3 -> FPresult */ |
| 1725 | if (t1 == Ity_I32 && t2 == Ity_I32 && t3 == Ity_I32 && t4 == Ity_I32 |
| 1726 | && finalVty == Ity_I32) { |
| 1727 | if (0) VG_(printf)("mkLazy4: I32 x I32 x I32 x I32 -> I32\n"); |
| 1728 | at = va1; |
| 1729 | /* Now fold in 2nd, 3rd, 4th args. */ |
| 1730 | at = mkUifU(mce, Ity_I32, at, va2); |
| 1731 | at = mkUifU(mce, Ity_I32, at, va3); |
| 1732 | at = mkUifU(mce, Ity_I32, at, va4); |
| 1733 | at = mkPCastTo(mce, Ity_I32, at); |
| 1734 | return at; |
| 1735 | } |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1736 | |
| 1737 | if (1) { |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1738 | VG_(printf)("mkLazy4: "); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1739 | ppIRType(t1); |
| 1740 | VG_(printf)(" x "); |
| 1741 | ppIRType(t2); |
| 1742 | VG_(printf)(" x "); |
| 1743 | ppIRType(t3); |
| 1744 | VG_(printf)(" x "); |
| 1745 | ppIRType(t4); |
| 1746 | VG_(printf)(" -> "); |
| 1747 | ppIRType(finalVty); |
| 1748 | VG_(printf)("\n"); |
| 1749 | } |
| 1750 | |
| 1751 | tl_assert(0); |
| 1752 | } |
| 1753 | |
| 1754 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1755 | /* Do the lazy propagation game from a null-terminated vector of |
| 1756 | atoms. This is presumably the arguments to a helper call, so the |
| 1757 | IRCallee info is also supplied in order that we can know which |
| 1758 | arguments should be ignored (via the .mcx_mask field). |
| 1759 | */ |
| 1760 | static |
| 1761 | IRAtom* mkLazyN ( MCEnv* mce, |
| 1762 | IRAtom** exprvec, IRType finalVtype, IRCallee* cee ) |
| 1763 | { |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1764 | Int i; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1765 | IRAtom* here; |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1766 | IRAtom* curr; |
| 1767 | IRType mergeTy; |
sewardj | 9943003 | 2011-05-04 09:09:31 +0000 | [diff] [blame] | 1768 | Bool mergeTy64 = True; |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1769 | |
| 1770 | /* Decide on the type of the merge intermediary. If all relevant |
| 1771 | args are I64, then it's I64. In all other circumstances, use |
| 1772 | I32. */ |
| 1773 | for (i = 0; exprvec[i]; i++) { |
| 1774 | tl_assert(i < 32); |
| 1775 | tl_assert(isOriginalAtom(mce, exprvec[i])); |
| 1776 | if (cee->mcx_mask & (1<<i)) |
| 1777 | continue; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1778 | if (typeOfIRExpr(mce->sb->tyenv, exprvec[i]) != Ity_I64) |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1779 | mergeTy64 = False; |
| 1780 | } |
| 1781 | |
| 1782 | mergeTy = mergeTy64 ? Ity_I64 : Ity_I32; |
| 1783 | curr = definedOfType(mergeTy); |
| 1784 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1785 | for (i = 0; exprvec[i]; i++) { |
| 1786 | tl_assert(i < 32); |
| 1787 | tl_assert(isOriginalAtom(mce, exprvec[i])); |
| 1788 | /* Only take notice of this arg if the callee's mc-exclusion |
| 1789 | mask does not say it is to be excluded. */ |
| 1790 | if (cee->mcx_mask & (1<<i)) { |
| 1791 | /* the arg is to be excluded from definedness checking. Do |
| 1792 | nothing. */ |
| 1793 | if (0) VG_(printf)("excluding %s(%d)\n", cee->name, i); |
| 1794 | } else { |
| 1795 | /* calculate the arg's definedness, and pessimistically merge |
| 1796 | it in. */ |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1797 | here = mkPCastTo( mce, mergeTy, expr2vbits(mce, exprvec[i]) ); |
| 1798 | curr = mergeTy64 |
| 1799 | ? mkUifU64(mce, here, curr) |
| 1800 | : mkUifU32(mce, here, curr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1801 | } |
| 1802 | } |
| 1803 | return mkPCastTo(mce, finalVtype, curr ); |
| 1804 | } |
| 1805 | |
| 1806 | |
| 1807 | /*------------------------------------------------------------*/ |
| 1808 | /*--- Generating expensive sequences for exact carry-chain ---*/ |
| 1809 | /*--- propagation in add/sub and related operations. ---*/ |
| 1810 | /*------------------------------------------------------------*/ |
| 1811 | |
| 1812 | static |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1813 | IRAtom* expensiveAddSub ( MCEnv* mce, |
| 1814 | Bool add, |
| 1815 | IRType ty, |
| 1816 | IRAtom* qaa, IRAtom* qbb, |
| 1817 | IRAtom* aa, IRAtom* bb ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1818 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1819 | IRAtom *a_min, *b_min, *a_max, *b_max; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1820 | IROp opAND, opOR, opXOR, opNOT, opADD, opSUB; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1821 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1822 | tl_assert(isShadowAtom(mce,qaa)); |
| 1823 | tl_assert(isShadowAtom(mce,qbb)); |
| 1824 | tl_assert(isOriginalAtom(mce,aa)); |
| 1825 | tl_assert(isOriginalAtom(mce,bb)); |
| 1826 | tl_assert(sameKindedAtoms(qaa,aa)); |
| 1827 | tl_assert(sameKindedAtoms(qbb,bb)); |
| 1828 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1829 | switch (ty) { |
| 1830 | case Ity_I32: |
| 1831 | opAND = Iop_And32; |
| 1832 | opOR = Iop_Or32; |
| 1833 | opXOR = Iop_Xor32; |
| 1834 | opNOT = Iop_Not32; |
| 1835 | opADD = Iop_Add32; |
| 1836 | opSUB = Iop_Sub32; |
| 1837 | break; |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 1838 | case Ity_I64: |
| 1839 | opAND = Iop_And64; |
| 1840 | opOR = Iop_Or64; |
| 1841 | opXOR = Iop_Xor64; |
| 1842 | opNOT = Iop_Not64; |
| 1843 | opADD = Iop_Add64; |
| 1844 | opSUB = Iop_Sub64; |
| 1845 | break; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1846 | default: |
| 1847 | VG_(tool_panic)("expensiveAddSub"); |
| 1848 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1849 | |
| 1850 | // a_min = aa & ~qaa |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1851 | a_min = assignNew('V', mce,ty, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1852 | binop(opAND, aa, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1853 | assignNew('V', mce,ty, unop(opNOT, qaa)))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1854 | |
| 1855 | // b_min = bb & ~qbb |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1856 | b_min = assignNew('V', mce,ty, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1857 | binop(opAND, bb, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1858 | assignNew('V', mce,ty, unop(opNOT, qbb)))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1859 | |
| 1860 | // a_max = aa | qaa |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1861 | a_max = assignNew('V', mce,ty, binop(opOR, aa, qaa)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1862 | |
| 1863 | // b_max = bb | qbb |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1864 | b_max = assignNew('V', mce,ty, binop(opOR, bb, qbb)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1865 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1866 | if (add) { |
| 1867 | // result = (qaa | qbb) | ((a_min + b_min) ^ (a_max + b_max)) |
| 1868 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1869 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1870 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1871 | assignNew('V', mce,ty, binop(opOR, qaa, qbb)), |
| 1872 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1873 | binop( opXOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1874 | assignNew('V', mce,ty, binop(opADD, a_min, b_min)), |
| 1875 | assignNew('V', mce,ty, binop(opADD, a_max, b_max)) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1876 | ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1877 | ) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1878 | ) |
| 1879 | ); |
| 1880 | } else { |
| 1881 | // result = (qaa | qbb) | ((a_min - b_max) ^ (a_max + b_min)) |
| 1882 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1883 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1884 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1885 | assignNew('V', mce,ty, binop(opOR, qaa, qbb)), |
| 1886 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1887 | binop( opXOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1888 | assignNew('V', mce,ty, binop(opSUB, a_min, b_max)), |
| 1889 | assignNew('V', mce,ty, binop(opSUB, a_max, b_min)) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1890 | ) |
| 1891 | ) |
| 1892 | ) |
| 1893 | ); |
| 1894 | } |
| 1895 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 1899 | static |
| 1900 | IRAtom* expensiveCountTrailingZeroes ( MCEnv* mce, IROp czop, |
| 1901 | IRAtom* atom, IRAtom* vatom ) |
| 1902 | { |
| 1903 | IRType ty; |
| 1904 | IROp xorOp, subOp, andOp; |
| 1905 | IRExpr *one; |
| 1906 | IRAtom *improver, *improved; |
| 1907 | tl_assert(isShadowAtom(mce,vatom)); |
| 1908 | tl_assert(isOriginalAtom(mce,atom)); |
| 1909 | tl_assert(sameKindedAtoms(atom,vatom)); |
| 1910 | |
| 1911 | switch (czop) { |
| 1912 | case Iop_Ctz32: |
| 1913 | ty = Ity_I32; |
| 1914 | xorOp = Iop_Xor32; |
| 1915 | subOp = Iop_Sub32; |
| 1916 | andOp = Iop_And32; |
| 1917 | one = mkU32(1); |
| 1918 | break; |
| 1919 | case Iop_Ctz64: |
| 1920 | ty = Ity_I64; |
| 1921 | xorOp = Iop_Xor64; |
| 1922 | subOp = Iop_Sub64; |
| 1923 | andOp = Iop_And64; |
| 1924 | one = mkU64(1); |
| 1925 | break; |
| 1926 | default: |
| 1927 | ppIROp(czop); |
| 1928 | VG_(tool_panic)("memcheck:expensiveCountTrailingZeroes"); |
| 1929 | } |
| 1930 | |
| 1931 | // improver = atom ^ (atom - 1) |
| 1932 | // |
| 1933 | // That is, improver has its low ctz(atom) bits equal to one; |
| 1934 | // higher bits (if any) equal to zero. |
| 1935 | improver = assignNew('V', mce,ty, |
| 1936 | binop(xorOp, |
| 1937 | atom, |
| 1938 | assignNew('V', mce, ty, |
| 1939 | binop(subOp, atom, one)))); |
| 1940 | |
| 1941 | // improved = vatom & improver |
| 1942 | // |
| 1943 | // That is, treat any V bits above the first ctz(atom) bits as |
| 1944 | // "defined". |
| 1945 | improved = assignNew('V', mce, ty, |
| 1946 | binop(andOp, vatom, improver)); |
| 1947 | |
| 1948 | // Return pessimizing cast of improved. |
| 1949 | return mkPCastTo(mce, ty, improved); |
| 1950 | } |
| 1951 | |
| 1952 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1953 | /*------------------------------------------------------------*/ |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1954 | /*--- Scalar shifts. ---*/ |
| 1955 | /*------------------------------------------------------------*/ |
| 1956 | |
| 1957 | /* Produce an interpretation for (aa << bb) (or >>s, >>u). The basic |
| 1958 | idea is to shift the definedness bits by the original shift amount. |
| 1959 | This introduces 0s ("defined") in new positions for left shifts and |
| 1960 | unsigned right shifts, and copies the top definedness bit for |
| 1961 | signed right shifts. So, conveniently, applying the original shift |
| 1962 | operator to the definedness bits for the left arg is exactly the |
| 1963 | right thing to do: |
| 1964 | |
| 1965 | (qaa << bb) |
| 1966 | |
| 1967 | However if the shift amount is undefined then the whole result |
| 1968 | is undefined. Hence need: |
| 1969 | |
| 1970 | (qaa << bb) `UifU` PCast(qbb) |
| 1971 | |
| 1972 | If the shift amount bb is a literal than qbb will say 'all defined' |
| 1973 | and the UifU and PCast will get folded out by post-instrumentation |
| 1974 | optimisation. |
| 1975 | */ |
| 1976 | static IRAtom* scalarShift ( MCEnv* mce, |
| 1977 | IRType ty, |
| 1978 | IROp original_op, |
| 1979 | IRAtom* qaa, IRAtom* qbb, |
| 1980 | IRAtom* aa, IRAtom* bb ) |
| 1981 | { |
| 1982 | tl_assert(isShadowAtom(mce,qaa)); |
| 1983 | tl_assert(isShadowAtom(mce,qbb)); |
| 1984 | tl_assert(isOriginalAtom(mce,aa)); |
| 1985 | tl_assert(isOriginalAtom(mce,bb)); |
| 1986 | tl_assert(sameKindedAtoms(qaa,aa)); |
| 1987 | tl_assert(sameKindedAtoms(qbb,bb)); |
| 1988 | return |
| 1989 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1990 | 'V', mce, ty, |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1991 | mkUifU( mce, ty, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1992 | assignNew('V', mce, ty, binop(original_op, qaa, bb)), |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1993 | mkPCastTo(mce, ty, qbb) |
| 1994 | ) |
| 1995 | ); |
| 1996 | } |
| 1997 | |
| 1998 | |
| 1999 | /*------------------------------------------------------------*/ |
| 2000 | /*--- Helpers for dealing with vector primops. ---*/ |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2001 | /*------------------------------------------------------------*/ |
| 2002 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2003 | /* Vector pessimisation -- pessimise within each lane individually. */ |
| 2004 | |
| 2005 | static IRAtom* mkPCast8x16 ( MCEnv* mce, IRAtom* at ) |
| 2006 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2007 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ8x16, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | static IRAtom* mkPCast16x8 ( MCEnv* mce, IRAtom* at ) |
| 2011 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2012 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ16x8, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | static IRAtom* mkPCast32x4 ( MCEnv* mce, IRAtom* at ) |
| 2016 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2017 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ32x4, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | static IRAtom* mkPCast64x2 ( MCEnv* mce, IRAtom* at ) |
| 2021 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2022 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ64x2, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 2025 | static IRAtom* mkPCast64x4 ( MCEnv* mce, IRAtom* at ) |
| 2026 | { |
| 2027 | return assignNew('V', mce, Ity_V256, unop(Iop_CmpNEZ64x4, at)); |
| 2028 | } |
| 2029 | |
| 2030 | static IRAtom* mkPCast32x8 ( MCEnv* mce, IRAtom* at ) |
| 2031 | { |
| 2032 | return assignNew('V', mce, Ity_V256, unop(Iop_CmpNEZ32x8, at)); |
| 2033 | } |
| 2034 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2035 | static IRAtom* mkPCast32x2 ( MCEnv* mce, IRAtom* at ) |
| 2036 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2037 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ32x2, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 2040 | static IRAtom* mkPCast16x16 ( MCEnv* mce, IRAtom* at ) |
| 2041 | { |
| 2042 | return assignNew('V', mce, Ity_V256, unop(Iop_CmpNEZ16x16, at)); |
| 2043 | } |
| 2044 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2045 | static IRAtom* mkPCast16x4 ( MCEnv* mce, IRAtom* at ) |
| 2046 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2047 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ16x4, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 2050 | static IRAtom* mkPCast8x32 ( MCEnv* mce, IRAtom* at ) |
| 2051 | { |
| 2052 | return assignNew('V', mce, Ity_V256, unop(Iop_CmpNEZ8x32, at)); |
| 2053 | } |
| 2054 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2055 | static IRAtom* mkPCast8x8 ( MCEnv* mce, IRAtom* at ) |
| 2056 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2057 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ8x8, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2058 | } |
| 2059 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2060 | static IRAtom* mkPCast16x2 ( MCEnv* mce, IRAtom* at ) |
| 2061 | { |
| 2062 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpNEZ16x2, at)); |
| 2063 | } |
| 2064 | |
| 2065 | static IRAtom* mkPCast8x4 ( MCEnv* mce, IRAtom* at ) |
| 2066 | { |
| 2067 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpNEZ8x4, at)); |
| 2068 | } |
| 2069 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2070 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2071 | /* Here's a simple scheme capable of handling ops derived from SSE1 |
| 2072 | code and while only generating ops that can be efficiently |
| 2073 | implemented in SSE1. */ |
| 2074 | |
| 2075 | /* All-lanes versions are straightforward: |
| 2076 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2077 | binary32Fx4(x,y) ==> PCast32x4(UifUV128(x#,y#)) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2078 | |
| 2079 | unary32Fx4(x,y) ==> PCast32x4(x#) |
| 2080 | |
| 2081 | Lowest-lane-only versions are more complex: |
| 2082 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2083 | binary32F0x4(x,y) ==> SetV128lo32( |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2084 | x#, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2085 | PCast32(V128to32(UifUV128(x#,y#))) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2086 | ) |
| 2087 | |
| 2088 | This is perhaps not so obvious. In particular, it's faster to |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2089 | do a V128-bit UifU and then take the bottom 32 bits than the more |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2090 | obvious scheme of taking the bottom 32 bits of each operand |
| 2091 | and doing a 32-bit UifU. Basically since UifU is fast and |
| 2092 | chopping lanes off vector values is slow. |
| 2093 | |
| 2094 | Finally: |
| 2095 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2096 | unary32F0x4(x) ==> SetV128lo32( |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2097 | x#, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2098 | PCast32(V128to32(x#)) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2099 | ) |
| 2100 | |
| 2101 | Where: |
| 2102 | |
| 2103 | PCast32(v#) = 1Sto32(CmpNE32(v#,0)) |
| 2104 | PCast32x4(v#) = CmpNEZ32x4(v#) |
| 2105 | */ |
| 2106 | |
| 2107 | static |
| 2108 | IRAtom* binary32Fx4 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2109 | { |
| 2110 | IRAtom* at; |
| 2111 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2112 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2113 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2114 | at = assignNew('V', mce, Ity_V128, mkPCast32x4(mce, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2115 | return at; |
| 2116 | } |
| 2117 | |
| 2118 | static |
| 2119 | IRAtom* unary32Fx4 ( MCEnv* mce, IRAtom* vatomX ) |
| 2120 | { |
| 2121 | IRAtom* at; |
| 2122 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2123 | at = assignNew('V', mce, Ity_V128, mkPCast32x4(mce, vatomX)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2124 | return at; |
| 2125 | } |
| 2126 | |
| 2127 | static |
| 2128 | IRAtom* binary32F0x4 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2129 | { |
| 2130 | IRAtom* at; |
| 2131 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2132 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2133 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2134 | at = assignNew('V', mce, Ity_I32, unop(Iop_V128to32, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2135 | at = mkPCastTo(mce, Ity_I32, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2136 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo32, vatomX, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2137 | return at; |
| 2138 | } |
| 2139 | |
| 2140 | static |
| 2141 | IRAtom* unary32F0x4 ( MCEnv* mce, IRAtom* vatomX ) |
| 2142 | { |
| 2143 | IRAtom* at; |
| 2144 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2145 | at = assignNew('V', mce, Ity_I32, unop(Iop_V128to32, vatomX)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2146 | at = mkPCastTo(mce, Ity_I32, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2147 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo32, vatomX, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2148 | return at; |
| 2149 | } |
| 2150 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2151 | /* --- ... and ... 64Fx2 versions of the same ... --- */ |
| 2152 | |
| 2153 | static |
| 2154 | IRAtom* binary64Fx2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2155 | { |
| 2156 | IRAtom* at; |
| 2157 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2158 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2159 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2160 | at = assignNew('V', mce, Ity_V128, mkPCast64x2(mce, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2161 | return at; |
| 2162 | } |
| 2163 | |
| 2164 | static |
| 2165 | IRAtom* unary64Fx2 ( MCEnv* mce, IRAtom* vatomX ) |
| 2166 | { |
| 2167 | IRAtom* at; |
| 2168 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2169 | at = assignNew('V', mce, Ity_V128, mkPCast64x2(mce, vatomX)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2170 | return at; |
| 2171 | } |
| 2172 | |
| 2173 | static |
| 2174 | IRAtom* binary64F0x2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2175 | { |
| 2176 | IRAtom* at; |
| 2177 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2178 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2179 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2180 | at = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2181 | at = mkPCastTo(mce, Ity_I64, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2182 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo64, vatomX, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2183 | return at; |
| 2184 | } |
| 2185 | |
| 2186 | static |
| 2187 | IRAtom* unary64F0x2 ( MCEnv* mce, IRAtom* vatomX ) |
| 2188 | { |
| 2189 | IRAtom* at; |
| 2190 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2191 | at = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, vatomX)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2192 | at = mkPCastTo(mce, Ity_I64, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2193 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo64, vatomX, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2194 | return at; |
| 2195 | } |
| 2196 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2197 | /* --- --- ... and ... 32Fx2 versions of the same --- --- */ |
| 2198 | |
| 2199 | static |
| 2200 | IRAtom* binary32Fx2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2201 | { |
| 2202 | IRAtom* at; |
| 2203 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2204 | tl_assert(isShadowAtom(mce, vatomY)); |
| 2205 | at = mkUifU64(mce, vatomX, vatomY); |
| 2206 | at = assignNew('V', mce, Ity_I64, mkPCast32x2(mce, at)); |
| 2207 | return at; |
| 2208 | } |
| 2209 | |
| 2210 | static |
| 2211 | IRAtom* unary32Fx2 ( MCEnv* mce, IRAtom* vatomX ) |
| 2212 | { |
| 2213 | IRAtom* at; |
| 2214 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2215 | at = assignNew('V', mce, Ity_I64, mkPCast32x2(mce, vatomX)); |
| 2216 | return at; |
| 2217 | } |
| 2218 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 2219 | /* --- ... and ... 64Fx4 versions of the same ... --- */ |
| 2220 | |
| 2221 | static |
| 2222 | IRAtom* binary64Fx4 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2223 | { |
| 2224 | IRAtom* at; |
| 2225 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2226 | tl_assert(isShadowAtom(mce, vatomY)); |
| 2227 | at = mkUifUV256(mce, vatomX, vatomY); |
| 2228 | at = assignNew('V', mce, Ity_V256, mkPCast64x4(mce, at)); |
| 2229 | return at; |
| 2230 | } |
| 2231 | |
| 2232 | static |
| 2233 | IRAtom* unary64Fx4 ( MCEnv* mce, IRAtom* vatomX ) |
| 2234 | { |
| 2235 | IRAtom* at; |
| 2236 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2237 | at = assignNew('V', mce, Ity_V256, mkPCast64x4(mce, vatomX)); |
| 2238 | return at; |
| 2239 | } |
| 2240 | |
| 2241 | /* --- ... and ... 32Fx8 versions of the same ... --- */ |
| 2242 | |
| 2243 | static |
| 2244 | IRAtom* binary32Fx8 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 2245 | { |
| 2246 | IRAtom* at; |
| 2247 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2248 | tl_assert(isShadowAtom(mce, vatomY)); |
| 2249 | at = mkUifUV256(mce, vatomX, vatomY); |
| 2250 | at = assignNew('V', mce, Ity_V256, mkPCast32x8(mce, at)); |
| 2251 | return at; |
| 2252 | } |
| 2253 | |
| 2254 | static |
| 2255 | IRAtom* unary32Fx8 ( MCEnv* mce, IRAtom* vatomX ) |
| 2256 | { |
| 2257 | IRAtom* at; |
| 2258 | tl_assert(isShadowAtom(mce, vatomX)); |
| 2259 | at = assignNew('V', mce, Ity_V256, mkPCast32x8(mce, vatomX)); |
| 2260 | return at; |
| 2261 | } |
| 2262 | |
sewardj | 1eb272f | 2014-01-26 18:36:52 +0000 | [diff] [blame] | 2263 | /* --- 64Fx2 binary FP ops, with rounding mode --- */ |
| 2264 | |
| 2265 | static |
| 2266 | IRAtom* binary64Fx2_w_rm ( MCEnv* mce, IRAtom* vRM, |
| 2267 | IRAtom* vatomX, IRAtom* vatomY ) |
| 2268 | { |
| 2269 | /* This is the same as binary64Fx2, except that we subsequently |
| 2270 | pessimise vRM (definedness of the rounding mode), widen to 128 |
| 2271 | bits and UifU it into the result. As with the scalar cases, if |
| 2272 | the RM is a constant then it is defined and so this extra bit |
| 2273 | will get constant-folded out later. */ |
| 2274 | // "do" the vector args |
| 2275 | IRAtom* t1 = binary64Fx2(mce, vatomX, vatomY); |
| 2276 | // PCast the RM, and widen it to 128 bits |
| 2277 | IRAtom* t2 = mkPCastTo(mce, Ity_V128, vRM); |
| 2278 | // Roll it into the result |
| 2279 | t1 = mkUifUV128(mce, t1, t2); |
| 2280 | return t1; |
| 2281 | } |
| 2282 | |
| 2283 | /* --- ... and ... 32Fx4 versions of the same --- */ |
| 2284 | |
| 2285 | static |
| 2286 | IRAtom* binary32Fx4_w_rm ( MCEnv* mce, IRAtom* vRM, |
| 2287 | IRAtom* vatomX, IRAtom* vatomY ) |
| 2288 | { |
| 2289 | IRAtom* t1 = binary32Fx4(mce, vatomX, vatomY); |
| 2290 | // PCast the RM, and widen it to 128 bits |
| 2291 | IRAtom* t2 = mkPCastTo(mce, Ity_V128, vRM); |
| 2292 | // Roll it into the result |
| 2293 | t1 = mkUifUV128(mce, t1, t2); |
| 2294 | return t1; |
| 2295 | } |
| 2296 | |
| 2297 | /* --- ... and ... 64Fx4 versions of the same --- */ |
| 2298 | |
| 2299 | static |
| 2300 | IRAtom* binary64Fx4_w_rm ( MCEnv* mce, IRAtom* vRM, |
| 2301 | IRAtom* vatomX, IRAtom* vatomY ) |
| 2302 | { |
| 2303 | IRAtom* t1 = binary64Fx4(mce, vatomX, vatomY); |
| 2304 | // PCast the RM, and widen it to 256 bits |
| 2305 | IRAtom* t2 = mkPCastTo(mce, Ity_V256, vRM); |
| 2306 | // Roll it into the result |
| 2307 | t1 = mkUifUV256(mce, t1, t2); |
| 2308 | return t1; |
| 2309 | } |
| 2310 | |
| 2311 | /* --- ... and ... 32Fx8 versions of the same --- */ |
| 2312 | |
| 2313 | static |
| 2314 | IRAtom* binary32Fx8_w_rm ( MCEnv* mce, IRAtom* vRM, |
| 2315 | IRAtom* vatomX, IRAtom* vatomY ) |
| 2316 | { |
| 2317 | IRAtom* t1 = binary32Fx8(mce, vatomX, vatomY); |
| 2318 | // PCast the RM, and widen it to 256 bits |
| 2319 | IRAtom* t2 = mkPCastTo(mce, Ity_V256, vRM); |
| 2320 | // Roll it into the result |
| 2321 | t1 = mkUifUV256(mce, t1, t2); |
| 2322 | return t1; |
| 2323 | } |
| 2324 | |
| 2325 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2326 | /* --- --- Vector saturated narrowing --- --- */ |
| 2327 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2328 | /* We used to do something very clever here, but on closer inspection |
| 2329 | (2011-Jun-15), and in particular bug #279698, it turns out to be |
| 2330 | wrong. Part of the problem came from the fact that for a long |
| 2331 | time, the IR primops to do with saturated narrowing were |
| 2332 | underspecified and managed to confuse multiple cases which needed |
| 2333 | to be separate: the op names had a signedness qualifier, but in |
| 2334 | fact the source and destination signednesses needed to be specified |
| 2335 | independently, so the op names really need two independent |
| 2336 | signedness specifiers. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2337 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2338 | As of 2011-Jun-15 (ish) the underspecification was sorted out |
| 2339 | properly. The incorrect instrumentation remained, though. That |
| 2340 | has now (2011-Oct-22) been fixed. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2341 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2342 | What we now do is simple: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2343 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2344 | Let the original narrowing op be QNarrowBinXtoYxZ, where Z is a |
| 2345 | number of lanes, X is the source lane width and signedness, and Y |
| 2346 | is the destination lane width and signedness. In all cases the |
| 2347 | destination lane width is half the source lane width, so the names |
| 2348 | have a bit of redundancy, but are at least easy to read. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2349 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2350 | For example, Iop_QNarrowBin32Sto16Ux8 narrows 8 lanes of signed 32s |
| 2351 | to unsigned 16s. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2352 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2353 | Let Vanilla(OP) be a function that takes OP, one of these |
| 2354 | saturating narrowing ops, and produces the same "shaped" narrowing |
| 2355 | op which is not saturating, but merely dumps the most significant |
| 2356 | bits. "same shape" means that the lane numbers and widths are the |
| 2357 | same as with OP. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2358 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2359 | For example, Vanilla(Iop_QNarrowBin32Sto16Ux8) |
| 2360 | = Iop_NarrowBin32to16x8, |
| 2361 | that is, narrow 8 lanes of 32 bits to 8 lanes of 16 bits, by |
| 2362 | dumping the top half of each lane. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2363 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2364 | So, with that in place, the scheme is simple, and it is simple to |
| 2365 | pessimise each lane individually and then apply Vanilla(OP) so as |
| 2366 | to get the result in the right "shape". If the original OP is |
| 2367 | QNarrowBinXtoYxZ then we produce |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2368 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2369 | Vanilla(OP)( PCast-X-to-X-x-Z(vatom1), PCast-X-to-X-x-Z(vatom2) ) |
sewardj | 9beeb0a | 2011-06-15 15:11:07 +0000 | [diff] [blame] | 2370 | |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2371 | or for the case when OP is unary (Iop_QNarrowUn*) |
| 2372 | |
| 2373 | Vanilla(OP)( PCast-X-to-X-x-Z(vatom) ) |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2374 | */ |
| 2375 | static |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2376 | IROp vanillaNarrowingOpOfShape ( IROp qnarrowOp ) |
| 2377 | { |
| 2378 | switch (qnarrowOp) { |
| 2379 | /* Binary: (128, 128) -> 128 */ |
| 2380 | case Iop_QNarrowBin16Sto8Ux16: |
| 2381 | case Iop_QNarrowBin16Sto8Sx16: |
| 2382 | case Iop_QNarrowBin16Uto8Ux16: |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 2383 | case Iop_QNarrowBin64Sto32Sx4: |
| 2384 | case Iop_QNarrowBin64Uto32Ux4: |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2385 | return Iop_NarrowBin16to8x16; |
| 2386 | case Iop_QNarrowBin32Sto16Ux8: |
| 2387 | case Iop_QNarrowBin32Sto16Sx8: |
| 2388 | case Iop_QNarrowBin32Uto16Ux8: |
| 2389 | return Iop_NarrowBin32to16x8; |
| 2390 | /* Binary: (64, 64) -> 64 */ |
| 2391 | case Iop_QNarrowBin32Sto16Sx4: |
| 2392 | return Iop_NarrowBin32to16x4; |
| 2393 | case Iop_QNarrowBin16Sto8Ux8: |
| 2394 | case Iop_QNarrowBin16Sto8Sx8: |
| 2395 | return Iop_NarrowBin16to8x8; |
| 2396 | /* Unary: 128 -> 64 */ |
| 2397 | case Iop_QNarrowUn64Uto32Ux2: |
| 2398 | case Iop_QNarrowUn64Sto32Sx2: |
| 2399 | case Iop_QNarrowUn64Sto32Ux2: |
| 2400 | return Iop_NarrowUn64to32x2; |
| 2401 | case Iop_QNarrowUn32Uto16Ux4: |
| 2402 | case Iop_QNarrowUn32Sto16Sx4: |
| 2403 | case Iop_QNarrowUn32Sto16Ux4: |
| 2404 | return Iop_NarrowUn32to16x4; |
| 2405 | case Iop_QNarrowUn16Uto8Ux8: |
| 2406 | case Iop_QNarrowUn16Sto8Sx8: |
| 2407 | case Iop_QNarrowUn16Sto8Ux8: |
| 2408 | return Iop_NarrowUn16to8x8; |
| 2409 | default: |
| 2410 | ppIROp(qnarrowOp); |
| 2411 | VG_(tool_panic)("vanillaNarrowOpOfShape"); |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2416 | IRAtom* vectorNarrowBinV128 ( MCEnv* mce, IROp narrow_op, |
| 2417 | IRAtom* vatom1, IRAtom* vatom2) |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2418 | { |
| 2419 | IRAtom *at1, *at2, *at3; |
| 2420 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2421 | switch (narrow_op) { |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 2422 | case Iop_QNarrowBin64Sto32Sx4: pcast = mkPCast32x4; break; |
| 2423 | case Iop_QNarrowBin64Uto32Ux4: pcast = mkPCast32x4; break; |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2424 | case Iop_QNarrowBin32Sto16Sx8: pcast = mkPCast32x4; break; |
| 2425 | case Iop_QNarrowBin32Uto16Ux8: pcast = mkPCast32x4; break; |
| 2426 | case Iop_QNarrowBin32Sto16Ux8: pcast = mkPCast32x4; break; |
| 2427 | case Iop_QNarrowBin16Sto8Sx16: pcast = mkPCast16x8; break; |
| 2428 | case Iop_QNarrowBin16Uto8Ux16: pcast = mkPCast16x8; break; |
| 2429 | case Iop_QNarrowBin16Sto8Ux16: pcast = mkPCast16x8; break; |
| 2430 | default: VG_(tool_panic)("vectorNarrowBinV128"); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2431 | } |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2432 | IROp vanilla_narrow = vanillaNarrowingOpOfShape(narrow_op); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2433 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2434 | tl_assert(isShadowAtom(mce,vatom2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2435 | at1 = assignNew('V', mce, Ity_V128, pcast(mce, vatom1)); |
| 2436 | at2 = assignNew('V', mce, Ity_V128, pcast(mce, vatom2)); |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2437 | at3 = assignNew('V', mce, Ity_V128, binop(vanilla_narrow, at1, at2)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2438 | return at3; |
| 2439 | } |
| 2440 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2441 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2442 | IRAtom* vectorNarrowBin64 ( MCEnv* mce, IROp narrow_op, |
| 2443 | IRAtom* vatom1, IRAtom* vatom2) |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2444 | { |
| 2445 | IRAtom *at1, *at2, *at3; |
| 2446 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2447 | switch (narrow_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2448 | case Iop_QNarrowBin32Sto16Sx4: pcast = mkPCast32x2; break; |
| 2449 | case Iop_QNarrowBin16Sto8Sx8: pcast = mkPCast16x4; break; |
| 2450 | case Iop_QNarrowBin16Sto8Ux8: pcast = mkPCast16x4; break; |
| 2451 | default: VG_(tool_panic)("vectorNarrowBin64"); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2452 | } |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2453 | IROp vanilla_narrow = vanillaNarrowingOpOfShape(narrow_op); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2454 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2455 | tl_assert(isShadowAtom(mce,vatom2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2456 | at1 = assignNew('V', mce, Ity_I64, pcast(mce, vatom1)); |
| 2457 | at2 = assignNew('V', mce, Ity_I64, pcast(mce, vatom2)); |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2458 | at3 = assignNew('V', mce, Ity_I64, binop(vanilla_narrow, at1, at2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2459 | return at3; |
| 2460 | } |
| 2461 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2462 | static |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2463 | IRAtom* vectorNarrowUnV128 ( MCEnv* mce, IROp narrow_op, |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2464 | IRAtom* vatom1) |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2465 | { |
| 2466 | IRAtom *at1, *at2; |
| 2467 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2468 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2469 | /* For vanilla narrowing (non-saturating), we can just apply |
| 2470 | the op directly to the V bits. */ |
| 2471 | switch (narrow_op) { |
| 2472 | case Iop_NarrowUn16to8x8: |
| 2473 | case Iop_NarrowUn32to16x4: |
| 2474 | case Iop_NarrowUn64to32x2: |
| 2475 | at1 = assignNew('V', mce, Ity_I64, unop(narrow_op, vatom1)); |
| 2476 | return at1; |
| 2477 | default: |
| 2478 | break; /* Do Plan B */ |
| 2479 | } |
| 2480 | /* Plan B: for ops that involve a saturation operation on the args, |
| 2481 | we must PCast before the vanilla narrow. */ |
| 2482 | switch (narrow_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2483 | case Iop_QNarrowUn16Sto8Sx8: pcast = mkPCast16x8; break; |
| 2484 | case Iop_QNarrowUn16Sto8Ux8: pcast = mkPCast16x8; break; |
| 2485 | case Iop_QNarrowUn16Uto8Ux8: pcast = mkPCast16x8; break; |
| 2486 | case Iop_QNarrowUn32Sto16Sx4: pcast = mkPCast32x4; break; |
| 2487 | case Iop_QNarrowUn32Sto16Ux4: pcast = mkPCast32x4; break; |
| 2488 | case Iop_QNarrowUn32Uto16Ux4: pcast = mkPCast32x4; break; |
| 2489 | case Iop_QNarrowUn64Sto32Sx2: pcast = mkPCast64x2; break; |
| 2490 | case Iop_QNarrowUn64Sto32Ux2: pcast = mkPCast64x2; break; |
| 2491 | case Iop_QNarrowUn64Uto32Ux2: pcast = mkPCast64x2; break; |
| 2492 | default: VG_(tool_panic)("vectorNarrowUnV128"); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2493 | } |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2494 | IROp vanilla_narrow = vanillaNarrowingOpOfShape(narrow_op); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2495 | at1 = assignNew('V', mce, Ity_V128, pcast(mce, vatom1)); |
sewardj | b5a2923 | 2011-10-22 09:29:41 +0000 | [diff] [blame] | 2496 | at2 = assignNew('V', mce, Ity_I64, unop(vanilla_narrow, at1)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2497 | return at2; |
| 2498 | } |
| 2499 | |
| 2500 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2501 | IRAtom* vectorWidenI64 ( MCEnv* mce, IROp longen_op, |
| 2502 | IRAtom* vatom1) |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2503 | { |
| 2504 | IRAtom *at1, *at2; |
| 2505 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2506 | switch (longen_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2507 | case Iop_Widen8Uto16x8: pcast = mkPCast16x8; break; |
| 2508 | case Iop_Widen8Sto16x8: pcast = mkPCast16x8; break; |
| 2509 | case Iop_Widen16Uto32x4: pcast = mkPCast32x4; break; |
| 2510 | case Iop_Widen16Sto32x4: pcast = mkPCast32x4; break; |
| 2511 | case Iop_Widen32Uto64x2: pcast = mkPCast64x2; break; |
| 2512 | case Iop_Widen32Sto64x2: pcast = mkPCast64x2; break; |
| 2513 | default: VG_(tool_panic)("vectorWidenI64"); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2514 | } |
| 2515 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2516 | at1 = assignNew('V', mce, Ity_V128, unop(longen_op, vatom1)); |
| 2517 | at2 = assignNew('V', mce, Ity_V128, pcast(mce, at1)); |
| 2518 | return at2; |
| 2519 | } |
| 2520 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2521 | |
| 2522 | /* --- --- Vector integer arithmetic --- --- */ |
| 2523 | |
| 2524 | /* Simple ... UifU the args and per-lane pessimise the results. */ |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2525 | |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 2526 | /* --- V256-bit versions --- */ |
| 2527 | |
| 2528 | static |
| 2529 | IRAtom* binary8Ix32 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2530 | { |
| 2531 | IRAtom* at; |
| 2532 | at = mkUifUV256(mce, vatom1, vatom2); |
| 2533 | at = mkPCast8x32(mce, at); |
| 2534 | return at; |
| 2535 | } |
| 2536 | |
| 2537 | static |
| 2538 | IRAtom* binary16Ix16 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2539 | { |
| 2540 | IRAtom* at; |
| 2541 | at = mkUifUV256(mce, vatom1, vatom2); |
| 2542 | at = mkPCast16x16(mce, at); |
| 2543 | return at; |
| 2544 | } |
| 2545 | |
| 2546 | static |
| 2547 | IRAtom* binary32Ix8 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2548 | { |
| 2549 | IRAtom* at; |
| 2550 | at = mkUifUV256(mce, vatom1, vatom2); |
| 2551 | at = mkPCast32x8(mce, at); |
| 2552 | return at; |
| 2553 | } |
| 2554 | |
| 2555 | static |
| 2556 | IRAtom* binary64Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2557 | { |
| 2558 | IRAtom* at; |
| 2559 | at = mkUifUV256(mce, vatom1, vatom2); |
| 2560 | at = mkPCast64x4(mce, at); |
| 2561 | return at; |
| 2562 | } |
| 2563 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2564 | /* --- V128-bit versions --- */ |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2565 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2566 | static |
| 2567 | IRAtom* binary8Ix16 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2568 | { |
| 2569 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2570 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2571 | at = mkPCast8x16(mce, at); |
| 2572 | return at; |
| 2573 | } |
| 2574 | |
| 2575 | static |
| 2576 | IRAtom* binary16Ix8 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2577 | { |
| 2578 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2579 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2580 | at = mkPCast16x8(mce, at); |
| 2581 | return at; |
| 2582 | } |
| 2583 | |
| 2584 | static |
| 2585 | IRAtom* binary32Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2586 | { |
| 2587 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2588 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2589 | at = mkPCast32x4(mce, at); |
| 2590 | return at; |
| 2591 | } |
| 2592 | |
| 2593 | static |
| 2594 | IRAtom* binary64Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2595 | { |
| 2596 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2597 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2598 | at = mkPCast64x2(mce, at); |
| 2599 | return at; |
| 2600 | } |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2601 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2602 | /* --- 64-bit versions --- */ |
| 2603 | |
| 2604 | static |
| 2605 | IRAtom* binary8Ix8 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2606 | { |
| 2607 | IRAtom* at; |
| 2608 | at = mkUifU64(mce, vatom1, vatom2); |
| 2609 | at = mkPCast8x8(mce, at); |
| 2610 | return at; |
| 2611 | } |
| 2612 | |
| 2613 | static |
| 2614 | IRAtom* binary16Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2615 | { |
| 2616 | IRAtom* at; |
| 2617 | at = mkUifU64(mce, vatom1, vatom2); |
| 2618 | at = mkPCast16x4(mce, at); |
| 2619 | return at; |
| 2620 | } |
| 2621 | |
| 2622 | static |
| 2623 | IRAtom* binary32Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2624 | { |
| 2625 | IRAtom* at; |
| 2626 | at = mkUifU64(mce, vatom1, vatom2); |
| 2627 | at = mkPCast32x2(mce, at); |
| 2628 | return at; |
| 2629 | } |
| 2630 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2631 | static |
| 2632 | IRAtom* binary64Ix1 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2633 | { |
| 2634 | IRAtom* at; |
| 2635 | at = mkUifU64(mce, vatom1, vatom2); |
| 2636 | at = mkPCastTo(mce, Ity_I64, at); |
| 2637 | return at; |
| 2638 | } |
| 2639 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2640 | /* --- 32-bit versions --- */ |
| 2641 | |
| 2642 | static |
| 2643 | IRAtom* binary8Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2644 | { |
| 2645 | IRAtom* at; |
| 2646 | at = mkUifU32(mce, vatom1, vatom2); |
| 2647 | at = mkPCast8x4(mce, at); |
| 2648 | return at; |
| 2649 | } |
| 2650 | |
| 2651 | static |
| 2652 | IRAtom* binary16Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2653 | { |
| 2654 | IRAtom* at; |
| 2655 | at = mkUifU32(mce, vatom1, vatom2); |
| 2656 | at = mkPCast16x2(mce, at); |
| 2657 | return at; |
| 2658 | } |
| 2659 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2660 | |
| 2661 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2662 | /*--- Generate shadow values from all kinds of IRExprs. ---*/ |
| 2663 | /*------------------------------------------------------------*/ |
| 2664 | |
| 2665 | static |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 2666 | IRAtom* expr2vbits_Qop ( MCEnv* mce, |
| 2667 | IROp op, |
| 2668 | IRAtom* atom1, IRAtom* atom2, |
| 2669 | IRAtom* atom3, IRAtom* atom4 ) |
| 2670 | { |
| 2671 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2672 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2673 | IRAtom* vatom3 = expr2vbits( mce, atom3 ); |
| 2674 | IRAtom* vatom4 = expr2vbits( mce, atom4 ); |
| 2675 | |
| 2676 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2677 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2678 | tl_assert(isOriginalAtom(mce,atom3)); |
| 2679 | tl_assert(isOriginalAtom(mce,atom4)); |
| 2680 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2681 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2682 | tl_assert(isShadowAtom(mce,vatom3)); |
| 2683 | tl_assert(isShadowAtom(mce,vatom4)); |
| 2684 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2685 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2686 | tl_assert(sameKindedAtoms(atom3,vatom3)); |
| 2687 | tl_assert(sameKindedAtoms(atom4,vatom4)); |
| 2688 | switch (op) { |
| 2689 | case Iop_MAddF64: |
| 2690 | case Iop_MAddF64r32: |
| 2691 | case Iop_MSubF64: |
| 2692 | case Iop_MSubF64r32: |
| 2693 | /* I32(rm) x F64 x F64 x F64 -> F64 */ |
| 2694 | return mkLazy4(mce, Ity_I64, vatom1, vatom2, vatom3, vatom4); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2695 | |
| 2696 | case Iop_MAddF32: |
| 2697 | case Iop_MSubF32: |
| 2698 | /* I32(rm) x F32 x F32 x F32 -> F32 */ |
| 2699 | return mkLazy4(mce, Ity_I32, vatom1, vatom2, vatom3, vatom4); |
| 2700 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 2701 | /* V256-bit data-steering */ |
| 2702 | case Iop_64x4toV256: |
| 2703 | return assignNew('V', mce, Ity_V256, |
| 2704 | IRExpr_Qop(op, vatom1, vatom2, vatom3, vatom4)); |
| 2705 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 2706 | default: |
| 2707 | ppIROp(op); |
| 2708 | VG_(tool_panic)("memcheck:expr2vbits_Qop"); |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | |
| 2713 | static |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2714 | IRAtom* expr2vbits_Triop ( MCEnv* mce, |
| 2715 | IROp op, |
| 2716 | IRAtom* atom1, IRAtom* atom2, IRAtom* atom3 ) |
| 2717 | { |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2718 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2719 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2720 | IRAtom* vatom3 = expr2vbits( mce, atom3 ); |
| 2721 | |
| 2722 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2723 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2724 | tl_assert(isOriginalAtom(mce,atom3)); |
| 2725 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2726 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2727 | tl_assert(isShadowAtom(mce,vatom3)); |
| 2728 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2729 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2730 | tl_assert(sameKindedAtoms(atom3,vatom3)); |
| 2731 | switch (op) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2732 | case Iop_AddF128: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2733 | case Iop_AddD128: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2734 | case Iop_SubF128: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2735 | case Iop_SubD128: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2736 | case Iop_MulF128: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2737 | case Iop_MulD128: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2738 | case Iop_DivF128: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2739 | case Iop_DivD128: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 2740 | case Iop_QuantizeD128: |
| 2741 | /* I32(rm) x F128/D128 x F128/D128 -> F128/D128 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2742 | return mkLazy3(mce, Ity_I128, vatom1, vatom2, vatom3); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2743 | case Iop_AddF64: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2744 | case Iop_AddD64: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2745 | case Iop_AddF64r32: |
| 2746 | case Iop_SubF64: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2747 | case Iop_SubD64: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2748 | case Iop_SubF64r32: |
| 2749 | case Iop_MulF64: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2750 | case Iop_MulD64: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2751 | case Iop_MulF64r32: |
| 2752 | case Iop_DivF64: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 2753 | case Iop_DivD64: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2754 | case Iop_DivF64r32: |
sewardj | 22ac5f4 | 2006-02-03 22:55:04 +0000 | [diff] [blame] | 2755 | case Iop_ScaleF64: |
| 2756 | case Iop_Yl2xF64: |
| 2757 | case Iop_Yl2xp1F64: |
| 2758 | case Iop_AtanF64: |
sewardj | d6075eb | 2006-02-04 15:25:23 +0000 | [diff] [blame] | 2759 | case Iop_PRemF64: |
| 2760 | case Iop_PRem1F64: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 2761 | case Iop_QuantizeD64: |
| 2762 | /* I32(rm) x F64/D64 x F64/D64 -> F64/D64 */ |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2763 | return mkLazy3(mce, Ity_I64, vatom1, vatom2, vatom3); |
sewardj | d6075eb | 2006-02-04 15:25:23 +0000 | [diff] [blame] | 2764 | case Iop_PRemC3210F64: |
| 2765 | case Iop_PRem1C3210F64: |
| 2766 | /* I32(rm) x F64 x F64 -> I32 */ |
| 2767 | return mkLazy3(mce, Ity_I32, vatom1, vatom2, vatom3); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2768 | case Iop_AddF32: |
| 2769 | case Iop_SubF32: |
| 2770 | case Iop_MulF32: |
| 2771 | case Iop_DivF32: |
| 2772 | /* I32(rm) x F32 x F32 -> I32 */ |
| 2773 | return mkLazy3(mce, Ity_I32, vatom1, vatom2, vatom3); |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 2774 | case Iop_SignificanceRoundD64: |
florian | 733b4db | 2013-06-06 19:13:29 +0000 | [diff] [blame] | 2775 | /* IRRoundingMode(I32) x I8 x D64 -> D64 */ |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 2776 | return mkLazy3(mce, Ity_I64, vatom1, vatom2, vatom3); |
| 2777 | case Iop_SignificanceRoundD128: |
florian | 733b4db | 2013-06-06 19:13:29 +0000 | [diff] [blame] | 2778 | /* IRRoundingMode(I32) x I8 x D128 -> D128 */ |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 2779 | return mkLazy3(mce, Ity_I128, vatom1, vatom2, vatom3); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2780 | case Iop_ExtractV128: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2781 | complainIfUndefined(mce, atom3, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2782 | return assignNew('V', mce, Ity_V128, triop(op, vatom1, vatom2, atom3)); |
| 2783 | case Iop_Extract64: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2784 | complainIfUndefined(mce, atom3, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2785 | return assignNew('V', mce, Ity_I64, triop(op, vatom1, vatom2, atom3)); |
| 2786 | case Iop_SetElem8x8: |
| 2787 | case Iop_SetElem16x4: |
| 2788 | case Iop_SetElem32x2: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2789 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2790 | return assignNew('V', mce, Ity_I64, triop(op, vatom1, atom2, vatom3)); |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 2791 | /* BCDIops */ |
| 2792 | case Iop_BCDAdd: |
| 2793 | case Iop_BCDSub: |
| 2794 | complainIfUndefined(mce, atom3, NULL); |
| 2795 | return assignNew('V', mce, Ity_V128, triop(op, vatom1, vatom2, atom3)); |
| 2796 | |
sewardj | 1eb272f | 2014-01-26 18:36:52 +0000 | [diff] [blame] | 2797 | /* Vector FP with rounding mode as the first arg */ |
| 2798 | case Iop_Add64Fx2: |
| 2799 | case Iop_Sub64Fx2: |
| 2800 | case Iop_Mul64Fx2: |
| 2801 | case Iop_Div64Fx2: |
| 2802 | return binary64Fx2_w_rm(mce, vatom1, vatom2, vatom3); |
| 2803 | |
| 2804 | case Iop_Add32Fx4: |
| 2805 | case Iop_Sub32Fx4: |
| 2806 | case Iop_Mul32Fx4: |
| 2807 | case Iop_Div32Fx4: |
| 2808 | return binary32Fx4_w_rm(mce, vatom1, vatom2, vatom3); |
| 2809 | |
| 2810 | case Iop_Add64Fx4: |
| 2811 | case Iop_Sub64Fx4: |
| 2812 | case Iop_Mul64Fx4: |
| 2813 | case Iop_Div64Fx4: |
| 2814 | return binary64Fx4_w_rm(mce, vatom1, vatom2, vatom3); |
| 2815 | |
| 2816 | case Iop_Add32Fx8: |
| 2817 | case Iop_Sub32Fx8: |
| 2818 | case Iop_Mul32Fx8: |
| 2819 | case Iop_Div32Fx8: |
| 2820 | return binary32Fx8_w_rm(mce, vatom1, vatom2, vatom3); |
| 2821 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2822 | default: |
| 2823 | ppIROp(op); |
| 2824 | VG_(tool_panic)("memcheck:expr2vbits_Triop"); |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | |
| 2829 | static |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2830 | IRAtom* expr2vbits_Binop ( MCEnv* mce, |
| 2831 | IROp op, |
| 2832 | IRAtom* atom1, IRAtom* atom2 ) |
| 2833 | { |
| 2834 | IRType and_or_ty; |
| 2835 | IRAtom* (*uifu) (MCEnv*, IRAtom*, IRAtom*); |
| 2836 | IRAtom* (*difd) (MCEnv*, IRAtom*, IRAtom*); |
| 2837 | IRAtom* (*improve) (MCEnv*, IRAtom*, IRAtom*); |
| 2838 | |
| 2839 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2840 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2841 | |
| 2842 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2843 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2844 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2845 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2846 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2847 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2848 | switch (op) { |
| 2849 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2850 | /* 32-bit SIMD */ |
| 2851 | |
| 2852 | case Iop_Add16x2: |
| 2853 | case Iop_HAdd16Ux2: |
| 2854 | case Iop_HAdd16Sx2: |
| 2855 | case Iop_Sub16x2: |
| 2856 | case Iop_HSub16Ux2: |
| 2857 | case Iop_HSub16Sx2: |
| 2858 | case Iop_QAdd16Sx2: |
| 2859 | case Iop_QSub16Sx2: |
sewardj | 9fb3109 | 2012-09-17 15:28:46 +0000 | [diff] [blame] | 2860 | case Iop_QSub16Ux2: |
sewardj | 7a37065 | 2013-07-04 20:37:33 +0000 | [diff] [blame] | 2861 | case Iop_QAdd16Ux2: |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2862 | return binary16Ix2(mce, vatom1, vatom2); |
| 2863 | |
| 2864 | case Iop_Add8x4: |
| 2865 | case Iop_HAdd8Ux4: |
| 2866 | case Iop_HAdd8Sx4: |
| 2867 | case Iop_Sub8x4: |
| 2868 | case Iop_HSub8Ux4: |
| 2869 | case Iop_HSub8Sx4: |
| 2870 | case Iop_QSub8Ux4: |
| 2871 | case Iop_QAdd8Ux4: |
| 2872 | case Iop_QSub8Sx4: |
| 2873 | case Iop_QAdd8Sx4: |
| 2874 | return binary8Ix4(mce, vatom1, vatom2); |
| 2875 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2876 | /* 64-bit SIMD */ |
| 2877 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2878 | case Iop_ShrN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2879 | case Iop_ShrN16x4: |
| 2880 | case Iop_ShrN32x2: |
sewardj | 03809ae | 2006-12-27 01:16:58 +0000 | [diff] [blame] | 2881 | case Iop_SarN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2882 | case Iop_SarN16x4: |
| 2883 | case Iop_SarN32x2: |
| 2884 | case Iop_ShlN16x4: |
| 2885 | case Iop_ShlN32x2: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2886 | case Iop_ShlN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2887 | /* Same scheme as with all other shifts. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2888 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2889 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2890 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2891 | case Iop_QNarrowBin32Sto16Sx4: |
| 2892 | case Iop_QNarrowBin16Sto8Sx8: |
| 2893 | case Iop_QNarrowBin16Sto8Ux8: |
| 2894 | return vectorNarrowBin64(mce, op, vatom1, vatom2); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2895 | |
| 2896 | case Iop_Min8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2897 | case Iop_Min8Sx8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2898 | case Iop_Max8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2899 | case Iop_Max8Sx8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2900 | case Iop_Avg8Ux8: |
| 2901 | case Iop_QSub8Sx8: |
| 2902 | case Iop_QSub8Ux8: |
| 2903 | case Iop_Sub8x8: |
| 2904 | case Iop_CmpGT8Sx8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2905 | case Iop_CmpGT8Ux8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2906 | case Iop_CmpEQ8x8: |
| 2907 | case Iop_QAdd8Sx8: |
| 2908 | case Iop_QAdd8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2909 | case Iop_QSal8x8: |
| 2910 | case Iop_QShl8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2911 | case Iop_Add8x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2912 | case Iop_Mul8x8: |
| 2913 | case Iop_PolynomialMul8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2914 | return binary8Ix8(mce, vatom1, vatom2); |
| 2915 | |
| 2916 | case Iop_Min16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2917 | case Iop_Min16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2918 | case Iop_Max16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2919 | case Iop_Max16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2920 | case Iop_Avg16Ux4: |
| 2921 | case Iop_QSub16Ux4: |
| 2922 | case Iop_QSub16Sx4: |
| 2923 | case Iop_Sub16x4: |
| 2924 | case Iop_Mul16x4: |
| 2925 | case Iop_MulHi16Sx4: |
| 2926 | case Iop_MulHi16Ux4: |
| 2927 | case Iop_CmpGT16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2928 | case Iop_CmpGT16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2929 | case Iop_CmpEQ16x4: |
| 2930 | case Iop_QAdd16Sx4: |
| 2931 | case Iop_QAdd16Ux4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2932 | case Iop_QSal16x4: |
| 2933 | case Iop_QShl16x4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2934 | case Iop_Add16x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2935 | case Iop_QDMulHi16Sx4: |
| 2936 | case Iop_QRDMulHi16Sx4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2937 | return binary16Ix4(mce, vatom1, vatom2); |
| 2938 | |
| 2939 | case Iop_Sub32x2: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2940 | case Iop_Mul32x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2941 | case Iop_Max32Sx2: |
| 2942 | case Iop_Max32Ux2: |
| 2943 | case Iop_Min32Sx2: |
| 2944 | case Iop_Min32Ux2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2945 | case Iop_CmpGT32Sx2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2946 | case Iop_CmpGT32Ux2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2947 | case Iop_CmpEQ32x2: |
| 2948 | case Iop_Add32x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2949 | case Iop_QAdd32Ux2: |
| 2950 | case Iop_QAdd32Sx2: |
| 2951 | case Iop_QSub32Ux2: |
| 2952 | case Iop_QSub32Sx2: |
| 2953 | case Iop_QSal32x2: |
| 2954 | case Iop_QShl32x2: |
| 2955 | case Iop_QDMulHi32Sx2: |
| 2956 | case Iop_QRDMulHi32Sx2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2957 | return binary32Ix2(mce, vatom1, vatom2); |
| 2958 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2959 | case Iop_QSub64Ux1: |
| 2960 | case Iop_QSub64Sx1: |
| 2961 | case Iop_QAdd64Ux1: |
| 2962 | case Iop_QAdd64Sx1: |
| 2963 | case Iop_QSal64x1: |
| 2964 | case Iop_QShl64x1: |
| 2965 | case Iop_Sal64x1: |
| 2966 | return binary64Ix1(mce, vatom1, vatom2); |
| 2967 | |
| 2968 | case Iop_QShlN8Sx8: |
| 2969 | case Iop_QShlN8x8: |
| 2970 | case Iop_QSalN8x8: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2971 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2972 | return mkPCast8x8(mce, vatom1); |
| 2973 | |
| 2974 | case Iop_QShlN16Sx4: |
| 2975 | case Iop_QShlN16x4: |
| 2976 | case Iop_QSalN16x4: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2977 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2978 | return mkPCast16x4(mce, vatom1); |
| 2979 | |
| 2980 | case Iop_QShlN32Sx2: |
| 2981 | case Iop_QShlN32x2: |
| 2982 | case Iop_QSalN32x2: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2983 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2984 | return mkPCast32x2(mce, vatom1); |
| 2985 | |
| 2986 | case Iop_QShlN64Sx1: |
| 2987 | case Iop_QShlN64x1: |
| 2988 | case Iop_QSalN64x1: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 2989 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2990 | return mkPCast32x2(mce, vatom1); |
| 2991 | |
| 2992 | case Iop_PwMax32Sx2: |
| 2993 | case Iop_PwMax32Ux2: |
| 2994 | case Iop_PwMin32Sx2: |
| 2995 | case Iop_PwMin32Ux2: |
| 2996 | case Iop_PwMax32Fx2: |
| 2997 | case Iop_PwMin32Fx2: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 2998 | return assignNew('V', mce, Ity_I64, |
| 2999 | binop(Iop_PwMax32Ux2, |
| 3000 | mkPCast32x2(mce, vatom1), |
| 3001 | mkPCast32x2(mce, vatom2))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3002 | |
| 3003 | case Iop_PwMax16Sx4: |
| 3004 | case Iop_PwMax16Ux4: |
| 3005 | case Iop_PwMin16Sx4: |
| 3006 | case Iop_PwMin16Ux4: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3007 | return assignNew('V', mce, Ity_I64, |
| 3008 | binop(Iop_PwMax16Ux4, |
| 3009 | mkPCast16x4(mce, vatom1), |
| 3010 | mkPCast16x4(mce, vatom2))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3011 | |
| 3012 | case Iop_PwMax8Sx8: |
| 3013 | case Iop_PwMax8Ux8: |
| 3014 | case Iop_PwMin8Sx8: |
| 3015 | case Iop_PwMin8Ux8: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3016 | return assignNew('V', mce, Ity_I64, |
| 3017 | binop(Iop_PwMax8Ux8, |
| 3018 | mkPCast8x8(mce, vatom1), |
| 3019 | mkPCast8x8(mce, vatom2))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3020 | |
| 3021 | case Iop_PwAdd32x2: |
| 3022 | case Iop_PwAdd32Fx2: |
| 3023 | return mkPCast32x2(mce, |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3024 | assignNew('V', mce, Ity_I64, |
| 3025 | binop(Iop_PwAdd32x2, |
| 3026 | mkPCast32x2(mce, vatom1), |
| 3027 | mkPCast32x2(mce, vatom2)))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3028 | |
| 3029 | case Iop_PwAdd16x4: |
| 3030 | return mkPCast16x4(mce, |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3031 | assignNew('V', mce, Ity_I64, |
| 3032 | binop(op, mkPCast16x4(mce, vatom1), |
| 3033 | mkPCast16x4(mce, vatom2)))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3034 | |
| 3035 | case Iop_PwAdd8x8: |
| 3036 | return mkPCast8x8(mce, |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3037 | assignNew('V', mce, Ity_I64, |
| 3038 | binop(op, mkPCast8x8(mce, vatom1), |
| 3039 | mkPCast8x8(mce, vatom2)))); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3040 | |
| 3041 | case Iop_Shl8x8: |
| 3042 | case Iop_Shr8x8: |
| 3043 | case Iop_Sar8x8: |
| 3044 | case Iop_Sal8x8: |
| 3045 | return mkUifU64(mce, |
| 3046 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 3047 | mkPCast8x8(mce,vatom2) |
| 3048 | ); |
| 3049 | |
| 3050 | case Iop_Shl16x4: |
| 3051 | case Iop_Shr16x4: |
| 3052 | case Iop_Sar16x4: |
| 3053 | case Iop_Sal16x4: |
| 3054 | return mkUifU64(mce, |
| 3055 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 3056 | mkPCast16x4(mce,vatom2) |
| 3057 | ); |
| 3058 | |
| 3059 | case Iop_Shl32x2: |
| 3060 | case Iop_Shr32x2: |
| 3061 | case Iop_Sar32x2: |
| 3062 | case Iop_Sal32x2: |
| 3063 | return mkUifU64(mce, |
| 3064 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 3065 | mkPCast32x2(mce,vatom2) |
| 3066 | ); |
| 3067 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 3068 | /* 64-bit data-steering */ |
| 3069 | case Iop_InterleaveLO32x2: |
| 3070 | case Iop_InterleaveLO16x4: |
| 3071 | case Iop_InterleaveLO8x8: |
| 3072 | case Iop_InterleaveHI32x2: |
| 3073 | case Iop_InterleaveHI16x4: |
| 3074 | case Iop_InterleaveHI8x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3075 | case Iop_CatOddLanes8x8: |
| 3076 | case Iop_CatEvenLanes8x8: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 3077 | case Iop_CatOddLanes16x4: |
| 3078 | case Iop_CatEvenLanes16x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3079 | case Iop_InterleaveOddLanes8x8: |
| 3080 | case Iop_InterleaveEvenLanes8x8: |
| 3081 | case Iop_InterleaveOddLanes16x4: |
| 3082 | case Iop_InterleaveEvenLanes16x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3083 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, vatom2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 3084 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3085 | case Iop_GetElem8x8: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3086 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3087 | return assignNew('V', mce, Ity_I8, binop(op, vatom1, atom2)); |
| 3088 | case Iop_GetElem16x4: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3089 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3090 | return assignNew('V', mce, Ity_I16, binop(op, vatom1, atom2)); |
| 3091 | case Iop_GetElem32x2: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3092 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3093 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, atom2)); |
| 3094 | |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 3095 | /* Perm8x8: rearrange values in left arg using steering values |
| 3096 | from right arg. So rearrange the vbits in the same way but |
| 3097 | pessimise wrt steering values. */ |
| 3098 | case Iop_Perm8x8: |
| 3099 | return mkUifU64( |
| 3100 | mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3101 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 3102 | mkPCast8x8(mce, vatom2) |
| 3103 | ); |
| 3104 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3105 | /* V128-bit SIMD */ |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3106 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3107 | case Iop_ShrN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3108 | case Iop_ShrN16x8: |
| 3109 | case Iop_ShrN32x4: |
| 3110 | case Iop_ShrN64x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3111 | case Iop_SarN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3112 | case Iop_SarN16x8: |
| 3113 | case Iop_SarN32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3114 | case Iop_SarN64x2: |
| 3115 | case Iop_ShlN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3116 | case Iop_ShlN16x8: |
| 3117 | case Iop_ShlN32x4: |
| 3118 | case Iop_ShlN64x2: |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 3119 | /* Same scheme as with all other shifts. Note: 22 Oct 05: |
| 3120 | this is wrong now, scalar shifts are done properly lazily. |
| 3121 | Vector shifts should be fixed too. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3122 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3123 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3124 | |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 3125 | /* V x V shifts/rotates are done using the standard lazy scheme. */ |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3126 | case Iop_Shl8x16: |
| 3127 | case Iop_Shr8x16: |
| 3128 | case Iop_Sar8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3129 | case Iop_Sal8x16: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 3130 | case Iop_Rol8x16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3131 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3132 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3133 | mkPCast8x16(mce,vatom2) |
| 3134 | ); |
| 3135 | |
| 3136 | case Iop_Shl16x8: |
| 3137 | case Iop_Shr16x8: |
| 3138 | case Iop_Sar16x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3139 | case Iop_Sal16x8: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 3140 | case Iop_Rol16x8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3141 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3142 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3143 | mkPCast16x8(mce,vatom2) |
| 3144 | ); |
| 3145 | |
| 3146 | case Iop_Shl32x4: |
| 3147 | case Iop_Shr32x4: |
| 3148 | case Iop_Sar32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3149 | case Iop_Sal32x4: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 3150 | case Iop_Rol32x4: |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 3151 | case Iop_Rol64x2: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3152 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3153 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3154 | mkPCast32x4(mce,vatom2) |
| 3155 | ); |
| 3156 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3157 | case Iop_Shl64x2: |
| 3158 | case Iop_Shr64x2: |
| 3159 | case Iop_Sar64x2: |
| 3160 | case Iop_Sal64x2: |
| 3161 | return mkUifUV128(mce, |
| 3162 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
| 3163 | mkPCast64x2(mce,vatom2) |
| 3164 | ); |
| 3165 | |
| 3166 | case Iop_F32ToFixed32Ux4_RZ: |
| 3167 | case Iop_F32ToFixed32Sx4_RZ: |
| 3168 | case Iop_Fixed32UToF32x4_RN: |
| 3169 | case Iop_Fixed32SToF32x4_RN: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3170 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3171 | return mkPCast32x4(mce, vatom1); |
| 3172 | |
| 3173 | case Iop_F32ToFixed32Ux2_RZ: |
| 3174 | case Iop_F32ToFixed32Sx2_RZ: |
| 3175 | case Iop_Fixed32UToF32x2_RN: |
| 3176 | case Iop_Fixed32SToF32x2_RN: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3177 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3178 | return mkPCast32x2(mce, vatom1); |
| 3179 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3180 | case Iop_QSub8Ux16: |
| 3181 | case Iop_QSub8Sx16: |
| 3182 | case Iop_Sub8x16: |
| 3183 | case Iop_Min8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3184 | case Iop_Min8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3185 | case Iop_Max8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3186 | case Iop_Max8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3187 | case Iop_CmpGT8Sx16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3188 | case Iop_CmpGT8Ux16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3189 | case Iop_CmpEQ8x16: |
| 3190 | case Iop_Avg8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3191 | case Iop_Avg8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3192 | case Iop_QAdd8Ux16: |
| 3193 | case Iop_QAdd8Sx16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3194 | case Iop_QSal8x16: |
| 3195 | case Iop_QShl8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3196 | case Iop_Add8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3197 | case Iop_Mul8x16: |
| 3198 | case Iop_PolynomialMul8x16: |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 3199 | case Iop_PolynomialMulAdd8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3200 | return binary8Ix16(mce, vatom1, vatom2); |
| 3201 | |
| 3202 | case Iop_QSub16Ux8: |
| 3203 | case Iop_QSub16Sx8: |
| 3204 | case Iop_Sub16x8: |
| 3205 | case Iop_Mul16x8: |
| 3206 | case Iop_MulHi16Sx8: |
| 3207 | case Iop_MulHi16Ux8: |
| 3208 | case Iop_Min16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3209 | case Iop_Min16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3210 | case Iop_Max16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3211 | case Iop_Max16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3212 | case Iop_CmpGT16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3213 | case Iop_CmpGT16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3214 | case Iop_CmpEQ16x8: |
| 3215 | case Iop_Avg16Ux8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3216 | case Iop_Avg16Sx8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3217 | case Iop_QAdd16Ux8: |
| 3218 | case Iop_QAdd16Sx8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3219 | case Iop_QSal16x8: |
| 3220 | case Iop_QShl16x8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3221 | case Iop_Add16x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3222 | case Iop_QDMulHi16Sx8: |
| 3223 | case Iop_QRDMulHi16Sx8: |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 3224 | case Iop_PolynomialMulAdd16x8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3225 | return binary16Ix8(mce, vatom1, vatom2); |
| 3226 | |
| 3227 | case Iop_Sub32x4: |
| 3228 | case Iop_CmpGT32Sx4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3229 | case Iop_CmpGT32Ux4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3230 | case Iop_CmpEQ32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3231 | case Iop_QAdd32Sx4: |
| 3232 | case Iop_QAdd32Ux4: |
| 3233 | case Iop_QSub32Sx4: |
| 3234 | case Iop_QSub32Ux4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3235 | case Iop_QSal32x4: |
| 3236 | case Iop_QShl32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3237 | case Iop_Avg32Ux4: |
| 3238 | case Iop_Avg32Sx4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3239 | case Iop_Add32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3240 | case Iop_Max32Ux4: |
| 3241 | case Iop_Max32Sx4: |
| 3242 | case Iop_Min32Ux4: |
| 3243 | case Iop_Min32Sx4: |
sewardj | b823b85 | 2010-06-18 08:18:38 +0000 | [diff] [blame] | 3244 | case Iop_Mul32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3245 | case Iop_QDMulHi32Sx4: |
| 3246 | case Iop_QRDMulHi32Sx4: |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 3247 | case Iop_PolynomialMulAdd32x4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3248 | return binary32Ix4(mce, vatom1, vatom2); |
| 3249 | |
| 3250 | case Iop_Sub64x2: |
| 3251 | case Iop_Add64x2: |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 3252 | case Iop_Max64Sx2: |
| 3253 | case Iop_Max64Ux2: |
| 3254 | case Iop_Min64Sx2: |
| 3255 | case Iop_Min64Ux2: |
sewardj | 9a2afe9 | 2011-10-19 15:24:55 +0000 | [diff] [blame] | 3256 | case Iop_CmpEQ64x2: |
sewardj | b823b85 | 2010-06-18 08:18:38 +0000 | [diff] [blame] | 3257 | case Iop_CmpGT64Sx2: |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 3258 | case Iop_CmpGT64Ux2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3259 | case Iop_QSal64x2: |
| 3260 | case Iop_QShl64x2: |
| 3261 | case Iop_QAdd64Ux2: |
| 3262 | case Iop_QAdd64Sx2: |
| 3263 | case Iop_QSub64Ux2: |
| 3264 | case Iop_QSub64Sx2: |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 3265 | case Iop_PolynomialMulAdd64x2: |
| 3266 | case Iop_CipherV128: |
| 3267 | case Iop_CipherLV128: |
| 3268 | case Iop_NCipherV128: |
| 3269 | case Iop_NCipherLV128: |
| 3270 | return binary64Ix2(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3271 | |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 3272 | case Iop_QNarrowBin64Sto32Sx4: |
| 3273 | case Iop_QNarrowBin64Uto32Ux4: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3274 | case Iop_QNarrowBin32Sto16Sx8: |
| 3275 | case Iop_QNarrowBin32Uto16Ux8: |
| 3276 | case Iop_QNarrowBin32Sto16Ux8: |
| 3277 | case Iop_QNarrowBin16Sto8Sx16: |
| 3278 | case Iop_QNarrowBin16Uto8Ux16: |
| 3279 | case Iop_QNarrowBin16Sto8Ux16: |
| 3280 | return vectorNarrowBinV128(mce, op, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3281 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3282 | case Iop_Min64Fx2: |
| 3283 | case Iop_Max64Fx2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3284 | case Iop_CmpLT64Fx2: |
| 3285 | case Iop_CmpLE64Fx2: |
| 3286 | case Iop_CmpEQ64Fx2: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 3287 | case Iop_CmpUN64Fx2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3288 | return binary64Fx2(mce, vatom1, vatom2); |
| 3289 | |
| 3290 | case Iop_Sub64F0x2: |
| 3291 | case Iop_Mul64F0x2: |
| 3292 | case Iop_Min64F0x2: |
| 3293 | case Iop_Max64F0x2: |
| 3294 | case Iop_Div64F0x2: |
| 3295 | case Iop_CmpLT64F0x2: |
| 3296 | case Iop_CmpLE64F0x2: |
| 3297 | case Iop_CmpEQ64F0x2: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 3298 | case Iop_CmpUN64F0x2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3299 | case Iop_Add64F0x2: |
| 3300 | return binary64F0x2(mce, vatom1, vatom2); |
| 3301 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3302 | case Iop_Min32Fx4: |
| 3303 | case Iop_Max32Fx4: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3304 | case Iop_CmpLT32Fx4: |
| 3305 | case Iop_CmpLE32Fx4: |
| 3306 | case Iop_CmpEQ32Fx4: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 3307 | case Iop_CmpUN32Fx4: |
cerion | e78ba2a | 2005-11-14 03:00:35 +0000 | [diff] [blame] | 3308 | case Iop_CmpGT32Fx4: |
| 3309 | case Iop_CmpGE32Fx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3310 | case Iop_Recps32Fx4: |
| 3311 | case Iop_Rsqrts32Fx4: |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 3312 | return binary32Fx4(mce, vatom1, vatom2); |
| 3313 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3314 | case Iop_Sub32Fx2: |
| 3315 | case Iop_Mul32Fx2: |
| 3316 | case Iop_Min32Fx2: |
| 3317 | case Iop_Max32Fx2: |
| 3318 | case Iop_CmpEQ32Fx2: |
| 3319 | case Iop_CmpGT32Fx2: |
| 3320 | case Iop_CmpGE32Fx2: |
| 3321 | case Iop_Add32Fx2: |
| 3322 | case Iop_Recps32Fx2: |
| 3323 | case Iop_Rsqrts32Fx2: |
| 3324 | return binary32Fx2(mce, vatom1, vatom2); |
| 3325 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3326 | case Iop_Sub32F0x4: |
| 3327 | case Iop_Mul32F0x4: |
| 3328 | case Iop_Min32F0x4: |
| 3329 | case Iop_Max32F0x4: |
| 3330 | case Iop_Div32F0x4: |
| 3331 | case Iop_CmpLT32F0x4: |
| 3332 | case Iop_CmpLE32F0x4: |
| 3333 | case Iop_CmpEQ32F0x4: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 3334 | case Iop_CmpUN32F0x4: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3335 | case Iop_Add32F0x4: |
| 3336 | return binary32F0x4(mce, vatom1, vatom2); |
| 3337 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3338 | case Iop_QShlN8Sx16: |
| 3339 | case Iop_QShlN8x16: |
| 3340 | case Iop_QSalN8x16: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3341 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3342 | return mkPCast8x16(mce, vatom1); |
| 3343 | |
| 3344 | case Iop_QShlN16Sx8: |
| 3345 | case Iop_QShlN16x8: |
| 3346 | case Iop_QSalN16x8: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3347 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3348 | return mkPCast16x8(mce, vatom1); |
| 3349 | |
| 3350 | case Iop_QShlN32Sx4: |
| 3351 | case Iop_QShlN32x4: |
| 3352 | case Iop_QSalN32x4: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3353 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3354 | return mkPCast32x4(mce, vatom1); |
| 3355 | |
| 3356 | case Iop_QShlN64Sx2: |
| 3357 | case Iop_QShlN64x2: |
| 3358 | case Iop_QSalN64x2: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3359 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3360 | return mkPCast32x4(mce, vatom1); |
| 3361 | |
| 3362 | case Iop_Mull32Sx2: |
| 3363 | case Iop_Mull32Ux2: |
| 3364 | case Iop_QDMulLong32Sx2: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3365 | return vectorWidenI64(mce, Iop_Widen32Sto64x2, |
| 3366 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3367 | |
| 3368 | case Iop_Mull16Sx4: |
| 3369 | case Iop_Mull16Ux4: |
| 3370 | case Iop_QDMulLong16Sx4: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3371 | return vectorWidenI64(mce, Iop_Widen16Sto32x4, |
| 3372 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3373 | |
| 3374 | case Iop_Mull8Sx8: |
| 3375 | case Iop_Mull8Ux8: |
| 3376 | case Iop_PolynomialMull8x8: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3377 | return vectorWidenI64(mce, Iop_Widen8Sto16x8, |
| 3378 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3379 | |
| 3380 | case Iop_PwAdd32x4: |
| 3381 | return mkPCast32x4(mce, |
| 3382 | assignNew('V', mce, Ity_V128, binop(op, mkPCast32x4(mce, vatom1), |
| 3383 | mkPCast32x4(mce, vatom2)))); |
| 3384 | |
| 3385 | case Iop_PwAdd16x8: |
| 3386 | return mkPCast16x8(mce, |
| 3387 | assignNew('V', mce, Ity_V128, binop(op, mkPCast16x8(mce, vatom1), |
| 3388 | mkPCast16x8(mce, vatom2)))); |
| 3389 | |
| 3390 | case Iop_PwAdd8x16: |
| 3391 | return mkPCast8x16(mce, |
| 3392 | assignNew('V', mce, Ity_V128, binop(op, mkPCast8x16(mce, vatom1), |
| 3393 | mkPCast8x16(mce, vatom2)))); |
| 3394 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3395 | /* V128-bit data-steering */ |
| 3396 | case Iop_SetV128lo32: |
| 3397 | case Iop_SetV128lo64: |
| 3398 | case Iop_64HLtoV128: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 3399 | case Iop_InterleaveLO64x2: |
| 3400 | case Iop_InterleaveLO32x4: |
| 3401 | case Iop_InterleaveLO16x8: |
| 3402 | case Iop_InterleaveLO8x16: |
| 3403 | case Iop_InterleaveHI64x2: |
| 3404 | case Iop_InterleaveHI32x4: |
| 3405 | case Iop_InterleaveHI16x8: |
| 3406 | case Iop_InterleaveHI8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3407 | case Iop_CatOddLanes8x16: |
| 3408 | case Iop_CatOddLanes16x8: |
| 3409 | case Iop_CatOddLanes32x4: |
| 3410 | case Iop_CatEvenLanes8x16: |
| 3411 | case Iop_CatEvenLanes16x8: |
| 3412 | case Iop_CatEvenLanes32x4: |
| 3413 | case Iop_InterleaveOddLanes8x16: |
| 3414 | case Iop_InterleaveOddLanes16x8: |
| 3415 | case Iop_InterleaveOddLanes32x4: |
| 3416 | case Iop_InterleaveEvenLanes8x16: |
| 3417 | case Iop_InterleaveEvenLanes16x8: |
| 3418 | case Iop_InterleaveEvenLanes32x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3419 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3420 | |
| 3421 | case Iop_GetElem8x16: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3422 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3423 | return assignNew('V', mce, Ity_I8, binop(op, vatom1, atom2)); |
| 3424 | case Iop_GetElem16x8: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3425 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3426 | return assignNew('V', mce, Ity_I16, binop(op, vatom1, atom2)); |
| 3427 | case Iop_GetElem32x4: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3428 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3429 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, atom2)); |
| 3430 | case Iop_GetElem64x2: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3431 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3432 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)); |
| 3433 | |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 3434 | /* Perm8x16: rearrange values in left arg using steering values |
| 3435 | from right arg. So rearrange the vbits in the same way but |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3436 | pessimise wrt steering values. Perm32x4 ditto. */ |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 3437 | case Iop_Perm8x16: |
| 3438 | return mkUifUV128( |
| 3439 | mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3440 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 3441 | mkPCast8x16(mce, vatom2) |
| 3442 | ); |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3443 | case Iop_Perm32x4: |
| 3444 | return mkUifUV128( |
| 3445 | mce, |
| 3446 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
| 3447 | mkPCast32x4(mce, vatom2) |
| 3448 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3449 | |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3450 | /* These two take the lower half of each 16-bit lane, sign/zero |
| 3451 | extend it to 32, and multiply together, producing a 32x4 |
| 3452 | result (and implicitly ignoring half the operand bits). So |
| 3453 | treat it as a bunch of independent 16x8 operations, but then |
| 3454 | do 32-bit shifts left-right to copy the lower half results |
| 3455 | (which are all 0s or all 1s due to PCasting in binary16Ix8) |
| 3456 | into the upper half of each result lane. */ |
| 3457 | case Iop_MullEven16Ux8: |
| 3458 | case Iop_MullEven16Sx8: { |
| 3459 | IRAtom* at; |
| 3460 | at = binary16Ix8(mce,vatom1,vatom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3461 | at = assignNew('V', mce, Ity_V128, binop(Iop_ShlN32x4, at, mkU8(16))); |
| 3462 | at = assignNew('V', mce, Ity_V128, binop(Iop_SarN32x4, at, mkU8(16))); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3463 | return at; |
| 3464 | } |
| 3465 | |
| 3466 | /* Same deal as Iop_MullEven16{S,U}x8 */ |
| 3467 | case Iop_MullEven8Ux16: |
| 3468 | case Iop_MullEven8Sx16: { |
| 3469 | IRAtom* at; |
| 3470 | at = binary8Ix16(mce,vatom1,vatom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3471 | at = assignNew('V', mce, Ity_V128, binop(Iop_ShlN16x8, at, mkU8(8))); |
| 3472 | at = assignNew('V', mce, Ity_V128, binop(Iop_SarN16x8, at, mkU8(8))); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3473 | return at; |
| 3474 | } |
| 3475 | |
carll | 6277067 | 2013-10-01 15:50:09 +0000 | [diff] [blame] | 3476 | /* Same deal as Iop_MullEven16{S,U}x8 */ |
| 3477 | case Iop_MullEven32Ux4: |
| 3478 | case Iop_MullEven32Sx4: { |
| 3479 | IRAtom* at; |
| 3480 | at = binary32Ix4(mce,vatom1,vatom2); |
| 3481 | at = assignNew('V', mce, Ity_V128, binop(Iop_ShlN64x2, at, mkU8(32))); |
| 3482 | at = assignNew('V', mce, Ity_V128, binop(Iop_SarN64x2, at, mkU8(32))); |
| 3483 | return at; |
| 3484 | } |
| 3485 | |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3486 | /* narrow 2xV128 into 1xV128, hi half from left arg, in a 2 x |
| 3487 | 32x4 -> 16x8 laneage, discarding the upper half of each lane. |
| 3488 | Simply apply same op to the V bits, since this really no more |
| 3489 | than a data steering operation. */ |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3490 | case Iop_NarrowBin32to16x8: |
| 3491 | case Iop_NarrowBin16to8x16: |
carll | dfbf294 | 2013-08-12 18:04:22 +0000 | [diff] [blame] | 3492 | case Iop_NarrowBin64to32x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3493 | return assignNew('V', mce, Ity_V128, |
| 3494 | binop(op, vatom1, vatom2)); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3495 | |
| 3496 | case Iop_ShrV128: |
| 3497 | case Iop_ShlV128: |
| 3498 | /* Same scheme as with all other shifts. Note: 10 Nov 05: |
| 3499 | this is wrong now, scalar shifts are done properly lazily. |
| 3500 | Vector shifts should be fixed too. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3501 | complainIfUndefined(mce, atom2, NULL); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3502 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 3503 | |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 3504 | /* SHA Iops */ |
| 3505 | case Iop_SHA256: |
| 3506 | case Iop_SHA512: |
| 3507 | complainIfUndefined(mce, atom2, NULL); |
| 3508 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)); |
| 3509 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3510 | /* I128-bit data-steering */ |
| 3511 | case Iop_64HLto128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3512 | return assignNew('V', mce, Ity_I128, binop(op, vatom1, vatom2)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3513 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3514 | /* V256-bit SIMD */ |
| 3515 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3516 | case Iop_Max64Fx4: |
| 3517 | case Iop_Min64Fx4: |
| 3518 | return binary64Fx4(mce, vatom1, vatom2); |
| 3519 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3520 | case Iop_Max32Fx8: |
| 3521 | case Iop_Min32Fx8: |
| 3522 | return binary32Fx8(mce, vatom1, vatom2); |
| 3523 | |
| 3524 | /* V256-bit data-steering */ |
| 3525 | case Iop_V128HLtoV256: |
| 3526 | return assignNew('V', mce, Ity_V256, binop(op, vatom1, vatom2)); |
| 3527 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 3528 | /* Scalar floating point */ |
| 3529 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3530 | case Iop_F32toI64S: |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 3531 | case Iop_F32toI64U: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3532 | /* I32(rm) x F32 -> I64 */ |
| 3533 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3534 | |
| 3535 | case Iop_I64StoF32: |
| 3536 | /* I32(rm) x I64 -> F32 */ |
| 3537 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3538 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 3539 | case Iop_RoundF64toInt: |
| 3540 | case Iop_RoundF64toF32: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 3541 | case Iop_F64toI64S: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3542 | case Iop_F64toI64U: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 3543 | case Iop_I64StoF64: |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 3544 | case Iop_I64UtoF64: |
sewardj | 22ac5f4 | 2006-02-03 22:55:04 +0000 | [diff] [blame] | 3545 | case Iop_SinF64: |
| 3546 | case Iop_CosF64: |
| 3547 | case Iop_TanF64: |
| 3548 | case Iop_2xm1F64: |
| 3549 | case Iop_SqrtF64: |
| 3550 | /* I32(rm) x I64/F64 -> I64/F64 */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3551 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3552 | |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3553 | case Iop_ShlD64: |
| 3554 | case Iop_ShrD64: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 3555 | case Iop_RoundD64toInt: |
florian | 054684f | 2013-06-06 21:21:46 +0000 | [diff] [blame] | 3556 | /* I32(rm) x D64 -> D64 */ |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3557 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3558 | |
| 3559 | case Iop_ShlD128: |
| 3560 | case Iop_ShrD128: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 3561 | case Iop_RoundD128toInt: |
florian | 054684f | 2013-06-06 21:21:46 +0000 | [diff] [blame] | 3562 | /* I32(rm) x D128 -> D128 */ |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3563 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3564 | |
| 3565 | case Iop_D64toI64S: |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 3566 | case Iop_D64toI64U: |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3567 | case Iop_I64StoD64: |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 3568 | case Iop_I64UtoD64: |
florian | 054684f | 2013-06-06 21:21:46 +0000 | [diff] [blame] | 3569 | /* I32(rm) x I64/D64 -> D64/I64 */ |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3570 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3571 | |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3572 | case Iop_F32toD32: |
| 3573 | case Iop_F64toD32: |
| 3574 | case Iop_F128toD32: |
| 3575 | case Iop_D32toF32: |
| 3576 | case Iop_D64toF32: |
| 3577 | case Iop_D128toF32: |
| 3578 | /* I32(rm) x F32/F64/F128/D32/D64/D128 -> D32/F32 */ |
| 3579 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3580 | |
| 3581 | case Iop_F32toD64: |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3582 | case Iop_F64toD64: |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3583 | case Iop_F128toD64: |
| 3584 | case Iop_D32toF64: |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3585 | case Iop_D64toF64: |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3586 | case Iop_D128toF64: |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3587 | /* I32(rm) x F32/F64/F128/D32/D64/D128 -> D64/F64 */ |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3588 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3589 | |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3590 | case Iop_F32toD128: |
| 3591 | case Iop_F64toD128: |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3592 | case Iop_F128toD128: |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3593 | case Iop_D32toF128: |
| 3594 | case Iop_D64toF128: |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3595 | case Iop_D128toF128: |
florian | ba5693c | 2013-06-17 19:04:24 +0000 | [diff] [blame] | 3596 | /* I32(rm) x F32/F64/F128/D32/D64/D128 -> D128/F128 */ |
florian | 39b08d8 | 2013-05-05 15:05:42 +0000 | [diff] [blame] | 3597 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3598 | |
sewardj | d376a76 | 2010-06-27 09:08:54 +0000 | [diff] [blame] | 3599 | case Iop_RoundF32toInt: |
sewardj | aec1be3 | 2010-01-03 22:29:32 +0000 | [diff] [blame] | 3600 | case Iop_SqrtF32: |
| 3601 | /* I32(rm) x I32/F32 -> I32/F32 */ |
| 3602 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3603 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3604 | case Iop_SqrtF128: |
| 3605 | /* I32(rm) x F128 -> F128 */ |
| 3606 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3607 | |
| 3608 | case Iop_I32StoF32: |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 3609 | case Iop_I32UtoF32: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3610 | case Iop_F32toI32S: |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 3611 | case Iop_F32toI32U: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3612 | /* First arg is I32 (rounding mode), second is F32/I32 (data). */ |
| 3613 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3614 | |
| 3615 | case Iop_F128toI32S: /* IRRoundingMode(I32) x F128 -> signed I32 */ |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 3616 | case Iop_F128toI32U: /* IRRoundingMode(I32) x F128 -> unsigned I32 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3617 | case Iop_F128toF32: /* IRRoundingMode(I32) x F128 -> F32 */ |
florian | 733b4db | 2013-06-06 19:13:29 +0000 | [diff] [blame] | 3618 | case Iop_D128toI32S: /* IRRoundingMode(I32) x D128 -> signed I32 */ |
| 3619 | case Iop_D128toI32U: /* IRRoundingMode(I32) x D128 -> unsigned I32 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3620 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3621 | |
| 3622 | case Iop_F128toI64S: /* IRRoundingMode(I32) x F128 -> signed I64 */ |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 3623 | case Iop_F128toI64U: /* IRRoundingMode(I32) x F128 -> unsigned I64 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3624 | case Iop_F128toF64: /* IRRoundingMode(I32) x F128 -> F64 */ |
florian | 733b4db | 2013-06-06 19:13:29 +0000 | [diff] [blame] | 3625 | case Iop_D128toD64: /* IRRoundingMode(I64) x D128 -> D64 */ |
| 3626 | case Iop_D128toI64S: /* IRRoundingMode(I64) x D128 -> signed I64 */ |
| 3627 | case Iop_D128toI64U: /* IRRoundingMode(I32) x D128 -> unsigned I64 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3628 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3629 | |
| 3630 | case Iop_F64HLtoF128: |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 3631 | case Iop_D64HLtoD128: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3632 | return assignNew('V', mce, Ity_I128, |
| 3633 | binop(Iop_64HLto128, vatom1, vatom2)); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3634 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 3635 | case Iop_F64toI32U: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 3636 | case Iop_F64toI32S: |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 3637 | case Iop_F64toF32: |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 3638 | case Iop_I64UtoF32: |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 3639 | case Iop_D64toI32U: |
| 3640 | case Iop_D64toI32S: |
| 3641 | /* First arg is I32 (rounding mode), second is F64/D64 (data). */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3642 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3643 | |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3644 | case Iop_D64toD32: |
florian | 054684f | 2013-06-06 21:21:46 +0000 | [diff] [blame] | 3645 | /* First arg is I32 (rounding mode), second is D64 (data). */ |
florian | f4bed37 | 2012-12-21 04:25:10 +0000 | [diff] [blame] | 3646 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 3647 | |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 3648 | case Iop_F64toI16S: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3649 | /* First arg is I32 (rounding mode), second is F64 (data). */ |
| 3650 | return mkLazy2(mce, Ity_I16, vatom1, vatom2); |
| 3651 | |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 3652 | case Iop_InsertExpD64: |
| 3653 | /* I64 x I64 -> D64 */ |
| 3654 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3655 | |
| 3656 | case Iop_InsertExpD128: |
| 3657 | /* I64 x I128 -> D128 */ |
| 3658 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3659 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3660 | case Iop_CmpF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3661 | case Iop_CmpF64: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3662 | case Iop_CmpF128: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 3663 | case Iop_CmpD64: |
| 3664 | case Iop_CmpD128: |
florian | 29a36b9 | 2012-12-26 17:48:46 +0000 | [diff] [blame] | 3665 | case Iop_CmpExpD64: |
| 3666 | case Iop_CmpExpD128: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3667 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3668 | |
| 3669 | /* non-FP after here */ |
| 3670 | |
| 3671 | case Iop_DivModU64to32: |
| 3672 | case Iop_DivModS64to32: |
| 3673 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3674 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3675 | case Iop_DivModU128to64: |
| 3676 | case Iop_DivModS128to64: |
| 3677 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3678 | |
florian | 537ed2d | 2012-08-20 16:51:39 +0000 | [diff] [blame] | 3679 | case Iop_8HLto16: |
| 3680 | return assignNew('V', mce, Ity_I16, binop(op, vatom1, vatom2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3681 | case Iop_16HLto32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3682 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, vatom2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3683 | case Iop_32HLto64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3684 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, vatom2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3685 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3686 | case Iop_DivModS64to64: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3687 | case Iop_MullS64: |
| 3688 | case Iop_MullU64: { |
| 3689 | IRAtom* vLo64 = mkLeft64(mce, mkUifU64(mce, vatom1,vatom2)); |
| 3690 | IRAtom* vHi64 = mkPCastTo(mce, Ity_I64, vLo64); |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3691 | return assignNew('V', mce, Ity_I128, |
| 3692 | binop(Iop_64HLto128, vHi64, vLo64)); |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3695 | case Iop_MullS32: |
| 3696 | case Iop_MullU32: { |
| 3697 | IRAtom* vLo32 = mkLeft32(mce, mkUifU32(mce, vatom1,vatom2)); |
| 3698 | IRAtom* vHi32 = mkPCastTo(mce, Ity_I32, vLo32); |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3699 | return assignNew('V', mce, Ity_I64, |
| 3700 | binop(Iop_32HLto64, vHi32, vLo32)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | case Iop_MullS16: |
| 3704 | case Iop_MullU16: { |
| 3705 | IRAtom* vLo16 = mkLeft16(mce, mkUifU16(mce, vatom1,vatom2)); |
| 3706 | IRAtom* vHi16 = mkPCastTo(mce, Ity_I16, vLo16); |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3707 | return assignNew('V', mce, Ity_I32, |
| 3708 | binop(Iop_16HLto32, vHi16, vLo16)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | case Iop_MullS8: |
| 3712 | case Iop_MullU8: { |
| 3713 | IRAtom* vLo8 = mkLeft8(mce, mkUifU8(mce, vatom1,vatom2)); |
| 3714 | IRAtom* vHi8 = mkPCastTo(mce, Ity_I8, vLo8); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3715 | return assignNew('V', mce, Ity_I16, binop(Iop_8HLto16, vHi8, vLo8)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
sewardj | 5af0506 | 2010-10-18 16:31:14 +0000 | [diff] [blame] | 3718 | case Iop_Sad8Ux4: /* maybe we could do better? ftm, do mkLazy2. */ |
cerion | 9e59108 | 2005-06-23 15:28:34 +0000 | [diff] [blame] | 3719 | case Iop_DivS32: |
| 3720 | case Iop_DivU32: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3721 | case Iop_DivU32E: |
sewardj | 169ac04 | 2011-09-05 12:12:34 +0000 | [diff] [blame] | 3722 | case Iop_DivS32E: |
sewardj | 2157b2c | 2012-07-11 13:20:58 +0000 | [diff] [blame] | 3723 | case Iop_QAdd32S: /* could probably do better */ |
| 3724 | case Iop_QSub32S: /* could probably do better */ |
cerion | 9e59108 | 2005-06-23 15:28:34 +0000 | [diff] [blame] | 3725 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3726 | |
sewardj | b00944a | 2005-12-23 12:47:16 +0000 | [diff] [blame] | 3727 | case Iop_DivS64: |
| 3728 | case Iop_DivU64: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3729 | case Iop_DivS64E: |
sewardj | 169ac04 | 2011-09-05 12:12:34 +0000 | [diff] [blame] | 3730 | case Iop_DivU64E: |
sewardj | b00944a | 2005-12-23 12:47:16 +0000 | [diff] [blame] | 3731 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3732 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3733 | case Iop_Add32: |
sewardj | 54eac25 | 2012-03-27 10:19:39 +0000 | [diff] [blame] | 3734 | if (mce->bogusLiterals || mce->useLLVMworkarounds) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3735 | return expensiveAddSub(mce,True,Ity_I32, |
| 3736 | vatom1,vatom2, atom1,atom2); |
| 3737 | else |
| 3738 | goto cheap_AddSub32; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3739 | case Iop_Sub32: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3740 | if (mce->bogusLiterals) |
| 3741 | return expensiveAddSub(mce,False,Ity_I32, |
| 3742 | vatom1,vatom2, atom1,atom2); |
| 3743 | else |
| 3744 | goto cheap_AddSub32; |
| 3745 | |
| 3746 | cheap_AddSub32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3747 | case Iop_Mul32: |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 3748 | return mkLeft32(mce, mkUifU32(mce, vatom1,vatom2)); |
| 3749 | |
sewardj | 463b3d9 | 2005-07-18 11:41:15 +0000 | [diff] [blame] | 3750 | case Iop_CmpORD32S: |
| 3751 | case Iop_CmpORD32U: |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 3752 | case Iop_CmpORD64S: |
| 3753 | case Iop_CmpORD64U: |
| 3754 | return doCmpORD(mce, op, vatom1,vatom2, atom1,atom2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3755 | |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3756 | case Iop_Add64: |
sewardj | 54eac25 | 2012-03-27 10:19:39 +0000 | [diff] [blame] | 3757 | if (mce->bogusLiterals || mce->useLLVMworkarounds) |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 3758 | return expensiveAddSub(mce,True,Ity_I64, |
| 3759 | vatom1,vatom2, atom1,atom2); |
| 3760 | else |
| 3761 | goto cheap_AddSub64; |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3762 | case Iop_Sub64: |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 3763 | if (mce->bogusLiterals) |
| 3764 | return expensiveAddSub(mce,False,Ity_I64, |
| 3765 | vatom1,vatom2, atom1,atom2); |
| 3766 | else |
| 3767 | goto cheap_AddSub64; |
| 3768 | |
| 3769 | cheap_AddSub64: |
| 3770 | case Iop_Mul64: |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3771 | return mkLeft64(mce, mkUifU64(mce, vatom1,vatom2)); |
| 3772 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3773 | case Iop_Mul16: |
| 3774 | case Iop_Add16: |
| 3775 | case Iop_Sub16: |
| 3776 | return mkLeft16(mce, mkUifU16(mce, vatom1,vatom2)); |
| 3777 | |
florian | 537ed2d | 2012-08-20 16:51:39 +0000 | [diff] [blame] | 3778 | case Iop_Mul8: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3779 | case Iop_Sub8: |
| 3780 | case Iop_Add8: |
| 3781 | return mkLeft8(mce, mkUifU8(mce, vatom1,vatom2)); |
| 3782 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3783 | case Iop_CmpEQ64: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 3784 | case Iop_CmpNE64: |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3785 | if (mce->bogusLiterals) |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 3786 | goto expensive_cmp64; |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3787 | else |
| 3788 | goto cheap_cmp64; |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 3789 | |
| 3790 | expensive_cmp64: |
| 3791 | case Iop_ExpCmpNE64: |
| 3792 | return expensiveCmpEQorNE(mce,Ity_I64, vatom1,vatom2, atom1,atom2 ); |
| 3793 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3794 | cheap_cmp64: |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 3795 | case Iop_CmpLE64S: case Iop_CmpLE64U: |
| 3796 | case Iop_CmpLT64U: case Iop_CmpLT64S: |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3797 | return mkPCastTo(mce, Ity_I1, mkUifU64(mce, vatom1,vatom2)); |
| 3798 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3799 | case Iop_CmpEQ32: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 3800 | case Iop_CmpNE32: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3801 | if (mce->bogusLiterals) |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 3802 | goto expensive_cmp32; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3803 | else |
| 3804 | goto cheap_cmp32; |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 3805 | |
| 3806 | expensive_cmp32: |
| 3807 | case Iop_ExpCmpNE32: |
| 3808 | return expensiveCmpEQorNE(mce,Ity_I32, vatom1,vatom2, atom1,atom2 ); |
| 3809 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3810 | cheap_cmp32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3811 | case Iop_CmpLE32S: case Iop_CmpLE32U: |
| 3812 | case Iop_CmpLT32U: case Iop_CmpLT32S: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3813 | return mkPCastTo(mce, Ity_I1, mkUifU32(mce, vatom1,vatom2)); |
| 3814 | |
| 3815 | case Iop_CmpEQ16: case Iop_CmpNE16: |
| 3816 | return mkPCastTo(mce, Ity_I1, mkUifU16(mce, vatom1,vatom2)); |
| 3817 | |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 3818 | case Iop_ExpCmpNE16: |
| 3819 | return expensiveCmpEQorNE(mce,Ity_I16, vatom1,vatom2, atom1,atom2 ); |
| 3820 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3821 | case Iop_CmpEQ8: case Iop_CmpNE8: |
| 3822 | return mkPCastTo(mce, Ity_I1, mkUifU8(mce, vatom1,vatom2)); |
| 3823 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 3824 | case Iop_CasCmpEQ8: case Iop_CasCmpNE8: |
| 3825 | case Iop_CasCmpEQ16: case Iop_CasCmpNE16: |
| 3826 | case Iop_CasCmpEQ32: case Iop_CasCmpNE32: |
| 3827 | case Iop_CasCmpEQ64: case Iop_CasCmpNE64: |
| 3828 | /* Just say these all produce a defined result, regardless |
| 3829 | of their arguments. See COMMENT_ON_CasCmpEQ in this file. */ |
| 3830 | return assignNew('V', mce, Ity_I1, definedOfType(Ity_I1)); |
| 3831 | |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3832 | case Iop_Shl64: case Iop_Shr64: case Iop_Sar64: |
| 3833 | return scalarShift( mce, Ity_I64, op, vatom1,vatom2, atom1,atom2 ); |
| 3834 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3835 | case Iop_Shl32: case Iop_Shr32: case Iop_Sar32: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3836 | return scalarShift( mce, Ity_I32, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3837 | |
sewardj | db67f5f | 2004-12-14 01:15:31 +0000 | [diff] [blame] | 3838 | case Iop_Shl16: case Iop_Shr16: case Iop_Sar16: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3839 | return scalarShift( mce, Ity_I16, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3840 | |
florian | 537ed2d | 2012-08-20 16:51:39 +0000 | [diff] [blame] | 3841 | case Iop_Shl8: case Iop_Shr8: case Iop_Sar8: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3842 | return scalarShift( mce, Ity_I8, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3843 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3844 | case Iop_AndV256: |
| 3845 | uifu = mkUifUV256; difd = mkDifDV256; |
| 3846 | and_or_ty = Ity_V256; improve = mkImproveANDV256; goto do_And_Or; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3847 | case Iop_AndV128: |
| 3848 | uifu = mkUifUV128; difd = mkDifDV128; |
| 3849 | and_or_ty = Ity_V128; improve = mkImproveANDV128; goto do_And_Or; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3850 | case Iop_And64: |
| 3851 | uifu = mkUifU64; difd = mkDifD64; |
| 3852 | and_or_ty = Ity_I64; improve = mkImproveAND64; goto do_And_Or; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3853 | case Iop_And32: |
| 3854 | uifu = mkUifU32; difd = mkDifD32; |
| 3855 | and_or_ty = Ity_I32; improve = mkImproveAND32; goto do_And_Or; |
| 3856 | case Iop_And16: |
| 3857 | uifu = mkUifU16; difd = mkDifD16; |
| 3858 | and_or_ty = Ity_I16; improve = mkImproveAND16; goto do_And_Or; |
| 3859 | case Iop_And8: |
| 3860 | uifu = mkUifU8; difd = mkDifD8; |
| 3861 | and_or_ty = Ity_I8; improve = mkImproveAND8; goto do_And_Or; |
| 3862 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3863 | case Iop_OrV256: |
| 3864 | uifu = mkUifUV256; difd = mkDifDV256; |
| 3865 | and_or_ty = Ity_V256; improve = mkImproveORV256; goto do_And_Or; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3866 | case Iop_OrV128: |
| 3867 | uifu = mkUifUV128; difd = mkDifDV128; |
| 3868 | and_or_ty = Ity_V128; improve = mkImproveORV128; goto do_And_Or; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3869 | case Iop_Or64: |
| 3870 | uifu = mkUifU64; difd = mkDifD64; |
| 3871 | and_or_ty = Ity_I64; improve = mkImproveOR64; goto do_And_Or; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3872 | case Iop_Or32: |
| 3873 | uifu = mkUifU32; difd = mkDifD32; |
| 3874 | and_or_ty = Ity_I32; improve = mkImproveOR32; goto do_And_Or; |
| 3875 | case Iop_Or16: |
| 3876 | uifu = mkUifU16; difd = mkDifD16; |
| 3877 | and_or_ty = Ity_I16; improve = mkImproveOR16; goto do_And_Or; |
| 3878 | case Iop_Or8: |
| 3879 | uifu = mkUifU8; difd = mkDifD8; |
| 3880 | and_or_ty = Ity_I8; improve = mkImproveOR8; goto do_And_Or; |
| 3881 | |
| 3882 | do_And_Or: |
| 3883 | return |
| 3884 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3885 | 'V', mce, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3886 | and_or_ty, |
| 3887 | difd(mce, uifu(mce, vatom1, vatom2), |
| 3888 | difd(mce, improve(mce, atom1, vatom1), |
| 3889 | improve(mce, atom2, vatom2) ) ) ); |
| 3890 | |
| 3891 | case Iop_Xor8: |
| 3892 | return mkUifU8(mce, vatom1, vatom2); |
| 3893 | case Iop_Xor16: |
| 3894 | return mkUifU16(mce, vatom1, vatom2); |
| 3895 | case Iop_Xor32: |
| 3896 | return mkUifU32(mce, vatom1, vatom2); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3897 | case Iop_Xor64: |
| 3898 | return mkUifU64(mce, vatom1, vatom2); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3899 | case Iop_XorV128: |
| 3900 | return mkUifUV128(mce, vatom1, vatom2); |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 3901 | case Iop_XorV256: |
| 3902 | return mkUifUV256(mce, vatom1, vatom2); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3903 | |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 3904 | /* V256-bit SIMD */ |
| 3905 | |
| 3906 | case Iop_ShrN16x16: |
| 3907 | case Iop_ShrN32x8: |
| 3908 | case Iop_ShrN64x4: |
| 3909 | case Iop_SarN16x16: |
| 3910 | case Iop_SarN32x8: |
| 3911 | case Iop_ShlN16x16: |
| 3912 | case Iop_ShlN32x8: |
| 3913 | case Iop_ShlN64x4: |
| 3914 | /* Same scheme as with all other shifts. Note: 22 Oct 05: |
| 3915 | this is wrong now, scalar shifts are done properly lazily. |
| 3916 | Vector shifts should be fixed too. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 3917 | complainIfUndefined(mce, atom2, NULL); |
sewardj | a2f3095 | 2013-03-27 11:40:02 +0000 | [diff] [blame] | 3918 | return assignNew('V', mce, Ity_V256, binop(op, vatom1, atom2)); |
| 3919 | |
| 3920 | case Iop_QSub8Ux32: |
| 3921 | case Iop_QSub8Sx32: |
| 3922 | case Iop_Sub8x32: |
| 3923 | case Iop_Min8Ux32: |
| 3924 | case Iop_Min8Sx32: |
| 3925 | case Iop_Max8Ux32: |
| 3926 | case Iop_Max8Sx32: |
| 3927 | case Iop_CmpGT8Sx32: |
| 3928 | case Iop_CmpEQ8x32: |
| 3929 | case Iop_Avg8Ux32: |
| 3930 | case Iop_QAdd8Ux32: |
| 3931 | case Iop_QAdd8Sx32: |
| 3932 | case Iop_Add8x32: |
| 3933 | return binary8Ix32(mce, vatom1, vatom2); |
| 3934 | |
| 3935 | case Iop_QSub16Ux16: |
| 3936 | case Iop_QSub16Sx16: |
| 3937 | case Iop_Sub16x16: |
| 3938 | case Iop_Mul16x16: |
| 3939 | case Iop_MulHi16Sx16: |
| 3940 | case Iop_MulHi16Ux16: |
| 3941 | case Iop_Min16Sx16: |
| 3942 | case Iop_Min16Ux16: |
| 3943 | case Iop_Max16Sx16: |
| 3944 | case Iop_Max16Ux16: |
| 3945 | case Iop_CmpGT16Sx16: |
| 3946 | case Iop_CmpEQ16x16: |
| 3947 | case Iop_Avg16Ux16: |
| 3948 | case Iop_QAdd16Ux16: |
| 3949 | case Iop_QAdd16Sx16: |
| 3950 | case Iop_Add16x16: |
| 3951 | return binary16Ix16(mce, vatom1, vatom2); |
| 3952 | |
| 3953 | case Iop_Sub32x8: |
| 3954 | case Iop_CmpGT32Sx8: |
| 3955 | case Iop_CmpEQ32x8: |
| 3956 | case Iop_Add32x8: |
| 3957 | case Iop_Max32Ux8: |
| 3958 | case Iop_Max32Sx8: |
| 3959 | case Iop_Min32Ux8: |
| 3960 | case Iop_Min32Sx8: |
| 3961 | case Iop_Mul32x8: |
| 3962 | return binary32Ix8(mce, vatom1, vatom2); |
| 3963 | |
| 3964 | case Iop_Sub64x4: |
| 3965 | case Iop_Add64x4: |
| 3966 | case Iop_CmpEQ64x4: |
| 3967 | case Iop_CmpGT64Sx4: |
| 3968 | return binary64Ix4(mce, vatom1, vatom2); |
| 3969 | |
| 3970 | /* Perm32x8: rearrange values in left arg using steering values |
| 3971 | from right arg. So rearrange the vbits in the same way but |
| 3972 | pessimise wrt steering values. */ |
| 3973 | case Iop_Perm32x8: |
| 3974 | return mkUifUV256( |
| 3975 | mce, |
| 3976 | assignNew('V', mce, Ity_V256, binop(op, vatom1, atom2)), |
| 3977 | mkPCast32x8(mce, vatom2) |
| 3978 | ); |
| 3979 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3980 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3981 | ppIROp(op); |
| 3982 | VG_(tool_panic)("memcheck:expr2vbits_Binop"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3983 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3986 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3987 | static |
| 3988 | IRExpr* expr2vbits_Unop ( MCEnv* mce, IROp op, IRAtom* atom ) |
| 3989 | { |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 3990 | /* For the widening operations {8,16,32}{U,S}to{16,32,64}, the |
| 3991 | selection of shadow operation implicitly duplicates the logic in |
| 3992 | do_shadow_LoadG and should be kept in sync (in the very unlikely |
| 3993 | event that the interpretation of such widening ops changes in |
| 3994 | future). See comment in do_shadow_LoadG. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3995 | IRAtom* vatom = expr2vbits( mce, atom ); |
| 3996 | tl_assert(isOriginalAtom(mce,atom)); |
| 3997 | switch (op) { |
| 3998 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3999 | case Iop_Sqrt64Fx2: |
sewardj | c46e6cc | 2014-03-10 10:42:36 +0000 | [diff] [blame] | 4000 | case Iop_Abs64Fx2: |
| 4001 | case Iop_Neg64Fx2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 4002 | return unary64Fx2(mce, vatom); |
| 4003 | |
| 4004 | case Iop_Sqrt64F0x2: |
| 4005 | return unary64F0x2(mce, vatom); |
| 4006 | |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 4007 | case Iop_Sqrt32Fx8: |
| 4008 | case Iop_RSqrt32Fx8: |
| 4009 | case Iop_Recip32Fx8: |
| 4010 | return unary32Fx8(mce, vatom); |
| 4011 | |
| 4012 | case Iop_Sqrt64Fx4: |
| 4013 | return unary64Fx4(mce, vatom); |
| 4014 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4015 | case Iop_Sqrt32Fx4: |
| 4016 | case Iop_RSqrt32Fx4: |
| 4017 | case Iop_Recip32Fx4: |
cerion | 176cb4c | 2005-11-16 17:21:49 +0000 | [diff] [blame] | 4018 | case Iop_I32UtoFx4: |
| 4019 | case Iop_I32StoFx4: |
| 4020 | case Iop_QFtoI32Ux4_RZ: |
| 4021 | case Iop_QFtoI32Sx4_RZ: |
| 4022 | case Iop_RoundF32x4_RM: |
| 4023 | case Iop_RoundF32x4_RP: |
| 4024 | case Iop_RoundF32x4_RN: |
| 4025 | case Iop_RoundF32x4_RZ: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4026 | case Iop_Recip32x4: |
| 4027 | case Iop_Abs32Fx4: |
| 4028 | case Iop_Neg32Fx4: |
| 4029 | case Iop_Rsqrte32Fx4: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4030 | return unary32Fx4(mce, vatom); |
| 4031 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4032 | case Iop_I32UtoFx2: |
| 4033 | case Iop_I32StoFx2: |
| 4034 | case Iop_Recip32Fx2: |
| 4035 | case Iop_Recip32x2: |
| 4036 | case Iop_Abs32Fx2: |
| 4037 | case Iop_Neg32Fx2: |
| 4038 | case Iop_Rsqrte32Fx2: |
| 4039 | return unary32Fx2(mce, vatom); |
| 4040 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4041 | case Iop_Sqrt32F0x4: |
| 4042 | case Iop_RSqrt32F0x4: |
| 4043 | case Iop_Recip32F0x4: |
| 4044 | return unary32F0x4(mce, vatom); |
| 4045 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 4046 | case Iop_32UtoV128: |
| 4047 | case Iop_64UtoV128: |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 4048 | case Iop_Dup8x16: |
| 4049 | case Iop_Dup16x8: |
| 4050 | case Iop_Dup32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4051 | case Iop_Reverse16_8x16: |
| 4052 | case Iop_Reverse32_8x16: |
| 4053 | case Iop_Reverse32_16x8: |
| 4054 | case Iop_Reverse64_8x16: |
| 4055 | case Iop_Reverse64_16x8: |
| 4056 | case Iop_Reverse64_32x4: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 4057 | case Iop_V256toV128_1: case Iop_V256toV128_0: |
sewardj | c46e6cc | 2014-03-10 10:42:36 +0000 | [diff] [blame] | 4058 | case Iop_ZeroHI64ofV128: |
| 4059 | case Iop_ZeroHI96ofV128: |
| 4060 | case Iop_ZeroHI112ofV128: |
| 4061 | case Iop_ZeroHI120ofV128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4062 | return assignNew('V', mce, Ity_V128, unop(op, vatom)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4063 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4064 | case Iop_F128HItoF64: /* F128 -> high half of F128 */ |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 4065 | case Iop_D128HItoD64: /* D128 -> high half of D128 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4066 | return assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, vatom)); |
| 4067 | case Iop_F128LOtoF64: /* F128 -> low half of F128 */ |
sewardj | b0ccb4d | 2012-04-02 10:22:05 +0000 | [diff] [blame] | 4068 | case Iop_D128LOtoD64: /* D128 -> low half of D128 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4069 | return assignNew('V', mce, Ity_I64, unop(Iop_128to64, vatom)); |
| 4070 | |
| 4071 | case Iop_NegF128: |
| 4072 | case Iop_AbsF128: |
| 4073 | return mkPCastTo(mce, Ity_I128, vatom); |
| 4074 | |
| 4075 | case Iop_I32StoF128: /* signed I32 -> F128 */ |
| 4076 | case Iop_I64StoF128: /* signed I64 -> F128 */ |
florian | 1b9609a | 2012-09-01 00:15:45 +0000 | [diff] [blame] | 4077 | case Iop_I32UtoF128: /* unsigned I32 -> F128 */ |
| 4078 | case Iop_I64UtoF128: /* unsigned I64 -> F128 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4079 | case Iop_F32toF128: /* F32 -> F128 */ |
| 4080 | case Iop_F64toF128: /* F64 -> F128 */ |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 4081 | case Iop_I32StoD128: /* signed I64 -> D128 */ |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 4082 | case Iop_I64StoD128: /* signed I64 -> D128 */ |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 4083 | case Iop_I32UtoD128: /* unsigned I32 -> D128 */ |
| 4084 | case Iop_I64UtoD128: /* unsigned I64 -> D128 */ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4085 | return mkPCastTo(mce, Ity_I128, vatom); |
| 4086 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4087 | case Iop_F32toF64: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 4088 | case Iop_I32StoF64: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 4089 | case Iop_I32UtoF64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4090 | case Iop_NegF64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4091 | case Iop_AbsF64: |
sewardj | 4f3e0f2 | 2006-01-27 15:11:31 +0000 | [diff] [blame] | 4092 | case Iop_Est5FRSqrt: |
sewardj | dead90a | 2008-08-08 08:38:23 +0000 | [diff] [blame] | 4093 | case Iop_RoundF64toF64_NEAREST: |
| 4094 | case Iop_RoundF64toF64_NegINF: |
| 4095 | case Iop_RoundF64toF64_PosINF: |
| 4096 | case Iop_RoundF64toF64_ZERO: |
sewardj | 39cc735 | 2005-06-09 21:31:55 +0000 | [diff] [blame] | 4097 | case Iop_Clz64: |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 4098 | case Iop_D32toD64: |
florian | 53eb2a0 | 2013-01-12 22:04:00 +0000 | [diff] [blame] | 4099 | case Iop_I32StoD64: |
| 4100 | case Iop_I32UtoD64: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 4101 | case Iop_ExtractExpD64: /* D64 -> I64 */ |
| 4102 | case Iop_ExtractExpD128: /* D128 -> I64 */ |
florian | 974b409 | 2012-12-27 20:06:18 +0000 | [diff] [blame] | 4103 | case Iop_ExtractSigD64: /* D64 -> I64 */ |
| 4104 | case Iop_ExtractSigD128: /* D128 -> I64 */ |
florian | 1943eb5 | 2012-08-22 18:09:07 +0000 | [diff] [blame] | 4105 | case Iop_DPBtoBCD: |
| 4106 | case Iop_BCDtoDPB: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4107 | return mkPCastTo(mce, Ity_I64, vatom); |
| 4108 | |
sewardj | ea8b02f | 2012-04-12 17:28:57 +0000 | [diff] [blame] | 4109 | case Iop_D64toD128: |
| 4110 | return mkPCastTo(mce, Ity_I128, vatom); |
| 4111 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4112 | case Iop_Clz32: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 4113 | case Iop_TruncF64asF32: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 4114 | case Iop_NegF32: |
| 4115 | case Iop_AbsF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4116 | return mkPCastTo(mce, Ity_I32, vatom); |
| 4117 | |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 4118 | case Iop_Ctz32: |
| 4119 | case Iop_Ctz64: |
| 4120 | return expensiveCountTrailingZeroes(mce, op, atom, vatom); |
| 4121 | |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4122 | case Iop_1Uto64: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 4123 | case Iop_1Sto64: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4124 | case Iop_8Uto64: |
| 4125 | case Iop_8Sto64: |
| 4126 | case Iop_16Uto64: |
| 4127 | case Iop_16Sto64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4128 | case Iop_32Sto64: |
| 4129 | case Iop_32Uto64: |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 4130 | case Iop_V128to64: |
| 4131 | case Iop_V128HIto64: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 4132 | case Iop_128HIto64: |
| 4133 | case Iop_128to64: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4134 | case Iop_Dup8x8: |
| 4135 | case Iop_Dup16x4: |
| 4136 | case Iop_Dup32x2: |
| 4137 | case Iop_Reverse16_8x8: |
| 4138 | case Iop_Reverse32_8x8: |
| 4139 | case Iop_Reverse32_16x4: |
| 4140 | case Iop_Reverse64_8x8: |
| 4141 | case Iop_Reverse64_16x4: |
| 4142 | case Iop_Reverse64_32x2: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 4143 | case Iop_V256to64_0: case Iop_V256to64_1: |
| 4144 | case Iop_V256to64_2: case Iop_V256to64_3: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4145 | return assignNew('V', mce, Ity_I64, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4146 | |
| 4147 | case Iop_64to32: |
| 4148 | case Iop_64HIto32: |
| 4149 | case Iop_1Uto32: |
sewardj | 463b3d9 | 2005-07-18 11:41:15 +0000 | [diff] [blame] | 4150 | case Iop_1Sto32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4151 | case Iop_8Uto32: |
| 4152 | case Iop_16Uto32: |
| 4153 | case Iop_16Sto32: |
| 4154 | case Iop_8Sto32: |
cerion | fafaa0d | 2005-09-12 22:29:38 +0000 | [diff] [blame] | 4155 | case Iop_V128to32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4156 | return assignNew('V', mce, Ity_I32, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4157 | |
| 4158 | case Iop_8Sto16: |
| 4159 | case Iop_8Uto16: |
| 4160 | case Iop_32to16: |
| 4161 | case Iop_32HIto16: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4162 | case Iop_64to16: |
sewardj | f517634 | 2012-12-13 18:31:49 +0000 | [diff] [blame] | 4163 | case Iop_GetMSBs8x16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4164 | return assignNew('V', mce, Ity_I16, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4165 | |
| 4166 | case Iop_1Uto8: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 4167 | case Iop_1Sto8: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4168 | case Iop_16to8: |
sewardj | 9a807e0 | 2006-12-17 14:20:31 +0000 | [diff] [blame] | 4169 | case Iop_16HIto8: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4170 | case Iop_32to8: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4171 | case Iop_64to8: |
sewardj | 4cfa81b | 2012-11-08 10:58:16 +0000 | [diff] [blame] | 4172 | case Iop_GetMSBs8x8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4173 | return assignNew('V', mce, Ity_I8, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4174 | |
| 4175 | case Iop_32to1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4176 | return assignNew('V', mce, Ity_I1, unop(Iop_32to1, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4177 | |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4178 | case Iop_64to1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4179 | return assignNew('V', mce, Ity_I1, unop(Iop_64to1, vatom)); |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 4180 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4181 | case Iop_ReinterpF64asI64: |
| 4182 | case Iop_ReinterpI64asF64: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 4183 | case Iop_ReinterpI32asF32: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 4184 | case Iop_ReinterpF32asI32: |
sewardj | 18c72fa | 2012-04-23 11:22:05 +0000 | [diff] [blame] | 4185 | case Iop_ReinterpI64asD64: |
sewardj | 0892b82 | 2012-04-29 20:20:16 +0000 | [diff] [blame] | 4186 | case Iop_ReinterpD64asI64: |
sewardj | 350e8f7 | 2012-06-25 07:52:15 +0000 | [diff] [blame] | 4187 | case Iop_NotV256: |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 4188 | case Iop_NotV128: |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 4189 | case Iop_Not64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4190 | case Iop_Not32: |
| 4191 | case Iop_Not16: |
| 4192 | case Iop_Not8: |
| 4193 | case Iop_Not1: |
| 4194 | return vatom; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 4195 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4196 | case Iop_CmpNEZ8x8: |
| 4197 | case Iop_Cnt8x8: |
| 4198 | case Iop_Clz8Sx8: |
| 4199 | case Iop_Cls8Sx8: |
| 4200 | case Iop_Abs8x8: |
| 4201 | return mkPCast8x8(mce, vatom); |
| 4202 | |
| 4203 | case Iop_CmpNEZ8x16: |
| 4204 | case Iop_Cnt8x16: |
| 4205 | case Iop_Clz8Sx16: |
| 4206 | case Iop_Cls8Sx16: |
| 4207 | case Iop_Abs8x16: |
| 4208 | return mkPCast8x16(mce, vatom); |
| 4209 | |
| 4210 | case Iop_CmpNEZ16x4: |
| 4211 | case Iop_Clz16Sx4: |
| 4212 | case Iop_Cls16Sx4: |
| 4213 | case Iop_Abs16x4: |
| 4214 | return mkPCast16x4(mce, vatom); |
| 4215 | |
| 4216 | case Iop_CmpNEZ16x8: |
| 4217 | case Iop_Clz16Sx8: |
| 4218 | case Iop_Cls16Sx8: |
| 4219 | case Iop_Abs16x8: |
| 4220 | return mkPCast16x8(mce, vatom); |
| 4221 | |
| 4222 | case Iop_CmpNEZ32x2: |
| 4223 | case Iop_Clz32Sx2: |
| 4224 | case Iop_Cls32Sx2: |
| 4225 | case Iop_FtoI32Ux2_RZ: |
| 4226 | case Iop_FtoI32Sx2_RZ: |
| 4227 | case Iop_Abs32x2: |
| 4228 | return mkPCast32x2(mce, vatom); |
| 4229 | |
| 4230 | case Iop_CmpNEZ32x4: |
| 4231 | case Iop_Clz32Sx4: |
| 4232 | case Iop_Cls32Sx4: |
| 4233 | case Iop_FtoI32Ux4_RZ: |
| 4234 | case Iop_FtoI32Sx4_RZ: |
| 4235 | case Iop_Abs32x4: |
| 4236 | return mkPCast32x4(mce, vatom); |
| 4237 | |
florian | 537ed2d | 2012-08-20 16:51:39 +0000 | [diff] [blame] | 4238 | case Iop_CmpwNEZ32: |
| 4239 | return mkPCastTo(mce, Ity_I32, vatom); |
| 4240 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4241 | case Iop_CmpwNEZ64: |
| 4242 | return mkPCastTo(mce, Ity_I64, vatom); |
| 4243 | |
| 4244 | case Iop_CmpNEZ64x2: |
carll | 24e40de | 2013-10-15 18:13:21 +0000 | [diff] [blame] | 4245 | case Iop_CipherSV128: |
| 4246 | case Iop_Clz64x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4247 | return mkPCast64x2(mce, vatom); |
| 4248 | |
carll | e6bd3e4 | 2013-10-18 01:20:11 +0000 | [diff] [blame] | 4249 | case Iop_PwBitMtxXpose64x2: |
| 4250 | return assignNew('V', mce, Ity_V128, unop(op, vatom)); |
| 4251 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 4252 | case Iop_NarrowUn16to8x8: |
| 4253 | case Iop_NarrowUn32to16x4: |
| 4254 | case Iop_NarrowUn64to32x2: |
| 4255 | case Iop_QNarrowUn16Sto8Sx8: |
| 4256 | case Iop_QNarrowUn16Sto8Ux8: |
| 4257 | case Iop_QNarrowUn16Uto8Ux8: |
| 4258 | case Iop_QNarrowUn32Sto16Sx4: |
| 4259 | case Iop_QNarrowUn32Sto16Ux4: |
| 4260 | case Iop_QNarrowUn32Uto16Ux4: |
| 4261 | case Iop_QNarrowUn64Sto32Sx2: |
| 4262 | case Iop_QNarrowUn64Sto32Ux2: |
| 4263 | case Iop_QNarrowUn64Uto32Ux2: |
| 4264 | return vectorNarrowUnV128(mce, op, vatom); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4265 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 4266 | case Iop_Widen8Sto16x8: |
| 4267 | case Iop_Widen8Uto16x8: |
| 4268 | case Iop_Widen16Sto32x4: |
| 4269 | case Iop_Widen16Uto32x4: |
| 4270 | case Iop_Widen32Sto64x2: |
| 4271 | case Iop_Widen32Uto64x2: |
| 4272 | return vectorWidenI64(mce, op, vatom); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 4273 | |
| 4274 | case Iop_PwAddL32Ux2: |
| 4275 | case Iop_PwAddL32Sx2: |
| 4276 | return mkPCastTo(mce, Ity_I64, |
| 4277 | assignNew('V', mce, Ity_I64, unop(op, mkPCast32x2(mce, vatom)))); |
| 4278 | |
| 4279 | case Iop_PwAddL16Ux4: |
| 4280 | case Iop_PwAddL16Sx4: |
| 4281 | return mkPCast32x2(mce, |
| 4282 | assignNew('V', mce, Ity_I64, unop(op, mkPCast16x4(mce, vatom)))); |
| 4283 | |
| 4284 | case Iop_PwAddL8Ux8: |
| 4285 | case Iop_PwAddL8Sx8: |
| 4286 | return mkPCast16x4(mce, |
| 4287 | assignNew('V', mce, Ity_I64, unop(op, mkPCast8x8(mce, vatom)))); |
| 4288 | |
| 4289 | case Iop_PwAddL32Ux4: |
| 4290 | case Iop_PwAddL32Sx4: |
| 4291 | return mkPCast64x2(mce, |
| 4292 | assignNew('V', mce, Ity_V128, unop(op, mkPCast32x4(mce, vatom)))); |
| 4293 | |
| 4294 | case Iop_PwAddL16Ux8: |
| 4295 | case Iop_PwAddL16Sx8: |
| 4296 | return mkPCast32x4(mce, |
| 4297 | assignNew('V', mce, Ity_V128, unop(op, mkPCast16x8(mce, vatom)))); |
| 4298 | |
| 4299 | case Iop_PwAddL8Ux16: |
| 4300 | case Iop_PwAddL8Sx16: |
| 4301 | return mkPCast16x8(mce, |
| 4302 | assignNew('V', mce, Ity_V128, unop(op, mkPCast8x16(mce, vatom)))); |
| 4303 | |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 4304 | case Iop_I64UtoF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4305 | default: |
| 4306 | ppIROp(op); |
| 4307 | VG_(tool_panic)("memcheck:expr2vbits_Unop"); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4312 | /* Worker function -- do not call directly. See comments on |
| 4313 | expr2vbits_Load for the meaning of |guard|. |
| 4314 | |
| 4315 | Generates IR to (1) perform a definedness test of |addr|, (2) |
| 4316 | perform a validity test of |addr|, and (3) return the Vbits for the |
| 4317 | location indicated by |addr|. All of this only happens when |
| 4318 | |guard| is NULL or |guard| evaluates to True at run time. |
| 4319 | |
| 4320 | If |guard| evaluates to False at run time, the returned value is |
| 4321 | the IR-mandated 0x55..55 value, and no checks nor shadow loads are |
| 4322 | performed. |
| 4323 | |
| 4324 | The definedness of |guard| itself is not checked. That is assumed |
| 4325 | to have been done before this point, by the caller. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4326 | static |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4327 | IRAtom* expr2vbits_Load_WRK ( MCEnv* mce, |
| 4328 | IREndness end, IRType ty, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4329 | IRAtom* addr, UInt bias, IRAtom* guard ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4330 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4331 | tl_assert(isOriginalAtom(mce,addr)); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4332 | tl_assert(end == Iend_LE || end == Iend_BE); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4333 | |
| 4334 | /* First, emit a definedness test for the address. This also sets |
| 4335 | the address (shadow) to 'defined' following the test. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4336 | complainIfUndefined( mce, addr, guard ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4337 | |
| 4338 | /* Now cook up a call to the relevant helper function, to read the |
| 4339 | data V bits from shadow memory. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4340 | ty = shadowTypeV(ty); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4341 | |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4342 | void* helper = NULL; |
| 4343 | const HChar* hname = NULL; |
| 4344 | Bool ret_via_outparam = False; |
| 4345 | |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4346 | if (end == Iend_LE) { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4347 | switch (ty) { |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4348 | case Ity_V256: helper = &MC_(helperc_LOADV256le); |
| 4349 | hname = "MC_(helperc_LOADV256le)"; |
| 4350 | ret_via_outparam = True; |
| 4351 | break; |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4352 | case Ity_V128: helper = &MC_(helperc_LOADV128le); |
| 4353 | hname = "MC_(helperc_LOADV128le)"; |
| 4354 | ret_via_outparam = True; |
| 4355 | break; |
| 4356 | case Ity_I64: helper = &MC_(helperc_LOADV64le); |
| 4357 | hname = "MC_(helperc_LOADV64le)"; |
| 4358 | break; |
| 4359 | case Ity_I32: helper = &MC_(helperc_LOADV32le); |
| 4360 | hname = "MC_(helperc_LOADV32le)"; |
| 4361 | break; |
| 4362 | case Ity_I16: helper = &MC_(helperc_LOADV16le); |
| 4363 | hname = "MC_(helperc_LOADV16le)"; |
| 4364 | break; |
| 4365 | case Ity_I8: helper = &MC_(helperc_LOADV8); |
| 4366 | hname = "MC_(helperc_LOADV8)"; |
| 4367 | break; |
| 4368 | default: ppIRType(ty); |
| 4369 | VG_(tool_panic)("memcheck:expr2vbits_Load_WRK(LE)"); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4370 | } |
| 4371 | } else { |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4372 | switch (ty) { |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4373 | case Ity_V256: helper = &MC_(helperc_LOADV256be); |
| 4374 | hname = "MC_(helperc_LOADV256be)"; |
| 4375 | ret_via_outparam = True; |
| 4376 | break; |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4377 | case Ity_V128: helper = &MC_(helperc_LOADV128be); |
| 4378 | hname = "MC_(helperc_LOADV128be)"; |
| 4379 | ret_via_outparam = True; |
| 4380 | break; |
| 4381 | case Ity_I64: helper = &MC_(helperc_LOADV64be); |
| 4382 | hname = "MC_(helperc_LOADV64be)"; |
| 4383 | break; |
| 4384 | case Ity_I32: helper = &MC_(helperc_LOADV32be); |
| 4385 | hname = "MC_(helperc_LOADV32be)"; |
| 4386 | break; |
| 4387 | case Ity_I16: helper = &MC_(helperc_LOADV16be); |
| 4388 | hname = "MC_(helperc_LOADV16be)"; |
| 4389 | break; |
| 4390 | case Ity_I8: helper = &MC_(helperc_LOADV8); |
| 4391 | hname = "MC_(helperc_LOADV8)"; |
| 4392 | break; |
| 4393 | default: ppIRType(ty); |
| 4394 | VG_(tool_panic)("memcheck:expr2vbits_Load_WRK(BE)"); |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4395 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4396 | } |
| 4397 | |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4398 | tl_assert(helper); |
| 4399 | tl_assert(hname); |
| 4400 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4401 | /* Generate the actual address into addrAct. */ |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4402 | IRAtom* addrAct; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4403 | if (bias == 0) { |
| 4404 | addrAct = addr; |
| 4405 | } else { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 4406 | IROp mkAdd; |
| 4407 | IRAtom* eBias; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4408 | IRType tyAddr = mce->hWordTy; |
| 4409 | tl_assert( tyAddr == Ity_I32 || tyAddr == Ity_I64 ); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 4410 | mkAdd = tyAddr==Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 4411 | eBias = tyAddr==Ity_I32 ? mkU32(bias) : mkU64(bias); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4412 | addrAct = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBias) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | /* We need to have a place to park the V bits we're just about to |
| 4416 | read. */ |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4417 | IRTemp datavbits = newTemp(mce, ty, VSh); |
| 4418 | |
| 4419 | /* Here's the call. */ |
| 4420 | IRDirty* di; |
| 4421 | if (ret_via_outparam) { |
| 4422 | di = unsafeIRDirty_1_N( datavbits, |
| 4423 | 2/*regparms*/, |
| 4424 | hname, VG_(fnptr_to_fnentry)( helper ), |
florian | a5c3ecb | 2013-08-15 20:55:42 +0000 | [diff] [blame] | 4425 | mkIRExprVec_2( IRExpr_VECRET(), addrAct ) ); |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4426 | } else { |
| 4427 | di = unsafeIRDirty_1_N( datavbits, |
| 4428 | 1/*regparms*/, |
| 4429 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4430 | mkIRExprVec_1( addrAct ) ); |
| 4431 | } |
| 4432 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4433 | setHelperAnns( mce, di ); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4434 | if (guard) { |
| 4435 | di->guard = guard; |
| 4436 | /* Ideally the didn't-happen return value here would be all-ones |
| 4437 | (all-undefined), so it'd be obvious if it got used |
| 4438 | inadvertantly. We can get by with the IR-mandated default |
| 4439 | value (0b01 repeating, 0x55 etc) as that'll still look pretty |
| 4440 | undefined if it ever leaks out. */ |
| 4441 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4442 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4443 | |
| 4444 | return mkexpr(datavbits); |
| 4445 | } |
| 4446 | |
| 4447 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4448 | /* Generate IR to do a shadow load. The helper is expected to check |
| 4449 | the validity of the address and return the V bits for that address. |
| 4450 | This can optionally be controlled by a guard, which is assumed to |
| 4451 | be True if NULL. In the case where the guard is False at runtime, |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4452 | the helper will return the didn't-do-the-call value of 0x55..55. |
| 4453 | Since that means "completely undefined result", the caller of |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4454 | this function will need to fix up the result somehow in that |
| 4455 | case. |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4456 | |
| 4457 | Caller of this function is also expected to have checked the |
| 4458 | definedness of |guard| before this point. |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4459 | */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4460 | static |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4461 | IRAtom* expr2vbits_Load ( MCEnv* mce, |
| 4462 | IREndness end, IRType ty, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4463 | IRAtom* addr, UInt bias, |
| 4464 | IRAtom* guard ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4465 | { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4466 | tl_assert(end == Iend_LE || end == Iend_BE); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4467 | switch (shadowTypeV(ty)) { |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4468 | case Ity_I8: |
| 4469 | case Ity_I16: |
| 4470 | case Ity_I32: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4471 | case Ity_I64: |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 4472 | case Ity_V128: |
sewardj | 6756454 | 2013-08-16 08:31:29 +0000 | [diff] [blame] | 4473 | case Ity_V256: |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4474 | return expr2vbits_Load_WRK(mce, end, ty, addr, bias, guard); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4475 | default: |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4476 | VG_(tool_panic)("expr2vbits_Load"); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4481 | /* The most general handler for guarded loads. Assumes the |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4482 | definedness of GUARD has already been checked by the caller. A |
| 4483 | GUARD of NULL is assumed to mean "always True". Generates code to |
| 4484 | check the definedness and validity of ADDR. |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4485 | |
| 4486 | Generate IR to do a shadow load from ADDR and return the V bits. |
| 4487 | The loaded type is TY. The loaded data is then (shadow) widened by |
| 4488 | using VWIDEN, which can be Iop_INVALID to denote a no-op. If GUARD |
| 4489 | evaluates to False at run time then the returned Vbits are simply |
| 4490 | VALT instead. Note therefore that the argument type of VWIDEN must |
| 4491 | be TY and the result type of VWIDEN must equal the type of VALT. |
| 4492 | */ |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 4493 | static |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4494 | IRAtom* expr2vbits_Load_guarded_General ( MCEnv* mce, |
| 4495 | IREndness end, IRType ty, |
| 4496 | IRAtom* addr, UInt bias, |
| 4497 | IRAtom* guard, |
| 4498 | IROp vwiden, IRAtom* valt ) |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 4499 | { |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4500 | /* Sanity check the conversion operation, and also set TYWIDE. */ |
| 4501 | IRType tyWide = Ity_INVALID; |
| 4502 | switch (vwiden) { |
| 4503 | case Iop_INVALID: |
| 4504 | tyWide = ty; |
| 4505 | break; |
| 4506 | case Iop_16Uto32: case Iop_16Sto32: case Iop_8Uto32: case Iop_8Sto32: |
| 4507 | tyWide = Ity_I32; |
| 4508 | break; |
| 4509 | default: |
| 4510 | VG_(tool_panic)("memcheck:expr2vbits_Load_guarded_General"); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 4511 | } |
| 4512 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4513 | /* If the guard evaluates to True, this will hold the loaded V bits |
| 4514 | at TY. If the guard evaluates to False, this will be all |
| 4515 | ones, meaning "all undefined", in which case we will have to |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4516 | replace it using an ITE below. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4517 | IRAtom* iftrue1 |
| 4518 | = assignNew('V', mce, ty, |
| 4519 | expr2vbits_Load(mce, end, ty, addr, bias, guard)); |
| 4520 | /* Now (shadow-) widen the loaded V bits to the desired width. In |
| 4521 | the guard-is-False case, the allowable widening operators will |
| 4522 | in the worst case (unsigned widening) at least leave the |
| 4523 | pre-widened part as being marked all-undefined, and in the best |
| 4524 | case (signed widening) mark the whole widened result as |
| 4525 | undefined. Anyway, it doesn't matter really, since in this case |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4526 | we will replace said value with the default value |valt| using an |
| 4527 | ITE. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4528 | IRAtom* iftrue2 |
| 4529 | = vwiden == Iop_INVALID |
| 4530 | ? iftrue1 |
| 4531 | : assignNew('V', mce, tyWide, unop(vwiden, iftrue1)); |
| 4532 | /* These are the V bits we will return if the load doesn't take |
| 4533 | place. */ |
| 4534 | IRAtom* iffalse |
| 4535 | = valt; |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4536 | /* Prepare the cond for the ITE. Convert a NULL cond into |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4537 | something that iropt knows how to fold out later. */ |
| 4538 | IRAtom* cond |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 4539 | = guard == NULL ? mkU1(1) : guard; |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4540 | /* And assemble the final result. */ |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4541 | return assignNew('V', mce, tyWide, IRExpr_ITE(cond, iftrue2, iffalse)); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | |
| 4545 | /* A simpler handler for guarded loads, in which there is no |
| 4546 | conversion operation, and the default V bit return (when the guard |
| 4547 | evaluates to False at runtime) is "all defined". If there is no |
| 4548 | guard expression or the guard is always TRUE this function behaves |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4549 | like expr2vbits_Load. It is assumed that definedness of GUARD has |
| 4550 | already been checked at the call site. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4551 | static |
| 4552 | IRAtom* expr2vbits_Load_guarded_Simple ( MCEnv* mce, |
| 4553 | IREndness end, IRType ty, |
| 4554 | IRAtom* addr, UInt bias, |
| 4555 | IRAtom *guard ) |
| 4556 | { |
| 4557 | return expr2vbits_Load_guarded_General( |
| 4558 | mce, end, ty, addr, bias, guard, Iop_INVALID, definedOfType(ty) |
| 4559 | ); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4563 | static |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4564 | IRAtom* expr2vbits_ITE ( MCEnv* mce, |
| 4565 | IRAtom* cond, IRAtom* iftrue, IRAtom* iffalse ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4566 | { |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4567 | IRAtom *vbitsC, *vbits0, *vbits1; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4568 | IRType ty; |
sewardj | 07bfda2 | 2013-01-29 21:11:55 +0000 | [diff] [blame] | 4569 | /* Given ITE(cond, iftrue, iffalse), generate |
| 4570 | ITE(cond, iftrue#, iffalse#) `UifU` PCast(cond#) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4571 | That is, steer the V bits like the originals, but trash the |
| 4572 | result if the steering value is undefined. This gives |
| 4573 | lazy propagation. */ |
| 4574 | tl_assert(isOriginalAtom(mce, cond)); |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4575 | tl_assert(isOriginalAtom(mce, iftrue)); |
| 4576 | tl_assert(isOriginalAtom(mce, iffalse)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4577 | |
| 4578 | vbitsC = expr2vbits(mce, cond); |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4579 | vbits1 = expr2vbits(mce, iftrue); |
sewardj | 07bfda2 | 2013-01-29 21:11:55 +0000 | [diff] [blame] | 4580 | vbits0 = expr2vbits(mce, iffalse); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4581 | ty = typeOfIRExpr(mce->sb->tyenv, vbits0); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4582 | |
| 4583 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4584 | mkUifU(mce, ty, assignNew('V', mce, ty, |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4585 | IRExpr_ITE(cond, vbits1, vbits0)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4586 | mkPCastTo(mce, ty, vbitsC) ); |
| 4587 | } |
| 4588 | |
| 4589 | /* --------- This is the main expression-handling function. --------- */ |
| 4590 | |
| 4591 | static |
| 4592 | IRExpr* expr2vbits ( MCEnv* mce, IRExpr* e ) |
| 4593 | { |
| 4594 | switch (e->tag) { |
| 4595 | |
| 4596 | case Iex_Get: |
| 4597 | return shadow_GET( mce, e->Iex.Get.offset, e->Iex.Get.ty ); |
| 4598 | |
| 4599 | case Iex_GetI: |
| 4600 | return shadow_GETI( mce, e->Iex.GetI.descr, |
| 4601 | e->Iex.GetI.ix, e->Iex.GetI.bias ); |
| 4602 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4603 | case Iex_RdTmp: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4604 | return IRExpr_RdTmp( findShadowTmpV(mce, e->Iex.RdTmp.tmp) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4605 | |
| 4606 | case Iex_Const: |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4607 | return definedOfType(shadowTypeV(typeOfIRExpr(mce->sb->tyenv, e))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4608 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 4609 | case Iex_Qop: |
| 4610 | return expr2vbits_Qop( |
| 4611 | mce, |
florian | e2ab297 | 2012-06-01 20:43:03 +0000 | [diff] [blame] | 4612 | e->Iex.Qop.details->op, |
| 4613 | e->Iex.Qop.details->arg1, e->Iex.Qop.details->arg2, |
| 4614 | e->Iex.Qop.details->arg3, e->Iex.Qop.details->arg4 |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 4615 | ); |
| 4616 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 4617 | case Iex_Triop: |
| 4618 | return expr2vbits_Triop( |
| 4619 | mce, |
florian | 2644174 | 2012-06-02 20:30:41 +0000 | [diff] [blame] | 4620 | e->Iex.Triop.details->op, |
| 4621 | e->Iex.Triop.details->arg1, e->Iex.Triop.details->arg2, |
| 4622 | e->Iex.Triop.details->arg3 |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 4623 | ); |
| 4624 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4625 | case Iex_Binop: |
| 4626 | return expr2vbits_Binop( |
| 4627 | mce, |
| 4628 | e->Iex.Binop.op, |
| 4629 | e->Iex.Binop.arg1, e->Iex.Binop.arg2 |
| 4630 | ); |
| 4631 | |
| 4632 | case Iex_Unop: |
| 4633 | return expr2vbits_Unop( mce, e->Iex.Unop.op, e->Iex.Unop.arg ); |
| 4634 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4635 | case Iex_Load: |
| 4636 | return expr2vbits_Load( mce, e->Iex.Load.end, |
| 4637 | e->Iex.Load.ty, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4638 | e->Iex.Load.addr, 0/*addr bias*/, |
| 4639 | NULL/* guard == "always True"*/ ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4640 | |
| 4641 | case Iex_CCall: |
| 4642 | return mkLazyN( mce, e->Iex.CCall.args, |
| 4643 | e->Iex.CCall.retty, |
| 4644 | e->Iex.CCall.cee ); |
| 4645 | |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 4646 | case Iex_ITE: |
| 4647 | return expr2vbits_ITE( mce, e->Iex.ITE.cond, e->Iex.ITE.iftrue, |
sewardj | 07bfda2 | 2013-01-29 21:11:55 +0000 | [diff] [blame] | 4648 | e->Iex.ITE.iffalse); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4649 | |
| 4650 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4651 | VG_(printf)("\n"); |
| 4652 | ppIRExpr(e); |
| 4653 | VG_(printf)("\n"); |
| 4654 | VG_(tool_panic)("memcheck: expr2vbits"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4655 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4659 | /*--- Generate shadow stmts from all kinds of IRStmts. ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4660 | /*------------------------------------------------------------*/ |
| 4661 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4662 | /* Widen a value to the host word size. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4663 | |
| 4664 | static |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4665 | IRExpr* zwidenToHostWord ( MCEnv* mce, IRAtom* vatom ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4666 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 4667 | IRType ty, tyH; |
| 4668 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4669 | /* vatom is vbits-value and as such can only have a shadow type. */ |
| 4670 | tl_assert(isShadowAtom(mce,vatom)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4671 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4672 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 4673 | tyH = mce->hWordTy; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4674 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4675 | if (tyH == Ity_I32) { |
| 4676 | switch (ty) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4677 | case Ity_I32: |
| 4678 | return vatom; |
| 4679 | case Ity_I16: |
| 4680 | return assignNew('V', mce, tyH, unop(Iop_16Uto32, vatom)); |
| 4681 | case Ity_I8: |
| 4682 | return assignNew('V', mce, tyH, unop(Iop_8Uto32, vatom)); |
| 4683 | default: |
| 4684 | goto unhandled; |
sewardj | 8ec2cfc | 2002-10-13 00:57:26 +0000 | [diff] [blame] | 4685 | } |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 4686 | } else |
| 4687 | if (tyH == Ity_I64) { |
| 4688 | switch (ty) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4689 | case Ity_I32: |
| 4690 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, vatom)); |
| 4691 | case Ity_I16: |
| 4692 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, |
| 4693 | assignNew('V', mce, Ity_I32, unop(Iop_16Uto32, vatom)))); |
| 4694 | case Ity_I8: |
| 4695 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, |
| 4696 | assignNew('V', mce, Ity_I32, unop(Iop_8Uto32, vatom)))); |
| 4697 | default: |
| 4698 | goto unhandled; |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 4699 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4700 | } else { |
| 4701 | goto unhandled; |
sewardj | 8ec2cfc | 2002-10-13 00:57:26 +0000 | [diff] [blame] | 4702 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4703 | unhandled: |
| 4704 | VG_(printf)("\nty = "); ppIRType(ty); VG_(printf)("\n"); |
| 4705 | VG_(tool_panic)("zwidenToHostWord"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4708 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4709 | /* Generate a shadow store. |addr| is always the original address |
| 4710 | atom. You can pass in either originals or V-bits for the data |
| 4711 | atom, but obviously not both. This function generates a check for |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4712 | the definedness and (indirectly) the validity of |addr|, but only |
| 4713 | when |guard| evaluates to True at run time (or is NULL). |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4714 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 4715 | |guard| :: Ity_I1 controls whether the store really happens; NULL |
| 4716 | means it unconditionally does. Note that |guard| itself is not |
| 4717 | checked for definedness; the caller of this function must do that |
| 4718 | if necessary. |
| 4719 | */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4720 | static |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4721 | void do_shadow_Store ( MCEnv* mce, |
| 4722 | IREndness end, |
| 4723 | IRAtom* addr, UInt bias, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4724 | IRAtom* data, IRAtom* vdata, |
| 4725 | IRAtom* guard ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4726 | { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4727 | IROp mkAdd; |
| 4728 | IRType ty, tyAddr; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4729 | void* helper = NULL; |
florian | a5f894c | 2012-10-21 03:43:20 +0000 | [diff] [blame] | 4730 | const HChar* hname = NULL; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4731 | IRConst* c; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4732 | |
| 4733 | tyAddr = mce->hWordTy; |
| 4734 | mkAdd = tyAddr==Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 4735 | tl_assert( tyAddr == Ity_I32 || tyAddr == Ity_I64 ); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4736 | tl_assert( end == Iend_LE || end == Iend_BE ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4737 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4738 | if (data) { |
| 4739 | tl_assert(!vdata); |
| 4740 | tl_assert(isOriginalAtom(mce, data)); |
| 4741 | tl_assert(bias == 0); |
| 4742 | vdata = expr2vbits( mce, data ); |
| 4743 | } else { |
| 4744 | tl_assert(vdata); |
| 4745 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4746 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4747 | tl_assert(isOriginalAtom(mce,addr)); |
| 4748 | tl_assert(isShadowAtom(mce,vdata)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4749 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4750 | if (guard) { |
| 4751 | tl_assert(isOriginalAtom(mce, guard)); |
| 4752 | tl_assert(typeOfIRExpr(mce->sb->tyenv, guard) == Ity_I1); |
| 4753 | } |
| 4754 | |
| 4755 | ty = typeOfIRExpr(mce->sb->tyenv, vdata); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4756 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4757 | // If we're not doing undefined value checking, pretend that this value |
| 4758 | // is "all valid". That lets Vex's optimiser remove some of the V bit |
| 4759 | // shadow computation ops that precede it. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4760 | if (MC_(clo_mc_level) == 1) { |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4761 | switch (ty) { |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 4762 | case Ity_V256: // V256 weirdness -- used four times |
sewardj | bd43bfa | 2012-06-29 15:29:37 +0000 | [diff] [blame] | 4763 | c = IRConst_V256(V_BITS32_DEFINED); break; |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 4764 | case Ity_V128: // V128 weirdness -- used twice |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4765 | c = IRConst_V128(V_BITS16_DEFINED); break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4766 | case Ity_I64: c = IRConst_U64 (V_BITS64_DEFINED); break; |
| 4767 | case Ity_I32: c = IRConst_U32 (V_BITS32_DEFINED); break; |
| 4768 | case Ity_I16: c = IRConst_U16 (V_BITS16_DEFINED); break; |
| 4769 | case Ity_I8: c = IRConst_U8 (V_BITS8_DEFINED); break; |
| 4770 | default: VG_(tool_panic)("memcheck:do_shadow_Store(LE)"); |
| 4771 | } |
| 4772 | vdata = IRExpr_Const( c ); |
| 4773 | } |
| 4774 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4775 | /* First, emit a definedness test for the address. This also sets |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 4776 | the address (shadow) to 'defined' following the test. Both of |
| 4777 | those actions are gated on |guard|. */ |
| 4778 | complainIfUndefined( mce, addr, guard ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4779 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4780 | /* Now decide which helper function to call to write the data V |
| 4781 | bits into shadow memory. */ |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4782 | if (end == Iend_LE) { |
| 4783 | switch (ty) { |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 4784 | case Ity_V256: /* we'll use the helper four times */ |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4785 | case Ity_V128: /* we'll use the helper twice */ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4786 | case Ity_I64: helper = &MC_(helperc_STOREV64le); |
| 4787 | hname = "MC_(helperc_STOREV64le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4788 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4789 | case Ity_I32: helper = &MC_(helperc_STOREV32le); |
| 4790 | hname = "MC_(helperc_STOREV32le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4791 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4792 | case Ity_I16: helper = &MC_(helperc_STOREV16le); |
| 4793 | hname = "MC_(helperc_STOREV16le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4794 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4795 | case Ity_I8: helper = &MC_(helperc_STOREV8); |
| 4796 | hname = "MC_(helperc_STOREV8)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4797 | break; |
| 4798 | default: VG_(tool_panic)("memcheck:do_shadow_Store(LE)"); |
| 4799 | } |
| 4800 | } else { |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4801 | switch (ty) { |
| 4802 | case Ity_V128: /* we'll use the helper twice */ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4803 | case Ity_I64: helper = &MC_(helperc_STOREV64be); |
| 4804 | hname = "MC_(helperc_STOREV64be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4805 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4806 | case Ity_I32: helper = &MC_(helperc_STOREV32be); |
| 4807 | hname = "MC_(helperc_STOREV32be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4808 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4809 | case Ity_I16: helper = &MC_(helperc_STOREV16be); |
| 4810 | hname = "MC_(helperc_STOREV16be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4811 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 4812 | case Ity_I8: helper = &MC_(helperc_STOREV8); |
| 4813 | hname = "MC_(helperc_STOREV8)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4814 | break; |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 4815 | /* Note, no V256 case here, because no big-endian target that |
| 4816 | we support, has 256 vectors. */ |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 4817 | default: VG_(tool_panic)("memcheck:do_shadow_Store(BE)"); |
| 4818 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4819 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4820 | |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 4821 | if (UNLIKELY(ty == Ity_V256)) { |
| 4822 | |
| 4823 | /* V256-bit case -- phrased in terms of 64 bit units (Qs), with |
| 4824 | Q3 being the most significant lane. */ |
| 4825 | /* These are the offsets of the Qs in memory. */ |
| 4826 | Int offQ0, offQ1, offQ2, offQ3; |
| 4827 | |
| 4828 | /* Various bits for constructing the 4 lane helper calls */ |
| 4829 | IRDirty *diQ0, *diQ1, *diQ2, *diQ3; |
| 4830 | IRAtom *addrQ0, *addrQ1, *addrQ2, *addrQ3; |
| 4831 | IRAtom *vdataQ0, *vdataQ1, *vdataQ2, *vdataQ3; |
| 4832 | IRAtom *eBiasQ0, *eBiasQ1, *eBiasQ2, *eBiasQ3; |
| 4833 | |
| 4834 | if (end == Iend_LE) { |
| 4835 | offQ0 = 0; offQ1 = 8; offQ2 = 16; offQ3 = 24; |
| 4836 | } else { |
| 4837 | offQ3 = 0; offQ2 = 8; offQ1 = 16; offQ0 = 24; |
| 4838 | } |
| 4839 | |
| 4840 | eBiasQ0 = tyAddr==Ity_I32 ? mkU32(bias+offQ0) : mkU64(bias+offQ0); |
| 4841 | addrQ0 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasQ0) ); |
| 4842 | vdataQ0 = assignNew('V', mce, Ity_I64, unop(Iop_V256to64_0, vdata)); |
| 4843 | diQ0 = unsafeIRDirty_0_N( |
| 4844 | 1/*regparms*/, |
| 4845 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4846 | mkIRExprVec_2( addrQ0, vdataQ0 ) |
| 4847 | ); |
| 4848 | |
| 4849 | eBiasQ1 = tyAddr==Ity_I32 ? mkU32(bias+offQ1) : mkU64(bias+offQ1); |
| 4850 | addrQ1 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasQ1) ); |
| 4851 | vdataQ1 = assignNew('V', mce, Ity_I64, unop(Iop_V256to64_1, vdata)); |
| 4852 | diQ1 = unsafeIRDirty_0_N( |
| 4853 | 1/*regparms*/, |
| 4854 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4855 | mkIRExprVec_2( addrQ1, vdataQ1 ) |
| 4856 | ); |
| 4857 | |
| 4858 | eBiasQ2 = tyAddr==Ity_I32 ? mkU32(bias+offQ2) : mkU64(bias+offQ2); |
| 4859 | addrQ2 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasQ2) ); |
| 4860 | vdataQ2 = assignNew('V', mce, Ity_I64, unop(Iop_V256to64_2, vdata)); |
| 4861 | diQ2 = unsafeIRDirty_0_N( |
| 4862 | 1/*regparms*/, |
| 4863 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4864 | mkIRExprVec_2( addrQ2, vdataQ2 ) |
| 4865 | ); |
| 4866 | |
| 4867 | eBiasQ3 = tyAddr==Ity_I32 ? mkU32(bias+offQ3) : mkU64(bias+offQ3); |
| 4868 | addrQ3 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasQ3) ); |
| 4869 | vdataQ3 = assignNew('V', mce, Ity_I64, unop(Iop_V256to64_3, vdata)); |
| 4870 | diQ3 = unsafeIRDirty_0_N( |
| 4871 | 1/*regparms*/, |
| 4872 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4873 | mkIRExprVec_2( addrQ3, vdataQ3 ) |
| 4874 | ); |
| 4875 | |
| 4876 | if (guard) |
| 4877 | diQ0->guard = diQ1->guard = diQ2->guard = diQ3->guard = guard; |
| 4878 | |
| 4879 | setHelperAnns( mce, diQ0 ); |
| 4880 | setHelperAnns( mce, diQ1 ); |
| 4881 | setHelperAnns( mce, diQ2 ); |
| 4882 | setHelperAnns( mce, diQ3 ); |
| 4883 | stmt( 'V', mce, IRStmt_Dirty(diQ0) ); |
| 4884 | stmt( 'V', mce, IRStmt_Dirty(diQ1) ); |
| 4885 | stmt( 'V', mce, IRStmt_Dirty(diQ2) ); |
| 4886 | stmt( 'V', mce, IRStmt_Dirty(diQ3) ); |
| 4887 | |
| 4888 | } |
| 4889 | else if (UNLIKELY(ty == Ity_V128)) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4890 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 4891 | /* V128-bit case */ |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4892 | /* See comment in next clause re 64-bit regparms */ |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4893 | /* also, need to be careful about endianness */ |
| 4894 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 4895 | Int offLo64, offHi64; |
| 4896 | IRDirty *diLo64, *diHi64; |
| 4897 | IRAtom *addrLo64, *addrHi64; |
| 4898 | IRAtom *vdataLo64, *vdataHi64; |
| 4899 | IRAtom *eBiasLo64, *eBiasHi64; |
| 4900 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4901 | if (end == Iend_LE) { |
| 4902 | offLo64 = 0; |
| 4903 | offHi64 = 8; |
| 4904 | } else { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4905 | offLo64 = 8; |
| 4906 | offHi64 = 0; |
| 4907 | } |
| 4908 | |
| 4909 | eBiasLo64 = tyAddr==Ity_I32 ? mkU32(bias+offLo64) : mkU64(bias+offLo64); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4910 | addrLo64 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasLo64) ); |
| 4911 | vdataLo64 = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, vdata)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4912 | diLo64 = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4913 | 1/*regparms*/, |
| 4914 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4915 | mkIRExprVec_2( addrLo64, vdataLo64 ) |
| 4916 | ); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4917 | eBiasHi64 = tyAddr==Ity_I32 ? mkU32(bias+offHi64) : mkU64(bias+offHi64); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4918 | addrHi64 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasHi64) ); |
| 4919 | vdataHi64 = assignNew('V', mce, Ity_I64, unop(Iop_V128HIto64, vdata)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4920 | diHi64 = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4921 | 1/*regparms*/, |
| 4922 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4923 | mkIRExprVec_2( addrHi64, vdataHi64 ) |
| 4924 | ); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4925 | if (guard) diLo64->guard = guard; |
| 4926 | if (guard) diHi64->guard = guard; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4927 | setHelperAnns( mce, diLo64 ); |
| 4928 | setHelperAnns( mce, diHi64 ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4929 | stmt( 'V', mce, IRStmt_Dirty(diLo64) ); |
| 4930 | stmt( 'V', mce, IRStmt_Dirty(diHi64) ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4931 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4932 | } else { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4933 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 4934 | IRDirty *di; |
| 4935 | IRAtom *addrAct; |
| 4936 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4937 | /* 8/16/32/64-bit cases */ |
| 4938 | /* Generate the actual address into addrAct. */ |
| 4939 | if (bias == 0) { |
| 4940 | addrAct = addr; |
| 4941 | } else { |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 4942 | IRAtom* eBias = tyAddr==Ity_I32 ? mkU32(bias) : mkU64(bias); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4943 | addrAct = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBias)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | if (ty == Ity_I64) { |
| 4947 | /* We can't do this with regparm 2 on 32-bit platforms, since |
| 4948 | the back ends aren't clever enough to handle 64-bit |
| 4949 | regparm args. Therefore be different. */ |
| 4950 | di = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4951 | 1/*regparms*/, |
| 4952 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 4953 | mkIRExprVec_2( addrAct, vdata ) |
| 4954 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4955 | } else { |
| 4956 | di = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4957 | 2/*regparms*/, |
| 4958 | hname, VG_(fnptr_to_fnentry)( helper ), |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4959 | mkIRExprVec_2( addrAct, |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4960 | zwidenToHostWord( mce, vdata )) |
| 4961 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4962 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4963 | if (guard) di->guard = guard; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 4964 | setHelperAnns( mce, di ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4965 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4966 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4967 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4968 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4969 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4970 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4971 | /* Do lazy pessimistic propagation through a dirty helper call, by |
| 4972 | looking at the annotations on it. This is the most complex part of |
| 4973 | Memcheck. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4974 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4975 | static IRType szToITy ( Int n ) |
| 4976 | { |
| 4977 | switch (n) { |
| 4978 | case 1: return Ity_I8; |
| 4979 | case 2: return Ity_I16; |
| 4980 | case 4: return Ity_I32; |
| 4981 | case 8: return Ity_I64; |
| 4982 | default: VG_(tool_panic)("szToITy(memcheck)"); |
| 4983 | } |
| 4984 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4985 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4986 | static |
| 4987 | void do_shadow_Dirty ( MCEnv* mce, IRDirty* d ) |
| 4988 | { |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 4989 | Int i, k, n, toDo, gSz, gOff; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4990 | IRAtom *src, *here, *curr; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 4991 | IRType tySrc, tyDst; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4992 | IRTemp dst; |
| 4993 | IREndness end; |
| 4994 | |
| 4995 | /* What's the native endianness? We need to know this. */ |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 4996 | # if defined(VG_BIGENDIAN) |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4997 | end = Iend_BE; |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 4998 | # elif defined(VG_LITTLEENDIAN) |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4999 | end = Iend_LE; |
| 5000 | # else |
| 5001 | # error "Unknown endianness" |
| 5002 | # endif |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5003 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5004 | /* First check the guard. */ |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 5005 | complainIfUndefined(mce, d->guard, NULL); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5006 | |
| 5007 | /* Now round up all inputs and PCast over them. */ |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 5008 | curr = definedOfType(Ity_I32); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5009 | |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5010 | /* Inputs: unmasked args |
| 5011 | Note: arguments are evaluated REGARDLESS of the guard expression */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5012 | for (i = 0; d->args[i]; i++) { |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 5013 | IRAtom* arg = d->args[i]; |
| 5014 | if ( (d->cee->mcx_mask & (1<<i)) |
florian | a5c3ecb | 2013-08-15 20:55:42 +0000 | [diff] [blame] | 5015 | || UNLIKELY(is_IRExpr_VECRET_or_BBPTR(arg)) ) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5016 | /* ignore this arg */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5017 | } else { |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 5018 | here = mkPCastTo( mce, Ity_I32, expr2vbits(mce, arg) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5019 | curr = mkUifU32(mce, here, curr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5020 | } |
| 5021 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5022 | |
| 5023 | /* Inputs: guest state that we read. */ |
| 5024 | for (i = 0; i < d->nFxState; i++) { |
| 5025 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 5026 | if (d->fxState[i].fx == Ifx_Write) |
| 5027 | continue; |
sewardj | a720325 | 2004-11-26 19:17:47 +0000 | [diff] [blame] | 5028 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5029 | /* Enumerate the described state segments */ |
| 5030 | for (k = 0; k < 1 + d->fxState[i].nRepeats; k++) { |
| 5031 | gOff = d->fxState[i].offset + k * d->fxState[i].repeatLen; |
| 5032 | gSz = d->fxState[i].size; |
sewardj | a720325 | 2004-11-26 19:17:47 +0000 | [diff] [blame] | 5033 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5034 | /* Ignore any sections marked as 'always defined'. */ |
| 5035 | if (isAlwaysDefd(mce, gOff, gSz)) { |
| 5036 | if (0) |
| 5037 | VG_(printf)("memcheck: Dirty gst: ignored off %d, sz %d\n", |
| 5038 | gOff, gSz); |
| 5039 | continue; |
| 5040 | } |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 5041 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5042 | /* This state element is read or modified. So we need to |
| 5043 | consider it. If larger than 8 bytes, deal with it in |
| 5044 | 8-byte chunks. */ |
| 5045 | while (True) { |
| 5046 | tl_assert(gSz >= 0); |
| 5047 | if (gSz == 0) break; |
| 5048 | n = gSz <= 8 ? gSz : 8; |
| 5049 | /* update 'curr' with UifU of the state slice |
| 5050 | gOff .. gOff+n-1 */ |
| 5051 | tySrc = szToITy( n ); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5052 | |
| 5053 | /* Observe the guard expression. If it is false use an |
| 5054 | all-bits-defined bit pattern */ |
| 5055 | IRAtom *cond, *iffalse, *iftrue; |
| 5056 | |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 5057 | cond = assignNew('V', mce, Ity_I1, d->guard); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5058 | iftrue = assignNew('V', mce, tySrc, shadow_GET(mce, gOff, tySrc)); |
| 5059 | iffalse = assignNew('V', mce, tySrc, definedOfType(tySrc)); |
| 5060 | src = assignNew('V', mce, tySrc, |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 5061 | IRExpr_ITE(cond, iftrue, iffalse)); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5062 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5063 | here = mkPCastTo( mce, Ity_I32, src ); |
| 5064 | curr = mkUifU32(mce, here, curr); |
| 5065 | gSz -= n; |
| 5066 | gOff += n; |
| 5067 | } |
| 5068 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | /* Inputs: memory. First set up some info needed regardless of |
| 5072 | whether we're doing reads or writes. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5073 | |
| 5074 | if (d->mFx != Ifx_None) { |
| 5075 | /* Because we may do multiple shadow loads/stores from the same |
| 5076 | base address, it's best to do a single test of its |
| 5077 | definedness right now. Post-instrumentation optimisation |
| 5078 | should remove all but this test. */ |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 5079 | IRType tyAddr; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5080 | tl_assert(d->mAddr); |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 5081 | complainIfUndefined(mce, d->mAddr, d->guard); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5082 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5083 | tyAddr = typeOfIRExpr(mce->sb->tyenv, d->mAddr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5084 | tl_assert(tyAddr == Ity_I32 || tyAddr == Ity_I64); |
| 5085 | tl_assert(tyAddr == mce->hWordTy); /* not really right */ |
| 5086 | } |
| 5087 | |
| 5088 | /* Deal with memory inputs (reads or modifies) */ |
| 5089 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5090 | toDo = d->mSize; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5091 | /* chew off 32-bit chunks. We don't care about the endianness |
| 5092 | since it's all going to be condensed down to a single bit, |
| 5093 | but nevertheless choose an endianness which is hopefully |
| 5094 | native to the platform. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5095 | while (toDo >= 4) { |
| 5096 | here = mkPCastTo( |
| 5097 | mce, Ity_I32, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5098 | expr2vbits_Load_guarded_Simple( |
| 5099 | mce, end, Ity_I32, d->mAddr, d->mSize - toDo, d->guard ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5100 | ); |
| 5101 | curr = mkUifU32(mce, here, curr); |
| 5102 | toDo -= 4; |
| 5103 | } |
| 5104 | /* chew off 16-bit chunks */ |
| 5105 | while (toDo >= 2) { |
| 5106 | here = mkPCastTo( |
| 5107 | mce, Ity_I32, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5108 | expr2vbits_Load_guarded_Simple( |
| 5109 | mce, end, Ity_I16, d->mAddr, d->mSize - toDo, d->guard ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5110 | ); |
| 5111 | curr = mkUifU32(mce, here, curr); |
| 5112 | toDo -= 2; |
| 5113 | } |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 5114 | /* chew off the remaining 8-bit chunk, if any */ |
| 5115 | if (toDo == 1) { |
| 5116 | here = mkPCastTo( |
| 5117 | mce, Ity_I32, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5118 | expr2vbits_Load_guarded_Simple( |
| 5119 | mce, end, Ity_I8, d->mAddr, d->mSize - toDo, d->guard ) |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 5120 | ); |
| 5121 | curr = mkUifU32(mce, here, curr); |
| 5122 | toDo -= 1; |
| 5123 | } |
| 5124 | tl_assert(toDo == 0); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | /* Whew! So curr is a 32-bit V-value summarising pessimistically |
| 5128 | all the inputs to the helper. Now we need to re-distribute the |
| 5129 | results to all destinations. */ |
| 5130 | |
| 5131 | /* Outputs: the destination temporary, if there is one. */ |
| 5132 | if (d->tmp != IRTemp_INVALID) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5133 | dst = findShadowTmpV(mce, d->tmp); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5134 | tyDst = typeOfIRTemp(mce->sb->tyenv, d->tmp); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5135 | assign( 'V', mce, dst, mkPCastTo( mce, tyDst, curr) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5136 | } |
| 5137 | |
| 5138 | /* Outputs: guest state that we write or modify. */ |
| 5139 | for (i = 0; i < d->nFxState; i++) { |
| 5140 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 5141 | if (d->fxState[i].fx == Ifx_Read) |
| 5142 | continue; |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5143 | |
| 5144 | /* Enumerate the described state segments */ |
| 5145 | for (k = 0; k < 1 + d->fxState[i].nRepeats; k++) { |
| 5146 | gOff = d->fxState[i].offset + k * d->fxState[i].repeatLen; |
| 5147 | gSz = d->fxState[i].size; |
| 5148 | |
| 5149 | /* Ignore any sections marked as 'always defined'. */ |
| 5150 | if (isAlwaysDefd(mce, gOff, gSz)) |
| 5151 | continue; |
| 5152 | |
| 5153 | /* This state element is written or modified. So we need to |
| 5154 | consider it. If larger than 8 bytes, deal with it in |
| 5155 | 8-byte chunks. */ |
| 5156 | while (True) { |
| 5157 | tl_assert(gSz >= 0); |
| 5158 | if (gSz == 0) break; |
| 5159 | n = gSz <= 8 ? gSz : 8; |
| 5160 | /* Write suitably-casted 'curr' to the state slice |
| 5161 | gOff .. gOff+n-1 */ |
| 5162 | tyDst = szToITy( n ); |
| 5163 | do_shadow_PUT( mce, gOff, |
| 5164 | NULL, /* original atom */ |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5165 | mkPCastTo( mce, tyDst, curr ), d->guard ); |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 5166 | gSz -= n; |
| 5167 | gOff += n; |
| 5168 | } |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 5169 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5170 | } |
| 5171 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5172 | /* Outputs: memory that we write or modify. Same comments about |
| 5173 | endianness as above apply. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5174 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5175 | toDo = d->mSize; |
| 5176 | /* chew off 32-bit chunks */ |
| 5177 | while (toDo >= 4) { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5178 | do_shadow_Store( mce, end, d->mAddr, d->mSize - toDo, |
| 5179 | NULL, /* original data */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5180 | mkPCastTo( mce, Ity_I32, curr ), |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5181 | d->guard ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5182 | toDo -= 4; |
| 5183 | } |
| 5184 | /* chew off 16-bit chunks */ |
| 5185 | while (toDo >= 2) { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5186 | do_shadow_Store( mce, end, d->mAddr, d->mSize - toDo, |
| 5187 | NULL, /* original data */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5188 | mkPCastTo( mce, Ity_I16, curr ), |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5189 | d->guard ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5190 | toDo -= 2; |
| 5191 | } |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 5192 | /* chew off the remaining 8-bit chunk, if any */ |
| 5193 | if (toDo == 1) { |
| 5194 | do_shadow_Store( mce, end, d->mAddr, d->mSize - toDo, |
| 5195 | NULL, /* original data */ |
| 5196 | mkPCastTo( mce, Ity_I8, curr ), |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 5197 | d->guard ); |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 5198 | toDo -= 1; |
| 5199 | } |
| 5200 | tl_assert(toDo == 0); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5201 | } |
| 5202 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5205 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5206 | /* We have an ABI hint telling us that [base .. base+len-1] is to |
| 5207 | become undefined ("writable"). Generate code to call a helper to |
| 5208 | notify the A/V bit machinery of this fact. |
| 5209 | |
| 5210 | We call |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5211 | void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len, |
| 5212 | Addr nia ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5213 | */ |
| 5214 | static |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5215 | void do_AbiHint ( MCEnv* mce, IRExpr* base, Int len, IRExpr* nia ) |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5216 | { |
| 5217 | IRDirty* di; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5218 | /* Minor optimisation: if not doing origin tracking, ignore the |
| 5219 | supplied nia and pass zero instead. This is on the basis that |
| 5220 | MC_(helperc_MAKE_STACK_UNINIT) will ignore it anyway, and we can |
| 5221 | almost always generate a shorter instruction to put zero into a |
| 5222 | register than any other value. */ |
| 5223 | if (MC_(clo_mc_level) < 3) |
| 5224 | nia = mkIRExpr_HWord(0); |
| 5225 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5226 | di = unsafeIRDirty_0_N( |
| 5227 | 0/*regparms*/, |
| 5228 | "MC_(helperc_MAKE_STACK_UNINIT)", |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 5229 | VG_(fnptr_to_fnentry)( &MC_(helperc_MAKE_STACK_UNINIT) ), |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5230 | mkIRExprVec_3( base, mkIRExpr_HWord( (UInt)len), nia ) |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5231 | ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5232 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5235 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5236 | /* ------ Dealing with IRCAS (big and complex) ------ */ |
| 5237 | |
| 5238 | /* FWDS */ |
| 5239 | static IRAtom* gen_load_b ( MCEnv* mce, Int szB, |
| 5240 | IRAtom* baseaddr, Int offset ); |
| 5241 | static IRAtom* gen_maxU32 ( MCEnv* mce, IRAtom* b1, IRAtom* b2 ); |
| 5242 | static void gen_store_b ( MCEnv* mce, Int szB, |
| 5243 | IRAtom* baseaddr, Int offset, IRAtom* dataB, |
| 5244 | IRAtom* guard ); |
| 5245 | |
| 5246 | static void do_shadow_CAS_single ( MCEnv* mce, IRCAS* cas ); |
| 5247 | static void do_shadow_CAS_double ( MCEnv* mce, IRCAS* cas ); |
| 5248 | |
| 5249 | |
| 5250 | /* Either ORIG and SHADOW are both IRExpr.RdTmps, or they are both |
| 5251 | IRExpr.Consts, else this asserts. If they are both Consts, it |
| 5252 | doesn't do anything. So that just leaves the RdTmp case. |
| 5253 | |
| 5254 | In which case: this assigns the shadow value SHADOW to the IR |
| 5255 | shadow temporary associated with ORIG. That is, ORIG, being an |
| 5256 | original temporary, will have a shadow temporary associated with |
| 5257 | it. However, in the case envisaged here, there will so far have |
| 5258 | been no IR emitted to actually write a shadow value into that |
| 5259 | temporary. What this routine does is to (emit IR to) copy the |
| 5260 | value in SHADOW into said temporary, so that after this call, |
| 5261 | IRExpr.RdTmps of ORIG's shadow temp will correctly pick up the |
| 5262 | value in SHADOW. |
| 5263 | |
| 5264 | Point is to allow callers to compute "by hand" a shadow value for |
| 5265 | ORIG, and force it to be associated with ORIG. |
| 5266 | |
| 5267 | How do we know that that shadow associated with ORIG has not so far |
| 5268 | been assigned to? Well, we don't per se know that, but supposing |
| 5269 | it had. Then this routine would create a second assignment to it, |
| 5270 | and later the IR sanity checker would barf. But that never |
| 5271 | happens. QED. |
| 5272 | */ |
| 5273 | static void bind_shadow_tmp_to_orig ( UChar how, |
| 5274 | MCEnv* mce, |
| 5275 | IRAtom* orig, IRAtom* shadow ) |
| 5276 | { |
| 5277 | tl_assert(isOriginalAtom(mce, orig)); |
| 5278 | tl_assert(isShadowAtom(mce, shadow)); |
| 5279 | switch (orig->tag) { |
| 5280 | case Iex_Const: |
| 5281 | tl_assert(shadow->tag == Iex_Const); |
| 5282 | break; |
| 5283 | case Iex_RdTmp: |
| 5284 | tl_assert(shadow->tag == Iex_RdTmp); |
| 5285 | if (how == 'V') { |
| 5286 | assign('V', mce, findShadowTmpV(mce,orig->Iex.RdTmp.tmp), |
| 5287 | shadow); |
| 5288 | } else { |
| 5289 | tl_assert(how == 'B'); |
| 5290 | assign('B', mce, findShadowTmpB(mce,orig->Iex.RdTmp.tmp), |
| 5291 | shadow); |
| 5292 | } |
| 5293 | break; |
| 5294 | default: |
| 5295 | tl_assert(0); |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | |
| 5300 | static |
| 5301 | void do_shadow_CAS ( MCEnv* mce, IRCAS* cas ) |
| 5302 | { |
| 5303 | /* Scheme is (both single- and double- cases): |
| 5304 | |
| 5305 | 1. fetch data#,dataB (the proposed new value) |
| 5306 | |
| 5307 | 2. fetch expd#,expdB (what we expect to see at the address) |
| 5308 | |
| 5309 | 3. check definedness of address |
| 5310 | |
| 5311 | 4. load old#,oldB from shadow memory; this also checks |
| 5312 | addressibility of the address |
| 5313 | |
| 5314 | 5. the CAS itself |
| 5315 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5316 | 6. compute "expected == old". See COMMENT_ON_CasCmpEQ below. |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5317 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5318 | 7. if "expected == old" (as computed by (6)) |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5319 | store data#,dataB to shadow memory |
| 5320 | |
| 5321 | Note that 5 reads 'old' but 4 reads 'old#'. Similarly, 5 stores |
| 5322 | 'data' but 7 stores 'data#'. Hence it is possible for the |
| 5323 | shadow data to be incorrectly checked and/or updated: |
| 5324 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5325 | * 7 is at least gated correctly, since the 'expected == old' |
| 5326 | condition is derived from outputs of 5. However, the shadow |
| 5327 | write could happen too late: imagine after 5 we are |
| 5328 | descheduled, a different thread runs, writes a different |
| 5329 | (shadow) value at the address, and then we resume, hence |
| 5330 | overwriting the shadow value written by the other thread. |
| 5331 | |
| 5332 | Because the original memory access is atomic, there's no way to |
| 5333 | make both the original and shadow accesses into a single atomic |
| 5334 | thing, hence this is unavoidable. |
| 5335 | |
| 5336 | At least as Valgrind stands, I don't think it's a problem, since |
| 5337 | we're single threaded *and* we guarantee that there are no |
| 5338 | context switches during the execution of any specific superblock |
| 5339 | -- context switches can only happen at superblock boundaries. |
| 5340 | |
| 5341 | If Valgrind ever becomes MT in the future, then it might be more |
| 5342 | of a problem. A possible kludge would be to artificially |
| 5343 | associate with the location, a lock, which we must acquire and |
| 5344 | release around the transaction as a whole. Hmm, that probably |
| 5345 | would't work properly since it only guards us against other |
| 5346 | threads doing CASs on the same location, not against other |
| 5347 | threads doing normal reads and writes. |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5348 | |
| 5349 | ------------------------------------------------------------ |
| 5350 | |
| 5351 | COMMENT_ON_CasCmpEQ: |
| 5352 | |
| 5353 | Note two things. Firstly, in the sequence above, we compute |
| 5354 | "expected == old", but we don't check definedness of it. Why |
| 5355 | not? Also, the x86 and amd64 front ends use |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 5356 | Iop_CasCmp{EQ,NE}{8,16,32,64} comparisons to make the equivalent |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5357 | determination (expected == old ?) for themselves, and we also |
| 5358 | don't check definedness for those primops; we just say that the |
| 5359 | result is defined. Why? Details follow. |
| 5360 | |
| 5361 | x86/amd64 contains various forms of locked insns: |
| 5362 | * lock prefix before all basic arithmetic insn; |
| 5363 | eg lock xorl %reg1,(%reg2) |
| 5364 | * atomic exchange reg-mem |
| 5365 | * compare-and-swaps |
| 5366 | |
| 5367 | Rather than attempt to represent them all, which would be a |
| 5368 | royal PITA, I used a result from Maurice Herlihy |
| 5369 | (http://en.wikipedia.org/wiki/Maurice_Herlihy), in which he |
| 5370 | demonstrates that compare-and-swap is a primitive more general |
| 5371 | than the other two, and so can be used to represent all of them. |
| 5372 | So the translation scheme for (eg) lock incl (%reg) is as |
| 5373 | follows: |
| 5374 | |
| 5375 | again: |
| 5376 | old = * %reg |
| 5377 | new = old + 1 |
| 5378 | atomically { if (* %reg == old) { * %reg = new } else { goto again } } |
| 5379 | |
| 5380 | The "atomically" is the CAS bit. The scheme is always the same: |
| 5381 | get old value from memory, compute new value, atomically stuff |
| 5382 | new value back in memory iff the old value has not changed (iow, |
| 5383 | no other thread modified it in the meantime). If it has changed |
| 5384 | then we've been out-raced and we have to start over. |
| 5385 | |
| 5386 | Now that's all very neat, but it has the bad side effect of |
| 5387 | introducing an explicit equality test into the translation. |
| 5388 | Consider the behaviour of said code on a memory location which |
| 5389 | is uninitialised. We will wind up doing a comparison on |
| 5390 | uninitialised data, and mc duly complains. |
| 5391 | |
| 5392 | What's difficult about this is, the common case is that the |
| 5393 | location is uncontended, and so we're usually comparing the same |
| 5394 | value (* %reg) with itself. So we shouldn't complain even if it |
| 5395 | is undefined. But mc doesn't know that. |
| 5396 | |
| 5397 | My solution is to mark the == in the IR specially, so as to tell |
| 5398 | mc that it almost certainly compares a value with itself, and we |
| 5399 | should just regard the result as always defined. Rather than |
| 5400 | add a bit to all IROps, I just cloned Iop_CmpEQ{8,16,32,64} into |
| 5401 | Iop_CasCmpEQ{8,16,32,64} so as not to disturb anything else. |
| 5402 | |
| 5403 | So there's always the question of, can this give a false |
| 5404 | negative? eg, imagine that initially, * %reg is defined; and we |
| 5405 | read that; but then in the gap between the read and the CAS, a |
| 5406 | different thread writes an undefined (and different) value at |
| 5407 | the location. Then the CAS in this thread will fail and we will |
| 5408 | go back to "again:", but without knowing that the trip back |
| 5409 | there was based on an undefined comparison. No matter; at least |
| 5410 | the other thread won the race and the location is correctly |
| 5411 | marked as undefined. What if it wrote an uninitialised version |
| 5412 | of the same value that was there originally, though? |
| 5413 | |
| 5414 | etc etc. Seems like there's a small corner case in which we |
| 5415 | might lose the fact that something's defined -- we're out-raced |
| 5416 | in between the "old = * reg" and the "atomically {", _and_ the |
| 5417 | other thread is writing in an undefined version of what's |
| 5418 | already there. Well, that seems pretty unlikely. |
| 5419 | |
| 5420 | --- |
| 5421 | |
| 5422 | If we ever need to reinstate it .. code which generates a |
| 5423 | definedness test for "expected == old" was removed at r10432 of |
| 5424 | this file. |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5425 | */ |
| 5426 | if (cas->oldHi == IRTemp_INVALID) { |
| 5427 | do_shadow_CAS_single( mce, cas ); |
| 5428 | } else { |
| 5429 | do_shadow_CAS_double( mce, cas ); |
| 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | |
| 5434 | static void do_shadow_CAS_single ( MCEnv* mce, IRCAS* cas ) |
| 5435 | { |
| 5436 | IRAtom *vdataLo = NULL, *bdataLo = NULL; |
| 5437 | IRAtom *vexpdLo = NULL, *bexpdLo = NULL; |
| 5438 | IRAtom *voldLo = NULL, *boldLo = NULL; |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5439 | IRAtom *expd_eq_old = NULL; |
| 5440 | IROp opCasCmpEQ; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5441 | Int elemSzB; |
| 5442 | IRType elemTy; |
| 5443 | Bool otrak = MC_(clo_mc_level) >= 3; /* a shorthand */ |
| 5444 | |
| 5445 | /* single CAS */ |
| 5446 | tl_assert(cas->oldHi == IRTemp_INVALID); |
| 5447 | tl_assert(cas->expdHi == NULL); |
| 5448 | tl_assert(cas->dataHi == NULL); |
| 5449 | |
| 5450 | elemTy = typeOfIRExpr(mce->sb->tyenv, cas->expdLo); |
| 5451 | switch (elemTy) { |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5452 | case Ity_I8: elemSzB = 1; opCasCmpEQ = Iop_CasCmpEQ8; break; |
| 5453 | case Ity_I16: elemSzB = 2; opCasCmpEQ = Iop_CasCmpEQ16; break; |
| 5454 | case Ity_I32: elemSzB = 4; opCasCmpEQ = Iop_CasCmpEQ32; break; |
| 5455 | case Ity_I64: elemSzB = 8; opCasCmpEQ = Iop_CasCmpEQ64; break; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5456 | default: tl_assert(0); /* IR defn disallows any other types */ |
| 5457 | } |
| 5458 | |
| 5459 | /* 1. fetch data# (the proposed new value) */ |
| 5460 | tl_assert(isOriginalAtom(mce, cas->dataLo)); |
| 5461 | vdataLo |
| 5462 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataLo)); |
| 5463 | tl_assert(isShadowAtom(mce, vdataLo)); |
| 5464 | if (otrak) { |
| 5465 | bdataLo |
| 5466 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataLo)); |
| 5467 | tl_assert(isShadowAtom(mce, bdataLo)); |
| 5468 | } |
| 5469 | |
| 5470 | /* 2. fetch expected# (what we expect to see at the address) */ |
| 5471 | tl_assert(isOriginalAtom(mce, cas->expdLo)); |
| 5472 | vexpdLo |
| 5473 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdLo)); |
| 5474 | tl_assert(isShadowAtom(mce, vexpdLo)); |
| 5475 | if (otrak) { |
| 5476 | bexpdLo |
| 5477 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdLo)); |
| 5478 | tl_assert(isShadowAtom(mce, bexpdLo)); |
| 5479 | } |
| 5480 | |
| 5481 | /* 3. check definedness of address */ |
| 5482 | /* 4. fetch old# from shadow memory; this also checks |
| 5483 | addressibility of the address */ |
| 5484 | voldLo |
| 5485 | = assignNew( |
| 5486 | 'V', mce, elemTy, |
| 5487 | expr2vbits_Load( |
| 5488 | mce, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5489 | cas->end, elemTy, cas->addr, 0/*Addr bias*/, |
| 5490 | NULL/*always happens*/ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5491 | )); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5492 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldLo), voldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5493 | if (otrak) { |
| 5494 | boldLo |
| 5495 | = assignNew('B', mce, Ity_I32, |
| 5496 | gen_load_b(mce, elemSzB, cas->addr, 0/*addr bias*/)); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5497 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldLo), boldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | /* 5. the CAS itself */ |
| 5501 | stmt( 'C', mce, IRStmt_CAS(cas) ); |
| 5502 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5503 | /* 6. compute "expected == old" */ |
| 5504 | /* See COMMENT_ON_CasCmpEQ in this file background/rationale. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5505 | /* Note that 'C' is kinda faking it; it is indeed a non-shadow |
| 5506 | tree, but it's not copied from the input block. */ |
| 5507 | expd_eq_old |
| 5508 | = assignNew('C', mce, Ity_I1, |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5509 | binop(opCasCmpEQ, cas->expdLo, mkexpr(cas->oldLo))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5510 | |
| 5511 | /* 7. if "expected == old" |
| 5512 | store data# to shadow memory */ |
| 5513 | do_shadow_Store( mce, cas->end, cas->addr, 0/*bias*/, |
| 5514 | NULL/*data*/, vdataLo/*vdata*/, |
| 5515 | expd_eq_old/*guard for store*/ ); |
| 5516 | if (otrak) { |
| 5517 | gen_store_b( mce, elemSzB, cas->addr, 0/*offset*/, |
| 5518 | bdataLo/*bdata*/, |
| 5519 | expd_eq_old/*guard for store*/ ); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | |
| 5524 | static void do_shadow_CAS_double ( MCEnv* mce, IRCAS* cas ) |
| 5525 | { |
| 5526 | IRAtom *vdataHi = NULL, *bdataHi = NULL; |
| 5527 | IRAtom *vdataLo = NULL, *bdataLo = NULL; |
| 5528 | IRAtom *vexpdHi = NULL, *bexpdHi = NULL; |
| 5529 | IRAtom *vexpdLo = NULL, *bexpdLo = NULL; |
| 5530 | IRAtom *voldHi = NULL, *boldHi = NULL; |
| 5531 | IRAtom *voldLo = NULL, *boldLo = NULL; |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5532 | IRAtom *xHi = NULL, *xLo = NULL, *xHL = NULL; |
| 5533 | IRAtom *expd_eq_old = NULL, *zero = NULL; |
| 5534 | IROp opCasCmpEQ, opOr, opXor; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5535 | Int elemSzB, memOffsLo, memOffsHi; |
| 5536 | IRType elemTy; |
| 5537 | Bool otrak = MC_(clo_mc_level) >= 3; /* a shorthand */ |
| 5538 | |
| 5539 | /* double CAS */ |
| 5540 | tl_assert(cas->oldHi != IRTemp_INVALID); |
| 5541 | tl_assert(cas->expdHi != NULL); |
| 5542 | tl_assert(cas->dataHi != NULL); |
| 5543 | |
| 5544 | elemTy = typeOfIRExpr(mce->sb->tyenv, cas->expdLo); |
| 5545 | switch (elemTy) { |
| 5546 | case Ity_I8: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5547 | opCasCmpEQ = Iop_CasCmpEQ8; opOr = Iop_Or8; opXor = Iop_Xor8; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5548 | elemSzB = 1; zero = mkU8(0); |
| 5549 | break; |
| 5550 | case Ity_I16: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5551 | opCasCmpEQ = Iop_CasCmpEQ16; opOr = Iop_Or16; opXor = Iop_Xor16; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5552 | elemSzB = 2; zero = mkU16(0); |
| 5553 | break; |
| 5554 | case Ity_I32: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5555 | opCasCmpEQ = Iop_CasCmpEQ32; opOr = Iop_Or32; opXor = Iop_Xor32; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5556 | elemSzB = 4; zero = mkU32(0); |
| 5557 | break; |
| 5558 | case Ity_I64: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5559 | opCasCmpEQ = Iop_CasCmpEQ64; opOr = Iop_Or64; opXor = Iop_Xor64; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5560 | elemSzB = 8; zero = mkU64(0); |
| 5561 | break; |
| 5562 | default: |
| 5563 | tl_assert(0); /* IR defn disallows any other types */ |
| 5564 | } |
| 5565 | |
| 5566 | /* 1. fetch data# (the proposed new value) */ |
| 5567 | tl_assert(isOriginalAtom(mce, cas->dataHi)); |
| 5568 | tl_assert(isOriginalAtom(mce, cas->dataLo)); |
| 5569 | vdataHi |
| 5570 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataHi)); |
| 5571 | vdataLo |
| 5572 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataLo)); |
| 5573 | tl_assert(isShadowAtom(mce, vdataHi)); |
| 5574 | tl_assert(isShadowAtom(mce, vdataLo)); |
| 5575 | if (otrak) { |
| 5576 | bdataHi |
| 5577 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataHi)); |
| 5578 | bdataLo |
| 5579 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataLo)); |
| 5580 | tl_assert(isShadowAtom(mce, bdataHi)); |
| 5581 | tl_assert(isShadowAtom(mce, bdataLo)); |
| 5582 | } |
| 5583 | |
| 5584 | /* 2. fetch expected# (what we expect to see at the address) */ |
| 5585 | tl_assert(isOriginalAtom(mce, cas->expdHi)); |
| 5586 | tl_assert(isOriginalAtom(mce, cas->expdLo)); |
| 5587 | vexpdHi |
| 5588 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdHi)); |
| 5589 | vexpdLo |
| 5590 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdLo)); |
| 5591 | tl_assert(isShadowAtom(mce, vexpdHi)); |
| 5592 | tl_assert(isShadowAtom(mce, vexpdLo)); |
| 5593 | if (otrak) { |
| 5594 | bexpdHi |
| 5595 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdHi)); |
| 5596 | bexpdLo |
| 5597 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdLo)); |
| 5598 | tl_assert(isShadowAtom(mce, bexpdHi)); |
| 5599 | tl_assert(isShadowAtom(mce, bexpdLo)); |
| 5600 | } |
| 5601 | |
| 5602 | /* 3. check definedness of address */ |
| 5603 | /* 4. fetch old# from shadow memory; this also checks |
| 5604 | addressibility of the address */ |
| 5605 | if (cas->end == Iend_LE) { |
| 5606 | memOffsLo = 0; |
| 5607 | memOffsHi = elemSzB; |
| 5608 | } else { |
| 5609 | tl_assert(cas->end == Iend_BE); |
| 5610 | memOffsLo = elemSzB; |
| 5611 | memOffsHi = 0; |
| 5612 | } |
| 5613 | voldHi |
| 5614 | = assignNew( |
| 5615 | 'V', mce, elemTy, |
| 5616 | expr2vbits_Load( |
| 5617 | mce, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5618 | cas->end, elemTy, cas->addr, memOffsHi/*Addr bias*/, |
| 5619 | NULL/*always happens*/ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5620 | )); |
| 5621 | voldLo |
| 5622 | = assignNew( |
| 5623 | 'V', mce, elemTy, |
| 5624 | expr2vbits_Load( |
| 5625 | mce, |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5626 | cas->end, elemTy, cas->addr, memOffsLo/*Addr bias*/, |
| 5627 | NULL/*always happens*/ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5628 | )); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5629 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldHi), voldHi); |
| 5630 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldLo), voldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5631 | if (otrak) { |
| 5632 | boldHi |
| 5633 | = assignNew('B', mce, Ity_I32, |
| 5634 | gen_load_b(mce, elemSzB, cas->addr, |
| 5635 | memOffsHi/*addr bias*/)); |
| 5636 | boldLo |
| 5637 | = assignNew('B', mce, Ity_I32, |
| 5638 | gen_load_b(mce, elemSzB, cas->addr, |
| 5639 | memOffsLo/*addr bias*/)); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5640 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldHi), boldHi); |
| 5641 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldLo), boldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | /* 5. the CAS itself */ |
| 5645 | stmt( 'C', mce, IRStmt_CAS(cas) ); |
| 5646 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5647 | /* 6. compute "expected == old" */ |
| 5648 | /* See COMMENT_ON_CasCmpEQ in this file background/rationale. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5649 | /* Note that 'C' is kinda faking it; it is indeed a non-shadow |
| 5650 | tree, but it's not copied from the input block. */ |
| 5651 | /* |
| 5652 | xHi = oldHi ^ expdHi; |
| 5653 | xLo = oldLo ^ expdLo; |
| 5654 | xHL = xHi | xLo; |
| 5655 | expd_eq_old = xHL == 0; |
| 5656 | */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5657 | xHi = assignNew('C', mce, elemTy, |
| 5658 | binop(opXor, cas->expdHi, mkexpr(cas->oldHi))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5659 | xLo = assignNew('C', mce, elemTy, |
| 5660 | binop(opXor, cas->expdLo, mkexpr(cas->oldLo))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5661 | xHL = assignNew('C', mce, elemTy, |
| 5662 | binop(opOr, xHi, xLo)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5663 | expd_eq_old |
| 5664 | = assignNew('C', mce, Ity_I1, |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5665 | binop(opCasCmpEQ, xHL, zero)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5666 | |
| 5667 | /* 7. if "expected == old" |
| 5668 | store data# to shadow memory */ |
| 5669 | do_shadow_Store( mce, cas->end, cas->addr, memOffsHi/*bias*/, |
| 5670 | NULL/*data*/, vdataHi/*vdata*/, |
| 5671 | expd_eq_old/*guard for store*/ ); |
| 5672 | do_shadow_Store( mce, cas->end, cas->addr, memOffsLo/*bias*/, |
| 5673 | NULL/*data*/, vdataLo/*vdata*/, |
| 5674 | expd_eq_old/*guard for store*/ ); |
| 5675 | if (otrak) { |
| 5676 | gen_store_b( mce, elemSzB, cas->addr, memOffsHi/*offset*/, |
| 5677 | bdataHi/*bdata*/, |
| 5678 | expd_eq_old/*guard for store*/ ); |
| 5679 | gen_store_b( mce, elemSzB, cas->addr, memOffsLo/*offset*/, |
| 5680 | bdataLo/*bdata*/, |
| 5681 | expd_eq_old/*guard for store*/ ); |
| 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5686 | /* ------ Dealing with LL/SC (not difficult) ------ */ |
| 5687 | |
| 5688 | static void do_shadow_LLSC ( MCEnv* mce, |
| 5689 | IREndness stEnd, |
| 5690 | IRTemp stResult, |
| 5691 | IRExpr* stAddr, |
| 5692 | IRExpr* stStoredata ) |
| 5693 | { |
| 5694 | /* In short: treat a load-linked like a normal load followed by an |
| 5695 | assignment of the loaded (shadow) data to the result temporary. |
| 5696 | Treat a store-conditional like a normal store, and mark the |
| 5697 | result temporary as defined. */ |
| 5698 | IRType resTy = typeOfIRTemp(mce->sb->tyenv, stResult); |
| 5699 | IRTemp resTmp = findShadowTmpV(mce, stResult); |
| 5700 | |
| 5701 | tl_assert(isIRAtom(stAddr)); |
| 5702 | if (stStoredata) |
| 5703 | tl_assert(isIRAtom(stStoredata)); |
| 5704 | |
| 5705 | if (stStoredata == NULL) { |
| 5706 | /* Load Linked */ |
| 5707 | /* Just treat this as a normal load, followed by an assignment of |
| 5708 | the value to .result. */ |
| 5709 | /* Stay sane */ |
| 5710 | tl_assert(resTy == Ity_I64 || resTy == Ity_I32 |
| 5711 | || resTy == Ity_I16 || resTy == Ity_I8); |
| 5712 | assign( 'V', mce, resTmp, |
| 5713 | expr2vbits_Load( |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5714 | mce, stEnd, resTy, stAddr, 0/*addr bias*/, |
| 5715 | NULL/*always happens*/) ); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5716 | } else { |
| 5717 | /* Store Conditional */ |
| 5718 | /* Stay sane */ |
| 5719 | IRType dataTy = typeOfIRExpr(mce->sb->tyenv, |
| 5720 | stStoredata); |
| 5721 | tl_assert(dataTy == Ity_I64 || dataTy == Ity_I32 |
| 5722 | || dataTy == Ity_I16 || dataTy == Ity_I8); |
| 5723 | do_shadow_Store( mce, stEnd, |
| 5724 | stAddr, 0/* addr bias */, |
| 5725 | stStoredata, |
| 5726 | NULL /* shadow data */, |
| 5727 | NULL/*guard*/ ); |
| 5728 | /* This is a store conditional, so it writes to .result a value |
| 5729 | indicating whether or not the store succeeded. Just claim |
| 5730 | this value is always defined. In the PowerPC interpretation |
| 5731 | of store-conditional, definedness of the success indication |
| 5732 | depends on whether the address of the store matches the |
| 5733 | reservation address. But we can't tell that here (and |
| 5734 | anyway, we're not being PowerPC-specific). At least we are |
| 5735 | guaranteed that the definedness of the store address, and its |
| 5736 | addressibility, will be checked as per normal. So it seems |
| 5737 | pretty safe to just say that the success indication is always |
| 5738 | defined. |
| 5739 | |
| 5740 | In schemeS, for origin tracking, we must correspondingly set |
| 5741 | a no-origin value for the origin shadow of .result. |
| 5742 | */ |
| 5743 | tl_assert(resTy == Ity_I1); |
| 5744 | assign( 'V', mce, resTmp, definedOfType(resTy) ); |
| 5745 | } |
| 5746 | } |
| 5747 | |
| 5748 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5749 | /* ---- Dealing with LoadG/StoreG (not entirely simple) ---- */ |
| 5750 | |
| 5751 | static void do_shadow_StoreG ( MCEnv* mce, IRStoreG* sg ) |
| 5752 | { |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 5753 | complainIfUndefined(mce, sg->guard, NULL); |
| 5754 | /* do_shadow_Store will generate code to check the definedness and |
| 5755 | validity of sg->addr, in the case where sg->guard evaluates to |
| 5756 | True at run-time. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5757 | do_shadow_Store( mce, sg->end, |
| 5758 | sg->addr, 0/* addr bias */, |
| 5759 | sg->data, |
| 5760 | NULL /* shadow data */, |
| 5761 | sg->guard ); |
| 5762 | } |
| 5763 | |
| 5764 | static void do_shadow_LoadG ( MCEnv* mce, IRLoadG* lg ) |
| 5765 | { |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 5766 | complainIfUndefined(mce, lg->guard, NULL); |
| 5767 | /* expr2vbits_Load_guarded_General will generate code to check the |
| 5768 | definedness and validity of lg->addr, in the case where |
| 5769 | lg->guard evaluates to True at run-time. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5770 | |
| 5771 | /* Look at the LoadG's built-in conversion operation, to determine |
| 5772 | the source (actual loaded data) type, and the equivalent IROp. |
| 5773 | NOTE that implicitly we are taking a widening operation to be |
| 5774 | applied to original atoms and producing one that applies to V |
| 5775 | bits. Since signed and unsigned widening are self-shadowing, |
| 5776 | this is a straight copy of the op (modulo swapping from the |
| 5777 | IRLoadGOp form to the IROp form). Note also therefore that this |
| 5778 | implicitly duplicates the logic to do with said widening ops in |
| 5779 | expr2vbits_Unop. See comment at the start of expr2vbits_Unop. */ |
| 5780 | IROp vwiden = Iop_INVALID; |
| 5781 | IRType loadedTy = Ity_INVALID; |
| 5782 | switch (lg->cvt) { |
| 5783 | case ILGop_Ident32: loadedTy = Ity_I32; vwiden = Iop_INVALID; break; |
| 5784 | case ILGop_16Uto32: loadedTy = Ity_I16; vwiden = Iop_16Uto32; break; |
| 5785 | case ILGop_16Sto32: loadedTy = Ity_I16; vwiden = Iop_16Sto32; break; |
| 5786 | case ILGop_8Uto32: loadedTy = Ity_I8; vwiden = Iop_8Uto32; break; |
| 5787 | case ILGop_8Sto32: loadedTy = Ity_I8; vwiden = Iop_8Sto32; break; |
| 5788 | default: VG_(tool_panic)("do_shadow_LoadG"); |
| 5789 | } |
| 5790 | |
| 5791 | IRAtom* vbits_alt |
| 5792 | = expr2vbits( mce, lg->alt ); |
| 5793 | IRAtom* vbits_final |
| 5794 | = expr2vbits_Load_guarded_General(mce, lg->end, loadedTy, |
| 5795 | lg->addr, 0/*addr bias*/, |
| 5796 | lg->guard, vwiden, vbits_alt ); |
| 5797 | /* And finally, bind the V bits to the destination temporary. */ |
| 5798 | assign( 'V', mce, findShadowTmpV(mce, lg->dst), vbits_final ); |
| 5799 | } |
| 5800 | |
| 5801 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5802 | /*------------------------------------------------------------*/ |
| 5803 | /*--- Memcheck main ---*/ |
| 5804 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5805 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5806 | static void schemeS ( MCEnv* mce, IRStmt* st ); |
| 5807 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5808 | static Bool isBogusAtom ( IRAtom* at ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5809 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5810 | ULong n = 0; |
| 5811 | IRConst* con; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 5812 | tl_assert(isIRAtom(at)); |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 5813 | if (at->tag == Iex_RdTmp) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5814 | return False; |
| 5815 | tl_assert(at->tag == Iex_Const); |
| 5816 | con = at->Iex.Const.con; |
| 5817 | switch (con->tag) { |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5818 | case Ico_U1: return False; |
| 5819 | case Ico_U8: n = (ULong)con->Ico.U8; break; |
| 5820 | case Ico_U16: n = (ULong)con->Ico.U16; break; |
| 5821 | case Ico_U32: n = (ULong)con->Ico.U32; break; |
| 5822 | case Ico_U64: n = (ULong)con->Ico.U64; break; |
| 5823 | case Ico_F64: return False; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 5824 | case Ico_F32i: return False; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5825 | case Ico_F64i: return False; |
| 5826 | case Ico_V128: return False; |
sewardj | 1eb272f | 2014-01-26 18:36:52 +0000 | [diff] [blame] | 5827 | case Ico_V256: return False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5828 | default: ppIRExpr(at); tl_assert(0); |
| 5829 | } |
| 5830 | /* VG_(printf)("%llx\n", n); */ |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 5831 | return (/*32*/ n == 0xFEFEFEFFULL |
| 5832 | /*32*/ || n == 0x80808080ULL |
sewardj | 17b4743 | 2008-12-17 01:12:58 +0000 | [diff] [blame] | 5833 | /*32*/ || n == 0x7F7F7F7FULL |
sewardj | a150fe9 | 2013-12-11 16:49:46 +0000 | [diff] [blame] | 5834 | /*32*/ || n == 0x7EFEFEFFULL |
| 5835 | /*32*/ || n == 0x81010100ULL |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 5836 | /*64*/ || n == 0xFFFFFFFFFEFEFEFFULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 5837 | /*64*/ || n == 0xFEFEFEFEFEFEFEFFULL |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 5838 | /*64*/ || n == 0x0000000000008080ULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 5839 | /*64*/ || n == 0x8080808080808080ULL |
sewardj | 17b4743 | 2008-12-17 01:12:58 +0000 | [diff] [blame] | 5840 | /*64*/ || n == 0x0101010101010101ULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 5841 | ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5842 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5843 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5844 | static Bool checkForBogusLiterals ( /*FLAT*/ IRStmt* st ) |
| 5845 | { |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5846 | Int i; |
| 5847 | IRExpr* e; |
| 5848 | IRDirty* d; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5849 | IRCAS* cas; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5850 | switch (st->tag) { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 5851 | case Ist_WrTmp: |
| 5852 | e = st->Ist.WrTmp.data; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5853 | switch (e->tag) { |
| 5854 | case Iex_Get: |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 5855 | case Iex_RdTmp: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5856 | return False; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5857 | case Iex_Const: |
| 5858 | return isBogusAtom(e); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5859 | case Iex_Unop: |
sewardj | a150fe9 | 2013-12-11 16:49:46 +0000 | [diff] [blame] | 5860 | return isBogusAtom(e->Iex.Unop.arg) |
| 5861 | || e->Iex.Unop.op == Iop_GetMSBs8x16; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5862 | case Iex_GetI: |
| 5863 | return isBogusAtom(e->Iex.GetI.ix); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5864 | case Iex_Binop: |
| 5865 | return isBogusAtom(e->Iex.Binop.arg1) |
| 5866 | || isBogusAtom(e->Iex.Binop.arg2); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 5867 | case Iex_Triop: |
florian | 2644174 | 2012-06-02 20:30:41 +0000 | [diff] [blame] | 5868 | return isBogusAtom(e->Iex.Triop.details->arg1) |
| 5869 | || isBogusAtom(e->Iex.Triop.details->arg2) |
| 5870 | || isBogusAtom(e->Iex.Triop.details->arg3); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 5871 | case Iex_Qop: |
florian | e2ab297 | 2012-06-01 20:43:03 +0000 | [diff] [blame] | 5872 | return isBogusAtom(e->Iex.Qop.details->arg1) |
| 5873 | || isBogusAtom(e->Iex.Qop.details->arg2) |
| 5874 | || isBogusAtom(e->Iex.Qop.details->arg3) |
| 5875 | || isBogusAtom(e->Iex.Qop.details->arg4); |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 5876 | case Iex_ITE: |
| 5877 | return isBogusAtom(e->Iex.ITE.cond) |
| 5878 | || isBogusAtom(e->Iex.ITE.iftrue) |
| 5879 | || isBogusAtom(e->Iex.ITE.iffalse); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5880 | case Iex_Load: |
| 5881 | return isBogusAtom(e->Iex.Load.addr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5882 | case Iex_CCall: |
| 5883 | for (i = 0; e->Iex.CCall.args[i]; i++) |
| 5884 | if (isBogusAtom(e->Iex.CCall.args[i])) |
| 5885 | return True; |
| 5886 | return False; |
| 5887 | default: |
| 5888 | goto unhandled; |
| 5889 | } |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5890 | case Ist_Dirty: |
| 5891 | d = st->Ist.Dirty.details; |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 5892 | for (i = 0; d->args[i]; i++) { |
| 5893 | IRAtom* atom = d->args[i]; |
florian | a5c3ecb | 2013-08-15 20:55:42 +0000 | [diff] [blame] | 5894 | if (LIKELY(!is_IRExpr_VECRET_or_BBPTR(atom))) { |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 5895 | if (isBogusAtom(atom)) |
| 5896 | return True; |
| 5897 | } |
| 5898 | } |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 5899 | if (isBogusAtom(d->guard)) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5900 | return True; |
| 5901 | if (d->mAddr && isBogusAtom(d->mAddr)) |
| 5902 | return True; |
| 5903 | return False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5904 | case Ist_Put: |
| 5905 | return isBogusAtom(st->Ist.Put.data); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5906 | case Ist_PutI: |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 5907 | return isBogusAtom(st->Ist.PutI.details->ix) |
| 5908 | || isBogusAtom(st->Ist.PutI.details->data); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 5909 | case Ist_Store: |
| 5910 | return isBogusAtom(st->Ist.Store.addr) |
| 5911 | || isBogusAtom(st->Ist.Store.data); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 5912 | case Ist_StoreG: { |
| 5913 | IRStoreG* sg = st->Ist.StoreG.details; |
| 5914 | return isBogusAtom(sg->addr) || isBogusAtom(sg->data) |
| 5915 | || isBogusAtom(sg->guard); |
| 5916 | } |
| 5917 | case Ist_LoadG: { |
| 5918 | IRLoadG* lg = st->Ist.LoadG.details; |
| 5919 | return isBogusAtom(lg->addr) || isBogusAtom(lg->alt) |
| 5920 | || isBogusAtom(lg->guard); |
| 5921 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5922 | case Ist_Exit: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5923 | return isBogusAtom(st->Ist.Exit.guard); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5924 | case Ist_AbiHint: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5925 | return isBogusAtom(st->Ist.AbiHint.base) |
| 5926 | || isBogusAtom(st->Ist.AbiHint.nia); |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 5927 | case Ist_NoOp: |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 5928 | case Ist_IMark: |
sewardj | 72d7513 | 2007-11-09 23:06:35 +0000 | [diff] [blame] | 5929 | case Ist_MBE: |
sewardj | bd598e1 | 2005-01-07 12:10:21 +0000 | [diff] [blame] | 5930 | return False; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5931 | case Ist_CAS: |
| 5932 | cas = st->Ist.CAS.details; |
| 5933 | return isBogusAtom(cas->addr) |
| 5934 | || (cas->expdHi ? isBogusAtom(cas->expdHi) : False) |
| 5935 | || isBogusAtom(cas->expdLo) |
| 5936 | || (cas->dataHi ? isBogusAtom(cas->dataHi) : False) |
| 5937 | || isBogusAtom(cas->dataLo); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5938 | case Ist_LLSC: |
| 5939 | return isBogusAtom(st->Ist.LLSC.addr) |
| 5940 | || (st->Ist.LLSC.storedata |
| 5941 | ? isBogusAtom(st->Ist.LLSC.storedata) |
| 5942 | : False); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5943 | default: |
| 5944 | unhandled: |
| 5945 | ppIRStmt(st); |
| 5946 | VG_(tool_panic)("hasBogusLiterals"); |
| 5947 | } |
| 5948 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5949 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5950 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 5951 | IRSB* MC_(instrument) ( VgCallbackClosure* closure, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5952 | IRSB* sb_in, |
sewardj | 461df9c | 2006-01-17 02:06:39 +0000 | [diff] [blame] | 5953 | VexGuestLayout* layout, |
| 5954 | VexGuestExtents* vge, |
florian | ca503be | 2012-10-07 21:59:42 +0000 | [diff] [blame] | 5955 | VexArchInfo* archinfo_host, |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 5956 | IRType gWordTy, IRType hWordTy ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5957 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5958 | Bool verboze = 0||False; |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 5959 | Bool bogus; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5960 | Int i, j, first_stmt; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5961 | IRStmt* st; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5962 | MCEnv mce; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5963 | IRSB* sb_out; |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 5964 | |
| 5965 | if (gWordTy != hWordTy) { |
| 5966 | /* We don't currently support this case. */ |
| 5967 | VG_(tool_panic)("host/guest word size mismatch"); |
| 5968 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5969 | |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 5970 | /* Check we're not completely nuts */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5971 | tl_assert(sizeof(UWord) == sizeof(void*)); |
| 5972 | tl_assert(sizeof(Word) == sizeof(void*)); |
| 5973 | tl_assert(sizeof(Addr) == sizeof(void*)); |
| 5974 | tl_assert(sizeof(ULong) == 8); |
| 5975 | tl_assert(sizeof(Long) == 8); |
| 5976 | tl_assert(sizeof(Addr64) == 8); |
| 5977 | tl_assert(sizeof(UInt) == 4); |
| 5978 | tl_assert(sizeof(Int) == 4); |
| 5979 | |
| 5980 | tl_assert(MC_(clo_mc_level) >= 1 && MC_(clo_mc_level) <= 3); |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 5981 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 5982 | /* Set up SB */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5983 | sb_out = deepCopyIRSBExceptStmts(sb_in); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5984 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5985 | /* Set up the running environment. Both .sb and .tmpMap are |
| 5986 | modified as we go along. Note that tmps are added to both |
| 5987 | .sb->tyenv and .tmpMap together, so the valid index-set for |
| 5988 | those two arrays should always be identical. */ |
| 5989 | VG_(memset)(&mce, 0, sizeof(mce)); |
| 5990 | mce.sb = sb_out; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5991 | mce.trace = verboze; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5992 | mce.layout = layout; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5993 | mce.hWordTy = hWordTy; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 5994 | mce.bogusLiterals = False; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5995 | |
sewardj | 54eac25 | 2012-03-27 10:19:39 +0000 | [diff] [blame] | 5996 | /* Do expensive interpretation for Iop_Add32 and Iop_Add64 on |
| 5997 | Darwin. 10.7 is mostly built with LLVM, which uses these for |
| 5998 | bitfield inserts, and we get a lot of false errors if the cheap |
| 5999 | interpretation is used, alas. Could solve this much better if |
| 6000 | we knew which of such adds came from x86/amd64 LEA instructions, |
| 6001 | since these are the only ones really needing the expensive |
| 6002 | interpretation, but that would require some way to tag them in |
| 6003 | the _toIR.c front ends, which is a lot of faffing around. So |
| 6004 | for now just use the slow and blunt-instrument solution. */ |
| 6005 | mce.useLLVMworkarounds = False; |
| 6006 | # if defined(VGO_darwin) |
| 6007 | mce.useLLVMworkarounds = True; |
| 6008 | # endif |
| 6009 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6010 | mce.tmpMap = VG_(newXA)( VG_(malloc), "mc.MC_(instrument).1", VG_(free), |
| 6011 | sizeof(TempMapEnt)); |
| 6012 | for (i = 0; i < sb_in->tyenv->types_used; i++) { |
| 6013 | TempMapEnt ent; |
| 6014 | ent.kind = Orig; |
| 6015 | ent.shadowV = IRTemp_INVALID; |
| 6016 | ent.shadowB = IRTemp_INVALID; |
| 6017 | VG_(addToXA)( mce.tmpMap, &ent ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6018 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6019 | tl_assert( VG_(sizeXA)( mce.tmpMap ) == sb_in->tyenv->types_used ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6020 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6021 | /* Make a preliminary inspection of the statements, to see if there |
| 6022 | are any dodgy-looking literals. If there are, we generate |
| 6023 | extra-detailed (hence extra-expensive) instrumentation in |
| 6024 | places. Scan the whole bb even if dodgyness is found earlier, |
| 6025 | so that the flatness assertion is applied to all stmts. */ |
| 6026 | |
| 6027 | bogus = False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6028 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6029 | for (i = 0; i < sb_in->stmts_used; i++) { |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6030 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6031 | st = sb_in->stmts[i]; |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 6032 | tl_assert(st); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6033 | tl_assert(isFlatIRStmt(st)); |
| 6034 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6035 | if (!bogus) { |
| 6036 | bogus = checkForBogusLiterals(st); |
| 6037 | if (0 && bogus) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6038 | VG_(printf)("bogus: "); |
| 6039 | ppIRStmt(st); |
| 6040 | VG_(printf)("\n"); |
| 6041 | } |
| 6042 | } |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 6043 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | mce.bogusLiterals = bogus; |
| 6047 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6048 | /* Copy verbatim any IR preamble preceding the first IMark */ |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6049 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6050 | tl_assert(mce.sb == sb_out); |
| 6051 | tl_assert(mce.sb != sb_in); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6052 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6053 | i = 0; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6054 | while (i < sb_in->stmts_used && sb_in->stmts[i]->tag != Ist_IMark) { |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6055 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6056 | st = sb_in->stmts[i]; |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6057 | tl_assert(st); |
| 6058 | tl_assert(isFlatIRStmt(st)); |
| 6059 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6060 | stmt( 'C', &mce, sb_in->stmts[i] ); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6061 | i++; |
| 6062 | } |
| 6063 | |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6064 | /* Nasty problem. IR optimisation of the pre-instrumented IR may |
| 6065 | cause the IR following the preamble to contain references to IR |
| 6066 | temporaries defined in the preamble. Because the preamble isn't |
| 6067 | instrumented, these temporaries don't have any shadows. |
| 6068 | Nevertheless uses of them following the preamble will cause |
| 6069 | memcheck to generate references to their shadows. End effect is |
| 6070 | to cause IR sanity check failures, due to references to |
| 6071 | non-existent shadows. This is only evident for the complex |
| 6072 | preambles used for function wrapping on TOC-afflicted platforms |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 6073 | (ppc64-linux). |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6074 | |
| 6075 | The following loop therefore scans the preamble looking for |
| 6076 | assignments to temporaries. For each one found it creates an |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6077 | assignment to the corresponding (V) shadow temp, marking it as |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6078 | 'defined'. This is the same resulting IR as if the main |
| 6079 | instrumentation loop before had been applied to the statement |
| 6080 | 'tmp = CONSTANT'. |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6081 | |
| 6082 | Similarly, if origin tracking is enabled, we must generate an |
| 6083 | assignment for the corresponding origin (B) shadow, claiming |
| 6084 | no-origin, as appropriate for a defined value. |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6085 | */ |
| 6086 | for (j = 0; j < i; j++) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6087 | if (sb_in->stmts[j]->tag == Ist_WrTmp) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6088 | /* findShadowTmpV checks its arg is an original tmp; |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6089 | no need to assert that here. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6090 | IRTemp tmp_o = sb_in->stmts[j]->Ist.WrTmp.tmp; |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6091 | IRTemp tmp_v = findShadowTmpV(&mce, tmp_o); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6092 | IRType ty_v = typeOfIRTemp(sb_out->tyenv, tmp_v); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6093 | assign( 'V', &mce, tmp_v, definedOfType( ty_v ) ); |
| 6094 | if (MC_(clo_mc_level) == 3) { |
| 6095 | IRTemp tmp_b = findShadowTmpB(&mce, tmp_o); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6096 | tl_assert(typeOfIRTemp(sb_out->tyenv, tmp_b) == Ity_I32); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6097 | assign( 'B', &mce, tmp_b, mkU32(0)/* UNKNOWN ORIGIN */); |
| 6098 | } |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6099 | if (0) { |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 6100 | VG_(printf)("create shadow tmp(s) for preamble tmp [%d] ty ", j); |
| 6101 | ppIRType( ty_v ); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 6102 | VG_(printf)("\n"); |
| 6103 | } |
| 6104 | } |
| 6105 | } |
| 6106 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6107 | /* Iterate over the remaining stmts to generate instrumentation. */ |
| 6108 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6109 | tl_assert(sb_in->stmts_used > 0); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6110 | tl_assert(i >= 0); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6111 | tl_assert(i < sb_in->stmts_used); |
| 6112 | tl_assert(sb_in->stmts[i]->tag == Ist_IMark); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 6113 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6114 | for (/* use current i*/; i < sb_in->stmts_used; i++) { |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 6115 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6116 | st = sb_in->stmts[i]; |
| 6117 | first_stmt = sb_out->stmts_used; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6118 | |
| 6119 | if (verboze) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6120 | VG_(printf)("\n"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6121 | ppIRStmt(st); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6122 | VG_(printf)("\n"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6125 | if (MC_(clo_mc_level) == 3) { |
| 6126 | /* See comments on case Ist_CAS below. */ |
| 6127 | if (st->tag != Ist_CAS) |
| 6128 | schemeS( &mce, st ); |
| 6129 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6130 | |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 6131 | /* Generate instrumentation code for each stmt ... */ |
| 6132 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6133 | switch (st->tag) { |
| 6134 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 6135 | case Ist_WrTmp: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6136 | assign( 'V', &mce, findShadowTmpV(&mce, st->Ist.WrTmp.tmp), |
| 6137 | expr2vbits( &mce, st->Ist.WrTmp.data) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6138 | break; |
| 6139 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6140 | case Ist_Put: |
| 6141 | do_shadow_PUT( &mce, |
| 6142 | st->Ist.Put.offset, |
| 6143 | st->Ist.Put.data, |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6144 | NULL /* shadow atom */, NULL /* guard */ ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6145 | break; |
| 6146 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6147 | case Ist_PutI: |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 6148 | do_shadow_PUTI( &mce, st->Ist.PutI.details); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6149 | break; |
| 6150 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 6151 | case Ist_Store: |
| 6152 | do_shadow_Store( &mce, st->Ist.Store.end, |
| 6153 | st->Ist.Store.addr, 0/* addr bias */, |
| 6154 | st->Ist.Store.data, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6155 | NULL /* shadow data */, |
| 6156 | NULL/*guard*/ ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6157 | break; |
| 6158 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6159 | case Ist_StoreG: |
| 6160 | do_shadow_StoreG( &mce, st->Ist.StoreG.details ); |
| 6161 | break; |
| 6162 | |
| 6163 | case Ist_LoadG: |
| 6164 | do_shadow_LoadG( &mce, st->Ist.LoadG.details ); |
| 6165 | break; |
| 6166 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6167 | case Ist_Exit: |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 6168 | complainIfUndefined( &mce, st->Ist.Exit.guard, NULL ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6169 | break; |
| 6170 | |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 6171 | case Ist_IMark: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6172 | break; |
| 6173 | |
| 6174 | case Ist_NoOp: |
sewardj | 72d7513 | 2007-11-09 23:06:35 +0000 | [diff] [blame] | 6175 | case Ist_MBE: |
sewardj | bd598e1 | 2005-01-07 12:10:21 +0000 | [diff] [blame] | 6176 | break; |
| 6177 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6178 | case Ist_Dirty: |
| 6179 | do_shadow_Dirty( &mce, st->Ist.Dirty.details ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6180 | break; |
| 6181 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 6182 | case Ist_AbiHint: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6183 | do_AbiHint( &mce, st->Ist.AbiHint.base, |
| 6184 | st->Ist.AbiHint.len, |
| 6185 | st->Ist.AbiHint.nia ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 6186 | break; |
| 6187 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6188 | case Ist_CAS: |
| 6189 | do_shadow_CAS( &mce, st->Ist.CAS.details ); |
| 6190 | /* Note, do_shadow_CAS copies the CAS itself to the output |
| 6191 | block, because it needs to add instrumentation both |
| 6192 | before and after it. Hence skip the copy below. Also |
| 6193 | skip the origin-tracking stuff (call to schemeS) above, |
| 6194 | since that's all tangled up with it too; do_shadow_CAS |
| 6195 | does it all. */ |
| 6196 | break; |
| 6197 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 6198 | case Ist_LLSC: |
| 6199 | do_shadow_LLSC( &mce, |
| 6200 | st->Ist.LLSC.end, |
| 6201 | st->Ist.LLSC.result, |
| 6202 | st->Ist.LLSC.addr, |
| 6203 | st->Ist.LLSC.storedata ); |
| 6204 | break; |
| 6205 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6206 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6207 | VG_(printf)("\n"); |
| 6208 | ppIRStmt(st); |
| 6209 | VG_(printf)("\n"); |
| 6210 | VG_(tool_panic)("memcheck: unhandled IRStmt"); |
| 6211 | |
| 6212 | } /* switch (st->tag) */ |
| 6213 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6214 | if (0 && verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6215 | for (j = first_stmt; j < sb_out->stmts_used; j++) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6216 | VG_(printf)(" "); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6217 | ppIRStmt(sb_out->stmts[j]); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6218 | VG_(printf)("\n"); |
| 6219 | } |
| 6220 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6221 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6222 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6223 | /* ... and finally copy the stmt itself to the output. Except, |
| 6224 | skip the copy of IRCASs; see comments on case Ist_CAS |
| 6225 | above. */ |
| 6226 | if (st->tag != Ist_CAS) |
| 6227 | stmt('C', &mce, st); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6228 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6229 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6230 | /* Now we need to complain if the jump target is undefined. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6231 | first_stmt = sb_out->stmts_used; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6232 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6233 | if (verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6234 | VG_(printf)("sb_in->next = "); |
| 6235 | ppIRExpr(sb_in->next); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6236 | VG_(printf)("\n\n"); |
| 6237 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6238 | |
sewardj | b9e6d24 | 2013-05-11 13:42:08 +0000 | [diff] [blame] | 6239 | complainIfUndefined( &mce, sb_in->next, NULL ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6240 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6241 | if (0 && verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6242 | for (j = first_stmt; j < sb_out->stmts_used; j++) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6243 | VG_(printf)(" "); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6244 | ppIRStmt(sb_out->stmts[j]); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6245 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6246 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6247 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6248 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6249 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6250 | /* If this fails, there's been some serious snafu with tmp management, |
| 6251 | that should be investigated. */ |
| 6252 | tl_assert( VG_(sizeXA)( mce.tmpMap ) == mce.sb->tyenv->types_used ); |
| 6253 | VG_(deleteXA)( mce.tmpMap ); |
| 6254 | |
| 6255 | tl_assert(mce.sb == sb_out); |
| 6256 | return sb_out; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 6257 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 6258 | |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6259 | /*------------------------------------------------------------*/ |
| 6260 | /*--- Post-tree-build final tidying ---*/ |
| 6261 | /*------------------------------------------------------------*/ |
| 6262 | |
| 6263 | /* This exploits the observation that Memcheck often produces |
| 6264 | repeated conditional calls of the form |
| 6265 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6266 | Dirty G MC_(helperc_value_check0/1/4/8_fail)(UInt otag) |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6267 | |
| 6268 | with the same guard expression G guarding the same helper call. |
| 6269 | The second and subsequent calls are redundant. This usually |
| 6270 | results from instrumentation of guest code containing multiple |
| 6271 | memory references at different constant offsets from the same base |
| 6272 | register. After optimisation of the instrumentation, you get a |
| 6273 | test for the definedness of the base register for each memory |
| 6274 | reference, which is kinda pointless. MC_(final_tidy) therefore |
| 6275 | looks for such repeated calls and removes all but the first. */ |
| 6276 | |
| 6277 | /* A struct for recording which (helper, guard) pairs we have already |
| 6278 | seen. */ |
| 6279 | typedef |
| 6280 | struct { void* entry; IRExpr* guard; } |
| 6281 | Pair; |
| 6282 | |
| 6283 | /* Return True if e1 and e2 definitely denote the same value (used to |
| 6284 | compare guards). Return False if unknown; False is the safe |
| 6285 | answer. Since guest registers and guest memory do not have the |
| 6286 | SSA property we must return False if any Gets or Loads appear in |
| 6287 | the expression. */ |
| 6288 | |
| 6289 | static Bool sameIRValue ( IRExpr* e1, IRExpr* e2 ) |
| 6290 | { |
| 6291 | if (e1->tag != e2->tag) |
| 6292 | return False; |
| 6293 | switch (e1->tag) { |
| 6294 | case Iex_Const: |
| 6295 | return eqIRConst( e1->Iex.Const.con, e2->Iex.Const.con ); |
| 6296 | case Iex_Binop: |
| 6297 | return e1->Iex.Binop.op == e2->Iex.Binop.op |
| 6298 | && sameIRValue(e1->Iex.Binop.arg1, e2->Iex.Binop.arg1) |
| 6299 | && sameIRValue(e1->Iex.Binop.arg2, e2->Iex.Binop.arg2); |
| 6300 | case Iex_Unop: |
| 6301 | return e1->Iex.Unop.op == e2->Iex.Unop.op |
| 6302 | && sameIRValue(e1->Iex.Unop.arg, e2->Iex.Unop.arg); |
| 6303 | case Iex_RdTmp: |
| 6304 | return e1->Iex.RdTmp.tmp == e2->Iex.RdTmp.tmp; |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6305 | case Iex_ITE: |
| 6306 | return sameIRValue( e1->Iex.ITE.cond, e2->Iex.ITE.cond ) |
| 6307 | && sameIRValue( e1->Iex.ITE.iftrue, e2->Iex.ITE.iftrue ) |
| 6308 | && sameIRValue( e1->Iex.ITE.iffalse, e2->Iex.ITE.iffalse ); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6309 | case Iex_Qop: |
| 6310 | case Iex_Triop: |
| 6311 | case Iex_CCall: |
| 6312 | /* be lazy. Could define equality for these, but they never |
| 6313 | appear to be used. */ |
| 6314 | return False; |
| 6315 | case Iex_Get: |
| 6316 | case Iex_GetI: |
| 6317 | case Iex_Load: |
| 6318 | /* be conservative - these may not give the same value each |
| 6319 | time */ |
| 6320 | return False; |
| 6321 | case Iex_Binder: |
| 6322 | /* should never see this */ |
| 6323 | /* fallthrough */ |
| 6324 | default: |
| 6325 | VG_(printf)("mc_translate.c: sameIRValue: unhandled: "); |
| 6326 | ppIRExpr(e1); |
| 6327 | VG_(tool_panic)("memcheck:sameIRValue"); |
| 6328 | return False; |
| 6329 | } |
| 6330 | } |
| 6331 | |
| 6332 | /* See if 'pairs' already has an entry for (entry, guard). Return |
| 6333 | True if so. If not, add an entry. */ |
| 6334 | |
| 6335 | static |
| 6336 | Bool check_or_add ( XArray* /*of Pair*/ pairs, IRExpr* guard, void* entry ) |
| 6337 | { |
| 6338 | Pair p; |
| 6339 | Pair* pp; |
| 6340 | Int i, n = VG_(sizeXA)( pairs ); |
| 6341 | for (i = 0; i < n; i++) { |
| 6342 | pp = VG_(indexXA)( pairs, i ); |
| 6343 | if (pp->entry == entry && sameIRValue(pp->guard, guard)) |
| 6344 | return True; |
| 6345 | } |
| 6346 | p.guard = guard; |
| 6347 | p.entry = entry; |
| 6348 | VG_(addToXA)( pairs, &p ); |
| 6349 | return False; |
| 6350 | } |
| 6351 | |
florian | 11f3cc8 | 2012-10-21 02:19:35 +0000 | [diff] [blame] | 6352 | static Bool is_helperc_value_checkN_fail ( const HChar* name ) |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6353 | { |
| 6354 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6355 | 0==VG_(strcmp)(name, "MC_(helperc_value_check0_fail_no_o)") |
| 6356 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check1_fail_no_o)") |
| 6357 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check4_fail_no_o)") |
| 6358 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check8_fail_no_o)") |
| 6359 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check0_fail_w_o)") |
| 6360 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check1_fail_w_o)") |
| 6361 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check4_fail_w_o)") |
| 6362 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check8_fail_w_o)"); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | IRSB* MC_(final_tidy) ( IRSB* sb_in ) |
| 6366 | { |
| 6367 | Int i; |
| 6368 | IRStmt* st; |
| 6369 | IRDirty* di; |
| 6370 | IRExpr* guard; |
| 6371 | IRCallee* cee; |
| 6372 | Bool alreadyPresent; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 6373 | XArray* pairs = VG_(newXA)( VG_(malloc), "mc.ft.1", |
| 6374 | VG_(free), sizeof(Pair) ); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6375 | /* Scan forwards through the statements. Each time a call to one |
| 6376 | of the relevant helpers is seen, check if we have made a |
| 6377 | previous call to the same helper using the same guard |
| 6378 | expression, and if so, delete the call. */ |
| 6379 | for (i = 0; i < sb_in->stmts_used; i++) { |
| 6380 | st = sb_in->stmts[i]; |
| 6381 | tl_assert(st); |
| 6382 | if (st->tag != Ist_Dirty) |
| 6383 | continue; |
| 6384 | di = st->Ist.Dirty.details; |
| 6385 | guard = di->guard; |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 6386 | tl_assert(guard); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 6387 | if (0) { ppIRExpr(guard); VG_(printf)("\n"); } |
| 6388 | cee = di->cee; |
| 6389 | if (!is_helperc_value_checkN_fail( cee->name )) |
| 6390 | continue; |
| 6391 | /* Ok, we have a call to helperc_value_check0/1/4/8_fail with |
| 6392 | guard 'guard'. Check if we have already seen a call to this |
| 6393 | function with the same guard. If so, delete it. If not, |
| 6394 | add it to the set of calls we do know about. */ |
| 6395 | alreadyPresent = check_or_add( pairs, guard, cee->addr ); |
| 6396 | if (alreadyPresent) { |
| 6397 | sb_in->stmts[i] = IRStmt_NoOp(); |
| 6398 | if (0) VG_(printf)("XX\n"); |
| 6399 | } |
| 6400 | } |
| 6401 | VG_(deleteXA)( pairs ); |
| 6402 | return sb_in; |
| 6403 | } |
| 6404 | |
| 6405 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6406 | /*------------------------------------------------------------*/ |
| 6407 | /*--- Origin tracking stuff ---*/ |
| 6408 | /*------------------------------------------------------------*/ |
| 6409 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6410 | /* Almost identical to findShadowTmpV. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6411 | static IRTemp findShadowTmpB ( MCEnv* mce, IRTemp orig ) |
| 6412 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6413 | TempMapEnt* ent; |
| 6414 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 6415 | here. */ |
| 6416 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 6417 | tl_assert(ent->kind == Orig); |
| 6418 | if (ent->shadowB == IRTemp_INVALID) { |
| 6419 | IRTemp tmpB |
| 6420 | = newTemp( mce, Ity_I32, BSh ); |
| 6421 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 6422 | from VG_(indexXA) are invalid. */ |
| 6423 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 6424 | tl_assert(ent->kind == Orig); |
| 6425 | tl_assert(ent->shadowB == IRTemp_INVALID); |
| 6426 | ent->shadowB = tmpB; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6427 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6428 | return ent->shadowB; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | static IRAtom* gen_maxU32 ( MCEnv* mce, IRAtom* b1, IRAtom* b2 ) |
| 6432 | { |
| 6433 | return assignNew( 'B', mce, Ity_I32, binop(Iop_Max32U, b1, b2) ); |
| 6434 | } |
| 6435 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6436 | |
| 6437 | /* Make a guarded origin load, with no special handling in the |
| 6438 | didn't-happen case. A GUARD of NULL is assumed to mean "always |
| 6439 | True". |
| 6440 | |
| 6441 | Generate IR to do a shadow origins load from BASEADDR+OFFSET and |
| 6442 | return the otag. The loaded size is SZB. If GUARD evaluates to |
| 6443 | False at run time then the returned otag is zero. |
| 6444 | */ |
| 6445 | static IRAtom* gen_guarded_load_b ( MCEnv* mce, Int szB, |
| 6446 | IRAtom* baseaddr, |
| 6447 | Int offset, IRExpr* guard ) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6448 | { |
| 6449 | void* hFun; |
florian | 6bd9dc1 | 2012-11-23 16:17:43 +0000 | [diff] [blame] | 6450 | const HChar* hName; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6451 | IRTemp bTmp; |
| 6452 | IRDirty* di; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6453 | IRType aTy = typeOfIRExpr( mce->sb->tyenv, baseaddr ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6454 | IROp opAdd = aTy == Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 6455 | IRAtom* ea = baseaddr; |
| 6456 | if (offset != 0) { |
| 6457 | IRAtom* off = aTy == Ity_I32 ? mkU32( offset ) |
| 6458 | : mkU64( (Long)(Int)offset ); |
| 6459 | ea = assignNew( 'B', mce, aTy, binop(opAdd, ea, off)); |
| 6460 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6461 | bTmp = newTemp(mce, mce->hWordTy, BSh); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6462 | |
| 6463 | switch (szB) { |
| 6464 | case 1: hFun = (void*)&MC_(helperc_b_load1); |
| 6465 | hName = "MC_(helperc_b_load1)"; |
| 6466 | break; |
| 6467 | case 2: hFun = (void*)&MC_(helperc_b_load2); |
| 6468 | hName = "MC_(helperc_b_load2)"; |
| 6469 | break; |
| 6470 | case 4: hFun = (void*)&MC_(helperc_b_load4); |
| 6471 | hName = "MC_(helperc_b_load4)"; |
| 6472 | break; |
| 6473 | case 8: hFun = (void*)&MC_(helperc_b_load8); |
| 6474 | hName = "MC_(helperc_b_load8)"; |
| 6475 | break; |
| 6476 | case 16: hFun = (void*)&MC_(helperc_b_load16); |
| 6477 | hName = "MC_(helperc_b_load16)"; |
| 6478 | break; |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 6479 | case 32: hFun = (void*)&MC_(helperc_b_load32); |
| 6480 | hName = "MC_(helperc_b_load32)"; |
| 6481 | break; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6482 | default: |
| 6483 | VG_(printf)("mc_translate.c: gen_load_b: unhandled szB == %d\n", szB); |
| 6484 | tl_assert(0); |
| 6485 | } |
| 6486 | di = unsafeIRDirty_1_N( |
| 6487 | bTmp, 1/*regparms*/, hName, VG_(fnptr_to_fnentry)( hFun ), |
| 6488 | mkIRExprVec_1( ea ) |
| 6489 | ); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6490 | if (guard) { |
| 6491 | di->guard = guard; |
| 6492 | /* Ideally the didn't-happen return value here would be |
| 6493 | all-zeroes (unknown-origin), so it'd be harmless if it got |
| 6494 | used inadvertantly. We slum it out with the IR-mandated |
| 6495 | default value (0b01 repeating, 0x55 etc) as that'll probably |
| 6496 | trump all legitimate otags via Max32, and it's pretty |
| 6497 | obviously bogus. */ |
| 6498 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6499 | /* no need to mess with any annotations. This call accesses |
| 6500 | neither guest state nor guest memory. */ |
| 6501 | stmt( 'B', mce, IRStmt_Dirty(di) ); |
| 6502 | if (mce->hWordTy == Ity_I64) { |
| 6503 | /* 64-bit host */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6504 | IRTemp bTmp32 = newTemp(mce, Ity_I32, BSh); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6505 | assign( 'B', mce, bTmp32, unop(Iop_64to32, mkexpr(bTmp)) ); |
| 6506 | return mkexpr(bTmp32); |
| 6507 | } else { |
| 6508 | /* 32-bit host */ |
| 6509 | return mkexpr(bTmp); |
| 6510 | } |
| 6511 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6512 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6513 | |
| 6514 | /* Generate IR to do a shadow origins load from BASEADDR+OFFSET. The |
| 6515 | loaded size is SZB. The load is regarded as unconditional (always |
| 6516 | happens). |
| 6517 | */ |
| 6518 | static IRAtom* gen_load_b ( MCEnv* mce, Int szB, IRAtom* baseaddr, |
| 6519 | Int offset ) |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6520 | { |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6521 | return gen_guarded_load_b(mce, szB, baseaddr, offset, NULL/*guard*/); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6522 | } |
| 6523 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6524 | |
| 6525 | /* The most general handler for guarded origin loads. A GUARD of NULL |
| 6526 | is assumed to mean "always True". |
| 6527 | |
| 6528 | Generate IR to do a shadow origin load from ADDR+BIAS and return |
| 6529 | the B bits. The loaded type is TY. If GUARD evaluates to False at |
| 6530 | run time then the returned B bits are simply BALT instead. |
| 6531 | */ |
| 6532 | static |
| 6533 | IRAtom* expr2ori_Load_guarded_General ( MCEnv* mce, |
| 6534 | IRType ty, |
| 6535 | IRAtom* addr, UInt bias, |
| 6536 | IRAtom* guard, IRAtom* balt ) |
| 6537 | { |
| 6538 | /* If the guard evaluates to True, this will hold the loaded |
| 6539 | origin. If the guard evaluates to False, this will be zero, |
| 6540 | meaning "unknown origin", in which case we will have to replace |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6541 | it using an ITE below. */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6542 | IRAtom* iftrue |
| 6543 | = assignNew('B', mce, Ity_I32, |
| 6544 | gen_guarded_load_b(mce, sizeofIRType(ty), |
| 6545 | addr, bias, guard)); |
| 6546 | /* These are the bits we will return if the load doesn't take |
| 6547 | place. */ |
| 6548 | IRAtom* iffalse |
| 6549 | = balt; |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6550 | /* Prepare the cond for the ITE. Convert a NULL cond into |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6551 | something that iropt knows how to fold out later. */ |
| 6552 | IRAtom* cond |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 6553 | = guard == NULL ? mkU1(1) : guard; |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6554 | /* And assemble the final result. */ |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6555 | return assignNew('B', mce, Ity_I32, IRExpr_ITE(cond, iftrue, iffalse)); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6556 | } |
| 6557 | |
| 6558 | |
| 6559 | /* Generate a shadow origins store. guard :: Ity_I1 controls whether |
| 6560 | the store really happens; NULL means it unconditionally does. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6561 | static void gen_store_b ( MCEnv* mce, Int szB, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6562 | IRAtom* baseaddr, Int offset, IRAtom* dataB, |
| 6563 | IRAtom* guard ) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6564 | { |
| 6565 | void* hFun; |
florian | 6bd9dc1 | 2012-11-23 16:17:43 +0000 | [diff] [blame] | 6566 | const HChar* hName; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6567 | IRDirty* di; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6568 | IRType aTy = typeOfIRExpr( mce->sb->tyenv, baseaddr ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6569 | IROp opAdd = aTy == Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 6570 | IRAtom* ea = baseaddr; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6571 | if (guard) { |
| 6572 | tl_assert(isOriginalAtom(mce, guard)); |
| 6573 | tl_assert(typeOfIRExpr(mce->sb->tyenv, guard) == Ity_I1); |
| 6574 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6575 | if (offset != 0) { |
| 6576 | IRAtom* off = aTy == Ity_I32 ? mkU32( offset ) |
| 6577 | : mkU64( (Long)(Int)offset ); |
| 6578 | ea = assignNew( 'B', mce, aTy, binop(opAdd, ea, off)); |
| 6579 | } |
| 6580 | if (mce->hWordTy == Ity_I64) |
| 6581 | dataB = assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, dataB)); |
| 6582 | |
| 6583 | switch (szB) { |
| 6584 | case 1: hFun = (void*)&MC_(helperc_b_store1); |
| 6585 | hName = "MC_(helperc_b_store1)"; |
| 6586 | break; |
| 6587 | case 2: hFun = (void*)&MC_(helperc_b_store2); |
| 6588 | hName = "MC_(helperc_b_store2)"; |
| 6589 | break; |
| 6590 | case 4: hFun = (void*)&MC_(helperc_b_store4); |
| 6591 | hName = "MC_(helperc_b_store4)"; |
| 6592 | break; |
| 6593 | case 8: hFun = (void*)&MC_(helperc_b_store8); |
| 6594 | hName = "MC_(helperc_b_store8)"; |
| 6595 | break; |
| 6596 | case 16: hFun = (void*)&MC_(helperc_b_store16); |
| 6597 | hName = "MC_(helperc_b_store16)"; |
| 6598 | break; |
sewardj | 45fa9f4 | 2012-05-21 10:18:10 +0000 | [diff] [blame] | 6599 | case 32: hFun = (void*)&MC_(helperc_b_store32); |
| 6600 | hName = "MC_(helperc_b_store32)"; |
| 6601 | break; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6602 | default: |
| 6603 | tl_assert(0); |
| 6604 | } |
| 6605 | di = unsafeIRDirty_0_N( 2/*regparms*/, |
| 6606 | hName, VG_(fnptr_to_fnentry)( hFun ), |
| 6607 | mkIRExprVec_2( ea, dataB ) |
| 6608 | ); |
| 6609 | /* no need to mess with any annotations. This call accesses |
| 6610 | neither guest state nor guest memory. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6611 | if (guard) di->guard = guard; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6612 | stmt( 'B', mce, IRStmt_Dirty(di) ); |
| 6613 | } |
| 6614 | |
| 6615 | static IRAtom* narrowTo32 ( MCEnv* mce, IRAtom* e ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6616 | IRType eTy = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6617 | if (eTy == Ity_I64) |
| 6618 | return assignNew( 'B', mce, Ity_I32, unop(Iop_64to32, e) ); |
| 6619 | if (eTy == Ity_I32) |
| 6620 | return e; |
| 6621 | tl_assert(0); |
| 6622 | } |
| 6623 | |
| 6624 | static IRAtom* zWidenFrom32 ( MCEnv* mce, IRType dstTy, IRAtom* e ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6625 | IRType eTy = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6626 | tl_assert(eTy == Ity_I32); |
| 6627 | if (dstTy == Ity_I64) |
| 6628 | return assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, e) ); |
| 6629 | tl_assert(0); |
| 6630 | } |
| 6631 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 6632 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6633 | static IRAtom* schemeE ( MCEnv* mce, IRExpr* e ) |
| 6634 | { |
| 6635 | tl_assert(MC_(clo_mc_level) == 3); |
| 6636 | |
| 6637 | switch (e->tag) { |
| 6638 | |
| 6639 | case Iex_GetI: { |
| 6640 | IRRegArray* descr_b; |
| 6641 | IRAtom *t1, *t2, *t3, *t4; |
| 6642 | IRRegArray* descr = e->Iex.GetI.descr; |
| 6643 | IRType equivIntTy |
| 6644 | = MC_(get_otrack_reg_array_equiv_int_type)(descr); |
| 6645 | /* If this array is unshadowable for whatever reason, use the |
| 6646 | usual approximation. */ |
| 6647 | if (equivIntTy == Ity_INVALID) |
| 6648 | return mkU32(0); |
| 6649 | tl_assert(sizeofIRType(equivIntTy) >= 4); |
| 6650 | tl_assert(sizeofIRType(equivIntTy) == sizeofIRType(descr->elemTy)); |
| 6651 | descr_b = mkIRRegArray( descr->base + 2*mce->layout->total_sizeB, |
| 6652 | equivIntTy, descr->nElems ); |
| 6653 | /* Do a shadow indexed get of the same size, giving t1. Take |
| 6654 | the bottom 32 bits of it, giving t2. Compute into t3 the |
| 6655 | origin for the index (almost certainly zero, but there's |
| 6656 | no harm in being completely general here, since iropt will |
| 6657 | remove any useless code), and fold it in, giving a final |
| 6658 | value t4. */ |
| 6659 | t1 = assignNew( 'B', mce, equivIntTy, |
| 6660 | IRExpr_GetI( descr_b, e->Iex.GetI.ix, |
| 6661 | e->Iex.GetI.bias )); |
| 6662 | t2 = narrowTo32( mce, t1 ); |
| 6663 | t3 = schemeE( mce, e->Iex.GetI.ix ); |
| 6664 | t4 = gen_maxU32( mce, t2, t3 ); |
| 6665 | return t4; |
| 6666 | } |
| 6667 | case Iex_CCall: { |
| 6668 | Int i; |
| 6669 | IRAtom* here; |
| 6670 | IRExpr** args = e->Iex.CCall.args; |
| 6671 | IRAtom* curr = mkU32(0); |
| 6672 | for (i = 0; args[i]; i++) { |
| 6673 | tl_assert(i < 32); |
| 6674 | tl_assert(isOriginalAtom(mce, args[i])); |
| 6675 | /* Only take notice of this arg if the callee's |
| 6676 | mc-exclusion mask does not say it is to be excluded. */ |
| 6677 | if (e->Iex.CCall.cee->mcx_mask & (1<<i)) { |
| 6678 | /* the arg is to be excluded from definedness checking. |
| 6679 | Do nothing. */ |
| 6680 | if (0) VG_(printf)("excluding %s(%d)\n", |
| 6681 | e->Iex.CCall.cee->name, i); |
| 6682 | } else { |
| 6683 | /* calculate the arg's definedness, and pessimistically |
| 6684 | merge it in. */ |
| 6685 | here = schemeE( mce, args[i] ); |
| 6686 | curr = gen_maxU32( mce, curr, here ); |
| 6687 | } |
| 6688 | } |
| 6689 | return curr; |
| 6690 | } |
| 6691 | case Iex_Load: { |
| 6692 | Int dszB; |
| 6693 | dszB = sizeofIRType(e->Iex.Load.ty); |
| 6694 | /* assert that the B value for the address is already |
| 6695 | available (somewhere) */ |
| 6696 | tl_assert(isIRAtom(e->Iex.Load.addr)); |
| 6697 | tl_assert(mce->hWordTy == Ity_I32 || mce->hWordTy == Ity_I64); |
| 6698 | return gen_load_b( mce, dszB, e->Iex.Load.addr, 0 ); |
| 6699 | } |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6700 | case Iex_ITE: { |
| 6701 | IRAtom* b1 = schemeE( mce, e->Iex.ITE.cond ); |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6702 | IRAtom* b3 = schemeE( mce, e->Iex.ITE.iftrue ); |
sewardj | 07bfda2 | 2013-01-29 21:11:55 +0000 | [diff] [blame] | 6703 | IRAtom* b2 = schemeE( mce, e->Iex.ITE.iffalse ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6704 | return gen_maxU32( mce, b1, gen_maxU32( mce, b2, b3 )); |
| 6705 | } |
| 6706 | case Iex_Qop: { |
florian | e2ab297 | 2012-06-01 20:43:03 +0000 | [diff] [blame] | 6707 | IRAtom* b1 = schemeE( mce, e->Iex.Qop.details->arg1 ); |
| 6708 | IRAtom* b2 = schemeE( mce, e->Iex.Qop.details->arg2 ); |
| 6709 | IRAtom* b3 = schemeE( mce, e->Iex.Qop.details->arg3 ); |
| 6710 | IRAtom* b4 = schemeE( mce, e->Iex.Qop.details->arg4 ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6711 | return gen_maxU32( mce, gen_maxU32( mce, b1, b2 ), |
| 6712 | gen_maxU32( mce, b3, b4 ) ); |
| 6713 | } |
| 6714 | case Iex_Triop: { |
florian | 2644174 | 2012-06-02 20:30:41 +0000 | [diff] [blame] | 6715 | IRAtom* b1 = schemeE( mce, e->Iex.Triop.details->arg1 ); |
| 6716 | IRAtom* b2 = schemeE( mce, e->Iex.Triop.details->arg2 ); |
| 6717 | IRAtom* b3 = schemeE( mce, e->Iex.Triop.details->arg3 ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6718 | return gen_maxU32( mce, b1, gen_maxU32( mce, b2, b3 ) ); |
| 6719 | } |
| 6720 | case Iex_Binop: { |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 6721 | switch (e->Iex.Binop.op) { |
| 6722 | case Iop_CasCmpEQ8: case Iop_CasCmpNE8: |
| 6723 | case Iop_CasCmpEQ16: case Iop_CasCmpNE16: |
| 6724 | case Iop_CasCmpEQ32: case Iop_CasCmpNE32: |
| 6725 | case Iop_CasCmpEQ64: case Iop_CasCmpNE64: |
| 6726 | /* Just say these all produce a defined result, |
| 6727 | regardless of their arguments. See |
| 6728 | COMMENT_ON_CasCmpEQ in this file. */ |
| 6729 | return mkU32(0); |
| 6730 | default: { |
| 6731 | IRAtom* b1 = schemeE( mce, e->Iex.Binop.arg1 ); |
| 6732 | IRAtom* b2 = schemeE( mce, e->Iex.Binop.arg2 ); |
| 6733 | return gen_maxU32( mce, b1, b2 ); |
| 6734 | } |
| 6735 | } |
| 6736 | tl_assert(0); |
| 6737 | /*NOTREACHED*/ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6738 | } |
| 6739 | case Iex_Unop: { |
| 6740 | IRAtom* b1 = schemeE( mce, e->Iex.Unop.arg ); |
| 6741 | return b1; |
| 6742 | } |
| 6743 | case Iex_Const: |
| 6744 | return mkU32(0); |
| 6745 | case Iex_RdTmp: |
| 6746 | return mkexpr( findShadowTmpB( mce, e->Iex.RdTmp.tmp )); |
| 6747 | case Iex_Get: { |
| 6748 | Int b_offset = MC_(get_otrack_shadow_offset)( |
| 6749 | e->Iex.Get.offset, |
| 6750 | sizeofIRType(e->Iex.Get.ty) |
| 6751 | ); |
| 6752 | tl_assert(b_offset >= -1 |
| 6753 | && b_offset <= mce->layout->total_sizeB -4); |
| 6754 | if (b_offset >= 0) { |
| 6755 | /* FIXME: this isn't an atom! */ |
| 6756 | return IRExpr_Get( b_offset + 2*mce->layout->total_sizeB, |
| 6757 | Ity_I32 ); |
| 6758 | } |
| 6759 | return mkU32(0); |
| 6760 | } |
| 6761 | default: |
| 6762 | VG_(printf)("mc_translate.c: schemeE: unhandled: "); |
| 6763 | ppIRExpr(e); |
| 6764 | VG_(tool_panic)("memcheck:schemeE"); |
| 6765 | } |
| 6766 | } |
| 6767 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 6768 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6769 | static void do_origins_Dirty ( MCEnv* mce, IRDirty* d ) |
| 6770 | { |
| 6771 | // This is a hacked version of do_shadow_Dirty |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6772 | Int i, k, n, toDo, gSz, gOff; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6773 | IRAtom *here, *curr; |
| 6774 | IRTemp dst; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6775 | |
| 6776 | /* First check the guard. */ |
| 6777 | curr = schemeE( mce, d->guard ); |
| 6778 | |
| 6779 | /* Now round up all inputs and maxU32 over them. */ |
| 6780 | |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6781 | /* Inputs: unmasked args |
| 6782 | Note: arguments are evaluated REGARDLESS of the guard expression */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6783 | for (i = 0; d->args[i]; i++) { |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 6784 | IRAtom* arg = d->args[i]; |
| 6785 | if ( (d->cee->mcx_mask & (1<<i)) |
florian | a5c3ecb | 2013-08-15 20:55:42 +0000 | [diff] [blame] | 6786 | || UNLIKELY(is_IRExpr_VECRET_or_BBPTR(arg)) ) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6787 | /* ignore this arg */ |
| 6788 | } else { |
sewardj | 21a5f8c | 2013-08-08 10:41:46 +0000 | [diff] [blame] | 6789 | here = schemeE( mce, arg ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6790 | curr = gen_maxU32( mce, curr, here ); |
| 6791 | } |
| 6792 | } |
| 6793 | |
| 6794 | /* Inputs: guest state that we read. */ |
| 6795 | for (i = 0; i < d->nFxState; i++) { |
| 6796 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 6797 | if (d->fxState[i].fx == Ifx_Write) |
| 6798 | continue; |
| 6799 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6800 | /* Enumerate the described state segments */ |
| 6801 | for (k = 0; k < 1 + d->fxState[i].nRepeats; k++) { |
| 6802 | gOff = d->fxState[i].offset + k * d->fxState[i].repeatLen; |
| 6803 | gSz = d->fxState[i].size; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6804 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6805 | /* Ignore any sections marked as 'always defined'. */ |
| 6806 | if (isAlwaysDefd(mce, gOff, gSz)) { |
| 6807 | if (0) |
| 6808 | VG_(printf)("memcheck: Dirty gst: ignored off %d, sz %d\n", |
| 6809 | gOff, gSz); |
| 6810 | continue; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6811 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6812 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6813 | /* This state element is read or modified. So we need to |
| 6814 | consider it. If larger than 4 bytes, deal with it in |
| 6815 | 4-byte chunks. */ |
| 6816 | while (True) { |
| 6817 | Int b_offset; |
| 6818 | tl_assert(gSz >= 0); |
| 6819 | if (gSz == 0) break; |
| 6820 | n = gSz <= 4 ? gSz : 4; |
| 6821 | /* update 'curr' with maxU32 of the state slice |
| 6822 | gOff .. gOff+n-1 */ |
| 6823 | b_offset = MC_(get_otrack_shadow_offset)(gOff, 4); |
| 6824 | if (b_offset != -1) { |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6825 | /* Observe the guard expression. If it is false use 0, i.e. |
| 6826 | nothing is known about the origin */ |
| 6827 | IRAtom *cond, *iffalse, *iftrue; |
| 6828 | |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 6829 | cond = assignNew( 'B', mce, Ity_I1, d->guard); |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6830 | iffalse = mkU32(0); |
| 6831 | iftrue = assignNew( 'B', mce, Ity_I32, |
| 6832 | IRExpr_Get(b_offset |
| 6833 | + 2*mce->layout->total_sizeB, |
| 6834 | Ity_I32)); |
| 6835 | here = assignNew( 'B', mce, Ity_I32, |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6836 | IRExpr_ITE(cond, iftrue, iffalse)); |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6837 | curr = gen_maxU32( mce, curr, here ); |
| 6838 | } |
| 6839 | gSz -= n; |
| 6840 | gOff += n; |
| 6841 | } |
| 6842 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | /* Inputs: memory */ |
| 6846 | |
| 6847 | if (d->mFx != Ifx_None) { |
| 6848 | /* Because we may do multiple shadow loads/stores from the same |
| 6849 | base address, it's best to do a single test of its |
| 6850 | definedness right now. Post-instrumentation optimisation |
| 6851 | should remove all but this test. */ |
| 6852 | tl_assert(d->mAddr); |
| 6853 | here = schemeE( mce, d->mAddr ); |
| 6854 | curr = gen_maxU32( mce, curr, here ); |
| 6855 | } |
| 6856 | |
| 6857 | /* Deal with memory inputs (reads or modifies) */ |
| 6858 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6859 | toDo = d->mSize; |
| 6860 | /* chew off 32-bit chunks. We don't care about the endianness |
| 6861 | since it's all going to be condensed down to a single bit, |
| 6862 | but nevertheless choose an endianness which is hopefully |
| 6863 | native to the platform. */ |
| 6864 | while (toDo >= 4) { |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6865 | here = gen_guarded_load_b( mce, 4, d->mAddr, d->mSize - toDo, |
| 6866 | d->guard ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6867 | curr = gen_maxU32( mce, curr, here ); |
| 6868 | toDo -= 4; |
| 6869 | } |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 6870 | /* handle possible 16-bit excess */ |
| 6871 | while (toDo >= 2) { |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6872 | here = gen_guarded_load_b( mce, 2, d->mAddr, d->mSize - toDo, |
| 6873 | d->guard ); |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 6874 | curr = gen_maxU32( mce, curr, here ); |
| 6875 | toDo -= 2; |
| 6876 | } |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 6877 | /* chew off the remaining 8-bit chunk, if any */ |
| 6878 | if (toDo == 1) { |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6879 | here = gen_guarded_load_b( mce, 1, d->mAddr, d->mSize - toDo, |
| 6880 | d->guard ); |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 6881 | curr = gen_maxU32( mce, curr, here ); |
| 6882 | toDo -= 1; |
| 6883 | } |
| 6884 | tl_assert(toDo == 0); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6885 | } |
| 6886 | |
| 6887 | /* Whew! So curr is a 32-bit B-value which should give an origin |
| 6888 | of some use if any of the inputs to the helper are undefined. |
| 6889 | Now we need to re-distribute the results to all destinations. */ |
| 6890 | |
| 6891 | /* Outputs: the destination temporary, if there is one. */ |
| 6892 | if (d->tmp != IRTemp_INVALID) { |
| 6893 | dst = findShadowTmpB(mce, d->tmp); |
| 6894 | assign( 'V', mce, dst, curr ); |
| 6895 | } |
| 6896 | |
| 6897 | /* Outputs: guest state that we write or modify. */ |
| 6898 | for (i = 0; i < d->nFxState; i++) { |
| 6899 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 6900 | if (d->fxState[i].fx == Ifx_Read) |
| 6901 | continue; |
| 6902 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6903 | /* Enumerate the described state segments */ |
| 6904 | for (k = 0; k < 1 + d->fxState[i].nRepeats; k++) { |
| 6905 | gOff = d->fxState[i].offset + k * d->fxState[i].repeatLen; |
| 6906 | gSz = d->fxState[i].size; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6907 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6908 | /* Ignore any sections marked as 'always defined'. */ |
| 6909 | if (isAlwaysDefd(mce, gOff, gSz)) |
| 6910 | continue; |
| 6911 | |
| 6912 | /* This state element is written or modified. So we need to |
| 6913 | consider it. If larger than 4 bytes, deal with it in |
| 6914 | 4-byte chunks. */ |
| 6915 | while (True) { |
| 6916 | Int b_offset; |
| 6917 | tl_assert(gSz >= 0); |
| 6918 | if (gSz == 0) break; |
| 6919 | n = gSz <= 4 ? gSz : 4; |
| 6920 | /* Write 'curr' to the state slice gOff .. gOff+n-1 */ |
| 6921 | b_offset = MC_(get_otrack_shadow_offset)(gOff, 4); |
| 6922 | if (b_offset != -1) { |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6923 | |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 6924 | /* If the guard expression evaluates to false we simply Put |
| 6925 | the value that is already stored in the guest state slot */ |
| 6926 | IRAtom *cond, *iffalse; |
| 6927 | |
sewardj | cc96165 | 2013-01-26 11:49:15 +0000 | [diff] [blame] | 6928 | cond = assignNew('B', mce, Ity_I1, |
| 6929 | d->guard); |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 6930 | iffalse = assignNew('B', mce, Ity_I32, |
| 6931 | IRExpr_Get(b_offset + |
| 6932 | 2*mce->layout->total_sizeB, |
| 6933 | Ity_I32)); |
| 6934 | curr = assignNew('V', mce, Ity_I32, |
florian | 5686b2d | 2013-01-29 03:57:40 +0000 | [diff] [blame] | 6935 | IRExpr_ITE(cond, curr, iffalse)); |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 6936 | |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6937 | stmt( 'B', mce, IRStmt_Put(b_offset |
florian | 6c0aa2c | 2013-01-21 01:27:22 +0000 | [diff] [blame] | 6938 | + 2*mce->layout->total_sizeB, |
sewardj | 2eecb74 | 2012-06-01 16:11:41 +0000 | [diff] [blame] | 6939 | curr )); |
| 6940 | } |
| 6941 | gSz -= n; |
| 6942 | gOff += n; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6943 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | /* Outputs: memory that we write or modify. Same comments about |
| 6948 | endianness as above apply. */ |
| 6949 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6950 | toDo = d->mSize; |
| 6951 | /* chew off 32-bit chunks */ |
| 6952 | while (toDo >= 4) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 6953 | gen_store_b( mce, 4, d->mAddr, d->mSize - toDo, curr, |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6954 | d->guard ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6955 | toDo -= 4; |
| 6956 | } |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 6957 | /* handle possible 16-bit excess */ |
| 6958 | while (toDo >= 2) { |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6959 | gen_store_b( mce, 2, d->mAddr, d->mSize - toDo, curr, |
| 6960 | d->guard ); |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 6961 | toDo -= 2; |
| 6962 | } |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 6963 | /* chew off the remaining 8-bit chunk, if any */ |
| 6964 | if (toDo == 1) { |
| 6965 | gen_store_b( mce, 1, d->mAddr, d->mSize - toDo, curr, |
florian | 434ffae | 2012-07-19 17:23:42 +0000 | [diff] [blame] | 6966 | d->guard ); |
florian | cda994b | 2012-06-08 16:01:19 +0000 | [diff] [blame] | 6967 | toDo -= 1; |
| 6968 | } |
| 6969 | tl_assert(toDo == 0); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6970 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 6971 | } |
| 6972 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 6973 | |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6974 | /* Generate IR for origin shadowing for a general guarded store. */ |
| 6975 | static void do_origins_Store_guarded ( MCEnv* mce, |
| 6976 | IREndness stEnd, |
| 6977 | IRExpr* stAddr, |
| 6978 | IRExpr* stData, |
| 6979 | IRExpr* guard ) |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 6980 | { |
| 6981 | Int dszB; |
| 6982 | IRAtom* dataB; |
| 6983 | /* assert that the B value for the address is already available |
| 6984 | (somewhere), since the call to schemeE will want to see it. |
| 6985 | XXXX how does this actually ensure that?? */ |
| 6986 | tl_assert(isIRAtom(stAddr)); |
| 6987 | tl_assert(isIRAtom(stData)); |
| 6988 | dszB = sizeofIRType( typeOfIRExpr(mce->sb->tyenv, stData ) ); |
| 6989 | dataB = schemeE( mce, stData ); |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 6990 | gen_store_b( mce, dszB, stAddr, 0/*offset*/, dataB, guard ); |
| 6991 | } |
| 6992 | |
| 6993 | |
| 6994 | /* Generate IR for origin shadowing for a plain store. */ |
| 6995 | static void do_origins_Store_plain ( MCEnv* mce, |
| 6996 | IREndness stEnd, |
| 6997 | IRExpr* stAddr, |
| 6998 | IRExpr* stData ) |
| 6999 | { |
| 7000 | do_origins_Store_guarded ( mce, stEnd, stAddr, stData, |
| 7001 | NULL/*guard*/ ); |
| 7002 | } |
| 7003 | |
| 7004 | |
| 7005 | /* ---- Dealing with LoadG/StoreG (not entirely simple) ---- */ |
| 7006 | |
| 7007 | static void do_origins_StoreG ( MCEnv* mce, IRStoreG* sg ) |
| 7008 | { |
| 7009 | do_origins_Store_guarded( mce, sg->end, sg->addr, |
| 7010 | sg->data, sg->guard ); |
| 7011 | } |
| 7012 | |
| 7013 | static void do_origins_LoadG ( MCEnv* mce, IRLoadG* lg ) |
| 7014 | { |
| 7015 | IRType loadedTy = Ity_INVALID; |
| 7016 | switch (lg->cvt) { |
| 7017 | case ILGop_Ident32: loadedTy = Ity_I32; break; |
| 7018 | case ILGop_16Uto32: loadedTy = Ity_I16; break; |
| 7019 | case ILGop_16Sto32: loadedTy = Ity_I16; break; |
| 7020 | case ILGop_8Uto32: loadedTy = Ity_I8; break; |
| 7021 | case ILGop_8Sto32: loadedTy = Ity_I8; break; |
| 7022 | default: VG_(tool_panic)("schemeS.IRLoadG"); |
| 7023 | } |
| 7024 | IRAtom* ori_alt |
| 7025 | = schemeE( mce,lg->alt ); |
| 7026 | IRAtom* ori_final |
| 7027 | = expr2ori_Load_guarded_General(mce, loadedTy, |
| 7028 | lg->addr, 0/*addr bias*/, |
| 7029 | lg->guard, ori_alt ); |
| 7030 | /* And finally, bind the origin to the destination temporary. */ |
| 7031 | assign( 'B', mce, findShadowTmpB(mce, lg->dst), ori_final ); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7032 | } |
| 7033 | |
| 7034 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7035 | static void schemeS ( MCEnv* mce, IRStmt* st ) |
| 7036 | { |
| 7037 | tl_assert(MC_(clo_mc_level) == 3); |
| 7038 | |
| 7039 | switch (st->tag) { |
| 7040 | |
| 7041 | case Ist_AbiHint: |
| 7042 | /* The value-check instrumenter handles this - by arranging |
| 7043 | to pass the address of the next instruction to |
| 7044 | MC_(helperc_MAKE_STACK_UNINIT). This is all that needs to |
| 7045 | happen for origin tracking w.r.t. AbiHints. So there is |
| 7046 | nothing to do here. */ |
| 7047 | break; |
| 7048 | |
| 7049 | case Ist_PutI: { |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 7050 | IRPutI *puti = st->Ist.PutI.details; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7051 | IRRegArray* descr_b; |
| 7052 | IRAtom *t1, *t2, *t3, *t4; |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 7053 | IRRegArray* descr = puti->descr; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7054 | IRType equivIntTy |
| 7055 | = MC_(get_otrack_reg_array_equiv_int_type)(descr); |
| 7056 | /* If this array is unshadowable for whatever reason, |
| 7057 | generate no code. */ |
| 7058 | if (equivIntTy == Ity_INVALID) |
| 7059 | break; |
| 7060 | tl_assert(sizeofIRType(equivIntTy) >= 4); |
| 7061 | tl_assert(sizeofIRType(equivIntTy) == sizeofIRType(descr->elemTy)); |
| 7062 | descr_b |
| 7063 | = mkIRRegArray( descr->base + 2*mce->layout->total_sizeB, |
| 7064 | equivIntTy, descr->nElems ); |
| 7065 | /* Compute a value to Put - the conjoinment of the origin for |
| 7066 | the data to be Put-ted (obviously) and of the index value |
| 7067 | (not so obviously). */ |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 7068 | t1 = schemeE( mce, puti->data ); |
| 7069 | t2 = schemeE( mce, puti->ix ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7070 | t3 = gen_maxU32( mce, t1, t2 ); |
| 7071 | t4 = zWidenFrom32( mce, equivIntTy, t3 ); |
florian | d39b022 | 2012-05-31 15:48:13 +0000 | [diff] [blame] | 7072 | stmt( 'B', mce, IRStmt_PutI( mkIRPutI(descr_b, puti->ix, |
| 7073 | puti->bias, t4) )); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7074 | break; |
| 7075 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7076 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7077 | case Ist_Dirty: |
| 7078 | do_origins_Dirty( mce, st->Ist.Dirty.details ); |
| 7079 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7080 | |
| 7081 | case Ist_Store: |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 7082 | do_origins_Store_plain( mce, st->Ist.Store.end, |
| 7083 | st->Ist.Store.addr, |
| 7084 | st->Ist.Store.data ); |
| 7085 | break; |
| 7086 | |
| 7087 | case Ist_StoreG: |
| 7088 | do_origins_StoreG( mce, st->Ist.StoreG.details ); |
| 7089 | break; |
| 7090 | |
| 7091 | case Ist_LoadG: |
| 7092 | do_origins_LoadG( mce, st->Ist.LoadG.details ); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7093 | break; |
| 7094 | |
| 7095 | case Ist_LLSC: { |
| 7096 | /* In short: treat a load-linked like a normal load followed |
| 7097 | by an assignment of the loaded (shadow) data the result |
| 7098 | temporary. Treat a store-conditional like a normal store, |
| 7099 | and mark the result temporary as defined. */ |
| 7100 | if (st->Ist.LLSC.storedata == NULL) { |
| 7101 | /* Load Linked */ |
| 7102 | IRType resTy |
| 7103 | = typeOfIRTemp(mce->sb->tyenv, st->Ist.LLSC.result); |
| 7104 | IRExpr* vanillaLoad |
| 7105 | = IRExpr_Load(st->Ist.LLSC.end, resTy, st->Ist.LLSC.addr); |
| 7106 | tl_assert(resTy == Ity_I64 || resTy == Ity_I32 |
| 7107 | || resTy == Ity_I16 || resTy == Ity_I8); |
| 7108 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.LLSC.result), |
| 7109 | schemeE(mce, vanillaLoad)); |
| 7110 | } else { |
| 7111 | /* Store conditional */ |
sewardj | cafe505 | 2013-01-17 14:24:35 +0000 | [diff] [blame] | 7112 | do_origins_Store_plain( mce, st->Ist.LLSC.end, |
| 7113 | st->Ist.LLSC.addr, |
| 7114 | st->Ist.LLSC.storedata ); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7115 | /* For the rationale behind this, see comments at the |
| 7116 | place where the V-shadow for .result is constructed, in |
| 7117 | do_shadow_LLSC. In short, we regard .result as |
| 7118 | always-defined. */ |
| 7119 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.LLSC.result), |
| 7120 | mkU32(0) ); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 7121 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7122 | break; |
| 7123 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7124 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7125 | case Ist_Put: { |
| 7126 | Int b_offset |
| 7127 | = MC_(get_otrack_shadow_offset)( |
| 7128 | st->Ist.Put.offset, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 7129 | sizeofIRType(typeOfIRExpr(mce->sb->tyenv, st->Ist.Put.data)) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7130 | ); |
| 7131 | if (b_offset >= 0) { |
| 7132 | /* FIXME: this isn't an atom! */ |
| 7133 | stmt( 'B', mce, IRStmt_Put(b_offset + 2*mce->layout->total_sizeB, |
| 7134 | schemeE( mce, st->Ist.Put.data )) ); |
| 7135 | } |
| 7136 | break; |
| 7137 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7138 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7139 | case Ist_WrTmp: |
| 7140 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.WrTmp.tmp), |
| 7141 | schemeE(mce, st->Ist.WrTmp.data) ); |
| 7142 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7143 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7144 | case Ist_MBE: |
| 7145 | case Ist_NoOp: |
| 7146 | case Ist_Exit: |
| 7147 | case Ist_IMark: |
| 7148 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 7149 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 7150 | default: |
| 7151 | VG_(printf)("mc_translate.c: schemeS: unhandled: "); |
| 7152 | ppIRStmt(st); |
| 7153 | VG_(tool_panic)("memcheck:schemeS"); |
| 7154 | } |
| 7155 | } |
| 7156 | |
| 7157 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 7158 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 7159 | /*--- end mc_translate.c ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 7160 | /*--------------------------------------------------------------------*/ |