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 | 9eecbbb | 2010-05-03 21:37:12 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2010 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" |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 33 | #include "pub_tool_hashtable.h" // For mc_include.h |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 34 | #include "pub_tool_libcassert.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 35 | #include "pub_tool_libcprint.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 36 | #include "pub_tool_tooliface.h" |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 37 | #include "pub_tool_machine.h" // VG_(fnptr_to_fnentry) |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 38 | #include "pub_tool_xarray.h" |
| 39 | #include "pub_tool_mallocfree.h" |
| 40 | #include "pub_tool_libcbase.h" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 41 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 42 | #include "mc_include.h" |
| 43 | |
| 44 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 45 | /* FIXMEs JRS 2011-June-16. |
| 46 | |
| 47 | Check the interpretation for vector narrowing and widening ops, |
| 48 | particularly the saturating ones. I suspect they are either overly |
| 49 | pessimistic and/or wrong. |
| 50 | */ |
| 51 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 52 | /* This file implements the Memcheck instrumentation, and in |
| 53 | particular contains the core of its undefined value detection |
| 54 | machinery. For a comprehensive background of the terminology, |
| 55 | algorithms and rationale used herein, read: |
| 56 | |
| 57 | Using Valgrind to detect undefined value errors with |
| 58 | bit-precision |
| 59 | |
| 60 | Julian Seward and Nicholas Nethercote |
| 61 | |
| 62 | 2005 USENIX Annual Technical Conference (General Track), |
| 63 | Anaheim, CA, USA, April 10-15, 2005. |
njn | 6665ea2 | 2007-05-24 23:14:41 +0000 | [diff] [blame] | 64 | |
| 65 | ---- |
| 66 | |
| 67 | Here is as good a place as any to record exactly when V bits are and |
| 68 | should be checked, why, and what function is responsible. |
| 69 | |
| 70 | |
| 71 | Memcheck complains when an undefined value is used: |
| 72 | |
| 73 | 1. In the condition of a conditional branch. Because it could cause |
| 74 | incorrect control flow, and thus cause incorrect externally-visible |
| 75 | behaviour. [mc_translate.c:complainIfUndefined] |
| 76 | |
| 77 | 2. As an argument to a system call, or as the value that specifies |
| 78 | the system call number. Because it could cause an incorrect |
| 79 | externally-visible side effect. [mc_translate.c:mc_pre_reg_read] |
| 80 | |
| 81 | 3. As the address in a load or store. Because it could cause an |
| 82 | incorrect value to be used later, which could cause externally-visible |
| 83 | behaviour (eg. via incorrect control flow or an incorrect system call |
| 84 | argument) [complainIfUndefined] |
| 85 | |
| 86 | 4. As the target address of a branch. Because it could cause incorrect |
| 87 | control flow. [complainIfUndefined] |
| 88 | |
| 89 | 5. As an argument to setenv, unsetenv, or putenv. Because it could put |
| 90 | an incorrect value into the external environment. |
| 91 | [mc_replace_strmem.c:VG_WRAP_FUNCTION_ZU(*, *env)] |
| 92 | |
| 93 | 6. As the index in a GETI or PUTI operation. I'm not sure why... (njn). |
| 94 | [complainIfUndefined] |
| 95 | |
| 96 | 7. As an argument to the VALGRIND_CHECK_MEM_IS_DEFINED and |
| 97 | VALGRIND_CHECK_VALUE_IS_DEFINED client requests. Because the user |
| 98 | requested it. [in memcheck.h] |
| 99 | |
| 100 | |
| 101 | Memcheck also complains, but should not, when an undefined value is used: |
| 102 | |
| 103 | 8. As the shift value in certain SIMD shift operations (but not in the |
| 104 | standard integer shift operations). This inconsistency is due to |
| 105 | historical reasons.) [complainIfUndefined] |
| 106 | |
| 107 | |
| 108 | Memcheck does not complain, but should, when an undefined value is used: |
| 109 | |
| 110 | 9. As an input to a client request. Because the client request may |
| 111 | affect the visible behaviour -- see bug #144362 for an example |
| 112 | involving the malloc replacements in vg_replace_malloc.c and |
| 113 | VALGRIND_NON_SIMD_CALL* requests, where an uninitialised argument |
| 114 | isn't identified. That bug report also has some info on how to solve |
| 115 | the problem. [valgrind.h:VALGRIND_DO_CLIENT_REQUEST] |
| 116 | |
| 117 | |
| 118 | In practice, 1 and 2 account for the vast majority of cases. |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 119 | */ |
| 120 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 121 | /*------------------------------------------------------------*/ |
| 122 | /*--- Forward decls ---*/ |
| 123 | /*------------------------------------------------------------*/ |
| 124 | |
| 125 | struct _MCEnv; |
| 126 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 127 | static IRType shadowTypeV ( IRType ty ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 128 | static IRExpr* expr2vbits ( struct _MCEnv* mce, IRExpr* e ); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 129 | static IRTemp findShadowTmpB ( struct _MCEnv* mce, IRTemp orig ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 130 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 131 | static IRExpr *i128_const_zero(void); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 132 | |
| 133 | /*------------------------------------------------------------*/ |
| 134 | /*--- Memcheck running state, and tmp management. ---*/ |
| 135 | /*------------------------------------------------------------*/ |
| 136 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 137 | /* Carries info about a particular tmp. The tmp's number is not |
| 138 | recorded, as this is implied by (equal to) its index in the tmpMap |
| 139 | in MCEnv. The tmp's type is also not recorded, as this is present |
| 140 | in MCEnv.sb->tyenv. |
| 141 | |
| 142 | When .kind is Orig, .shadowV and .shadowB may give the identities |
| 143 | of the temps currently holding the associated definedness (shadowV) |
| 144 | and origin (shadowB) values, or these may be IRTemp_INVALID if code |
| 145 | to compute such values has not yet been emitted. |
| 146 | |
| 147 | When .kind is VSh or BSh then the tmp is holds a V- or B- value, |
| 148 | and so .shadowV and .shadowB must be IRTemp_INVALID, since it is |
| 149 | illogical for a shadow tmp itself to be shadowed. |
| 150 | */ |
| 151 | typedef |
| 152 | enum { Orig=1, VSh=2, BSh=3 } |
| 153 | TempKind; |
| 154 | |
| 155 | typedef |
| 156 | struct { |
| 157 | TempKind kind; |
| 158 | IRTemp shadowV; |
| 159 | IRTemp shadowB; |
| 160 | } |
| 161 | TempMapEnt; |
| 162 | |
| 163 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 164 | /* Carries around state during memcheck instrumentation. */ |
| 165 | typedef |
| 166 | struct _MCEnv { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 167 | /* MODIFIED: the superblock being constructed. IRStmts are |
| 168 | added. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 169 | IRSB* sb; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 170 | Bool trace; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 171 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 172 | /* MODIFIED: a table [0 .. #temps_in_sb-1] which gives the |
| 173 | current kind and possibly shadow temps for each temp in the |
| 174 | IRSB being constructed. Note that it does not contain the |
| 175 | type of each tmp. If you want to know the type, look at the |
| 176 | relevant entry in sb->tyenv. It follows that at all times |
| 177 | during the instrumentation process, the valid indices for |
| 178 | tmpMap and sb->tyenv are identical, being 0 .. N-1 where N is |
| 179 | total number of Orig, V- and B- temps allocated so far. |
| 180 | |
| 181 | The reason for this strange split (types in one place, all |
| 182 | other info in another) is that we need the types to be |
| 183 | attached to sb so as to make it possible to do |
| 184 | "typeOfIRExpr(mce->bb->tyenv, ...)" at various places in the |
| 185 | instrumentation process. */ |
| 186 | XArray* /* of TempMapEnt */ tmpMap; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 187 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 188 | /* MODIFIED: indicates whether "bogus" literals have so far been |
| 189 | found. Starts off False, and may change to True. */ |
| 190 | Bool bogusLiterals; |
| 191 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 192 | /* READONLY: the guest layout. This indicates which parts of |
| 193 | the guest state should be regarded as 'always defined'. */ |
| 194 | VexGuestLayout* layout; |
sewardj | 634ba77 | 2006-10-15 12:47:37 +0000 | [diff] [blame] | 195 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 196 | /* READONLY: the host word type. Needed for constructing |
| 197 | arguments of type 'HWord' to be passed to helper functions. |
| 198 | Ity_I32 or Ity_I64 only. */ |
| 199 | IRType hWordTy; |
| 200 | } |
| 201 | MCEnv; |
| 202 | |
| 203 | /* SHADOW TMP MANAGEMENT. Shadow tmps are allocated lazily (on |
| 204 | demand), as they are encountered. This is for two reasons. |
| 205 | |
| 206 | (1) (less important reason): Many original tmps are unused due to |
| 207 | initial IR optimisation, and we do not want to spaces in tables |
| 208 | tracking them. |
| 209 | |
| 210 | Shadow IRTemps are therefore allocated on demand. mce.tmpMap is a |
| 211 | table indexed [0 .. n_types-1], which gives the current shadow for |
| 212 | each original tmp, or INVALID_IRTEMP if none is so far assigned. |
| 213 | It is necessary to support making multiple assignments to a shadow |
| 214 | -- specifically, after testing a shadow for definedness, it needs |
| 215 | to be made defined. But IR's SSA property disallows this. |
| 216 | |
| 217 | (2) (more important reason): Therefore, when a shadow needs to get |
| 218 | a new value, a new temporary is created, the value is assigned to |
| 219 | that, and the tmpMap is updated to reflect the new binding. |
| 220 | |
| 221 | A corollary is that if the tmpMap maps a given tmp to |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 222 | IRTemp_INVALID and we are hoping to read that shadow tmp, it means |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 223 | there's a read-before-write error in the original tmps. The IR |
| 224 | sanity checker should catch all such anomalies, however. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 225 | */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 226 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 227 | /* Create a new IRTemp of type 'ty' and kind 'kind', and add it to |
| 228 | both the table in mce->sb and to our auxiliary mapping. Note that |
| 229 | newTemp may cause mce->tmpMap to resize, hence previous results |
| 230 | from VG_(indexXA)(mce->tmpMap) are invalidated. */ |
| 231 | static IRTemp newTemp ( MCEnv* mce, IRType ty, TempKind kind ) |
| 232 | { |
| 233 | Word newIx; |
| 234 | TempMapEnt ent; |
| 235 | IRTemp tmp = newIRTemp(mce->sb->tyenv, ty); |
| 236 | ent.kind = kind; |
| 237 | ent.shadowV = IRTemp_INVALID; |
| 238 | ent.shadowB = IRTemp_INVALID; |
| 239 | newIx = VG_(addToXA)( mce->tmpMap, &ent ); |
| 240 | tl_assert(newIx == (Word)tmp); |
| 241 | return tmp; |
| 242 | } |
| 243 | |
| 244 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 245 | /* Find the tmp currently shadowing the given original tmp. If none |
| 246 | so far exists, allocate one. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 247 | static IRTemp findShadowTmpV ( MCEnv* mce, IRTemp orig ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 248 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 249 | TempMapEnt* ent; |
| 250 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 251 | here. */ |
| 252 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 253 | tl_assert(ent->kind == Orig); |
| 254 | if (ent->shadowV == IRTemp_INVALID) { |
| 255 | IRTemp tmpV |
| 256 | = newTemp( mce, shadowTypeV(mce->sb->tyenv->types[orig]), VSh ); |
| 257 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 258 | from VG_(indexXA) are invalid. */ |
| 259 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 260 | tl_assert(ent->kind == Orig); |
| 261 | tl_assert(ent->shadowV == IRTemp_INVALID); |
| 262 | ent->shadowV = tmpV; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 263 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 264 | return ent->shadowV; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 265 | } |
| 266 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 267 | /* Allocate a new shadow for the given original tmp. This means any |
| 268 | previous shadow is abandoned. This is needed because it is |
| 269 | necessary to give a new value to a shadow once it has been tested |
| 270 | for undefinedness, but unfortunately IR's SSA property disallows |
| 271 | this. Instead we must abandon the old shadow, allocate a new one |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 272 | and use that instead. |
| 273 | |
| 274 | This is the same as findShadowTmpV, except we don't bother to see |
| 275 | if a shadow temp already existed -- we simply allocate a new one |
| 276 | regardless. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 277 | static void newShadowTmpV ( MCEnv* mce, IRTemp orig ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 279 | TempMapEnt* ent; |
| 280 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 281 | here. */ |
| 282 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 283 | tl_assert(ent->kind == Orig); |
| 284 | if (1) { |
| 285 | IRTemp tmpV |
| 286 | = newTemp( mce, shadowTypeV(mce->sb->tyenv->types[orig]), VSh ); |
| 287 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 288 | from VG_(indexXA) are invalid. */ |
| 289 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 290 | tl_assert(ent->kind == Orig); |
| 291 | ent->shadowV = tmpV; |
| 292 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
| 296 | /*------------------------------------------------------------*/ |
| 297 | /*--- IRAtoms -- a subset of IRExprs ---*/ |
| 298 | /*------------------------------------------------------------*/ |
| 299 | |
| 300 | /* 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] | 301 | isIRAtom() in libvex_ir.h. Because this instrumenter expects flat |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 302 | input, most of this code deals in atoms. Usefully, a value atom |
| 303 | always has a V-value which is also an atom: constants are shadowed |
| 304 | by constants, and temps are shadowed by the corresponding shadow |
| 305 | temporary. */ |
| 306 | |
| 307 | typedef IRExpr IRAtom; |
| 308 | |
| 309 | /* (used for sanity checks only): is this an atom which looks |
| 310 | like it's from original code? */ |
| 311 | static Bool isOriginalAtom ( MCEnv* mce, IRAtom* a1 ) |
| 312 | { |
| 313 | if (a1->tag == Iex_Const) |
| 314 | return True; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 315 | if (a1->tag == Iex_RdTmp) { |
| 316 | TempMapEnt* ent = VG_(indexXA)( mce->tmpMap, a1->Iex.RdTmp.tmp ); |
| 317 | return ent->kind == Orig; |
| 318 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 319 | return False; |
| 320 | } |
| 321 | |
| 322 | /* (used for sanity checks only): is this an atom which looks |
| 323 | like it's from shadow code? */ |
| 324 | static Bool isShadowAtom ( MCEnv* mce, IRAtom* a1 ) |
| 325 | { |
| 326 | if (a1->tag == Iex_Const) |
| 327 | return True; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 328 | if (a1->tag == Iex_RdTmp) { |
| 329 | TempMapEnt* ent = VG_(indexXA)( mce->tmpMap, a1->Iex.RdTmp.tmp ); |
| 330 | return ent->kind == VSh || ent->kind == BSh; |
| 331 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 332 | return False; |
| 333 | } |
| 334 | |
| 335 | /* (used for sanity checks only): check that both args are atoms and |
| 336 | are identically-kinded. */ |
| 337 | static Bool sameKindedAtoms ( IRAtom* a1, IRAtom* a2 ) |
| 338 | { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 339 | if (a1->tag == Iex_RdTmp && a2->tag == Iex_RdTmp) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 340 | return True; |
sewardj | bef552a | 2005-08-30 12:54:36 +0000 | [diff] [blame] | 341 | if (a1->tag == Iex_Const && a2->tag == Iex_Const) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 342 | return True; |
| 343 | return False; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /*------------------------------------------------------------*/ |
| 348 | /*--- Type management ---*/ |
| 349 | /*------------------------------------------------------------*/ |
| 350 | |
| 351 | /* Shadow state is always accessed using integer types. This returns |
| 352 | an integer type with the same size (as per sizeofIRType) as the |
| 353 | given type. The only valid shadow types are Bit, I8, I16, I32, |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 354 | I64, I128, V128. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 355 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 356 | static IRType shadowTypeV ( IRType ty ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 357 | { |
| 358 | switch (ty) { |
| 359 | case Ity_I1: |
| 360 | case Ity_I8: |
| 361 | case Ity_I16: |
| 362 | case Ity_I32: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 363 | case Ity_I64: |
| 364 | case Ity_I128: return ty; |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 365 | case Ity_F32: return Ity_I32; |
| 366 | case Ity_F64: return Ity_I64; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 367 | case Ity_F128: return Ity_I128; |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 368 | case Ity_V128: return Ity_V128; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 369 | default: ppIRType(ty); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 370 | VG_(tool_panic)("memcheck:shadowTypeV"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | /* Produce a 'defined' value of the given shadow type. Should only be |
| 375 | supplied shadow types (Bit/I8/I16/I32/UI64). */ |
| 376 | static IRExpr* definedOfType ( IRType ty ) { |
| 377 | switch (ty) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 378 | case Ity_I1: return IRExpr_Const(IRConst_U1(False)); |
| 379 | case Ity_I8: return IRExpr_Const(IRConst_U8(0)); |
| 380 | case Ity_I16: return IRExpr_Const(IRConst_U16(0)); |
| 381 | case Ity_I32: return IRExpr_Const(IRConst_U32(0)); |
| 382 | case Ity_I64: return IRExpr_Const(IRConst_U64(0)); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 383 | case Ity_I128: return i128_const_zero(); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 384 | case Ity_V128: return IRExpr_Const(IRConst_V128(0x0000)); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 385 | default: VG_(tool_panic)("memcheck:definedOfType"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 390 | /*------------------------------------------------------------*/ |
| 391 | /*--- Constructing IR fragments ---*/ |
| 392 | /*------------------------------------------------------------*/ |
| 393 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 394 | /* add stmt to a bb */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 395 | static inline void stmt ( HChar cat, MCEnv* mce, IRStmt* st ) { |
| 396 | if (mce->trace) { |
| 397 | VG_(printf)(" %c: ", cat); |
| 398 | ppIRStmt(st); |
| 399 | VG_(printf)("\n"); |
| 400 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 401 | addStmtToIRSB(mce->sb, st); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /* assign value to tmp */ |
| 405 | static inline |
| 406 | void assign ( HChar cat, MCEnv* mce, IRTemp tmp, IRExpr* expr ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 407 | stmt(cat, mce, IRStmt_WrTmp(tmp,expr)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 408 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 409 | |
| 410 | /* build various kinds of expressions */ |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 411 | #define triop(_op, _arg1, _arg2, _arg3) \ |
| 412 | IRExpr_Triop((_op),(_arg1),(_arg2),(_arg3)) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 413 | #define binop(_op, _arg1, _arg2) IRExpr_Binop((_op),(_arg1),(_arg2)) |
| 414 | #define unop(_op, _arg) IRExpr_Unop((_op),(_arg)) |
| 415 | #define mkU8(_n) IRExpr_Const(IRConst_U8(_n)) |
| 416 | #define mkU16(_n) IRExpr_Const(IRConst_U16(_n)) |
| 417 | #define mkU32(_n) IRExpr_Const(IRConst_U32(_n)) |
| 418 | #define mkU64(_n) IRExpr_Const(IRConst_U64(_n)) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 419 | #define mkV128(_n) IRExpr_Const(IRConst_V128(_n)) |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 420 | #define mkexpr(_tmp) IRExpr_RdTmp((_tmp)) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 421 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 422 | /* Bind the given expression to a new temporary, and return the |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 423 | temporary. This effectively converts an arbitrary expression into |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 424 | an atom. |
| 425 | |
| 426 | '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] | 427 | needs to be. But passing it in is redundant, since we can deduce |
| 428 | the type merely by inspecting 'e'. So at least use that fact to |
| 429 | assert that the two types agree. */ |
| 430 | static IRAtom* assignNew ( HChar cat, MCEnv* mce, IRType ty, IRExpr* e ) |
| 431 | { |
| 432 | TempKind k; |
| 433 | IRTemp t; |
| 434 | IRType tyE = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 435 | tl_assert(tyE == ty); /* so 'ty' is redundant (!) */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 436 | switch (cat) { |
| 437 | case 'V': k = VSh; break; |
| 438 | case 'B': k = BSh; break; |
| 439 | case 'C': k = Orig; break; |
| 440 | /* happens when we are making up new "orig" |
| 441 | expressions, for IRCAS handling */ |
| 442 | default: tl_assert(0); |
| 443 | } |
| 444 | t = newTemp(mce, ty, k); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 445 | assign(cat, mce, t, e); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 446 | return mkexpr(t); |
| 447 | } |
| 448 | |
| 449 | |
| 450 | /*------------------------------------------------------------*/ |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 451 | /*--- Helper functions for 128-bit ops ---*/ |
| 452 | /*------------------------------------------------------------*/ |
| 453 | static IRExpr *i128_const_zero(void) |
| 454 | { |
| 455 | return binop(Iop_64HLto128, IRExpr_Const(IRConst_U64(0)), |
| 456 | IRExpr_Const(IRConst_U64(0))); |
| 457 | } |
| 458 | |
| 459 | /* There are no 128-bit loads and/or stores. So we do not need to worry |
| 460 | about that in expr2vbits_Load */ |
| 461 | |
| 462 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 463 | /*--- Constructing definedness primitive ops ---*/ |
| 464 | /*------------------------------------------------------------*/ |
| 465 | |
| 466 | /* --------- Defined-if-either-defined --------- */ |
| 467 | |
| 468 | static IRAtom* mkDifD8 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 469 | tl_assert(isShadowAtom(mce,a1)); |
| 470 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 471 | return assignNew('V', mce, Ity_I8, binop(Iop_And8, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static IRAtom* mkDifD16 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 475 | tl_assert(isShadowAtom(mce,a1)); |
| 476 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 477 | return assignNew('V', mce, Ity_I16, binop(Iop_And16, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static IRAtom* mkDifD32 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 481 | tl_assert(isShadowAtom(mce,a1)); |
| 482 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 483 | return assignNew('V', mce, Ity_I32, binop(Iop_And32, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 484 | } |
| 485 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 486 | static IRAtom* mkDifD64 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 487 | tl_assert(isShadowAtom(mce,a1)); |
| 488 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 489 | return assignNew('V', mce, Ity_I64, binop(Iop_And64, a1, a2)); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 490 | } |
| 491 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 492 | static IRAtom* mkDifDV128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 493 | tl_assert(isShadowAtom(mce,a1)); |
| 494 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 495 | return assignNew('V', mce, Ity_V128, binop(Iop_AndV128, a1, a2)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 496 | } |
| 497 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 498 | /* --------- Undefined-if-either-undefined --------- */ |
| 499 | |
| 500 | static IRAtom* mkUifU8 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 501 | tl_assert(isShadowAtom(mce,a1)); |
| 502 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 503 | return assignNew('V', mce, Ity_I8, binop(Iop_Or8, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static IRAtom* mkUifU16 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 507 | tl_assert(isShadowAtom(mce,a1)); |
| 508 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 509 | return assignNew('V', mce, Ity_I16, binop(Iop_Or16, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static IRAtom* mkUifU32 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 513 | tl_assert(isShadowAtom(mce,a1)); |
| 514 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 515 | return assignNew('V', mce, Ity_I32, binop(Iop_Or32, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static IRAtom* mkUifU64 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 519 | tl_assert(isShadowAtom(mce,a1)); |
| 520 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 521 | return assignNew('V', mce, Ity_I64, binop(Iop_Or64, a1, a2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 522 | } |
| 523 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 524 | static IRAtom* mkUifU128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
| 525 | IRAtom *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6; |
| 526 | tl_assert(isShadowAtom(mce,a1)); |
| 527 | tl_assert(isShadowAtom(mce,a2)); |
| 528 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, a1)); |
| 529 | tmp2 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, a1)); |
| 530 | tmp3 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, a2)); |
| 531 | tmp4 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, a2)); |
| 532 | tmp5 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp1, tmp3)); |
| 533 | tmp6 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp2, tmp4)); |
| 534 | |
| 535 | return assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, tmp6, tmp5)); |
| 536 | } |
| 537 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 538 | static IRAtom* mkUifUV128 ( MCEnv* mce, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 539 | tl_assert(isShadowAtom(mce,a1)); |
| 540 | tl_assert(isShadowAtom(mce,a2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 541 | return assignNew('V', mce, Ity_V128, binop(Iop_OrV128, a1, a2)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 542 | } |
| 543 | |
sewardj | e50a1b1 | 2004-12-17 01:24:54 +0000 | [diff] [blame] | 544 | static IRAtom* mkUifU ( MCEnv* mce, IRType vty, IRAtom* a1, IRAtom* a2 ) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 545 | switch (vty) { |
sewardj | e50a1b1 | 2004-12-17 01:24:54 +0000 | [diff] [blame] | 546 | case Ity_I8: return mkUifU8(mce, a1, a2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 547 | case Ity_I16: return mkUifU16(mce, a1, a2); |
| 548 | case Ity_I32: return mkUifU32(mce, a1, a2); |
| 549 | case Ity_I64: return mkUifU64(mce, a1, a2); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 550 | case Ity_I128: return mkUifU128(mce, a1, a2); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 551 | case Ity_V128: return mkUifUV128(mce, a1, a2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 552 | default: |
| 553 | VG_(printf)("\n"); ppIRType(vty); VG_(printf)("\n"); |
| 554 | VG_(tool_panic)("memcheck:mkUifU"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 558 | /* --------- The Left-family of operations. --------- */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 559 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 560 | static IRAtom* mkLeft8 ( MCEnv* mce, IRAtom* a1 ) { |
| 561 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 562 | return assignNew('V', mce, Ity_I8, unop(Iop_Left8, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static IRAtom* mkLeft16 ( MCEnv* mce, IRAtom* a1 ) { |
| 566 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 567 | return assignNew('V', mce, Ity_I16, unop(Iop_Left16, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static IRAtom* mkLeft32 ( MCEnv* mce, IRAtom* a1 ) { |
| 571 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 572 | return assignNew('V', mce, Ity_I32, unop(Iop_Left32, a1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 573 | } |
| 574 | |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 575 | static IRAtom* mkLeft64 ( MCEnv* mce, IRAtom* a1 ) { |
| 576 | tl_assert(isShadowAtom(mce,a1)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 577 | return assignNew('V', mce, Ity_I64, unop(Iop_Left64, a1)); |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 578 | } |
| 579 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 580 | /* --------- 'Improvement' functions for AND/OR. --------- */ |
| 581 | |
| 582 | /* ImproveAND(data, vbits) = data OR vbits. Defined (0) data 0s give |
| 583 | defined (0); all other -> undefined (1). |
| 584 | */ |
| 585 | static IRAtom* mkImproveAND8 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 586 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 587 | tl_assert(isOriginalAtom(mce, data)); |
| 588 | tl_assert(isShadowAtom(mce, vbits)); |
| 589 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 590 | return assignNew('V', mce, Ity_I8, binop(Iop_Or8, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 591 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 592 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 593 | static IRAtom* mkImproveAND16 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 594 | { |
| 595 | tl_assert(isOriginalAtom(mce, data)); |
| 596 | tl_assert(isShadowAtom(mce, vbits)); |
| 597 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 598 | return assignNew('V', mce, Ity_I16, binop(Iop_Or16, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 599 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 600 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 601 | static IRAtom* mkImproveAND32 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 602 | { |
| 603 | tl_assert(isOriginalAtom(mce, data)); |
| 604 | tl_assert(isShadowAtom(mce, vbits)); |
| 605 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 606 | return assignNew('V', mce, Ity_I32, binop(Iop_Or32, data, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 607 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 608 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 609 | static IRAtom* mkImproveAND64 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 610 | { |
| 611 | tl_assert(isOriginalAtom(mce, data)); |
| 612 | tl_assert(isShadowAtom(mce, vbits)); |
| 613 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 614 | return assignNew('V', mce, Ity_I64, binop(Iop_Or64, data, vbits)); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 615 | } |
| 616 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 617 | static IRAtom* mkImproveANDV128 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 618 | { |
| 619 | tl_assert(isOriginalAtom(mce, data)); |
| 620 | tl_assert(isShadowAtom(mce, vbits)); |
| 621 | tl_assert(sameKindedAtoms(data, vbits)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 622 | return assignNew('V', mce, Ity_V128, binop(Iop_OrV128, data, vbits)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 623 | } |
| 624 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 625 | /* ImproveOR(data, vbits) = ~data OR vbits. Defined (0) data 1s give |
| 626 | defined (0); all other -> undefined (1). |
| 627 | */ |
| 628 | static IRAtom* mkImproveOR8 ( 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)); |
| 633 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 634 | 'V', mce, Ity_I8, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 635 | binop(Iop_Or8, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 636 | assignNew('V', mce, Ity_I8, unop(Iop_Not8, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 637 | vbits) ); |
| 638 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 639 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 640 | static IRAtom* mkImproveOR16 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 641 | { |
| 642 | tl_assert(isOriginalAtom(mce, data)); |
| 643 | tl_assert(isShadowAtom(mce, vbits)); |
| 644 | tl_assert(sameKindedAtoms(data, vbits)); |
| 645 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 646 | 'V', mce, Ity_I16, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 647 | binop(Iop_Or16, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 648 | assignNew('V', mce, Ity_I16, unop(Iop_Not16, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 649 | vbits) ); |
| 650 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 651 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 652 | static IRAtom* mkImproveOR32 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 653 | { |
| 654 | tl_assert(isOriginalAtom(mce, data)); |
| 655 | tl_assert(isShadowAtom(mce, vbits)); |
| 656 | tl_assert(sameKindedAtoms(data, vbits)); |
| 657 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 658 | 'V', mce, Ity_I32, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 659 | binop(Iop_Or32, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 660 | assignNew('V', mce, Ity_I32, unop(Iop_Not32, data)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 661 | vbits) ); |
| 662 | } |
| 663 | |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 664 | static IRAtom* mkImproveOR64 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
| 665 | { |
| 666 | tl_assert(isOriginalAtom(mce, data)); |
| 667 | tl_assert(isShadowAtom(mce, vbits)); |
| 668 | tl_assert(sameKindedAtoms(data, vbits)); |
| 669 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 670 | 'V', mce, Ity_I64, |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 671 | binop(Iop_Or64, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 672 | assignNew('V', mce, Ity_I64, unop(Iop_Not64, data)), |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 673 | vbits) ); |
| 674 | } |
| 675 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 676 | static IRAtom* mkImproveORV128 ( MCEnv* mce, IRAtom* data, IRAtom* vbits ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 677 | { |
| 678 | tl_assert(isOriginalAtom(mce, data)); |
| 679 | tl_assert(isShadowAtom(mce, vbits)); |
| 680 | tl_assert(sameKindedAtoms(data, vbits)); |
| 681 | return assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 682 | 'V', mce, Ity_V128, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 683 | binop(Iop_OrV128, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 684 | assignNew('V', mce, Ity_V128, unop(Iop_NotV128, data)), |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 685 | vbits) ); |
| 686 | } |
| 687 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 688 | /* --------- Pessimising casts. --------- */ |
| 689 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 690 | /* The function returns an expression of type DST_TY. If any of the VBITS |
| 691 | is undefined (value == 1) the resulting expression has all bits set to |
| 692 | 1. Otherwise, all bits are 0. */ |
| 693 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 694 | static IRAtom* mkPCastTo( MCEnv* mce, IRType dst_ty, IRAtom* vbits ) |
| 695 | { |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 696 | IRType src_ty; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 697 | IRAtom* tmp1; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 698 | /* Note, dst_ty is a shadow type, not an original type. */ |
| 699 | /* First of all, collapse vbits down to a single bit. */ |
| 700 | tl_assert(isShadowAtom(mce,vbits)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 701 | src_ty = typeOfIRExpr(mce->sb->tyenv, vbits); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 702 | |
| 703 | /* Fast-track some common cases */ |
| 704 | if (src_ty == Ity_I32 && dst_ty == Ity_I32) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 705 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 706 | |
| 707 | if (src_ty == Ity_I64 && dst_ty == Ity_I64) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 708 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpwNEZ64, vbits)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 709 | |
| 710 | if (src_ty == Ity_I32 && dst_ty == Ity_I64) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 711 | IRAtom* tmp = assignNew('V', mce, Ity_I32, unop(Iop_CmpwNEZ32, vbits)); |
| 712 | return assignNew('V', mce, Ity_I64, binop(Iop_32HLto64, tmp, tmp)); |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /* Else do it the slow way .. */ |
| 716 | tmp1 = NULL; |
| 717 | switch (src_ty) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 718 | case Ity_I1: |
| 719 | tmp1 = vbits; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 720 | break; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 721 | case Ity_I8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 722 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ8, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 723 | break; |
| 724 | case Ity_I16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 725 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ16, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 726 | break; |
| 727 | case Ity_I32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 728 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ32, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 729 | break; |
| 730 | case Ity_I64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 731 | tmp1 = assignNew('V', mce, Ity_I1, unop(Iop_CmpNEZ64, vbits)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 732 | break; |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 733 | case Ity_I128: { |
| 734 | /* Gah. Chop it in half, OR the halves together, and compare |
| 735 | that with zero. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 736 | IRAtom* tmp2 = assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, vbits)); |
| 737 | IRAtom* tmp3 = assignNew('V', mce, Ity_I64, unop(Iop_128to64, vbits)); |
| 738 | IRAtom* tmp4 = assignNew('V', mce, Ity_I64, binop(Iop_Or64, tmp2, tmp3)); |
| 739 | tmp1 = assignNew('V', mce, Ity_I1, |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 740 | unop(Iop_CmpNEZ64, tmp4)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 741 | break; |
| 742 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 743 | default: |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 744 | ppIRType(src_ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 745 | VG_(tool_panic)("mkPCastTo(1)"); |
| 746 | } |
| 747 | tl_assert(tmp1); |
| 748 | /* Now widen up to the dst type. */ |
| 749 | switch (dst_ty) { |
| 750 | case Ity_I1: |
| 751 | return tmp1; |
| 752 | case Ity_I8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 753 | return assignNew('V', mce, Ity_I8, unop(Iop_1Sto8, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 754 | case Ity_I16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 755 | return assignNew('V', mce, Ity_I16, unop(Iop_1Sto16, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 756 | case Ity_I32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 757 | return assignNew('V', mce, Ity_I32, unop(Iop_1Sto32, tmp1)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 758 | case Ity_I64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 759 | return assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 760 | case Ity_V128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 761 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
| 762 | tmp1 = assignNew('V', mce, Ity_V128, binop(Iop_64HLtoV128, tmp1, tmp1)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 763 | return tmp1; |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 764 | case Ity_I128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 765 | tmp1 = assignNew('V', mce, Ity_I64, unop(Iop_1Sto64, tmp1)); |
| 766 | tmp1 = assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, tmp1, tmp1)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 767 | return tmp1; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 768 | default: |
| 769 | ppIRType(dst_ty); |
| 770 | VG_(tool_panic)("mkPCastTo(2)"); |
| 771 | } |
| 772 | } |
| 773 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 774 | /* --------- Accurate interpretation of CmpEQ/CmpNE. --------- */ |
| 775 | /* |
| 776 | Normally, we can do CmpEQ/CmpNE by doing UifU on the arguments, and |
| 777 | PCasting to Ity_U1. However, sometimes it is necessary to be more |
| 778 | accurate. The insight is that the result is defined if two |
| 779 | corresponding bits can be found, one from each argument, so that |
| 780 | both bits are defined but are different -- that makes EQ say "No" |
| 781 | and NE say "Yes". Hence, we compute an improvement term and DifD |
| 782 | it onto the "normal" (UifU) result. |
| 783 | |
| 784 | The result is: |
| 785 | |
| 786 | PCastTo<1> ( |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 787 | -- naive version |
| 788 | PCastTo<sz>( UifU<sz>(vxx, vyy) ) |
| 789 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 790 | `DifD<sz>` |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 791 | |
| 792 | -- improvement term |
| 793 | PCastTo<sz>( PCast<sz>( CmpEQ<sz> ( vec, 1...1 ) ) ) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 794 | ) |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 795 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 796 | where |
| 797 | vec contains 0 (defined) bits where the corresponding arg bits |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 798 | are defined but different, and 1 bits otherwise. |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 799 | |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 800 | vec = Or<sz>( vxx, // 0 iff bit defined |
| 801 | vyy, // 0 iff bit defined |
| 802 | Not<sz>(Xor<sz>( xx, yy )) // 0 iff bits different |
| 803 | ) |
| 804 | |
| 805 | If any bit of vec is 0, the result is defined and so the |
| 806 | improvement term should produce 0...0, else it should produce |
| 807 | 1...1. |
| 808 | |
| 809 | Hence require for the improvement term: |
| 810 | |
| 811 | if vec == 1...1 then 1...1 else 0...0 |
| 812 | -> |
| 813 | PCast<sz>( CmpEQ<sz> ( vec, 1...1 ) ) |
| 814 | |
| 815 | This was extensively re-analysed and checked on 6 July 05. |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 816 | */ |
| 817 | static IRAtom* expensiveCmpEQorNE ( MCEnv* mce, |
| 818 | IRType ty, |
| 819 | IRAtom* vxx, IRAtom* vyy, |
| 820 | IRAtom* xx, IRAtom* yy ) |
| 821 | { |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 822 | IRAtom *naive, *vec, *improvement_term; |
| 823 | IRAtom *improved, *final_cast, *top; |
| 824 | IROp opDIFD, opUIFU, opXOR, opNOT, opCMP, opOR; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 825 | |
| 826 | tl_assert(isShadowAtom(mce,vxx)); |
| 827 | tl_assert(isShadowAtom(mce,vyy)); |
| 828 | tl_assert(isOriginalAtom(mce,xx)); |
| 829 | tl_assert(isOriginalAtom(mce,yy)); |
| 830 | tl_assert(sameKindedAtoms(vxx,xx)); |
| 831 | tl_assert(sameKindedAtoms(vyy,yy)); |
| 832 | |
| 833 | switch (ty) { |
| 834 | case Ity_I32: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 835 | opOR = Iop_Or32; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 836 | opDIFD = Iop_And32; |
| 837 | opUIFU = Iop_Or32; |
| 838 | opNOT = Iop_Not32; |
| 839 | opXOR = Iop_Xor32; |
| 840 | opCMP = Iop_CmpEQ32; |
| 841 | top = mkU32(0xFFFFFFFF); |
| 842 | break; |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 843 | case Ity_I64: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 844 | opOR = Iop_Or64; |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 845 | opDIFD = Iop_And64; |
| 846 | opUIFU = Iop_Or64; |
| 847 | opNOT = Iop_Not64; |
| 848 | opXOR = Iop_Xor64; |
| 849 | opCMP = Iop_CmpEQ64; |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 850 | top = mkU64(0xFFFFFFFFFFFFFFFFULL); |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 851 | break; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 852 | default: |
| 853 | VG_(tool_panic)("expensiveCmpEQorNE"); |
| 854 | } |
| 855 | |
| 856 | naive |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 857 | = mkPCastTo(mce,ty, |
| 858 | assignNew('V', mce, ty, binop(opUIFU, vxx, vyy))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 859 | |
| 860 | vec |
| 861 | = assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 862 | 'V', mce,ty, |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 863 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 864 | assignNew('V', mce,ty, binop(opOR, vxx, vyy)), |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 865 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 866 | 'V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 867 | unop( opNOT, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 868 | assignNew('V', mce,ty, binop(opXOR, xx, yy)))))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 869 | |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 870 | improvement_term |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 871 | = mkPCastTo( mce,ty, |
| 872 | assignNew('V', mce,Ity_I1, binop(opCMP, vec, top))); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 873 | |
| 874 | improved |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 875 | = assignNew( 'V', mce,ty, binop(opDIFD, naive, improvement_term) ); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 876 | |
| 877 | final_cast |
| 878 | = mkPCastTo( mce, Ity_I1, improved ); |
| 879 | |
| 880 | return final_cast; |
| 881 | } |
| 882 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 883 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 884 | /* --------- Semi-accurate interpretation of CmpORD. --------- */ |
| 885 | |
| 886 | /* CmpORD32{S,U} does PowerPC-style 3-way comparisons: |
| 887 | |
| 888 | CmpORD32S(x,y) = 1<<3 if x <s y |
| 889 | = 1<<2 if x >s y |
| 890 | = 1<<1 if x == y |
| 891 | |
| 892 | and similarly the unsigned variant. The default interpretation is: |
| 893 | |
| 894 | CmpORD32{S,U}#(x,y,x#,y#) = PCast(x# `UifU` y#) |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 895 | & (7<<1) |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 896 | |
| 897 | The "& (7<<1)" reflects the fact that all result bits except 3,2,1 |
| 898 | are zero and therefore defined (viz, zero). |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 899 | |
| 900 | Also deal with a special case better: |
| 901 | |
| 902 | CmpORD32S(x,0) |
| 903 | |
| 904 | Here, bit 3 (LT) of the result is a copy of the top bit of x and |
| 905 | will be defined even if the rest of x isn't. In which case we do: |
| 906 | |
| 907 | CmpORD32S#(x,x#,0,{impliedly 0}#) |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 908 | = PCast(x#) & (3<<1) -- standard interp for GT#,EQ# |
| 909 | | (x# >>u 31) << 3 -- LT# = x#[31] |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 910 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 911 | Analogous handling for CmpORD64{S,U}. |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 912 | */ |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 913 | static Bool isZeroU32 ( IRAtom* e ) |
| 914 | { |
| 915 | return |
| 916 | toBool( e->tag == Iex_Const |
| 917 | && e->Iex.Const.con->tag == Ico_U32 |
| 918 | && e->Iex.Const.con->Ico.U32 == 0 ); |
| 919 | } |
| 920 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 921 | static Bool isZeroU64 ( IRAtom* e ) |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 922 | { |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 923 | return |
| 924 | toBool( e->tag == Iex_Const |
| 925 | && e->Iex.Const.con->tag == Ico_U64 |
| 926 | && e->Iex.Const.con->Ico.U64 == 0 ); |
| 927 | } |
| 928 | |
| 929 | static IRAtom* doCmpORD ( MCEnv* mce, |
| 930 | IROp cmp_op, |
| 931 | IRAtom* xxhash, IRAtom* yyhash, |
| 932 | IRAtom* xx, IRAtom* yy ) |
| 933 | { |
| 934 | Bool m64 = cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD64U; |
| 935 | Bool syned = cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD32S; |
| 936 | IROp opOR = m64 ? Iop_Or64 : Iop_Or32; |
| 937 | IROp opAND = m64 ? Iop_And64 : Iop_And32; |
| 938 | IROp opSHL = m64 ? Iop_Shl64 : Iop_Shl32; |
| 939 | IROp opSHR = m64 ? Iop_Shr64 : Iop_Shr32; |
| 940 | IRType ty = m64 ? Ity_I64 : Ity_I32; |
| 941 | Int width = m64 ? 64 : 32; |
| 942 | |
| 943 | Bool (*isZero)(IRAtom*) = m64 ? isZeroU64 : isZeroU32; |
| 944 | |
| 945 | IRAtom* threeLeft1 = NULL; |
| 946 | IRAtom* sevenLeft1 = NULL; |
| 947 | |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 948 | tl_assert(isShadowAtom(mce,xxhash)); |
| 949 | tl_assert(isShadowAtom(mce,yyhash)); |
| 950 | tl_assert(isOriginalAtom(mce,xx)); |
| 951 | tl_assert(isOriginalAtom(mce,yy)); |
| 952 | tl_assert(sameKindedAtoms(xxhash,xx)); |
| 953 | tl_assert(sameKindedAtoms(yyhash,yy)); |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 954 | tl_assert(cmp_op == Iop_CmpORD32S || cmp_op == Iop_CmpORD32U |
| 955 | || cmp_op == Iop_CmpORD64S || cmp_op == Iop_CmpORD64U); |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 956 | |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 957 | if (0) { |
| 958 | ppIROp(cmp_op); VG_(printf)(" "); |
| 959 | ppIRExpr(xx); VG_(printf)(" "); ppIRExpr( yy ); VG_(printf)("\n"); |
| 960 | } |
| 961 | |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 962 | if (syned && isZero(yy)) { |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 963 | /* fancy interpretation */ |
| 964 | /* if yy is zero, then it must be fully defined (zero#). */ |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 965 | tl_assert(isZero(yyhash)); |
| 966 | threeLeft1 = m64 ? mkU64(3<<1) : mkU32(3<<1); |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 967 | return |
| 968 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 969 | opOR, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 970 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 971 | 'V', mce,ty, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 972 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 973 | opAND, |
| 974 | mkPCastTo(mce,ty, xxhash), |
| 975 | threeLeft1 |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 976 | )), |
| 977 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 978 | 'V', mce,ty, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 979 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 980 | opSHL, |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 981 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 982 | 'V', mce,ty, |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 983 | binop(opSHR, xxhash, mkU8(width-1))), |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 984 | mkU8(3) |
| 985 | )) |
| 986 | ); |
| 987 | } else { |
| 988 | /* standard interpretation */ |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 989 | sevenLeft1 = m64 ? mkU64(7<<1) : mkU32(7<<1); |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 990 | return |
| 991 | binop( |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 992 | opAND, |
| 993 | mkPCastTo( mce,ty, |
| 994 | mkUifU(mce,ty, xxhash,yyhash)), |
| 995 | sevenLeft1 |
sewardj | a9e62a9 | 2005-10-07 12:13:21 +0000 | [diff] [blame] | 996 | ); |
| 997 | } |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1001 | /*------------------------------------------------------------*/ |
| 1002 | /*--- Emit a test and complaint if something is undefined. ---*/ |
| 1003 | /*------------------------------------------------------------*/ |
| 1004 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1005 | static IRAtom* schemeE ( MCEnv* mce, IRExpr* e ); /* fwds */ |
| 1006 | |
| 1007 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1008 | /* Set the annotations on a dirty helper to indicate that the stack |
| 1009 | pointer and instruction pointers might be read. This is the |
| 1010 | behaviour of all 'emit-a-complaint' style functions we might |
| 1011 | call. */ |
| 1012 | |
| 1013 | static void setHelperAnns ( MCEnv* mce, IRDirty* di ) { |
| 1014 | di->nFxState = 2; |
| 1015 | di->fxState[0].fx = Ifx_Read; |
| 1016 | di->fxState[0].offset = mce->layout->offset_SP; |
| 1017 | di->fxState[0].size = mce->layout->sizeof_SP; |
| 1018 | di->fxState[1].fx = Ifx_Read; |
| 1019 | di->fxState[1].offset = mce->layout->offset_IP; |
| 1020 | di->fxState[1].size = mce->layout->sizeof_IP; |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | /* Check the supplied **original** atom for undefinedness, and emit a |
| 1025 | complaint if so. Once that happens, mark it as defined. This is |
| 1026 | possible because the atom is either a tmp or literal. If it's a |
| 1027 | tmp, it will be shadowed by a tmp, and so we can set the shadow to |
| 1028 | be defined. In fact as mentioned above, we will have to allocate a |
| 1029 | new tmp to carry the new 'defined' shadow value, and update the |
| 1030 | original->tmp mapping accordingly; we cannot simply assign a new |
| 1031 | value to an existing shadow tmp as this breaks SSAness -- resulting |
| 1032 | in the post-instrumentation sanity checker spluttering in disapproval. |
| 1033 | */ |
| 1034 | static void complainIfUndefined ( MCEnv* mce, IRAtom* atom ) |
| 1035 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1036 | IRAtom* vatom; |
| 1037 | IRType ty; |
| 1038 | Int sz; |
| 1039 | IRDirty* di; |
| 1040 | IRAtom* cond; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1041 | IRAtom* origin; |
| 1042 | void* fn; |
| 1043 | HChar* nm; |
| 1044 | IRExpr** args; |
| 1045 | Int nargs; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1046 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1047 | // 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] | 1048 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1049 | return; |
| 1050 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1051 | /* Since the original expression is atomic, there's no duplicated |
| 1052 | work generated by making multiple V-expressions for it. So we |
| 1053 | don't really care about the possibility that someone else may |
| 1054 | also create a V-interpretion for it. */ |
| 1055 | tl_assert(isOriginalAtom(mce, atom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1056 | vatom = expr2vbits( mce, atom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1057 | tl_assert(isShadowAtom(mce, vatom)); |
| 1058 | tl_assert(sameKindedAtoms(atom, vatom)); |
| 1059 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1060 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1061 | |
| 1062 | /* sz is only used for constructing the error message */ |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1063 | sz = ty==Ity_I1 ? 0 : sizeofIRType(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1064 | |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1065 | cond = mkPCastTo( mce, Ity_I1, vatom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1066 | /* cond will be 0 if all defined, and 1 if any not defined. */ |
| 1067 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1068 | /* Get the origin info for the value we are about to check. At |
| 1069 | least, if we are doing origin tracking. If not, use a dummy |
| 1070 | zero origin. */ |
| 1071 | if (MC_(clo_mc_level) == 3) { |
| 1072 | origin = schemeE( mce, atom ); |
| 1073 | if (mce->hWordTy == Ity_I64) { |
| 1074 | origin = assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, origin) ); |
| 1075 | } |
| 1076 | } else { |
| 1077 | origin = NULL; |
| 1078 | } |
| 1079 | |
| 1080 | fn = NULL; |
| 1081 | nm = NULL; |
| 1082 | args = NULL; |
| 1083 | nargs = -1; |
| 1084 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1085 | switch (sz) { |
| 1086 | case 0: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1087 | if (origin) { |
| 1088 | fn = &MC_(helperc_value_check0_fail_w_o); |
| 1089 | nm = "MC_(helperc_value_check0_fail_w_o)"; |
| 1090 | args = mkIRExprVec_1(origin); |
| 1091 | nargs = 1; |
| 1092 | } else { |
| 1093 | fn = &MC_(helperc_value_check0_fail_no_o); |
| 1094 | nm = "MC_(helperc_value_check0_fail_no_o)"; |
| 1095 | args = mkIRExprVec_0(); |
| 1096 | nargs = 0; |
| 1097 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1098 | break; |
| 1099 | case 1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1100 | if (origin) { |
| 1101 | fn = &MC_(helperc_value_check1_fail_w_o); |
| 1102 | nm = "MC_(helperc_value_check1_fail_w_o)"; |
| 1103 | args = mkIRExprVec_1(origin); |
| 1104 | nargs = 1; |
| 1105 | } else { |
| 1106 | fn = &MC_(helperc_value_check1_fail_no_o); |
| 1107 | nm = "MC_(helperc_value_check1_fail_no_o)"; |
| 1108 | args = mkIRExprVec_0(); |
| 1109 | nargs = 0; |
| 1110 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1111 | break; |
| 1112 | case 4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1113 | if (origin) { |
| 1114 | fn = &MC_(helperc_value_check4_fail_w_o); |
| 1115 | nm = "MC_(helperc_value_check4_fail_w_o)"; |
| 1116 | args = mkIRExprVec_1(origin); |
| 1117 | nargs = 1; |
| 1118 | } else { |
| 1119 | fn = &MC_(helperc_value_check4_fail_no_o); |
| 1120 | nm = "MC_(helperc_value_check4_fail_no_o)"; |
| 1121 | args = mkIRExprVec_0(); |
| 1122 | nargs = 0; |
| 1123 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1124 | break; |
sewardj | 11bcc4e | 2005-04-23 22:38:38 +0000 | [diff] [blame] | 1125 | case 8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1126 | if (origin) { |
| 1127 | fn = &MC_(helperc_value_check8_fail_w_o); |
| 1128 | nm = "MC_(helperc_value_check8_fail_w_o)"; |
| 1129 | args = mkIRExprVec_1(origin); |
| 1130 | nargs = 1; |
| 1131 | } else { |
| 1132 | fn = &MC_(helperc_value_check8_fail_no_o); |
| 1133 | nm = "MC_(helperc_value_check8_fail_no_o)"; |
| 1134 | args = mkIRExprVec_0(); |
| 1135 | nargs = 0; |
| 1136 | } |
sewardj | 11bcc4e | 2005-04-23 22:38:38 +0000 | [diff] [blame] | 1137 | break; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 1138 | case 2: |
| 1139 | case 16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1140 | if (origin) { |
| 1141 | fn = &MC_(helperc_value_checkN_fail_w_o); |
| 1142 | nm = "MC_(helperc_value_checkN_fail_w_o)"; |
| 1143 | args = mkIRExprVec_2( mkIRExpr_HWord( sz ), origin); |
| 1144 | nargs = 2; |
| 1145 | } else { |
| 1146 | fn = &MC_(helperc_value_checkN_fail_no_o); |
| 1147 | nm = "MC_(helperc_value_checkN_fail_no_o)"; |
| 1148 | args = mkIRExprVec_1( mkIRExpr_HWord( sz ) ); |
| 1149 | nargs = 1; |
| 1150 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1151 | break; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 1152 | default: |
| 1153 | VG_(tool_panic)("unexpected szB"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1154 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1155 | |
| 1156 | tl_assert(fn); |
| 1157 | tl_assert(nm); |
| 1158 | tl_assert(args); |
| 1159 | tl_assert(nargs >= 0 && nargs <= 2); |
| 1160 | tl_assert( (MC_(clo_mc_level) == 3 && origin != NULL) |
| 1161 | || (MC_(clo_mc_level) == 2 && origin == NULL) ); |
| 1162 | |
| 1163 | di = unsafeIRDirty_0_N( nargs/*regparms*/, nm, |
| 1164 | VG_(fnptr_to_fnentry)( fn ), args ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1165 | di->guard = cond; |
| 1166 | setHelperAnns( mce, di ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1167 | stmt( 'V', mce, IRStmt_Dirty(di)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1168 | |
| 1169 | /* Set the shadow tmp to be defined. First, update the |
| 1170 | orig->shadow tmp mapping to reflect the fact that this shadow is |
| 1171 | getting a new value. */ |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 1172 | tl_assert(isIRAtom(vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1173 | /* sameKindedAtoms ... */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1174 | if (vatom->tag == Iex_RdTmp) { |
| 1175 | tl_assert(atom->tag == Iex_RdTmp); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1176 | newShadowTmpV(mce, atom->Iex.RdTmp.tmp); |
| 1177 | assign('V', mce, findShadowTmpV(mce, atom->Iex.RdTmp.tmp), |
| 1178 | definedOfType(ty)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | |
| 1183 | /*------------------------------------------------------------*/ |
| 1184 | /*--- Shadowing PUTs/GETs, and indexed variants thereof ---*/ |
| 1185 | /*------------------------------------------------------------*/ |
| 1186 | |
| 1187 | /* Examine the always-defined sections declared in layout to see if |
| 1188 | the (offset,size) section is within one. Note, is is an error to |
| 1189 | partially fall into such a region: (offset,size) should either be |
| 1190 | completely in such a region or completely not-in such a region. |
| 1191 | */ |
| 1192 | static Bool isAlwaysDefd ( MCEnv* mce, Int offset, Int size ) |
| 1193 | { |
| 1194 | Int minoffD, maxoffD, i; |
| 1195 | Int minoff = offset; |
| 1196 | Int maxoff = minoff + size - 1; |
| 1197 | tl_assert((minoff & ~0xFFFF) == 0); |
| 1198 | tl_assert((maxoff & ~0xFFFF) == 0); |
| 1199 | |
| 1200 | for (i = 0; i < mce->layout->n_alwaysDefd; i++) { |
| 1201 | minoffD = mce->layout->alwaysDefd[i].offset; |
| 1202 | maxoffD = minoffD + mce->layout->alwaysDefd[i].size - 1; |
| 1203 | tl_assert((minoffD & ~0xFFFF) == 0); |
| 1204 | tl_assert((maxoffD & ~0xFFFF) == 0); |
| 1205 | |
| 1206 | if (maxoff < minoffD || maxoffD < minoff) |
| 1207 | continue; /* no overlap */ |
| 1208 | if (minoff >= minoffD && maxoff <= maxoffD) |
| 1209 | return True; /* completely contained in an always-defd section */ |
| 1210 | |
| 1211 | VG_(tool_panic)("memcheck:isAlwaysDefd:partial overlap"); |
| 1212 | } |
| 1213 | return False; /* could not find any containing section */ |
| 1214 | } |
| 1215 | |
| 1216 | |
| 1217 | /* Generate into bb suitable actions to shadow this Put. If the state |
| 1218 | slice is marked 'always defined', do nothing. Otherwise, write the |
| 1219 | supplied V bits to the shadow state. We can pass in either an |
| 1220 | original atom or a V-atom, but not both. In the former case the |
| 1221 | relevant V-bits are then generated from the original. |
| 1222 | */ |
| 1223 | static |
| 1224 | void do_shadow_PUT ( MCEnv* mce, Int offset, |
| 1225 | IRAtom* atom, IRAtom* vatom ) |
| 1226 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1227 | IRType ty; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1228 | |
| 1229 | // Don't do shadow PUTs if we're not doing undefined value checking. |
| 1230 | // Their absence lets Vex's optimiser remove all the shadow computation |
| 1231 | // that they depend on, which includes GETs of the shadow registers. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1232 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1233 | return; |
| 1234 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1235 | if (atom) { |
| 1236 | tl_assert(!vatom); |
| 1237 | tl_assert(isOriginalAtom(mce, atom)); |
| 1238 | vatom = expr2vbits( mce, atom ); |
| 1239 | } else { |
| 1240 | tl_assert(vatom); |
| 1241 | tl_assert(isShadowAtom(mce, vatom)); |
| 1242 | } |
| 1243 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1244 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1245 | tl_assert(ty != Ity_I1); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1246 | tl_assert(ty != Ity_I128); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1247 | if (isAlwaysDefd(mce, offset, sizeofIRType(ty))) { |
| 1248 | /* later: no ... */ |
| 1249 | /* emit code to emit a complaint if any of the vbits are 1. */ |
| 1250 | /* complainIfUndefined(mce, atom); */ |
| 1251 | } else { |
| 1252 | /* Do a plain shadow Put. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1253 | stmt( 'V', mce, IRStmt_Put( offset + mce->layout->total_sizeB, vatom ) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | /* Return an expression which contains the V bits corresponding to the |
| 1259 | given GETI (passed in in pieces). |
| 1260 | */ |
| 1261 | static |
| 1262 | void do_shadow_PUTI ( MCEnv* mce, |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1263 | IRRegArray* descr, |
| 1264 | IRAtom* ix, Int bias, IRAtom* atom ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1265 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1266 | IRAtom* vatom; |
| 1267 | IRType ty, tyS; |
| 1268 | Int arrSize;; |
| 1269 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1270 | // Don't do shadow PUTIs if we're not doing undefined value checking. |
| 1271 | // Their absence lets Vex's optimiser remove all the shadow computation |
| 1272 | // that they depend on, which includes GETIs of the shadow registers. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1273 | if (MC_(clo_mc_level) == 1) |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 1274 | return; |
| 1275 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1276 | tl_assert(isOriginalAtom(mce,atom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1277 | vatom = expr2vbits( mce, atom ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1278 | tl_assert(sameKindedAtoms(atom, vatom)); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1279 | ty = descr->elemTy; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1280 | tyS = shadowTypeV(ty); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1281 | arrSize = descr->nElems * sizeofIRType(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1282 | tl_assert(ty != Ity_I1); |
| 1283 | tl_assert(isOriginalAtom(mce,ix)); |
| 1284 | complainIfUndefined(mce,ix); |
| 1285 | if (isAlwaysDefd(mce, descr->base, arrSize)) { |
| 1286 | /* later: no ... */ |
| 1287 | /* emit code to emit a complaint if any of the vbits are 1. */ |
| 1288 | /* complainIfUndefined(mce, atom); */ |
| 1289 | } else { |
| 1290 | /* Do a cloned version of the Put that refers to the shadow |
| 1291 | area. */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1292 | IRRegArray* new_descr |
| 1293 | = mkIRRegArray( descr->base + mce->layout->total_sizeB, |
| 1294 | tyS, descr->nElems); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1295 | stmt( 'V', mce, IRStmt_PutI( new_descr, ix, bias, vatom )); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | /* Return an expression which contains the V bits corresponding to the |
| 1301 | given GET (passed in in pieces). |
| 1302 | */ |
| 1303 | static |
| 1304 | IRExpr* shadow_GET ( MCEnv* mce, Int offset, IRType ty ) |
| 1305 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1306 | IRType tyS = shadowTypeV(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1307 | tl_assert(ty != Ity_I1); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1308 | tl_assert(ty != Ity_I128); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1309 | if (isAlwaysDefd(mce, offset, sizeofIRType(ty))) { |
| 1310 | /* Always defined, return all zeroes of the relevant type */ |
| 1311 | return definedOfType(tyS); |
| 1312 | } else { |
| 1313 | /* return a cloned version of the Get that refers to the shadow |
| 1314 | area. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1315 | /* FIXME: this isn't an atom! */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1316 | return IRExpr_Get( offset + mce->layout->total_sizeB, tyS ); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | /* Return an expression which contains the V bits corresponding to the |
| 1322 | given GETI (passed in in pieces). |
| 1323 | */ |
| 1324 | static |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1325 | IRExpr* shadow_GETI ( MCEnv* mce, |
| 1326 | IRRegArray* descr, IRAtom* ix, Int bias ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1327 | { |
| 1328 | IRType ty = descr->elemTy; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1329 | IRType tyS = shadowTypeV(ty); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1330 | Int arrSize = descr->nElems * sizeofIRType(ty); |
| 1331 | tl_assert(ty != Ity_I1); |
| 1332 | tl_assert(isOriginalAtom(mce,ix)); |
| 1333 | complainIfUndefined(mce,ix); |
| 1334 | if (isAlwaysDefd(mce, descr->base, arrSize)) { |
| 1335 | /* Always defined, return all zeroes of the relevant type */ |
| 1336 | return definedOfType(tyS); |
| 1337 | } else { |
| 1338 | /* return a cloned version of the Get that refers to the shadow |
| 1339 | area. */ |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 1340 | IRRegArray* new_descr |
| 1341 | = mkIRRegArray( descr->base + mce->layout->total_sizeB, |
| 1342 | tyS, descr->nElems); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1343 | return IRExpr_GetI( new_descr, ix, bias ); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | /*------------------------------------------------------------*/ |
| 1349 | /*--- Generating approximations for unknown operations, ---*/ |
| 1350 | /*--- using lazy-propagate semantics ---*/ |
| 1351 | /*------------------------------------------------------------*/ |
| 1352 | |
| 1353 | /* Lazy propagation of undefinedness from two values, resulting in the |
| 1354 | specified shadow type. |
| 1355 | */ |
| 1356 | static |
| 1357 | IRAtom* mkLazy2 ( MCEnv* mce, IRType finalVty, IRAtom* va1, IRAtom* va2 ) |
| 1358 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1359 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1360 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1361 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1362 | tl_assert(isShadowAtom(mce,va1)); |
| 1363 | tl_assert(isShadowAtom(mce,va2)); |
sewardj | 37c31cc | 2005-04-26 23:49:24 +0000 | [diff] [blame] | 1364 | |
| 1365 | /* The general case is inefficient because PCast is an expensive |
| 1366 | operation. Here are some special cases which use PCast only |
| 1367 | once rather than twice. */ |
| 1368 | |
| 1369 | /* I64 x I64 -> I64 */ |
| 1370 | if (t1 == Ity_I64 && t2 == Ity_I64 && finalVty == Ity_I64) { |
| 1371 | if (0) VG_(printf)("mkLazy2: I64 x I64 -> I64\n"); |
| 1372 | at = mkUifU(mce, Ity_I64, va1, va2); |
| 1373 | at = mkPCastTo(mce, Ity_I64, at); |
| 1374 | return at; |
| 1375 | } |
| 1376 | |
| 1377 | /* I64 x I64 -> I32 */ |
| 1378 | if (t1 == Ity_I64 && t2 == Ity_I64 && finalVty == Ity_I32) { |
| 1379 | if (0) VG_(printf)("mkLazy2: I64 x I64 -> I32\n"); |
| 1380 | at = mkUifU(mce, Ity_I64, va1, va2); |
| 1381 | at = mkPCastTo(mce, Ity_I32, at); |
| 1382 | return at; |
| 1383 | } |
| 1384 | |
| 1385 | if (0) { |
| 1386 | VG_(printf)("mkLazy2 "); |
| 1387 | ppIRType(t1); |
| 1388 | VG_(printf)("_"); |
| 1389 | ppIRType(t2); |
| 1390 | VG_(printf)("_"); |
| 1391 | ppIRType(finalVty); |
| 1392 | VG_(printf)("\n"); |
| 1393 | } |
| 1394 | |
| 1395 | /* General case: force everything via 32-bit intermediaries. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1396 | at = mkPCastTo(mce, Ity_I32, va1); |
| 1397 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va2)); |
| 1398 | at = mkPCastTo(mce, finalVty, at); |
| 1399 | return at; |
| 1400 | } |
| 1401 | |
| 1402 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1403 | /* 3-arg version of the above. */ |
| 1404 | static |
| 1405 | IRAtom* mkLazy3 ( MCEnv* mce, IRType finalVty, |
| 1406 | IRAtom* va1, IRAtom* va2, IRAtom* va3 ) |
| 1407 | { |
| 1408 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1409 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1410 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
| 1411 | IRType t3 = typeOfIRExpr(mce->sb->tyenv, va3); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1412 | tl_assert(isShadowAtom(mce,va1)); |
| 1413 | tl_assert(isShadowAtom(mce,va2)); |
| 1414 | tl_assert(isShadowAtom(mce,va3)); |
| 1415 | |
| 1416 | /* The general case is inefficient because PCast is an expensive |
| 1417 | operation. Here are some special cases which use PCast only |
| 1418 | twice rather than three times. */ |
| 1419 | |
| 1420 | /* I32 x I64 x I64 -> I64 */ |
| 1421 | /* Standard FP idiom: rm x FParg1 x FParg2 -> FPresult */ |
| 1422 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 |
| 1423 | && finalVty == Ity_I64) { |
| 1424 | if (0) VG_(printf)("mkLazy3: I32 x I64 x I64 -> I64\n"); |
| 1425 | /* Widen 1st arg to I64. Since 1st arg is typically a rounding |
| 1426 | mode indication which is fully defined, this should get |
| 1427 | folded out later. */ |
| 1428 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1429 | /* Now fold in 2nd and 3rd args. */ |
| 1430 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1431 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1432 | /* and PCast once again. */ |
| 1433 | at = mkPCastTo(mce, Ity_I64, at); |
| 1434 | return at; |
| 1435 | } |
| 1436 | |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1437 | /* I32 x I64 x I64 -> I32 */ |
| 1438 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 |
| 1439 | && finalVty == Ity_I32) { |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1440 | if (0) VG_(printf)("mkLazy3: I32 x I64 x I64 -> I32\n"); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1441 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1442 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1443 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1444 | at = mkPCastTo(mce, Ity_I32, at); |
| 1445 | return at; |
| 1446 | } |
| 1447 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1448 | /* I32 x I32 x I32 -> I32 */ |
| 1449 | /* 32-bit FP idiom, as (eg) happens on ARM */ |
| 1450 | if (t1 == Ity_I32 && t2 == Ity_I32 && t3 == Ity_I32 |
| 1451 | && finalVty == Ity_I32) { |
| 1452 | if (0) VG_(printf)("mkLazy3: I32 x I32 x I32 -> I32\n"); |
| 1453 | at = va1; |
| 1454 | at = mkUifU(mce, Ity_I32, at, va2); |
| 1455 | at = mkUifU(mce, Ity_I32, at, va3); |
| 1456 | at = mkPCastTo(mce, Ity_I32, at); |
| 1457 | return at; |
| 1458 | } |
| 1459 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1460 | /* I32 x I128 x I128 -> I128 */ |
| 1461 | /* Standard FP idiom: rm x FParg1 x FParg2 -> FPresult */ |
| 1462 | if (t1 == Ity_I32 && t2 == Ity_I128 && t3 == Ity_I128 |
| 1463 | && finalVty == Ity_I128) { |
| 1464 | if (0) VG_(printf)("mkLazy3: I32 x I128 x I128 -> I128\n"); |
| 1465 | /* Widen 1st arg to I128. Since 1st arg is typically a rounding |
| 1466 | mode indication which is fully defined, this should get |
| 1467 | folded out later. */ |
| 1468 | at = mkPCastTo(mce, Ity_I128, va1); |
| 1469 | /* Now fold in 2nd and 3rd args. */ |
| 1470 | at = mkUifU(mce, Ity_I128, at, va2); |
| 1471 | at = mkUifU(mce, Ity_I128, at, va3); |
| 1472 | /* and PCast once again. */ |
| 1473 | at = mkPCastTo(mce, Ity_I128, at); |
| 1474 | return at; |
| 1475 | } |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1476 | if (1) { |
| 1477 | VG_(printf)("mkLazy3: "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1478 | ppIRType(t1); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1479 | VG_(printf)(" x "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1480 | ppIRType(t2); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1481 | VG_(printf)(" x "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1482 | ppIRType(t3); |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1483 | VG_(printf)(" -> "); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1484 | ppIRType(finalVty); |
| 1485 | VG_(printf)("\n"); |
| 1486 | } |
| 1487 | |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1488 | tl_assert(0); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1489 | /* General case: force everything via 32-bit intermediaries. */ |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1490 | /* |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1491 | at = mkPCastTo(mce, Ity_I32, va1); |
| 1492 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va2)); |
| 1493 | at = mkUifU(mce, Ity_I32, at, mkPCastTo(mce, Ity_I32, va3)); |
| 1494 | at = mkPCastTo(mce, finalVty, at); |
| 1495 | return at; |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1496 | */ |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1500 | /* 4-arg version of the above. */ |
| 1501 | static |
| 1502 | IRAtom* mkLazy4 ( MCEnv* mce, IRType finalVty, |
| 1503 | IRAtom* va1, IRAtom* va2, IRAtom* va3, IRAtom* va4 ) |
| 1504 | { |
| 1505 | IRAtom* at; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1506 | IRType t1 = typeOfIRExpr(mce->sb->tyenv, va1); |
| 1507 | IRType t2 = typeOfIRExpr(mce->sb->tyenv, va2); |
| 1508 | IRType t3 = typeOfIRExpr(mce->sb->tyenv, va3); |
| 1509 | IRType t4 = typeOfIRExpr(mce->sb->tyenv, va4); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1510 | tl_assert(isShadowAtom(mce,va1)); |
| 1511 | tl_assert(isShadowAtom(mce,va2)); |
| 1512 | tl_assert(isShadowAtom(mce,va3)); |
| 1513 | tl_assert(isShadowAtom(mce,va4)); |
| 1514 | |
| 1515 | /* The general case is inefficient because PCast is an expensive |
| 1516 | operation. Here are some special cases which use PCast only |
| 1517 | twice rather than three times. */ |
| 1518 | |
| 1519 | /* I32 x I64 x I64 x I64 -> I64 */ |
| 1520 | /* Standard FP idiom: rm x FParg1 x FParg2 x FParg3 -> FPresult */ |
| 1521 | if (t1 == Ity_I32 && t2 == Ity_I64 && t3 == Ity_I64 && t4 == Ity_I64 |
| 1522 | && finalVty == Ity_I64) { |
| 1523 | if (0) VG_(printf)("mkLazy4: I32 x I64 x I64 x I64 -> I64\n"); |
| 1524 | /* Widen 1st arg to I64. Since 1st arg is typically a rounding |
| 1525 | mode indication which is fully defined, this should get |
| 1526 | folded out later. */ |
| 1527 | at = mkPCastTo(mce, Ity_I64, va1); |
| 1528 | /* Now fold in 2nd, 3rd, 4th args. */ |
| 1529 | at = mkUifU(mce, Ity_I64, at, va2); |
| 1530 | at = mkUifU(mce, Ity_I64, at, va3); |
| 1531 | at = mkUifU(mce, Ity_I64, at, va4); |
| 1532 | /* and PCast once again. */ |
| 1533 | at = mkPCastTo(mce, Ity_I64, at); |
| 1534 | return at; |
| 1535 | } |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1536 | /* I32 x I32 x I32 x I32 -> I32 */ |
| 1537 | /* Standard FP idiom: rm x FParg1 x FParg2 x FParg3 -> FPresult */ |
| 1538 | if (t1 == Ity_I32 && t2 == Ity_I32 && t3 == Ity_I32 && t4 == Ity_I32 |
| 1539 | && finalVty == Ity_I32) { |
| 1540 | if (0) VG_(printf)("mkLazy4: I32 x I32 x I32 x I32 -> I32\n"); |
| 1541 | at = va1; |
| 1542 | /* Now fold in 2nd, 3rd, 4th args. */ |
| 1543 | at = mkUifU(mce, Ity_I32, at, va2); |
| 1544 | at = mkUifU(mce, Ity_I32, at, va3); |
| 1545 | at = mkUifU(mce, Ity_I32, at, va4); |
| 1546 | at = mkPCastTo(mce, Ity_I32, at); |
| 1547 | return at; |
| 1548 | } |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1549 | |
| 1550 | if (1) { |
sewardj | 453e8f8 | 2006-02-09 03:25:06 +0000 | [diff] [blame] | 1551 | VG_(printf)("mkLazy4: "); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 1552 | ppIRType(t1); |
| 1553 | VG_(printf)(" x "); |
| 1554 | ppIRType(t2); |
| 1555 | VG_(printf)(" x "); |
| 1556 | ppIRType(t3); |
| 1557 | VG_(printf)(" x "); |
| 1558 | ppIRType(t4); |
| 1559 | VG_(printf)(" -> "); |
| 1560 | ppIRType(finalVty); |
| 1561 | VG_(printf)("\n"); |
| 1562 | } |
| 1563 | |
| 1564 | tl_assert(0); |
| 1565 | } |
| 1566 | |
| 1567 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1568 | /* Do the lazy propagation game from a null-terminated vector of |
| 1569 | atoms. This is presumably the arguments to a helper call, so the |
| 1570 | IRCallee info is also supplied in order that we can know which |
| 1571 | arguments should be ignored (via the .mcx_mask field). |
| 1572 | */ |
| 1573 | static |
| 1574 | IRAtom* mkLazyN ( MCEnv* mce, |
| 1575 | IRAtom** exprvec, IRType finalVtype, IRCallee* cee ) |
| 1576 | { |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1577 | Int i; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1578 | IRAtom* here; |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1579 | IRAtom* curr; |
| 1580 | IRType mergeTy; |
sewardj | 9943003 | 2011-05-04 09:09:31 +0000 | [diff] [blame] | 1581 | Bool mergeTy64 = True; |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1582 | |
| 1583 | /* Decide on the type of the merge intermediary. If all relevant |
| 1584 | args are I64, then it's I64. In all other circumstances, use |
| 1585 | I32. */ |
| 1586 | for (i = 0; exprvec[i]; i++) { |
| 1587 | tl_assert(i < 32); |
| 1588 | tl_assert(isOriginalAtom(mce, exprvec[i])); |
| 1589 | if (cee->mcx_mask & (1<<i)) |
| 1590 | continue; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 1591 | if (typeOfIRExpr(mce->sb->tyenv, exprvec[i]) != Ity_I64) |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1592 | mergeTy64 = False; |
| 1593 | } |
| 1594 | |
| 1595 | mergeTy = mergeTy64 ? Ity_I64 : Ity_I32; |
| 1596 | curr = definedOfType(mergeTy); |
| 1597 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1598 | for (i = 0; exprvec[i]; i++) { |
| 1599 | tl_assert(i < 32); |
| 1600 | tl_assert(isOriginalAtom(mce, exprvec[i])); |
| 1601 | /* Only take notice of this arg if the callee's mc-exclusion |
| 1602 | mask does not say it is to be excluded. */ |
| 1603 | if (cee->mcx_mask & (1<<i)) { |
| 1604 | /* the arg is to be excluded from definedness checking. Do |
| 1605 | nothing. */ |
| 1606 | if (0) VG_(printf)("excluding %s(%d)\n", cee->name, i); |
| 1607 | } else { |
| 1608 | /* calculate the arg's definedness, and pessimistically merge |
| 1609 | it in. */ |
sewardj | 4cc684b | 2007-08-25 23:09:36 +0000 | [diff] [blame] | 1610 | here = mkPCastTo( mce, mergeTy, expr2vbits(mce, exprvec[i]) ); |
| 1611 | curr = mergeTy64 |
| 1612 | ? mkUifU64(mce, here, curr) |
| 1613 | : mkUifU32(mce, here, curr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | return mkPCastTo(mce, finalVtype, curr ); |
| 1617 | } |
| 1618 | |
| 1619 | |
| 1620 | /*------------------------------------------------------------*/ |
| 1621 | /*--- Generating expensive sequences for exact carry-chain ---*/ |
| 1622 | /*--- propagation in add/sub and related operations. ---*/ |
| 1623 | /*------------------------------------------------------------*/ |
| 1624 | |
| 1625 | static |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1626 | IRAtom* expensiveAddSub ( MCEnv* mce, |
| 1627 | Bool add, |
| 1628 | IRType ty, |
| 1629 | IRAtom* qaa, IRAtom* qbb, |
| 1630 | IRAtom* aa, IRAtom* bb ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1631 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1632 | IRAtom *a_min, *b_min, *a_max, *b_max; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1633 | IROp opAND, opOR, opXOR, opNOT, opADD, opSUB; |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 1634 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1635 | tl_assert(isShadowAtom(mce,qaa)); |
| 1636 | tl_assert(isShadowAtom(mce,qbb)); |
| 1637 | tl_assert(isOriginalAtom(mce,aa)); |
| 1638 | tl_assert(isOriginalAtom(mce,bb)); |
| 1639 | tl_assert(sameKindedAtoms(qaa,aa)); |
| 1640 | tl_assert(sameKindedAtoms(qbb,bb)); |
| 1641 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1642 | switch (ty) { |
| 1643 | case Ity_I32: |
| 1644 | opAND = Iop_And32; |
| 1645 | opOR = Iop_Or32; |
| 1646 | opXOR = Iop_Xor32; |
| 1647 | opNOT = Iop_Not32; |
| 1648 | opADD = Iop_Add32; |
| 1649 | opSUB = Iop_Sub32; |
| 1650 | break; |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 1651 | case Ity_I64: |
| 1652 | opAND = Iop_And64; |
| 1653 | opOR = Iop_Or64; |
| 1654 | opXOR = Iop_Xor64; |
| 1655 | opNOT = Iop_Not64; |
| 1656 | opADD = Iop_Add64; |
| 1657 | opSUB = Iop_Sub64; |
| 1658 | break; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1659 | default: |
| 1660 | VG_(tool_panic)("expensiveAddSub"); |
| 1661 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1662 | |
| 1663 | // a_min = aa & ~qaa |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1664 | a_min = assignNew('V', mce,ty, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1665 | binop(opAND, aa, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1666 | assignNew('V', mce,ty, unop(opNOT, qaa)))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1667 | |
| 1668 | // b_min = bb & ~qbb |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1669 | b_min = assignNew('V', mce,ty, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1670 | binop(opAND, bb, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1671 | assignNew('V', mce,ty, unop(opNOT, qbb)))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1672 | |
| 1673 | // a_max = aa | qaa |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1674 | a_max = assignNew('V', mce,ty, binop(opOR, aa, qaa)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1675 | |
| 1676 | // b_max = bb | qbb |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1677 | b_max = assignNew('V', mce,ty, binop(opOR, bb, qbb)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1678 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1679 | if (add) { |
| 1680 | // result = (qaa | qbb) | ((a_min + b_min) ^ (a_max + b_max)) |
| 1681 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1682 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1683 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1684 | assignNew('V', mce,ty, binop(opOR, qaa, qbb)), |
| 1685 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1686 | binop( opXOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1687 | assignNew('V', mce,ty, binop(opADD, a_min, b_min)), |
| 1688 | assignNew('V', mce,ty, binop(opADD, a_max, b_max)) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1689 | ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1690 | ) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1691 | ) |
| 1692 | ); |
| 1693 | } else { |
| 1694 | // result = (qaa | qbb) | ((a_min - b_max) ^ (a_max + b_min)) |
| 1695 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1696 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1697 | binop( opOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1698 | assignNew('V', mce,ty, binop(opOR, qaa, qbb)), |
| 1699 | assignNew('V', mce,ty, |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1700 | binop( opXOR, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1701 | assignNew('V', mce,ty, binop(opSUB, a_min, b_max)), |
| 1702 | assignNew('V', mce,ty, binop(opSUB, a_max, b_min)) |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 1703 | ) |
| 1704 | ) |
| 1705 | ) |
| 1706 | ); |
| 1707 | } |
| 1708 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | /*------------------------------------------------------------*/ |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1713 | /*--- Scalar shifts. ---*/ |
| 1714 | /*------------------------------------------------------------*/ |
| 1715 | |
| 1716 | /* Produce an interpretation for (aa << bb) (or >>s, >>u). The basic |
| 1717 | idea is to shift the definedness bits by the original shift amount. |
| 1718 | This introduces 0s ("defined") in new positions for left shifts and |
| 1719 | unsigned right shifts, and copies the top definedness bit for |
| 1720 | signed right shifts. So, conveniently, applying the original shift |
| 1721 | operator to the definedness bits for the left arg is exactly the |
| 1722 | right thing to do: |
| 1723 | |
| 1724 | (qaa << bb) |
| 1725 | |
| 1726 | However if the shift amount is undefined then the whole result |
| 1727 | is undefined. Hence need: |
| 1728 | |
| 1729 | (qaa << bb) `UifU` PCast(qbb) |
| 1730 | |
| 1731 | If the shift amount bb is a literal than qbb will say 'all defined' |
| 1732 | and the UifU and PCast will get folded out by post-instrumentation |
| 1733 | optimisation. |
| 1734 | */ |
| 1735 | static IRAtom* scalarShift ( MCEnv* mce, |
| 1736 | IRType ty, |
| 1737 | IROp original_op, |
| 1738 | IRAtom* qaa, IRAtom* qbb, |
| 1739 | IRAtom* aa, IRAtom* bb ) |
| 1740 | { |
| 1741 | tl_assert(isShadowAtom(mce,qaa)); |
| 1742 | tl_assert(isShadowAtom(mce,qbb)); |
| 1743 | tl_assert(isOriginalAtom(mce,aa)); |
| 1744 | tl_assert(isOriginalAtom(mce,bb)); |
| 1745 | tl_assert(sameKindedAtoms(qaa,aa)); |
| 1746 | tl_assert(sameKindedAtoms(qbb,bb)); |
| 1747 | return |
| 1748 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1749 | 'V', mce, ty, |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1750 | mkUifU( mce, ty, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1751 | assignNew('V', mce, ty, binop(original_op, qaa, bb)), |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 1752 | mkPCastTo(mce, ty, qbb) |
| 1753 | ) |
| 1754 | ); |
| 1755 | } |
| 1756 | |
| 1757 | |
| 1758 | /*------------------------------------------------------------*/ |
| 1759 | /*--- Helpers for dealing with vector primops. ---*/ |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1760 | /*------------------------------------------------------------*/ |
| 1761 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1762 | /* Vector pessimisation -- pessimise within each lane individually. */ |
| 1763 | |
| 1764 | static IRAtom* mkPCast8x16 ( MCEnv* mce, IRAtom* at ) |
| 1765 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1766 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ8x16, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | static IRAtom* mkPCast16x8 ( MCEnv* mce, IRAtom* at ) |
| 1770 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1771 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ16x8, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | static IRAtom* mkPCast32x4 ( MCEnv* mce, IRAtom* at ) |
| 1775 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1776 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ32x4, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | static IRAtom* mkPCast64x2 ( MCEnv* mce, IRAtom* at ) |
| 1780 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1781 | return assignNew('V', mce, Ity_V128, unop(Iop_CmpNEZ64x2, at)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 1784 | static IRAtom* mkPCast32x2 ( MCEnv* mce, IRAtom* at ) |
| 1785 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1786 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ32x2, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | static IRAtom* mkPCast16x4 ( MCEnv* mce, IRAtom* at ) |
| 1790 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1791 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ16x4, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | static IRAtom* mkPCast8x8 ( MCEnv* mce, IRAtom* at ) |
| 1795 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1796 | return assignNew('V', mce, Ity_I64, unop(Iop_CmpNEZ8x8, at)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 1799 | static IRAtom* mkPCast16x2 ( MCEnv* mce, IRAtom* at ) |
| 1800 | { |
| 1801 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpNEZ16x2, at)); |
| 1802 | } |
| 1803 | |
| 1804 | static IRAtom* mkPCast8x4 ( MCEnv* mce, IRAtom* at ) |
| 1805 | { |
| 1806 | return assignNew('V', mce, Ity_I32, unop(Iop_CmpNEZ8x4, at)); |
| 1807 | } |
| 1808 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1809 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1810 | /* Here's a simple scheme capable of handling ops derived from SSE1 |
| 1811 | code and while only generating ops that can be efficiently |
| 1812 | implemented in SSE1. */ |
| 1813 | |
| 1814 | /* All-lanes versions are straightforward: |
| 1815 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1816 | binary32Fx4(x,y) ==> PCast32x4(UifUV128(x#,y#)) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1817 | |
| 1818 | unary32Fx4(x,y) ==> PCast32x4(x#) |
| 1819 | |
| 1820 | Lowest-lane-only versions are more complex: |
| 1821 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1822 | binary32F0x4(x,y) ==> SetV128lo32( |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1823 | x#, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1824 | PCast32(V128to32(UifUV128(x#,y#))) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1825 | ) |
| 1826 | |
| 1827 | This is perhaps not so obvious. In particular, it's faster to |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1828 | 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] | 1829 | obvious scheme of taking the bottom 32 bits of each operand |
| 1830 | and doing a 32-bit UifU. Basically since UifU is fast and |
| 1831 | chopping lanes off vector values is slow. |
| 1832 | |
| 1833 | Finally: |
| 1834 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1835 | unary32F0x4(x) ==> SetV128lo32( |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1836 | x#, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1837 | PCast32(V128to32(x#)) |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1838 | ) |
| 1839 | |
| 1840 | Where: |
| 1841 | |
| 1842 | PCast32(v#) = 1Sto32(CmpNE32(v#,0)) |
| 1843 | PCast32x4(v#) = CmpNEZ32x4(v#) |
| 1844 | */ |
| 1845 | |
| 1846 | static |
| 1847 | IRAtom* binary32Fx4 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 1848 | { |
| 1849 | IRAtom* at; |
| 1850 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1851 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1852 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1853 | at = assignNew('V', mce, Ity_V128, mkPCast32x4(mce, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1854 | return at; |
| 1855 | } |
| 1856 | |
| 1857 | static |
| 1858 | IRAtom* unary32Fx4 ( MCEnv* mce, IRAtom* vatomX ) |
| 1859 | { |
| 1860 | IRAtom* at; |
| 1861 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1862 | at = assignNew('V', mce, Ity_V128, mkPCast32x4(mce, vatomX)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1863 | return at; |
| 1864 | } |
| 1865 | |
| 1866 | static |
| 1867 | IRAtom* binary32F0x4 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 1868 | { |
| 1869 | IRAtom* at; |
| 1870 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1871 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1872 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1873 | at = assignNew('V', mce, Ity_I32, unop(Iop_V128to32, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1874 | at = mkPCastTo(mce, Ity_I32, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1875 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo32, vatomX, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1876 | return at; |
| 1877 | } |
| 1878 | |
| 1879 | static |
| 1880 | IRAtom* unary32F0x4 ( MCEnv* mce, IRAtom* vatomX ) |
| 1881 | { |
| 1882 | IRAtom* at; |
| 1883 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1884 | at = assignNew('V', mce, Ity_I32, unop(Iop_V128to32, vatomX)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1885 | at = mkPCastTo(mce, Ity_I32, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1886 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo32, vatomX, at)); |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 1887 | return at; |
| 1888 | } |
| 1889 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1890 | /* --- ... and ... 64Fx2 versions of the same ... --- */ |
| 1891 | |
| 1892 | static |
| 1893 | IRAtom* binary64Fx2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 1894 | { |
| 1895 | IRAtom* at; |
| 1896 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1897 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1898 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1899 | at = assignNew('V', mce, Ity_V128, mkPCast64x2(mce, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1900 | return at; |
| 1901 | } |
| 1902 | |
| 1903 | static |
| 1904 | IRAtom* unary64Fx2 ( MCEnv* mce, IRAtom* vatomX ) |
| 1905 | { |
| 1906 | IRAtom* at; |
| 1907 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1908 | at = assignNew('V', mce, Ity_V128, mkPCast64x2(mce, vatomX)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1909 | return at; |
| 1910 | } |
| 1911 | |
| 1912 | static |
| 1913 | IRAtom* binary64F0x2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 1914 | { |
| 1915 | IRAtom* at; |
| 1916 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1917 | tl_assert(isShadowAtom(mce, vatomY)); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 1918 | at = mkUifUV128(mce, vatomX, vatomY); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1919 | at = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1920 | at = mkPCastTo(mce, Ity_I64, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1921 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo64, vatomX, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1922 | return at; |
| 1923 | } |
| 1924 | |
| 1925 | static |
| 1926 | IRAtom* unary64F0x2 ( MCEnv* mce, IRAtom* vatomX ) |
| 1927 | { |
| 1928 | IRAtom* at; |
| 1929 | tl_assert(isShadowAtom(mce, vatomX)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1930 | at = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, vatomX)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1931 | at = mkPCastTo(mce, Ity_I64, at); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1932 | at = assignNew('V', mce, Ity_V128, binop(Iop_SetV128lo64, vatomX, at)); |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 1933 | return at; |
| 1934 | } |
| 1935 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 1936 | /* --- --- ... and ... 32Fx2 versions of the same --- --- */ |
| 1937 | |
| 1938 | static |
| 1939 | IRAtom* binary32Fx2 ( MCEnv* mce, IRAtom* vatomX, IRAtom* vatomY ) |
| 1940 | { |
| 1941 | IRAtom* at; |
| 1942 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1943 | tl_assert(isShadowAtom(mce, vatomY)); |
| 1944 | at = mkUifU64(mce, vatomX, vatomY); |
| 1945 | at = assignNew('V', mce, Ity_I64, mkPCast32x2(mce, at)); |
| 1946 | return at; |
| 1947 | } |
| 1948 | |
| 1949 | static |
| 1950 | IRAtom* unary32Fx2 ( MCEnv* mce, IRAtom* vatomX ) |
| 1951 | { |
| 1952 | IRAtom* at; |
| 1953 | tl_assert(isShadowAtom(mce, vatomX)); |
| 1954 | at = assignNew('V', mce, Ity_I64, mkPCast32x2(mce, vatomX)); |
| 1955 | return at; |
| 1956 | } |
| 1957 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1958 | /* --- --- Vector saturated narrowing --- --- */ |
| 1959 | |
| 1960 | /* This is quite subtle. What to do is simple: |
| 1961 | |
| 1962 | Let the original narrowing op be QNarrowW{S,U}xN. Produce: |
| 1963 | |
| 1964 | the-narrowing-op( PCastWxN(vatom1), PCastWxN(vatom2)) |
| 1965 | |
| 1966 | Why this is right is not so simple. Consider a lane in the args, |
| 1967 | vatom1 or 2, doesn't matter. |
| 1968 | |
| 1969 | After the PCast, that lane is all 0s (defined) or all |
| 1970 | 1s(undefined). |
| 1971 | |
| 1972 | Both signed and unsigned saturating narrowing of all 0s produces |
| 1973 | all 0s, which is what we want. |
| 1974 | |
| 1975 | The all-1s case is more complex. Unsigned narrowing interprets an |
| 1976 | all-1s input as the largest unsigned integer, and so produces all |
| 1977 | 1s as a result since that is the largest unsigned value at the |
| 1978 | smaller width. |
| 1979 | |
| 1980 | Signed narrowing interprets all 1s as -1. Fortunately, -1 narrows |
| 1981 | to -1, so we still wind up with all 1s at the smaller width. |
| 1982 | |
| 1983 | So: In short, pessimise the args, then apply the original narrowing |
| 1984 | op. |
sewardj | 9beeb0a | 2011-06-15 15:11:07 +0000 | [diff] [blame] | 1985 | |
| 1986 | FIXME JRS 2011-Jun-15: figure out if this is still correct |
| 1987 | following today's rationalisation/cleanup of vector narrowing |
| 1988 | primops. |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1989 | */ |
| 1990 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 1991 | IRAtom* vectorNarrowBinV128 ( MCEnv* mce, IROp narrow_op, |
| 1992 | IRAtom* vatom1, IRAtom* vatom2) |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 1993 | { |
| 1994 | IRAtom *at1, *at2, *at3; |
| 1995 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 1996 | switch (narrow_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 1997 | case Iop_QNarrowBin32Sto16Sx8: pcast = mkPCast32x4; break; |
| 1998 | case Iop_QNarrowBin32Uto16Ux8: pcast = mkPCast32x4; break; |
| 1999 | case Iop_QNarrowBin32Sto16Ux8: pcast = mkPCast32x4; break; |
| 2000 | case Iop_QNarrowBin16Sto8Sx16: pcast = mkPCast16x8; break; |
| 2001 | case Iop_QNarrowBin16Uto8Ux16: pcast = mkPCast16x8; break; |
| 2002 | case Iop_QNarrowBin16Sto8Ux16: pcast = mkPCast16x8; break; |
| 2003 | default: VG_(tool_panic)("vectorNarrowBinV128"); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2004 | } |
| 2005 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2006 | tl_assert(isShadowAtom(mce,vatom2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2007 | at1 = assignNew('V', mce, Ity_V128, pcast(mce, vatom1)); |
| 2008 | at2 = assignNew('V', mce, Ity_V128, pcast(mce, vatom2)); |
| 2009 | at3 = assignNew('V', mce, Ity_V128, binop(narrow_op, at1, at2)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2010 | return at3; |
| 2011 | } |
| 2012 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2013 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2014 | IRAtom* vectorNarrowBin64 ( MCEnv* mce, IROp narrow_op, |
| 2015 | IRAtom* vatom1, IRAtom* vatom2) |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2016 | { |
| 2017 | IRAtom *at1, *at2, *at3; |
| 2018 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2019 | switch (narrow_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2020 | case Iop_QNarrowBin32Sto16Sx4: pcast = mkPCast32x2; break; |
| 2021 | case Iop_QNarrowBin16Sto8Sx8: pcast = mkPCast16x4; break; |
| 2022 | case Iop_QNarrowBin16Sto8Ux8: pcast = mkPCast16x4; break; |
| 2023 | default: VG_(tool_panic)("vectorNarrowBin64"); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2024 | } |
| 2025 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2026 | tl_assert(isShadowAtom(mce,vatom2)); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2027 | at1 = assignNew('V', mce, Ity_I64, pcast(mce, vatom1)); |
| 2028 | at2 = assignNew('V', mce, Ity_I64, pcast(mce, vatom2)); |
| 2029 | at3 = assignNew('V', mce, Ity_I64, binop(narrow_op, at1, at2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2030 | return at3; |
| 2031 | } |
| 2032 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2033 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2034 | IRAtom* vectorNarrowUnV128 ( MCEnv* mce, IROp shorten_op, |
| 2035 | IRAtom* vatom1) |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2036 | { |
| 2037 | IRAtom *at1, *at2; |
| 2038 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2039 | switch (shorten_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2040 | /* FIXME: first 3 are too pessimistic; we can just |
| 2041 | apply them directly to the V bits. */ |
| 2042 | case Iop_NarrowUn16to8x8: pcast = mkPCast16x8; break; |
| 2043 | case Iop_NarrowUn32to16x4: pcast = mkPCast32x4; break; |
| 2044 | case Iop_NarrowUn64to32x2: pcast = mkPCast64x2; break; |
| 2045 | case Iop_QNarrowUn16Sto8Sx8: pcast = mkPCast16x8; break; |
| 2046 | case Iop_QNarrowUn16Sto8Ux8: pcast = mkPCast16x8; break; |
| 2047 | case Iop_QNarrowUn16Uto8Ux8: pcast = mkPCast16x8; break; |
| 2048 | case Iop_QNarrowUn32Sto16Sx4: pcast = mkPCast32x4; break; |
| 2049 | case Iop_QNarrowUn32Sto16Ux4: pcast = mkPCast32x4; break; |
| 2050 | case Iop_QNarrowUn32Uto16Ux4: pcast = mkPCast32x4; break; |
| 2051 | case Iop_QNarrowUn64Sto32Sx2: pcast = mkPCast64x2; break; |
| 2052 | case Iop_QNarrowUn64Sto32Ux2: pcast = mkPCast64x2; break; |
| 2053 | case Iop_QNarrowUn64Uto32Ux2: pcast = mkPCast64x2; break; |
| 2054 | default: VG_(tool_panic)("vectorNarrowUnV128"); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2055 | } |
| 2056 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2057 | at1 = assignNew('V', mce, Ity_V128, pcast(mce, vatom1)); |
| 2058 | at2 = assignNew('V', mce, Ity_I64, unop(shorten_op, at1)); |
| 2059 | return at2; |
| 2060 | } |
| 2061 | |
| 2062 | static |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2063 | IRAtom* vectorWidenI64 ( MCEnv* mce, IROp longen_op, |
| 2064 | IRAtom* vatom1) |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2065 | { |
| 2066 | IRAtom *at1, *at2; |
| 2067 | IRAtom* (*pcast)( MCEnv*, IRAtom* ); |
| 2068 | switch (longen_op) { |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2069 | case Iop_Widen8Uto16x8: pcast = mkPCast16x8; break; |
| 2070 | case Iop_Widen8Sto16x8: pcast = mkPCast16x8; break; |
| 2071 | case Iop_Widen16Uto32x4: pcast = mkPCast32x4; break; |
| 2072 | case Iop_Widen16Sto32x4: pcast = mkPCast32x4; break; |
| 2073 | case Iop_Widen32Uto64x2: pcast = mkPCast64x2; break; |
| 2074 | case Iop_Widen32Sto64x2: pcast = mkPCast64x2; break; |
| 2075 | default: VG_(tool_panic)("vectorWidenI64"); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2076 | } |
| 2077 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2078 | at1 = assignNew('V', mce, Ity_V128, unop(longen_op, vatom1)); |
| 2079 | at2 = assignNew('V', mce, Ity_V128, pcast(mce, at1)); |
| 2080 | return at2; |
| 2081 | } |
| 2082 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2083 | |
| 2084 | /* --- --- Vector integer arithmetic --- --- */ |
| 2085 | |
| 2086 | /* Simple ... UifU the args and per-lane pessimise the results. */ |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2087 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2088 | /* --- V128-bit versions --- */ |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2089 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2090 | static |
| 2091 | IRAtom* binary8Ix16 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2092 | { |
| 2093 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2094 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2095 | at = mkPCast8x16(mce, at); |
| 2096 | return at; |
| 2097 | } |
| 2098 | |
| 2099 | static |
| 2100 | IRAtom* binary16Ix8 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2101 | { |
| 2102 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2103 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2104 | at = mkPCast16x8(mce, at); |
| 2105 | return at; |
| 2106 | } |
| 2107 | |
| 2108 | static |
| 2109 | IRAtom* binary32Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2110 | { |
| 2111 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2112 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2113 | at = mkPCast32x4(mce, at); |
| 2114 | return at; |
| 2115 | } |
| 2116 | |
| 2117 | static |
| 2118 | IRAtom* binary64Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2119 | { |
| 2120 | IRAtom* at; |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2121 | at = mkUifUV128(mce, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2122 | at = mkPCast64x2(mce, at); |
| 2123 | return at; |
| 2124 | } |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2125 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2126 | /* --- 64-bit versions --- */ |
| 2127 | |
| 2128 | static |
| 2129 | IRAtom* binary8Ix8 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2130 | { |
| 2131 | IRAtom* at; |
| 2132 | at = mkUifU64(mce, vatom1, vatom2); |
| 2133 | at = mkPCast8x8(mce, at); |
| 2134 | return at; |
| 2135 | } |
| 2136 | |
| 2137 | static |
| 2138 | IRAtom* binary16Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2139 | { |
| 2140 | IRAtom* at; |
| 2141 | at = mkUifU64(mce, vatom1, vatom2); |
| 2142 | at = mkPCast16x4(mce, at); |
| 2143 | return at; |
| 2144 | } |
| 2145 | |
| 2146 | static |
| 2147 | IRAtom* binary32Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2148 | { |
| 2149 | IRAtom* at; |
| 2150 | at = mkUifU64(mce, vatom1, vatom2); |
| 2151 | at = mkPCast32x2(mce, at); |
| 2152 | return at; |
| 2153 | } |
| 2154 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2155 | static |
| 2156 | IRAtom* binary64Ix1 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2157 | { |
| 2158 | IRAtom* at; |
| 2159 | at = mkUifU64(mce, vatom1, vatom2); |
| 2160 | at = mkPCastTo(mce, Ity_I64, at); |
| 2161 | return at; |
| 2162 | } |
| 2163 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2164 | /* --- 32-bit versions --- */ |
| 2165 | |
| 2166 | static |
| 2167 | IRAtom* binary8Ix4 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2168 | { |
| 2169 | IRAtom* at; |
| 2170 | at = mkUifU32(mce, vatom1, vatom2); |
| 2171 | at = mkPCast8x4(mce, at); |
| 2172 | return at; |
| 2173 | } |
| 2174 | |
| 2175 | static |
| 2176 | IRAtom* binary16Ix2 ( MCEnv* mce, IRAtom* vatom1, IRAtom* vatom2 ) |
| 2177 | { |
| 2178 | IRAtom* at; |
| 2179 | at = mkUifU32(mce, vatom1, vatom2); |
| 2180 | at = mkPCast16x2(mce, at); |
| 2181 | return at; |
| 2182 | } |
| 2183 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2184 | |
| 2185 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2186 | /*--- Generate shadow values from all kinds of IRExprs. ---*/ |
| 2187 | /*------------------------------------------------------------*/ |
| 2188 | |
| 2189 | static |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 2190 | IRAtom* expr2vbits_Qop ( MCEnv* mce, |
| 2191 | IROp op, |
| 2192 | IRAtom* atom1, IRAtom* atom2, |
| 2193 | IRAtom* atom3, IRAtom* atom4 ) |
| 2194 | { |
| 2195 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2196 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2197 | IRAtom* vatom3 = expr2vbits( mce, atom3 ); |
| 2198 | IRAtom* vatom4 = expr2vbits( mce, atom4 ); |
| 2199 | |
| 2200 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2201 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2202 | tl_assert(isOriginalAtom(mce,atom3)); |
| 2203 | tl_assert(isOriginalAtom(mce,atom4)); |
| 2204 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2205 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2206 | tl_assert(isShadowAtom(mce,vatom3)); |
| 2207 | tl_assert(isShadowAtom(mce,vatom4)); |
| 2208 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2209 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2210 | tl_assert(sameKindedAtoms(atom3,vatom3)); |
| 2211 | tl_assert(sameKindedAtoms(atom4,vatom4)); |
| 2212 | switch (op) { |
| 2213 | case Iop_MAddF64: |
| 2214 | case Iop_MAddF64r32: |
| 2215 | case Iop_MSubF64: |
| 2216 | case Iop_MSubF64r32: |
| 2217 | /* I32(rm) x F64 x F64 x F64 -> F64 */ |
| 2218 | return mkLazy4(mce, Ity_I64, vatom1, vatom2, vatom3, vatom4); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2219 | |
| 2220 | case Iop_MAddF32: |
| 2221 | case Iop_MSubF32: |
| 2222 | /* I32(rm) x F32 x F32 x F32 -> F32 */ |
| 2223 | return mkLazy4(mce, Ity_I32, vatom1, vatom2, vatom3, vatom4); |
| 2224 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 2225 | default: |
| 2226 | ppIROp(op); |
| 2227 | VG_(tool_panic)("memcheck:expr2vbits_Qop"); |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | |
| 2232 | static |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2233 | IRAtom* expr2vbits_Triop ( MCEnv* mce, |
| 2234 | IROp op, |
| 2235 | IRAtom* atom1, IRAtom* atom2, IRAtom* atom3 ) |
| 2236 | { |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2237 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2238 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2239 | IRAtom* vatom3 = expr2vbits( mce, atom3 ); |
| 2240 | |
| 2241 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2242 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2243 | tl_assert(isOriginalAtom(mce,atom3)); |
| 2244 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2245 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2246 | tl_assert(isShadowAtom(mce,vatom3)); |
| 2247 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2248 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2249 | tl_assert(sameKindedAtoms(atom3,vatom3)); |
| 2250 | switch (op) { |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2251 | case Iop_AddF128: |
| 2252 | case Iop_SubF128: |
| 2253 | case Iop_MulF128: |
| 2254 | case Iop_DivF128: |
| 2255 | /* I32(rm) x F128 x F128 -> F128 */ |
| 2256 | return mkLazy3(mce, Ity_I128, vatom1, vatom2, vatom3); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2257 | case Iop_AddF64: |
| 2258 | case Iop_AddF64r32: |
| 2259 | case Iop_SubF64: |
| 2260 | case Iop_SubF64r32: |
| 2261 | case Iop_MulF64: |
| 2262 | case Iop_MulF64r32: |
| 2263 | case Iop_DivF64: |
| 2264 | case Iop_DivF64r32: |
sewardj | 22ac5f4 | 2006-02-03 22:55:04 +0000 | [diff] [blame] | 2265 | case Iop_ScaleF64: |
| 2266 | case Iop_Yl2xF64: |
| 2267 | case Iop_Yl2xp1F64: |
| 2268 | case Iop_AtanF64: |
sewardj | d6075eb | 2006-02-04 15:25:23 +0000 | [diff] [blame] | 2269 | case Iop_PRemF64: |
| 2270 | case Iop_PRem1F64: |
sewardj | 22ac5f4 | 2006-02-03 22:55:04 +0000 | [diff] [blame] | 2271 | /* I32(rm) x F64 x F64 -> F64 */ |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2272 | return mkLazy3(mce, Ity_I64, vatom1, vatom2, vatom3); |
sewardj | d6075eb | 2006-02-04 15:25:23 +0000 | [diff] [blame] | 2273 | case Iop_PRemC3210F64: |
| 2274 | case Iop_PRem1C3210F64: |
| 2275 | /* I32(rm) x F64 x F64 -> I32 */ |
| 2276 | return mkLazy3(mce, Ity_I32, vatom1, vatom2, vatom3); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2277 | case Iop_AddF32: |
| 2278 | case Iop_SubF32: |
| 2279 | case Iop_MulF32: |
| 2280 | case Iop_DivF32: |
| 2281 | /* I32(rm) x F32 x F32 -> I32 */ |
| 2282 | return mkLazy3(mce, Ity_I32, vatom1, vatom2, vatom3); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2283 | case Iop_ExtractV128: |
| 2284 | complainIfUndefined(mce, atom3); |
| 2285 | return assignNew('V', mce, Ity_V128, triop(op, vatom1, vatom2, atom3)); |
| 2286 | case Iop_Extract64: |
| 2287 | complainIfUndefined(mce, atom3); |
| 2288 | return assignNew('V', mce, Ity_I64, triop(op, vatom1, vatom2, atom3)); |
| 2289 | case Iop_SetElem8x8: |
| 2290 | case Iop_SetElem16x4: |
| 2291 | case Iop_SetElem32x2: |
| 2292 | complainIfUndefined(mce, atom2); |
| 2293 | return assignNew('V', mce, Ity_I64, triop(op, vatom1, atom2, vatom3)); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2294 | default: |
| 2295 | ppIROp(op); |
| 2296 | VG_(tool_panic)("memcheck:expr2vbits_Triop"); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | static |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2302 | IRAtom* expr2vbits_Binop ( MCEnv* mce, |
| 2303 | IROp op, |
| 2304 | IRAtom* atom1, IRAtom* atom2 ) |
| 2305 | { |
| 2306 | IRType and_or_ty; |
| 2307 | IRAtom* (*uifu) (MCEnv*, IRAtom*, IRAtom*); |
| 2308 | IRAtom* (*difd) (MCEnv*, IRAtom*, IRAtom*); |
| 2309 | IRAtom* (*improve) (MCEnv*, IRAtom*, IRAtom*); |
| 2310 | |
| 2311 | IRAtom* vatom1 = expr2vbits( mce, atom1 ); |
| 2312 | IRAtom* vatom2 = expr2vbits( mce, atom2 ); |
| 2313 | |
| 2314 | tl_assert(isOriginalAtom(mce,atom1)); |
| 2315 | tl_assert(isOriginalAtom(mce,atom2)); |
| 2316 | tl_assert(isShadowAtom(mce,vatom1)); |
| 2317 | tl_assert(isShadowAtom(mce,vatom2)); |
| 2318 | tl_assert(sameKindedAtoms(atom1,vatom1)); |
| 2319 | tl_assert(sameKindedAtoms(atom2,vatom2)); |
| 2320 | switch (op) { |
| 2321 | |
sewardj | c678b85 | 2010-09-22 00:58:51 +0000 | [diff] [blame] | 2322 | /* 32-bit SIMD */ |
| 2323 | |
| 2324 | case Iop_Add16x2: |
| 2325 | case Iop_HAdd16Ux2: |
| 2326 | case Iop_HAdd16Sx2: |
| 2327 | case Iop_Sub16x2: |
| 2328 | case Iop_HSub16Ux2: |
| 2329 | case Iop_HSub16Sx2: |
| 2330 | case Iop_QAdd16Sx2: |
| 2331 | case Iop_QSub16Sx2: |
| 2332 | return binary16Ix2(mce, vatom1, vatom2); |
| 2333 | |
| 2334 | case Iop_Add8x4: |
| 2335 | case Iop_HAdd8Ux4: |
| 2336 | case Iop_HAdd8Sx4: |
| 2337 | case Iop_Sub8x4: |
| 2338 | case Iop_HSub8Ux4: |
| 2339 | case Iop_HSub8Sx4: |
| 2340 | case Iop_QSub8Ux4: |
| 2341 | case Iop_QAdd8Ux4: |
| 2342 | case Iop_QSub8Sx4: |
| 2343 | case Iop_QAdd8Sx4: |
| 2344 | return binary8Ix4(mce, vatom1, vatom2); |
| 2345 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2346 | /* 64-bit SIMD */ |
| 2347 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2348 | case Iop_ShrN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2349 | case Iop_ShrN16x4: |
| 2350 | case Iop_ShrN32x2: |
sewardj | 03809ae | 2006-12-27 01:16:58 +0000 | [diff] [blame] | 2351 | case Iop_SarN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2352 | case Iop_SarN16x4: |
| 2353 | case Iop_SarN32x2: |
| 2354 | case Iop_ShlN16x4: |
| 2355 | case Iop_ShlN32x2: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2356 | case Iop_ShlN8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2357 | /* Same scheme as with all other shifts. */ |
| 2358 | complainIfUndefined(mce, atom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2359 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2360 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2361 | case Iop_QNarrowBin32Sto16Sx4: |
| 2362 | case Iop_QNarrowBin16Sto8Sx8: |
| 2363 | case Iop_QNarrowBin16Sto8Ux8: |
| 2364 | return vectorNarrowBin64(mce, op, vatom1, vatom2); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2365 | |
| 2366 | case Iop_Min8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2367 | case Iop_Min8Sx8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2368 | case Iop_Max8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2369 | case Iop_Max8Sx8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2370 | case Iop_Avg8Ux8: |
| 2371 | case Iop_QSub8Sx8: |
| 2372 | case Iop_QSub8Ux8: |
| 2373 | case Iop_Sub8x8: |
| 2374 | case Iop_CmpGT8Sx8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2375 | case Iop_CmpGT8Ux8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2376 | case Iop_CmpEQ8x8: |
| 2377 | case Iop_QAdd8Sx8: |
| 2378 | case Iop_QAdd8Ux8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2379 | case Iop_QSal8x8: |
| 2380 | case Iop_QShl8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2381 | case Iop_Add8x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2382 | case Iop_Mul8x8: |
| 2383 | case Iop_PolynomialMul8x8: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2384 | return binary8Ix8(mce, vatom1, vatom2); |
| 2385 | |
| 2386 | case Iop_Min16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2387 | case Iop_Min16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2388 | case Iop_Max16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2389 | case Iop_Max16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2390 | case Iop_Avg16Ux4: |
| 2391 | case Iop_QSub16Ux4: |
| 2392 | case Iop_QSub16Sx4: |
| 2393 | case Iop_Sub16x4: |
| 2394 | case Iop_Mul16x4: |
| 2395 | case Iop_MulHi16Sx4: |
| 2396 | case Iop_MulHi16Ux4: |
| 2397 | case Iop_CmpGT16Sx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2398 | case Iop_CmpGT16Ux4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2399 | case Iop_CmpEQ16x4: |
| 2400 | case Iop_QAdd16Sx4: |
| 2401 | case Iop_QAdd16Ux4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2402 | case Iop_QSal16x4: |
| 2403 | case Iop_QShl16x4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2404 | case Iop_Add16x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2405 | case Iop_QDMulHi16Sx4: |
| 2406 | case Iop_QRDMulHi16Sx4: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2407 | return binary16Ix4(mce, vatom1, vatom2); |
| 2408 | |
| 2409 | case Iop_Sub32x2: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2410 | case Iop_Mul32x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2411 | case Iop_Max32Sx2: |
| 2412 | case Iop_Max32Ux2: |
| 2413 | case Iop_Min32Sx2: |
| 2414 | case Iop_Min32Ux2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2415 | case Iop_CmpGT32Sx2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2416 | case Iop_CmpGT32Ux2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2417 | case Iop_CmpEQ32x2: |
| 2418 | case Iop_Add32x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2419 | case Iop_QAdd32Ux2: |
| 2420 | case Iop_QAdd32Sx2: |
| 2421 | case Iop_QSub32Ux2: |
| 2422 | case Iop_QSub32Sx2: |
| 2423 | case Iop_QSal32x2: |
| 2424 | case Iop_QShl32x2: |
| 2425 | case Iop_QDMulHi32Sx2: |
| 2426 | case Iop_QRDMulHi32Sx2: |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2427 | return binary32Ix2(mce, vatom1, vatom2); |
| 2428 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2429 | case Iop_QSub64Ux1: |
| 2430 | case Iop_QSub64Sx1: |
| 2431 | case Iop_QAdd64Ux1: |
| 2432 | case Iop_QAdd64Sx1: |
| 2433 | case Iop_QSal64x1: |
| 2434 | case Iop_QShl64x1: |
| 2435 | case Iop_Sal64x1: |
| 2436 | return binary64Ix1(mce, vatom1, vatom2); |
| 2437 | |
| 2438 | case Iop_QShlN8Sx8: |
| 2439 | case Iop_QShlN8x8: |
| 2440 | case Iop_QSalN8x8: |
| 2441 | complainIfUndefined(mce, atom2); |
| 2442 | return mkPCast8x8(mce, vatom1); |
| 2443 | |
| 2444 | case Iop_QShlN16Sx4: |
| 2445 | case Iop_QShlN16x4: |
| 2446 | case Iop_QSalN16x4: |
| 2447 | complainIfUndefined(mce, atom2); |
| 2448 | return mkPCast16x4(mce, vatom1); |
| 2449 | |
| 2450 | case Iop_QShlN32Sx2: |
| 2451 | case Iop_QShlN32x2: |
| 2452 | case Iop_QSalN32x2: |
| 2453 | complainIfUndefined(mce, atom2); |
| 2454 | return mkPCast32x2(mce, vatom1); |
| 2455 | |
| 2456 | case Iop_QShlN64Sx1: |
| 2457 | case Iop_QShlN64x1: |
| 2458 | case Iop_QSalN64x1: |
| 2459 | complainIfUndefined(mce, atom2); |
| 2460 | return mkPCast32x2(mce, vatom1); |
| 2461 | |
| 2462 | case Iop_PwMax32Sx2: |
| 2463 | case Iop_PwMax32Ux2: |
| 2464 | case Iop_PwMin32Sx2: |
| 2465 | case Iop_PwMin32Ux2: |
| 2466 | case Iop_PwMax32Fx2: |
| 2467 | case Iop_PwMin32Fx2: |
| 2468 | return assignNew('V', mce, Ity_I64, binop(Iop_PwMax32Ux2, mkPCast32x2(mce, vatom1), |
| 2469 | mkPCast32x2(mce, vatom2))); |
| 2470 | |
| 2471 | case Iop_PwMax16Sx4: |
| 2472 | case Iop_PwMax16Ux4: |
| 2473 | case Iop_PwMin16Sx4: |
| 2474 | case Iop_PwMin16Ux4: |
| 2475 | return assignNew('V', mce, Ity_I64, binop(Iop_PwMax16Ux4, mkPCast16x4(mce, vatom1), |
| 2476 | mkPCast16x4(mce, vatom2))); |
| 2477 | |
| 2478 | case Iop_PwMax8Sx8: |
| 2479 | case Iop_PwMax8Ux8: |
| 2480 | case Iop_PwMin8Sx8: |
| 2481 | case Iop_PwMin8Ux8: |
| 2482 | return assignNew('V', mce, Ity_I64, binop(Iop_PwMax8Ux8, mkPCast8x8(mce, vatom1), |
| 2483 | mkPCast8x8(mce, vatom2))); |
| 2484 | |
| 2485 | case Iop_PwAdd32x2: |
| 2486 | case Iop_PwAdd32Fx2: |
| 2487 | return mkPCast32x2(mce, |
| 2488 | assignNew('V', mce, Ity_I64, binop(Iop_PwAdd32x2, mkPCast32x2(mce, vatom1), |
| 2489 | mkPCast32x2(mce, vatom2)))); |
| 2490 | |
| 2491 | case Iop_PwAdd16x4: |
| 2492 | return mkPCast16x4(mce, |
| 2493 | assignNew('V', mce, Ity_I64, binop(op, mkPCast16x4(mce, vatom1), |
| 2494 | mkPCast16x4(mce, vatom2)))); |
| 2495 | |
| 2496 | case Iop_PwAdd8x8: |
| 2497 | return mkPCast8x8(mce, |
| 2498 | assignNew('V', mce, Ity_I64, binop(op, mkPCast8x8(mce, vatom1), |
| 2499 | mkPCast8x8(mce, vatom2)))); |
| 2500 | |
| 2501 | case Iop_Shl8x8: |
| 2502 | case Iop_Shr8x8: |
| 2503 | case Iop_Sar8x8: |
| 2504 | case Iop_Sal8x8: |
| 2505 | return mkUifU64(mce, |
| 2506 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 2507 | mkPCast8x8(mce,vatom2) |
| 2508 | ); |
| 2509 | |
| 2510 | case Iop_Shl16x4: |
| 2511 | case Iop_Shr16x4: |
| 2512 | case Iop_Sar16x4: |
| 2513 | case Iop_Sal16x4: |
| 2514 | return mkUifU64(mce, |
| 2515 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 2516 | mkPCast16x4(mce,vatom2) |
| 2517 | ); |
| 2518 | |
| 2519 | case Iop_Shl32x2: |
| 2520 | case Iop_Shr32x2: |
| 2521 | case Iop_Sar32x2: |
| 2522 | case Iop_Sal32x2: |
| 2523 | return mkUifU64(mce, |
| 2524 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
| 2525 | mkPCast32x2(mce,vatom2) |
| 2526 | ); |
| 2527 | |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2528 | /* 64-bit data-steering */ |
| 2529 | case Iop_InterleaveLO32x2: |
| 2530 | case Iop_InterleaveLO16x4: |
| 2531 | case Iop_InterleaveLO8x8: |
| 2532 | case Iop_InterleaveHI32x2: |
| 2533 | case Iop_InterleaveHI16x4: |
| 2534 | case Iop_InterleaveHI8x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2535 | case Iop_CatOddLanes8x8: |
| 2536 | case Iop_CatEvenLanes8x8: |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2537 | case Iop_CatOddLanes16x4: |
| 2538 | case Iop_CatEvenLanes16x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2539 | case Iop_InterleaveOddLanes8x8: |
| 2540 | case Iop_InterleaveEvenLanes8x8: |
| 2541 | case Iop_InterleaveOddLanes16x4: |
| 2542 | case Iop_InterleaveEvenLanes16x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2543 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, vatom2)); |
sewardj | acd2e91 | 2005-01-13 19:17:06 +0000 | [diff] [blame] | 2544 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2545 | case Iop_GetElem8x8: |
| 2546 | complainIfUndefined(mce, atom2); |
| 2547 | return assignNew('V', mce, Ity_I8, binop(op, vatom1, atom2)); |
| 2548 | case Iop_GetElem16x4: |
| 2549 | complainIfUndefined(mce, atom2); |
| 2550 | return assignNew('V', mce, Ity_I16, binop(op, vatom1, atom2)); |
| 2551 | case Iop_GetElem32x2: |
| 2552 | complainIfUndefined(mce, atom2); |
| 2553 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, atom2)); |
| 2554 | |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2555 | /* Perm8x8: rearrange values in left arg using steering values |
| 2556 | from right arg. So rearrange the vbits in the same way but |
| 2557 | pessimise wrt steering values. */ |
| 2558 | case Iop_Perm8x8: |
| 2559 | return mkUifU64( |
| 2560 | mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2561 | assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)), |
sewardj | 114a917 | 2008-02-09 01:49:32 +0000 | [diff] [blame] | 2562 | mkPCast8x8(mce, vatom2) |
| 2563 | ); |
| 2564 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2565 | /* V128-bit SIMD */ |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2566 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2567 | case Iop_ShrN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2568 | case Iop_ShrN16x8: |
| 2569 | case Iop_ShrN32x4: |
| 2570 | case Iop_ShrN64x2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2571 | case Iop_SarN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2572 | case Iop_SarN16x8: |
| 2573 | case Iop_SarN32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2574 | case Iop_SarN64x2: |
| 2575 | case Iop_ShlN8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2576 | case Iop_ShlN16x8: |
| 2577 | case Iop_ShlN32x4: |
| 2578 | case Iop_ShlN64x2: |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 2579 | /* Same scheme as with all other shifts. Note: 22 Oct 05: |
| 2580 | this is wrong now, scalar shifts are done properly lazily. |
| 2581 | Vector shifts should be fixed too. */ |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2582 | complainIfUndefined(mce, atom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2583 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2584 | |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 2585 | /* V x V shifts/rotates are done using the standard lazy scheme. */ |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2586 | case Iop_Shl8x16: |
| 2587 | case Iop_Shr8x16: |
| 2588 | case Iop_Sar8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2589 | case Iop_Sal8x16: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 2590 | case Iop_Rol8x16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2591 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2592 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2593 | mkPCast8x16(mce,vatom2) |
| 2594 | ); |
| 2595 | |
| 2596 | case Iop_Shl16x8: |
| 2597 | case Iop_Shr16x8: |
| 2598 | case Iop_Sar16x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2599 | case Iop_Sal16x8: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 2600 | case Iop_Rol16x8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2601 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2602 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2603 | mkPCast16x8(mce,vatom2) |
| 2604 | ); |
| 2605 | |
| 2606 | case Iop_Shl32x4: |
| 2607 | case Iop_Shr32x4: |
| 2608 | case Iop_Sar32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2609 | case Iop_Sal32x4: |
sewardj | cbf8be7 | 2005-11-10 18:34:41 +0000 | [diff] [blame] | 2610 | case Iop_Rol32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2611 | return mkUifUV128(mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2612 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2613 | mkPCast32x4(mce,vatom2) |
| 2614 | ); |
| 2615 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2616 | case Iop_Shl64x2: |
| 2617 | case Iop_Shr64x2: |
| 2618 | case Iop_Sar64x2: |
| 2619 | case Iop_Sal64x2: |
| 2620 | return mkUifUV128(mce, |
| 2621 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
| 2622 | mkPCast64x2(mce,vatom2) |
| 2623 | ); |
| 2624 | |
| 2625 | case Iop_F32ToFixed32Ux4_RZ: |
| 2626 | case Iop_F32ToFixed32Sx4_RZ: |
| 2627 | case Iop_Fixed32UToF32x4_RN: |
| 2628 | case Iop_Fixed32SToF32x4_RN: |
| 2629 | complainIfUndefined(mce, atom2); |
| 2630 | return mkPCast32x4(mce, vatom1); |
| 2631 | |
| 2632 | case Iop_F32ToFixed32Ux2_RZ: |
| 2633 | case Iop_F32ToFixed32Sx2_RZ: |
| 2634 | case Iop_Fixed32UToF32x2_RN: |
| 2635 | case Iop_Fixed32SToF32x2_RN: |
| 2636 | complainIfUndefined(mce, atom2); |
| 2637 | return mkPCast32x2(mce, vatom1); |
| 2638 | |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2639 | case Iop_QSub8Ux16: |
| 2640 | case Iop_QSub8Sx16: |
| 2641 | case Iop_Sub8x16: |
| 2642 | case Iop_Min8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2643 | case Iop_Min8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2644 | case Iop_Max8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2645 | case Iop_Max8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2646 | case Iop_CmpGT8Sx16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2647 | case Iop_CmpGT8Ux16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2648 | case Iop_CmpEQ8x16: |
| 2649 | case Iop_Avg8Ux16: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2650 | case Iop_Avg8Sx16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2651 | case Iop_QAdd8Ux16: |
| 2652 | case Iop_QAdd8Sx16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2653 | case Iop_QSal8x16: |
| 2654 | case Iop_QShl8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2655 | case Iop_Add8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2656 | case Iop_Mul8x16: |
| 2657 | case Iop_PolynomialMul8x16: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2658 | return binary8Ix16(mce, vatom1, vatom2); |
| 2659 | |
| 2660 | case Iop_QSub16Ux8: |
| 2661 | case Iop_QSub16Sx8: |
| 2662 | case Iop_Sub16x8: |
| 2663 | case Iop_Mul16x8: |
| 2664 | case Iop_MulHi16Sx8: |
| 2665 | case Iop_MulHi16Ux8: |
| 2666 | case Iop_Min16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2667 | case Iop_Min16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2668 | case Iop_Max16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2669 | case Iop_Max16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2670 | case Iop_CmpGT16Sx8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2671 | case Iop_CmpGT16Ux8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2672 | case Iop_CmpEQ16x8: |
| 2673 | case Iop_Avg16Ux8: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2674 | case Iop_Avg16Sx8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2675 | case Iop_QAdd16Ux8: |
| 2676 | case Iop_QAdd16Sx8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2677 | case Iop_QSal16x8: |
| 2678 | case Iop_QShl16x8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2679 | case Iop_Add16x8: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2680 | case Iop_QDMulHi16Sx8: |
| 2681 | case Iop_QRDMulHi16Sx8: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2682 | return binary16Ix8(mce, vatom1, vatom2); |
| 2683 | |
| 2684 | case Iop_Sub32x4: |
| 2685 | case Iop_CmpGT32Sx4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2686 | case Iop_CmpGT32Ux4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2687 | case Iop_CmpEQ32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2688 | case Iop_QAdd32Sx4: |
| 2689 | case Iop_QAdd32Ux4: |
| 2690 | case Iop_QSub32Sx4: |
| 2691 | case Iop_QSub32Ux4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2692 | case Iop_QSal32x4: |
| 2693 | case Iop_QShl32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2694 | case Iop_Avg32Ux4: |
| 2695 | case Iop_Avg32Sx4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2696 | case Iop_Add32x4: |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2697 | case Iop_Max32Ux4: |
| 2698 | case Iop_Max32Sx4: |
| 2699 | case Iop_Min32Ux4: |
| 2700 | case Iop_Min32Sx4: |
sewardj | b823b85 | 2010-06-18 08:18:38 +0000 | [diff] [blame] | 2701 | case Iop_Mul32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2702 | case Iop_QDMulHi32Sx4: |
| 2703 | case Iop_QRDMulHi32Sx4: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2704 | return binary32Ix4(mce, vatom1, vatom2); |
| 2705 | |
| 2706 | case Iop_Sub64x2: |
| 2707 | case Iop_Add64x2: |
sewardj | 9a2afe9 | 2011-10-19 15:24:55 +0000 | [diff] [blame^] | 2708 | case Iop_CmpEQ64x2: |
sewardj | b823b85 | 2010-06-18 08:18:38 +0000 | [diff] [blame] | 2709 | case Iop_CmpGT64Sx2: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2710 | case Iop_QSal64x2: |
| 2711 | case Iop_QShl64x2: |
| 2712 | case Iop_QAdd64Ux2: |
| 2713 | case Iop_QAdd64Sx2: |
| 2714 | case Iop_QSub64Ux2: |
| 2715 | case Iop_QSub64Sx2: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2716 | return binary64Ix2(mce, vatom1, vatom2); |
| 2717 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2718 | case Iop_QNarrowBin32Sto16Sx8: |
| 2719 | case Iop_QNarrowBin32Uto16Ux8: |
| 2720 | case Iop_QNarrowBin32Sto16Ux8: |
| 2721 | case Iop_QNarrowBin16Sto8Sx16: |
| 2722 | case Iop_QNarrowBin16Uto8Ux16: |
| 2723 | case Iop_QNarrowBin16Sto8Ux16: |
| 2724 | return vectorNarrowBinV128(mce, op, vatom1, vatom2); |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2725 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2726 | case Iop_Sub64Fx2: |
| 2727 | case Iop_Mul64Fx2: |
| 2728 | case Iop_Min64Fx2: |
| 2729 | case Iop_Max64Fx2: |
| 2730 | case Iop_Div64Fx2: |
| 2731 | case Iop_CmpLT64Fx2: |
| 2732 | case Iop_CmpLE64Fx2: |
| 2733 | case Iop_CmpEQ64Fx2: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 2734 | case Iop_CmpUN64Fx2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2735 | case Iop_Add64Fx2: |
| 2736 | return binary64Fx2(mce, vatom1, vatom2); |
| 2737 | |
| 2738 | case Iop_Sub64F0x2: |
| 2739 | case Iop_Mul64F0x2: |
| 2740 | case Iop_Min64F0x2: |
| 2741 | case Iop_Max64F0x2: |
| 2742 | case Iop_Div64F0x2: |
| 2743 | case Iop_CmpLT64F0x2: |
| 2744 | case Iop_CmpLE64F0x2: |
| 2745 | case Iop_CmpEQ64F0x2: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 2746 | case Iop_CmpUN64F0x2: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 2747 | case Iop_Add64F0x2: |
| 2748 | return binary64F0x2(mce, vatom1, vatom2); |
| 2749 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 2750 | case Iop_Sub32Fx4: |
| 2751 | case Iop_Mul32Fx4: |
| 2752 | case Iop_Min32Fx4: |
| 2753 | case Iop_Max32Fx4: |
| 2754 | case Iop_Div32Fx4: |
| 2755 | case Iop_CmpLT32Fx4: |
| 2756 | case Iop_CmpLE32Fx4: |
| 2757 | case Iop_CmpEQ32Fx4: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 2758 | case Iop_CmpUN32Fx4: |
cerion | e78ba2a | 2005-11-14 03:00:35 +0000 | [diff] [blame] | 2759 | case Iop_CmpGT32Fx4: |
| 2760 | case Iop_CmpGE32Fx4: |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2761 | case Iop_Add32Fx4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2762 | case Iop_Recps32Fx4: |
| 2763 | case Iop_Rsqrts32Fx4: |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2764 | return binary32Fx4(mce, vatom1, vatom2); |
| 2765 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2766 | case Iop_Sub32Fx2: |
| 2767 | case Iop_Mul32Fx2: |
| 2768 | case Iop_Min32Fx2: |
| 2769 | case Iop_Max32Fx2: |
| 2770 | case Iop_CmpEQ32Fx2: |
| 2771 | case Iop_CmpGT32Fx2: |
| 2772 | case Iop_CmpGE32Fx2: |
| 2773 | case Iop_Add32Fx2: |
| 2774 | case Iop_Recps32Fx2: |
| 2775 | case Iop_Rsqrts32Fx2: |
| 2776 | return binary32Fx2(mce, vatom1, vatom2); |
| 2777 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 2778 | case Iop_Sub32F0x4: |
| 2779 | case Iop_Mul32F0x4: |
| 2780 | case Iop_Min32F0x4: |
| 2781 | case Iop_Max32F0x4: |
| 2782 | case Iop_Div32F0x4: |
| 2783 | case Iop_CmpLT32F0x4: |
| 2784 | case Iop_CmpLE32F0x4: |
| 2785 | case Iop_CmpEQ32F0x4: |
sewardj | 545663e | 2005-11-05 01:55:04 +0000 | [diff] [blame] | 2786 | case Iop_CmpUN32F0x4: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 2787 | case Iop_Add32F0x4: |
| 2788 | return binary32F0x4(mce, vatom1, vatom2); |
| 2789 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2790 | case Iop_QShlN8Sx16: |
| 2791 | case Iop_QShlN8x16: |
| 2792 | case Iop_QSalN8x16: |
| 2793 | complainIfUndefined(mce, atom2); |
| 2794 | return mkPCast8x16(mce, vatom1); |
| 2795 | |
| 2796 | case Iop_QShlN16Sx8: |
| 2797 | case Iop_QShlN16x8: |
| 2798 | case Iop_QSalN16x8: |
| 2799 | complainIfUndefined(mce, atom2); |
| 2800 | return mkPCast16x8(mce, vatom1); |
| 2801 | |
| 2802 | case Iop_QShlN32Sx4: |
| 2803 | case Iop_QShlN32x4: |
| 2804 | case Iop_QSalN32x4: |
| 2805 | complainIfUndefined(mce, atom2); |
| 2806 | return mkPCast32x4(mce, vatom1); |
| 2807 | |
| 2808 | case Iop_QShlN64Sx2: |
| 2809 | case Iop_QShlN64x2: |
| 2810 | case Iop_QSalN64x2: |
| 2811 | complainIfUndefined(mce, atom2); |
| 2812 | return mkPCast32x4(mce, vatom1); |
| 2813 | |
| 2814 | case Iop_Mull32Sx2: |
| 2815 | case Iop_Mull32Ux2: |
| 2816 | case Iop_QDMulLong32Sx2: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2817 | return vectorWidenI64(mce, Iop_Widen32Sto64x2, |
| 2818 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2819 | |
| 2820 | case Iop_Mull16Sx4: |
| 2821 | case Iop_Mull16Ux4: |
| 2822 | case Iop_QDMulLong16Sx4: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2823 | return vectorWidenI64(mce, Iop_Widen16Sto32x4, |
| 2824 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2825 | |
| 2826 | case Iop_Mull8Sx8: |
| 2827 | case Iop_Mull8Ux8: |
| 2828 | case Iop_PolynomialMull8x8: |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2829 | return vectorWidenI64(mce, Iop_Widen8Sto16x8, |
| 2830 | mkUifU64(mce, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2831 | |
| 2832 | case Iop_PwAdd32x4: |
| 2833 | return mkPCast32x4(mce, |
| 2834 | assignNew('V', mce, Ity_V128, binop(op, mkPCast32x4(mce, vatom1), |
| 2835 | mkPCast32x4(mce, vatom2)))); |
| 2836 | |
| 2837 | case Iop_PwAdd16x8: |
| 2838 | return mkPCast16x8(mce, |
| 2839 | assignNew('V', mce, Ity_V128, binop(op, mkPCast16x8(mce, vatom1), |
| 2840 | mkPCast16x8(mce, vatom2)))); |
| 2841 | |
| 2842 | case Iop_PwAdd8x16: |
| 2843 | return mkPCast8x16(mce, |
| 2844 | assignNew('V', mce, Ity_V128, binop(op, mkPCast8x16(mce, vatom1), |
| 2845 | mkPCast8x16(mce, vatom2)))); |
| 2846 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 2847 | /* V128-bit data-steering */ |
| 2848 | case Iop_SetV128lo32: |
| 2849 | case Iop_SetV128lo64: |
| 2850 | case Iop_64HLtoV128: |
sewardj | a1d9330 | 2004-12-12 16:45:06 +0000 | [diff] [blame] | 2851 | case Iop_InterleaveLO64x2: |
| 2852 | case Iop_InterleaveLO32x4: |
| 2853 | case Iop_InterleaveLO16x8: |
| 2854 | case Iop_InterleaveLO8x16: |
| 2855 | case Iop_InterleaveHI64x2: |
| 2856 | case Iop_InterleaveHI32x4: |
| 2857 | case Iop_InterleaveHI16x8: |
| 2858 | case Iop_InterleaveHI8x16: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2859 | case Iop_CatOddLanes8x16: |
| 2860 | case Iop_CatOddLanes16x8: |
| 2861 | case Iop_CatOddLanes32x4: |
| 2862 | case Iop_CatEvenLanes8x16: |
| 2863 | case Iop_CatEvenLanes16x8: |
| 2864 | case Iop_CatEvenLanes32x4: |
| 2865 | case Iop_InterleaveOddLanes8x16: |
| 2866 | case Iop_InterleaveOddLanes16x8: |
| 2867 | case Iop_InterleaveOddLanes32x4: |
| 2868 | case Iop_InterleaveEvenLanes8x16: |
| 2869 | case Iop_InterleaveEvenLanes16x8: |
| 2870 | case Iop_InterleaveEvenLanes32x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2871 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, vatom2)); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 2872 | |
| 2873 | case Iop_GetElem8x16: |
| 2874 | complainIfUndefined(mce, atom2); |
| 2875 | return assignNew('V', mce, Ity_I8, binop(op, vatom1, atom2)); |
| 2876 | case Iop_GetElem16x8: |
| 2877 | complainIfUndefined(mce, atom2); |
| 2878 | return assignNew('V', mce, Ity_I16, binop(op, vatom1, atom2)); |
| 2879 | case Iop_GetElem32x4: |
| 2880 | complainIfUndefined(mce, atom2); |
| 2881 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, atom2)); |
| 2882 | case Iop_GetElem64x2: |
| 2883 | complainIfUndefined(mce, atom2); |
| 2884 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, atom2)); |
| 2885 | |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 2886 | /* Perm8x16: rearrange values in left arg using steering values |
| 2887 | from right arg. So rearrange the vbits in the same way but |
| 2888 | pessimise wrt steering values. */ |
| 2889 | case Iop_Perm8x16: |
| 2890 | return mkUifUV128( |
| 2891 | mce, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2892 | assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)), |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 2893 | mkPCast8x16(mce, vatom2) |
| 2894 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 2895 | |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2896 | /* These two take the lower half of each 16-bit lane, sign/zero |
| 2897 | extend it to 32, and multiply together, producing a 32x4 |
| 2898 | result (and implicitly ignoring half the operand bits). So |
| 2899 | treat it as a bunch of independent 16x8 operations, but then |
| 2900 | do 32-bit shifts left-right to copy the lower half results |
| 2901 | (which are all 0s or all 1s due to PCasting in binary16Ix8) |
| 2902 | into the upper half of each result lane. */ |
| 2903 | case Iop_MullEven16Ux8: |
| 2904 | case Iop_MullEven16Sx8: { |
| 2905 | IRAtom* at; |
| 2906 | at = binary16Ix8(mce,vatom1,vatom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2907 | at = assignNew('V', mce, Ity_V128, binop(Iop_ShlN32x4, at, mkU8(16))); |
| 2908 | at = assignNew('V', mce, Ity_V128, binop(Iop_SarN32x4, at, mkU8(16))); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2909 | return at; |
| 2910 | } |
| 2911 | |
| 2912 | /* Same deal as Iop_MullEven16{S,U}x8 */ |
| 2913 | case Iop_MullEven8Ux16: |
| 2914 | case Iop_MullEven8Sx16: { |
| 2915 | IRAtom* at; |
| 2916 | at = binary8Ix16(mce,vatom1,vatom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2917 | at = assignNew('V', mce, Ity_V128, binop(Iop_ShlN16x8, at, mkU8(8))); |
| 2918 | at = assignNew('V', mce, Ity_V128, binop(Iop_SarN16x8, at, mkU8(8))); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2919 | return at; |
| 2920 | } |
| 2921 | |
| 2922 | /* narrow 2xV128 into 1xV128, hi half from left arg, in a 2 x |
| 2923 | 32x4 -> 16x8 laneage, discarding the upper half of each lane. |
| 2924 | Simply apply same op to the V bits, since this really no more |
| 2925 | than a data steering operation. */ |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 2926 | case Iop_NarrowBin32to16x8: |
| 2927 | case Iop_NarrowBin16to8x16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2928 | return assignNew('V', mce, Ity_V128, |
| 2929 | binop(op, vatom1, vatom2)); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2930 | |
| 2931 | case Iop_ShrV128: |
| 2932 | case Iop_ShlV128: |
| 2933 | /* Same scheme as with all other shifts. Note: 10 Nov 05: |
| 2934 | this is wrong now, scalar shifts are done properly lazily. |
| 2935 | Vector shifts should be fixed too. */ |
| 2936 | complainIfUndefined(mce, atom2); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2937 | return assignNew('V', mce, Ity_V128, binop(op, vatom1, atom2)); |
sewardj | 43d6075 | 2005-11-10 18:13:01 +0000 | [diff] [blame] | 2938 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 2939 | /* I128-bit data-steering */ |
| 2940 | case Iop_64HLto128: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 2941 | return assignNew('V', mce, Ity_I128, binop(op, vatom1, vatom2)); |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 2942 | |
sewardj | 3245c91 | 2004-12-10 14:58:26 +0000 | [diff] [blame] | 2943 | /* Scalar floating point */ |
| 2944 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2945 | case Iop_F32toI64S: |
| 2946 | /* I32(rm) x F32 -> I64 */ |
| 2947 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 2948 | |
| 2949 | case Iop_I64StoF32: |
| 2950 | /* I32(rm) x I64 -> F32 */ |
| 2951 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 2952 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 2953 | case Iop_RoundF64toInt: |
| 2954 | case Iop_RoundF64toF32: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 2955 | case Iop_F64toI64S: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 2956 | case Iop_F64toI64U: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 2957 | case Iop_I64StoF64: |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 2958 | case Iop_I64UtoF64: |
sewardj | 22ac5f4 | 2006-02-03 22:55:04 +0000 | [diff] [blame] | 2959 | case Iop_SinF64: |
| 2960 | case Iop_CosF64: |
| 2961 | case Iop_TanF64: |
| 2962 | case Iop_2xm1F64: |
| 2963 | case Iop_SqrtF64: |
| 2964 | /* I32(rm) x I64/F64 -> I64/F64 */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2965 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 2966 | |
sewardj | d376a76 | 2010-06-27 09:08:54 +0000 | [diff] [blame] | 2967 | case Iop_RoundF32toInt: |
sewardj | aec1be3 | 2010-01-03 22:29:32 +0000 | [diff] [blame] | 2968 | case Iop_SqrtF32: |
| 2969 | /* I32(rm) x I32/F32 -> I32/F32 */ |
| 2970 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 2971 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2972 | case Iop_SqrtF128: |
| 2973 | /* I32(rm) x F128 -> F128 */ |
| 2974 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 2975 | |
| 2976 | case Iop_I32StoF32: |
| 2977 | case Iop_F32toI32S: |
| 2978 | /* First arg is I32 (rounding mode), second is F32/I32 (data). */ |
| 2979 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 2980 | |
| 2981 | case Iop_F128toI32S: /* IRRoundingMode(I32) x F128 -> signed I32 */ |
| 2982 | case Iop_F128toF32: /* IRRoundingMode(I32) x F128 -> F32 */ |
| 2983 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 2984 | |
| 2985 | case Iop_F128toI64S: /* IRRoundingMode(I32) x F128 -> signed I64 */ |
| 2986 | case Iop_F128toF64: /* IRRoundingMode(I32) x F128 -> F64 */ |
| 2987 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 2988 | |
| 2989 | case Iop_F64HLtoF128: |
| 2990 | return assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, vatom1, vatom2)); |
| 2991 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2992 | case Iop_F64toI32U: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 2993 | case Iop_F64toI32S: |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 2994 | case Iop_F64toF32: |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 2995 | case Iop_I64UtoF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 2996 | /* First arg is I32 (rounding mode), second is F64 (data). */ |
| 2997 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 2998 | |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 2999 | case Iop_F64toI16S: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3000 | /* First arg is I32 (rounding mode), second is F64 (data). */ |
| 3001 | return mkLazy2(mce, Ity_I16, vatom1, vatom2); |
| 3002 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3003 | case Iop_CmpF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3004 | case Iop_CmpF64: |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3005 | case Iop_CmpF128: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3006 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3007 | |
| 3008 | /* non-FP after here */ |
| 3009 | |
| 3010 | case Iop_DivModU64to32: |
| 3011 | case Iop_DivModS64to32: |
| 3012 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3013 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3014 | case Iop_DivModU128to64: |
| 3015 | case Iop_DivModS128to64: |
| 3016 | return mkLazy2(mce, Ity_I128, vatom1, vatom2); |
| 3017 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3018 | case Iop_16HLto32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3019 | return assignNew('V', mce, Ity_I32, binop(op, vatom1, vatom2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3020 | case Iop_32HLto64: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3021 | return assignNew('V', mce, Ity_I64, binop(op, vatom1, vatom2)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3022 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3023 | case Iop_DivModS64to64: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3024 | case Iop_MullS64: |
| 3025 | case Iop_MullU64: { |
| 3026 | IRAtom* vLo64 = mkLeft64(mce, mkUifU64(mce, vatom1,vatom2)); |
| 3027 | IRAtom* vHi64 = mkPCastTo(mce, Ity_I64, vLo64); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3028 | return assignNew('V', mce, Ity_I128, binop(Iop_64HLto128, vHi64, vLo64)); |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3031 | case Iop_MullS32: |
| 3032 | case Iop_MullU32: { |
| 3033 | IRAtom* vLo32 = mkLeft32(mce, mkUifU32(mce, vatom1,vatom2)); |
| 3034 | IRAtom* vHi32 = mkPCastTo(mce, Ity_I32, vLo32); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3035 | return assignNew('V', mce, Ity_I64, binop(Iop_32HLto64, vHi32, vLo32)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | case Iop_MullS16: |
| 3039 | case Iop_MullU16: { |
| 3040 | IRAtom* vLo16 = mkLeft16(mce, mkUifU16(mce, vatom1,vatom2)); |
| 3041 | IRAtom* vHi16 = mkPCastTo(mce, Ity_I16, vLo16); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3042 | return assignNew('V', mce, Ity_I32, binop(Iop_16HLto32, vHi16, vLo16)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | case Iop_MullS8: |
| 3046 | case Iop_MullU8: { |
| 3047 | IRAtom* vLo8 = mkLeft8(mce, mkUifU8(mce, vatom1,vatom2)); |
| 3048 | IRAtom* vHi8 = mkPCastTo(mce, Ity_I8, vLo8); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3049 | return assignNew('V', mce, Ity_I16, binop(Iop_8HLto16, vHi8, vLo8)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
sewardj | 5af0506 | 2010-10-18 16:31:14 +0000 | [diff] [blame] | 3052 | case Iop_Sad8Ux4: /* maybe we could do better? ftm, do mkLazy2. */ |
cerion | 9e59108 | 2005-06-23 15:28:34 +0000 | [diff] [blame] | 3053 | case Iop_DivS32: |
| 3054 | case Iop_DivU32: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3055 | case Iop_DivU32E: |
sewardj | 169ac04 | 2011-09-05 12:12:34 +0000 | [diff] [blame] | 3056 | case Iop_DivS32E: |
cerion | 9e59108 | 2005-06-23 15:28:34 +0000 | [diff] [blame] | 3057 | return mkLazy2(mce, Ity_I32, vatom1, vatom2); |
| 3058 | |
sewardj | b00944a | 2005-12-23 12:47:16 +0000 | [diff] [blame] | 3059 | case Iop_DivS64: |
| 3060 | case Iop_DivU64: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3061 | case Iop_DivS64E: |
sewardj | 169ac04 | 2011-09-05 12:12:34 +0000 | [diff] [blame] | 3062 | case Iop_DivU64E: |
sewardj | b00944a | 2005-12-23 12:47:16 +0000 | [diff] [blame] | 3063 | return mkLazy2(mce, Ity_I64, vatom1, vatom2); |
| 3064 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3065 | case Iop_Add32: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3066 | if (mce->bogusLiterals) |
| 3067 | return expensiveAddSub(mce,True,Ity_I32, |
| 3068 | vatom1,vatom2, atom1,atom2); |
| 3069 | else |
| 3070 | goto cheap_AddSub32; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3071 | case Iop_Sub32: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3072 | if (mce->bogusLiterals) |
| 3073 | return expensiveAddSub(mce,False,Ity_I32, |
| 3074 | vatom1,vatom2, atom1,atom2); |
| 3075 | else |
| 3076 | goto cheap_AddSub32; |
| 3077 | |
| 3078 | cheap_AddSub32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3079 | case Iop_Mul32: |
sewardj | 992dff9 | 2005-10-07 11:08:55 +0000 | [diff] [blame] | 3080 | return mkLeft32(mce, mkUifU32(mce, vatom1,vatom2)); |
| 3081 | |
sewardj | 463b3d9 | 2005-07-18 11:41:15 +0000 | [diff] [blame] | 3082 | case Iop_CmpORD32S: |
| 3083 | case Iop_CmpORD32U: |
sewardj | 1bc8210 | 2005-12-23 00:16:24 +0000 | [diff] [blame] | 3084 | case Iop_CmpORD64S: |
| 3085 | case Iop_CmpORD64U: |
| 3086 | return doCmpORD(mce, op, vatom1,vatom2, atom1,atom2); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3087 | |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3088 | case Iop_Add64: |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 3089 | if (mce->bogusLiterals) |
| 3090 | return expensiveAddSub(mce,True,Ity_I64, |
| 3091 | vatom1,vatom2, atom1,atom2); |
| 3092 | else |
| 3093 | goto cheap_AddSub64; |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3094 | case Iop_Sub64: |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 3095 | if (mce->bogusLiterals) |
| 3096 | return expensiveAddSub(mce,False,Ity_I64, |
| 3097 | vatom1,vatom2, atom1,atom2); |
| 3098 | else |
| 3099 | goto cheap_AddSub64; |
| 3100 | |
| 3101 | cheap_AddSub64: |
| 3102 | case Iop_Mul64: |
sewardj | 681be30 | 2005-01-15 20:43:58 +0000 | [diff] [blame] | 3103 | return mkLeft64(mce, mkUifU64(mce, vatom1,vatom2)); |
| 3104 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3105 | case Iop_Mul16: |
| 3106 | case Iop_Add16: |
| 3107 | case Iop_Sub16: |
| 3108 | return mkLeft16(mce, mkUifU16(mce, vatom1,vatom2)); |
| 3109 | |
| 3110 | case Iop_Sub8: |
| 3111 | case Iop_Add8: |
| 3112 | return mkLeft8(mce, mkUifU8(mce, vatom1,vatom2)); |
| 3113 | |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3114 | case Iop_CmpEQ64: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 3115 | case Iop_CmpNE64: |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3116 | if (mce->bogusLiterals) |
| 3117 | return expensiveCmpEQorNE(mce,Ity_I64, vatom1,vatom2, atom1,atom2 ); |
| 3118 | else |
| 3119 | goto cheap_cmp64; |
| 3120 | cheap_cmp64: |
tom | cd98633 | 2005-04-26 07:44:48 +0000 | [diff] [blame] | 3121 | case Iop_CmpLE64S: case Iop_CmpLE64U: |
| 3122 | case Iop_CmpLT64U: case Iop_CmpLT64S: |
sewardj | 69a1332 | 2005-04-23 01:14:51 +0000 | [diff] [blame] | 3123 | return mkPCastTo(mce, Ity_I1, mkUifU64(mce, vatom1,vatom2)); |
| 3124 | |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3125 | case Iop_CmpEQ32: |
sewardj | e6f8af4 | 2005-07-06 18:48:59 +0000 | [diff] [blame] | 3126 | case Iop_CmpNE32: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3127 | if (mce->bogusLiterals) |
| 3128 | return expensiveCmpEQorNE(mce,Ity_I32, vatom1,vatom2, atom1,atom2 ); |
| 3129 | else |
| 3130 | goto cheap_cmp32; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 3131 | cheap_cmp32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3132 | case Iop_CmpLE32S: case Iop_CmpLE32U: |
| 3133 | case Iop_CmpLT32U: case Iop_CmpLT32S: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3134 | return mkPCastTo(mce, Ity_I1, mkUifU32(mce, vatom1,vatom2)); |
| 3135 | |
| 3136 | case Iop_CmpEQ16: case Iop_CmpNE16: |
| 3137 | return mkPCastTo(mce, Ity_I1, mkUifU16(mce, vatom1,vatom2)); |
| 3138 | |
| 3139 | case Iop_CmpEQ8: case Iop_CmpNE8: |
| 3140 | return mkPCastTo(mce, Ity_I1, mkUifU8(mce, vatom1,vatom2)); |
| 3141 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 3142 | case Iop_CasCmpEQ8: case Iop_CasCmpNE8: |
| 3143 | case Iop_CasCmpEQ16: case Iop_CasCmpNE16: |
| 3144 | case Iop_CasCmpEQ32: case Iop_CasCmpNE32: |
| 3145 | case Iop_CasCmpEQ64: case Iop_CasCmpNE64: |
| 3146 | /* Just say these all produce a defined result, regardless |
| 3147 | of their arguments. See COMMENT_ON_CasCmpEQ in this file. */ |
| 3148 | return assignNew('V', mce, Ity_I1, definedOfType(Ity_I1)); |
| 3149 | |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3150 | case Iop_Shl64: case Iop_Shr64: case Iop_Sar64: |
| 3151 | return scalarShift( mce, Ity_I64, op, vatom1,vatom2, atom1,atom2 ); |
| 3152 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3153 | case Iop_Shl32: case Iop_Shr32: case Iop_Sar32: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3154 | return scalarShift( mce, Ity_I32, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3155 | |
sewardj | db67f5f | 2004-12-14 01:15:31 +0000 | [diff] [blame] | 3156 | case Iop_Shl16: case Iop_Shr16: case Iop_Sar16: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3157 | return scalarShift( mce, Ity_I16, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3158 | |
| 3159 | case Iop_Shl8: case Iop_Shr8: |
sewardj | aaddbc2 | 2005-10-07 09:49:53 +0000 | [diff] [blame] | 3160 | return scalarShift( mce, Ity_I8, op, vatom1,vatom2, atom1,atom2 ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3161 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3162 | case Iop_AndV128: |
| 3163 | uifu = mkUifUV128; difd = mkDifDV128; |
| 3164 | and_or_ty = Ity_V128; improve = mkImproveANDV128; goto do_And_Or; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3165 | case Iop_And64: |
| 3166 | uifu = mkUifU64; difd = mkDifD64; |
| 3167 | and_or_ty = Ity_I64; improve = mkImproveAND64; goto do_And_Or; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3168 | case Iop_And32: |
| 3169 | uifu = mkUifU32; difd = mkDifD32; |
| 3170 | and_or_ty = Ity_I32; improve = mkImproveAND32; goto do_And_Or; |
| 3171 | case Iop_And16: |
| 3172 | uifu = mkUifU16; difd = mkDifD16; |
| 3173 | and_or_ty = Ity_I16; improve = mkImproveAND16; goto do_And_Or; |
| 3174 | case Iop_And8: |
| 3175 | uifu = mkUifU8; difd = mkDifD8; |
| 3176 | and_or_ty = Ity_I8; improve = mkImproveAND8; goto do_And_Or; |
| 3177 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3178 | case Iop_OrV128: |
| 3179 | uifu = mkUifUV128; difd = mkDifDV128; |
| 3180 | and_or_ty = Ity_V128; improve = mkImproveORV128; goto do_And_Or; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3181 | case Iop_Or64: |
| 3182 | uifu = mkUifU64; difd = mkDifD64; |
| 3183 | and_or_ty = Ity_I64; improve = mkImproveOR64; goto do_And_Or; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3184 | case Iop_Or32: |
| 3185 | uifu = mkUifU32; difd = mkDifD32; |
| 3186 | and_or_ty = Ity_I32; improve = mkImproveOR32; goto do_And_Or; |
| 3187 | case Iop_Or16: |
| 3188 | uifu = mkUifU16; difd = mkDifD16; |
| 3189 | and_or_ty = Ity_I16; improve = mkImproveOR16; goto do_And_Or; |
| 3190 | case Iop_Or8: |
| 3191 | uifu = mkUifU8; difd = mkDifD8; |
| 3192 | and_or_ty = Ity_I8; improve = mkImproveOR8; goto do_And_Or; |
| 3193 | |
| 3194 | do_And_Or: |
| 3195 | return |
| 3196 | assignNew( |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3197 | 'V', mce, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3198 | and_or_ty, |
| 3199 | difd(mce, uifu(mce, vatom1, vatom2), |
| 3200 | difd(mce, improve(mce, atom1, vatom1), |
| 3201 | improve(mce, atom2, vatom2) ) ) ); |
| 3202 | |
| 3203 | case Iop_Xor8: |
| 3204 | return mkUifU8(mce, vatom1, vatom2); |
| 3205 | case Iop_Xor16: |
| 3206 | return mkUifU16(mce, vatom1, vatom2); |
| 3207 | case Iop_Xor32: |
| 3208 | return mkUifU32(mce, vatom1, vatom2); |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3209 | case Iop_Xor64: |
| 3210 | return mkUifU64(mce, vatom1, vatom2); |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3211 | case Iop_XorV128: |
| 3212 | return mkUifUV128(mce, vatom1, vatom2); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3213 | |
| 3214 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3215 | ppIROp(op); |
| 3216 | VG_(tool_panic)("memcheck:expr2vbits_Binop"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3217 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3220 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3221 | static |
| 3222 | IRExpr* expr2vbits_Unop ( MCEnv* mce, IROp op, IRAtom* atom ) |
| 3223 | { |
| 3224 | IRAtom* vatom = expr2vbits( mce, atom ); |
| 3225 | tl_assert(isOriginalAtom(mce,atom)); |
| 3226 | switch (op) { |
| 3227 | |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3228 | case Iop_Sqrt64Fx2: |
| 3229 | return unary64Fx2(mce, vatom); |
| 3230 | |
| 3231 | case Iop_Sqrt64F0x2: |
| 3232 | return unary64F0x2(mce, vatom); |
| 3233 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3234 | case Iop_Sqrt32Fx4: |
| 3235 | case Iop_RSqrt32Fx4: |
| 3236 | case Iop_Recip32Fx4: |
cerion | 176cb4c | 2005-11-16 17:21:49 +0000 | [diff] [blame] | 3237 | case Iop_I32UtoFx4: |
| 3238 | case Iop_I32StoFx4: |
| 3239 | case Iop_QFtoI32Ux4_RZ: |
| 3240 | case Iop_QFtoI32Sx4_RZ: |
| 3241 | case Iop_RoundF32x4_RM: |
| 3242 | case Iop_RoundF32x4_RP: |
| 3243 | case Iop_RoundF32x4_RN: |
| 3244 | case Iop_RoundF32x4_RZ: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3245 | case Iop_Recip32x4: |
| 3246 | case Iop_Abs32Fx4: |
| 3247 | case Iop_Neg32Fx4: |
| 3248 | case Iop_Rsqrte32Fx4: |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3249 | return unary32Fx4(mce, vatom); |
| 3250 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3251 | case Iop_I32UtoFx2: |
| 3252 | case Iop_I32StoFx2: |
| 3253 | case Iop_Recip32Fx2: |
| 3254 | case Iop_Recip32x2: |
| 3255 | case Iop_Abs32Fx2: |
| 3256 | case Iop_Neg32Fx2: |
| 3257 | case Iop_Rsqrte32Fx2: |
| 3258 | return unary32Fx2(mce, vatom); |
| 3259 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3260 | case Iop_Sqrt32F0x4: |
| 3261 | case Iop_RSqrt32F0x4: |
| 3262 | case Iop_Recip32F0x4: |
| 3263 | return unary32F0x4(mce, vatom); |
| 3264 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3265 | case Iop_32UtoV128: |
| 3266 | case Iop_64UtoV128: |
sewardj | 620eb5b | 2005-10-22 12:50:43 +0000 | [diff] [blame] | 3267 | case Iop_Dup8x16: |
| 3268 | case Iop_Dup16x8: |
| 3269 | case Iop_Dup32x4: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3270 | case Iop_Reverse16_8x16: |
| 3271 | case Iop_Reverse32_8x16: |
| 3272 | case Iop_Reverse32_16x8: |
| 3273 | case Iop_Reverse64_8x16: |
| 3274 | case Iop_Reverse64_16x8: |
| 3275 | case Iop_Reverse64_32x4: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3276 | return assignNew('V', mce, Ity_V128, unop(op, vatom)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3277 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3278 | case Iop_F128HItoF64: /* F128 -> high half of F128 */ |
| 3279 | return assignNew('V', mce, Ity_I64, unop(Iop_128HIto64, vatom)); |
| 3280 | case Iop_F128LOtoF64: /* F128 -> low half of F128 */ |
| 3281 | return assignNew('V', mce, Ity_I64, unop(Iop_128to64, vatom)); |
| 3282 | |
| 3283 | case Iop_NegF128: |
| 3284 | case Iop_AbsF128: |
| 3285 | return mkPCastTo(mce, Ity_I128, vatom); |
| 3286 | |
| 3287 | case Iop_I32StoF128: /* signed I32 -> F128 */ |
| 3288 | case Iop_I64StoF128: /* signed I64 -> F128 */ |
| 3289 | case Iop_F32toF128: /* F32 -> F128 */ |
| 3290 | case Iop_F64toF128: /* F64 -> F128 */ |
| 3291 | return mkPCastTo(mce, Ity_I128, vatom); |
| 3292 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3293 | case Iop_F32toF64: |
sewardj | 06f96d0 | 2009-12-31 19:24:12 +0000 | [diff] [blame] | 3294 | case Iop_I32StoF64: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 3295 | case Iop_I32UtoF64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3296 | case Iop_NegF64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3297 | case Iop_AbsF64: |
sewardj | 4f3e0f2 | 2006-01-27 15:11:31 +0000 | [diff] [blame] | 3298 | case Iop_Est5FRSqrt: |
sewardj | dead90a | 2008-08-08 08:38:23 +0000 | [diff] [blame] | 3299 | case Iop_RoundF64toF64_NEAREST: |
| 3300 | case Iop_RoundF64toF64_NegINF: |
| 3301 | case Iop_RoundF64toF64_PosINF: |
| 3302 | case Iop_RoundF64toF64_ZERO: |
sewardj | 39cc735 | 2005-06-09 21:31:55 +0000 | [diff] [blame] | 3303 | case Iop_Clz64: |
| 3304 | case Iop_Ctz64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3305 | return mkPCastTo(mce, Ity_I64, vatom); |
| 3306 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3307 | case Iop_Clz32: |
| 3308 | case Iop_Ctz32: |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 3309 | case Iop_TruncF64asF32: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 3310 | case Iop_NegF32: |
| 3311 | case Iop_AbsF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3312 | return mkPCastTo(mce, Ity_I32, vatom); |
| 3313 | |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3314 | case Iop_1Uto64: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3315 | case Iop_1Sto64: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3316 | case Iop_8Uto64: |
| 3317 | case Iop_8Sto64: |
| 3318 | case Iop_16Uto64: |
| 3319 | case Iop_16Sto64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3320 | case Iop_32Sto64: |
| 3321 | case Iop_32Uto64: |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3322 | case Iop_V128to64: |
| 3323 | case Iop_V128HIto64: |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3324 | case Iop_128HIto64: |
| 3325 | case Iop_128to64: |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3326 | case Iop_Dup8x8: |
| 3327 | case Iop_Dup16x4: |
| 3328 | case Iop_Dup32x2: |
| 3329 | case Iop_Reverse16_8x8: |
| 3330 | case Iop_Reverse32_8x8: |
| 3331 | case Iop_Reverse32_16x4: |
| 3332 | case Iop_Reverse64_8x8: |
| 3333 | case Iop_Reverse64_16x4: |
| 3334 | case Iop_Reverse64_32x2: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3335 | return assignNew('V', mce, Ity_I64, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3336 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 3337 | case Iop_I16StoF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3338 | case Iop_64to32: |
| 3339 | case Iop_64HIto32: |
| 3340 | case Iop_1Uto32: |
sewardj | 463b3d9 | 2005-07-18 11:41:15 +0000 | [diff] [blame] | 3341 | case Iop_1Sto32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3342 | case Iop_8Uto32: |
| 3343 | case Iop_16Uto32: |
| 3344 | case Iop_16Sto32: |
| 3345 | case Iop_8Sto32: |
cerion | fafaa0d | 2005-09-12 22:29:38 +0000 | [diff] [blame] | 3346 | case Iop_V128to32: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3347 | return assignNew('V', mce, Ity_I32, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3348 | |
| 3349 | case Iop_8Sto16: |
| 3350 | case Iop_8Uto16: |
| 3351 | case Iop_32to16: |
| 3352 | case Iop_32HIto16: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3353 | case Iop_64to16: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3354 | return assignNew('V', mce, Ity_I16, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3355 | |
| 3356 | case Iop_1Uto8: |
sewardj | a201c45 | 2011-07-24 14:15:54 +0000 | [diff] [blame] | 3357 | case Iop_1Sto8: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3358 | case Iop_16to8: |
sewardj | 9a807e0 | 2006-12-17 14:20:31 +0000 | [diff] [blame] | 3359 | case Iop_16HIto8: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3360 | case Iop_32to8: |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3361 | case Iop_64to8: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3362 | return assignNew('V', mce, Ity_I8, unop(op, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3363 | |
| 3364 | case Iop_32to1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3365 | return assignNew('V', mce, Ity_I1, unop(Iop_32to1, vatom)); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3366 | |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3367 | case Iop_64to1: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3368 | return assignNew('V', mce, Ity_I1, unop(Iop_64to1, vatom)); |
sewardj | d9dbc19 | 2005-04-27 11:40:27 +0000 | [diff] [blame] | 3369 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3370 | case Iop_ReinterpF64asI64: |
| 3371 | case Iop_ReinterpI64asF64: |
sewardj | 0b07059 | 2004-12-10 21:44:22 +0000 | [diff] [blame] | 3372 | case Iop_ReinterpI32asF32: |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 3373 | case Iop_ReinterpF32asI32: |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3374 | case Iop_NotV128: |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3375 | case Iop_Not64: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3376 | case Iop_Not32: |
| 3377 | case Iop_Not16: |
| 3378 | case Iop_Not8: |
| 3379 | case Iop_Not1: |
| 3380 | return vatom; |
sewardj | 7010f6e | 2004-12-10 13:35:22 +0000 | [diff] [blame] | 3381 | |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3382 | case Iop_CmpNEZ8x8: |
| 3383 | case Iop_Cnt8x8: |
| 3384 | case Iop_Clz8Sx8: |
| 3385 | case Iop_Cls8Sx8: |
| 3386 | case Iop_Abs8x8: |
| 3387 | return mkPCast8x8(mce, vatom); |
| 3388 | |
| 3389 | case Iop_CmpNEZ8x16: |
| 3390 | case Iop_Cnt8x16: |
| 3391 | case Iop_Clz8Sx16: |
| 3392 | case Iop_Cls8Sx16: |
| 3393 | case Iop_Abs8x16: |
| 3394 | return mkPCast8x16(mce, vatom); |
| 3395 | |
| 3396 | case Iop_CmpNEZ16x4: |
| 3397 | case Iop_Clz16Sx4: |
| 3398 | case Iop_Cls16Sx4: |
| 3399 | case Iop_Abs16x4: |
| 3400 | return mkPCast16x4(mce, vatom); |
| 3401 | |
| 3402 | case Iop_CmpNEZ16x8: |
| 3403 | case Iop_Clz16Sx8: |
| 3404 | case Iop_Cls16Sx8: |
| 3405 | case Iop_Abs16x8: |
| 3406 | return mkPCast16x8(mce, vatom); |
| 3407 | |
| 3408 | case Iop_CmpNEZ32x2: |
| 3409 | case Iop_Clz32Sx2: |
| 3410 | case Iop_Cls32Sx2: |
| 3411 | case Iop_FtoI32Ux2_RZ: |
| 3412 | case Iop_FtoI32Sx2_RZ: |
| 3413 | case Iop_Abs32x2: |
| 3414 | return mkPCast32x2(mce, vatom); |
| 3415 | |
| 3416 | case Iop_CmpNEZ32x4: |
| 3417 | case Iop_Clz32Sx4: |
| 3418 | case Iop_Cls32Sx4: |
| 3419 | case Iop_FtoI32Ux4_RZ: |
| 3420 | case Iop_FtoI32Sx4_RZ: |
| 3421 | case Iop_Abs32x4: |
| 3422 | return mkPCast32x4(mce, vatom); |
| 3423 | |
| 3424 | case Iop_CmpwNEZ64: |
| 3425 | return mkPCastTo(mce, Ity_I64, vatom); |
| 3426 | |
| 3427 | case Iop_CmpNEZ64x2: |
| 3428 | return mkPCast64x2(mce, vatom); |
| 3429 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3430 | case Iop_NarrowUn16to8x8: |
| 3431 | case Iop_NarrowUn32to16x4: |
| 3432 | case Iop_NarrowUn64to32x2: |
| 3433 | case Iop_QNarrowUn16Sto8Sx8: |
| 3434 | case Iop_QNarrowUn16Sto8Ux8: |
| 3435 | case Iop_QNarrowUn16Uto8Ux8: |
| 3436 | case Iop_QNarrowUn32Sto16Sx4: |
| 3437 | case Iop_QNarrowUn32Sto16Ux4: |
| 3438 | case Iop_QNarrowUn32Uto16Ux4: |
| 3439 | case Iop_QNarrowUn64Sto32Sx2: |
| 3440 | case Iop_QNarrowUn64Sto32Ux2: |
| 3441 | case Iop_QNarrowUn64Uto32Ux2: |
| 3442 | return vectorNarrowUnV128(mce, op, vatom); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3443 | |
sewardj | 7ee7d85 | 2011-06-16 11:37:21 +0000 | [diff] [blame] | 3444 | case Iop_Widen8Sto16x8: |
| 3445 | case Iop_Widen8Uto16x8: |
| 3446 | case Iop_Widen16Sto32x4: |
| 3447 | case Iop_Widen16Uto32x4: |
| 3448 | case Iop_Widen32Sto64x2: |
| 3449 | case Iop_Widen32Uto64x2: |
| 3450 | return vectorWidenI64(mce, op, vatom); |
sewardj | 57f92b0 | 2010-08-22 11:54:14 +0000 | [diff] [blame] | 3451 | |
| 3452 | case Iop_PwAddL32Ux2: |
| 3453 | case Iop_PwAddL32Sx2: |
| 3454 | return mkPCastTo(mce, Ity_I64, |
| 3455 | assignNew('V', mce, Ity_I64, unop(op, mkPCast32x2(mce, vatom)))); |
| 3456 | |
| 3457 | case Iop_PwAddL16Ux4: |
| 3458 | case Iop_PwAddL16Sx4: |
| 3459 | return mkPCast32x2(mce, |
| 3460 | assignNew('V', mce, Ity_I64, unop(op, mkPCast16x4(mce, vatom)))); |
| 3461 | |
| 3462 | case Iop_PwAddL8Ux8: |
| 3463 | case Iop_PwAddL8Sx8: |
| 3464 | return mkPCast16x4(mce, |
| 3465 | assignNew('V', mce, Ity_I64, unop(op, mkPCast8x8(mce, vatom)))); |
| 3466 | |
| 3467 | case Iop_PwAddL32Ux4: |
| 3468 | case Iop_PwAddL32Sx4: |
| 3469 | return mkPCast64x2(mce, |
| 3470 | assignNew('V', mce, Ity_V128, unop(op, mkPCast32x4(mce, vatom)))); |
| 3471 | |
| 3472 | case Iop_PwAddL16Ux8: |
| 3473 | case Iop_PwAddL16Sx8: |
| 3474 | return mkPCast32x4(mce, |
| 3475 | assignNew('V', mce, Ity_V128, unop(op, mkPCast16x8(mce, vatom)))); |
| 3476 | |
| 3477 | case Iop_PwAddL8Ux16: |
| 3478 | case Iop_PwAddL8Sx16: |
| 3479 | return mkPCast16x8(mce, |
| 3480 | assignNew('V', mce, Ity_V128, unop(op, mkPCast8x16(mce, vatom)))); |
| 3481 | |
sewardj | f34eb49 | 2011-04-15 11:57:05 +0000 | [diff] [blame] | 3482 | case Iop_I64UtoF32: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3483 | default: |
| 3484 | ppIROp(op); |
| 3485 | VG_(tool_panic)("memcheck:expr2vbits_Unop"); |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3490 | /* Worker function; do not call directly. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3491 | static |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3492 | IRAtom* expr2vbits_Load_WRK ( MCEnv* mce, |
| 3493 | IREndness end, IRType ty, |
| 3494 | IRAtom* addr, UInt bias ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3495 | { |
| 3496 | void* helper; |
| 3497 | Char* hname; |
| 3498 | IRDirty* di; |
| 3499 | IRTemp datavbits; |
| 3500 | IRAtom* addrAct; |
| 3501 | |
| 3502 | tl_assert(isOriginalAtom(mce,addr)); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3503 | tl_assert(end == Iend_LE || end == Iend_BE); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3504 | |
| 3505 | /* First, emit a definedness test for the address. This also sets |
| 3506 | the address (shadow) to 'defined' following the test. */ |
| 3507 | complainIfUndefined( mce, addr ); |
| 3508 | |
| 3509 | /* Now cook up a call to the relevant helper function, to read the |
| 3510 | data V bits from shadow memory. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3511 | ty = shadowTypeV(ty); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3512 | |
| 3513 | if (end == Iend_LE) { |
| 3514 | switch (ty) { |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3515 | case Ity_I64: helper = &MC_(helperc_LOADV64le); |
| 3516 | hname = "MC_(helperc_LOADV64le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3517 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3518 | case Ity_I32: helper = &MC_(helperc_LOADV32le); |
| 3519 | hname = "MC_(helperc_LOADV32le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3520 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3521 | case Ity_I16: helper = &MC_(helperc_LOADV16le); |
| 3522 | hname = "MC_(helperc_LOADV16le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3523 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3524 | case Ity_I8: helper = &MC_(helperc_LOADV8); |
| 3525 | hname = "MC_(helperc_LOADV8)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3526 | break; |
| 3527 | default: ppIRType(ty); |
| 3528 | VG_(tool_panic)("memcheck:do_shadow_Load(LE)"); |
| 3529 | } |
| 3530 | } else { |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3531 | switch (ty) { |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3532 | case Ity_I64: helper = &MC_(helperc_LOADV64be); |
| 3533 | hname = "MC_(helperc_LOADV64be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3534 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3535 | case Ity_I32: helper = &MC_(helperc_LOADV32be); |
| 3536 | hname = "MC_(helperc_LOADV32be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3537 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3538 | case Ity_I16: helper = &MC_(helperc_LOADV16be); |
| 3539 | hname = "MC_(helperc_LOADV16be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3540 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3541 | case Ity_I8: helper = &MC_(helperc_LOADV8); |
| 3542 | hname = "MC_(helperc_LOADV8)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3543 | break; |
| 3544 | default: ppIRType(ty); |
| 3545 | VG_(tool_panic)("memcheck:do_shadow_Load(BE)"); |
| 3546 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /* Generate the actual address into addrAct. */ |
| 3550 | if (bias == 0) { |
| 3551 | addrAct = addr; |
| 3552 | } else { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 3553 | IROp mkAdd; |
| 3554 | IRAtom* eBias; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3555 | IRType tyAddr = mce->hWordTy; |
| 3556 | tl_assert( tyAddr == Ity_I32 || tyAddr == Ity_I64 ); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 3557 | mkAdd = tyAddr==Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 3558 | eBias = tyAddr==Ity_I32 ? mkU32(bias) : mkU64(bias); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3559 | addrAct = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBias) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | /* We need to have a place to park the V bits we're just about to |
| 3563 | read. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3564 | datavbits = newTemp(mce, ty, VSh); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3565 | di = unsafeIRDirty_1_N( datavbits, |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3566 | 1/*regparms*/, |
| 3567 | hname, VG_(fnptr_to_fnentry)( helper ), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3568 | mkIRExprVec_1( addrAct )); |
| 3569 | setHelperAnns( mce, di ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3570 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3571 | |
| 3572 | return mkexpr(datavbits); |
| 3573 | } |
| 3574 | |
| 3575 | |
| 3576 | static |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3577 | IRAtom* expr2vbits_Load ( MCEnv* mce, |
| 3578 | IREndness end, IRType ty, |
| 3579 | IRAtom* addr, UInt bias ) |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3580 | { |
| 3581 | IRAtom *v64hi, *v64lo; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3582 | tl_assert(end == Iend_LE || end == Iend_BE); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3583 | switch (shadowTypeV(ty)) { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3584 | case Ity_I8: |
| 3585 | case Ity_I16: |
| 3586 | case Ity_I32: |
| 3587 | case Ity_I64: |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3588 | return expr2vbits_Load_WRK(mce, end, ty, addr, bias); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3589 | case Ity_V128: |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3590 | if (end == Iend_LE) { |
| 3591 | v64lo = expr2vbits_Load_WRK(mce, end, Ity_I64, addr, bias); |
| 3592 | v64hi = expr2vbits_Load_WRK(mce, end, Ity_I64, addr, bias+8); |
| 3593 | } else { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3594 | v64hi = expr2vbits_Load_WRK(mce, end, Ity_I64, addr, bias); |
| 3595 | v64lo = expr2vbits_Load_WRK(mce, end, Ity_I64, addr, bias+8); |
| 3596 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3597 | return assignNew( 'V', mce, |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3598 | Ity_V128, |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3599 | binop(Iop_64HLtoV128, v64hi, v64lo)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3600 | default: |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3601 | VG_(tool_panic)("expr2vbits_Load"); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | |
| 3606 | static |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3607 | IRAtom* expr2vbits_Mux0X ( MCEnv* mce, |
| 3608 | IRAtom* cond, IRAtom* expr0, IRAtom* exprX ) |
| 3609 | { |
| 3610 | IRAtom *vbitsC, *vbits0, *vbitsX; |
| 3611 | IRType ty; |
| 3612 | /* Given Mux0X(cond,expr0,exprX), generate |
| 3613 | Mux0X(cond,expr0#,exprX#) `UifU` PCast(cond#) |
| 3614 | That is, steer the V bits like the originals, but trash the |
| 3615 | result if the steering value is undefined. This gives |
| 3616 | lazy propagation. */ |
| 3617 | tl_assert(isOriginalAtom(mce, cond)); |
| 3618 | tl_assert(isOriginalAtom(mce, expr0)); |
| 3619 | tl_assert(isOriginalAtom(mce, exprX)); |
| 3620 | |
| 3621 | vbitsC = expr2vbits(mce, cond); |
| 3622 | vbits0 = expr2vbits(mce, expr0); |
| 3623 | vbitsX = expr2vbits(mce, exprX); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3624 | ty = typeOfIRExpr(mce->sb->tyenv, vbits0); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3625 | |
| 3626 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3627 | mkUifU(mce, ty, assignNew('V', mce, ty, |
| 3628 | IRExpr_Mux0X(cond, vbits0, vbitsX)), |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3629 | mkPCastTo(mce, ty, vbitsC) ); |
| 3630 | } |
| 3631 | |
| 3632 | /* --------- This is the main expression-handling function. --------- */ |
| 3633 | |
| 3634 | static |
| 3635 | IRExpr* expr2vbits ( MCEnv* mce, IRExpr* e ) |
| 3636 | { |
| 3637 | switch (e->tag) { |
| 3638 | |
| 3639 | case Iex_Get: |
| 3640 | return shadow_GET( mce, e->Iex.Get.offset, e->Iex.Get.ty ); |
| 3641 | |
| 3642 | case Iex_GetI: |
| 3643 | return shadow_GETI( mce, e->Iex.GetI.descr, |
| 3644 | e->Iex.GetI.ix, e->Iex.GetI.bias ); |
| 3645 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 3646 | case Iex_RdTmp: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3647 | return IRExpr_RdTmp( findShadowTmpV(mce, e->Iex.RdTmp.tmp) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3648 | |
| 3649 | case Iex_Const: |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3650 | return definedOfType(shadowTypeV(typeOfIRExpr(mce->sb->tyenv, e))); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3651 | |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 3652 | case Iex_Qop: |
| 3653 | return expr2vbits_Qop( |
| 3654 | mce, |
| 3655 | e->Iex.Qop.op, |
| 3656 | e->Iex.Qop.arg1, e->Iex.Qop.arg2, |
| 3657 | e->Iex.Qop.arg3, e->Iex.Qop.arg4 |
| 3658 | ); |
| 3659 | |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 3660 | case Iex_Triop: |
| 3661 | return expr2vbits_Triop( |
| 3662 | mce, |
| 3663 | e->Iex.Triop.op, |
| 3664 | e->Iex.Triop.arg1, e->Iex.Triop.arg2, e->Iex.Triop.arg3 |
| 3665 | ); |
| 3666 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3667 | case Iex_Binop: |
| 3668 | return expr2vbits_Binop( |
| 3669 | mce, |
| 3670 | e->Iex.Binop.op, |
| 3671 | e->Iex.Binop.arg1, e->Iex.Binop.arg2 |
| 3672 | ); |
| 3673 | |
| 3674 | case Iex_Unop: |
| 3675 | return expr2vbits_Unop( mce, e->Iex.Unop.op, e->Iex.Unop.arg ); |
| 3676 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3677 | case Iex_Load: |
| 3678 | return expr2vbits_Load( mce, e->Iex.Load.end, |
| 3679 | e->Iex.Load.ty, |
| 3680 | e->Iex.Load.addr, 0/*addr bias*/ ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3681 | |
| 3682 | case Iex_CCall: |
| 3683 | return mkLazyN( mce, e->Iex.CCall.args, |
| 3684 | e->Iex.CCall.retty, |
| 3685 | e->Iex.CCall.cee ); |
| 3686 | |
| 3687 | case Iex_Mux0X: |
| 3688 | return expr2vbits_Mux0X( mce, e->Iex.Mux0X.cond, e->Iex.Mux0X.expr0, |
| 3689 | e->Iex.Mux0X.exprX); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3690 | |
| 3691 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3692 | VG_(printf)("\n"); |
| 3693 | ppIRExpr(e); |
| 3694 | VG_(printf)("\n"); |
| 3695 | VG_(tool_panic)("memcheck: expr2vbits"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3696 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | /*------------------------------------------------------------*/ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3700 | /*--- Generate shadow stmts from all kinds of IRStmts. ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3701 | /*------------------------------------------------------------*/ |
| 3702 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3703 | /* Widen a value to the host word size. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3704 | |
| 3705 | static |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3706 | IRExpr* zwidenToHostWord ( MCEnv* mce, IRAtom* vatom ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3707 | { |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 3708 | IRType ty, tyH; |
| 3709 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3710 | /* vatom is vbits-value and as such can only have a shadow type. */ |
| 3711 | tl_assert(isShadowAtom(mce,vatom)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3712 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3713 | ty = typeOfIRExpr(mce->sb->tyenv, vatom); |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 3714 | tyH = mce->hWordTy; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3715 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3716 | if (tyH == Ity_I32) { |
| 3717 | switch (ty) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3718 | case Ity_I32: |
| 3719 | return vatom; |
| 3720 | case Ity_I16: |
| 3721 | return assignNew('V', mce, tyH, unop(Iop_16Uto32, vatom)); |
| 3722 | case Ity_I8: |
| 3723 | return assignNew('V', mce, tyH, unop(Iop_8Uto32, vatom)); |
| 3724 | default: |
| 3725 | goto unhandled; |
sewardj | 8ec2cfc | 2002-10-13 00:57:26 +0000 | [diff] [blame] | 3726 | } |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3727 | } else |
| 3728 | if (tyH == Ity_I64) { |
| 3729 | switch (ty) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3730 | case Ity_I32: |
| 3731 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, vatom)); |
| 3732 | case Ity_I16: |
| 3733 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, |
| 3734 | assignNew('V', mce, Ity_I32, unop(Iop_16Uto32, vatom)))); |
| 3735 | case Ity_I8: |
| 3736 | return assignNew('V', mce, tyH, unop(Iop_32Uto64, |
| 3737 | assignNew('V', mce, Ity_I32, unop(Iop_8Uto32, vatom)))); |
| 3738 | default: |
| 3739 | goto unhandled; |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 3740 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3741 | } else { |
| 3742 | goto unhandled; |
sewardj | 8ec2cfc | 2002-10-13 00:57:26 +0000 | [diff] [blame] | 3743 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3744 | unhandled: |
| 3745 | VG_(printf)("\nty = "); ppIRType(ty); VG_(printf)("\n"); |
| 3746 | VG_(tool_panic)("zwidenToHostWord"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3749 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3750 | /* Generate a shadow store. addr is always the original address atom. |
| 3751 | You can pass in either originals or V-bits for the data atom, but |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3752 | obviously not both. guard :: Ity_I1 controls whether the store |
| 3753 | really happens; NULL means it unconditionally does. Note that |
| 3754 | guard itself is not checked for definedness; the caller of this |
| 3755 | function must do that if necessary. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3756 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3757 | static |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3758 | void do_shadow_Store ( MCEnv* mce, |
| 3759 | IREndness end, |
| 3760 | IRAtom* addr, UInt bias, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3761 | IRAtom* data, IRAtom* vdata, |
| 3762 | IRAtom* guard ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3763 | { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3764 | IROp mkAdd; |
| 3765 | IRType ty, tyAddr; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3766 | void* helper = NULL; |
| 3767 | Char* hname = NULL; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3768 | IRConst* c; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3769 | |
| 3770 | tyAddr = mce->hWordTy; |
| 3771 | mkAdd = tyAddr==Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 3772 | tl_assert( tyAddr == Ity_I32 || tyAddr == Ity_I64 ); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3773 | tl_assert( end == Iend_LE || end == Iend_BE ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3774 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3775 | if (data) { |
| 3776 | tl_assert(!vdata); |
| 3777 | tl_assert(isOriginalAtom(mce, data)); |
| 3778 | tl_assert(bias == 0); |
| 3779 | vdata = expr2vbits( mce, data ); |
| 3780 | } else { |
| 3781 | tl_assert(vdata); |
| 3782 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3783 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3784 | tl_assert(isOriginalAtom(mce,addr)); |
| 3785 | tl_assert(isShadowAtom(mce,vdata)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3786 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3787 | if (guard) { |
| 3788 | tl_assert(isOriginalAtom(mce, guard)); |
| 3789 | tl_assert(typeOfIRExpr(mce->sb->tyenv, guard) == Ity_I1); |
| 3790 | } |
| 3791 | |
| 3792 | ty = typeOfIRExpr(mce->sb->tyenv, vdata); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3793 | |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3794 | // If we're not doing undefined value checking, pretend that this value |
| 3795 | // is "all valid". That lets Vex's optimiser remove some of the V bit |
| 3796 | // shadow computation ops that precede it. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3797 | if (MC_(clo_mc_level) == 1) { |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3798 | switch (ty) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3799 | case Ity_V128: // V128 weirdness |
| 3800 | c = IRConst_V128(V_BITS16_DEFINED); break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3801 | case Ity_I64: c = IRConst_U64 (V_BITS64_DEFINED); break; |
| 3802 | case Ity_I32: c = IRConst_U32 (V_BITS32_DEFINED); break; |
| 3803 | case Ity_I16: c = IRConst_U16 (V_BITS16_DEFINED); break; |
| 3804 | case Ity_I8: c = IRConst_U8 (V_BITS8_DEFINED); break; |
| 3805 | default: VG_(tool_panic)("memcheck:do_shadow_Store(LE)"); |
| 3806 | } |
| 3807 | vdata = IRExpr_Const( c ); |
| 3808 | } |
| 3809 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3810 | /* First, emit a definedness test for the address. This also sets |
| 3811 | the address (shadow) to 'defined' following the test. */ |
| 3812 | complainIfUndefined( mce, addr ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3813 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3814 | /* Now decide which helper function to call to write the data V |
| 3815 | bits into shadow memory. */ |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3816 | if (end == Iend_LE) { |
| 3817 | switch (ty) { |
| 3818 | case Ity_V128: /* we'll use the helper twice */ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3819 | case Ity_I64: helper = &MC_(helperc_STOREV64le); |
| 3820 | hname = "MC_(helperc_STOREV64le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3821 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3822 | case Ity_I32: helper = &MC_(helperc_STOREV32le); |
| 3823 | hname = "MC_(helperc_STOREV32le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3824 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3825 | case Ity_I16: helper = &MC_(helperc_STOREV16le); |
| 3826 | hname = "MC_(helperc_STOREV16le)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3827 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3828 | case Ity_I8: helper = &MC_(helperc_STOREV8); |
| 3829 | hname = "MC_(helperc_STOREV8)"; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3830 | break; |
| 3831 | default: VG_(tool_panic)("memcheck:do_shadow_Store(LE)"); |
| 3832 | } |
| 3833 | } else { |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3834 | switch (ty) { |
| 3835 | case Ity_V128: /* we'll use the helper twice */ |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3836 | case Ity_I64: helper = &MC_(helperc_STOREV64be); |
| 3837 | hname = "MC_(helperc_STOREV64be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3838 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3839 | case Ity_I32: helper = &MC_(helperc_STOREV32be); |
| 3840 | hname = "MC_(helperc_STOREV32be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3841 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3842 | case Ity_I16: helper = &MC_(helperc_STOREV16be); |
| 3843 | hname = "MC_(helperc_STOREV16be)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3844 | break; |
njn | 1d0825f | 2006-03-27 11:37:07 +0000 | [diff] [blame] | 3845 | case Ity_I8: helper = &MC_(helperc_STOREV8); |
| 3846 | hname = "MC_(helperc_STOREV8)"; |
sewardj | 8cf88b7 | 2005-07-08 01:29:33 +0000 | [diff] [blame] | 3847 | break; |
| 3848 | default: VG_(tool_panic)("memcheck:do_shadow_Store(BE)"); |
| 3849 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3850 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3851 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3852 | if (ty == Ity_V128) { |
| 3853 | |
sewardj | 20d38f2 | 2005-02-07 23:50:18 +0000 | [diff] [blame] | 3854 | /* V128-bit case */ |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3855 | /* See comment in next clause re 64-bit regparms */ |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3856 | /* also, need to be careful about endianness */ |
| 3857 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 3858 | Int offLo64, offHi64; |
| 3859 | IRDirty *diLo64, *diHi64; |
| 3860 | IRAtom *addrLo64, *addrHi64; |
| 3861 | IRAtom *vdataLo64, *vdataHi64; |
| 3862 | IRAtom *eBiasLo64, *eBiasHi64; |
| 3863 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3864 | if (end == Iend_LE) { |
| 3865 | offLo64 = 0; |
| 3866 | offHi64 = 8; |
| 3867 | } else { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3868 | offLo64 = 8; |
| 3869 | offHi64 = 0; |
| 3870 | } |
| 3871 | |
| 3872 | eBiasLo64 = tyAddr==Ity_I32 ? mkU32(bias+offLo64) : mkU64(bias+offLo64); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3873 | addrLo64 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasLo64) ); |
| 3874 | vdataLo64 = assignNew('V', mce, Ity_I64, unop(Iop_V128to64, vdata)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3875 | diLo64 = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3876 | 1/*regparms*/, |
| 3877 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 3878 | mkIRExprVec_2( addrLo64, vdataLo64 ) |
| 3879 | ); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3880 | eBiasHi64 = tyAddr==Ity_I32 ? mkU32(bias+offHi64) : mkU64(bias+offHi64); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3881 | addrHi64 = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBiasHi64) ); |
| 3882 | vdataHi64 = assignNew('V', mce, Ity_I64, unop(Iop_V128HIto64, vdata)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3883 | diHi64 = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3884 | 1/*regparms*/, |
| 3885 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 3886 | mkIRExprVec_2( addrHi64, vdataHi64 ) |
| 3887 | ); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3888 | if (guard) diLo64->guard = guard; |
| 3889 | if (guard) diHi64->guard = guard; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3890 | setHelperAnns( mce, diLo64 ); |
| 3891 | setHelperAnns( mce, diHi64 ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3892 | stmt( 'V', mce, IRStmt_Dirty(diLo64) ); |
| 3893 | stmt( 'V', mce, IRStmt_Dirty(diHi64) ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3894 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3895 | } else { |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3896 | |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 3897 | IRDirty *di; |
| 3898 | IRAtom *addrAct; |
| 3899 | |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3900 | /* 8/16/32/64-bit cases */ |
| 3901 | /* Generate the actual address into addrAct. */ |
| 3902 | if (bias == 0) { |
| 3903 | addrAct = addr; |
| 3904 | } else { |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 3905 | IRAtom* eBias = tyAddr==Ity_I32 ? mkU32(bias) : mkU64(bias); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3906 | addrAct = assignNew('V', mce, tyAddr, binop(mkAdd, addr, eBias)); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | if (ty == Ity_I64) { |
| 3910 | /* We can't do this with regparm 2 on 32-bit platforms, since |
| 3911 | the back ends aren't clever enough to handle 64-bit |
| 3912 | regparm args. Therefore be different. */ |
| 3913 | di = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3914 | 1/*regparms*/, |
| 3915 | hname, VG_(fnptr_to_fnentry)( helper ), |
| 3916 | mkIRExprVec_2( addrAct, vdata ) |
| 3917 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3918 | } else { |
| 3919 | di = unsafeIRDirty_0_N( |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3920 | 2/*regparms*/, |
| 3921 | hname, VG_(fnptr_to_fnentry)( helper ), |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3922 | mkIRExprVec_2( addrAct, |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 3923 | zwidenToHostWord( mce, vdata )) |
| 3924 | ); |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3925 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 3926 | if (guard) di->guard = guard; |
sewardj | 170ee21 | 2004-12-10 18:57:51 +0000 | [diff] [blame] | 3927 | setHelperAnns( mce, di ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 3928 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3929 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3930 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3931 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3932 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3933 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3934 | /* Do lazy pessimistic propagation through a dirty helper call, by |
| 3935 | looking at the annotations on it. This is the most complex part of |
| 3936 | Memcheck. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3937 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3938 | static IRType szToITy ( Int n ) |
| 3939 | { |
| 3940 | switch (n) { |
| 3941 | case 1: return Ity_I8; |
| 3942 | case 2: return Ity_I16; |
| 3943 | case 4: return Ity_I32; |
| 3944 | case 8: return Ity_I64; |
| 3945 | default: VG_(tool_panic)("szToITy(memcheck)"); |
| 3946 | } |
| 3947 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3948 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3949 | static |
| 3950 | void do_shadow_Dirty ( MCEnv* mce, IRDirty* d ) |
| 3951 | { |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 3952 | Int i, n, toDo, gSz, gOff; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3953 | IRAtom *src, *here, *curr; |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 3954 | IRType tySrc, tyDst; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3955 | IRTemp dst; |
| 3956 | IREndness end; |
| 3957 | |
| 3958 | /* What's the native endianness? We need to know this. */ |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 3959 | # if defined(VG_BIGENDIAN) |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3960 | end = Iend_BE; |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 3961 | # elif defined(VG_LITTLEENDIAN) |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 3962 | end = Iend_LE; |
| 3963 | # else |
| 3964 | # error "Unknown endianness" |
| 3965 | # endif |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3966 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3967 | /* First check the guard. */ |
| 3968 | complainIfUndefined(mce, d->guard); |
| 3969 | |
| 3970 | /* Now round up all inputs and PCast over them. */ |
sewardj | 7cf97ee | 2004-11-28 14:25:01 +0000 | [diff] [blame] | 3971 | curr = definedOfType(Ity_I32); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3972 | |
| 3973 | /* Inputs: unmasked args */ |
| 3974 | for (i = 0; d->args[i]; i++) { |
| 3975 | if (d->cee->mcx_mask & (1<<i)) { |
| 3976 | /* ignore this arg */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3977 | } else { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3978 | here = mkPCastTo( mce, Ity_I32, expr2vbits(mce, d->args[i]) ); |
| 3979 | curr = mkUifU32(mce, here, curr); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 3980 | } |
| 3981 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3982 | |
| 3983 | /* Inputs: guest state that we read. */ |
| 3984 | for (i = 0; i < d->nFxState; i++) { |
| 3985 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 3986 | if (d->fxState[i].fx == Ifx_Write) |
| 3987 | continue; |
sewardj | a720325 | 2004-11-26 19:17:47 +0000 | [diff] [blame] | 3988 | |
| 3989 | /* Ignore any sections marked as 'always defined'. */ |
| 3990 | if (isAlwaysDefd(mce, d->fxState[i].offset, d->fxState[i].size )) { |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 3991 | if (0) |
sewardj | a720325 | 2004-11-26 19:17:47 +0000 | [diff] [blame] | 3992 | VG_(printf)("memcheck: Dirty gst: ignored off %d, sz %d\n", |
| 3993 | d->fxState[i].offset, d->fxState[i].size ); |
| 3994 | continue; |
| 3995 | } |
| 3996 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 3997 | /* This state element is read or modified. So we need to |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 3998 | consider it. If larger than 8 bytes, deal with it in 8-byte |
| 3999 | chunks. */ |
| 4000 | gSz = d->fxState[i].size; |
| 4001 | gOff = d->fxState[i].offset; |
| 4002 | tl_assert(gSz > 0); |
| 4003 | while (True) { |
| 4004 | if (gSz == 0) break; |
| 4005 | n = gSz <= 8 ? gSz : 8; |
| 4006 | /* update 'curr' with UifU of the state slice |
| 4007 | gOff .. gOff+n-1 */ |
| 4008 | tySrc = szToITy( n ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4009 | src = assignNew( 'V', mce, tySrc, |
| 4010 | shadow_GET(mce, gOff, tySrc ) ); |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 4011 | here = mkPCastTo( mce, Ity_I32, src ); |
| 4012 | curr = mkUifU32(mce, here, curr); |
| 4013 | gSz -= n; |
| 4014 | gOff += n; |
| 4015 | } |
| 4016 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | /* Inputs: memory. First set up some info needed regardless of |
| 4020 | whether we're doing reads or writes. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4021 | |
| 4022 | if (d->mFx != Ifx_None) { |
| 4023 | /* Because we may do multiple shadow loads/stores from the same |
| 4024 | base address, it's best to do a single test of its |
| 4025 | definedness right now. Post-instrumentation optimisation |
| 4026 | should remove all but this test. */ |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 4027 | IRType tyAddr; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4028 | tl_assert(d->mAddr); |
| 4029 | complainIfUndefined(mce, d->mAddr); |
| 4030 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4031 | tyAddr = typeOfIRExpr(mce->sb->tyenv, d->mAddr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4032 | tl_assert(tyAddr == Ity_I32 || tyAddr == Ity_I64); |
| 4033 | tl_assert(tyAddr == mce->hWordTy); /* not really right */ |
| 4034 | } |
| 4035 | |
| 4036 | /* Deal with memory inputs (reads or modifies) */ |
| 4037 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4038 | toDo = d->mSize; |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4039 | /* chew off 32-bit chunks. We don't care about the endianness |
| 4040 | since it's all going to be condensed down to a single bit, |
| 4041 | but nevertheless choose an endianness which is hopefully |
| 4042 | native to the platform. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4043 | while (toDo >= 4) { |
| 4044 | here = mkPCastTo( |
| 4045 | mce, Ity_I32, |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4046 | expr2vbits_Load ( mce, end, Ity_I32, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4047 | d->mAddr, d->mSize - toDo ) |
| 4048 | ); |
| 4049 | curr = mkUifU32(mce, here, curr); |
| 4050 | toDo -= 4; |
| 4051 | } |
| 4052 | /* chew off 16-bit chunks */ |
| 4053 | while (toDo >= 2) { |
| 4054 | here = mkPCastTo( |
| 4055 | mce, Ity_I32, |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4056 | expr2vbits_Load ( mce, end, Ity_I16, |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4057 | d->mAddr, d->mSize - toDo ) |
| 4058 | ); |
| 4059 | curr = mkUifU32(mce, here, curr); |
| 4060 | toDo -= 2; |
| 4061 | } |
| 4062 | tl_assert(toDo == 0); /* also need to handle 1-byte excess */ |
| 4063 | } |
| 4064 | |
| 4065 | /* Whew! So curr is a 32-bit V-value summarising pessimistically |
| 4066 | all the inputs to the helper. Now we need to re-distribute the |
| 4067 | results to all destinations. */ |
| 4068 | |
| 4069 | /* Outputs: the destination temporary, if there is one. */ |
| 4070 | if (d->tmp != IRTemp_INVALID) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4071 | dst = findShadowTmpV(mce, d->tmp); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4072 | tyDst = typeOfIRTemp(mce->sb->tyenv, d->tmp); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4073 | assign( 'V', mce, dst, mkPCastTo( mce, tyDst, curr) ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | /* Outputs: guest state that we write or modify. */ |
| 4077 | for (i = 0; i < d->nFxState; i++) { |
| 4078 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 4079 | if (d->fxState[i].fx == Ifx_Read) |
| 4080 | continue; |
sewardj | a720325 | 2004-11-26 19:17:47 +0000 | [diff] [blame] | 4081 | /* Ignore any sections marked as 'always defined'. */ |
| 4082 | if (isAlwaysDefd(mce, d->fxState[i].offset, d->fxState[i].size )) |
| 4083 | continue; |
sewardj | e9e16d3 | 2004-12-10 13:17:55 +0000 | [diff] [blame] | 4084 | /* This state element is written or modified. So we need to |
| 4085 | consider it. If larger than 8 bytes, deal with it in 8-byte |
| 4086 | chunks. */ |
| 4087 | gSz = d->fxState[i].size; |
| 4088 | gOff = d->fxState[i].offset; |
| 4089 | tl_assert(gSz > 0); |
| 4090 | while (True) { |
| 4091 | if (gSz == 0) break; |
| 4092 | n = gSz <= 8 ? gSz : 8; |
| 4093 | /* Write suitably-casted 'curr' to the state slice |
| 4094 | gOff .. gOff+n-1 */ |
| 4095 | tyDst = szToITy( n ); |
| 4096 | do_shadow_PUT( mce, gOff, |
| 4097 | NULL, /* original atom */ |
| 4098 | mkPCastTo( mce, tyDst, curr ) ); |
| 4099 | gSz -= n; |
| 4100 | gOff += n; |
| 4101 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4102 | } |
| 4103 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4104 | /* Outputs: memory that we write or modify. Same comments about |
| 4105 | endianness as above apply. */ |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4106 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4107 | toDo = d->mSize; |
| 4108 | /* chew off 32-bit chunks */ |
| 4109 | while (toDo >= 4) { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4110 | do_shadow_Store( mce, end, d->mAddr, d->mSize - toDo, |
| 4111 | NULL, /* original data */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4112 | mkPCastTo( mce, Ity_I32, curr ), |
| 4113 | NULL/*guard*/ ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4114 | toDo -= 4; |
| 4115 | } |
| 4116 | /* chew off 16-bit chunks */ |
| 4117 | while (toDo >= 2) { |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4118 | do_shadow_Store( mce, end, d->mAddr, d->mSize - toDo, |
| 4119 | NULL, /* original data */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4120 | mkPCastTo( mce, Ity_I16, curr ), |
| 4121 | NULL/*guard*/ ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4122 | toDo -= 2; |
| 4123 | } |
| 4124 | tl_assert(toDo == 0); /* also need to handle 1-byte excess */ |
| 4125 | } |
| 4126 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4127 | } |
| 4128 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4129 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4130 | /* We have an ABI hint telling us that [base .. base+len-1] is to |
| 4131 | become undefined ("writable"). Generate code to call a helper to |
| 4132 | notify the A/V bit machinery of this fact. |
| 4133 | |
| 4134 | We call |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4135 | void MC_(helperc_MAKE_STACK_UNINIT) ( Addr base, UWord len, |
| 4136 | Addr nia ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4137 | */ |
| 4138 | static |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4139 | void do_AbiHint ( MCEnv* mce, IRExpr* base, Int len, IRExpr* nia ) |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4140 | { |
| 4141 | IRDirty* di; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4142 | /* Minor optimisation: if not doing origin tracking, ignore the |
| 4143 | supplied nia and pass zero instead. This is on the basis that |
| 4144 | MC_(helperc_MAKE_STACK_UNINIT) will ignore it anyway, and we can |
| 4145 | almost always generate a shorter instruction to put zero into a |
| 4146 | register than any other value. */ |
| 4147 | if (MC_(clo_mc_level) < 3) |
| 4148 | nia = mkIRExpr_HWord(0); |
| 4149 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4150 | di = unsafeIRDirty_0_N( |
| 4151 | 0/*regparms*/, |
| 4152 | "MC_(helperc_MAKE_STACK_UNINIT)", |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 4153 | VG_(fnptr_to_fnentry)( &MC_(helperc_MAKE_STACK_UNINIT) ), |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4154 | mkIRExprVec_3( base, mkIRExpr_HWord( (UInt)len), nia ) |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4155 | ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4156 | stmt( 'V', mce, IRStmt_Dirty(di) ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4159 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4160 | /* ------ Dealing with IRCAS (big and complex) ------ */ |
| 4161 | |
| 4162 | /* FWDS */ |
| 4163 | static IRAtom* gen_load_b ( MCEnv* mce, Int szB, |
| 4164 | IRAtom* baseaddr, Int offset ); |
| 4165 | static IRAtom* gen_maxU32 ( MCEnv* mce, IRAtom* b1, IRAtom* b2 ); |
| 4166 | static void gen_store_b ( MCEnv* mce, Int szB, |
| 4167 | IRAtom* baseaddr, Int offset, IRAtom* dataB, |
| 4168 | IRAtom* guard ); |
| 4169 | |
| 4170 | static void do_shadow_CAS_single ( MCEnv* mce, IRCAS* cas ); |
| 4171 | static void do_shadow_CAS_double ( MCEnv* mce, IRCAS* cas ); |
| 4172 | |
| 4173 | |
| 4174 | /* Either ORIG and SHADOW are both IRExpr.RdTmps, or they are both |
| 4175 | IRExpr.Consts, else this asserts. If they are both Consts, it |
| 4176 | doesn't do anything. So that just leaves the RdTmp case. |
| 4177 | |
| 4178 | In which case: this assigns the shadow value SHADOW to the IR |
| 4179 | shadow temporary associated with ORIG. That is, ORIG, being an |
| 4180 | original temporary, will have a shadow temporary associated with |
| 4181 | it. However, in the case envisaged here, there will so far have |
| 4182 | been no IR emitted to actually write a shadow value into that |
| 4183 | temporary. What this routine does is to (emit IR to) copy the |
| 4184 | value in SHADOW into said temporary, so that after this call, |
| 4185 | IRExpr.RdTmps of ORIG's shadow temp will correctly pick up the |
| 4186 | value in SHADOW. |
| 4187 | |
| 4188 | Point is to allow callers to compute "by hand" a shadow value for |
| 4189 | ORIG, and force it to be associated with ORIG. |
| 4190 | |
| 4191 | How do we know that that shadow associated with ORIG has not so far |
| 4192 | been assigned to? Well, we don't per se know that, but supposing |
| 4193 | it had. Then this routine would create a second assignment to it, |
| 4194 | and later the IR sanity checker would barf. But that never |
| 4195 | happens. QED. |
| 4196 | */ |
| 4197 | static void bind_shadow_tmp_to_orig ( UChar how, |
| 4198 | MCEnv* mce, |
| 4199 | IRAtom* orig, IRAtom* shadow ) |
| 4200 | { |
| 4201 | tl_assert(isOriginalAtom(mce, orig)); |
| 4202 | tl_assert(isShadowAtom(mce, shadow)); |
| 4203 | switch (orig->tag) { |
| 4204 | case Iex_Const: |
| 4205 | tl_assert(shadow->tag == Iex_Const); |
| 4206 | break; |
| 4207 | case Iex_RdTmp: |
| 4208 | tl_assert(shadow->tag == Iex_RdTmp); |
| 4209 | if (how == 'V') { |
| 4210 | assign('V', mce, findShadowTmpV(mce,orig->Iex.RdTmp.tmp), |
| 4211 | shadow); |
| 4212 | } else { |
| 4213 | tl_assert(how == 'B'); |
| 4214 | assign('B', mce, findShadowTmpB(mce,orig->Iex.RdTmp.tmp), |
| 4215 | shadow); |
| 4216 | } |
| 4217 | break; |
| 4218 | default: |
| 4219 | tl_assert(0); |
| 4220 | } |
| 4221 | } |
| 4222 | |
| 4223 | |
| 4224 | static |
| 4225 | void do_shadow_CAS ( MCEnv* mce, IRCAS* cas ) |
| 4226 | { |
| 4227 | /* Scheme is (both single- and double- cases): |
| 4228 | |
| 4229 | 1. fetch data#,dataB (the proposed new value) |
| 4230 | |
| 4231 | 2. fetch expd#,expdB (what we expect to see at the address) |
| 4232 | |
| 4233 | 3. check definedness of address |
| 4234 | |
| 4235 | 4. load old#,oldB from shadow memory; this also checks |
| 4236 | addressibility of the address |
| 4237 | |
| 4238 | 5. the CAS itself |
| 4239 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4240 | 6. compute "expected == old". See COMMENT_ON_CasCmpEQ below. |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4241 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4242 | 7. if "expected == old" (as computed by (6)) |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4243 | store data#,dataB to shadow memory |
| 4244 | |
| 4245 | Note that 5 reads 'old' but 4 reads 'old#'. Similarly, 5 stores |
| 4246 | 'data' but 7 stores 'data#'. Hence it is possible for the |
| 4247 | shadow data to be incorrectly checked and/or updated: |
| 4248 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4249 | * 7 is at least gated correctly, since the 'expected == old' |
| 4250 | condition is derived from outputs of 5. However, the shadow |
| 4251 | write could happen too late: imagine after 5 we are |
| 4252 | descheduled, a different thread runs, writes a different |
| 4253 | (shadow) value at the address, and then we resume, hence |
| 4254 | overwriting the shadow value written by the other thread. |
| 4255 | |
| 4256 | Because the original memory access is atomic, there's no way to |
| 4257 | make both the original and shadow accesses into a single atomic |
| 4258 | thing, hence this is unavoidable. |
| 4259 | |
| 4260 | At least as Valgrind stands, I don't think it's a problem, since |
| 4261 | we're single threaded *and* we guarantee that there are no |
| 4262 | context switches during the execution of any specific superblock |
| 4263 | -- context switches can only happen at superblock boundaries. |
| 4264 | |
| 4265 | If Valgrind ever becomes MT in the future, then it might be more |
| 4266 | of a problem. A possible kludge would be to artificially |
| 4267 | associate with the location, a lock, which we must acquire and |
| 4268 | release around the transaction as a whole. Hmm, that probably |
| 4269 | would't work properly since it only guards us against other |
| 4270 | threads doing CASs on the same location, not against other |
| 4271 | threads doing normal reads and writes. |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4272 | |
| 4273 | ------------------------------------------------------------ |
| 4274 | |
| 4275 | COMMENT_ON_CasCmpEQ: |
| 4276 | |
| 4277 | Note two things. Firstly, in the sequence above, we compute |
| 4278 | "expected == old", but we don't check definedness of it. Why |
| 4279 | not? Also, the x86 and amd64 front ends use |
| 4280 | Iop_CmpCas{EQ,NE}{8,16,32,64} comparisons to make the equivalent |
| 4281 | determination (expected == old ?) for themselves, and we also |
| 4282 | don't check definedness for those primops; we just say that the |
| 4283 | result is defined. Why? Details follow. |
| 4284 | |
| 4285 | x86/amd64 contains various forms of locked insns: |
| 4286 | * lock prefix before all basic arithmetic insn; |
| 4287 | eg lock xorl %reg1,(%reg2) |
| 4288 | * atomic exchange reg-mem |
| 4289 | * compare-and-swaps |
| 4290 | |
| 4291 | Rather than attempt to represent them all, which would be a |
| 4292 | royal PITA, I used a result from Maurice Herlihy |
| 4293 | (http://en.wikipedia.org/wiki/Maurice_Herlihy), in which he |
| 4294 | demonstrates that compare-and-swap is a primitive more general |
| 4295 | than the other two, and so can be used to represent all of them. |
| 4296 | So the translation scheme for (eg) lock incl (%reg) is as |
| 4297 | follows: |
| 4298 | |
| 4299 | again: |
| 4300 | old = * %reg |
| 4301 | new = old + 1 |
| 4302 | atomically { if (* %reg == old) { * %reg = new } else { goto again } } |
| 4303 | |
| 4304 | The "atomically" is the CAS bit. The scheme is always the same: |
| 4305 | get old value from memory, compute new value, atomically stuff |
| 4306 | new value back in memory iff the old value has not changed (iow, |
| 4307 | no other thread modified it in the meantime). If it has changed |
| 4308 | then we've been out-raced and we have to start over. |
| 4309 | |
| 4310 | Now that's all very neat, but it has the bad side effect of |
| 4311 | introducing an explicit equality test into the translation. |
| 4312 | Consider the behaviour of said code on a memory location which |
| 4313 | is uninitialised. We will wind up doing a comparison on |
| 4314 | uninitialised data, and mc duly complains. |
| 4315 | |
| 4316 | What's difficult about this is, the common case is that the |
| 4317 | location is uncontended, and so we're usually comparing the same |
| 4318 | value (* %reg) with itself. So we shouldn't complain even if it |
| 4319 | is undefined. But mc doesn't know that. |
| 4320 | |
| 4321 | My solution is to mark the == in the IR specially, so as to tell |
| 4322 | mc that it almost certainly compares a value with itself, and we |
| 4323 | should just regard the result as always defined. Rather than |
| 4324 | add a bit to all IROps, I just cloned Iop_CmpEQ{8,16,32,64} into |
| 4325 | Iop_CasCmpEQ{8,16,32,64} so as not to disturb anything else. |
| 4326 | |
| 4327 | So there's always the question of, can this give a false |
| 4328 | negative? eg, imagine that initially, * %reg is defined; and we |
| 4329 | read that; but then in the gap between the read and the CAS, a |
| 4330 | different thread writes an undefined (and different) value at |
| 4331 | the location. Then the CAS in this thread will fail and we will |
| 4332 | go back to "again:", but without knowing that the trip back |
| 4333 | there was based on an undefined comparison. No matter; at least |
| 4334 | the other thread won the race and the location is correctly |
| 4335 | marked as undefined. What if it wrote an uninitialised version |
| 4336 | of the same value that was there originally, though? |
| 4337 | |
| 4338 | etc etc. Seems like there's a small corner case in which we |
| 4339 | might lose the fact that something's defined -- we're out-raced |
| 4340 | in between the "old = * reg" and the "atomically {", _and_ the |
| 4341 | other thread is writing in an undefined version of what's |
| 4342 | already there. Well, that seems pretty unlikely. |
| 4343 | |
| 4344 | --- |
| 4345 | |
| 4346 | If we ever need to reinstate it .. code which generates a |
| 4347 | definedness test for "expected == old" was removed at r10432 of |
| 4348 | this file. |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4349 | */ |
| 4350 | if (cas->oldHi == IRTemp_INVALID) { |
| 4351 | do_shadow_CAS_single( mce, cas ); |
| 4352 | } else { |
| 4353 | do_shadow_CAS_double( mce, cas ); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | |
| 4358 | static void do_shadow_CAS_single ( MCEnv* mce, IRCAS* cas ) |
| 4359 | { |
| 4360 | IRAtom *vdataLo = NULL, *bdataLo = NULL; |
| 4361 | IRAtom *vexpdLo = NULL, *bexpdLo = NULL; |
| 4362 | IRAtom *voldLo = NULL, *boldLo = NULL; |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4363 | IRAtom *expd_eq_old = NULL; |
| 4364 | IROp opCasCmpEQ; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4365 | Int elemSzB; |
| 4366 | IRType elemTy; |
| 4367 | Bool otrak = MC_(clo_mc_level) >= 3; /* a shorthand */ |
| 4368 | |
| 4369 | /* single CAS */ |
| 4370 | tl_assert(cas->oldHi == IRTemp_INVALID); |
| 4371 | tl_assert(cas->expdHi == NULL); |
| 4372 | tl_assert(cas->dataHi == NULL); |
| 4373 | |
| 4374 | elemTy = typeOfIRExpr(mce->sb->tyenv, cas->expdLo); |
| 4375 | switch (elemTy) { |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4376 | case Ity_I8: elemSzB = 1; opCasCmpEQ = Iop_CasCmpEQ8; break; |
| 4377 | case Ity_I16: elemSzB = 2; opCasCmpEQ = Iop_CasCmpEQ16; break; |
| 4378 | case Ity_I32: elemSzB = 4; opCasCmpEQ = Iop_CasCmpEQ32; break; |
| 4379 | case Ity_I64: elemSzB = 8; opCasCmpEQ = Iop_CasCmpEQ64; break; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4380 | default: tl_assert(0); /* IR defn disallows any other types */ |
| 4381 | } |
| 4382 | |
| 4383 | /* 1. fetch data# (the proposed new value) */ |
| 4384 | tl_assert(isOriginalAtom(mce, cas->dataLo)); |
| 4385 | vdataLo |
| 4386 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataLo)); |
| 4387 | tl_assert(isShadowAtom(mce, vdataLo)); |
| 4388 | if (otrak) { |
| 4389 | bdataLo |
| 4390 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataLo)); |
| 4391 | tl_assert(isShadowAtom(mce, bdataLo)); |
| 4392 | } |
| 4393 | |
| 4394 | /* 2. fetch expected# (what we expect to see at the address) */ |
| 4395 | tl_assert(isOriginalAtom(mce, cas->expdLo)); |
| 4396 | vexpdLo |
| 4397 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdLo)); |
| 4398 | tl_assert(isShadowAtom(mce, vexpdLo)); |
| 4399 | if (otrak) { |
| 4400 | bexpdLo |
| 4401 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdLo)); |
| 4402 | tl_assert(isShadowAtom(mce, bexpdLo)); |
| 4403 | } |
| 4404 | |
| 4405 | /* 3. check definedness of address */ |
| 4406 | /* 4. fetch old# from shadow memory; this also checks |
| 4407 | addressibility of the address */ |
| 4408 | voldLo |
| 4409 | = assignNew( |
| 4410 | 'V', mce, elemTy, |
| 4411 | expr2vbits_Load( |
| 4412 | mce, |
| 4413 | cas->end, elemTy, cas->addr, 0/*Addr bias*/ |
| 4414 | )); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4415 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldLo), voldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4416 | if (otrak) { |
| 4417 | boldLo |
| 4418 | = assignNew('B', mce, Ity_I32, |
| 4419 | gen_load_b(mce, elemSzB, cas->addr, 0/*addr bias*/)); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4420 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldLo), boldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | /* 5. the CAS itself */ |
| 4424 | stmt( 'C', mce, IRStmt_CAS(cas) ); |
| 4425 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4426 | /* 6. compute "expected == old" */ |
| 4427 | /* See COMMENT_ON_CasCmpEQ in this file background/rationale. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4428 | /* Note that 'C' is kinda faking it; it is indeed a non-shadow |
| 4429 | tree, but it's not copied from the input block. */ |
| 4430 | expd_eq_old |
| 4431 | = assignNew('C', mce, Ity_I1, |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4432 | binop(opCasCmpEQ, cas->expdLo, mkexpr(cas->oldLo))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4433 | |
| 4434 | /* 7. if "expected == old" |
| 4435 | store data# to shadow memory */ |
| 4436 | do_shadow_Store( mce, cas->end, cas->addr, 0/*bias*/, |
| 4437 | NULL/*data*/, vdataLo/*vdata*/, |
| 4438 | expd_eq_old/*guard for store*/ ); |
| 4439 | if (otrak) { |
| 4440 | gen_store_b( mce, elemSzB, cas->addr, 0/*offset*/, |
| 4441 | bdataLo/*bdata*/, |
| 4442 | expd_eq_old/*guard for store*/ ); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | |
| 4447 | static void do_shadow_CAS_double ( MCEnv* mce, IRCAS* cas ) |
| 4448 | { |
| 4449 | IRAtom *vdataHi = NULL, *bdataHi = NULL; |
| 4450 | IRAtom *vdataLo = NULL, *bdataLo = NULL; |
| 4451 | IRAtom *vexpdHi = NULL, *bexpdHi = NULL; |
| 4452 | IRAtom *vexpdLo = NULL, *bexpdLo = NULL; |
| 4453 | IRAtom *voldHi = NULL, *boldHi = NULL; |
| 4454 | IRAtom *voldLo = NULL, *boldLo = NULL; |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4455 | IRAtom *xHi = NULL, *xLo = NULL, *xHL = NULL; |
| 4456 | IRAtom *expd_eq_old = NULL, *zero = NULL; |
| 4457 | IROp opCasCmpEQ, opOr, opXor; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4458 | Int elemSzB, memOffsLo, memOffsHi; |
| 4459 | IRType elemTy; |
| 4460 | Bool otrak = MC_(clo_mc_level) >= 3; /* a shorthand */ |
| 4461 | |
| 4462 | /* double CAS */ |
| 4463 | tl_assert(cas->oldHi != IRTemp_INVALID); |
| 4464 | tl_assert(cas->expdHi != NULL); |
| 4465 | tl_assert(cas->dataHi != NULL); |
| 4466 | |
| 4467 | elemTy = typeOfIRExpr(mce->sb->tyenv, cas->expdLo); |
| 4468 | switch (elemTy) { |
| 4469 | case Ity_I8: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4470 | opCasCmpEQ = Iop_CasCmpEQ8; opOr = Iop_Or8; opXor = Iop_Xor8; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4471 | elemSzB = 1; zero = mkU8(0); |
| 4472 | break; |
| 4473 | case Ity_I16: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4474 | opCasCmpEQ = Iop_CasCmpEQ16; opOr = Iop_Or16; opXor = Iop_Xor16; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4475 | elemSzB = 2; zero = mkU16(0); |
| 4476 | break; |
| 4477 | case Ity_I32: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4478 | opCasCmpEQ = Iop_CasCmpEQ32; opOr = Iop_Or32; opXor = Iop_Xor32; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4479 | elemSzB = 4; zero = mkU32(0); |
| 4480 | break; |
| 4481 | case Ity_I64: |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4482 | opCasCmpEQ = Iop_CasCmpEQ64; opOr = Iop_Or64; opXor = Iop_Xor64; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4483 | elemSzB = 8; zero = mkU64(0); |
| 4484 | break; |
| 4485 | default: |
| 4486 | tl_assert(0); /* IR defn disallows any other types */ |
| 4487 | } |
| 4488 | |
| 4489 | /* 1. fetch data# (the proposed new value) */ |
| 4490 | tl_assert(isOriginalAtom(mce, cas->dataHi)); |
| 4491 | tl_assert(isOriginalAtom(mce, cas->dataLo)); |
| 4492 | vdataHi |
| 4493 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataHi)); |
| 4494 | vdataLo |
| 4495 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->dataLo)); |
| 4496 | tl_assert(isShadowAtom(mce, vdataHi)); |
| 4497 | tl_assert(isShadowAtom(mce, vdataLo)); |
| 4498 | if (otrak) { |
| 4499 | bdataHi |
| 4500 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataHi)); |
| 4501 | bdataLo |
| 4502 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->dataLo)); |
| 4503 | tl_assert(isShadowAtom(mce, bdataHi)); |
| 4504 | tl_assert(isShadowAtom(mce, bdataLo)); |
| 4505 | } |
| 4506 | |
| 4507 | /* 2. fetch expected# (what we expect to see at the address) */ |
| 4508 | tl_assert(isOriginalAtom(mce, cas->expdHi)); |
| 4509 | tl_assert(isOriginalAtom(mce, cas->expdLo)); |
| 4510 | vexpdHi |
| 4511 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdHi)); |
| 4512 | vexpdLo |
| 4513 | = assignNew('V', mce, elemTy, expr2vbits(mce, cas->expdLo)); |
| 4514 | tl_assert(isShadowAtom(mce, vexpdHi)); |
| 4515 | tl_assert(isShadowAtom(mce, vexpdLo)); |
| 4516 | if (otrak) { |
| 4517 | bexpdHi |
| 4518 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdHi)); |
| 4519 | bexpdLo |
| 4520 | = assignNew('B', mce, Ity_I32, schemeE(mce, cas->expdLo)); |
| 4521 | tl_assert(isShadowAtom(mce, bexpdHi)); |
| 4522 | tl_assert(isShadowAtom(mce, bexpdLo)); |
| 4523 | } |
| 4524 | |
| 4525 | /* 3. check definedness of address */ |
| 4526 | /* 4. fetch old# from shadow memory; this also checks |
| 4527 | addressibility of the address */ |
| 4528 | if (cas->end == Iend_LE) { |
| 4529 | memOffsLo = 0; |
| 4530 | memOffsHi = elemSzB; |
| 4531 | } else { |
| 4532 | tl_assert(cas->end == Iend_BE); |
| 4533 | memOffsLo = elemSzB; |
| 4534 | memOffsHi = 0; |
| 4535 | } |
| 4536 | voldHi |
| 4537 | = assignNew( |
| 4538 | 'V', mce, elemTy, |
| 4539 | expr2vbits_Load( |
| 4540 | mce, |
| 4541 | cas->end, elemTy, cas->addr, memOffsHi/*Addr bias*/ |
| 4542 | )); |
| 4543 | voldLo |
| 4544 | = assignNew( |
| 4545 | 'V', mce, elemTy, |
| 4546 | expr2vbits_Load( |
| 4547 | mce, |
| 4548 | cas->end, elemTy, cas->addr, memOffsLo/*Addr bias*/ |
| 4549 | )); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4550 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldHi), voldHi); |
| 4551 | bind_shadow_tmp_to_orig('V', mce, mkexpr(cas->oldLo), voldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4552 | if (otrak) { |
| 4553 | boldHi |
| 4554 | = assignNew('B', mce, Ity_I32, |
| 4555 | gen_load_b(mce, elemSzB, cas->addr, |
| 4556 | memOffsHi/*addr bias*/)); |
| 4557 | boldLo |
| 4558 | = assignNew('B', mce, Ity_I32, |
| 4559 | gen_load_b(mce, elemSzB, cas->addr, |
| 4560 | memOffsLo/*addr bias*/)); |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4561 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldHi), boldHi); |
| 4562 | bind_shadow_tmp_to_orig('B', mce, mkexpr(cas->oldLo), boldLo); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | /* 5. the CAS itself */ |
| 4566 | stmt( 'C', mce, IRStmt_CAS(cas) ); |
| 4567 | |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4568 | /* 6. compute "expected == old" */ |
| 4569 | /* See COMMENT_ON_CasCmpEQ in this file background/rationale. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4570 | /* Note that 'C' is kinda faking it; it is indeed a non-shadow |
| 4571 | tree, but it's not copied from the input block. */ |
| 4572 | /* |
| 4573 | xHi = oldHi ^ expdHi; |
| 4574 | xLo = oldLo ^ expdLo; |
| 4575 | xHL = xHi | xLo; |
| 4576 | expd_eq_old = xHL == 0; |
| 4577 | */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4578 | xHi = assignNew('C', mce, elemTy, |
| 4579 | binop(opXor, cas->expdHi, mkexpr(cas->oldHi))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4580 | xLo = assignNew('C', mce, elemTy, |
| 4581 | binop(opXor, cas->expdLo, mkexpr(cas->oldLo))); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4582 | xHL = assignNew('C', mce, elemTy, |
| 4583 | binop(opOr, xHi, xLo)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4584 | expd_eq_old |
| 4585 | = assignNew('C', mce, Ity_I1, |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 4586 | binop(opCasCmpEQ, xHL, zero)); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4587 | |
| 4588 | /* 7. if "expected == old" |
| 4589 | store data# to shadow memory */ |
| 4590 | do_shadow_Store( mce, cas->end, cas->addr, memOffsHi/*bias*/, |
| 4591 | NULL/*data*/, vdataHi/*vdata*/, |
| 4592 | expd_eq_old/*guard for store*/ ); |
| 4593 | do_shadow_Store( mce, cas->end, cas->addr, memOffsLo/*bias*/, |
| 4594 | NULL/*data*/, vdataLo/*vdata*/, |
| 4595 | expd_eq_old/*guard for store*/ ); |
| 4596 | if (otrak) { |
| 4597 | gen_store_b( mce, elemSzB, cas->addr, memOffsHi/*offset*/, |
| 4598 | bdataHi/*bdata*/, |
| 4599 | expd_eq_old/*guard for store*/ ); |
| 4600 | gen_store_b( mce, elemSzB, cas->addr, memOffsLo/*offset*/, |
| 4601 | bdataLo/*bdata*/, |
| 4602 | expd_eq_old/*guard for store*/ ); |
| 4603 | } |
| 4604 | } |
| 4605 | |
| 4606 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 4607 | /* ------ Dealing with LL/SC (not difficult) ------ */ |
| 4608 | |
| 4609 | static void do_shadow_LLSC ( MCEnv* mce, |
| 4610 | IREndness stEnd, |
| 4611 | IRTemp stResult, |
| 4612 | IRExpr* stAddr, |
| 4613 | IRExpr* stStoredata ) |
| 4614 | { |
| 4615 | /* In short: treat a load-linked like a normal load followed by an |
| 4616 | assignment of the loaded (shadow) data to the result temporary. |
| 4617 | Treat a store-conditional like a normal store, and mark the |
| 4618 | result temporary as defined. */ |
| 4619 | IRType resTy = typeOfIRTemp(mce->sb->tyenv, stResult); |
| 4620 | IRTemp resTmp = findShadowTmpV(mce, stResult); |
| 4621 | |
| 4622 | tl_assert(isIRAtom(stAddr)); |
| 4623 | if (stStoredata) |
| 4624 | tl_assert(isIRAtom(stStoredata)); |
| 4625 | |
| 4626 | if (stStoredata == NULL) { |
| 4627 | /* Load Linked */ |
| 4628 | /* Just treat this as a normal load, followed by an assignment of |
| 4629 | the value to .result. */ |
| 4630 | /* Stay sane */ |
| 4631 | tl_assert(resTy == Ity_I64 || resTy == Ity_I32 |
| 4632 | || resTy == Ity_I16 || resTy == Ity_I8); |
| 4633 | assign( 'V', mce, resTmp, |
| 4634 | expr2vbits_Load( |
| 4635 | mce, stEnd, resTy, stAddr, 0/*addr bias*/)); |
| 4636 | } else { |
| 4637 | /* Store Conditional */ |
| 4638 | /* Stay sane */ |
| 4639 | IRType dataTy = typeOfIRExpr(mce->sb->tyenv, |
| 4640 | stStoredata); |
| 4641 | tl_assert(dataTy == Ity_I64 || dataTy == Ity_I32 |
| 4642 | || dataTy == Ity_I16 || dataTy == Ity_I8); |
| 4643 | do_shadow_Store( mce, stEnd, |
| 4644 | stAddr, 0/* addr bias */, |
| 4645 | stStoredata, |
| 4646 | NULL /* shadow data */, |
| 4647 | NULL/*guard*/ ); |
| 4648 | /* This is a store conditional, so it writes to .result a value |
| 4649 | indicating whether or not the store succeeded. Just claim |
| 4650 | this value is always defined. In the PowerPC interpretation |
| 4651 | of store-conditional, definedness of the success indication |
| 4652 | depends on whether the address of the store matches the |
| 4653 | reservation address. But we can't tell that here (and |
| 4654 | anyway, we're not being PowerPC-specific). At least we are |
| 4655 | guaranteed that the definedness of the store address, and its |
| 4656 | addressibility, will be checked as per normal. So it seems |
| 4657 | pretty safe to just say that the success indication is always |
| 4658 | defined. |
| 4659 | |
| 4660 | In schemeS, for origin tracking, we must correspondingly set |
| 4661 | a no-origin value for the origin shadow of .result. |
| 4662 | */ |
| 4663 | tl_assert(resTy == Ity_I1); |
| 4664 | assign( 'V', mce, resTmp, definedOfType(resTy) ); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4669 | /*------------------------------------------------------------*/ |
| 4670 | /*--- Memcheck main ---*/ |
| 4671 | /*------------------------------------------------------------*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4672 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4673 | static void schemeS ( MCEnv* mce, IRStmt* st ); |
| 4674 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4675 | static Bool isBogusAtom ( IRAtom* at ) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4676 | { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4677 | ULong n = 0; |
| 4678 | IRConst* con; |
sewardj | 710d6c2 | 2005-03-20 18:55:15 +0000 | [diff] [blame] | 4679 | tl_assert(isIRAtom(at)); |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4680 | if (at->tag == Iex_RdTmp) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4681 | return False; |
| 4682 | tl_assert(at->tag == Iex_Const); |
| 4683 | con = at->Iex.Const.con; |
| 4684 | switch (con->tag) { |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4685 | case Ico_U1: return False; |
| 4686 | case Ico_U8: n = (ULong)con->Ico.U8; break; |
| 4687 | case Ico_U16: n = (ULong)con->Ico.U16; break; |
| 4688 | case Ico_U32: n = (ULong)con->Ico.U32; break; |
| 4689 | case Ico_U64: n = (ULong)con->Ico.U64; break; |
| 4690 | case Ico_F64: return False; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 4691 | case Ico_F32i: return False; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4692 | case Ico_F64i: return False; |
| 4693 | case Ico_V128: return False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4694 | default: ppIRExpr(at); tl_assert(0); |
| 4695 | } |
| 4696 | /* VG_(printf)("%llx\n", n); */ |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 4697 | return (/*32*/ n == 0xFEFEFEFFULL |
| 4698 | /*32*/ || n == 0x80808080ULL |
sewardj | 17b4743 | 2008-12-17 01:12:58 +0000 | [diff] [blame] | 4699 | /*32*/ || n == 0x7F7F7F7FULL |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 4700 | /*64*/ || n == 0xFFFFFFFFFEFEFEFFULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 4701 | /*64*/ || n == 0xFEFEFEFEFEFEFEFFULL |
tom | d9774d7 | 2005-06-27 08:11:01 +0000 | [diff] [blame] | 4702 | /*64*/ || n == 0x0000000000008080ULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 4703 | /*64*/ || n == 0x8080808080808080ULL |
sewardj | 17b4743 | 2008-12-17 01:12:58 +0000 | [diff] [blame] | 4704 | /*64*/ || n == 0x0101010101010101ULL |
sewardj | 96a922e | 2005-04-23 23:26:29 +0000 | [diff] [blame] | 4705 | ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4706 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4707 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4708 | static Bool checkForBogusLiterals ( /*FLAT*/ IRStmt* st ) |
| 4709 | { |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4710 | Int i; |
| 4711 | IRExpr* e; |
| 4712 | IRDirty* d; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4713 | IRCAS* cas; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4714 | switch (st->tag) { |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4715 | case Ist_WrTmp: |
| 4716 | e = st->Ist.WrTmp.data; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4717 | switch (e->tag) { |
| 4718 | case Iex_Get: |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4719 | case Iex_RdTmp: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4720 | return False; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4721 | case Iex_Const: |
| 4722 | return isBogusAtom(e); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4723 | case Iex_Unop: |
| 4724 | return isBogusAtom(e->Iex.Unop.arg); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4725 | case Iex_GetI: |
| 4726 | return isBogusAtom(e->Iex.GetI.ix); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4727 | case Iex_Binop: |
| 4728 | return isBogusAtom(e->Iex.Binop.arg1) |
| 4729 | || isBogusAtom(e->Iex.Binop.arg2); |
sewardj | ed69fdb | 2006-02-03 16:12:27 +0000 | [diff] [blame] | 4730 | case Iex_Triop: |
| 4731 | return isBogusAtom(e->Iex.Triop.arg1) |
| 4732 | || isBogusAtom(e->Iex.Triop.arg2) |
| 4733 | || isBogusAtom(e->Iex.Triop.arg3); |
sewardj | e91cea7 | 2006-02-08 19:32:02 +0000 | [diff] [blame] | 4734 | case Iex_Qop: |
| 4735 | return isBogusAtom(e->Iex.Qop.arg1) |
| 4736 | || isBogusAtom(e->Iex.Qop.arg2) |
| 4737 | || isBogusAtom(e->Iex.Qop.arg3) |
| 4738 | || isBogusAtom(e->Iex.Qop.arg4); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4739 | case Iex_Mux0X: |
| 4740 | return isBogusAtom(e->Iex.Mux0X.cond) |
| 4741 | || isBogusAtom(e->Iex.Mux0X.expr0) |
| 4742 | || isBogusAtom(e->Iex.Mux0X.exprX); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4743 | case Iex_Load: |
| 4744 | return isBogusAtom(e->Iex.Load.addr); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4745 | case Iex_CCall: |
| 4746 | for (i = 0; e->Iex.CCall.args[i]; i++) |
| 4747 | if (isBogusAtom(e->Iex.CCall.args[i])) |
| 4748 | return True; |
| 4749 | return False; |
| 4750 | default: |
| 4751 | goto unhandled; |
| 4752 | } |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4753 | case Ist_Dirty: |
| 4754 | d = st->Ist.Dirty.details; |
| 4755 | for (i = 0; d->args[i]; i++) |
| 4756 | if (isBogusAtom(d->args[i])) |
| 4757 | return True; |
| 4758 | if (d->guard && isBogusAtom(d->guard)) |
| 4759 | return True; |
| 4760 | if (d->mAddr && isBogusAtom(d->mAddr)) |
| 4761 | return True; |
| 4762 | return False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4763 | case Ist_Put: |
| 4764 | return isBogusAtom(st->Ist.Put.data); |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4765 | case Ist_PutI: |
| 4766 | return isBogusAtom(st->Ist.PutI.ix) |
| 4767 | || isBogusAtom(st->Ist.PutI.data); |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4768 | case Ist_Store: |
| 4769 | return isBogusAtom(st->Ist.Store.addr) |
| 4770 | || isBogusAtom(st->Ist.Store.data); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4771 | case Ist_Exit: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4772 | return isBogusAtom(st->Ist.Exit.guard); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 4773 | case Ist_AbiHint: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4774 | return isBogusAtom(st->Ist.AbiHint.base) |
| 4775 | || isBogusAtom(st->Ist.AbiHint.nia); |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 4776 | case Ist_NoOp: |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 4777 | case Ist_IMark: |
sewardj | 72d7513 | 2007-11-09 23:06:35 +0000 | [diff] [blame] | 4778 | case Ist_MBE: |
sewardj | bd598e1 | 2005-01-07 12:10:21 +0000 | [diff] [blame] | 4779 | return False; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4780 | case Ist_CAS: |
| 4781 | cas = st->Ist.CAS.details; |
| 4782 | return isBogusAtom(cas->addr) |
| 4783 | || (cas->expdHi ? isBogusAtom(cas->expdHi) : False) |
| 4784 | || isBogusAtom(cas->expdLo) |
| 4785 | || (cas->dataHi ? isBogusAtom(cas->dataHi) : False) |
| 4786 | || isBogusAtom(cas->dataLo); |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 4787 | case Ist_LLSC: |
| 4788 | return isBogusAtom(st->Ist.LLSC.addr) |
| 4789 | || (st->Ist.LLSC.storedata |
| 4790 | ? isBogusAtom(st->Ist.LLSC.storedata) |
| 4791 | : False); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4792 | default: |
| 4793 | unhandled: |
| 4794 | ppIRStmt(st); |
| 4795 | VG_(tool_panic)("hasBogusLiterals"); |
| 4796 | } |
| 4797 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4798 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4799 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4800 | IRSB* MC_(instrument) ( VgCallbackClosure* closure, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4801 | IRSB* sb_in, |
sewardj | 461df9c | 2006-01-17 02:06:39 +0000 | [diff] [blame] | 4802 | VexGuestLayout* layout, |
| 4803 | VexGuestExtents* vge, |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 4804 | IRType gWordTy, IRType hWordTy ) |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4805 | { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4806 | Bool verboze = 0||False; |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4807 | Bool bogus; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4808 | Int i, j, first_stmt; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4809 | IRStmt* st; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4810 | MCEnv mce; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4811 | IRSB* sb_out; |
sewardj | d54babf | 2005-03-21 00:55:49 +0000 | [diff] [blame] | 4812 | |
| 4813 | if (gWordTy != hWordTy) { |
| 4814 | /* We don't currently support this case. */ |
| 4815 | VG_(tool_panic)("host/guest word size mismatch"); |
| 4816 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4817 | |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 4818 | /* Check we're not completely nuts */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4819 | tl_assert(sizeof(UWord) == sizeof(void*)); |
| 4820 | tl_assert(sizeof(Word) == sizeof(void*)); |
| 4821 | tl_assert(sizeof(Addr) == sizeof(void*)); |
| 4822 | tl_assert(sizeof(ULong) == 8); |
| 4823 | tl_assert(sizeof(Long) == 8); |
| 4824 | tl_assert(sizeof(Addr64) == 8); |
| 4825 | tl_assert(sizeof(UInt) == 4); |
| 4826 | tl_assert(sizeof(Int) == 4); |
| 4827 | |
| 4828 | tl_assert(MC_(clo_mc_level) >= 1 && MC_(clo_mc_level) <= 3); |
sewardj | 6cf40ff | 2005-04-20 22:31:26 +0000 | [diff] [blame] | 4829 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4830 | /* Set up SB */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4831 | sb_out = deepCopyIRSBExceptStmts(sb_in); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4832 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4833 | /* Set up the running environment. Both .sb and .tmpMap are |
| 4834 | modified as we go along. Note that tmps are added to both |
| 4835 | .sb->tyenv and .tmpMap together, so the valid index-set for |
| 4836 | those two arrays should always be identical. */ |
| 4837 | VG_(memset)(&mce, 0, sizeof(mce)); |
| 4838 | mce.sb = sb_out; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4839 | mce.trace = verboze; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4840 | mce.layout = layout; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4841 | mce.hWordTy = hWordTy; |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4842 | mce.bogusLiterals = False; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4843 | |
| 4844 | mce.tmpMap = VG_(newXA)( VG_(malloc), "mc.MC_(instrument).1", VG_(free), |
| 4845 | sizeof(TempMapEnt)); |
| 4846 | for (i = 0; i < sb_in->tyenv->types_used; i++) { |
| 4847 | TempMapEnt ent; |
| 4848 | ent.kind = Orig; |
| 4849 | ent.shadowV = IRTemp_INVALID; |
| 4850 | ent.shadowB = IRTemp_INVALID; |
| 4851 | VG_(addToXA)( mce.tmpMap, &ent ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4852 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4853 | tl_assert( VG_(sizeXA)( mce.tmpMap ) == sb_in->tyenv->types_used ); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4854 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4855 | /* Make a preliminary inspection of the statements, to see if there |
| 4856 | are any dodgy-looking literals. If there are, we generate |
| 4857 | extra-detailed (hence extra-expensive) instrumentation in |
| 4858 | places. Scan the whole bb even if dodgyness is found earlier, |
| 4859 | so that the flatness assertion is applied to all stmts. */ |
| 4860 | |
| 4861 | bogus = False; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4862 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4863 | for (i = 0; i < sb_in->stmts_used; i++) { |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4864 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4865 | st = sb_in->stmts[i]; |
sewardj | 21dc345 | 2005-03-21 00:27:41 +0000 | [diff] [blame] | 4866 | tl_assert(st); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4867 | tl_assert(isFlatIRStmt(st)); |
| 4868 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4869 | if (!bogus) { |
| 4870 | bogus = checkForBogusLiterals(st); |
| 4871 | if (0 && bogus) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4872 | VG_(printf)("bogus: "); |
| 4873 | ppIRStmt(st); |
| 4874 | VG_(printf)("\n"); |
| 4875 | } |
| 4876 | } |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4877 | |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | mce.bogusLiterals = bogus; |
| 4881 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4882 | /* Copy verbatim any IR preamble preceding the first IMark */ |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4883 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4884 | tl_assert(mce.sb == sb_out); |
| 4885 | tl_assert(mce.sb != sb_in); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4886 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4887 | i = 0; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4888 | while (i < sb_in->stmts_used && sb_in->stmts[i]->tag != Ist_IMark) { |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4889 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4890 | st = sb_in->stmts[i]; |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4891 | tl_assert(st); |
| 4892 | tl_assert(isFlatIRStmt(st)); |
| 4893 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4894 | stmt( 'C', &mce, sb_in->stmts[i] ); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4895 | i++; |
| 4896 | } |
| 4897 | |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4898 | /* Nasty problem. IR optimisation of the pre-instrumented IR may |
| 4899 | cause the IR following the preamble to contain references to IR |
| 4900 | temporaries defined in the preamble. Because the preamble isn't |
| 4901 | instrumented, these temporaries don't have any shadows. |
| 4902 | Nevertheless uses of them following the preamble will cause |
| 4903 | memcheck to generate references to their shadows. End effect is |
| 4904 | to cause IR sanity check failures, due to references to |
| 4905 | non-existent shadows. This is only evident for the complex |
| 4906 | preambles used for function wrapping on TOC-afflicted platforms |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 4907 | (ppc64-linux). |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4908 | |
| 4909 | The following loop therefore scans the preamble looking for |
| 4910 | assignments to temporaries. For each one found it creates an |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4911 | assignment to the corresponding (V) shadow temp, marking it as |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4912 | 'defined'. This is the same resulting IR as if the main |
| 4913 | instrumentation loop before had been applied to the statement |
| 4914 | 'tmp = CONSTANT'. |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4915 | |
| 4916 | Similarly, if origin tracking is enabled, we must generate an |
| 4917 | assignment for the corresponding origin (B) shadow, claiming |
| 4918 | no-origin, as appropriate for a defined value. |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4919 | */ |
| 4920 | for (j = 0; j < i; j++) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4921 | if (sb_in->stmts[j]->tag == Ist_WrTmp) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4922 | /* findShadowTmpV checks its arg is an original tmp; |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4923 | no need to assert that here. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4924 | IRTemp tmp_o = sb_in->stmts[j]->Ist.WrTmp.tmp; |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4925 | IRTemp tmp_v = findShadowTmpV(&mce, tmp_o); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4926 | IRType ty_v = typeOfIRTemp(sb_out->tyenv, tmp_v); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4927 | assign( 'V', &mce, tmp_v, definedOfType( ty_v ) ); |
| 4928 | if (MC_(clo_mc_level) == 3) { |
| 4929 | IRTemp tmp_b = findShadowTmpB(&mce, tmp_o); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4930 | tl_assert(typeOfIRTemp(sb_out->tyenv, tmp_b) == Ity_I32); |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4931 | assign( 'B', &mce, tmp_b, mkU32(0)/* UNKNOWN ORIGIN */); |
| 4932 | } |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4933 | if (0) { |
sewardj | afa617b | 2008-07-22 09:59:48 +0000 | [diff] [blame] | 4934 | VG_(printf)("create shadow tmp(s) for preamble tmp [%d] ty ", j); |
| 4935 | ppIRType( ty_v ); |
sewardj | f1962d3 | 2006-10-19 13:22:16 +0000 | [diff] [blame] | 4936 | VG_(printf)("\n"); |
| 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4941 | /* Iterate over the remaining stmts to generate instrumentation. */ |
| 4942 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4943 | tl_assert(sb_in->stmts_used > 0); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4944 | tl_assert(i >= 0); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4945 | tl_assert(i < sb_in->stmts_used); |
| 4946 | tl_assert(sb_in->stmts[i]->tag == Ist_IMark); |
sewardj | a087148 | 2006-10-18 12:41:55 +0000 | [diff] [blame] | 4947 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4948 | for (/* use current i*/; i < sb_in->stmts_used; i++) { |
sewardj | 151b90d | 2005-07-06 19:42:23 +0000 | [diff] [blame] | 4949 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4950 | st = sb_in->stmts[i]; |
| 4951 | first_stmt = sb_out->stmts_used; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4952 | |
| 4953 | if (verboze) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4954 | VG_(printf)("\n"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4955 | ppIRStmt(st); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4956 | VG_(printf)("\n"); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4957 | } |
| 4958 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4959 | if (MC_(clo_mc_level) == 3) { |
| 4960 | /* See comments on case Ist_CAS below. */ |
| 4961 | if (st->tag != Ist_CAS) |
| 4962 | schemeS( &mce, st ); |
| 4963 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4964 | |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 4965 | /* Generate instrumentation code for each stmt ... */ |
| 4966 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4967 | switch (st->tag) { |
| 4968 | |
sewardj | 0b9d74a | 2006-12-24 02:24:11 +0000 | [diff] [blame] | 4969 | case Ist_WrTmp: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 4970 | assign( 'V', &mce, findShadowTmpV(&mce, st->Ist.WrTmp.tmp), |
| 4971 | expr2vbits( &mce, st->Ist.WrTmp.data) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4972 | break; |
| 4973 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4974 | case Ist_Put: |
| 4975 | do_shadow_PUT( &mce, |
| 4976 | st->Ist.Put.offset, |
| 4977 | st->Ist.Put.data, |
| 4978 | NULL /* shadow atom */ ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4979 | break; |
| 4980 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4981 | case Ist_PutI: |
| 4982 | do_shadow_PUTI( &mce, |
| 4983 | st->Ist.PutI.descr, |
| 4984 | st->Ist.PutI.ix, |
| 4985 | st->Ist.PutI.bias, |
| 4986 | st->Ist.PutI.data ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4987 | break; |
| 4988 | |
sewardj | 2e59585 | 2005-06-30 23:33:37 +0000 | [diff] [blame] | 4989 | case Ist_Store: |
| 4990 | do_shadow_Store( &mce, st->Ist.Store.end, |
| 4991 | st->Ist.Store.addr, 0/* addr bias */, |
| 4992 | st->Ist.Store.data, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 4993 | NULL /* shadow data */, |
| 4994 | NULL/*guard*/ ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4995 | break; |
| 4996 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 4997 | case Ist_Exit: |
sewardj | d5204dc | 2004-12-31 01:16:11 +0000 | [diff] [blame] | 4998 | complainIfUndefined( &mce, st->Ist.Exit.guard ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 4999 | break; |
| 5000 | |
sewardj | 29faa50 | 2005-03-16 18:20:21 +0000 | [diff] [blame] | 5001 | case Ist_IMark: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5002 | break; |
| 5003 | |
| 5004 | case Ist_NoOp: |
sewardj | 72d7513 | 2007-11-09 23:06:35 +0000 | [diff] [blame] | 5005 | case Ist_MBE: |
sewardj | bd598e1 | 2005-01-07 12:10:21 +0000 | [diff] [blame] | 5006 | break; |
| 5007 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5008 | case Ist_Dirty: |
| 5009 | do_shadow_Dirty( &mce, st->Ist.Dirty.details ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5010 | break; |
| 5011 | |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5012 | case Ist_AbiHint: |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5013 | do_AbiHint( &mce, st->Ist.AbiHint.base, |
| 5014 | st->Ist.AbiHint.len, |
| 5015 | st->Ist.AbiHint.nia ); |
sewardj | 826ec49 | 2005-05-12 18:05:00 +0000 | [diff] [blame] | 5016 | break; |
| 5017 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5018 | case Ist_CAS: |
| 5019 | do_shadow_CAS( &mce, st->Ist.CAS.details ); |
| 5020 | /* Note, do_shadow_CAS copies the CAS itself to the output |
| 5021 | block, because it needs to add instrumentation both |
| 5022 | before and after it. Hence skip the copy below. Also |
| 5023 | skip the origin-tracking stuff (call to schemeS) above, |
| 5024 | since that's all tangled up with it too; do_shadow_CAS |
| 5025 | does it all. */ |
| 5026 | break; |
| 5027 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5028 | case Ist_LLSC: |
| 5029 | do_shadow_LLSC( &mce, |
| 5030 | st->Ist.LLSC.end, |
| 5031 | st->Ist.LLSC.result, |
| 5032 | st->Ist.LLSC.addr, |
| 5033 | st->Ist.LLSC.storedata ); |
| 5034 | break; |
| 5035 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5036 | default: |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5037 | VG_(printf)("\n"); |
| 5038 | ppIRStmt(st); |
| 5039 | VG_(printf)("\n"); |
| 5040 | VG_(tool_panic)("memcheck: unhandled IRStmt"); |
| 5041 | |
| 5042 | } /* switch (st->tag) */ |
| 5043 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5044 | if (0 && verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5045 | for (j = first_stmt; j < sb_out->stmts_used; j++) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5046 | VG_(printf)(" "); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5047 | ppIRStmt(sb_out->stmts[j]); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5048 | VG_(printf)("\n"); |
| 5049 | } |
| 5050 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5051 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5052 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5053 | /* ... and finally copy the stmt itself to the output. Except, |
| 5054 | skip the copy of IRCASs; see comments on case Ist_CAS |
| 5055 | above. */ |
| 5056 | if (st->tag != Ist_CAS) |
| 5057 | stmt('C', &mce, st); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5058 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5059 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5060 | /* Now we need to complain if the jump target is undefined. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5061 | first_stmt = sb_out->stmts_used; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5062 | |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5063 | if (verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5064 | VG_(printf)("sb_in->next = "); |
| 5065 | ppIRExpr(sb_in->next); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5066 | VG_(printf)("\n\n"); |
| 5067 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5068 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5069 | complainIfUndefined( &mce, sb_in->next ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5070 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5071 | if (0 && verboze) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5072 | for (j = first_stmt; j < sb_out->stmts_used; j++) { |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5073 | VG_(printf)(" "); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5074 | ppIRStmt(sb_out->stmts[j]); |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5075 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5076 | } |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5077 | VG_(printf)("\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5078 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5079 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5080 | /* If this fails, there's been some serious snafu with tmp management, |
| 5081 | that should be investigated. */ |
| 5082 | tl_assert( VG_(sizeXA)( mce.tmpMap ) == mce.sb->tyenv->types_used ); |
| 5083 | VG_(deleteXA)( mce.tmpMap ); |
| 5084 | |
| 5085 | tl_assert(mce.sb == sb_out); |
| 5086 | return sb_out; |
sewardj | 9544807 | 2004-11-22 20:19:51 +0000 | [diff] [blame] | 5087 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5088 | |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 5089 | /*------------------------------------------------------------*/ |
| 5090 | /*--- Post-tree-build final tidying ---*/ |
| 5091 | /*------------------------------------------------------------*/ |
| 5092 | |
| 5093 | /* This exploits the observation that Memcheck often produces |
| 5094 | repeated conditional calls of the form |
| 5095 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5096 | Dirty G MC_(helperc_value_check0/1/4/8_fail)(UInt otag) |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 5097 | |
| 5098 | with the same guard expression G guarding the same helper call. |
| 5099 | The second and subsequent calls are redundant. This usually |
| 5100 | results from instrumentation of guest code containing multiple |
| 5101 | memory references at different constant offsets from the same base |
| 5102 | register. After optimisation of the instrumentation, you get a |
| 5103 | test for the definedness of the base register for each memory |
| 5104 | reference, which is kinda pointless. MC_(final_tidy) therefore |
| 5105 | looks for such repeated calls and removes all but the first. */ |
| 5106 | |
| 5107 | /* A struct for recording which (helper, guard) pairs we have already |
| 5108 | seen. */ |
| 5109 | typedef |
| 5110 | struct { void* entry; IRExpr* guard; } |
| 5111 | Pair; |
| 5112 | |
| 5113 | /* Return True if e1 and e2 definitely denote the same value (used to |
| 5114 | compare guards). Return False if unknown; False is the safe |
| 5115 | answer. Since guest registers and guest memory do not have the |
| 5116 | SSA property we must return False if any Gets or Loads appear in |
| 5117 | the expression. */ |
| 5118 | |
| 5119 | static Bool sameIRValue ( IRExpr* e1, IRExpr* e2 ) |
| 5120 | { |
| 5121 | if (e1->tag != e2->tag) |
| 5122 | return False; |
| 5123 | switch (e1->tag) { |
| 5124 | case Iex_Const: |
| 5125 | return eqIRConst( e1->Iex.Const.con, e2->Iex.Const.con ); |
| 5126 | case Iex_Binop: |
| 5127 | return e1->Iex.Binop.op == e2->Iex.Binop.op |
| 5128 | && sameIRValue(e1->Iex.Binop.arg1, e2->Iex.Binop.arg1) |
| 5129 | && sameIRValue(e1->Iex.Binop.arg2, e2->Iex.Binop.arg2); |
| 5130 | case Iex_Unop: |
| 5131 | return e1->Iex.Unop.op == e2->Iex.Unop.op |
| 5132 | && sameIRValue(e1->Iex.Unop.arg, e2->Iex.Unop.arg); |
| 5133 | case Iex_RdTmp: |
| 5134 | return e1->Iex.RdTmp.tmp == e2->Iex.RdTmp.tmp; |
| 5135 | case Iex_Mux0X: |
| 5136 | return sameIRValue( e1->Iex.Mux0X.cond, e2->Iex.Mux0X.cond ) |
| 5137 | && sameIRValue( e1->Iex.Mux0X.expr0, e2->Iex.Mux0X.expr0 ) |
| 5138 | && sameIRValue( e1->Iex.Mux0X.exprX, e2->Iex.Mux0X.exprX ); |
| 5139 | case Iex_Qop: |
| 5140 | case Iex_Triop: |
| 5141 | case Iex_CCall: |
| 5142 | /* be lazy. Could define equality for these, but they never |
| 5143 | appear to be used. */ |
| 5144 | return False; |
| 5145 | case Iex_Get: |
| 5146 | case Iex_GetI: |
| 5147 | case Iex_Load: |
| 5148 | /* be conservative - these may not give the same value each |
| 5149 | time */ |
| 5150 | return False; |
| 5151 | case Iex_Binder: |
| 5152 | /* should never see this */ |
| 5153 | /* fallthrough */ |
| 5154 | default: |
| 5155 | VG_(printf)("mc_translate.c: sameIRValue: unhandled: "); |
| 5156 | ppIRExpr(e1); |
| 5157 | VG_(tool_panic)("memcheck:sameIRValue"); |
| 5158 | return False; |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | /* See if 'pairs' already has an entry for (entry, guard). Return |
| 5163 | True if so. If not, add an entry. */ |
| 5164 | |
| 5165 | static |
| 5166 | Bool check_or_add ( XArray* /*of Pair*/ pairs, IRExpr* guard, void* entry ) |
| 5167 | { |
| 5168 | Pair p; |
| 5169 | Pair* pp; |
| 5170 | Int i, n = VG_(sizeXA)( pairs ); |
| 5171 | for (i = 0; i < n; i++) { |
| 5172 | pp = VG_(indexXA)( pairs, i ); |
| 5173 | if (pp->entry == entry && sameIRValue(pp->guard, guard)) |
| 5174 | return True; |
| 5175 | } |
| 5176 | p.guard = guard; |
| 5177 | p.entry = entry; |
| 5178 | VG_(addToXA)( pairs, &p ); |
| 5179 | return False; |
| 5180 | } |
| 5181 | |
| 5182 | static Bool is_helperc_value_checkN_fail ( HChar* name ) |
| 5183 | { |
| 5184 | return |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5185 | 0==VG_(strcmp)(name, "MC_(helperc_value_check0_fail_no_o)") |
| 5186 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check1_fail_no_o)") |
| 5187 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check4_fail_no_o)") |
| 5188 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check8_fail_no_o)") |
| 5189 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check0_fail_w_o)") |
| 5190 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check1_fail_w_o)") |
| 5191 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check4_fail_w_o)") |
| 5192 | || 0==VG_(strcmp)(name, "MC_(helperc_value_check8_fail_w_o)"); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | IRSB* MC_(final_tidy) ( IRSB* sb_in ) |
| 5196 | { |
| 5197 | Int i; |
| 5198 | IRStmt* st; |
| 5199 | IRDirty* di; |
| 5200 | IRExpr* guard; |
| 5201 | IRCallee* cee; |
| 5202 | Bool alreadyPresent; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 5203 | XArray* pairs = VG_(newXA)( VG_(malloc), "mc.ft.1", |
| 5204 | VG_(free), sizeof(Pair) ); |
sewardj | 81651dc | 2007-08-28 06:05:20 +0000 | [diff] [blame] | 5205 | /* Scan forwards through the statements. Each time a call to one |
| 5206 | of the relevant helpers is seen, check if we have made a |
| 5207 | previous call to the same helper using the same guard |
| 5208 | expression, and if so, delete the call. */ |
| 5209 | for (i = 0; i < sb_in->stmts_used; i++) { |
| 5210 | st = sb_in->stmts[i]; |
| 5211 | tl_assert(st); |
| 5212 | if (st->tag != Ist_Dirty) |
| 5213 | continue; |
| 5214 | di = st->Ist.Dirty.details; |
| 5215 | guard = di->guard; |
| 5216 | if (!guard) |
| 5217 | continue; |
| 5218 | if (0) { ppIRExpr(guard); VG_(printf)("\n"); } |
| 5219 | cee = di->cee; |
| 5220 | if (!is_helperc_value_checkN_fail( cee->name )) |
| 5221 | continue; |
| 5222 | /* Ok, we have a call to helperc_value_check0/1/4/8_fail with |
| 5223 | guard 'guard'. Check if we have already seen a call to this |
| 5224 | function with the same guard. If so, delete it. If not, |
| 5225 | add it to the set of calls we do know about. */ |
| 5226 | alreadyPresent = check_or_add( pairs, guard, cee->addr ); |
| 5227 | if (alreadyPresent) { |
| 5228 | sb_in->stmts[i] = IRStmt_NoOp(); |
| 5229 | if (0) VG_(printf)("XX\n"); |
| 5230 | } |
| 5231 | } |
| 5232 | VG_(deleteXA)( pairs ); |
| 5233 | return sb_in; |
| 5234 | } |
| 5235 | |
| 5236 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5237 | /*------------------------------------------------------------*/ |
| 5238 | /*--- Origin tracking stuff ---*/ |
| 5239 | /*------------------------------------------------------------*/ |
| 5240 | |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5241 | /* Almost identical to findShadowTmpV. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5242 | static IRTemp findShadowTmpB ( MCEnv* mce, IRTemp orig ) |
| 5243 | { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5244 | TempMapEnt* ent; |
| 5245 | /* VG_(indexXA) range-checks 'orig', hence no need to check |
| 5246 | here. */ |
| 5247 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 5248 | tl_assert(ent->kind == Orig); |
| 5249 | if (ent->shadowB == IRTemp_INVALID) { |
| 5250 | IRTemp tmpB |
| 5251 | = newTemp( mce, Ity_I32, BSh ); |
| 5252 | /* newTemp may cause mce->tmpMap to resize, hence previous results |
| 5253 | from VG_(indexXA) are invalid. */ |
| 5254 | ent = (TempMapEnt*)VG_(indexXA)( mce->tmpMap, (Word)orig ); |
| 5255 | tl_assert(ent->kind == Orig); |
| 5256 | tl_assert(ent->shadowB == IRTemp_INVALID); |
| 5257 | ent->shadowB = tmpB; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5258 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5259 | return ent->shadowB; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5260 | } |
| 5261 | |
| 5262 | static IRAtom* gen_maxU32 ( MCEnv* mce, IRAtom* b1, IRAtom* b2 ) |
| 5263 | { |
| 5264 | return assignNew( 'B', mce, Ity_I32, binop(Iop_Max32U, b1, b2) ); |
| 5265 | } |
| 5266 | |
| 5267 | static IRAtom* gen_load_b ( MCEnv* mce, Int szB, |
| 5268 | IRAtom* baseaddr, Int offset ) |
| 5269 | { |
| 5270 | void* hFun; |
| 5271 | HChar* hName; |
| 5272 | IRTemp bTmp; |
| 5273 | IRDirty* di; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5274 | IRType aTy = typeOfIRExpr( mce->sb->tyenv, baseaddr ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5275 | IROp opAdd = aTy == Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 5276 | IRAtom* ea = baseaddr; |
| 5277 | if (offset != 0) { |
| 5278 | IRAtom* off = aTy == Ity_I32 ? mkU32( offset ) |
| 5279 | : mkU64( (Long)(Int)offset ); |
| 5280 | ea = assignNew( 'B', mce, aTy, binop(opAdd, ea, off)); |
| 5281 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5282 | bTmp = newTemp(mce, mce->hWordTy, BSh); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5283 | |
| 5284 | switch (szB) { |
| 5285 | case 1: hFun = (void*)&MC_(helperc_b_load1); |
| 5286 | hName = "MC_(helperc_b_load1)"; |
| 5287 | break; |
| 5288 | case 2: hFun = (void*)&MC_(helperc_b_load2); |
| 5289 | hName = "MC_(helperc_b_load2)"; |
| 5290 | break; |
| 5291 | case 4: hFun = (void*)&MC_(helperc_b_load4); |
| 5292 | hName = "MC_(helperc_b_load4)"; |
| 5293 | break; |
| 5294 | case 8: hFun = (void*)&MC_(helperc_b_load8); |
| 5295 | hName = "MC_(helperc_b_load8)"; |
| 5296 | break; |
| 5297 | case 16: hFun = (void*)&MC_(helperc_b_load16); |
| 5298 | hName = "MC_(helperc_b_load16)"; |
| 5299 | break; |
| 5300 | default: |
| 5301 | VG_(printf)("mc_translate.c: gen_load_b: unhandled szB == %d\n", szB); |
| 5302 | tl_assert(0); |
| 5303 | } |
| 5304 | di = unsafeIRDirty_1_N( |
| 5305 | bTmp, 1/*regparms*/, hName, VG_(fnptr_to_fnentry)( hFun ), |
| 5306 | mkIRExprVec_1( ea ) |
| 5307 | ); |
| 5308 | /* no need to mess with any annotations. This call accesses |
| 5309 | neither guest state nor guest memory. */ |
| 5310 | stmt( 'B', mce, IRStmt_Dirty(di) ); |
| 5311 | if (mce->hWordTy == Ity_I64) { |
| 5312 | /* 64-bit host */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5313 | IRTemp bTmp32 = newTemp(mce, Ity_I32, BSh); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5314 | assign( 'B', mce, bTmp32, unop(Iop_64to32, mkexpr(bTmp)) ); |
| 5315 | return mkexpr(bTmp32); |
| 5316 | } else { |
| 5317 | /* 32-bit host */ |
| 5318 | return mkexpr(bTmp); |
| 5319 | } |
| 5320 | } |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5321 | |
| 5322 | /* Generate a shadow store. guard :: Ity_I1 controls whether the |
| 5323 | store really happens; NULL means it unconditionally does. */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5324 | static void gen_store_b ( MCEnv* mce, Int szB, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5325 | IRAtom* baseaddr, Int offset, IRAtom* dataB, |
| 5326 | IRAtom* guard ) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5327 | { |
| 5328 | void* hFun; |
| 5329 | HChar* hName; |
| 5330 | IRDirty* di; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5331 | IRType aTy = typeOfIRExpr( mce->sb->tyenv, baseaddr ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5332 | IROp opAdd = aTy == Ity_I32 ? Iop_Add32 : Iop_Add64; |
| 5333 | IRAtom* ea = baseaddr; |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5334 | if (guard) { |
| 5335 | tl_assert(isOriginalAtom(mce, guard)); |
| 5336 | tl_assert(typeOfIRExpr(mce->sb->tyenv, guard) == Ity_I1); |
| 5337 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5338 | if (offset != 0) { |
| 5339 | IRAtom* off = aTy == Ity_I32 ? mkU32( offset ) |
| 5340 | : mkU64( (Long)(Int)offset ); |
| 5341 | ea = assignNew( 'B', mce, aTy, binop(opAdd, ea, off)); |
| 5342 | } |
| 5343 | if (mce->hWordTy == Ity_I64) |
| 5344 | dataB = assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, dataB)); |
| 5345 | |
| 5346 | switch (szB) { |
| 5347 | case 1: hFun = (void*)&MC_(helperc_b_store1); |
| 5348 | hName = "MC_(helperc_b_store1)"; |
| 5349 | break; |
| 5350 | case 2: hFun = (void*)&MC_(helperc_b_store2); |
| 5351 | hName = "MC_(helperc_b_store2)"; |
| 5352 | break; |
| 5353 | case 4: hFun = (void*)&MC_(helperc_b_store4); |
| 5354 | hName = "MC_(helperc_b_store4)"; |
| 5355 | break; |
| 5356 | case 8: hFun = (void*)&MC_(helperc_b_store8); |
| 5357 | hName = "MC_(helperc_b_store8)"; |
| 5358 | break; |
| 5359 | case 16: hFun = (void*)&MC_(helperc_b_store16); |
| 5360 | hName = "MC_(helperc_b_store16)"; |
| 5361 | break; |
| 5362 | default: |
| 5363 | tl_assert(0); |
| 5364 | } |
| 5365 | di = unsafeIRDirty_0_N( 2/*regparms*/, |
| 5366 | hName, VG_(fnptr_to_fnentry)( hFun ), |
| 5367 | mkIRExprVec_2( ea, dataB ) |
| 5368 | ); |
| 5369 | /* no need to mess with any annotations. This call accesses |
| 5370 | neither guest state nor guest memory. */ |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5371 | if (guard) di->guard = guard; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5372 | stmt( 'B', mce, IRStmt_Dirty(di) ); |
| 5373 | } |
| 5374 | |
| 5375 | static IRAtom* narrowTo32 ( MCEnv* mce, IRAtom* e ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5376 | IRType eTy = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5377 | if (eTy == Ity_I64) |
| 5378 | return assignNew( 'B', mce, Ity_I32, unop(Iop_64to32, e) ); |
| 5379 | if (eTy == Ity_I32) |
| 5380 | return e; |
| 5381 | tl_assert(0); |
| 5382 | } |
| 5383 | |
| 5384 | static IRAtom* zWidenFrom32 ( MCEnv* mce, IRType dstTy, IRAtom* e ) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5385 | IRType eTy = typeOfIRExpr(mce->sb->tyenv, e); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5386 | tl_assert(eTy == Ity_I32); |
| 5387 | if (dstTy == Ity_I64) |
| 5388 | return assignNew( 'B', mce, Ity_I64, unop(Iop_32Uto64, e) ); |
| 5389 | tl_assert(0); |
| 5390 | } |
| 5391 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5392 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5393 | static IRAtom* schemeE ( MCEnv* mce, IRExpr* e ) |
| 5394 | { |
| 5395 | tl_assert(MC_(clo_mc_level) == 3); |
| 5396 | |
| 5397 | switch (e->tag) { |
| 5398 | |
| 5399 | case Iex_GetI: { |
| 5400 | IRRegArray* descr_b; |
| 5401 | IRAtom *t1, *t2, *t3, *t4; |
| 5402 | IRRegArray* descr = e->Iex.GetI.descr; |
| 5403 | IRType equivIntTy |
| 5404 | = MC_(get_otrack_reg_array_equiv_int_type)(descr); |
| 5405 | /* If this array is unshadowable for whatever reason, use the |
| 5406 | usual approximation. */ |
| 5407 | if (equivIntTy == Ity_INVALID) |
| 5408 | return mkU32(0); |
| 5409 | tl_assert(sizeofIRType(equivIntTy) >= 4); |
| 5410 | tl_assert(sizeofIRType(equivIntTy) == sizeofIRType(descr->elemTy)); |
| 5411 | descr_b = mkIRRegArray( descr->base + 2*mce->layout->total_sizeB, |
| 5412 | equivIntTy, descr->nElems ); |
| 5413 | /* Do a shadow indexed get of the same size, giving t1. Take |
| 5414 | the bottom 32 bits of it, giving t2. Compute into t3 the |
| 5415 | origin for the index (almost certainly zero, but there's |
| 5416 | no harm in being completely general here, since iropt will |
| 5417 | remove any useless code), and fold it in, giving a final |
| 5418 | value t4. */ |
| 5419 | t1 = assignNew( 'B', mce, equivIntTy, |
| 5420 | IRExpr_GetI( descr_b, e->Iex.GetI.ix, |
| 5421 | e->Iex.GetI.bias )); |
| 5422 | t2 = narrowTo32( mce, t1 ); |
| 5423 | t3 = schemeE( mce, e->Iex.GetI.ix ); |
| 5424 | t4 = gen_maxU32( mce, t2, t3 ); |
| 5425 | return t4; |
| 5426 | } |
| 5427 | case Iex_CCall: { |
| 5428 | Int i; |
| 5429 | IRAtom* here; |
| 5430 | IRExpr** args = e->Iex.CCall.args; |
| 5431 | IRAtom* curr = mkU32(0); |
| 5432 | for (i = 0; args[i]; i++) { |
| 5433 | tl_assert(i < 32); |
| 5434 | tl_assert(isOriginalAtom(mce, args[i])); |
| 5435 | /* Only take notice of this arg if the callee's |
| 5436 | mc-exclusion mask does not say it is to be excluded. */ |
| 5437 | if (e->Iex.CCall.cee->mcx_mask & (1<<i)) { |
| 5438 | /* the arg is to be excluded from definedness checking. |
| 5439 | Do nothing. */ |
| 5440 | if (0) VG_(printf)("excluding %s(%d)\n", |
| 5441 | e->Iex.CCall.cee->name, i); |
| 5442 | } else { |
| 5443 | /* calculate the arg's definedness, and pessimistically |
| 5444 | merge it in. */ |
| 5445 | here = schemeE( mce, args[i] ); |
| 5446 | curr = gen_maxU32( mce, curr, here ); |
| 5447 | } |
| 5448 | } |
| 5449 | return curr; |
| 5450 | } |
| 5451 | case Iex_Load: { |
| 5452 | Int dszB; |
| 5453 | dszB = sizeofIRType(e->Iex.Load.ty); |
| 5454 | /* assert that the B value for the address is already |
| 5455 | available (somewhere) */ |
| 5456 | tl_assert(isIRAtom(e->Iex.Load.addr)); |
| 5457 | tl_assert(mce->hWordTy == Ity_I32 || mce->hWordTy == Ity_I64); |
| 5458 | return gen_load_b( mce, dszB, e->Iex.Load.addr, 0 ); |
| 5459 | } |
| 5460 | case Iex_Mux0X: { |
| 5461 | IRAtom* b1 = schemeE( mce, e->Iex.Mux0X.cond ); |
| 5462 | IRAtom* b2 = schemeE( mce, e->Iex.Mux0X.expr0 ); |
| 5463 | IRAtom* b3 = schemeE( mce, e->Iex.Mux0X.exprX ); |
| 5464 | return gen_maxU32( mce, b1, gen_maxU32( mce, b2, b3 )); |
| 5465 | } |
| 5466 | case Iex_Qop: { |
| 5467 | IRAtom* b1 = schemeE( mce, e->Iex.Qop.arg1 ); |
| 5468 | IRAtom* b2 = schemeE( mce, e->Iex.Qop.arg2 ); |
| 5469 | IRAtom* b3 = schemeE( mce, e->Iex.Qop.arg3 ); |
| 5470 | IRAtom* b4 = schemeE( mce, e->Iex.Qop.arg4 ); |
| 5471 | return gen_maxU32( mce, gen_maxU32( mce, b1, b2 ), |
| 5472 | gen_maxU32( mce, b3, b4 ) ); |
| 5473 | } |
| 5474 | case Iex_Triop: { |
| 5475 | IRAtom* b1 = schemeE( mce, e->Iex.Triop.arg1 ); |
| 5476 | IRAtom* b2 = schemeE( mce, e->Iex.Triop.arg2 ); |
| 5477 | IRAtom* b3 = schemeE( mce, e->Iex.Triop.arg3 ); |
| 5478 | return gen_maxU32( mce, b1, gen_maxU32( mce, b2, b3 ) ); |
| 5479 | } |
| 5480 | case Iex_Binop: { |
sewardj | afed4c5 | 2009-07-12 13:00:17 +0000 | [diff] [blame] | 5481 | switch (e->Iex.Binop.op) { |
| 5482 | case Iop_CasCmpEQ8: case Iop_CasCmpNE8: |
| 5483 | case Iop_CasCmpEQ16: case Iop_CasCmpNE16: |
| 5484 | case Iop_CasCmpEQ32: case Iop_CasCmpNE32: |
| 5485 | case Iop_CasCmpEQ64: case Iop_CasCmpNE64: |
| 5486 | /* Just say these all produce a defined result, |
| 5487 | regardless of their arguments. See |
| 5488 | COMMENT_ON_CasCmpEQ in this file. */ |
| 5489 | return mkU32(0); |
| 5490 | default: { |
| 5491 | IRAtom* b1 = schemeE( mce, e->Iex.Binop.arg1 ); |
| 5492 | IRAtom* b2 = schemeE( mce, e->Iex.Binop.arg2 ); |
| 5493 | return gen_maxU32( mce, b1, b2 ); |
| 5494 | } |
| 5495 | } |
| 5496 | tl_assert(0); |
| 5497 | /*NOTREACHED*/ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5498 | } |
| 5499 | case Iex_Unop: { |
| 5500 | IRAtom* b1 = schemeE( mce, e->Iex.Unop.arg ); |
| 5501 | return b1; |
| 5502 | } |
| 5503 | case Iex_Const: |
| 5504 | return mkU32(0); |
| 5505 | case Iex_RdTmp: |
| 5506 | return mkexpr( findShadowTmpB( mce, e->Iex.RdTmp.tmp )); |
| 5507 | case Iex_Get: { |
| 5508 | Int b_offset = MC_(get_otrack_shadow_offset)( |
| 5509 | e->Iex.Get.offset, |
| 5510 | sizeofIRType(e->Iex.Get.ty) |
| 5511 | ); |
| 5512 | tl_assert(b_offset >= -1 |
| 5513 | && b_offset <= mce->layout->total_sizeB -4); |
| 5514 | if (b_offset >= 0) { |
| 5515 | /* FIXME: this isn't an atom! */ |
| 5516 | return IRExpr_Get( b_offset + 2*mce->layout->total_sizeB, |
| 5517 | Ity_I32 ); |
| 5518 | } |
| 5519 | return mkU32(0); |
| 5520 | } |
| 5521 | default: |
| 5522 | VG_(printf)("mc_translate.c: schemeE: unhandled: "); |
| 5523 | ppIRExpr(e); |
| 5524 | VG_(tool_panic)("memcheck:schemeE"); |
| 5525 | } |
| 5526 | } |
| 5527 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5528 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5529 | static void do_origins_Dirty ( MCEnv* mce, IRDirty* d ) |
| 5530 | { |
| 5531 | // This is a hacked version of do_shadow_Dirty |
njn | 4c245e5 | 2009-03-15 23:25:38 +0000 | [diff] [blame] | 5532 | Int i, n, toDo, gSz, gOff; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5533 | IRAtom *here, *curr; |
| 5534 | IRTemp dst; |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5535 | |
| 5536 | /* First check the guard. */ |
| 5537 | curr = schemeE( mce, d->guard ); |
| 5538 | |
| 5539 | /* Now round up all inputs and maxU32 over them. */ |
| 5540 | |
| 5541 | /* Inputs: unmasked args */ |
| 5542 | for (i = 0; d->args[i]; i++) { |
| 5543 | if (d->cee->mcx_mask & (1<<i)) { |
| 5544 | /* ignore this arg */ |
| 5545 | } else { |
| 5546 | here = schemeE( mce, d->args[i] ); |
| 5547 | curr = gen_maxU32( mce, curr, here ); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | /* Inputs: guest state that we read. */ |
| 5552 | for (i = 0; i < d->nFxState; i++) { |
| 5553 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 5554 | if (d->fxState[i].fx == Ifx_Write) |
| 5555 | continue; |
| 5556 | |
| 5557 | /* Ignore any sections marked as 'always defined'. */ |
| 5558 | if (isAlwaysDefd(mce, d->fxState[i].offset, d->fxState[i].size )) { |
| 5559 | if (0) |
| 5560 | VG_(printf)("memcheck: Dirty gst: ignored off %d, sz %d\n", |
| 5561 | d->fxState[i].offset, d->fxState[i].size ); |
| 5562 | continue; |
| 5563 | } |
| 5564 | |
| 5565 | /* This state element is read or modified. So we need to |
| 5566 | consider it. If larger than 4 bytes, deal with it in 4-byte |
| 5567 | chunks. */ |
| 5568 | gSz = d->fxState[i].size; |
| 5569 | gOff = d->fxState[i].offset; |
| 5570 | tl_assert(gSz > 0); |
| 5571 | while (True) { |
| 5572 | Int b_offset; |
| 5573 | if (gSz == 0) break; |
| 5574 | n = gSz <= 4 ? gSz : 4; |
| 5575 | /* update 'curr' with maxU32 of the state slice |
| 5576 | gOff .. gOff+n-1 */ |
| 5577 | b_offset = MC_(get_otrack_shadow_offset)(gOff, 4); |
| 5578 | if (b_offset != -1) { |
| 5579 | here = assignNew( 'B',mce, |
| 5580 | Ity_I32, |
| 5581 | IRExpr_Get(b_offset + 2*mce->layout->total_sizeB, |
| 5582 | Ity_I32)); |
| 5583 | curr = gen_maxU32( mce, curr, here ); |
| 5584 | } |
| 5585 | gSz -= n; |
| 5586 | gOff += n; |
| 5587 | } |
| 5588 | |
| 5589 | } |
| 5590 | |
| 5591 | /* Inputs: memory */ |
| 5592 | |
| 5593 | if (d->mFx != Ifx_None) { |
| 5594 | /* Because we may do multiple shadow loads/stores from the same |
| 5595 | base address, it's best to do a single test of its |
| 5596 | definedness right now. Post-instrumentation optimisation |
| 5597 | should remove all but this test. */ |
| 5598 | tl_assert(d->mAddr); |
| 5599 | here = schemeE( mce, d->mAddr ); |
| 5600 | curr = gen_maxU32( mce, curr, here ); |
| 5601 | } |
| 5602 | |
| 5603 | /* Deal with memory inputs (reads or modifies) */ |
| 5604 | if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5605 | toDo = d->mSize; |
| 5606 | /* chew off 32-bit chunks. We don't care about the endianness |
| 5607 | since it's all going to be condensed down to a single bit, |
| 5608 | but nevertheless choose an endianness which is hopefully |
| 5609 | native to the platform. */ |
| 5610 | while (toDo >= 4) { |
| 5611 | here = gen_load_b( mce, 4, d->mAddr, d->mSize - toDo ); |
| 5612 | curr = gen_maxU32( mce, curr, here ); |
| 5613 | toDo -= 4; |
| 5614 | } |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 5615 | /* handle possible 16-bit excess */ |
| 5616 | while (toDo >= 2) { |
| 5617 | here = gen_load_b( mce, 2, d->mAddr, d->mSize - toDo ); |
| 5618 | curr = gen_maxU32( mce, curr, here ); |
| 5619 | toDo -= 2; |
| 5620 | } |
| 5621 | tl_assert(toDo == 0); /* also need to handle 1-byte excess */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | /* Whew! So curr is a 32-bit B-value which should give an origin |
| 5625 | of some use if any of the inputs to the helper are undefined. |
| 5626 | Now we need to re-distribute the results to all destinations. */ |
| 5627 | |
| 5628 | /* Outputs: the destination temporary, if there is one. */ |
| 5629 | if (d->tmp != IRTemp_INVALID) { |
| 5630 | dst = findShadowTmpB(mce, d->tmp); |
| 5631 | assign( 'V', mce, dst, curr ); |
| 5632 | } |
| 5633 | |
| 5634 | /* Outputs: guest state that we write or modify. */ |
| 5635 | for (i = 0; i < d->nFxState; i++) { |
| 5636 | tl_assert(d->fxState[i].fx != Ifx_None); |
| 5637 | if (d->fxState[i].fx == Ifx_Read) |
| 5638 | continue; |
| 5639 | |
| 5640 | /* Ignore any sections marked as 'always defined'. */ |
| 5641 | if (isAlwaysDefd(mce, d->fxState[i].offset, d->fxState[i].size )) |
| 5642 | continue; |
| 5643 | |
| 5644 | /* This state element is written or modified. So we need to |
| 5645 | consider it. If larger than 4 bytes, deal with it in 4-byte |
| 5646 | chunks. */ |
| 5647 | gSz = d->fxState[i].size; |
| 5648 | gOff = d->fxState[i].offset; |
| 5649 | tl_assert(gSz > 0); |
| 5650 | while (True) { |
| 5651 | Int b_offset; |
| 5652 | if (gSz == 0) break; |
| 5653 | n = gSz <= 4 ? gSz : 4; |
| 5654 | /* Write 'curr' to the state slice gOff .. gOff+n-1 */ |
| 5655 | b_offset = MC_(get_otrack_shadow_offset)(gOff, 4); |
| 5656 | if (b_offset != -1) { |
| 5657 | stmt( 'B', mce, IRStmt_Put(b_offset + 2*mce->layout->total_sizeB, |
| 5658 | curr )); |
| 5659 | } |
| 5660 | gSz -= n; |
| 5661 | gOff += n; |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | /* Outputs: memory that we write or modify. Same comments about |
| 5666 | endianness as above apply. */ |
| 5667 | if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) { |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5668 | toDo = d->mSize; |
| 5669 | /* chew off 32-bit chunks */ |
| 5670 | while (toDo >= 4) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5671 | gen_store_b( mce, 4, d->mAddr, d->mSize - toDo, curr, |
| 5672 | NULL/*guard*/ ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5673 | toDo -= 4; |
| 5674 | } |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 5675 | /* handle possible 16-bit excess */ |
| 5676 | while (toDo >= 2) { |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5677 | gen_store_b( mce, 2, d->mAddr, d->mSize - toDo, curr, |
| 5678 | NULL/*guard*/ ); |
sewardj | 8c93fcc | 2008-10-30 13:08:31 +0000 | [diff] [blame] | 5679 | toDo -= 2; |
| 5680 | } |
| 5681 | tl_assert(toDo == 0); /* also need to handle 1-byte excess */ |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5682 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5683 | } |
| 5684 | |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5685 | |
| 5686 | static void do_origins_Store ( MCEnv* mce, |
| 5687 | IREndness stEnd, |
| 5688 | IRExpr* stAddr, |
| 5689 | IRExpr* stData ) |
| 5690 | { |
| 5691 | Int dszB; |
| 5692 | IRAtom* dataB; |
| 5693 | /* assert that the B value for the address is already available |
| 5694 | (somewhere), since the call to schemeE will want to see it. |
| 5695 | XXXX how does this actually ensure that?? */ |
| 5696 | tl_assert(isIRAtom(stAddr)); |
| 5697 | tl_assert(isIRAtom(stData)); |
| 5698 | dszB = sizeofIRType( typeOfIRExpr(mce->sb->tyenv, stData ) ); |
| 5699 | dataB = schemeE( mce, stData ); |
| 5700 | gen_store_b( mce, dszB, stAddr, 0/*offset*/, dataB, |
| 5701 | NULL/*guard*/ ); |
| 5702 | } |
| 5703 | |
| 5704 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5705 | static void schemeS ( MCEnv* mce, IRStmt* st ) |
| 5706 | { |
| 5707 | tl_assert(MC_(clo_mc_level) == 3); |
| 5708 | |
| 5709 | switch (st->tag) { |
| 5710 | |
| 5711 | case Ist_AbiHint: |
| 5712 | /* The value-check instrumenter handles this - by arranging |
| 5713 | to pass the address of the next instruction to |
| 5714 | MC_(helperc_MAKE_STACK_UNINIT). This is all that needs to |
| 5715 | happen for origin tracking w.r.t. AbiHints. So there is |
| 5716 | nothing to do here. */ |
| 5717 | break; |
| 5718 | |
| 5719 | case Ist_PutI: { |
| 5720 | IRRegArray* descr_b; |
| 5721 | IRAtom *t1, *t2, *t3, *t4; |
| 5722 | IRRegArray* descr = st->Ist.PutI.descr; |
| 5723 | IRType equivIntTy |
| 5724 | = MC_(get_otrack_reg_array_equiv_int_type)(descr); |
| 5725 | /* If this array is unshadowable for whatever reason, |
| 5726 | generate no code. */ |
| 5727 | if (equivIntTy == Ity_INVALID) |
| 5728 | break; |
| 5729 | tl_assert(sizeofIRType(equivIntTy) >= 4); |
| 5730 | tl_assert(sizeofIRType(equivIntTy) == sizeofIRType(descr->elemTy)); |
| 5731 | descr_b |
| 5732 | = mkIRRegArray( descr->base + 2*mce->layout->total_sizeB, |
| 5733 | equivIntTy, descr->nElems ); |
| 5734 | /* Compute a value to Put - the conjoinment of the origin for |
| 5735 | the data to be Put-ted (obviously) and of the index value |
| 5736 | (not so obviously). */ |
| 5737 | t1 = schemeE( mce, st->Ist.PutI.data ); |
| 5738 | t2 = schemeE( mce, st->Ist.PutI.ix ); |
| 5739 | t3 = gen_maxU32( mce, t1, t2 ); |
| 5740 | t4 = zWidenFrom32( mce, equivIntTy, t3 ); |
| 5741 | stmt( 'B', mce, IRStmt_PutI( descr_b, st->Ist.PutI.ix, |
| 5742 | st->Ist.PutI.bias, t4 )); |
| 5743 | break; |
| 5744 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5745 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5746 | case Ist_Dirty: |
| 5747 | do_origins_Dirty( mce, st->Ist.Dirty.details ); |
| 5748 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5749 | |
| 5750 | case Ist_Store: |
| 5751 | do_origins_Store( mce, st->Ist.Store.end, |
| 5752 | st->Ist.Store.addr, |
| 5753 | st->Ist.Store.data ); |
| 5754 | break; |
| 5755 | |
| 5756 | case Ist_LLSC: { |
| 5757 | /* In short: treat a load-linked like a normal load followed |
| 5758 | by an assignment of the loaded (shadow) data the result |
| 5759 | temporary. Treat a store-conditional like a normal store, |
| 5760 | and mark the result temporary as defined. */ |
| 5761 | if (st->Ist.LLSC.storedata == NULL) { |
| 5762 | /* Load Linked */ |
| 5763 | IRType resTy |
| 5764 | = typeOfIRTemp(mce->sb->tyenv, st->Ist.LLSC.result); |
| 5765 | IRExpr* vanillaLoad |
| 5766 | = IRExpr_Load(st->Ist.LLSC.end, resTy, st->Ist.LLSC.addr); |
| 5767 | tl_assert(resTy == Ity_I64 || resTy == Ity_I32 |
| 5768 | || resTy == Ity_I16 || resTy == Ity_I8); |
| 5769 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.LLSC.result), |
| 5770 | schemeE(mce, vanillaLoad)); |
| 5771 | } else { |
| 5772 | /* Store conditional */ |
| 5773 | do_origins_Store( mce, st->Ist.LLSC.end, |
| 5774 | st->Ist.LLSC.addr, |
| 5775 | st->Ist.LLSC.storedata ); |
| 5776 | /* For the rationale behind this, see comments at the |
| 5777 | place where the V-shadow for .result is constructed, in |
| 5778 | do_shadow_LLSC. In short, we regard .result as |
| 5779 | always-defined. */ |
| 5780 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.LLSC.result), |
| 5781 | mkU32(0) ); |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5782 | } |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5783 | break; |
| 5784 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5785 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5786 | case Ist_Put: { |
| 5787 | Int b_offset |
| 5788 | = MC_(get_otrack_shadow_offset)( |
| 5789 | st->Ist.Put.offset, |
sewardj | 1c0ce7a | 2009-07-01 08:10:49 +0000 | [diff] [blame] | 5790 | sizeofIRType(typeOfIRExpr(mce->sb->tyenv, st->Ist.Put.data)) |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5791 | ); |
| 5792 | if (b_offset >= 0) { |
| 5793 | /* FIXME: this isn't an atom! */ |
| 5794 | stmt( 'B', mce, IRStmt_Put(b_offset + 2*mce->layout->total_sizeB, |
| 5795 | schemeE( mce, st->Ist.Put.data )) ); |
| 5796 | } |
| 5797 | break; |
| 5798 | } |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5799 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5800 | case Ist_WrTmp: |
| 5801 | assign( 'B', mce, findShadowTmpB(mce, st->Ist.WrTmp.tmp), |
| 5802 | schemeE(mce, st->Ist.WrTmp.data) ); |
| 5803 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5804 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5805 | case Ist_MBE: |
| 5806 | case Ist_NoOp: |
| 5807 | case Ist_Exit: |
| 5808 | case Ist_IMark: |
| 5809 | break; |
sewardj | db5907d | 2009-11-26 17:20:21 +0000 | [diff] [blame] | 5810 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 5811 | default: |
| 5812 | VG_(printf)("mc_translate.c: schemeS: unhandled: "); |
| 5813 | ppIRStmt(st); |
| 5814 | VG_(tool_panic)("memcheck:schemeS"); |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5819 | /*--------------------------------------------------------------------*/ |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 5820 | /*--- end mc_translate.c ---*/ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 5821 | /*--------------------------------------------------------------------*/ |