cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 4 | /*--- This file (guest-ppc/toIR.c) is ---*/ |
sewardj | dbcfae7 | 2005-08-02 11:14:04 +0000 | [diff] [blame] | 5 | /*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 6 | /*--- ---*/ |
| 7 | /*--------------------------------------------------------------------*/ |
| 8 | |
| 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 13 | Copyright (C) 2004-2005 OpenWorks LLP. All rights reserved. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 14 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 15 | This library is made available under a dual licensing scheme. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 16 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 17 | If you link LibVEX against other code all of which is itself |
| 18 | licensed under the GNU General Public License, version 2 dated June |
| 19 | 1991 ("GPL v2"), then you may use LibVEX under the terms of the GPL |
| 20 | v2, as appearing in the file LICENSE.GPL. If the file LICENSE.GPL |
| 21 | is missing, you can obtain a copy of the GPL v2 from the Free |
| 22 | Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | 02110-1301, USA. |
| 24 | |
| 25 | For any other uses of LibVEX, you must first obtain a commercial |
| 26 | license from OpenWorks LLP. Please contact info@open-works.co.uk |
| 27 | for information about commercial licensing. |
| 28 | |
| 29 | This software is provided by OpenWorks LLP "as is" and any express |
| 30 | or implied warranties, including, but not limited to, the implied |
| 31 | warranties of merchantability and fitness for a particular purpose |
| 32 | are disclaimed. In no event shall OpenWorks LLP be liable for any |
| 33 | direct, indirect, incidental, special, exemplary, or consequential |
| 34 | damages (including, but not limited to, procurement of substitute |
| 35 | goods or services; loss of use, data, or profits; or business |
| 36 | interruption) however caused and on any theory of liability, |
| 37 | whether in contract, strict liability, or tort (including |
| 38 | negligence or otherwise) arising in any way out of the use of this |
| 39 | software, even if advised of the possibility of such damage. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 40 | |
| 41 | Neither the names of the U.S. Department of Energy nor the |
| 42 | University of California nor the names of its contributors may be |
| 43 | used to endorse or promote products derived from this software |
| 44 | without prior written permission. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 47 | /* TODO 18/Nov/05: |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 48 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 49 | Spot rlwimi cases which are simply left/right shifts and |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 50 | emit Shl32/Shr32 accordingly. |
| 51 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 52 | Altivec |
| 53 | - datastream insns |
| 54 | - lvxl,stvxl: load/store with 'least recently used' hint |
| 55 | - vexptefp, vlogefp |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 56 | |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 57 | Floating Point |
| 58 | - Single precision stores are rounded twice - once by F64toF32, |
| 59 | and then again by the backend for storeBE( F32 ), giving a loss |
| 60 | of precision. |
| 61 | |
| 62 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 63 | LIMITATIONS: |
| 64 | |
| 65 | Various, including: |
| 66 | |
| 67 | - Some invalid forms of lswi and lswx are accepted when they should |
| 68 | not be. |
| 69 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 70 | - Floating Point: |
| 71 | - All exceptions disabled in FPSCR |
| 72 | - condition codes not set in FPSCR |
| 73 | - some error in accuracy |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 74 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 75 | - Altivec floating point: |
| 76 | - vmaddfp, vnmsubfp |
| 77 | Because we're using Java/IEEE mode (FPSCR[NJ]), rather than the |
| 78 | system default of Non-Java mode, we get some small errors |
| 79 | (lowest bit only). |
| 80 | This is because Non-Java mode brutally hacks denormalised results |
| 81 | to zero, whereas we keep maximum accuracy. However, using |
| 82 | Non-Java mode would give us more inaccuracy, as our intermediate |
| 83 | results would then be zeroed, too. |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 84 | */ |
| 85 | |
| 86 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 87 | /* Translates PPC32/64 code to IR. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 88 | |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 89 | /* References |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 90 | |
| 91 | #define PPC32 |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 92 | "PowerPC Microprocessor Family: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 93 | The Programming Environments Manual for 32-Bit Microprocessors" |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 94 | 02/21/2000 |
| 95 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2 |
| 96 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 97 | #define PPC64 |
| 98 | "PowerPC Microprocessor Family: |
| 99 | Programming Environments Manual for 64-Bit Microprocessors" |
| 100 | 06/10/2003 |
| 101 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/F7E732FF811F783187256FDD004D3797 |
| 102 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 103 | #define AV |
| 104 | "PowerPC Microprocessor Family: |
| 105 | AltiVec(TM) Technology Programming Environments Manual" |
| 106 | 07/10/2003 |
| 107 | http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/FBFA164F824370F987256D6A006F424D |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 108 | */ |
| 109 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 110 | #include "libvex_basictypes.h" |
| 111 | #include "libvex_ir.h" |
| 112 | #include "libvex.h" |
cerion | 1515db9 | 2005-01-25 17:21:23 +0000 | [diff] [blame] | 113 | #include "libvex_guest_ppc32.h" |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 114 | #include "libvex_guest_ppc64.h" |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 115 | |
| 116 | #include "main/vex_util.h" |
| 117 | #include "main/vex_globals.h" |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 118 | #include "guest-generic/bb_to_IR.h" |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 119 | #include "guest-ppc/gdefs.h" |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 120 | |
| 121 | |
| 122 | /*------------------------------------------------------------*/ |
| 123 | /*--- Globals ---*/ |
| 124 | /*------------------------------------------------------------*/ |
| 125 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 126 | /* These are set at the start of the translation of an insn, right |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 127 | down in disInstr_PPC, so that we don't have to pass them around |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 128 | endlessly. They are all constant during the translation of any |
| 129 | given insn. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 130 | |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 131 | /* We need to know this to do sub-register accesses correctly. */ |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 132 | static Bool host_is_bigendian; |
| 133 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 134 | /* Pointer to the guest code area. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 135 | static UChar* guest_code; |
| 136 | |
| 137 | /* The guest address corresponding to guest_code[0]. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 138 | static Addr64 guest_CIA_bbstart; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 139 | |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 140 | /* The guest address for the instruction currently being |
| 141 | translated. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 142 | static Addr64 guest_CIA_curr_instr; |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 143 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 144 | /* The IRBB* into which we're generating code. */ |
| 145 | static IRBB* irbb; |
| 146 | |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 147 | /* Is our guest binary 32 or 64bit? Set at each call to |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 148 | disInstr_PPC below. */ |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 149 | static Bool mode64 = False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 150 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 151 | |
| 152 | /*------------------------------------------------------------*/ |
| 153 | /*--- Debugging output ---*/ |
| 154 | /*------------------------------------------------------------*/ |
| 155 | |
| 156 | #define DIP(format, args...) \ |
| 157 | if (vex_traceflags & VEX_TRACE_FE) \ |
| 158 | vex_printf(format, ## args) |
| 159 | |
| 160 | #define DIS(buf, format, args...) \ |
| 161 | if (vex_traceflags & VEX_TRACE_FE) \ |
| 162 | vex_sprintf(buf, format, ## args) |
| 163 | |
| 164 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 165 | /*------------------------------------------------------------*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 166 | /*--- Offsets of various parts of the ppc32/64 guest state ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 167 | /*------------------------------------------------------------*/ |
| 168 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 169 | #define offsetofPPCGuestState(_x) \ |
| 170 | (mode64 ? offsetof(VexGuestPPC64State, _x) : \ |
| 171 | offsetof(VexGuestPPC32State, _x)) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 172 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 173 | #define OFFB_CIA offsetofPPCGuestState(guest_CIA) |
| 174 | #define OFFB_LR offsetofPPCGuestState(guest_LR) |
| 175 | #define OFFB_CTR offsetofPPCGuestState(guest_CTR) |
| 176 | #define OFFB_XER_SO offsetofPPCGuestState(guest_XER_SO) |
| 177 | #define OFFB_XER_OV offsetofPPCGuestState(guest_XER_OV) |
| 178 | #define OFFB_XER_CA offsetofPPCGuestState(guest_XER_CA) |
| 179 | #define OFFB_XER_BC offsetofPPCGuestState(guest_XER_BC) |
| 180 | #define OFFB_FPROUND offsetofPPCGuestState(guest_FPROUND) |
| 181 | #define OFFB_VRSAVE offsetofPPCGuestState(guest_VRSAVE) |
| 182 | #define OFFB_VSCR offsetofPPCGuestState(guest_VSCR) |
| 183 | #define OFFB_EMWARN offsetofPPCGuestState(guest_EMWARN) |
| 184 | #define OFFB_TISTART offsetofPPCGuestState(guest_TISTART) |
| 185 | #define OFFB_TILEN offsetofPPCGuestState(guest_TILEN) |
| 186 | #define OFFB_RESVN offsetofPPCGuestState(guest_RESVN) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 187 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 188 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 189 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 190 | /*------------------------------------------------------------*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 191 | /*--- Extract instruction fields --- */ |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 192 | /*------------------------------------------------------------*/ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 193 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 194 | /* Extract field from insn, given idx (zero = lsb) and field length */ |
| 195 | #define IFIELD( insn, idx, len ) ((insn >> idx) & ((1<<len)-1)) |
| 196 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 197 | /* Extract primary opcode, instr[31:26] */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 198 | static UChar ifieldOPC( UInt instr ) { |
| 199 | return toUChar( IFIELD( instr, 26, 6 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 200 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 201 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 202 | /* Extract 10-bit secondary opcode, instr[10:1] */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 203 | static UInt ifieldOPClo10 ( UInt instr) { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 204 | return IFIELD( instr, 1, 10 ); |
| 205 | } |
| 206 | |
| 207 | /* Extract 9-bit secondary opcode, instr[9:1] */ |
| 208 | static UInt ifieldOPClo9 ( UInt instr) { |
| 209 | return IFIELD( instr, 1, 9 ); |
| 210 | } |
| 211 | |
| 212 | /* Extract 5-bit secondary opcode, instr[5:1] */ |
| 213 | static UInt ifieldOPClo5 ( UInt instr) { |
| 214 | return IFIELD( instr, 1, 5 ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 215 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 216 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 217 | /* Extract RD (destination register) field, instr[25:21] */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 218 | static UChar ifieldRegDS( UInt instr ) { |
| 219 | return toUChar( IFIELD( instr, 21, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 220 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 221 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 222 | /* Extract RA (1st source register) field, instr[20:16] */ |
| 223 | static UChar ifieldRegA ( UInt instr ) { |
| 224 | return toUChar( IFIELD( instr, 16, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 225 | } |
| 226 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 227 | /* Extract RB (2nd source register) field, instr[15:11] */ |
| 228 | static UChar ifieldRegB ( UInt instr ) { |
| 229 | return toUChar( IFIELD( instr, 11, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 230 | } |
| 231 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 232 | /* Extract RC (3rd source register) field, instr[10:6] */ |
| 233 | static UChar ifieldRegC ( UInt instr ) { |
| 234 | return toUChar( IFIELD( instr, 6, 5 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 235 | } |
| 236 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 237 | /* Extract 2nd lowest bit, instr[1] */ |
| 238 | static UChar ifieldBIT10 ( UInt instr ) { |
| 239 | return toUChar( IFIELD( instr, 10, 1 ) ); |
| 240 | } |
| 241 | |
| 242 | /* Extract 2nd lowest bit, instr[1] */ |
| 243 | static UChar ifieldBIT1 ( UInt instr ) { |
| 244 | return toUChar( IFIELD( instr, 1, 1 ) ); |
| 245 | } |
| 246 | |
| 247 | /* Extract lowest bit, instr[0] */ |
| 248 | static UChar ifieldBIT0 ( UInt instr ) { |
| 249 | return toUChar( instr & 0x1 ); |
| 250 | } |
| 251 | |
| 252 | /* Extract unsigned bottom half, instr[15:0] */ |
| 253 | static UInt ifieldUIMM16 ( UInt instr ) { |
| 254 | return instr & 0xFFFF; |
| 255 | } |
| 256 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 257 | /* Extract unsigned bottom 26 bits, instr[25:0] */ |
| 258 | static UInt ifieldUIMM26 ( UInt instr ) { |
| 259 | return instr & 0x3FFFFFF; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 260 | } |
| 261 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 262 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 263 | /*------------------------------------------------------------*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 264 | /*--- Guest-state identifiers ---*/ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 265 | /*------------------------------------------------------------*/ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 266 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 267 | typedef enum { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 268 | PPC_GST_CIA, // Current Instruction Address |
| 269 | PPC_GST_LR, // Link Register |
| 270 | PPC_GST_CTR, // Count Register |
| 271 | PPC_GST_XER, // Overflow, carry flags, byte count |
| 272 | PPC_GST_CR, // Condition Register |
| 273 | PPC_GST_FPSCR, // Floating Point Status/Control Register |
| 274 | PPC_GST_VRSAVE, // Vector Save/Restore Register |
| 275 | PPC_GST_VSCR, // Vector Status and Control Register |
| 276 | PPC_GST_EMWARN, // Emulation warnings |
| 277 | PPC_GST_TISTART,// For icbi: start of area to invalidate |
| 278 | PPC_GST_TILEN, // For icbi: length of area to invalidate |
| 279 | PPC_GST_RESVN, // For lwarx/stwcx. |
| 280 | PPC_GST_MAX |
| 281 | } PPC_GST; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 282 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 283 | #define MASK_FPSCR_RN 0x3 |
| 284 | #define MASK_VSCR_VALID 0x00010001 |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 285 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 286 | |
| 287 | /*------------------------------------------------------------*/ |
| 288 | /*--- FP Helpers ---*/ |
| 289 | /*------------------------------------------------------------*/ |
| 290 | |
sewardj | 2ead522 | 2005-11-23 03:53:45 +0000 | [diff] [blame] | 291 | /* Produce the 32-bit pattern corresponding to the supplied |
| 292 | float. */ |
| 293 | static UInt float_to_bits ( Float f ) |
| 294 | { |
| 295 | union { UInt i; Float f; } u; |
| 296 | vassert(4 == sizeof(UInt)); |
| 297 | vassert(4 == sizeof(Float)); |
| 298 | vassert(4 == sizeof(u)); |
| 299 | u.f = f; |
| 300 | return u.i; |
| 301 | } |
| 302 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 303 | |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 304 | /*------------------------------------------------------------*/ |
| 305 | /*--- Misc Helpers ---*/ |
| 306 | /*------------------------------------------------------------*/ |
| 307 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 308 | /* Generate mask with 1's from 'begin' through 'end', |
| 309 | wrapping if begin > end. |
| 310 | begin->end works from right to left, 0=lsb |
| 311 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 312 | static UInt MASK32( UInt begin, UInt end ) |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 313 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 314 | vassert(begin < 32); |
| 315 | vassert(end < 32); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 316 | UInt m1 = ((UInt)(-1)) << begin; |
| 317 | UInt m2 = ((UInt)(-1)) << (end + 1); |
| 318 | UInt mask = m1 ^ m2; |
| 319 | if (begin > end) mask = ~mask; // wrap mask |
| 320 | return mask; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 321 | } |
| 322 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 323 | /* ditto for 64bit mask */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 324 | static ULong MASK64( UInt begin, UInt end ) |
| 325 | { |
| 326 | vassert(begin < 64); |
| 327 | vassert(end < 64); |
| 328 | ULong m1 = ((ULong)(-1)) << begin; |
| 329 | ULong m2 = ((ULong)(-1)) << (end + 1); |
| 330 | ULong mask = m1 ^ m2; |
| 331 | if (begin > end) mask = ~mask; // wrap mask |
| 332 | return mask; |
| 333 | } |
| 334 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 335 | static Addr64 nextInsnAddr( void ) |
| 336 | { |
| 337 | return guest_CIA_curr_instr + 4; |
| 338 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 339 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 340 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 341 | /*------------------------------------------------------------*/ |
| 342 | /*--- Helper bits and pieces for deconstructing the ---*/ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 343 | /*--- ppc32/64 insn stream. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 344 | /*------------------------------------------------------------*/ |
| 345 | |
| 346 | /* Add a statement to the list held by "irbb". */ |
| 347 | static void stmt ( IRStmt* st ) |
| 348 | { |
| 349 | addStmtToIRBB( irbb, st ); |
| 350 | } |
| 351 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 352 | /* Generate a new temporary of the given type. */ |
| 353 | static IRTemp newTemp ( IRType ty ) |
| 354 | { |
sewardj | 496a58d | 2005-03-20 18:44:44 +0000 | [diff] [blame] | 355 | vassert(isPlausibleIRType(ty)); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 356 | return newIRTemp( irbb->tyenv, ty ); |
| 357 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 358 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 359 | /* Various simple conversions */ |
| 360 | |
| 361 | static UChar extend_s_5to8 ( UChar x ) |
| 362 | { |
| 363 | return toUChar((((Int)x) << 27) >> 27); |
| 364 | } |
| 365 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 366 | static UInt extend_s_8to32( UChar x ) |
| 367 | { |
| 368 | return (UInt)((((Int)x) << 24) >> 24); |
| 369 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 370 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 371 | static UInt extend_s_16to32 ( UInt x ) |
| 372 | { |
| 373 | return (UInt)((((Int)x) << 16) >> 16); |
| 374 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 375 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 376 | static ULong extend_s_16to64 ( UInt x ) |
| 377 | { |
| 378 | return (ULong)((((Long)x) << 48) >> 48); |
| 379 | } |
| 380 | |
| 381 | static ULong extend_s_26to64 ( UInt x ) |
| 382 | { |
| 383 | return (ULong)((((Long)x) << 38) >> 38); |
| 384 | } |
| 385 | |
| 386 | static ULong extend_s_32to64 ( UInt x ) |
| 387 | { |
| 388 | return (ULong)((((Long)x) << 32) >> 32); |
| 389 | } |
| 390 | |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 391 | /* Do a big-endian load of a 32-bit word, regardless of the endianness |
| 392 | of the underlying host. */ |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 393 | static UInt getUIntBigendianly ( UChar* p ) |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 394 | { |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 395 | UInt w = 0; |
sewardj | 684aa95 | 2005-01-30 12:52:14 +0000 | [diff] [blame] | 396 | w = (w << 8) | p[0]; |
| 397 | w = (w << 8) | p[1]; |
| 398 | w = (w << 8) | p[2]; |
| 399 | w = (w << 8) | p[3]; |
| 400 | return w; |
| 401 | } |
| 402 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 403 | |
| 404 | /*------------------------------------------------------------*/ |
| 405 | /*--- Helpers for constructing IR. ---*/ |
| 406 | /*------------------------------------------------------------*/ |
| 407 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 408 | static void assign ( IRTemp dst, IRExpr* e ) |
| 409 | { |
| 410 | stmt( IRStmt_Tmp(dst, e) ); |
| 411 | } |
| 412 | |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 413 | static void storeBE ( IRExpr* addr, IRExpr* data ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 414 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 415 | vassert(typeOfIRExpr(irbb->tyenv, addr) == Ity_I32 || |
| 416 | typeOfIRExpr(irbb->tyenv, addr) == Ity_I64); |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 417 | stmt( IRStmt_Store(Iend_BE,addr,data) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static IRExpr* unop ( IROp op, IRExpr* a ) |
| 421 | { |
| 422 | return IRExpr_Unop(op, a); |
| 423 | } |
| 424 | |
| 425 | static IRExpr* binop ( IROp op, IRExpr* a1, IRExpr* a2 ) |
| 426 | { |
| 427 | return IRExpr_Binop(op, a1, a2); |
| 428 | } |
| 429 | |
| 430 | static IRExpr* mkexpr ( IRTemp tmp ) |
| 431 | { |
| 432 | return IRExpr_Tmp(tmp); |
| 433 | } |
| 434 | |
sewardj | 7f08078 | 2005-07-27 00:22:15 +0000 | [diff] [blame] | 435 | //uu static IRExpr* mkU1 ( UInt i ) |
| 436 | //uu { |
| 437 | //uu vassert(i < 2); |
| 438 | //uu return IRExpr_Const(IRConst_U1( toBool(i) )); |
| 439 | //uu } |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 440 | |
sewardj | 684c037 | 2005-02-07 02:33:58 +0000 | [diff] [blame] | 441 | static IRExpr* mkU8 ( UChar i ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 442 | { |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 443 | return IRExpr_Const(IRConst_U8(i)); |
| 444 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 445 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 446 | static IRExpr* mkU16 ( UInt i ) |
| 447 | { |
| 448 | return IRExpr_Const(IRConst_U16(i)); |
| 449 | } |
| 450 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 451 | static IRExpr* mkU32 ( UInt i ) |
| 452 | { |
| 453 | return IRExpr_Const(IRConst_U32(i)); |
| 454 | } |
| 455 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 456 | static IRExpr* mkU64 ( ULong i ) |
| 457 | { |
| 458 | return IRExpr_Const(IRConst_U64(i)); |
| 459 | } |
| 460 | |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 461 | static IRExpr* loadBE ( IRType ty, IRExpr* data ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 462 | { |
sewardj | af1ceca | 2005-06-30 23:31:27 +0000 | [diff] [blame] | 463 | return IRExpr_Load(Iend_BE,ty,data); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 464 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 465 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 466 | static IRExpr* mkOR1 ( IRExpr* arg1, IRExpr* arg2 ) |
| 467 | { |
| 468 | vassert(typeOfIRExpr(irbb->tyenv, arg1) == Ity_I1); |
| 469 | vassert(typeOfIRExpr(irbb->tyenv, arg2) == Ity_I1); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 470 | return unop(Iop_32to1, binop(Iop_Or32, unop(Iop_1Uto32, arg1), |
| 471 | unop(Iop_1Uto32, arg2))); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static IRExpr* mkAND1 ( IRExpr* arg1, IRExpr* arg2 ) |
| 475 | { |
| 476 | vassert(typeOfIRExpr(irbb->tyenv, arg1) == Ity_I1); |
| 477 | vassert(typeOfIRExpr(irbb->tyenv, arg2) == Ity_I1); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 478 | return unop(Iop_32to1, binop(Iop_And32, unop(Iop_1Uto32, arg1), |
| 479 | unop(Iop_1Uto32, arg2))); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 480 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 481 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 482 | /* expand V128_8Ux16 to 2x V128_16Ux8's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 483 | static void expand8Ux16( IRExpr* vIn, |
| 484 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 485 | { |
| 486 | IRTemp ones8x16 = newTemp(Ity_V128); |
| 487 | |
| 488 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 489 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 490 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 491 | *vEvn = newTemp(Ity_V128); |
| 492 | *vOdd = newTemp(Ity_V128); |
| 493 | |
| 494 | assign( ones8x16, unop(Iop_Dup8x16, mkU8(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 495 | assign( *vOdd, binop(Iop_MullEven8Ux16, mkexpr(ones8x16), vIn) ); |
| 496 | assign( *vEvn, binop(Iop_MullEven8Ux16, mkexpr(ones8x16), |
| 497 | binop(Iop_ShrV128, vIn, mkU8(8))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* expand V128_8Sx16 to 2x V128_16Sx8's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 501 | static void expand8Sx16( IRExpr* vIn, |
| 502 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 503 | { |
| 504 | IRTemp ones8x16 = newTemp(Ity_V128); |
| 505 | |
| 506 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 507 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 508 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 509 | *vEvn = newTemp(Ity_V128); |
| 510 | *vOdd = newTemp(Ity_V128); |
| 511 | |
| 512 | assign( ones8x16, unop(Iop_Dup8x16, mkU8(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 513 | assign( *vOdd, binop(Iop_MullEven8Sx16, mkexpr(ones8x16), vIn) ); |
| 514 | assign( *vEvn, binop(Iop_MullEven8Sx16, mkexpr(ones8x16), |
| 515 | binop(Iop_ShrV128, vIn, mkU8(8))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* expand V128_16Uto8 to 2x V128_32Ux4's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 519 | static void expand16Ux8( IRExpr* vIn, |
| 520 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 521 | { |
| 522 | IRTemp ones16x8 = newTemp(Ity_V128); |
| 523 | |
| 524 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 525 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 526 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 527 | *vEvn = newTemp(Ity_V128); |
| 528 | *vOdd = newTemp(Ity_V128); |
| 529 | |
| 530 | assign( ones16x8, unop(Iop_Dup16x8, mkU16(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 531 | assign( *vOdd, binop(Iop_MullEven16Ux8, mkexpr(ones16x8), vIn) ); |
| 532 | assign( *vEvn, binop(Iop_MullEven16Ux8, mkexpr(ones16x8), |
| 533 | binop(Iop_ShrV128, vIn, mkU8(16))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | /* expand V128_16Sto8 to 2x V128_32Sx4's */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 537 | static void expand16Sx8( IRExpr* vIn, |
| 538 | /*OUTs*/ IRTemp* vEvn, IRTemp* vOdd ) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 539 | { |
| 540 | IRTemp ones16x8 = newTemp(Ity_V128); |
| 541 | |
| 542 | vassert(typeOfIRExpr(irbb->tyenv, vIn) == Ity_V128); |
| 543 | vassert(vEvn && *vEvn == IRTemp_INVALID); |
| 544 | vassert(vOdd && *vOdd == IRTemp_INVALID); |
| 545 | *vEvn = newTemp(Ity_V128); |
| 546 | *vOdd = newTemp(Ity_V128); |
| 547 | |
| 548 | assign( ones16x8, unop(Iop_Dup16x8, mkU16(0x1)) ); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 549 | assign( *vOdd, binop(Iop_MullEven16Sx8, mkexpr(ones16x8), vIn) ); |
| 550 | assign( *vEvn, binop(Iop_MullEven16Sx8, mkexpr(ones16x8), |
| 551 | binop(Iop_ShrV128, vIn, mkU8(16))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* break V128 to 4xI32's, then sign-extend to I64's */ |
| 555 | static void breakV128to4x64S( IRExpr* t128, |
| 556 | /*OUTs*/ |
| 557 | IRTemp* t3, IRTemp* t2, |
| 558 | IRTemp* t1, IRTemp* t0 ) |
| 559 | { |
| 560 | IRTemp hi64 = newTemp(Ity_I64); |
| 561 | IRTemp lo64 = newTemp(Ity_I64); |
| 562 | |
| 563 | vassert(typeOfIRExpr(irbb->tyenv, t128) == Ity_V128); |
| 564 | vassert(t0 && *t0 == IRTemp_INVALID); |
| 565 | vassert(t1 && *t1 == IRTemp_INVALID); |
| 566 | vassert(t2 && *t2 == IRTemp_INVALID); |
| 567 | vassert(t3 && *t3 == IRTemp_INVALID); |
| 568 | *t0 = newTemp(Ity_I64); |
| 569 | *t1 = newTemp(Ity_I64); |
| 570 | *t2 = newTemp(Ity_I64); |
| 571 | *t3 = newTemp(Ity_I64); |
| 572 | |
| 573 | assign( hi64, unop(Iop_V128HIto64, t128) ); |
| 574 | assign( lo64, unop(Iop_V128to64, t128) ); |
| 575 | assign( *t3, unop(Iop_32Sto64, unop(Iop_64HIto32, mkexpr(hi64))) ); |
| 576 | assign( *t2, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(hi64))) ); |
| 577 | assign( *t1, unop(Iop_32Sto64, unop(Iop_64HIto32, mkexpr(lo64))) ); |
| 578 | assign( *t0, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(lo64))) ); |
| 579 | } |
| 580 | |
| 581 | /* break V128 to 4xI32's, then zero-extend to I64's */ |
| 582 | static void breakV128to4x64U ( IRExpr* t128, |
| 583 | /*OUTs*/ |
| 584 | IRTemp* t3, IRTemp* t2, |
| 585 | IRTemp* t1, IRTemp* t0 ) |
| 586 | { |
| 587 | IRTemp hi64 = newTemp(Ity_I64); |
| 588 | IRTemp lo64 = newTemp(Ity_I64); |
| 589 | |
| 590 | vassert(typeOfIRExpr(irbb->tyenv, t128) == Ity_V128); |
| 591 | vassert(t0 && *t0 == IRTemp_INVALID); |
| 592 | vassert(t1 && *t1 == IRTemp_INVALID); |
| 593 | vassert(t2 && *t2 == IRTemp_INVALID); |
| 594 | vassert(t3 && *t3 == IRTemp_INVALID); |
| 595 | *t0 = newTemp(Ity_I64); |
| 596 | *t1 = newTemp(Ity_I64); |
| 597 | *t2 = newTemp(Ity_I64); |
| 598 | *t3 = newTemp(Ity_I64); |
| 599 | |
| 600 | assign( hi64, unop(Iop_V128HIto64, t128) ); |
| 601 | assign( lo64, unop(Iop_V128to64, t128) ); |
| 602 | assign( *t3, unop(Iop_32Uto64, unop(Iop_64HIto32, mkexpr(hi64))) ); |
| 603 | assign( *t2, unop(Iop_32Uto64, unop(Iop_64to32, mkexpr(hi64))) ); |
| 604 | assign( *t1, unop(Iop_32Uto64, unop(Iop_64HIto32, mkexpr(lo64))) ); |
| 605 | assign( *t0, unop(Iop_32Uto64, unop(Iop_64to32, mkexpr(lo64))) ); |
| 606 | } |
| 607 | |
| 608 | /* Signed saturating narrow 64S to 32 */ |
| 609 | static IRExpr* mkQNarrow64Sto32 ( IRExpr* t64 ) |
| 610 | { |
| 611 | IRTemp hi32 = newTemp(Ity_I32); |
| 612 | IRTemp lo32 = newTemp(Ity_I32); |
| 613 | |
| 614 | vassert(typeOfIRExpr(irbb->tyenv, t64) == Ity_I64); |
| 615 | |
| 616 | assign( hi32, unop(Iop_64HIto32, t64)); |
| 617 | assign( lo32, unop(Iop_64to32, t64)); |
| 618 | |
| 619 | return IRExpr_Mux0X( |
| 620 | /* if (hi32 == (lo32 >>s 31)) */ |
| 621 | unop(Iop_1Uto8, |
| 622 | binop(Iop_CmpEQ32, mkexpr(hi32), |
| 623 | binop( Iop_Sar32, mkexpr(lo32), mkU8(31)))), |
| 624 | /* else: sign dep saturate: 1->0x80000000, 0->0x7FFFFFFF */ |
| 625 | binop(Iop_Add32, mkU32(0x7FFFFFFF), |
| 626 | binop(Iop_Shr32, mkexpr(hi32), mkU8(31))), |
| 627 | /* then: within signed-32 range: lo half good enough */ |
| 628 | mkexpr(lo32) ); |
| 629 | } |
| 630 | |
| 631 | /* Unsigned saturating narrow 64S to 32 */ |
| 632 | static IRExpr* mkQNarrow64Uto32 ( IRExpr* t64 ) |
| 633 | { |
| 634 | IRTemp hi32 = newTemp(Ity_I32); |
| 635 | IRTemp lo32 = newTemp(Ity_I32); |
| 636 | |
| 637 | vassert(typeOfIRExpr(irbb->tyenv, t64) == Ity_I64); |
| 638 | |
| 639 | assign( hi32, unop(Iop_64HIto32, t64)); |
| 640 | assign( lo32, unop(Iop_64to32, t64)); |
| 641 | |
| 642 | return IRExpr_Mux0X( |
| 643 | /* if (top 32 bits of t64 are 0) */ |
| 644 | unop(Iop_1Uto8, binop(Iop_CmpEQ32, mkexpr(hi32), mkU32(0))), |
| 645 | /* else: positive saturate -> 0xFFFFFFFF */ |
| 646 | mkU32(0xFFFFFFFF), |
| 647 | /* then: within unsigned-32 range: lo half good enough */ |
| 648 | mkexpr(lo32) ); |
| 649 | } |
| 650 | |
| 651 | /* Signed saturate narrow 64->32, combining to V128 */ |
| 652 | static IRExpr* mkV128from4x64S ( IRExpr* t3, IRExpr* t2, |
| 653 | IRExpr* t1, IRExpr* t0 ) |
| 654 | { |
| 655 | vassert(typeOfIRExpr(irbb->tyenv, t3) == Ity_I64); |
| 656 | vassert(typeOfIRExpr(irbb->tyenv, t2) == Ity_I64); |
| 657 | vassert(typeOfIRExpr(irbb->tyenv, t1) == Ity_I64); |
| 658 | vassert(typeOfIRExpr(irbb->tyenv, t0) == Ity_I64); |
| 659 | return binop(Iop_64HLtoV128, |
| 660 | binop(Iop_32HLto64, |
| 661 | mkQNarrow64Sto32( t3 ), |
| 662 | mkQNarrow64Sto32( t2 )), |
| 663 | binop(Iop_32HLto64, |
| 664 | mkQNarrow64Sto32( t1 ), |
| 665 | mkQNarrow64Sto32( t0 ))); |
| 666 | } |
| 667 | |
| 668 | /* Unsigned saturate narrow 64->32, combining to V128 */ |
| 669 | static IRExpr* mkV128from4x64U ( IRExpr* t3, IRExpr* t2, |
| 670 | IRExpr* t1, IRExpr* t0 ) |
| 671 | { |
| 672 | vassert(typeOfIRExpr(irbb->tyenv, t3) == Ity_I64); |
| 673 | vassert(typeOfIRExpr(irbb->tyenv, t2) == Ity_I64); |
| 674 | vassert(typeOfIRExpr(irbb->tyenv, t1) == Ity_I64); |
| 675 | vassert(typeOfIRExpr(irbb->tyenv, t0) == Ity_I64); |
| 676 | return binop(Iop_64HLtoV128, |
| 677 | binop(Iop_32HLto64, |
| 678 | mkQNarrow64Uto32( t3 ), |
| 679 | mkQNarrow64Uto32( t2 )), |
| 680 | binop(Iop_32HLto64, |
| 681 | mkQNarrow64Uto32( t1 ), |
| 682 | mkQNarrow64Uto32( t0 ))); |
| 683 | } |
| 684 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 685 | /* Simulate irops Iop_MullOdd*, since we don't have them */ |
| 686 | #define MK_Iop_MullOdd8Ux16( expr_vA, expr_vB ) \ |
| 687 | binop(Iop_MullEven8Ux16, \ |
| 688 | binop(Iop_ShrV128, expr_vA, mkU8(8)), \ |
| 689 | binop(Iop_ShrV128, expr_vB, mkU8(8))) |
| 690 | |
| 691 | #define MK_Iop_MullOdd8Sx16( expr_vA, expr_vB ) \ |
| 692 | binop(Iop_MullEven8Sx16, \ |
| 693 | binop(Iop_ShrV128, expr_vA, mkU8(8)), \ |
| 694 | binop(Iop_ShrV128, expr_vB, mkU8(8))) |
| 695 | |
| 696 | #define MK_Iop_MullOdd16Ux8( expr_vA, expr_vB ) \ |
| 697 | binop(Iop_MullEven16Ux8, \ |
| 698 | binop(Iop_ShrV128, expr_vA, mkU8(16)), \ |
| 699 | binop(Iop_ShrV128, expr_vB, mkU8(16))) |
| 700 | |
| 701 | #define MK_Iop_MullOdd16Sx8( expr_vA, expr_vB ) \ |
| 702 | binop(Iop_MullEven16Sx8, \ |
| 703 | binop(Iop_ShrV128, expr_vA, mkU8(16)), \ |
| 704 | binop(Iop_ShrV128, expr_vB, mkU8(16))) |
| 705 | |
cerion | 59b2c31 | 2005-12-17 11:28:53 +0000 | [diff] [blame] | 706 | static IRExpr* /* :: Ity_I64 */ mk64lo32Sto64 ( IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 707 | { |
| 708 | vassert(typeOfIRExpr(irbb->tyenv, src) == Ity_I64); |
| 709 | return unop(Iop_32Sto64, unop(Iop_64to32, src)); |
| 710 | } |
| 711 | |
cerion | 59b2c31 | 2005-12-17 11:28:53 +0000 | [diff] [blame] | 712 | static IRExpr* /* :: Ity_I64 */ mk64lo32Uto64 ( IRExpr* src ) |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 713 | { |
| 714 | vassert(typeOfIRExpr(irbb->tyenv, src) == Ity_I64); |
| 715 | return unop(Iop_32Uto64, unop(Iop_64to32, src)); |
| 716 | } |
| 717 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 718 | static IROp mkSzOp ( IRType ty, IROp op8 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 719 | { |
| 720 | Int adj; |
| 721 | vassert(ty == Ity_I8 || ty == Ity_I16 || |
| 722 | ty == Ity_I32 || ty == Ity_I64); |
| 723 | vassert(op8 == Iop_Add8 || op8 == Iop_Sub8 || op8 == Iop_Mul8 || |
| 724 | op8 == Iop_Or8 || op8 == Iop_And8 || op8 == Iop_Xor8 || |
| 725 | op8 == Iop_Shl8 || op8 == Iop_Shr8 || op8 == Iop_Sar8 || |
| 726 | op8 == Iop_CmpEQ8 || op8 == Iop_CmpNE8 || |
| 727 | op8 == Iop_Not8 || op8 == Iop_Neg8 ); |
| 728 | adj = ty==Ity_I8 ? 0 : (ty==Ity_I16 ? 1 : (ty==Ity_I32 ? 2 : 3)); |
| 729 | return adj + op8; |
| 730 | } |
| 731 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 732 | /* Make sure we get valid 32 and 64bit addresses */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 733 | static Addr64 mkSzAddr ( IRType ty, Addr64 addr ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 734 | { |
| 735 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 736 | return ( ty == Ity_I64 ? |
| 737 | (Addr64)addr : |
| 738 | (Addr64)extend_s_32to64( toUInt(addr) ) ); |
| 739 | } |
| 740 | |
| 741 | /* sz, ULong -> IRExpr */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 742 | static IRExpr* mkSzImm ( IRType ty, ULong imm64 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 743 | { |
| 744 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 745 | return ty == Ity_I64 ? mkU64(imm64) : mkU32((UInt)imm64); |
| 746 | } |
| 747 | |
| 748 | /* sz, ULong -> IRConst */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 749 | static IRConst* mkSzConst ( IRType ty, ULong imm64 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 750 | { |
| 751 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 752 | return ( ty == Ity_I64 ? |
| 753 | IRConst_U64(imm64) : |
| 754 | IRConst_U32((UInt)imm64) ); |
| 755 | } |
| 756 | |
| 757 | /* Sign extend imm16 -> IRExpr* */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 758 | static IRExpr* mkSzExtendS16 ( IRType ty, UInt imm16 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 759 | { |
| 760 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 761 | return ( ty == Ity_I64 ? |
| 762 | mkU64(extend_s_16to64(imm16)) : |
| 763 | mkU32(extend_s_16to32(imm16)) ); |
| 764 | } |
| 765 | |
| 766 | /* Sign extend imm32 -> IRExpr* */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 767 | static IRExpr* mkSzExtendS32 ( IRType ty, UInt imm32 ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 768 | { |
| 769 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 770 | return ( ty == Ity_I64 ? |
| 771 | mkU64(extend_s_32to64(imm32)) : |
| 772 | mkU32(imm32) ); |
| 773 | } |
| 774 | |
| 775 | /* IR narrows I32/I64 -> I8/I16/I32 */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 776 | static IRExpr* mkSzNarrow8 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 777 | { |
| 778 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 779 | return ty == Ity_I64 ? unop(Iop_64to8, src) : unop(Iop_32to8, src); |
| 780 | } |
| 781 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 782 | static IRExpr* mkSzNarrow16 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 783 | { |
| 784 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 785 | return ty == Ity_I64 ? unop(Iop_64to16, src) : unop(Iop_32to16, src); |
| 786 | } |
| 787 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 788 | static IRExpr* mkSzNarrow32 ( IRType ty, IRExpr* src ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 789 | { |
| 790 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 791 | return ty == Ity_I64 ? unop(Iop_64to32, src) : src; |
| 792 | } |
| 793 | |
| 794 | /* Signed/Unsigned IR widens I8/I16/I32 -> I32/I64 */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 795 | static IRExpr* mkSzWiden8 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 796 | { |
| 797 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 798 | IROp op; |
| 799 | if (sined) op = (ty==Ity_I32) ? Iop_8Sto32 : Iop_8Sto64; |
| 800 | else op = (ty==Ity_I32) ? Iop_8Uto32 : Iop_8Uto64; |
| 801 | return unop(op, src); |
| 802 | } |
| 803 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 804 | static IRExpr* mkSzWiden16 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 805 | { |
| 806 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 807 | IROp op; |
| 808 | if (sined) op = (ty==Ity_I32) ? Iop_16Sto32 : Iop_16Sto64; |
| 809 | else op = (ty==Ity_I32) ? Iop_16Uto32 : Iop_16Uto64; |
| 810 | return unop(op, src); |
| 811 | } |
| 812 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 813 | static IRExpr* mkSzWiden32 ( IRType ty, IRExpr* src, Bool sined ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 814 | { |
| 815 | vassert(ty == Ity_I32 || ty == Ity_I64); |
| 816 | if (ty == Ity_I32) |
| 817 | return src; |
| 818 | return (sined) ? unop(Iop_32Sto64, src) : unop(Iop_32Uto64, src); |
| 819 | } |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 820 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 821 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 822 | static Int integerGuestRegOffset ( UInt archreg ) |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 823 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 824 | vassert(archreg < 32); |
| 825 | |
| 826 | // jrs: probably not necessary; only matters if we reference sub-parts |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 827 | // of the ppc registers, but that isn't the case |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 828 | // later: this might affect Altivec though? |
| 829 | vassert(host_is_bigendian); |
| 830 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 831 | switch (archreg) { |
| 832 | case 0: return offsetofPPCGuestState(guest_GPR0); |
| 833 | case 1: return offsetofPPCGuestState(guest_GPR1); |
| 834 | case 2: return offsetofPPCGuestState(guest_GPR2); |
| 835 | case 3: return offsetofPPCGuestState(guest_GPR3); |
| 836 | case 4: return offsetofPPCGuestState(guest_GPR4); |
| 837 | case 5: return offsetofPPCGuestState(guest_GPR5); |
| 838 | case 6: return offsetofPPCGuestState(guest_GPR6); |
| 839 | case 7: return offsetofPPCGuestState(guest_GPR7); |
| 840 | case 8: return offsetofPPCGuestState(guest_GPR8); |
| 841 | case 9: return offsetofPPCGuestState(guest_GPR9); |
| 842 | case 10: return offsetofPPCGuestState(guest_GPR10); |
| 843 | case 11: return offsetofPPCGuestState(guest_GPR11); |
| 844 | case 12: return offsetofPPCGuestState(guest_GPR12); |
| 845 | case 13: return offsetofPPCGuestState(guest_GPR13); |
| 846 | case 14: return offsetofPPCGuestState(guest_GPR14); |
| 847 | case 15: return offsetofPPCGuestState(guest_GPR15); |
| 848 | case 16: return offsetofPPCGuestState(guest_GPR16); |
| 849 | case 17: return offsetofPPCGuestState(guest_GPR17); |
| 850 | case 18: return offsetofPPCGuestState(guest_GPR18); |
| 851 | case 19: return offsetofPPCGuestState(guest_GPR19); |
| 852 | case 20: return offsetofPPCGuestState(guest_GPR20); |
| 853 | case 21: return offsetofPPCGuestState(guest_GPR21); |
| 854 | case 22: return offsetofPPCGuestState(guest_GPR22); |
| 855 | case 23: return offsetofPPCGuestState(guest_GPR23); |
| 856 | case 24: return offsetofPPCGuestState(guest_GPR24); |
| 857 | case 25: return offsetofPPCGuestState(guest_GPR25); |
| 858 | case 26: return offsetofPPCGuestState(guest_GPR26); |
| 859 | case 27: return offsetofPPCGuestState(guest_GPR27); |
| 860 | case 28: return offsetofPPCGuestState(guest_GPR28); |
| 861 | case 29: return offsetofPPCGuestState(guest_GPR29); |
| 862 | case 30: return offsetofPPCGuestState(guest_GPR30); |
| 863 | case 31: return offsetofPPCGuestState(guest_GPR31); |
| 864 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 865 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 866 | vpanic("integerGuestRegOffset(ppc,be)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static IRExpr* getIReg ( UInt archreg ) |
| 870 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 871 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 872 | vassert(archreg < 32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 873 | return IRExpr_Get( integerGuestRegOffset(archreg), ty ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* Ditto, but write to a reg instead. */ |
| 877 | static void putIReg ( UInt archreg, IRExpr* e ) |
| 878 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 879 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 880 | vassert(archreg < 32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 881 | vassert(typeOfIRExpr(irbb->tyenv, e) == ty ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 882 | stmt( IRStmt_Put(integerGuestRegOffset(archreg), e) ); |
| 883 | } |
| 884 | |
| 885 | |
| 886 | static Int floatGuestRegOffset ( UInt archreg ) |
| 887 | { |
| 888 | vassert(archreg < 32); |
| 889 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 890 | switch (archreg) { |
| 891 | case 0: return offsetofPPCGuestState(guest_FPR0); |
| 892 | case 1: return offsetofPPCGuestState(guest_FPR1); |
| 893 | case 2: return offsetofPPCGuestState(guest_FPR2); |
| 894 | case 3: return offsetofPPCGuestState(guest_FPR3); |
| 895 | case 4: return offsetofPPCGuestState(guest_FPR4); |
| 896 | case 5: return offsetofPPCGuestState(guest_FPR5); |
| 897 | case 6: return offsetofPPCGuestState(guest_FPR6); |
| 898 | case 7: return offsetofPPCGuestState(guest_FPR7); |
| 899 | case 8: return offsetofPPCGuestState(guest_FPR8); |
| 900 | case 9: return offsetofPPCGuestState(guest_FPR9); |
| 901 | case 10: return offsetofPPCGuestState(guest_FPR10); |
| 902 | case 11: return offsetofPPCGuestState(guest_FPR11); |
| 903 | case 12: return offsetofPPCGuestState(guest_FPR12); |
| 904 | case 13: return offsetofPPCGuestState(guest_FPR13); |
| 905 | case 14: return offsetofPPCGuestState(guest_FPR14); |
| 906 | case 15: return offsetofPPCGuestState(guest_FPR15); |
| 907 | case 16: return offsetofPPCGuestState(guest_FPR16); |
| 908 | case 17: return offsetofPPCGuestState(guest_FPR17); |
| 909 | case 18: return offsetofPPCGuestState(guest_FPR18); |
| 910 | case 19: return offsetofPPCGuestState(guest_FPR19); |
| 911 | case 20: return offsetofPPCGuestState(guest_FPR20); |
| 912 | case 21: return offsetofPPCGuestState(guest_FPR21); |
| 913 | case 22: return offsetofPPCGuestState(guest_FPR22); |
| 914 | case 23: return offsetofPPCGuestState(guest_FPR23); |
| 915 | case 24: return offsetofPPCGuestState(guest_FPR24); |
| 916 | case 25: return offsetofPPCGuestState(guest_FPR25); |
| 917 | case 26: return offsetofPPCGuestState(guest_FPR26); |
| 918 | case 27: return offsetofPPCGuestState(guest_FPR27); |
| 919 | case 28: return offsetofPPCGuestState(guest_FPR28); |
| 920 | case 29: return offsetofPPCGuestState(guest_FPR29); |
| 921 | case 30: return offsetofPPCGuestState(guest_FPR30); |
| 922 | case 31: return offsetofPPCGuestState(guest_FPR31); |
| 923 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 924 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 925 | vpanic("floatGuestRegOffset(ppc)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static IRExpr* getFReg ( UInt archreg ) |
| 929 | { |
| 930 | vassert(archreg < 32); |
| 931 | return IRExpr_Get( floatGuestRegOffset(archreg), Ity_F64 ); |
| 932 | } |
| 933 | |
| 934 | /* Ditto, but write to a reg instead. */ |
| 935 | static void putFReg ( UInt archreg, IRExpr* e ) |
| 936 | { |
| 937 | vassert(archreg < 32); |
| 938 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_F64); |
| 939 | stmt( IRStmt_Put(floatGuestRegOffset(archreg), e) ); |
| 940 | } |
| 941 | |
| 942 | |
| 943 | static Int vectorGuestRegOffset ( UInt archreg ) |
| 944 | { |
| 945 | vassert(archreg < 32); |
| 946 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 947 | switch (archreg) { |
| 948 | case 0: return offsetofPPCGuestState(guest_VR0); |
| 949 | case 1: return offsetofPPCGuestState(guest_VR1); |
| 950 | case 2: return offsetofPPCGuestState(guest_VR2); |
| 951 | case 3: return offsetofPPCGuestState(guest_VR3); |
| 952 | case 4: return offsetofPPCGuestState(guest_VR4); |
| 953 | case 5: return offsetofPPCGuestState(guest_VR5); |
| 954 | case 6: return offsetofPPCGuestState(guest_VR6); |
| 955 | case 7: return offsetofPPCGuestState(guest_VR7); |
| 956 | case 8: return offsetofPPCGuestState(guest_VR8); |
| 957 | case 9: return offsetofPPCGuestState(guest_VR9); |
| 958 | case 10: return offsetofPPCGuestState(guest_VR10); |
| 959 | case 11: return offsetofPPCGuestState(guest_VR11); |
| 960 | case 12: return offsetofPPCGuestState(guest_VR12); |
| 961 | case 13: return offsetofPPCGuestState(guest_VR13); |
| 962 | case 14: return offsetofPPCGuestState(guest_VR14); |
| 963 | case 15: return offsetofPPCGuestState(guest_VR15); |
| 964 | case 16: return offsetofPPCGuestState(guest_VR16); |
| 965 | case 17: return offsetofPPCGuestState(guest_VR17); |
| 966 | case 18: return offsetofPPCGuestState(guest_VR18); |
| 967 | case 19: return offsetofPPCGuestState(guest_VR19); |
| 968 | case 20: return offsetofPPCGuestState(guest_VR20); |
| 969 | case 21: return offsetofPPCGuestState(guest_VR21); |
| 970 | case 22: return offsetofPPCGuestState(guest_VR22); |
| 971 | case 23: return offsetofPPCGuestState(guest_VR23); |
| 972 | case 24: return offsetofPPCGuestState(guest_VR24); |
| 973 | case 25: return offsetofPPCGuestState(guest_VR25); |
| 974 | case 26: return offsetofPPCGuestState(guest_VR26); |
| 975 | case 27: return offsetofPPCGuestState(guest_VR27); |
| 976 | case 28: return offsetofPPCGuestState(guest_VR28); |
| 977 | case 29: return offsetofPPCGuestState(guest_VR29); |
| 978 | case 30: return offsetofPPCGuestState(guest_VR30); |
| 979 | case 31: return offsetofPPCGuestState(guest_VR31); |
| 980 | default: break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 981 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 982 | vpanic("vextorGuestRegOffset(ppc)"); /*notreached*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static IRExpr* getVReg ( UInt archreg ) |
| 986 | { |
| 987 | vassert(archreg < 32); |
| 988 | return IRExpr_Get( vectorGuestRegOffset(archreg), Ity_V128 ); |
| 989 | } |
| 990 | |
| 991 | /* Ditto, but write to a reg instead. */ |
| 992 | static void putVReg ( UInt archreg, IRExpr* e ) |
| 993 | { |
| 994 | vassert(archreg < 32); |
| 995 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_V128); |
| 996 | stmt( IRStmt_Put(vectorGuestRegOffset(archreg), e) ); |
| 997 | } |
| 998 | |
| 999 | static Int guestCR321offset ( UInt cr ) |
| 1000 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1001 | switch (cr) { |
| 1002 | case 0: return offsetofPPCGuestState(guest_CR0_321 ); |
| 1003 | case 1: return offsetofPPCGuestState(guest_CR1_321 ); |
| 1004 | case 2: return offsetofPPCGuestState(guest_CR2_321 ); |
| 1005 | case 3: return offsetofPPCGuestState(guest_CR3_321 ); |
| 1006 | case 4: return offsetofPPCGuestState(guest_CR4_321 ); |
| 1007 | case 5: return offsetofPPCGuestState(guest_CR5_321 ); |
| 1008 | case 6: return offsetofPPCGuestState(guest_CR6_321 ); |
| 1009 | case 7: return offsetofPPCGuestState(guest_CR7_321 ); |
| 1010 | default: vpanic("guestCR321offset(ppc)"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | static Int guestCR0offset ( UInt cr ) |
| 1015 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1016 | switch (cr) { |
| 1017 | case 0: return offsetofPPCGuestState(guest_CR0_0 ); |
| 1018 | case 1: return offsetofPPCGuestState(guest_CR1_0 ); |
| 1019 | case 2: return offsetofPPCGuestState(guest_CR2_0 ); |
| 1020 | case 3: return offsetofPPCGuestState(guest_CR3_0 ); |
| 1021 | case 4: return offsetofPPCGuestState(guest_CR4_0 ); |
| 1022 | case 5: return offsetofPPCGuestState(guest_CR5_0 ); |
| 1023 | case 6: return offsetofPPCGuestState(guest_CR6_0 ); |
| 1024 | case 7: return offsetofPPCGuestState(guest_CR7_0 ); |
| 1025 | default: vpanic("guestCR3offset(ppc)"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1026 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 1029 | // ROTL(src32/64, rot_amt5/6) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1030 | static IRExpr* /* :: Ity_I32/64 */ ROTL ( IRExpr* src, |
| 1031 | IRExpr* rot_amt ) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1032 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1033 | IRExpr *mask, *rot; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1034 | vassert(typeOfIRExpr(irbb->tyenv,rot_amt) == Ity_I8); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1035 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1036 | if (typeOfIRExpr(irbb->tyenv,src) == Ity_I64) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1037 | // rot = (src << rot_amt) | (src >> (64-rot_amt)) |
| 1038 | mask = binop(Iop_And8, rot_amt, mkU8(63)); |
| 1039 | rot = binop(Iop_Or64, |
| 1040 | binop(Iop_Shl64, src, mask), |
| 1041 | binop(Iop_Shr64, src, binop(Iop_Sub8, mkU8(64), mask))); |
| 1042 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1043 | // rot = (src << rot_amt) | (src >> (32-rot_amt)) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1044 | mask = binop(Iop_And8, rot_amt, mkU8(31)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1045 | rot = binop(Iop_Or32, |
| 1046 | binop(Iop_Shl32, src, mask), |
| 1047 | binop(Iop_Shr32, src, binop(Iop_Sub8, mkU8(32), mask))); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1048 | } |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 1049 | /* Note: the MuxOX is not merely an optimisation; it's needed |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1050 | because otherwise the Shr is a shift by the word size when |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1051 | mask denotes zero. For rotates by immediates, a lot of |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 1052 | this junk gets folded out. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1053 | return IRExpr_Mux0X( mask, /* zero rotate */ src, |
| 1054 | /* non-zero rotate */ rot ); |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 1055 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1056 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1057 | #if 0 |
| 1058 | /* ROTL32_64(src64, rot_amt5) |
| 1059 | Weirdo 32bit rotl on ppc64: |
| 1060 | rot32 = ROTL(src_lo32,y); |
| 1061 | return (rot32|rot32); |
| 1062 | */ |
| 1063 | static IRExpr* /* :: Ity_I64 */ ROTL32_64 ( IRExpr* src64, |
| 1064 | IRExpr* rot_amt ) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1065 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1066 | IRExpr *mask, *rot32; |
| 1067 | vassert(mode64); // used only in 64bit mode |
| 1068 | vassert(typeOfIRExpr(irbb->tyenv,src64) == Ity_I64); |
| 1069 | vassert(typeOfIRExpr(irbb->tyenv,rot_amt) == Ity_I8); |
| 1070 | |
| 1071 | mask = binop(Iop_And8, rot_amt, mkU8(31)); |
| 1072 | rot32 = ROTL( unop(Iop_64to32, src64), rot_amt ); |
| 1073 | |
| 1074 | return binop(Iop_Or64, |
| 1075 | binop(Iop_Shl64, unop(Iop_32Uto64, rot32), mkU8(32)), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1076 | unop(Iop_32Uto64, rot32)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1077 | } |
| 1078 | #endif |
| 1079 | |
| 1080 | |
| 1081 | /* Standard effective address calc: (rA + rB) */ |
| 1082 | static IRExpr* ea_rA_idxd ( UInt rA, UInt rB ) |
| 1083 | { |
| 1084 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1085 | vassert(rA < 32); |
| 1086 | vassert(rB < 32); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1087 | return binop(mkSzOp(ty, Iop_Add8), getIReg(rA), getIReg(rB)); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1090 | /* Standard effective address calc: (rA + simm) */ |
| 1091 | static IRExpr* ea_rA_simm ( UInt rA, UInt simm16 ) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1092 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1093 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1094 | vassert(rA < 32); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1095 | return binop(mkSzOp(ty, Iop_Add8), getIReg(rA), |
| 1096 | mkSzExtendS16(ty, simm16)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /* Standard effective address calc: (rA|0) */ |
| 1100 | static IRExpr* ea_rAor0 ( UInt rA ) |
| 1101 | { |
| 1102 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1103 | vassert(rA < 32); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1104 | if (rA == 0) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1105 | return mkSzImm(ty, 0); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 1106 | } else { |
| 1107 | return getIReg(rA); |
| 1108 | } |
| 1109 | } |
| 1110 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1111 | /* Standard effective address calc: (rA|0) + rB */ |
| 1112 | static IRExpr* ea_rAor0_idxd ( UInt rA, UInt rB ) |
| 1113 | { |
| 1114 | vassert(rA < 32); |
| 1115 | vassert(rB < 32); |
| 1116 | return (rA == 0) ? getIReg(rB) : ea_rA_idxd( rA, rB ); |
| 1117 | } |
| 1118 | |
| 1119 | /* Standard effective address calc: (rA|0) + simm16 */ |
| 1120 | static IRExpr* ea_rAor0_simm ( UInt rA, UInt simm16 ) |
| 1121 | { |
| 1122 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1123 | vassert(rA < 32); |
| 1124 | if (rA == 0) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1125 | return mkSzExtendS16(ty, simm16); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1126 | } else { |
| 1127 | return ea_rA_simm( rA, simm16 ); |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | /* Align effective address */ |
| 1133 | static IRExpr* addr_align( IRExpr* addr, UChar align ) |
| 1134 | { |
| 1135 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 1136 | Long mask; |
| 1137 | switch (align) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1138 | case 1: return addr; // byte aligned |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1139 | case 2: mask = ((Long)-1) << 1; break; // half-word aligned |
| 1140 | case 4: mask = ((Long)-1) << 2; break; // word aligned |
| 1141 | case 16: mask = ((Long)-1) << 4; break; // quad-word aligned |
| 1142 | default: |
| 1143 | vex_printf("addr_align: align = %u\n", align); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1144 | vpanic("addr_align(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | vassert(typeOfIRExpr(irbb->tyenv,addr) == ty); |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 1148 | return binop( mkSzOp(ty, Iop_And8), addr, mkSzImm(ty, mask) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1151 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1152 | /*------------------------------------------------------------*/ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1153 | /*--- Helpers for condition codes. ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1154 | /*------------------------------------------------------------*/ |
| 1155 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1156 | /* Condition register layout. |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1157 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1158 | In the hardware, CR is laid out like this. The leftmost end is the |
| 1159 | most significant bit in the register; however the IBM documentation |
| 1160 | numbers the bits backwards for some reason. |
| 1161 | |
| 1162 | CR0 CR1 .......... CR6 CR7 |
| 1163 | 0 .. 3 ....................... 28 .. 31 (IBM bit numbering) |
| 1164 | 31 28 3 0 (normal bit numbering) |
| 1165 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1166 | Each CR field is 4 bits: [<,>,==,SO] |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1167 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1168 | Hence in IBM's notation, BI=0 is CR7[SO], BI=1 is CR7[==], etc. |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1169 | |
| 1170 | Indexing from BI to guest state: |
| 1171 | |
| 1172 | let n = BI / 4 |
| 1173 | off = BI % 4 |
| 1174 | this references CR n: |
| 1175 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1176 | off==0 -> guest_CRn_321 >> 3 |
| 1177 | off==1 -> guest_CRn_321 >> 2 |
| 1178 | off==2 -> guest_CRn_321 >> 1 |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1179 | off==3 -> guest_CRn_SO |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1180 | |
| 1181 | Bear in mind the only significant bit in guest_CRn_SO is bit 0 |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1182 | (normal notation) and in guest_CRn_321 the significant bits are |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1183 | 3, 2 and 1 (normal notation). |
| 1184 | */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1185 | |
| 1186 | static void putCR321 ( UInt cr, IRExpr* e ) |
| 1187 | { |
| 1188 | vassert(cr < 8); |
| 1189 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
| 1190 | stmt( IRStmt_Put(guestCR321offset(cr), e) ); |
| 1191 | } |
| 1192 | |
| 1193 | static void putCR0 ( UInt cr, IRExpr* e ) |
| 1194 | { |
| 1195 | vassert(cr < 8); |
| 1196 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
| 1197 | stmt( IRStmt_Put(guestCR0offset(cr), e) ); |
| 1198 | } |
| 1199 | |
| 1200 | static IRExpr* /* :: Ity_I8 */ getCR0 ( UInt cr ) |
| 1201 | { |
| 1202 | vassert(cr < 8); |
| 1203 | return IRExpr_Get(guestCR0offset(cr), Ity_I8); |
| 1204 | } |
| 1205 | |
| 1206 | static IRExpr* /* :: Ity_I8 */ getCR321 ( UInt cr ) |
| 1207 | { |
| 1208 | vassert(cr < 8); |
| 1209 | return IRExpr_Get(guestCR321offset(cr), Ity_I8); |
| 1210 | } |
| 1211 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1212 | /* Fetch the specified CR bit (as per IBM/hardware notation) and |
| 1213 | return it at the bottom of an I32; the top 31 bits are guaranteed |
| 1214 | to be zero. */ |
| 1215 | static IRExpr* /* :: Ity_I32 */ getCRbit ( UInt bi ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1216 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1217 | UInt n = bi / 4; |
| 1218 | UInt off = bi % 4; |
| 1219 | vassert(bi < 32); |
| 1220 | if (off == 3) { |
| 1221 | /* Fetch the SO bit for this CR field */ |
| 1222 | /* Note: And32 is redundant paranoia iff guest state only has 0 |
| 1223 | or 1 in that slot. */ |
| 1224 | return binop(Iop_And32, unop(Iop_8Uto32, getCR0(n)), mkU32(1)); |
| 1225 | } else { |
| 1226 | /* Fetch the <, > or == bit for this CR field */ |
| 1227 | return binop( Iop_And32, |
| 1228 | binop( Iop_Shr32, |
| 1229 | unop(Iop_8Uto32, getCR321(n)), |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 1230 | mkU8(toUChar(3-off)) ), |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1231 | mkU32(1) ); |
| 1232 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 1233 | } |
| 1234 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1235 | /* Dually, write the least significant bit of BIT to the specified CR |
| 1236 | bit. Indexing as per getCRbit. */ |
| 1237 | static void putCRbit ( UInt bi, IRExpr* bit ) |
| 1238 | { |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 1239 | UInt n, off; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1240 | IRExpr* safe; |
| 1241 | vassert(typeOfIRExpr(irbb->tyenv,bit) == Ity_I32); |
| 1242 | safe = binop(Iop_And32, bit, mkU32(1)); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 1243 | n = bi / 4; |
| 1244 | off = bi % 4; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1245 | vassert(bi < 32); |
| 1246 | if (off == 3) { |
| 1247 | /* This is the SO bit for this CR field */ |
| 1248 | putCR0(n, unop(Iop_32to8, safe)); |
| 1249 | } else { |
| 1250 | off = 3 - off; |
| 1251 | vassert(off == 1 || off == 2 || off == 3); |
| 1252 | putCR321( |
| 1253 | n, |
| 1254 | unop( Iop_32to8, |
| 1255 | binop( Iop_Or32, |
| 1256 | /* old value with field masked out */ |
| 1257 | binop(Iop_And32, unop(Iop_8Uto32, getCR321(n)), |
| 1258 | mkU32(~(1 << off))), |
| 1259 | /* new value in the right place */ |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 1260 | binop(Iop_Shl32, safe, mkU8(toUChar(off))) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1261 | ) |
| 1262 | ) |
| 1263 | ); |
| 1264 | } |
| 1265 | } |
| 1266 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1267 | /* Fetch the specified CR bit (as per IBM/hardware notation) and |
| 1268 | return it somewhere in an I32; it does not matter where, but |
| 1269 | whichever bit it is, all other bits are guaranteed to be zero. In |
| 1270 | other words, the I32-typed expression will be zero if the bit is |
| 1271 | zero and nonzero if the bit is 1. Write into *where the index |
| 1272 | of where the bit will be. */ |
| 1273 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1274 | static |
| 1275 | IRExpr* /* :: Ity_I32 */ getCRbit_anywhere ( UInt bi, Int* where ) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1276 | { |
| 1277 | UInt n = bi / 4; |
| 1278 | UInt off = bi % 4; |
| 1279 | vassert(bi < 32); |
| 1280 | if (off == 3) { |
| 1281 | /* Fetch the SO bit for this CR field */ |
| 1282 | /* Note: And32 is redundant paranoia iff guest state only has 0 |
| 1283 | or 1 in that slot. */ |
| 1284 | *where = 0; |
| 1285 | return binop(Iop_And32, unop(Iop_8Uto32, getCR0(n)), mkU32(1)); |
| 1286 | } else { |
| 1287 | /* Fetch the <, > or == bit for this CR field */ |
| 1288 | *where = 3-off; |
| 1289 | return binop( Iop_And32, |
| 1290 | unop(Iop_8Uto32, getCR321(n)), |
| 1291 | mkU32(1 << (3-off)) ); |
| 1292 | } |
| 1293 | } |
| 1294 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1295 | /* Set the CR0 flags following an arithmetic operation. |
| 1296 | (Condition Register CR0 Field Definition, PPC32 p60) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1297 | */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1298 | static IRExpr* getXER_SO ( void ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1299 | static void set_CR0 ( IRExpr* result ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1300 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1301 | vassert(typeOfIRExpr(irbb->tyenv,result) == Ity_I32 || |
| 1302 | typeOfIRExpr(irbb->tyenv,result) == Ity_I64); |
| 1303 | if (mode64) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1304 | putCR321( 0, unop(Iop_64to8, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1305 | binop(Iop_CmpORD64S, result, mkU64(0))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1306 | } else { |
| 1307 | putCR321( 0, unop(Iop_32to8, |
| 1308 | binop(Iop_CmpORD32S, result, mkU32(0))) ); |
| 1309 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1310 | putCR0( 0, getXER_SO() ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1311 | } |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 1312 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1313 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1314 | /* Set the CR6 flags following an AltiVec compare operation. */ |
| 1315 | static void set_AV_CR6 ( IRExpr* result, Bool test_all_ones ) |
| 1316 | { |
| 1317 | /* CR6[0:3] = {all_ones, 0, all_zeros, 0} |
| 1318 | all_ones = (v[0] && v[1] && v[2] && v[3]) |
| 1319 | all_zeros = ~(v[0] || v[1] || v[2] || v[3]) |
| 1320 | */ |
| 1321 | IRTemp v0 = newTemp(Ity_V128); |
| 1322 | IRTemp v1 = newTemp(Ity_V128); |
| 1323 | IRTemp v2 = newTemp(Ity_V128); |
| 1324 | IRTemp v3 = newTemp(Ity_V128); |
| 1325 | IRTemp rOnes = newTemp(Ity_I8); |
| 1326 | IRTemp rZeros = newTemp(Ity_I8); |
| 1327 | |
| 1328 | vassert(typeOfIRExpr(irbb->tyenv,result) == Ity_V128); |
| 1329 | |
| 1330 | assign( v0, result ); |
| 1331 | assign( v1, binop(Iop_ShrV128, result, mkU8(32)) ); |
| 1332 | assign( v2, binop(Iop_ShrV128, result, mkU8(64)) ); |
| 1333 | assign( v3, binop(Iop_ShrV128, result, mkU8(96)) ); |
| 1334 | |
| 1335 | assign( rZeros, unop(Iop_1Uto8, |
| 1336 | binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF), |
| 1337 | unop(Iop_Not32, |
| 1338 | unop(Iop_V128to32, |
| 1339 | binop(Iop_OrV128, |
| 1340 | binop(Iop_OrV128, mkexpr(v0), mkexpr(v1)), |
| 1341 | binop(Iop_OrV128, mkexpr(v2), mkexpr(v3)))) |
| 1342 | ))) ); |
| 1343 | |
| 1344 | if (test_all_ones) { |
| 1345 | assign( rOnes, unop(Iop_1Uto8, |
| 1346 | binop(Iop_CmpEQ32, mkU32(0xFFFFFFFF), |
| 1347 | unop(Iop_V128to32, |
| 1348 | binop(Iop_AndV128, |
| 1349 | binop(Iop_AndV128, mkexpr(v0), mkexpr(v1)), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1350 | binop(Iop_AndV128, mkexpr(v2), mkexpr(v3))) |
| 1351 | ))) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1352 | putCR321( 6, binop(Iop_Or8, |
| 1353 | binop(Iop_Shl8, mkexpr(rOnes), mkU8(3)), |
| 1354 | binop(Iop_Shl8, mkexpr(rZeros), mkU8(1))) ); |
| 1355 | } else { |
| 1356 | putCR321( 6, binop(Iop_Shl8, mkexpr(rZeros), mkU8(1)) ); |
| 1357 | } |
| 1358 | putCR0( 6, mkU8(0) ); |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | /*------------------------------------------------------------*/ |
| 1364 | /*--- Helpers for XER flags. ---*/ |
| 1365 | /*------------------------------------------------------------*/ |
| 1366 | |
| 1367 | static void putXER_SO ( IRExpr* e ) |
| 1368 | { |
| 1369 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1370 | IRExpr* so = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1371 | stmt( IRStmt_Put( OFFB_XER_SO, so ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | static void putXER_OV ( IRExpr* e ) |
| 1375 | { |
| 1376 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1377 | IRExpr* ov = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1378 | stmt( IRStmt_Put( OFFB_XER_OV, ov ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void putXER_CA ( IRExpr* e ) |
| 1382 | { |
| 1383 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1384 | IRExpr* ca = binop(Iop_And8, e, mkU8(1)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1385 | stmt( IRStmt_Put( OFFB_XER_CA, ca ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | static void putXER_BC ( IRExpr* e ) |
| 1389 | { |
| 1390 | vassert(typeOfIRExpr(irbb->tyenv, e) == Ity_I8); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1391 | IRExpr* bc = binop(Iop_And8, e, mkU8(0x7F)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1392 | stmt( IRStmt_Put( OFFB_XER_BC, bc ) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static IRExpr* /* :: Ity_I8 */ getXER_SO ( void ) |
| 1396 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1397 | return IRExpr_Get( OFFB_XER_SO, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static IRExpr* /* :: Ity_I32 */ getXER_SO32 ( void ) |
| 1401 | { |
| 1402 | return binop( Iop_And32, unop(Iop_8Uto32, getXER_SO()), mkU32(1) ); |
| 1403 | } |
| 1404 | |
| 1405 | static IRExpr* /* :: Ity_I8 */ getXER_OV ( void ) |
| 1406 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1407 | return IRExpr_Get( OFFB_XER_OV, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static IRExpr* /* :: Ity_I32 */ getXER_OV32 ( void ) |
| 1411 | { |
| 1412 | return binop( Iop_And32, unop(Iop_8Uto32, getXER_OV()), mkU32(1) ); |
| 1413 | } |
| 1414 | |
| 1415 | static IRExpr* /* :: Ity_I32 */ getXER_CA32 ( void ) |
| 1416 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1417 | IRExpr* ca = IRExpr_Get( OFFB_XER_CA, Ity_I8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1418 | return binop( Iop_And32, unop(Iop_8Uto32, ca ), mkU32(1) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | static IRExpr* /* :: Ity_I8 */ getXER_BC ( void ) |
| 1422 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1423 | return IRExpr_Get( OFFB_XER_BC, Ity_I8 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | static IRExpr* /* :: Ity_I32 */ getXER_BC32 ( void ) |
| 1427 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1428 | IRExpr* bc = IRExpr_Get( OFFB_XER_BC, Ity_I8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1429 | return binop( Iop_And32, unop(Iop_8Uto32, bc), mkU32(0x7F) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1433 | /* RES is the result of doing OP on ARGL and ARGR. Set %XER.OV and |
| 1434 | %XER.SO accordingly. */ |
| 1435 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1436 | static void set_XER_OV_32( UInt op, IRExpr* res, |
| 1437 | IRExpr* argL, IRExpr* argR ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1438 | { |
| 1439 | IRTemp t64; |
| 1440 | IRExpr* xer_ov; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1441 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1442 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I32); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1443 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I32); |
| 1444 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I32); |
| 1445 | |
| 1446 | # define INT32_MIN 0x80000000 |
| 1447 | |
| 1448 | # define XOR2(_aa,_bb) \ |
| 1449 | binop(Iop_Xor32,(_aa),(_bb)) |
| 1450 | |
| 1451 | # define XOR3(_cc,_dd,_ee) \ |
| 1452 | binop(Iop_Xor32,binop(Iop_Xor32,(_cc),(_dd)),(_ee)) |
| 1453 | |
| 1454 | # define AND3(_ff,_gg,_hh) \ |
| 1455 | binop(Iop_And32,binop(Iop_And32,(_ff),(_gg)),(_hh)) |
| 1456 | |
| 1457 | #define NOT(_jj) \ |
| 1458 | unop(Iop_Not32, (_jj)) |
| 1459 | |
| 1460 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1461 | case /* 0 */ PPCG_FLAG_OP_ADD: |
| 1462 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1463 | /* (argL^argR^-1) & (argL^res) & (1<<31) ?1:0 */ |
| 1464 | // i.e. ((both_same_sign) & (sign_changed) & (sign_mask)) |
| 1465 | xer_ov |
| 1466 | = AND3( XOR3(argL,argR,mkU32(-1)), |
| 1467 | XOR2(argL,res), |
| 1468 | mkU32(INT32_MIN) ); |
| 1469 | /* xer_ov can only be 0 or 1<<31 */ |
| 1470 | xer_ov |
| 1471 | = binop(Iop_Shr32, xer_ov, mkU8(31) ); |
| 1472 | break; |
| 1473 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1474 | case /* 2 */ PPCG_FLAG_OP_DIVW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1475 | /* (argL == INT32_MIN && argR == -1) || argR == 0 */ |
| 1476 | xer_ov |
| 1477 | = mkOR1( |
| 1478 | mkAND1( |
| 1479 | binop(Iop_CmpEQ32, argL, mkU32(INT32_MIN)), |
| 1480 | binop(Iop_CmpEQ32, argR, mkU32(-1)) |
| 1481 | ), |
| 1482 | binop(Iop_CmpEQ32, argR, mkU32(0) ) |
| 1483 | ); |
| 1484 | xer_ov |
| 1485 | = unop(Iop_1Uto32, xer_ov); |
| 1486 | break; |
| 1487 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1488 | case /* 3 */ PPCG_FLAG_OP_DIVWU: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1489 | /* argR == 0 */ |
| 1490 | xer_ov |
| 1491 | = unop(Iop_1Uto32, binop(Iop_CmpEQ32, argR, mkU32(0))); |
| 1492 | break; |
| 1493 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1494 | case /* 4 */ PPCG_FLAG_OP_MULLW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1495 | /* OV true if result can't be represented in 32 bits |
| 1496 | i.e sHi != sign extension of sLo */ |
| 1497 | t64 = newTemp(Ity_I64); |
| 1498 | assign( t64, binop(Iop_MullS32, argL, argR) ); |
| 1499 | xer_ov |
| 1500 | = binop( Iop_CmpNE32, |
| 1501 | unop(Iop_64HIto32, mkexpr(t64)), |
| 1502 | binop( Iop_Sar32, |
| 1503 | unop(Iop_64to32, mkexpr(t64)), |
| 1504 | mkU8(31)) |
| 1505 | ); |
| 1506 | xer_ov |
| 1507 | = unop(Iop_1Uto32, xer_ov); |
| 1508 | break; |
| 1509 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1510 | case /* 5 */ PPCG_FLAG_OP_NEG: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1511 | /* argL == INT32_MIN */ |
| 1512 | xer_ov |
| 1513 | = unop( Iop_1Uto32, |
| 1514 | binop(Iop_CmpEQ32, argL, mkU32(INT32_MIN)) ); |
| 1515 | break; |
| 1516 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1517 | case /* 6 */ PPCG_FLAG_OP_SUBF: |
| 1518 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1519 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1520 | /* ((~argL)^argR^-1) & ((~argL)^res) & (1<<31) ?1:0; */ |
| 1521 | xer_ov |
| 1522 | = AND3( XOR3(NOT(argL),argR,mkU32(-1)), |
| 1523 | XOR2(NOT(argL),res), |
| 1524 | mkU32(INT32_MIN) ); |
| 1525 | /* xer_ov can only be 0 or 1<<31 */ |
| 1526 | xer_ov |
| 1527 | = binop(Iop_Shr32, xer_ov, mkU8(31) ); |
| 1528 | break; |
| 1529 | |
| 1530 | default: |
| 1531 | vex_printf("set_XER_OV: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1532 | vpanic("set_XER_OV(ppc)"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1533 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1534 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1535 | /* xer_ov MUST denote either 0 or 1, no other value allowed */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1536 | putXER_OV( unop(Iop_32to8, xer_ov) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1537 | |
| 1538 | /* Update the summary overflow */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1539 | putXER_SO( binop(Iop_Or8, getXER_SO(), getXER_OV()) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1540 | |
| 1541 | # undef INT32_MIN |
| 1542 | # undef AND3 |
| 1543 | # undef XOR3 |
| 1544 | # undef XOR2 |
| 1545 | # undef NOT |
| 1546 | } |
| 1547 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1548 | static void set_XER_OV_64( UInt op, IRExpr* res, |
| 1549 | IRExpr* argL, IRExpr* argR ) |
| 1550 | { |
| 1551 | IRExpr* xer_ov; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1552 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1553 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I64); |
| 1554 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I64); |
| 1555 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I64); |
| 1556 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1557 | # define INT64_MIN 0x8000000000000000ULL |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1558 | |
| 1559 | # define XOR2(_aa,_bb) \ |
| 1560 | binop(Iop_Xor64,(_aa),(_bb)) |
| 1561 | |
| 1562 | # define XOR3(_cc,_dd,_ee) \ |
| 1563 | binop(Iop_Xor64,binop(Iop_Xor64,(_cc),(_dd)),(_ee)) |
| 1564 | |
| 1565 | # define AND3(_ff,_gg,_hh) \ |
| 1566 | binop(Iop_And64,binop(Iop_And64,(_ff),(_gg)),(_hh)) |
| 1567 | |
| 1568 | #define NOT(_jj) \ |
| 1569 | unop(Iop_Not64, (_jj)) |
| 1570 | |
| 1571 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1572 | case /* 0 */ PPCG_FLAG_OP_ADD: |
| 1573 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1574 | /* (argL^argR^-1) & (argL^res) & (1<<63) ? 1:0 */ |
| 1575 | // i.e. ((both_same_sign) & (sign_changed) & (sign_mask)) |
| 1576 | xer_ov |
| 1577 | = AND3( XOR3(argL,argR,mkU64(-1)), |
| 1578 | XOR2(argL,res), |
| 1579 | mkU64(INT64_MIN) ); |
| 1580 | /* xer_ov can only be 0 or 1<<63 */ |
| 1581 | xer_ov |
| 1582 | = unop(Iop_64to1, binop(Iop_Shr64, xer_ov, mkU8(63))); |
| 1583 | break; |
| 1584 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1585 | case /* 2 */ PPCG_FLAG_OP_DIVW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1586 | /* (argL == INT64_MIN && argR == -1) || argR == 0 */ |
| 1587 | xer_ov |
| 1588 | = mkOR1( |
| 1589 | mkAND1( |
| 1590 | binop(Iop_CmpEQ64, argL, mkU64(INT64_MIN)), |
| 1591 | binop(Iop_CmpEQ64, argR, mkU64(-1)) |
| 1592 | ), |
| 1593 | binop(Iop_CmpEQ64, argR, mkU64(0) ) |
| 1594 | ); |
| 1595 | break; |
| 1596 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1597 | case /* 3 */ PPCG_FLAG_OP_DIVWU: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1598 | /* argR == 0 */ |
| 1599 | xer_ov |
| 1600 | = binop(Iop_CmpEQ64, argR, mkU64(0)); |
| 1601 | break; |
| 1602 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1603 | case /* 4 */ PPCG_FLAG_OP_MULLW: { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1604 | /* OV true if result can't be represented in 64 bits |
| 1605 | i.e sHi != sign extension of sLo */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1606 | xer_ov |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 1607 | = binop( Iop_CmpNE32, |
| 1608 | unop(Iop_64HIto32, res), |
| 1609 | binop( Iop_Sar32, |
| 1610 | unop(Iop_64to32, res), |
| 1611 | mkU8(31)) |
| 1612 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | } |
| 1615 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1616 | case /* 5 */ PPCG_FLAG_OP_NEG: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1617 | /* argL == INT64_MIN */ |
| 1618 | xer_ov |
| 1619 | = binop(Iop_CmpEQ64, argL, mkU64(INT64_MIN)); |
| 1620 | break; |
| 1621 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1622 | case /* 6 */ PPCG_FLAG_OP_SUBF: |
| 1623 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1624 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1625 | /* ((~argL)^argR^-1) & ((~argL)^res) & (1<<63) ?1:0; */ |
| 1626 | xer_ov |
| 1627 | = AND3( XOR3(NOT(argL),argR,mkU64(-1)), |
| 1628 | XOR2(NOT(argL),res), |
| 1629 | mkU64(INT64_MIN) ); |
| 1630 | /* xer_ov can only be 0 or 1<<63 */ |
| 1631 | xer_ov |
| 1632 | = unop(Iop_64to1, binop(Iop_Shr64, xer_ov, mkU8(63))); |
| 1633 | break; |
| 1634 | |
| 1635 | default: |
| 1636 | vex_printf("set_XER_OV: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1637 | vpanic("set_XER_OV(ppc64)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | /* xer_ov MUST denote either 0 or 1, no other value allowed */ |
| 1641 | putXER_OV( unop(Iop_1Uto8, xer_ov) ); |
| 1642 | |
| 1643 | /* Update the summary overflow */ |
| 1644 | putXER_SO( binop(Iop_Or8, getXER_SO(), getXER_OV()) ); |
| 1645 | |
| 1646 | # undef INT64_MIN |
| 1647 | # undef AND3 |
| 1648 | # undef XOR3 |
| 1649 | # undef XOR2 |
| 1650 | # undef NOT |
| 1651 | } |
| 1652 | |
| 1653 | static void set_XER_OV ( IRType ty, UInt op, IRExpr* res, |
| 1654 | IRExpr* argL, IRExpr* argR ) |
| 1655 | { |
| 1656 | if (ty == Ity_I32) |
| 1657 | set_XER_OV_32( op, res, argL, argR ); |
| 1658 | else |
| 1659 | set_XER_OV_64( op, res, argL, argR ); |
| 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1664 | /* RES is the result of doing OP on ARGL and ARGR with the old %XER.CA |
| 1665 | value being OLDCA. Set %XER.CA accordingly. */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 1666 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1667 | static void set_XER_CA_32 ( UInt op, IRExpr* res, |
| 1668 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 1669 | { |
sewardj | 9a036bf | 2005-03-14 18:19:08 +0000 | [diff] [blame] | 1670 | IRExpr* xer_ca; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1671 | vassert(op < PPCG_FLAG_OP_NUMBER); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1672 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I32); |
| 1673 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I32); |
| 1674 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I32); |
| 1675 | vassert(typeOfIRExpr(irbb->tyenv,oldca) == Ity_I32); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 1676 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1677 | /* Incoming oldca is assumed to hold the values 0 or 1 only. This |
| 1678 | seems reasonable given that it's always generated by |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1679 | getXER_CA32(), which masks it accordingly. In any case it being |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 1680 | 0 or 1 is an invariant of the ppc guest state representation; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1681 | if it has any other value, that invariant has been violated. */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 1682 | |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1683 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1684 | case /* 0 */ PPCG_FLAG_OP_ADD: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1685 | /* res <u argL */ |
| 1686 | xer_ca |
| 1687 | = unop(Iop_1Uto32, binop(Iop_CmpLT32U, res, argL)); |
| 1688 | break; |
| 1689 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1690 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1691 | /* res <u argL || (old_ca==1 && res==argL) */ |
| 1692 | xer_ca |
| 1693 | = mkOR1( |
| 1694 | binop(Iop_CmpLT32U, res, argL), |
| 1695 | mkAND1( |
| 1696 | binop(Iop_CmpEQ32, oldca, mkU32(1)), |
| 1697 | binop(Iop_CmpEQ32, res, argL) |
| 1698 | ) |
| 1699 | ); |
| 1700 | xer_ca |
| 1701 | = unop(Iop_1Uto32, xer_ca); |
| 1702 | break; |
| 1703 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1704 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1705 | /* res <u argR || (old_ca==1 && res==argR) */ |
| 1706 | xer_ca |
| 1707 | = mkOR1( |
| 1708 | binop(Iop_CmpLT32U, res, argR), |
| 1709 | mkAND1( |
| 1710 | binop(Iop_CmpEQ32, oldca, mkU32(1)), |
| 1711 | binop(Iop_CmpEQ32, res, argR) |
| 1712 | ) |
| 1713 | ); |
| 1714 | xer_ca |
| 1715 | = unop(Iop_1Uto32, xer_ca); |
| 1716 | break; |
| 1717 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1718 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1719 | case /* 9 */ PPCG_FLAG_OP_SUBFI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1720 | /* res <=u argR */ |
| 1721 | xer_ca |
| 1722 | = unop(Iop_1Uto32, binop(Iop_CmpLE32U, res, argR)); |
| 1723 | break; |
| 1724 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1725 | case /* 10 */ PPCG_FLAG_OP_SRAW: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1726 | /* The shift amount is guaranteed to be in 0 .. 63 inclusive. |
| 1727 | If it is <= 31, behave like SRAWI; else XER.CA is the sign |
| 1728 | bit of argL. */ |
| 1729 | /* This term valid for shift amount < 32 only */ |
| 1730 | xer_ca |
| 1731 | = binop( |
| 1732 | Iop_And32, |
| 1733 | binop(Iop_Sar32, argL, mkU8(31)), |
| 1734 | binop( Iop_And32, |
| 1735 | argL, |
| 1736 | binop( Iop_Sub32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1737 | binop(Iop_Shl32, mkU32(1), |
| 1738 | unop(Iop_32to8,argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1739 | mkU32(1) ) |
| 1740 | ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1741 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1742 | xer_ca |
| 1743 | = IRExpr_Mux0X( |
| 1744 | /* shift amt > 31 ? */ |
| 1745 | unop(Iop_1Uto8, binop(Iop_CmpLT32U, mkU32(31), argR)), |
| 1746 | /* no -- be like srawi */ |
| 1747 | unop(Iop_1Uto32, binop(Iop_CmpNE32, xer_ca, mkU32(0))), |
| 1748 | /* yes -- get sign bit of argL */ |
| 1749 | binop(Iop_Shr32, argL, mkU8(31)) |
| 1750 | ); |
| 1751 | break; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1752 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1753 | case /* 11 */ PPCG_FLAG_OP_SRAWI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1754 | /* xer_ca is 1 iff src was negative and bits_shifted_out != |
| 1755 | 0. Since the shift amount is known to be in the range |
| 1756 | 0 .. 31 inclusive the following seems viable: |
| 1757 | xer.ca == 1 iff the following is nonzero: |
| 1758 | (argL >>s 31) -- either all 0s or all 1s |
| 1759 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
| 1760 | xer_ca |
| 1761 | = binop( |
| 1762 | Iop_And32, |
| 1763 | binop(Iop_Sar32, argL, mkU8(31)), |
| 1764 | binop( Iop_And32, |
| 1765 | argL, |
| 1766 | binop( Iop_Sub32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1767 | binop(Iop_Shl32, mkU32(1), |
| 1768 | unop(Iop_32to8,argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1769 | mkU32(1) ) |
| 1770 | ) |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1771 | ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1772 | xer_ca |
| 1773 | = unop(Iop_1Uto32, binop(Iop_CmpNE32, xer_ca, mkU32(0))); |
| 1774 | break; |
| 1775 | |
| 1776 | default: |
| 1777 | vex_printf("set_XER_CA: op = %u\n", op); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1778 | vpanic("set_XER_CA(ppc)"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /* xer_ca MUST denote either 0 or 1, no other value allowed */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1782 | putXER_CA( unop(Iop_32to8, xer_ca) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1785 | static void set_XER_CA_64 ( UInt op, IRExpr* res, |
| 1786 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1787 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1788 | IRExpr* xer_ca; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1789 | vassert(op < PPCG_FLAG_OP_NUMBER); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1790 | vassert(typeOfIRExpr(irbb->tyenv,res) == Ity_I64); |
| 1791 | vassert(typeOfIRExpr(irbb->tyenv,argL) == Ity_I64); |
| 1792 | vassert(typeOfIRExpr(irbb->tyenv,argR) == Ity_I64); |
| 1793 | vassert(typeOfIRExpr(irbb->tyenv,oldca) == Ity_I64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1794 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1795 | /* Incoming oldca is assumed to hold the values 0 or 1 only. This |
| 1796 | seems reasonable given that it's always generated by |
| 1797 | getXER_CA32(), which masks it accordingly. In any case it being |
cerion | 7594920 | 2005-12-24 13:14:11 +0000 | [diff] [blame] | 1798 | 0 or 1 is an invariant of the ppc guest state representation; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1799 | if it has any other value, that invariant has been violated. */ |
| 1800 | |
| 1801 | switch (op) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1802 | case /* 0 */ PPCG_FLAG_OP_ADD: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1803 | /* res <u argL */ |
| 1804 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1805 | = unop(Iop_1Uto32, binop(Iop_CmpLT64U, res, argL)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1806 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1807 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1808 | case /* 1 */ PPCG_FLAG_OP_ADDE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1809 | /* res <u argL || (old_ca==1 && res==argL) */ |
| 1810 | xer_ca |
| 1811 | = mkOR1( |
| 1812 | binop(Iop_CmpLT64U, res, argL), |
| 1813 | mkAND1( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1814 | binop(Iop_CmpEQ64, oldca, mkU64(1)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1815 | binop(Iop_CmpEQ64, res, argL) |
| 1816 | ) |
| 1817 | ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1818 | xer_ca |
| 1819 | = unop(Iop_1Uto32, xer_ca); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1820 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1821 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1822 | case /* 8 */ PPCG_FLAG_OP_SUBFE: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1823 | /* res <u argR || (old_ca==1 && res==argR) */ |
| 1824 | xer_ca |
| 1825 | = mkOR1( |
| 1826 | binop(Iop_CmpLT64U, res, argR), |
| 1827 | mkAND1( |
| 1828 | binop(Iop_CmpEQ64, oldca, mkU64(1)), |
| 1829 | binop(Iop_CmpEQ64, res, argR) |
| 1830 | ) |
| 1831 | ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1832 | xer_ca |
| 1833 | = unop(Iop_1Uto32, xer_ca); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1834 | break; |
| 1835 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1836 | case /* 7 */ PPCG_FLAG_OP_SUBFC: |
| 1837 | case /* 9 */ PPCG_FLAG_OP_SUBFI: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1838 | /* res <=u argR */ |
| 1839 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1840 | = unop(Iop_1Uto32, binop(Iop_CmpLE64U, res, argR)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1841 | break; |
| 1842 | |
| 1843 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1844 | case /* 10 */ PPCG_FLAG_OP_SRAW: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1845 | /* The shift amount is guaranteed to be in 0 .. 31 inclusive. |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1846 | If it is <= 31, behave like SRAWI; else XER.CA is the sign |
| 1847 | bit of argL. */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1848 | /* This term valid for shift amount < 31 only */ |
| 1849 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1850 | xer_ca |
| 1851 | = binop( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1852 | Iop_And64, |
| 1853 | binop(Iop_Sar64, argL, mkU8(31)), |
| 1854 | binop( Iop_And64, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1855 | argL, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1856 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1857 | binop(Iop_Shl64, mkU64(1), |
| 1858 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1859 | mkU64(1) ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1860 | ) |
| 1861 | ); |
| 1862 | xer_ca |
| 1863 | = IRExpr_Mux0X( |
| 1864 | /* shift amt > 31 ? */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1865 | unop(Iop_1Uto8, binop(Iop_CmpLT64U, mkU64(31), argR)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1866 | /* no -- be like srawi */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1867 | unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1868 | /* yes -- get sign bit of argL */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1869 | unop(Iop_64to32, binop(Iop_Shr64, argL, mkU8(63))) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1870 | ); |
| 1871 | break; |
| 1872 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1873 | case /* 11 */ PPCG_FLAG_OP_SRAWI: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1874 | /* xer_ca is 1 iff src was negative and bits_shifted_out != 0. |
| 1875 | Since the shift amount is known to be in the range 0 .. 31 |
| 1876 | inclusive the following seems viable: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1877 | xer.ca == 1 iff the following is nonzero: |
| 1878 | (argL >>s 31) -- either all 0s or all 1s |
| 1879 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1880 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1881 | xer_ca |
| 1882 | = binop( |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1883 | Iop_And64, |
| 1884 | binop(Iop_Sar64, argL, mkU8(31)), |
| 1885 | binop( Iop_And64, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1886 | argL, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1887 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1888 | binop(Iop_Shl64, mkU64(1), |
| 1889 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1890 | mkU64(1) ) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1891 | ) |
| 1892 | ); |
| 1893 | xer_ca |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1894 | = unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1895 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1896 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1897 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1898 | case /* 12 */ PPCG_FLAG_OP_SRAD: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1899 | /* The shift amount is guaranteed to be in 0 .. 63 inclusive. |
| 1900 | If it is <= 63, behave like SRADI; else XER.CA is the sign |
| 1901 | bit of argL. */ |
| 1902 | /* This term valid for shift amount < 63 only */ |
| 1903 | |
| 1904 | xer_ca |
| 1905 | = binop( |
| 1906 | Iop_And64, |
| 1907 | binop(Iop_Sar64, argL, mkU8(63)), |
| 1908 | binop( Iop_And64, |
| 1909 | argL, |
| 1910 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1911 | binop(Iop_Shl64, mkU64(1), |
| 1912 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1913 | mkU64(1) ) |
| 1914 | ) |
| 1915 | ); |
| 1916 | xer_ca |
| 1917 | = IRExpr_Mux0X( |
| 1918 | /* shift amt > 63 ? */ |
| 1919 | unop(Iop_1Uto8, binop(Iop_CmpLT64U, mkU64(63), argR)), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 1920 | /* no -- be like sradi */ |
| 1921 | unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1922 | /* yes -- get sign bit of argL */ |
| 1923 | unop(Iop_64to32, binop(Iop_Shr64, argL, mkU8(63))) |
| 1924 | ); |
| 1925 | break; |
| 1926 | |
| 1927 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1928 | case /* 13 */ PPCG_FLAG_OP_SRADI: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1929 | /* xer_ca is 1 iff src was negative and bits_shifted_out != 0. |
| 1930 | Since the shift amount is known to be in the range 0 .. 63 |
| 1931 | inclusive, the following seems viable: |
| 1932 | xer.ca == 1 iff the following is nonzero: |
| 1933 | (argL >>s 63) -- either all 0s or all 1s |
| 1934 | & (argL & (1<<argR)-1) -- the stuff shifted out */ |
| 1935 | |
| 1936 | xer_ca |
| 1937 | = binop( |
| 1938 | Iop_And64, |
| 1939 | binop(Iop_Sar64, argL, mkU8(63)), |
| 1940 | binop( Iop_And64, |
| 1941 | argL, |
| 1942 | binop( Iop_Sub64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1943 | binop(Iop_Shl64, mkU64(1), |
| 1944 | unop(Iop_64to8,argR)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1945 | mkU64(1) ) |
| 1946 | ) |
| 1947 | ); |
| 1948 | xer_ca |
| 1949 | = unop(Iop_1Uto32, binop(Iop_CmpNE64, xer_ca, mkU64(0))); |
| 1950 | break; |
| 1951 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1952 | default: |
| 1953 | vex_printf("set_XER_CA: op = %u\n", op); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1954 | vpanic("set_XER_CA(ppc64)"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1955 | } |
| 1956 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1957 | /* xer_ca MUST denote either 0 or 1, no other value allowed */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1958 | putXER_CA( unop(Iop_32to8, xer_ca) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1961 | static void set_XER_CA ( IRType ty, UInt op, IRExpr* res, |
| 1962 | IRExpr* argL, IRExpr* argR, IRExpr* oldca ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1963 | { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 1964 | if (ty == Ity_I32) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1965 | set_XER_CA_32( op, res, argL, argR, oldca ); |
| 1966 | else |
| 1967 | set_XER_CA_64( op, res, argL, argR, oldca ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1970 | |
| 1971 | |
| 1972 | /*------------------------------------------------------------*/ |
| 1973 | /*--- Read/write to guest-state --- */ |
| 1974 | /*------------------------------------------------------------*/ |
| 1975 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 1976 | static IRExpr* /* :: Ity_I32/64 */ getGST ( PPC_GST reg ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1977 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1978 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1979 | switch (reg) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1980 | case PPC_GST_LR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1981 | return IRExpr_Get( OFFB_LR, ty ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1982 | |
| 1983 | case PPC_GST_CTR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1984 | return IRExpr_Get( OFFB_CTR, ty ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1985 | |
| 1986 | case PPC_GST_VRSAVE: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1987 | return IRExpr_Get( OFFB_VRSAVE, Ity_I32 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1988 | |
| 1989 | case PPC_GST_VSCR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 1990 | return binop(Iop_And32, IRExpr_Get( OFFB_VSCR,Ity_I32 ), |
| 1991 | mkU32(MASK_VSCR_VALID)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 1992 | |
| 1993 | case PPC_GST_CR: { |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 1994 | /* Synthesise the entire CR into a single word. Expensive. */ |
| 1995 | # define FIELD(_n) \ |
| 1996 | binop(Iop_Shl32, \ |
| 1997 | unop(Iop_8Uto32, \ |
| 1998 | binop(Iop_Or8, \ |
| 1999 | binop(Iop_And8, getCR321(_n), mkU8(7<<1)), \ |
| 2000 | binop(Iop_And8, getCR0(_n), mkU8(1)) \ |
| 2001 | ) \ |
| 2002 | ), \ |
| 2003 | mkU8(4 * (7-(_n))) \ |
| 2004 | ) |
| 2005 | return binop(Iop_Or32, |
| 2006 | binop(Iop_Or32, |
| 2007 | binop(Iop_Or32, FIELD(0), FIELD(1)), |
| 2008 | binop(Iop_Or32, FIELD(2), FIELD(3)) |
| 2009 | ), |
| 2010 | binop(Iop_Or32, |
| 2011 | binop(Iop_Or32, FIELD(4), FIELD(5)), |
| 2012 | binop(Iop_Or32, FIELD(6), FIELD(7)) |
| 2013 | ) |
| 2014 | ); |
| 2015 | # undef FIELD |
| 2016 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2017 | |
| 2018 | case PPC_GST_XER: |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2019 | return binop(Iop_Or32, |
| 2020 | binop(Iop_Or32, |
| 2021 | binop( Iop_Shl32, getXER_SO32(), mkU8(31)), |
| 2022 | binop( Iop_Shl32, getXER_OV32(), mkU8(30))), |
| 2023 | binop(Iop_Or32, |
| 2024 | binop( Iop_Shl32, getXER_CA32(), mkU8(29)), |
| 2025 | getXER_BC32())); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2026 | |
| 2027 | case PPC_GST_RESVN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2028 | return IRExpr_Get( OFFB_RESVN, ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2029 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2030 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2031 | vex_printf("getGST(ppc): reg = %u", reg); |
| 2032 | vpanic("getGST(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /* Get a masked word from the given reg */ |
| 2037 | static IRExpr* /* ::Ity_I32 */ getGST_masked ( PPC_GST reg, UInt mask ) |
| 2038 | { |
| 2039 | IRTemp val = newTemp(Ity_I32); |
| 2040 | vassert( reg < PPC_GST_MAX ); |
| 2041 | |
| 2042 | switch (reg) { |
| 2043 | |
| 2044 | case PPC_GST_FPSCR: { |
| 2045 | vassert((mask & 0x3) == 0x3 || (mask & 0x3) == 0x0); |
| 2046 | vassert((mask & 0xF000) == 0xF000 || (mask & 0xF000) == 0x0); |
| 2047 | /* all masks now refer to valid fields */ |
| 2048 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2049 | /* Vex-generated code expects the FPSCR to be set as follows: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2050 | all exceptions masked, round-to-nearest. |
| 2051 | This corresponds to a FPSCR value of 0x0. */ |
| 2052 | |
| 2053 | /* We're only keeping track of the rounding mode, |
| 2054 | so if the mask isn't asking for this, just return 0x0 */ |
| 2055 | if (mask & 0x3) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2056 | assign( val, IRExpr_Get( OFFB_FPROUND, Ity_I32 ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2057 | } else { |
| 2058 | assign( val, mkU32(0x0) ); |
| 2059 | } |
| 2060 | break; |
| 2061 | } |
| 2062 | |
| 2063 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2064 | vex_printf("getGST_masked(ppc): reg = %u", reg); |
| 2065 | vpanic("getGST_masked(ppc)"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | if (mask != 0xFFFFFFFF) { |
| 2069 | return binop(Iop_And32, mkexpr(val), mkU32(mask)); |
| 2070 | } else { |
| 2071 | return mkexpr(val); |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | /* Fetch the specified REG[FLD] nibble (as per IBM/hardware notation) |
| 2076 | and return it at the bottom of an I32; the top 27 bits are |
| 2077 | guaranteed to be zero. */ |
| 2078 | static IRExpr* /* ::Ity_I32 */ getGST_field ( PPC_GST reg, UInt fld ) |
| 2079 | { |
| 2080 | UInt shft, mask; |
| 2081 | |
| 2082 | vassert( fld < 8 ); |
| 2083 | vassert( reg < PPC_GST_MAX ); |
| 2084 | |
| 2085 | shft = 4*(7-fld); |
| 2086 | mask = 0xF<<shft; |
| 2087 | |
| 2088 | switch (reg) { |
| 2089 | case PPC_GST_XER: |
| 2090 | vassert(fld ==7); |
| 2091 | return binop(Iop_Or32, |
| 2092 | binop(Iop_Or32, |
| 2093 | binop(Iop_Shl32, getXER_SO32(), mkU8(3)), |
| 2094 | binop(Iop_Shl32, getXER_OV32(), mkU8(2))), |
| 2095 | binop( Iop_Shl32, getXER_CA32(), mkU8(1))); |
| 2096 | break; |
| 2097 | |
| 2098 | default: |
| 2099 | if (shft == 0) |
| 2100 | return getGST_masked( reg, mask ); |
| 2101 | else |
| 2102 | return binop(Iop_Shr32, |
| 2103 | getGST_masked( reg, mask ), |
| 2104 | mkU8(toUChar( shft ))); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | static void putGST ( PPC_GST reg, IRExpr* src ) |
| 2109 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2110 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2111 | IRType ty_src = typeOfIRExpr(irbb->tyenv,src ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2112 | vassert( reg < PPC_GST_MAX ); |
| 2113 | switch (reg) { |
| 2114 | case PPC_GST_CIA: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2115 | vassert( ty_src == ty ); |
| 2116 | stmt( IRStmt_Put( OFFB_CIA, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | case PPC_GST_LR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2119 | vassert( ty_src == ty ); |
| 2120 | stmt( IRStmt_Put( OFFB_LR, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | case PPC_GST_CTR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2123 | vassert( ty_src == ty ); |
| 2124 | stmt( IRStmt_Put( OFFB_CTR, src ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2125 | break; |
| 2126 | case PPC_GST_VRSAVE: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2127 | vassert( ty_src == Ity_I32 ); |
| 2128 | stmt( IRStmt_Put( OFFB_VRSAVE,src)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2129 | break; |
| 2130 | case PPC_GST_VSCR: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2131 | vassert( ty_src == Ity_I32 ); |
| 2132 | stmt( IRStmt_Put( OFFB_VSCR, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2133 | binop(Iop_And32, src, |
| 2134 | mkU32(MASK_VSCR_VALID)) ) ); |
| 2135 | break; |
| 2136 | case PPC_GST_XER: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2137 | vassert( ty_src == Ity_I32 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2138 | putXER_SO( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(31))) ); |
| 2139 | putXER_OV( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(30))) ); |
| 2140 | putXER_CA( unop(Iop_32to8, binop(Iop_Shr32, src, mkU8(29))) ); |
| 2141 | putXER_BC( unop(Iop_32to8, src) ); |
| 2142 | break; |
| 2143 | |
| 2144 | case PPC_GST_EMWARN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2145 | vassert( ty_src == Ity_I32 ); |
| 2146 | stmt( IRStmt_Put( OFFB_EMWARN,src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2147 | break; |
| 2148 | |
| 2149 | case PPC_GST_TISTART: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2150 | vassert( ty_src == ty ); |
| 2151 | stmt( IRStmt_Put( OFFB_TISTART, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2152 | break; |
| 2153 | |
| 2154 | case PPC_GST_TILEN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2155 | vassert( ty_src == ty ); |
| 2156 | stmt( IRStmt_Put( OFFB_TILEN, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | |
| 2159 | case PPC_GST_RESVN: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2160 | vassert( ty_src == ty ); |
| 2161 | stmt( IRStmt_Put( OFFB_RESVN, src) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2162 | break; |
| 2163 | |
| 2164 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2165 | vex_printf("putGST(ppc): reg = %u", reg); |
| 2166 | vpanic("putGST(ppc)"); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2167 | } |
| 2168 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2169 | |
| 2170 | /* Write masked src to the given reg */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2171 | static void putGST_masked ( PPC_GST reg, IRExpr* src, UInt mask ) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2172 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2173 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2174 | vassert( reg < PPC_GST_MAX ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2175 | vassert( typeOfIRExpr(irbb->tyenv,src ) == Ity_I32 ); |
| 2176 | |
| 2177 | switch (reg) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2178 | case PPC_GST_FPSCR: { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2179 | vassert((mask & 0x3) == 0x3 || (mask & 0x3) == 0x0); |
| 2180 | vassert((mask & 0xF000) == 0xF000 || (mask & 0xF000) == 0x0); |
| 2181 | /* all masks now refer to valid fields */ |
| 2182 | |
| 2183 | /* Allow writes to Rounding Mode */ |
| 2184 | if (mask & 0x3) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2185 | stmt( IRStmt_Put( OFFB_FPROUND, |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2186 | binop(Iop_And32, src, mkU32(0x3)) )); |
| 2187 | } |
| 2188 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2189 | /* Give EmWarn for attempted writes to: |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2190 | - Exception Controls |
| 2191 | - Non-IEEE Mode |
| 2192 | */ |
| 2193 | if (mask & 0xFC) { // Exception Control, Non-IEE mode |
| 2194 | VexEmWarn ew = EmWarn_PPC32exns; |
| 2195 | |
| 2196 | /* If any of the src::exception_control bits are actually set, |
| 2197 | side-exit to the next insn, reporting the warning, |
| 2198 | so that Valgrind's dispatcher sees the warning. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2199 | putGST( PPC_GST_EMWARN, mkU32(ew) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2200 | stmt( |
| 2201 | IRStmt_Exit( |
| 2202 | binop(Iop_CmpNE32, mkU32(ew), mkU32(EmWarn_NONE)), |
| 2203 | Ijk_EmWarn, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2204 | mkSzConst( ty, nextInsnAddr()) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2205 | } |
| 2206 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2207 | /* Ignore all other writes */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2208 | break; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2209 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2210 | |
| 2211 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2212 | vex_printf("putGST_masked(ppc): reg = %u", reg); |
| 2213 | vpanic("putGST_masked(ppc)"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2217 | /* Write the least significant nibble of src to the specified |
| 2218 | REG[FLD] (as per IBM/hardware notation). */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2219 | static void putGST_field ( PPC_GST reg, IRExpr* src, UInt fld ) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2220 | { |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 2221 | UInt shft, mask; |
| 2222 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2223 | vassert( typeOfIRExpr(irbb->tyenv,src ) == Ity_I32 ); |
| 2224 | vassert( fld < 8 ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2225 | vassert( reg < PPC_GST_MAX ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2226 | |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 2227 | shft = 4*(7-fld); |
| 2228 | mask = 0xF<<shft; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2229 | |
| 2230 | switch (reg) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2231 | case PPC_GST_CR: |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2232 | putCR0 (fld, binop(Iop_And8, mkU8(1 ), unop(Iop_32to8, src))); |
| 2233 | putCR321(fld, binop(Iop_And8, mkU8(7<<1), unop(Iop_32to8, src))); |
| 2234 | break; |
| 2235 | |
| 2236 | default: |
| 2237 | if (shft == 0) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2238 | putGST_masked( reg, src, mask ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2239 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2240 | putGST_masked( reg, |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 2241 | binop(Iop_Shl32, src, mkU8(toUChar(shft))), |
| 2242 | mask ); |
| 2243 | } |
| 2244 | } |
| 2245 | } |
cerion | 62bec57 | 2005-02-01 21:29:39 +0000 | [diff] [blame] | 2246 | |
cerion | 7622226 | 2005-02-05 13:45:57 +0000 | [diff] [blame] | 2247 | |
| 2248 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2249 | /*------------------------------------------------------------*/ |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 2250 | /*--- Integer Instruction Translation --- */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2251 | /*------------------------------------------------------------*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 2252 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2253 | /* |
| 2254 | Integer Arithmetic Instructions |
| 2255 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 2256 | static Bool dis_int_arith ( UInt theInstr ) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2257 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2258 | /* D-Form, XO-Form */ |
| 2259 | UChar opc1 = ifieldOPC(theInstr); |
| 2260 | UChar rD_addr = ifieldRegDS(theInstr); |
| 2261 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2262 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2263 | UChar rB_addr = ifieldRegB(theInstr); |
| 2264 | UChar flag_OE = ifieldBIT10(theInstr); |
| 2265 | UInt opc2 = ifieldOPClo9(theInstr); |
| 2266 | UChar flag_rC = ifieldBIT0(theInstr); |
| 2267 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2268 | Long simm16 = extend_s_16to64(uimm16); |
| 2269 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2270 | IRTemp rA = newTemp(ty); |
| 2271 | IRTemp rB = newTemp(ty); |
| 2272 | IRTemp rD = newTemp(ty); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2273 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2274 | Bool do_rc = False; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2275 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2276 | assign( rA, getIReg(rA_addr) ); |
| 2277 | assign( rB, getIReg(rB_addr) ); // XO-Form: rD, rA, rB |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2278 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2279 | switch (opc1) { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2280 | /* D-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2281 | case 0x0C: // addic (Add Immediate Carrying, PPC32 p351 |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2282 | DIP("addic r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2283 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2284 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2285 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2286 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2287 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 2288 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2289 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2290 | case 0x0D: // addic. (Add Immediate Carrying and Record, PPC32 p352) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2291 | DIP("addic. r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2292 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2293 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2294 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2295 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2296 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2297 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2298 | flag_rC = 1; |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 2299 | break; |
| 2300 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2301 | case 0x0E: // addi (Add Immediate, PPC32 p350) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2302 | // li rD,val == addi rD,0,val |
| 2303 | // la disp(rA) == addi rD,rA,disp |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2304 | if ( rA_addr == 0 ) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2305 | DIP("li r%u,%d\n", rD_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2306 | assign( rD, mkSzExtendS16(ty, uimm16) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2307 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2308 | DIP("addi r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2309 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2310 | mkSzExtendS16(ty, uimm16) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2311 | } |
| 2312 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2313 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2314 | case 0x0F: // addis (Add Immediate Shifted, PPC32 p353) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2315 | // lis rD,val == addis rD,0,val |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2316 | if ( rA_addr == 0 ) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2317 | DIP("lis r%u,%d\n", rD_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2318 | assign( rD, mkSzExtendS32(ty, uimm16 << 16) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2319 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2320 | DIP("addis r%u,r%u,0x%x\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2321 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2322 | mkSzExtendS32(ty, uimm16 << 16) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2323 | } |
| 2324 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2325 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2326 | case 0x07: // mulli (Multiply Low Immediate, PPC32 p490) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2327 | DIP("mulli r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
| 2328 | if (mode64) |
| 2329 | assign( rD, unop(Iop_128to64, |
| 2330 | binop(Iop_MullS64, mkexpr(rA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2331 | mkSzExtendS16(ty, uimm16))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2332 | else |
| 2333 | assign( rD, unop(Iop_64to32, |
| 2334 | binop(Iop_MullS32, mkexpr(rA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2335 | mkSzExtendS16(ty, uimm16))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2336 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2337 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2338 | case 0x08: // subfic (Subtract from Immediate Carrying, PPC32 p540) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2339 | DIP("subfic r%u,r%u,%d\n", rD_addr, rA_addr, (Int)simm16); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2340 | // rD = simm16 - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2341 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
| 2342 | mkSzExtendS16(ty, uimm16), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2343 | mkexpr(rA)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2344 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFI, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2345 | mkexpr(rD), mkexpr(rA), mkSzExtendS16(ty, uimm16), |
| 2346 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2347 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2348 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2349 | /* XO-Form */ |
| 2350 | case 0x1F: |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2351 | do_rc = True; // All below record to CR |
| 2352 | |
| 2353 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2354 | case 0x10A: // add (Add, PPC32 p347) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2355 | DIP("add%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2356 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2357 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2358 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2359 | mkexpr(rA), mkexpr(rB) ) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2360 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2361 | set_XER_OV( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2362 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2363 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2364 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2365 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2366 | case 0x00A: // addc (Add Carrying, PPC32 p348) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2367 | DIP("addc%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2368 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2369 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2370 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2371 | mkexpr(rA), mkexpr(rB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2372 | set_XER_CA( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2373 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2374 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2375 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2376 | set_XER_OV( ty, PPCG_FLAG_OP_ADD, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2377 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2378 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2381 | case 0x08A: { // adde (Add Extended, PPC32 p349) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2382 | IRTemp old_xer_ca = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2383 | DIP("adde%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2384 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2385 | rD_addr, rA_addr, rB_addr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2386 | // rD = rA + rB + XER[CA] |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2387 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2388 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2389 | binop( mkSzOp(ty, Iop_Add8), |
| 2390 | mkexpr(rB), mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2391 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2392 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2393 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2394 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2395 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2396 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2397 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2398 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2401 | case 0x0EA: { // addme (Add to Minus One Extended, PPC32 p354) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2402 | IRTemp old_xer_ca = newTemp(ty); |
| 2403 | IRExpr *min_one; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2404 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2405 | vex_printf("dis_int_arith(ppc)(addme,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2406 | return False; |
| 2407 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2408 | DIP("addme%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2409 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2410 | rD_addr, rA_addr, rB_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2411 | // rD = rA + (-1) + XER[CA] |
| 2412 | // => Just another form of adde |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2413 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2414 | min_one = mkSzImm(ty, (Long)-1); |
| 2415 | assign( rD, binop( mkSzOp(ty, Iop_Add8), mkexpr(rA), |
| 2416 | binop( mkSzOp(ty, Iop_Add8), |
| 2417 | min_one, mkexpr(old_xer_ca)) )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2418 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2419 | mkexpr(rD), mkexpr(rA), min_one, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2420 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2421 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2422 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2423 | mkexpr(rD), mkexpr(rA), min_one ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2424 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2425 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | case 0x0CA: { // addze (Add to Zero Extended, PPC32 p355) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2429 | IRTemp old_xer_ca = newTemp(ty); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2430 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2431 | vex_printf("dis_int_arith(ppc)(addze,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2432 | return False; |
| 2433 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2434 | DIP("addze%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2435 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2436 | rD_addr, rA_addr, rB_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2437 | // rD = rA + (0) + XER[CA] |
| 2438 | // => Just another form of adde |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2439 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2440 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2441 | mkexpr(rA), mkexpr(old_xer_ca)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2442 | set_XER_CA( ty, PPCG_FLAG_OP_ADDE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2443 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0), |
| 2444 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2445 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2446 | set_XER_OV( ty, PPCG_FLAG_OP_ADDE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2447 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2448 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2449 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2450 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2451 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2452 | case 0x1EB: // divw (Divide Word, PPC32 p388) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2453 | DIP("divw%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2454 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2455 | rD_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2456 | if (mode64) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2457 | /* Note: |
| 2458 | XER settings are mode independent, and reflect the |
| 2459 | overflow of the low-order 32bit result |
| 2460 | CR0[LT|GT|EQ] are undefined if flag_rC && mode64 |
| 2461 | */ |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2462 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2463 | - makes set_CR0 happy */ |
| 2464 | IRExpr* dividend = mk64lo32Sto64( mkexpr(rA) ); |
| 2465 | IRExpr* divisor = mk64lo32Sto64( mkexpr(rB) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2466 | assign( rD, mk64lo32Uto64( binop(Iop_DivS64, dividend, |
| 2467 | divisor) ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2468 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2469 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2470 | mkexpr(rD), dividend, divisor ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2471 | } |
| 2472 | } else { |
| 2473 | assign( rD, binop(Iop_DivS32, mkexpr(rA), mkexpr(rB)) ); |
| 2474 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2475 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2476 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2477 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2478 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2479 | /* Note: |
| 2480 | if (0x8000_0000 / -1) or (x / 0) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2481 | => rD=undef, if(flag_rC) CR7=undef, if(flag_OE) XER_OV=1 |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2482 | => But _no_ exception raised. */ |
| 2483 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2484 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2485 | case 0x1CB: // divwu (Divide Word Unsigned, PPC32 p389) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2486 | DIP("divwu%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2487 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2488 | rD_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2489 | if (mode64) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2490 | /* Note: |
| 2491 | XER settings are mode independent, and reflect the |
| 2492 | overflow of the low-order 32bit result |
| 2493 | CR0[LT|GT|EQ] are undefined if flag_rC && mode64 |
| 2494 | */ |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2495 | IRExpr* dividend = mk64lo32Uto64( mkexpr(rA) ); |
| 2496 | IRExpr* divisor = mk64lo32Uto64( mkexpr(rB) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2497 | assign( rD, mk64lo32Uto64( binop(Iop_DivU64, dividend, |
| 2498 | divisor) ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2499 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2500 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2501 | mkexpr(rD), dividend, divisor ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2502 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2503 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2504 | assign( rD, binop(Iop_DivU32, mkexpr(rA), mkexpr(rB)) ); |
| 2505 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2506 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2507 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2508 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2509 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2510 | /* Note: ditto comment divw, for (x / 0) */ |
| 2511 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2512 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2513 | case 0x04B: // mulhw (Multiply High Word, PPC32 p488) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2514 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2515 | vex_printf("dis_int_arith(ppc)(mulhw,flag_OE)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2516 | return False; |
| 2517 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2518 | DIP("mulhw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2519 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2520 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2521 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2522 | - makes set_CR0 happy */ |
| 2523 | assign( rD, binop(Iop_Sar64, |
| 2524 | binop(Iop_Mul64, |
| 2525 | mk64lo32Sto64( mkexpr(rA) ), |
| 2526 | mk64lo32Sto64( mkexpr(rB) )), |
| 2527 | mkU8(32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2528 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2529 | assign( rD, unop(Iop_64HIto32, |
| 2530 | binop(Iop_MullS32, |
| 2531 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2532 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2533 | break; |
cerion | c19d5e1 | 2005-02-01 15:56:25 +0000 | [diff] [blame] | 2534 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2535 | case 0x00B: // mulhwu (Multiply High Word Unsigned, PPC32 p489) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2536 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2537 | vex_printf("dis_int_arith(ppc)(mulhwu,flag_OE)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2538 | return False; |
| 2539 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2540 | DIP("mulhwu%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2541 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2542 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2543 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2544 | - makes set_CR0 happy */ |
| 2545 | assign( rD, binop(Iop_Sar64, |
| 2546 | binop(Iop_Mul64, |
| 2547 | mk64lo32Uto64( mkexpr(rA) ), |
| 2548 | mk64lo32Uto64( mkexpr(rB) ) ), |
| 2549 | mkU8(32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2550 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2551 | assign( rD, unop(Iop_64HIto32, |
| 2552 | binop(Iop_MullU32, |
| 2553 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2554 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2555 | break; |
| 2556 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2557 | case 0x0EB: // mullw (Multiply Low Word, PPC32 p491) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2558 | DIP("mullw%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2559 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2560 | rD_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2561 | if (mode64) { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2562 | /* rD[hi32] are undefined: setting them to sign of lo32 |
| 2563 | - set_XER_OV() and set_CR0() depend on this */ |
| 2564 | IRExpr *a = unop(Iop_64to32, mkexpr(rA) ); |
| 2565 | IRExpr *b = unop(Iop_64to32, mkexpr(rB) ); |
| 2566 | assign( rD, binop(Iop_MullS32, a, b) ); |
| 2567 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2568 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2569 | mkexpr(rD), |
| 2570 | unop(Iop_32Uto64, a), unop(Iop_32Uto64, b) ); |
| 2571 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2572 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2573 | assign( rD, unop(Iop_64to32, |
| 2574 | binop(Iop_MullU32, |
| 2575 | mkexpr(rA), mkexpr(rB))) ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2576 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2577 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2578 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2579 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2580 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2581 | break; |
cerion | c19d5e1 | 2005-02-01 15:56:25 +0000 | [diff] [blame] | 2582 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2583 | case 0x068: // neg (Negate, PPC32 p493) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2584 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2585 | vex_printf("dis_int_arith(ppc)(neg,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2586 | return False; |
| 2587 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2588 | DIP("neg%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2589 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2590 | rD_addr, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2591 | // rD = (~rA) + 1 |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2592 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2593 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA) ), |
| 2594 | mkSzImm(ty, 1)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2595 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2596 | set_XER_OV( ty, PPCG_FLAG_OP_NEG, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2597 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2598 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2599 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2600 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2601 | case 0x028: // subf (Subtract From, PPC32 p537) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2602 | DIP("subf%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2603 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2604 | rD_addr, rA_addr, rB_addr); |
cerion | 0190847 | 2005-02-25 16:43:08 +0000 | [diff] [blame] | 2605 | // rD = rB - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2606 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2607 | mkexpr(rB), mkexpr(rA)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2608 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2609 | set_XER_OV( ty, PPCG_FLAG_OP_SUBF, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2610 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2611 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2612 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2613 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2614 | case 0x008: // subfc (Subtract from Carrying, PPC32 p538) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2615 | DIP("subfc%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2616 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2617 | rD_addr, rA_addr, rB_addr); |
cerion | 0190847 | 2005-02-25 16:43:08 +0000 | [diff] [blame] | 2618 | // rD = rB - rA |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2619 | assign( rD, binop( mkSzOp(ty, Iop_Sub8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2620 | mkexpr(rB), mkexpr(rA)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2621 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFC, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2622 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2623 | mkSzImm(ty, 0)/*old xer.ca, which is ignored*/ ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2624 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2625 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFC, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2626 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2627 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2630 | case 0x088: {// subfe (Subtract from Extended, PPC32 p539) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2631 | IRTemp old_xer_ca = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2632 | DIP("subfe%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2633 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2634 | rD_addr, rA_addr, rB_addr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2635 | // rD = (log not)rA + rB + XER[CA] |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2636 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2637 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2638 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA)), |
| 2639 | binop( mkSzOp(ty, Iop_Add8), |
| 2640 | mkexpr(rB), mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2641 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2642 | mkexpr(rD), mkexpr(rA), mkexpr(rB), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2643 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2644 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2645 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2646 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2647 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2648 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2651 | case 0x0E8: { // subfme (Subtract from -1 Extended, PPC32 p541) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2652 | IRTemp old_xer_ca = newTemp(ty); |
| 2653 | IRExpr *min_one; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2654 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2655 | vex_printf("dis_int_arith(ppc)(subfme,rB_addr)\n"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2656 | return False; |
| 2657 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2658 | DIP("subfme%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2659 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2660 | rD_addr, rA_addr); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2661 | // rD = (log not)rA + (-1) + XER[CA] |
| 2662 | // => Just another form of subfe |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2663 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2664 | min_one = mkSzImm(ty, (Long)-1); |
| 2665 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2666 | unop( mkSzOp(ty, Iop_Not8), mkexpr(rA)), |
| 2667 | binop( mkSzOp(ty, Iop_Add8), |
| 2668 | min_one, mkexpr(old_xer_ca))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2669 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2670 | mkexpr(rD), mkexpr(rA), min_one, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2671 | mkexpr(old_xer_ca) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2672 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2673 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2674 | mkexpr(rD), mkexpr(rA), min_one ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 2675 | } |
| 2676 | break; |
| 2677 | } |
| 2678 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2679 | case 0x0C8: { // subfze (Subtract from Zero Extended, PPC32 p542) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2680 | IRTemp old_xer_ca = newTemp(ty); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2681 | if (rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2682 | vex_printf("dis_int_arith(ppc)(subfze,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2683 | return False; |
| 2684 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2685 | DIP("subfze%s%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2686 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2687 | rD_addr, rA_addr); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2688 | // rD = (log not)rA + (0) + XER[CA] |
| 2689 | // => Just another form of subfe |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2690 | assign( old_xer_ca, mkSzWiden32(ty, getXER_CA32(), False) ); |
| 2691 | assign( rD, binop( mkSzOp(ty, Iop_Add8), |
| 2692 | unop( mkSzOp(ty, Iop_Not8), |
| 2693 | mkexpr(rA)), mkexpr(old_xer_ca)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2694 | set_XER_CA( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2695 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0), |
| 2696 | mkexpr(old_xer_ca) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2697 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2698 | set_XER_OV( ty, PPCG_FLAG_OP_SUBFE, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2699 | mkexpr(rD), mkexpr(rA), mkSzImm(ty, 0) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2700 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2701 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 2702 | } |
cerion | ae69462 | 2005-01-28 17:52:47 +0000 | [diff] [blame] | 2703 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2704 | |
| 2705 | /* 64bit Arithmetic */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2706 | case 0x49: // mulhd (Multiply High DWord, PPC64 p539) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2707 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2708 | vex_printf("dis_int_arith(ppc)(mulhd,flagOE)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2709 | return False; |
| 2710 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2711 | DIP("mulhd%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2712 | rD_addr, rA_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2713 | assign( rD, unop(Iop_128HIto64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2714 | binop(Iop_MullS64, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2715 | mkexpr(rA), mkexpr(rB))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2716 | |
| 2717 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2718 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2719 | case 0x9: // mulhdu (Multiply High DWord Unsigned, PPC64 p540) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2720 | if (flag_OE != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2721 | vex_printf("dis_int_arith(ppc)(mulhdu,flagOE)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2722 | return False; |
| 2723 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2724 | DIP("mulhdu%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2725 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2726 | assign( rD, unop(Iop_128HIto64, |
| 2727 | binop(Iop_MullU64, |
| 2728 | mkexpr(rA), mkexpr(rB))) ); |
| 2729 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2730 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2731 | case 0xE9: // mulld (Multiply Low DWord, PPC64 p543) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2732 | DIP("mulld%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2733 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2734 | rD_addr, rA_addr, rB_addr); |
| 2735 | assign( rD, binop(Iop_Mul64, mkexpr(rA), mkexpr(rB)) ); |
| 2736 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2737 | set_XER_OV( ty, PPCG_FLAG_OP_MULLW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2738 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2739 | } |
| 2740 | break; |
| 2741 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2742 | case 0x1E9: // divd (Divide DWord, PPC64 p419) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2743 | DIP("divd%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2744 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2745 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2746 | assign( rD, binop(Iop_DivS64, mkexpr(rA), mkexpr(rB)) ); |
| 2747 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2748 | set_XER_OV( ty, PPCG_FLAG_OP_DIVW, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2749 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2750 | } |
| 2751 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2752 | /* Note: |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2753 | if (0x8000_0000_0000_0000 / -1) or (x / 0) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2754 | => rD=undef, if(flag_rC) CR7=undef, if(flag_OE) XER_OV=1 |
| 2755 | => But _no_ exception raised. */ |
| 2756 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2757 | case 0x1C9: // divdu (Divide DWord Unsigned, PPC64 p420) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2758 | DIP("divdu%s%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2759 | flag_OE ? "o" : "", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2760 | rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2761 | assign( rD, binop(Iop_DivU64, mkexpr(rA), mkexpr(rB)) ); |
| 2762 | if (flag_OE) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2763 | set_XER_OV( ty, PPCG_FLAG_OP_DIVWU, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 2764 | mkexpr(rD), mkexpr(rA), mkexpr(rB) ); |
| 2765 | } |
| 2766 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2767 | /* Note: ditto comment divd, for (x / 0) */ |
| 2768 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2769 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2770 | vex_printf("dis_int_arith(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2771 | return False; |
| 2772 | } |
| 2773 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 2774 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2775 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2776 | vex_printf("dis_int_arith(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2777 | return False; |
| 2778 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2779 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2780 | putIReg( rD_addr, mkexpr(rD) ); |
| 2781 | |
| 2782 | if (do_rc && flag_rC) { |
| 2783 | set_CR0( mkexpr(rD) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2784 | } |
| 2785 | return True; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | |
| 2789 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 2790 | /* |
| 2791 | Integer Compare Instructions |
| 2792 | */ |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2793 | static Bool dis_int_cmp ( UInt theInstr ) |
| 2794 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2795 | /* D-Form, X-Form */ |
| 2796 | UChar opc1 = ifieldOPC(theInstr); |
| 2797 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 2798 | UChar b22 = toUChar( IFIELD( theInstr, 22, 1 ) ); |
| 2799 | UChar flag_L = toUChar( IFIELD( theInstr, 21, 1 ) ); |
| 2800 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2801 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2802 | UChar rB_addr = ifieldRegB(theInstr); |
| 2803 | UInt opc2 = ifieldOPClo10(theInstr); |
| 2804 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2805 | |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2806 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2807 | IRExpr *a = getIReg(rA_addr); |
| 2808 | IRExpr *b; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2809 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2810 | if (!mode64 && flag_L==1) { // L==1 invalid for 32 bit. |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2811 | vex_printf("dis_int_cmp(ppc)(flag_L)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2812 | return False; |
| 2813 | } |
| 2814 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2815 | if (b22 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2816 | vex_printf("dis_int_cmp(ppc)(b22)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2817 | return False; |
| 2818 | } |
| 2819 | |
| 2820 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2821 | case 0x0B: // cmpi (Compare Immediate, PPC32 p368) |
| 2822 | DIP("cmpi cr%u,%u,r%u,%d\n", crfD, flag_L, rA_addr, |
| 2823 | (Int)extend_s_16to32(uimm16)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2824 | b = mkSzExtendS16( ty, uimm16 ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2825 | if (flag_L == 1) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2826 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2827 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2828 | a = mkSzNarrow32( ty, a ); |
| 2829 | b = mkSzNarrow32( ty, b ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2830 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32S, a, b))); |
| 2831 | } |
| 2832 | putCR0( crfD, getXER_SO() ); |
| 2833 | break; |
| 2834 | |
| 2835 | case 0x0A: // cmpli (Compare Logical Immediate, PPC32 p370) |
| 2836 | DIP("cmpli cr%u,%u,r%u,0x%x\n", crfD, flag_L, rA_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2837 | b = mkSzImm( ty, uimm16 ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2838 | if (flag_L == 1) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2839 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2840 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2841 | a = mkSzNarrow32( ty, a ); |
| 2842 | b = mkSzNarrow32( ty, b ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2843 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32U, a, b))); |
| 2844 | } |
| 2845 | putCR0( crfD, getXER_SO() ); |
| 2846 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2847 | |
| 2848 | /* X Form */ |
| 2849 | case 0x1F: |
| 2850 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2851 | vex_printf("dis_int_cmp(ppc)(0x1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2852 | return False; |
| 2853 | } |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2854 | b = getIReg(rB_addr); |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2855 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2856 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2857 | case 0x000: // cmp (Compare, PPC32 p367) |
| 2858 | DIP("cmp cr%u,%u,r%u,r%u\n", crfD, flag_L, rA_addr, rB_addr); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2859 | if (flag_L == 1) { |
| 2860 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2861 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2862 | a = mkSzNarrow32( ty, a ); |
| 2863 | b = mkSzNarrow32( ty, b ); |
| 2864 | putCR321(crfD, unop(Iop_32to8,binop(Iop_CmpORD32S, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2865 | } |
| 2866 | putCR0( crfD, getXER_SO() ); |
| 2867 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2868 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2869 | case 0x020: // cmpl (Compare Logical, PPC32 p369) |
| 2870 | DIP("cmpl cr%u,%u,r%u,r%u\n", crfD, flag_L, rA_addr, rB_addr); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2871 | if (flag_L == 1) { |
| 2872 | putCR321(crfD, unop(Iop_64to8, binop(Iop_CmpORD64U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2873 | } else { |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 2874 | a = mkSzNarrow32( ty, a ); |
| 2875 | b = mkSzNarrow32( ty, b ); |
| 2876 | putCR321(crfD, unop(Iop_32to8, binop(Iop_CmpORD32U, a, b))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2877 | } |
| 2878 | putCR0( crfD, getXER_SO() ); |
| 2879 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2880 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2881 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2882 | vex_printf("dis_int_cmp(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2883 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2884 | } |
| 2885 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2886 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2887 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2888 | vex_printf("dis_int_cmp(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2889 | return False; |
| 2890 | } |
| 2891 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2892 | return True; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 2896 | /* |
| 2897 | Integer Logical Instructions |
| 2898 | */ |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2899 | static Bool dis_int_logic ( UInt theInstr ) |
| 2900 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2901 | /* D-Form, X-Form */ |
| 2902 | UChar opc1 = ifieldOPC(theInstr); |
| 2903 | UChar rS_addr = ifieldRegDS(theInstr); |
| 2904 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2905 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2906 | UChar rB_addr = ifieldRegB(theInstr); |
| 2907 | UInt opc2 = ifieldOPClo10(theInstr); |
| 2908 | UChar flag_rC = ifieldBIT0(theInstr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2909 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2910 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 2911 | IRTemp rS = newTemp(ty); |
| 2912 | IRTemp rA = newTemp(ty); |
| 2913 | IRTemp rB = newTemp(ty); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2914 | IRExpr* irx; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2915 | Bool do_rc = False; |
| 2916 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2917 | assign( rS, getIReg(rS_addr) ); |
| 2918 | assign( rB, getIReg(rB_addr) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2919 | |
| 2920 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2921 | case 0x1C: // andi. (AND Immediate, PPC32 p358) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2922 | DIP("andi. r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2923 | assign( rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 2924 | mkSzImm(ty, uimm16)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2925 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2926 | flag_rC = 1; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2929 | case 0x1D: // andis. (AND Immediate Shifted, PPC32 p359) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2930 | DIP("andis r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2931 | assign( rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 2932 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2933 | do_rc = True; // Always record to CR |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 2934 | flag_rC = 1; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2935 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2936 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2937 | case 0x18: // ori (OR Immediate, PPC32 p497) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2938 | DIP("ori r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2939 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 2940 | mkSzImm(ty, uimm16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2941 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 2942 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2943 | case 0x19: // oris (OR Immediate Shifted, PPC32 p498) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2944 | DIP("oris r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2945 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 2946 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2947 | break; |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 2948 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2949 | case 0x1A: // xori (XOR Immediate, PPC32 p550) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2950 | DIP("xori r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2951 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), mkexpr(rS), |
| 2952 | mkSzImm(ty, uimm16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2953 | break; |
cerion | 3867460 | 2005-02-08 02:19:25 +0000 | [diff] [blame] | 2954 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 2955 | case 0x1B: // xoris (XOR Immediate Shifted, PPC32 p551) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2956 | DIP("xoris r%u,r%u,0x%x\n", rA_addr, rS_addr, uimm16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2957 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), mkexpr(rS), |
| 2958 | mkSzImm(ty, uimm16 << 16)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2959 | break; |
cerion | aabdfbf | 2005-01-29 12:56:15 +0000 | [diff] [blame] | 2960 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2961 | /* X Form */ |
| 2962 | case 0x1F: |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 2963 | do_rc = True; // All below record to CR |
| 2964 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 2965 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2966 | case 0x01C: // and (AND, PPC32 p356) |
| 2967 | DIP("and%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2968 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2969 | assign(rA, binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2970 | mkexpr(rS), mkexpr(rB))); |
| 2971 | break; |
| 2972 | |
| 2973 | case 0x03C: // andc (AND with Complement, PPC32 p357) |
| 2974 | DIP("andc%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2975 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 2976 | assign(rA, binop( mkSzOp(ty, Iop_And8), mkexpr(rS), |
| 2977 | unop( mkSzOp(ty, Iop_Not8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2978 | mkexpr(rB)))); |
| 2979 | break; |
| 2980 | |
| 2981 | case 0x01A: { // cntlzw (Count Leading Zeros Word, PPC32 p371) |
| 2982 | IRExpr* lo32; |
| 2983 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2984 | vex_printf("dis_int_logic(ppc)(cntlzw,rB_addr)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2985 | return False; |
| 2986 | } |
| 2987 | DIP("cntlzw%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2988 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 2989 | |
| 2990 | // mode64: count in low word only |
| 2991 | lo32 = mode64 ? unop(Iop_64to32, mkexpr(rS)) : mkexpr(rS); |
| 2992 | |
| 2993 | // Iop_Clz32 undefined for arg==0, so deal with that case: |
| 2994 | irx = binop(Iop_CmpNE32, lo32, mkU32(0)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 2995 | assign(rA, mkSzWiden32(ty, |
| 2996 | IRExpr_Mux0X( unop(Iop_1Uto8, irx), |
| 2997 | mkU32(32), |
| 2998 | unop(Iop_Clz32, lo32)), |
| 2999 | False)); |
| 3000 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3001 | // TODO: alternatively: assign(rA, verbose_Clz32(rS)); |
| 3002 | break; |
| 3003 | } |
| 3004 | |
| 3005 | case 0x11C: // eqv (Equivalent, PPC32 p396) |
| 3006 | DIP("eqv%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3007 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3008 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3009 | binop( mkSzOp(ty, Iop_Xor8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3010 | mkexpr(rS), mkexpr(rB))) ); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 3011 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3012 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3013 | case 0x3BA: // extsb (Extend Sign Byte, PPC32 p397 |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3014 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3015 | vex_printf("dis_int_logic(ppc)(extsb,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3016 | return False; |
| 3017 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3018 | DIP("extsb%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3019 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3020 | if (mode64) |
| 3021 | assign( rA, unop(Iop_8Sto64, unop(Iop_64to8, mkexpr(rS))) ); |
| 3022 | else |
| 3023 | assign( rA, unop(Iop_8Sto32, unop(Iop_32to8, mkexpr(rS))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3024 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3025 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3026 | case 0x39A: // extsh (Extend Sign Half Word, PPC32 p398) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3027 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3028 | vex_printf("dis_int_logic(ppc)(extsh,rB_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3029 | return False; |
| 3030 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3031 | DIP("extsh%s r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3032 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3033 | if (mode64) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3034 | assign( rA, unop(Iop_16Sto64, |
| 3035 | unop(Iop_64to16, mkexpr(rS))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3036 | else |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3037 | assign( rA, unop(Iop_16Sto32, |
| 3038 | unop(Iop_32to16, mkexpr(rS))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3039 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3040 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3041 | case 0x1DC: // nand (NAND, PPC32 p492) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3042 | DIP("nand%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3043 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3044 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3045 | binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3046 | mkexpr(rS), mkexpr(rB))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3047 | break; |
| 3048 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3049 | case 0x07C: // nor (NOR, PPC32 p494) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3050 | DIP("nor%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3051 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3052 | assign( rA, unop( mkSzOp(ty, Iop_Not8), |
| 3053 | binop( mkSzOp(ty, Iop_Or8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3054 | mkexpr(rS), mkexpr(rB))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3055 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3056 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3057 | case 0x1BC: // or (OR, PPC32 p495) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3058 | if ((!flag_rC) && rS_addr == rB_addr) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3059 | DIP("mr r%u,r%u\n", rA_addr, rS_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3060 | assign( rA, mkexpr(rS) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3061 | } else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3062 | DIP("or%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3063 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3064 | assign( rA, binop( mkSzOp(ty, Iop_Or8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3065 | mkexpr(rS), mkexpr(rB)) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3066 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3067 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3068 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3069 | case 0x19C: // orc (OR with Complement, PPC32 p496) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3070 | DIP("orc%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3071 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3072 | assign( rA, binop( mkSzOp(ty, Iop_Or8), mkexpr(rS), |
| 3073 | unop(mkSzOp(ty, Iop_Not8), mkexpr(rB)))); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3074 | break; |
| 3075 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3076 | case 0x13C: // xor (XOR, PPC32 p549) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3077 | DIP("xor%s r%u,r%u,r%u\n", |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3078 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3079 | assign( rA, binop( mkSzOp(ty, Iop_Xor8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3080 | mkexpr(rS), mkexpr(rB)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3081 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3082 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3083 | |
| 3084 | /* 64bit Integer Logical Instructions */ |
| 3085 | case 0x3DA: // extsw (Extend Sign Word, PPC64 p430) |
| 3086 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3087 | vex_printf("dis_int_logic(ppc)(extsw,rB_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3088 | return False; |
| 3089 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3090 | DIP("extsw%s r%u,r%u\n", flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3091 | assign(rA, unop(Iop_32Sto64, unop(Iop_64to32, mkexpr(rS)))); |
| 3092 | break; |
| 3093 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3094 | case 0x03A: // cntlzd (Count Leading Zeros DWord, PPC64 p401) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3095 | if (rB_addr!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3096 | vex_printf("dis_int_logic(ppc)(cntlzd,rB_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3097 | return False; |
| 3098 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3099 | DIP("cntlzd%s r%u,r%u\n", |
| 3100 | flag_rC ? ".":"", rA_addr, rS_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3101 | // Iop_Clz64 undefined for arg==0, so deal with that case: |
| 3102 | irx = binop(Iop_CmpNE64, mkexpr(rS), mkU64(0)); |
| 3103 | assign(rA, IRExpr_Mux0X( unop(Iop_1Uto8, irx), |
| 3104 | mkU64(64), |
| 3105 | unop(Iop_Clz64, mkexpr(rS)) )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3106 | // TODO: alternatively: assign(rA, verbose_Clz64(rS)); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3107 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3108 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3109 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3110 | vex_printf("dis_int_logic(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3111 | return False; |
| 3112 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3113 | break; |
| 3114 | |
| 3115 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3116 | vex_printf("dis_int_logic(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3117 | return False; |
| 3118 | } |
cerion | 70e2412 | 2005-03-16 00:27:37 +0000 | [diff] [blame] | 3119 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3120 | putIReg( rA_addr, mkexpr(rA) ); |
| 3121 | |
| 3122 | if (do_rc && flag_rC) { |
| 3123 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3124 | } |
| 3125 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | |
| 3129 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3130 | /* |
| 3131 | Integer Rotate Instructions |
| 3132 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3133 | static Bool dis_int_rot ( UInt theInstr ) |
| 3134 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3135 | /* M-Form, MDS-Form */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3136 | UChar opc1 = ifieldOPC(theInstr); |
| 3137 | UChar rS_addr = ifieldRegDS(theInstr); |
| 3138 | UChar rA_addr = ifieldRegA(theInstr); |
| 3139 | UChar rB_addr = ifieldRegB(theInstr); |
| 3140 | UChar sh_imm = rB_addr; |
| 3141 | UChar MaskBeg = toUChar( IFIELD( theInstr, 6, 5 ) ); |
| 3142 | UChar MaskEnd = toUChar( IFIELD( theInstr, 1, 5 ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3143 | UChar msk_imm = toUChar( IFIELD( theInstr, 5, 6 ) ); |
| 3144 | UChar opc2 = toUChar( IFIELD( theInstr, 2, 3 ) ); |
| 3145 | UChar b1 = ifieldBIT1(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3146 | UChar flag_rC = ifieldBIT0(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3147 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3148 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3149 | IRTemp rS = newTemp(ty); |
| 3150 | IRTemp rA = newTemp(ty); |
| 3151 | IRTemp rB = newTemp(ty); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3152 | IRTemp rot = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3153 | IRExpr *r; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3154 | UInt mask32; |
| 3155 | ULong mask64; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3156 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3157 | assign( rS, getIReg(rS_addr) ); |
| 3158 | assign( rB, getIReg(rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3159 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3160 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3161 | case 0x14: { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3162 | // rlwimi (Rotate Left Word Imm then Mask Insert, PPC32 p500) |
| 3163 | DIP("rlwimi%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3164 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3165 | if (mode64) { |
| 3166 | // tmp32 = (ROTL(rS_Lo32, Imm) |
| 3167 | // rA = ((tmp32 || tmp32) & mask64) | (rA & ~mask64) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3168 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3169 | r = ROTL( unop(Iop_64to32, mkexpr(rS) ), mkU8(sh_imm) ); |
| 3170 | r = unop(Iop_32Uto64, r); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3171 | assign( rot, binop(Iop_Or64, r, |
| 3172 | binop(Iop_Shl64, r, mkU8(32))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3173 | assign( rA, |
| 3174 | binop(Iop_Or64, |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3175 | binop(Iop_And64, mkexpr(rot), mkU64(mask64)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3176 | binop(Iop_And64, getIReg(rA_addr), mkU64(~mask64))) ); |
sewardj | 26b3320 | 2005-10-07 09:45:16 +0000 | [diff] [blame] | 3177 | } |
| 3178 | else { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3179 | // rA = (ROTL(rS, Imm) & mask) | (rA & ~mask); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3180 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
| 3181 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3182 | assign( rA, |
| 3183 | binop(Iop_Or32, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3184 | binop(Iop_And32, mkU32(mask32), r), |
| 3185 | binop(Iop_And32, getIReg(rA_addr), mkU32(~mask32))) ); |
sewardj | 26b3320 | 2005-10-07 09:45:16 +0000 | [diff] [blame] | 3186 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3187 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3188 | } |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 3189 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3190 | case 0x15: { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3191 | // rlwinm (Rotate Left Word Imm then AND with Mask, PPC32 p501) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3192 | vassert(MaskBeg < 32); |
| 3193 | vassert(MaskEnd < 32); |
| 3194 | vassert(sh_imm < 32); |
| 3195 | |
| 3196 | if (mode64) { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3197 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3198 | DIP("rlwinm%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3199 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3200 | // tmp32 = (ROTL(rS_Lo32, Imm) |
| 3201 | // rA = ((tmp32 || tmp32) & mask64) |
| 3202 | r = ROTL( unop(Iop_64to32, mkexpr(rS) ), mkU8(sh_imm) ); |
| 3203 | r = unop(Iop_32Uto64, r); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3204 | assign( rot, binop(Iop_Or64, r, |
| 3205 | binop(Iop_Shl64, r, mkU8(32))) ); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3206 | assign( rA, binop(Iop_And64, mkexpr(rot), mkU64(mask64)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3207 | } |
| 3208 | else { |
| 3209 | if (MaskBeg == 0 && sh_imm+MaskEnd == 31) { |
| 3210 | /* Special-case the ,n,0,31-n form as that is just n-bit |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3211 | shift left, PPC32 p501 */ |
| 3212 | DIP("slwi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3213 | rA_addr, rS_addr, sh_imm); |
| 3214 | assign( rA, binop(Iop_Shl32, mkexpr(rS), mkU8(sh_imm)) ); |
| 3215 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3216 | else if (MaskEnd == 31 && sh_imm+MaskBeg == 32) { |
| 3217 | /* Special-case the ,32-n,n,31 form as that is just n-bit |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3218 | unsigned shift right, PPC32 p501 */ |
| 3219 | DIP("srwi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3220 | rA_addr, rS_addr, sh_imm); |
| 3221 | assign( rA, binop(Iop_Shr32, mkexpr(rS), mkU8(MaskBeg)) ); |
| 3222 | } |
| 3223 | else { |
| 3224 | /* General case. */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3225 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3226 | DIP("rlwinm%s r%u,r%u,%d,%d,%d\n", flag_rC ? ".":"", |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3227 | rA_addr, rS_addr, sh_imm, MaskBeg, MaskEnd); |
| 3228 | // rA = ROTL(rS, Imm) & mask |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3229 | assign( rA, binop(Iop_And32, |
| 3230 | ROTL(mkexpr(rS), mkU8(sh_imm)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3231 | mkU32(mask32)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3232 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3233 | } |
sewardj | c965953 | 2005-07-21 21:33:57 +0000 | [diff] [blame] | 3234 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | case 0x17: { |
| 3238 | // rlwnm (Rotate Left Word then AND with Mask, PPC32 p503 |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3239 | DIP("rlwnm%s r%u,r%u,r%u,%d,%d\n", flag_rC ? ".":"", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3240 | rA_addr, rS_addr, rB_addr, MaskBeg, MaskEnd); |
| 3241 | if (mode64) { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3242 | mask64 = MASK64(31-MaskEnd, 31-MaskBeg); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3243 | /* weird insn alert! |
| 3244 | tmp32 = (ROTL(rS_Lo32, rB[0-4]) |
| 3245 | rA = ((tmp32 || tmp32) & mask64) |
| 3246 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3247 | // note, ROTL does the masking, so we don't do it here |
| 3248 | r = ROTL( unop(Iop_64to32, mkexpr(rS)), |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3249 | unop(Iop_64to8, mkexpr(rB)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3250 | r = unop(Iop_32Uto64, r); |
cerion | bb01b7c | 2005-12-16 13:40:18 +0000 | [diff] [blame] | 3251 | assign(rot, binop(Iop_Or64, r, binop(Iop_Shl64, r, mkU8(32)))); |
| 3252 | assign( rA, binop(Iop_And64, mkexpr(rot), mkU64(mask64)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3253 | } else { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3254 | mask32 = MASK32(31-MaskEnd, 31-MaskBeg); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3255 | // rA = ROTL(rS, rB[0-4]) & mask |
| 3256 | // note, ROTL does the masking, so we don't do it here |
| 3257 | assign( rA, binop(Iop_And32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3258 | ROTL(mkexpr(rS), |
| 3259 | unop(Iop_32to8, mkexpr(rB))), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3260 | mkU32(mask32)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3261 | } |
| 3262 | break; |
| 3263 | } |
cerion | 45b70ff | 2005-01-31 17:03:25 +0000 | [diff] [blame] | 3264 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3265 | |
| 3266 | /* 64bit Integer Rotates */ |
| 3267 | case 0x1E: { |
| 3268 | msk_imm = ((msk_imm & 1) << 5) | (msk_imm >> 1); |
| 3269 | sh_imm |= b1 << 5; |
| 3270 | |
| 3271 | vassert( msk_imm < 64 ); |
| 3272 | vassert( sh_imm < 64 ); |
| 3273 | |
| 3274 | switch (opc2) { |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3275 | case 0x4: { |
| 3276 | /* r = ROTL64( rS, rB_lo6) */ |
| 3277 | r = ROTL( mkexpr(rS), unop(Iop_64to8, mkexpr(rB)) ); |
| 3278 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3279 | if (b1 == 0) { // rldcl (Rotl DWord, Clear Left, PPC64 p555) |
| 3280 | DIP("rldcl%s r%u,r%u,r%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3281 | rA_addr, rS_addr, rB_addr, msk_imm); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3282 | // note, ROTL does the masking, so we don't do it here |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3283 | mask64 = MASK64(0, 63-msk_imm); |
| 3284 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3285 | break; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3286 | } else { // rldcr (Rotl DWord, Clear Right, PPC64 p556) |
| 3287 | DIP("rldcr%s r%u,r%u,r%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3288 | rA_addr, rS_addr, rB_addr, msk_imm); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3289 | mask64 = MASK64(63-msk_imm, 63); |
| 3290 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3291 | break; |
| 3292 | } |
| 3293 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3294 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3295 | case 0x2: // rldic (Rotl DWord Imm, Clear, PPC64 p557) |
| 3296 | DIP("rldic%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3297 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3298 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3299 | mask64 = MASK64(sh_imm, 63-msk_imm); |
| 3300 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3301 | break; |
| 3302 | // later: deal with special case: (msk_imm==0) => SHL(sh_imm) |
| 3303 | /* |
| 3304 | Hmm... looks like this'll do the job more simply: |
| 3305 | r = SHL(rS, sh_imm) |
| 3306 | m = ~(1 << (63-msk_imm)) |
| 3307 | assign(rA, r & m); |
| 3308 | */ |
| 3309 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3310 | case 0x0: // rldicl (Rotl DWord Imm, Clear Left, PPC64 p558) |
| 3311 | DIP("rldicl%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3312 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3313 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3314 | mask64 = MASK64(0, 63-msk_imm); |
| 3315 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3316 | break; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3317 | /* later: deal with special case: |
| 3318 | (msk_imm + sh_imm == 63) => SHR(63 - sh_imm) */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3319 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3320 | case 0x1: // rldicr (Rotl DWord Imm, Clear Right, PPC64 p559) |
| 3321 | DIP("rldicr%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3322 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3323 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3324 | mask64 = MASK64(63-msk_imm, 63); |
| 3325 | assign( rA, binop(Iop_And64, r, mkU64(mask64)) ); |
| 3326 | break; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3327 | /* later: deal with special case: |
| 3328 | (msk_imm == sh_imm) => SHL(sh_imm) */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3329 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3330 | case 0x3: { // rldimi (Rotl DWord Imm, Mask Insert, PPC64 p560) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3331 | IRTemp rA_orig = newTemp(ty); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3332 | DIP("rldimi%s r%u,r%u,%u,%u\n", flag_rC ? ".":"", |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3333 | rA_addr, rS_addr, sh_imm, msk_imm); |
| 3334 | r = ROTL(mkexpr(rS), mkU8(sh_imm)); |
| 3335 | mask64 = MASK64(sh_imm, 63-msk_imm); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3336 | assign( rA_orig, getIReg(rA_addr) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3337 | assign( rA, binop(Iop_Or64, |
| 3338 | binop(Iop_And64, mkU64(mask64), r), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3339 | binop(Iop_And64, mkU64(~mask64), |
| 3340 | mkexpr(rA_orig))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3341 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 3342 | } |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3343 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3344 | vex_printf("dis_int_rot(ppc)(opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3345 | return False; |
| 3346 | } |
| 3347 | break; |
| 3348 | } |
| 3349 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3350 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3351 | vex_printf("dis_int_rot(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3352 | return False; |
| 3353 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3354 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3355 | putIReg( rA_addr, mkexpr(rA) ); |
| 3356 | |
| 3357 | if (flag_rC) { |
| 3358 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3359 | } |
| 3360 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3364 | /* |
| 3365 | Integer Load Instructions |
| 3366 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3367 | static Bool dis_int_load ( UInt theInstr ) |
| 3368 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3369 | /* D-Form, X-Form, DS-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3370 | UChar opc1 = ifieldOPC(theInstr); |
| 3371 | UChar rD_addr = ifieldRegDS(theInstr); |
| 3372 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3373 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3374 | UChar rB_addr = ifieldRegB(theInstr); |
| 3375 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3376 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3377 | UChar b0 = ifieldBIT0(theInstr); |
| 3378 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3379 | Int simm16 = extend_s_16to32(uimm16); |
| 3380 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3381 | IRTemp EA = newTemp(ty); |
| 3382 | IRExpr* val; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3383 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3384 | switch (opc1) { |
| 3385 | case 0x1F: // register offset |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3386 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3387 | break; |
| 3388 | case 0x3A: // immediate offset: 64bit |
| 3389 | simm16 = simm16 & 0xFFFFFFFC; |
| 3390 | default: // immediate offset |
| 3391 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3392 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3393 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3394 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3395 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3396 | case 0x22: // lbz (Load B & Zero, PPC32 p433) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3397 | DIP("lbz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3398 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3399 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3400 | break; |
| 3401 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3402 | case 0x23: // lbzu (Load B & Zero, Update, PPC32 p434) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3403 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3404 | vex_printf("dis_int_load(ppc)(lbzu,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3405 | return False; |
| 3406 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3407 | DIP("lbzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3408 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3409 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3410 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3411 | break; |
| 3412 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3413 | case 0x2A: // lha (Load HW Alg, PPC32 p445) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3414 | DIP("lha r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3415 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3416 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3417 | break; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3418 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3419 | case 0x2B: // lhau (Load HW Alg, Update, PPC32 p446) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3420 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3421 | vex_printf("dis_int_load(ppc)(lhau,rA_addr|rD_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3422 | return False; |
| 3423 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3424 | DIP("lhau r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3425 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3426 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3427 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3428 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3429 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3430 | case 0x28: // lhz (Load HW & Zero, PPC32 p450) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3431 | DIP("lhz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3432 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3433 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3434 | break; |
| 3435 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3436 | case 0x29: // lhzu (Load HW & and Zero, Update, PPC32 p451) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3437 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3438 | vex_printf("dis_int_load(ppc)(lhzu,rA_addr|rD_addr)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 3439 | return False; |
| 3440 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3441 | DIP("lhzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3442 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3443 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3444 | putIReg( rA_addr, mkexpr(EA) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 3445 | break; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3446 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3447 | case 0x20: // lwz (Load W & Zero, PPC32 p460) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3448 | DIP("lwz r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3449 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3450 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3451 | break; |
| 3452 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3453 | case 0x21: // lwzu (Load W & Zero, Update, PPC32 p461)) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3454 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3455 | vex_printf("dis_int_load(ppc)(lwzu,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3456 | return False; |
| 3457 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3458 | DIP("lwzu r%u,%d(r%u)\n", rD_addr, (Int)simm16, rA_addr); |
| 3459 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3460 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3461 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | |
| 3464 | /* X Form */ |
| 3465 | case 0x1F: |
| 3466 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3467 | vex_printf("dis_int_load(ppc)(Ox1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3468 | return False; |
| 3469 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 3470 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3471 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3472 | case 0x077: // lbzux (Load B & Zero, Update Indexed, PPC32 p435) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3473 | DIP("lbzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3474 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3475 | vex_printf("dis_int_load(ppc)(lwzux,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3476 | return False; |
| 3477 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3478 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3479 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3480 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3481 | break; |
| 3482 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3483 | case 0x057: // lbzx (Load B & Zero, Indexed, PPC32 p436) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3484 | DIP("lbzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3485 | val = loadBE(Ity_I8, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3486 | putIReg( rD_addr, mkSzWiden8(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3487 | break; |
| 3488 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3489 | case 0x177: // lhaux (Load HW Alg, Update Indexed, PPC32 p447) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3490 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3491 | vex_printf("dis_int_load(ppc)(lhaux,rA_addr|rD_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3492 | return False; |
| 3493 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3494 | DIP("lhaux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3495 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3496 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3497 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3498 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3499 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3500 | case 0x157: // lhax (Load HW Alg, Indexed, PPC32 p448) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3501 | DIP("lhax r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3502 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3503 | putIReg( rD_addr, mkSzWiden16(ty, val, True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3504 | break; |
| 3505 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3506 | case 0x137: // lhzux (Load HW & Zero, Update Indexed, PPC32 p452) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3507 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3508 | vex_printf("dis_int_load(ppc)(lhzux,rA_addr|rD_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3509 | return False; |
| 3510 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3511 | DIP("lhzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3512 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3513 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3514 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3515 | break; |
| 3516 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3517 | case 0x117: // lhzx (Load HW & Zero, Indexed, PPC32 p453) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3518 | DIP("lhzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3519 | val = loadBE(Ity_I16, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3520 | putIReg( rD_addr, mkSzWiden16(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3521 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3522 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3523 | case 0x037: // lwzux (Load W & Zero, Update Indexed, PPC32 p462) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3524 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3525 | vex_printf("dis_int_load(ppc)(lwzux,rA_addr|rD_addr)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3526 | return False; |
| 3527 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3528 | DIP("lwzux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3529 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3530 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3531 | putIReg( rA_addr, mkexpr(EA) ); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3532 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3533 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3534 | case 0x017: // lwzx (Load W & Zero, Indexed, PPC32 p463) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3535 | DIP("lwzx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3536 | val = loadBE(Ity_I32, mkexpr(EA)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3537 | putIReg( rD_addr, mkSzWiden32(ty, val, False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3538 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3539 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3540 | |
| 3541 | /* 64bit Loads */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3542 | case 0x035: // ldux (Load DWord, Update Indexed, PPC64 p475) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3543 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3544 | vex_printf("dis_int_load(ppc)(ldux,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3545 | return False; |
| 3546 | } |
| 3547 | DIP("ldux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3548 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3549 | putIReg( rA_addr, mkexpr(EA) ); |
| 3550 | break; |
| 3551 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3552 | case 0x015: // ldx (Load DWord, Indexed, PPC64 p476) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3553 | DIP("ldx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
| 3554 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3555 | break; |
| 3556 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3557 | case 0x175: // lwaux (Load W Alg, Update Indexed, PPC64 p501) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3558 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3559 | vex_printf("dis_int_load(ppc)(lwaux,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3560 | return False; |
| 3561 | } |
| 3562 | DIP("lwaux r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3563 | putIReg( rD_addr, |
| 3564 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3565 | putIReg( rA_addr, mkexpr(EA) ); |
| 3566 | break; |
| 3567 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3568 | case 0x155: // lwax (Load W Alg, Indexed, PPC64 p502) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3569 | DIP("lwax r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3570 | putIReg( rD_addr, |
| 3571 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3572 | break; |
| 3573 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3574 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3575 | vex_printf("dis_int_load(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3576 | return False; |
| 3577 | } |
| 3578 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3579 | |
| 3580 | /* DS Form - 64bit Loads */ |
| 3581 | case 0x3A: |
| 3582 | switch (b1<<1 | b0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3583 | case 0x0: // ld (Load DWord, PPC64 p472) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3584 | DIP("ld r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3585 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3586 | break; |
| 3587 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3588 | case 0x1: // ldu (Load DWord, Update, PPC64 p474) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3589 | if (rA_addr == 0 || rA_addr == rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3590 | vex_printf("dis_int_load(ppc)(ldu,rA_addr|rD_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3591 | return False; |
| 3592 | } |
| 3593 | DIP("ldu r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3594 | simm16 = simm16 & ~0x3; |
| 3595 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 3596 | putIReg( rA_addr, mkexpr(EA) ); |
| 3597 | break; |
| 3598 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3599 | case 0x2: // lwa (Load Word Alg, PPC64 p499) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3600 | DIP("lwa r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3601 | putIReg( rD_addr, |
| 3602 | unop(Iop_32Sto64, loadBE(Ity_I32, mkexpr(EA))) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3603 | break; |
| 3604 | |
| 3605 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3606 | vex_printf("dis_int_load(ppc)(0x3A, opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3607 | return False; |
| 3608 | } |
| 3609 | break; |
| 3610 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3611 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3612 | vex_printf("dis_int_load(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3613 | return False; |
| 3614 | } |
| 3615 | return True; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | |
| 3619 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 3620 | /* |
| 3621 | Integer Store Instructions |
| 3622 | */ |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3623 | static Bool dis_int_store ( UInt theInstr ) |
| 3624 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3625 | /* D-Form, X-Form, DS-Form */ |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3626 | UChar opc1 = ifieldOPC(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3627 | UInt rS_addr = ifieldRegDS(theInstr); |
| 3628 | UInt rA_addr = ifieldRegA(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3629 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3630 | UInt rB_addr = ifieldRegB(theInstr); |
| 3631 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3632 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3633 | UChar b0 = ifieldBIT0(theInstr); |
| 3634 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3635 | Int simm16 = extend_s_16to32(uimm16); |
| 3636 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3637 | IRTemp rS = newTemp(ty); |
| 3638 | IRTemp rB = newTemp(ty); |
| 3639 | IRTemp EA = newTemp(ty); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3640 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3641 | assign( rB, getIReg(rB_addr) ); |
| 3642 | assign( rS, getIReg(rS_addr) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3643 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3644 | switch (opc1) { |
| 3645 | case 0x1F: // register offset |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3646 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3647 | break; |
| 3648 | case 0x3E: // immediate offset: 64bit |
| 3649 | simm16 = simm16 & 0xFFFFFFFC; |
| 3650 | default: // immediate offset |
| 3651 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3652 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3653 | } |
| 3654 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3655 | switch (opc1) { |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 3656 | case 0x26: // stb (Store B, PPC32 p509) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3657 | DIP("stb r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3658 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 3659 | break; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 3660 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3661 | case 0x27: // stbu (Store B, Update, PPC32 p510) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3662 | if (rA_addr == 0 ) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3663 | vex_printf("dis_int_store(ppc)(stbu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3664 | return False; |
| 3665 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3666 | DIP("stbu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3667 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3668 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3669 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3670 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3671 | case 0x2C: // sth (Store HW, PPC32 p522) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3672 | DIP("sth r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3673 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3674 | break; |
| 3675 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3676 | case 0x2D: // sthu (Store HW, Update, PPC32 p524) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3677 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3678 | vex_printf("dis_int_store(ppc)(sthu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3679 | return False; |
| 3680 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3681 | DIP("sthu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3682 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3683 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3684 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3685 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3686 | case 0x24: // stw (Store W, PPC32 p530) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3687 | DIP("stw r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3688 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3689 | break; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3690 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3691 | case 0x25: // stwu (Store W, Update, PPC32 p534) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3692 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3693 | vex_printf("dis_int_store(ppc)(stwu,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3694 | return False; |
| 3695 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3696 | DIP("stwu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3697 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3698 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3699 | break; |
| 3700 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3701 | /* X Form : all these use EA_indexed */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3702 | case 0x1F: |
| 3703 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3704 | vex_printf("dis_int_store(ppc)(0x1F,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3705 | return False; |
| 3706 | } |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3707 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3708 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3709 | case 0x0F7: // stbux (Store B, Update Indexed, PPC32 p511) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3710 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3711 | vex_printf("dis_int_store(ppc)(stbux,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3712 | return False; |
| 3713 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3714 | DIP("stbux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3715 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3716 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3717 | break; |
| 3718 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3719 | case 0x0D7: // stbx (Store B Indexed, PPC32 p512) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3720 | DIP("stbx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3721 | storeBE( mkexpr(EA), mkSzNarrow8(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3722 | break; |
| 3723 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3724 | case 0x1B7: // sthux (Store HW, Update Indexed, PPC32 p525) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3725 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3726 | vex_printf("dis_int_store(ppc)(sthux,rA_addr)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3727 | return False; |
| 3728 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3729 | DIP("sthux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3730 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3731 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 3732 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3733 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3734 | case 0x197: // sthx (Store HW Indexed, PPC32 p526) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3735 | DIP("sthx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3736 | storeBE( mkexpr(EA), mkSzNarrow16(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3737 | break; |
| 3738 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3739 | case 0x0B7: // stwux (Store W, Update Indexed, PPC32 p535) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3740 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3741 | vex_printf("dis_int_store(ppc)(stwux,rA_addr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3742 | return False; |
| 3743 | } |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3744 | DIP("stwux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3745 | putIReg( rA_addr, mkexpr(EA) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3746 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3747 | break; |
cerion | 44997f2 | 2005-01-31 18:45:59 +0000 | [diff] [blame] | 3748 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 3749 | case 0x097: // stwx (Store W Indexed, PPC32 p536) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3750 | DIP("stwx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3751 | storeBE( mkexpr(EA), mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3752 | break; |
| 3753 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3754 | |
| 3755 | /* 64bit Stores */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3756 | case 0x0B5: // stdux (Store DWord, Update Indexed, PPC64 p584) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3757 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3758 | vex_printf("dis_int_store(ppc)(stdux,rA_addr)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3759 | return False; |
| 3760 | } |
| 3761 | DIP("stdux r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
| 3762 | putIReg( rA_addr, mkexpr(EA) ); |
| 3763 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3764 | break; |
| 3765 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3766 | case 0x095: // stdx (Store DWord Indexed, PPC64 p585) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3767 | DIP("stdx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
| 3768 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3769 | break; |
| 3770 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3771 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3772 | vex_printf("dis_int_store(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3773 | return False; |
| 3774 | } |
| 3775 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3776 | |
| 3777 | /* DS Form - 64bit Stores */ |
| 3778 | case 0x3E: |
| 3779 | switch (b1<<1 | b0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3780 | case 0x0: // std (Store DWord, PPC64 p580) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3781 | DIP("std r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3782 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3783 | break; |
| 3784 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3785 | case 0x1: // stdu (Store DWord, Update, PPC64 p583) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3786 | DIP("stdu r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3787 | putIReg( rA_addr, mkexpr(EA) ); |
| 3788 | storeBE( mkexpr(EA), mkexpr(rS) ); |
| 3789 | break; |
| 3790 | |
| 3791 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3792 | vex_printf("dis_int_load(ppc)(0x3A, opc2)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 3793 | return False; |
| 3794 | } |
| 3795 | break; |
| 3796 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3797 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3798 | vex_printf("dis_int_store(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 3799 | return False; |
| 3800 | } |
| 3801 | return True; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | |
| 3805 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3806 | /* |
| 3807 | Integer Load/Store Multiple Instructions |
| 3808 | */ |
| 3809 | static Bool dis_int_ldst_mult ( UInt theInstr ) |
| 3810 | { |
| 3811 | /* D-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3812 | UChar opc1 = ifieldOPC(theInstr); |
| 3813 | UChar rD_addr = ifieldRegDS(theInstr); |
| 3814 | UChar rS_addr = rD_addr; |
| 3815 | UChar rA_addr = ifieldRegA(theInstr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3816 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3817 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3818 | Int simm16 = extend_s_16to32(uimm16); |
| 3819 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3820 | IRTemp EA = newTemp(ty); |
| 3821 | UInt r = 0; |
| 3822 | UInt ea_off = 0; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3823 | IRExpr* irx_addr; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3824 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3825 | assign( EA, ea_rAor0_simm( rA_addr, simm16 ) ); |
| 3826 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3827 | switch (opc1) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3828 | case 0x2E: // lmw (Load Multiple Word, PPC32 p454) |
| 3829 | if (rA_addr >= rD_addr) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3830 | vex_printf("dis_int_ldst_mult(ppc)(lmw,rA_addr)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3831 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3832 | } |
| 3833 | DIP("lmw r%u,%d(r%u)\n", rD_addr, simm16, rA_addr); |
| 3834 | for (r = rD_addr; r <= 31; r++) { |
| 3835 | irx_addr = binop(Iop_Add32, mkexpr(EA), mkU32(ea_off)); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3836 | putIReg( r, mkSzWiden32(ty, loadBE(Ity_I32, irx_addr ), |
| 3837 | False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3838 | ea_off += 4; |
| 3839 | } |
| 3840 | break; |
| 3841 | |
| 3842 | case 0x2F: // stmw (Store Multiple Word, PPC32 p527) |
| 3843 | DIP("stmw r%u,%d(r%u)\n", rS_addr, simm16, rA_addr); |
| 3844 | for (r = rS_addr; r <= 31; r++) { |
| 3845 | irx_addr = binop(Iop_Add32, mkexpr(EA), mkU32(ea_off)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3846 | storeBE( irx_addr, mkSzNarrow32(ty, getIReg(r)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3847 | ea_off += 4; |
| 3848 | } |
| 3849 | break; |
| 3850 | |
| 3851 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3852 | vex_printf("dis_int_ldst_mult(ppc)(opc1)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3853 | return False; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 3854 | } |
| 3855 | return True; |
| 3856 | } |
| 3857 | |
| 3858 | |
| 3859 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3860 | /* |
| 3861 | Integer Load/Store String Instructions |
| 3862 | */ |
| 3863 | static |
| 3864 | void generate_lsw_sequence ( IRTemp tNBytes, // # bytes, :: Ity_I32 |
| 3865 | IRTemp EA, // EA |
| 3866 | Int rD, // first dst register |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3867 | Int maxBytes ) // 32 or 128 |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3868 | { |
| 3869 | Int i, shift = 24; |
| 3870 | IRExpr* e_nbytes = mkexpr(tNBytes); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3871 | IRExpr* e_EA = mkexpr(EA); |
| 3872 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3873 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3874 | vassert(rD >= 0 && rD < 32); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3875 | rD--; if (rD < 0) rD = 31; |
| 3876 | |
| 3877 | for (i = 0; i < maxBytes; i++) { |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3878 | /* if (nBytes < (i+1)) goto NIA; */ |
| 3879 | stmt( IRStmt_Exit( binop(Iop_CmpLT32U, e_nbytes, mkU32(i+1)), |
| 3880 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3881 | mkSzConst( ty, nextInsnAddr()) )); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3882 | /* when crossing into a new dest register, set it to zero. */ |
| 3883 | if ((i % 4) == 0) { |
| 3884 | rD++; if (rD == 32) rD = 0; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3885 | putIReg(rD, mkSzImm(ty, 0)); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3886 | shift = 24; |
| 3887 | } |
| 3888 | /* rD |= (8Uto32(*(EA+i))) << shift */ |
| 3889 | vassert(shift == 0 || shift == 8 || shift == 16 || shift == 24); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3890 | putIReg( rD, |
| 3891 | mkSzWiden32(ty, |
| 3892 | binop(Iop_Or32, |
| 3893 | mkSzNarrow32(ty, getIReg(rD)), |
| 3894 | binop(Iop_Shl32, |
| 3895 | unop(Iop_8Uto32, |
| 3896 | loadBE(Ity_I8, |
| 3897 | binop(Iop_Add32, e_EA, mkU32(i)))), |
| 3898 | mkU8(toUChar(shift)))), |
| 3899 | /*Signed*/False) ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3900 | shift -= 8; |
| 3901 | } |
| 3902 | } |
| 3903 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3904 | static |
| 3905 | void generate_stsw_sequence ( IRTemp tNBytes, // # bytes, :: Ity_I32 |
| 3906 | IRTemp EA, // EA |
| 3907 | Int rS, // first src register |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3908 | Int maxBytes ) // 32 or 128 |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3909 | { |
| 3910 | Int i, shift = 24; |
| 3911 | IRExpr* e_nbytes = mkexpr(tNBytes); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3912 | IRExpr* e_EA = mkexpr(EA); |
| 3913 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3914 | |
| 3915 | vassert(rS >= 0 && rS < 32); |
| 3916 | rS--; if (rS < 0) rS = 31; |
| 3917 | |
| 3918 | for (i = 0; i < maxBytes; i++) { |
| 3919 | /* if (nBytes < (i+1)) goto NIA; */ |
| 3920 | stmt( IRStmt_Exit( binop(Iop_CmpLT32U, e_nbytes, mkU32(i+1)), |
| 3921 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3922 | mkSzConst( ty, nextInsnAddr() ) )); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3923 | /* check for crossing into a new src register. */ |
| 3924 | if ((i % 4) == 0) { |
| 3925 | rS++; if (rS == 32) rS = 0; |
| 3926 | shift = 24; |
| 3927 | } |
| 3928 | /* *(EA+i) = 32to8(rS >> shift) */ |
| 3929 | vassert(shift == 0 || shift == 8 || shift == 16 || shift == 24); |
| 3930 | storeBE( |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3931 | binop(mkSzOp(ty,Iop_Add8), e_EA, mkSzImm(ty,i)), |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3932 | unop(Iop_32to8, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 3933 | binop(Iop_Shr32, |
| 3934 | mkSzNarrow32(ty, getIReg(rS)), |
| 3935 | mkU8(toUChar(shift)))) |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 3936 | ); |
| 3937 | shift -= 8; |
| 3938 | } |
| 3939 | } |
| 3940 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3941 | static Bool dis_int_ldst_str ( UInt theInstr, /*OUT*/Bool* stopHere ) |
| 3942 | { |
| 3943 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3944 | UChar opc1 = ifieldOPC(theInstr); |
| 3945 | UChar rD_addr = ifieldRegDS(theInstr); |
| 3946 | UChar rS_addr = rD_addr; |
| 3947 | UChar rA_addr = ifieldRegA(theInstr); |
| 3948 | UChar rB_addr = ifieldRegB(theInstr); |
| 3949 | UChar NumBytes = rB_addr; |
| 3950 | UInt opc2 = ifieldOPClo10(theInstr); |
| 3951 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3952 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3953 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 3954 | IRTemp t_EA = newTemp(ty); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3955 | IRTemp t_nbytes = IRTemp_INVALID; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3956 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3957 | *stopHere = False; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3958 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3959 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 3960 | vex_printf("dis_int_ldst_str(ppc)(opc1)\n"); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3961 | return False; |
| 3962 | } |
| 3963 | |
| 3964 | switch (opc2) { |
| 3965 | case 0x255: // lswi (Load String Word Immediate, PPC32 p455) |
| 3966 | /* NB: does not reject the case where RA is in the range of |
| 3967 | registers to be loaded. It should. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3968 | DIP("lswi r%u,r%u,%d\n", rD_addr, rA_addr, NumBytes); |
| 3969 | assign( t_EA, ea_rAor0(rA_addr) ); |
| 3970 | if (!mode64 && NumBytes == 8) { |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3971 | /* Special case hack */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3972 | /* rD = Mem[EA]; (rD+1)%32 = Mem[EA+4] */ |
| 3973 | putIReg( rD_addr, |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3974 | loadBE(Ity_I32, mkexpr(t_EA)) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3975 | putIReg( (rD_addr+1) % 32, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3976 | loadBE(Ity_I32, |
| 3977 | binop(Iop_Add32, mkexpr(t_EA), mkU32(4))) ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3978 | } else { |
| 3979 | t_nbytes = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3980 | assign( t_nbytes, mkU32(NumBytes==0 ? 32 : NumBytes) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3981 | generate_lsw_sequence( t_nbytes, t_EA, rD_addr, 32 ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3982 | *stopHere = True; |
| 3983 | } |
| 3984 | return True; |
| 3985 | |
| 3986 | case 0x215: // lswx (Load String Word Indexed, PPC32 p456) |
| 3987 | /* NB: does not reject the case where RA is in the range of |
| 3988 | registers to be loaded. It should. Although considering |
| 3989 | that that can only be detected at run time, it's not easy to |
| 3990 | do so. */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3991 | if (rD_addr == rA_addr || rD_addr == rB_addr) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3992 | return False; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 3993 | if (rD_addr == 0 && rA_addr == 0) |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3994 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3995 | DIP("lswx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 3996 | t_nbytes = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3997 | assign( t_EA, ea_rAor0_idxd(rA_addr,rB_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 3998 | assign( t_nbytes, unop( Iop_8Uto32, getXER_BC() ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 3999 | generate_lsw_sequence( t_nbytes, t_EA, rD_addr, 128 ); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4000 | *stopHere = True; |
| 4001 | return True; |
| 4002 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4003 | case 0x2D5: // stswi (Store String Word Immediate, PPC32 p528) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4004 | DIP("stswi r%u,r%u,%d\n", rS_addr, rA_addr, NumBytes); |
| 4005 | assign( t_EA, ea_rAor0(rA_addr) ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4006 | if (NumBytes == 8) { |
| 4007 | /* Special case hack */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4008 | /* Mem[EA] = rD; Mem[EA+4] = (rD+1)%32 */ |
| 4009 | storeBE( mkexpr(t_EA), |
| 4010 | getIReg(rD_addr) ); |
| 4011 | storeBE( binop(Iop_Add32, mkexpr(t_EA), mkU32(4)), |
| 4012 | getIReg((rD_addr+1) % 32) ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4013 | } else { |
| 4014 | t_nbytes = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4015 | assign( t_nbytes, mkU32(NumBytes==0 ? 32 : NumBytes) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4016 | generate_stsw_sequence( t_nbytes, t_EA, rD_addr, 32 ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4017 | *stopHere = True; |
| 4018 | } |
| 4019 | return True; |
| 4020 | |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4021 | case 0x295: // stswx (Store String Word Indexed, PPC32 p529) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4022 | DIP("stswx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4023 | t_nbytes = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4024 | assign( t_EA, ea_rAor0_idxd(rA_addr,rB_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4025 | assign( t_nbytes, unop( Iop_8Uto32, getXER_BC() ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4026 | generate_stsw_sequence( t_nbytes, t_EA, rS_addr, 128 ); |
sewardj | 5876fa1 | 2005-09-09 09:35:29 +0000 | [diff] [blame] | 4027 | *stopHere = True; |
| 4028 | return True; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4029 | |
| 4030 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4031 | vex_printf("dis_int_ldst_str(ppc)(opc2)\n"); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 4032 | return False; |
| 4033 | } |
| 4034 | return True; |
| 4035 | } |
| 4036 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 4037 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4038 | /* ------------------------------------------------------------------ |
| 4039 | Integer Branch Instructions |
| 4040 | ------------------------------------------------------------------ */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4041 | |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4042 | /* |
| 4043 | Branch helper function |
| 4044 | ok = BO[2] | ((CTR[0] != 0) ^ BO[1]) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4045 | Returns an I32 which is 0x00000000 if the ctr condition failed |
| 4046 | and 0xFFFFFFFF otherwise. |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4047 | */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4048 | static IRExpr* /* :: Ity_I32 */ branch_ctr_ok( UInt BO ) |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4049 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4050 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4051 | IRTemp ok = newTemp(Ity_I32); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4052 | IRExpr* ctr_lo32; |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 4053 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4054 | if ((BO >> 2) & 1) { // independent of ctr |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4055 | assign( ok, mkU32(0xFFFFFFFF) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4056 | } else { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4057 | ctr_lo32 = mkSzNarrow32(ty, getGST( PPC_GST_CTR )); |
| 4058 | if ((BO >> 1) & 1) { // ctr == 0 ? |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4059 | assign( ok, unop( Iop_1Sto32, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4060 | binop( Iop_CmpEQ32, ctr_lo32, mkU32(0))) ); |
| 4061 | } else { // ctr != 0 ? |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4062 | assign( ok, unop( Iop_1Sto32, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4063 | binop( Iop_CmpNE32, ctr_lo32, mkU32(0))) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | return mkexpr(ok); |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4069 | |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4070 | /* |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4071 | Branch helper function cond_ok = BO[4] | (CR[BI] == BO[3]) |
| 4072 | Returns an I32 which is either 0 if the condition failed or |
| 4073 | some arbitrary nonzero value otherwise. */ |
| 4074 | |
| 4075 | static IRExpr* /* :: Ity_I32 */ branch_cond_ok( UInt BO, UInt BI ) |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4076 | { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4077 | Int where; |
| 4078 | IRTemp res = newTemp(Ity_I32); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4079 | IRTemp cr_bi = newTemp(Ity_I32); |
| 4080 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4081 | if ((BO >> 4) & 1) { |
| 4082 | assign( res, mkU32(1) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4083 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4084 | // ok = (CR[BI] == BO[3]) Note, the following relies on |
| 4085 | // getCRbit_anywhere returning a value which |
| 4086 | // is either zero or has exactly 1 bit set. |
| 4087 | assign( cr_bi, getCRbit_anywhere( BI, &where ) ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4088 | |
| 4089 | if ((BO >> 3) & 1) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4090 | /* We can use cr_bi as-is. */ |
| 4091 | assign( res, mkexpr(cr_bi) ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4092 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4093 | /* We have to invert the sense of the information held in |
| 4094 | cr_bi. For that we need to know which bit |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4095 | getCRbit_anywhere regards as significant. */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4096 | assign( res, binop(Iop_Xor32, mkexpr(cr_bi), |
| 4097 | mkU32(1<<where)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4098 | } |
| 4099 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4100 | return mkexpr(res); |
cerion | 45552a9 | 2005-02-03 18:20:22 +0000 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4104 | /* |
| 4105 | Integer Branch Instructions |
| 4106 | */ |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4107 | static Bool dis_branch ( UInt theInstr, |
| 4108 | /*OUT*/DisResult* dres, |
| 4109 | Bool (*resteerOkFn)(Addr64) ) |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4110 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4111 | UChar opc1 = ifieldOPC(theInstr); |
| 4112 | UChar BO = ifieldRegDS(theInstr); |
| 4113 | UChar BI = ifieldRegA(theInstr); |
| 4114 | UInt BD_u16 = ifieldUIMM16(theInstr) & 0xFFFFFFFC; /* mask off */ |
| 4115 | UChar b11to15 = ifieldRegB(theInstr); |
| 4116 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4117 | UInt LI_u26 = ifieldUIMM26(theInstr) & 0xFFFFFFFC; /* mask off */ |
| 4118 | UChar flag_AA = ifieldBIT1(theInstr); |
| 4119 | UChar flag_LK = ifieldBIT0(theInstr); |
| 4120 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4121 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4122 | Addr64 tgt = 0; |
| 4123 | Int BD = extend_s_16to32(BD_u16); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4124 | IRTemp do_branch = newTemp(Ity_I32); |
| 4125 | IRTemp ctr_ok = newTemp(Ity_I32); |
| 4126 | IRTemp cond_ok = newTemp(Ity_I32); |
| 4127 | IRExpr* e_nia = mkSzImm(ty, nextInsnAddr()); |
| 4128 | IRConst* c_nia = mkSzConst(ty, nextInsnAddr()); |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4129 | IRTemp lr_old = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4130 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4131 | /* Hack to pass through code that just wants to read the PC */ |
| 4132 | if (theInstr == 0x429F0005) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4133 | DIP("bcl 0x%x, 0x%x (a.k.a mr lr,cia+4)\n", BO, BI); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4134 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4135 | return True; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4136 | } |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4137 | |
| 4138 | /* The default what-next. Individual cases can override it. */ |
| 4139 | dres->whatNext = Dis_StopHere; |
| 4140 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4141 | switch (opc1) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4142 | case 0x12: // b (Branch, PPC32 p360) |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4143 | if (flag_AA) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4144 | tgt = mkSzAddr( ty, extend_s_26to64(LI_u26) ); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4145 | } else { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4146 | tgt = mkSzAddr( ty, guest_CIA_curr_instr + |
| 4147 | (Long)extend_s_26to64(LI_u26) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4148 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4149 | if (mode64) { |
| 4150 | DIP("b%s%s 0x%llx\n", |
| 4151 | flag_LK ? "l" : "", flag_AA ? "a" : "", tgt); |
| 4152 | } else { |
| 4153 | DIP("b%s%s 0x%x\n", |
| 4154 | flag_LK ? "l" : "", flag_AA ? "a" : "", (Addr32)tgt); |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4155 | } |
| 4156 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4157 | if (flag_LK) |
| 4158 | putGST( PPC_GST_LR, e_nia ); |
| 4159 | |
| 4160 | if (resteerOkFn(tgt)) { |
| 4161 | dres->whatNext = Dis_Resteer; |
| 4162 | dres->continueAt = tgt; |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4163 | } else { |
| 4164 | irbb->jumpkind = flag_LK ? Ijk_Call : Ijk_Boring; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4165 | irbb->next = mkSzImm(ty, tgt); |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 4166 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4167 | break; |
| 4168 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4169 | case 0x10: // bc (Branch Conditional, PPC32 p361) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4170 | DIP("bc%s%s 0x%x, 0x%x, 0x%x\n", |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4171 | flag_LK ? "l" : "", flag_AA ? "a" : "", BO, BI, BD); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4172 | |
| 4173 | if (!(BO & 0x4)) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4174 | putGST( PPC_GST_CTR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4175 | binop(mkSzOp(ty, Iop_Sub8), |
| 4176 | getGST( PPC_GST_CTR ), mkSzImm(ty, 1)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4177 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4178 | |
| 4179 | /* This is a bit subtle. ctr_ok is either all 0s or all 1s. |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4180 | cond_ok is either zero or nonzero, since that's the cheapest |
| 4181 | way to compute it. Anding them together gives a value which |
| 4182 | is either zero or non zero and so that's what we must test |
| 4183 | for in the IRStmt_Exit. */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4184 | assign( ctr_ok, branch_ctr_ok( BO ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4185 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4186 | assign( do_branch, |
| 4187 | binop(Iop_And32, mkexpr(cond_ok), mkexpr(ctr_ok)) ); |
| 4188 | |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4189 | if (flag_AA) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4190 | tgt = mkSzAddr(ty, extend_s_16to64(BD_u16)); |
cerion | 4561acb | 2005-02-21 14:07:48 +0000 | [diff] [blame] | 4191 | } else { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4192 | tgt = mkSzAddr(ty, guest_CIA_curr_instr + |
| 4193 | (Long)extend_s_16to64(BD_u16)); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4194 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4195 | if (flag_LK) |
| 4196 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4197 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4198 | stmt( IRStmt_Exit( |
| 4199 | binop(Iop_CmpNE32, mkexpr(do_branch), mkU32(0)), |
| 4200 | flag_LK ? Ijk_Call : Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4201 | mkSzConst(ty, tgt) ) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4202 | |
| 4203 | irbb->jumpkind = Ijk_Boring; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4204 | irbb->next = e_nia; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4205 | break; |
| 4206 | |
| 4207 | case 0x13: |
| 4208 | if (b11to15!=0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4209 | vex_printf("dis_int_branch(ppc)(0x13,b11to15)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4210 | return False; |
| 4211 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4212 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4213 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4214 | case 0x210: // bcctr (Branch Cond. to Count Register, PPC32 p363) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4215 | if ((BO & 0x4) == 0) { // "decr and test CTR" option invalid |
| 4216 | vex_printf("dis_int_branch(ppc)(bcctr,BO)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4217 | return False; |
| 4218 | } |
cerion | a31e8b5 | 2005-02-21 16:30:45 +0000 | [diff] [blame] | 4219 | DIP("bcctr%s 0x%x, 0x%x\n", flag_LK ? "l" : "", BO, BI); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4220 | |
| 4221 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4222 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4223 | assign( lr_old, addr_align( getGST( PPC_GST_CTR ), 4 )); |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4224 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4225 | if (flag_LK) |
| 4226 | putGST( PPC_GST_LR, e_nia ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4227 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4228 | stmt( IRStmt_Exit( |
| 4229 | binop(Iop_CmpEQ32, mkexpr(cond_ok), mkU32(0)), |
| 4230 | Ijk_Boring, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4231 | c_nia )); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4232 | |
| 4233 | irbb->jumpkind = flag_LK ? Ijk_Call : Ijk_Boring; |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4234 | irbb->next = mkexpr(lr_old); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4235 | break; |
| 4236 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4237 | case 0x010: // bclr (Branch Cond. to Link Register, PPC32 p365) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4238 | |
| 4239 | if ((BO & 0x14 /* 1z1zz */) == 0x14 && flag_LK == 0) { |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 4240 | DIP("blr\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4241 | } else { |
| 4242 | DIP("bclr%s 0x%x, 0x%x\n", flag_LK ? "l" : "", BO, BI); |
| 4243 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4244 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4245 | if (!(BO & 0x4)) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4246 | putGST( PPC_GST_CTR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4247 | binop(mkSzOp(ty, Iop_Sub8), |
| 4248 | getGST( PPC_GST_CTR ), mkSzImm(ty, 1)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4249 | } |
| 4250 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4251 | /* See comments above for 'bc' about this */ |
| 4252 | assign( ctr_ok, branch_ctr_ok( BO ) ); |
| 4253 | assign( cond_ok, branch_cond_ok( BO, BI ) ); |
| 4254 | assign( do_branch, |
| 4255 | binop(Iop_And32, mkexpr(cond_ok), mkexpr(ctr_ok)) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4256 | |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4257 | assign( lr_old, addr_align( getGST( PPC_GST_LR ), 4 )); |
| 4258 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4259 | if (flag_LK) |
| 4260 | putGST( PPC_GST_LR, e_nia ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4261 | |
| 4262 | stmt( IRStmt_Exit( |
| 4263 | binop(Iop_CmpEQ32, mkexpr(do_branch), mkU32(0)), |
| 4264 | Ijk_Boring, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4265 | c_nia )); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4266 | |
sewardj | d37be03 | 2005-11-12 12:56:31 +0000 | [diff] [blame] | 4267 | /* blrl is pretty strange; it's like a return that sets the |
| 4268 | return address of its caller to the insn following this |
| 4269 | one. Mark it as a return. */ |
| 4270 | irbb->jumpkind = Ijk_Ret; /* was flag_LK ? Ijk_Call : Ijk_Ret; */ |
sewardj | df07b88 | 2005-11-29 18:19:11 +0000 | [diff] [blame] | 4271 | irbb->next = mkexpr(lr_old); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4272 | break; |
| 4273 | |
| 4274 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4275 | vex_printf("dis_int_branch(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4276 | return False; |
| 4277 | } |
| 4278 | break; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4279 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4280 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4281 | vex_printf("dis_int_branch(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4282 | return False; |
| 4283 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4284 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4285 | return True; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | |
| 4289 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4290 | /* |
| 4291 | Condition Register Logical Instructions |
| 4292 | */ |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4293 | static Bool dis_cond_logic ( UInt theInstr ) |
| 4294 | { |
| 4295 | /* XL-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4296 | UChar opc1 = ifieldOPC(theInstr); |
| 4297 | UChar crbD_addr = ifieldRegDS(theInstr); |
| 4298 | UChar crfD_addr = toUChar( IFIELD(theInstr, 23, 3) ); |
| 4299 | UChar crbA_addr = ifieldRegA(theInstr); |
| 4300 | UChar crfS_addr = toUChar( IFIELD(theInstr, 18, 3) ); |
| 4301 | UChar crbB_addr = ifieldRegB(theInstr); |
| 4302 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4303 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4304 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4305 | IRTemp crbD = newTemp(Ity_I32); |
| 4306 | IRTemp crbA = newTemp(Ity_I32); |
| 4307 | IRTemp crbB = newTemp(Ity_I32); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4308 | |
| 4309 | if (opc1 != 19 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4310 | vex_printf("dis_cond_logic(ppc)(opc1)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4311 | return False; |
| 4312 | } |
| 4313 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4314 | if (opc2 == 0) { // mcrf (Move Cond Reg Field, PPC32 p464) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4315 | if (((crbD_addr & 0x3) != 0) || |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4316 | ((crbA_addr & 0x3) != 0) || (crbB_addr != 0)) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4317 | vex_printf("dis_cond_logic(ppc)(crbD|crbA|crbB != 0)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4318 | return False; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4319 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4320 | DIP("mcrf cr%u,cr%u\n", crfD_addr, crfS_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4321 | putCR0( crfD_addr, getCR0( crfS_addr) ); |
| 4322 | putCR321( crfD_addr, getCR321(crfS_addr) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4323 | } else { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4324 | assign( crbA, getCRbit(crbA_addr) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 4325 | if (crbA_addr == crbB_addr) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4326 | crbB = crbA; |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 4327 | else |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4328 | assign( crbB, getCRbit(crbB_addr) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4329 | |
| 4330 | switch (opc2) { |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4331 | case 0x101: // crand (Cond Reg AND, PPC32 p372) |
| 4332 | DIP("crand crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4333 | assign( crbD, binop(Iop_And32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4334 | break; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4335 | case 0x081: // crandc (Cond Reg AND w. Complement, PPC32 p373) |
| 4336 | DIP("crandc crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4337 | assign( crbD, binop(Iop_And32, |
| 4338 | mkexpr(crbA), |
| 4339 | unop(Iop_Not32, mkexpr(crbB))) ); |
| 4340 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 4341 | case 0x121: // creqv (Cond Reg Equivalent, PPC32 p374) |
| 4342 | DIP("creqv crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4343 | assign( crbD, unop(Iop_Not32, |
| 4344 | binop(Iop_Xor32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4345 | break; |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4346 | case 0x0E1: // crnand (Cond Reg NAND, PPC32 p375) |
| 4347 | DIP("crnand crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4348 | assign( crbD, unop(Iop_Not32, |
| 4349 | binop(Iop_And32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4350 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4351 | case 0x021: // crnor (Cond Reg NOR, PPC32 p376) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4352 | DIP("crnor crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4353 | assign( crbD, unop(Iop_Not32, |
| 4354 | binop(Iop_Or32, mkexpr(crbA), mkexpr(crbB))) ); |
| 4355 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4356 | case 0x1C1: // cror (Cond Reg OR, PPC32 p377) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4357 | DIP("cror crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4358 | assign( crbD, binop(Iop_Or32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4359 | break; |
sewardj | 7c2dc71 | 2005-09-08 17:33:27 +0000 | [diff] [blame] | 4360 | case 0x1A1: // crorc (Cond Reg OR w. Complement, PPC32 p378) |
| 4361 | DIP("crorc crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4362 | assign( crbD, binop(Iop_Or32, |
| 4363 | mkexpr(crbA), |
| 4364 | unop(Iop_Not32, mkexpr(crbB))) ); |
| 4365 | break; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4366 | case 0x0C1: // crxor (Cond Reg XOR, PPC32 p379) |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4367 | DIP("crxor crb%d,crb%d,crb%d\n", crbD_addr, crbA_addr, crbB_addr); |
| 4368 | assign( crbD, binop(Iop_Xor32, mkexpr(crbA), mkexpr(crbB)) ); |
| 4369 | break; |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4370 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4371 | vex_printf("dis_cond_logic(ppc)(opc2)\n"); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4372 | return False; |
| 4373 | } |
| 4374 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4375 | putCRbit( crbD_addr, mkexpr(crbD) ); |
cerion | 3007c7f | 2005-02-23 23:13:29 +0000 | [diff] [blame] | 4376 | } |
| 4377 | return True; |
| 4378 | } |
| 4379 | |
| 4380 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4381 | /* |
| 4382 | System Linkage Instructions |
| 4383 | */ |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 4384 | static Bool dis_syslink ( UInt theInstr, DisResult* dres ) |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4385 | { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4386 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4387 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4388 | if (theInstr != 0x44000002) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4389 | vex_printf("dis_syslink(ppc)(theInstr)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4390 | return False; |
| 4391 | } |
cerion | e1d857b | 2005-02-04 18:29:05 +0000 | [diff] [blame] | 4392 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4393 | // sc (System Call, PPC32 p504) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4394 | DIP("sc\n"); |
| 4395 | |
| 4396 | /* It's important that all ArchRegs carry their up-to-date value |
| 4397 | at this point. So we declare an end-of-block here, which |
| 4398 | forces any TempRegs caching ArchRegs to be flushed. */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4399 | irbb->next = mkSzImm( ty, nextInsnAddr() ); |
sewardj | 4fa325a | 2005-11-03 13:27:24 +0000 | [diff] [blame] | 4400 | irbb->jumpkind = Ijk_Sys_syscall; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4401 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 4402 | dres->whatNext = Dis_StopHere; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4403 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4406 | |
| 4407 | /* |
| 4408 | Memory Synchronization Instructions |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4409 | |
| 4410 | Note on Reservations: |
| 4411 | We rely on the assumption that V will in fact only allow one thread at |
| 4412 | once to run. In effect, a thread can make a reservation, but we don't |
| 4413 | check any stores it does. Instead, the reservation is cancelled when |
| 4414 | the scheduler switches to another thread (run_thread_for_a_while()). |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4415 | */ |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4416 | static Bool dis_memsync ( UInt theInstr ) |
| 4417 | { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4418 | /* X-Form, XL-Form */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4419 | UChar opc1 = ifieldOPC(theInstr); |
| 4420 | UInt b11to25 = IFIELD(theInstr, 11, 15); |
| 4421 | UChar rD_addr = ifieldRegDS(theInstr); |
| 4422 | UChar rS_addr = rD_addr; |
| 4423 | UChar rA_addr = ifieldRegA(theInstr); |
| 4424 | UChar rB_addr = ifieldRegB(theInstr); |
| 4425 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4426 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4427 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4428 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4429 | IRTemp EA = newTemp(ty); |
| 4430 | IRTemp rS = newTemp(ty); |
| 4431 | |
| 4432 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
| 4433 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4434 | switch (opc1) { |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 4435 | /* XL-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4436 | case 0x13: // isync (Instruction Synchronize, PPC32 p432) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4437 | if (opc2 != 0x096) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4438 | vex_printf("dis_memsync(ppc)(0x13,opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4439 | return False; |
| 4440 | } |
| 4441 | if (b11to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4442 | vex_printf("dis_memsync(ppc)(0x13,b11to25|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4443 | return False; |
| 4444 | } |
| 4445 | DIP("isync\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4446 | stmt( IRStmt_MFence() ); |
| 4447 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4448 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4449 | /* X-Form */ |
| 4450 | case 0x1F: |
| 4451 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4452 | case 0x356: // eieio (Enforce In-Order Exec of I/O, PPC32 p394) |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4453 | if (b11to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4454 | vex_printf("dis_memsync(ppc)(eiei0,b11to25|b0)\n"); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4455 | return False; |
| 4456 | } |
| 4457 | DIP("eieio\n"); |
| 4458 | /* Insert a memory fence, just to be on the safe side. */ |
| 4459 | stmt( IRStmt_MFence() ); |
| 4460 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4461 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4462 | case 0x014: // lwarx (Load Word and Reserve Indexed, PPC32 p458) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4463 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4464 | vex_printf("dis_memsync(ppc)(lwarx,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4465 | return False; |
| 4466 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4467 | DIP("lwarx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4468 | putIReg( rD_addr, mkSzWiden32(ty, loadBE(Ity_I32, mkexpr(EA)), |
| 4469 | False) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4470 | /* Take a reservation */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4471 | putGST( PPC_GST_RESVN, mkexpr(EA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4472 | break; |
| 4473 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4474 | case 0x096: { |
| 4475 | // stwcx. (Store Word Conditional Indexed, PPC32 p532) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4476 | IRTemp resaddr = newTemp(ty); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4477 | if (b0 != 1) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4478 | vex_printf("dis_memsync(ppc)(stwcx.,b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4479 | return False; |
| 4480 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4481 | DIP("stwcx. r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4482 | assign( rS, getIReg(rS_addr) ); |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 4483 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4484 | /* First set up as if the reservation failed */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4485 | // Set CR0[LT GT EQ S0] = 0b000 || XER[SO] |
| 4486 | putCR321(0, mkU8(0<<1)); |
| 4487 | putCR0(0, getXER_SO()); |
| 4488 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4489 | /* Get the reservation address into a temporary, then |
| 4490 | clear it. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4491 | assign( resaddr, getGST(PPC_GST_RESVN) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4492 | putGST( PPC_GST_RESVN, mkSzImm(ty, 0) ); |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4493 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4494 | /* Skip the rest if the reservation really did fail. */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4495 | stmt( IRStmt_Exit( |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4496 | ( mode64 ? |
| 4497 | binop(Iop_CmpNE64, mkexpr(resaddr), mkexpr(EA)) : |
| 4498 | binop(Iop_CmpNE32, mkexpr(resaddr), mkexpr(EA)) ), |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4499 | Ijk_Boring, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4500 | mkSzConst( ty, nextInsnAddr()) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4501 | |
| 4502 | /* Note for mode64: |
| 4503 | If resaddr != lwarx_resaddr, CR0[EQ] is undefined, and |
| 4504 | whether rS is stored is dependent on that value. */ |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4505 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4506 | /* Success? Do the store */ |
| 4507 | storeBE( mkexpr(EA), mkexpr(rS) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4508 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4509 | // Set CR0[LT GT EQ S0] = 0b001 || XER[SO] |
| 4510 | putCR321(0, mkU8(1<<1)); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4511 | break; |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4514 | case 0x256: // sync (Synchronize, PPC32 p543) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4515 | if (b11to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4516 | vex_printf("dis_memsync(ppc)(sync,b11to25|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4517 | return False; |
| 4518 | } |
| 4519 | DIP("sync\n"); |
| 4520 | /* Insert a memory fence. It's sometimes important that these |
| 4521 | are carried through to the generated code. */ |
| 4522 | stmt( IRStmt_MFence() ); |
| 4523 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4524 | |
| 4525 | |
| 4526 | /* 64bit Memsync */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4527 | case 0x054: // ldarx (Load DWord and Reserve Indexed, PPC64 p473) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4528 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4529 | vex_printf("dis_memsync(ppc)(ldarx,b0)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4530 | return False; |
| 4531 | } |
| 4532 | DIP("ldarx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4533 | putIReg( rD_addr, loadBE(Ity_I64, mkexpr(EA)) ); |
| 4534 | // Take a reservation |
| 4535 | putGST( PPC_GST_RESVN, mkexpr(EA) ); |
| 4536 | break; |
| 4537 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4538 | case 0x0D6: { // stdcx. (Store DWord Condition Indexd, PPC64 p581) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4539 | IRTemp resaddr = newTemp(ty); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4540 | if (b0 != 1) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4541 | vex_printf("dis_memsync(ppc)(stdcx.,b0)\n"); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4542 | return False; |
| 4543 | } |
| 4544 | DIP("stdcx. r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4545 | assign( rS, getIReg(rS_addr) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4546 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4547 | // First set up as if the reservation failed |
| 4548 | // Set CR0[LT GT EQ S0] = 0b000 || XER[SO] |
| 4549 | putCR321(0, mkU8(0<<1)); |
| 4550 | putCR0(0, getXER_SO()); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4551 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4552 | // Get the reservation address into a temporary, then clear it. |
| 4553 | assign( resaddr, getGST(PPC_GST_RESVN) ); |
| 4554 | putGST( PPC_GST_RESVN, mkSzImm(ty, 0) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4555 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4556 | // Skip the rest if the reservation really did fail. |
| 4557 | stmt( IRStmt_Exit( binop(Iop_CmpNE64, mkexpr(resaddr), |
| 4558 | mkexpr(EA)), |
| 4559 | Ijk_Boring, |
| 4560 | IRConst_U64(nextInsnAddr())) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4561 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4562 | // Success? Do the store |
| 4563 | storeBE( mkexpr(EA), mkexpr(rS) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4564 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4565 | // Set CR0[LT GT EQ S0] = 0b001 || XER[SO] |
| 4566 | putCR321(0, mkU8(1<<1)); |
| 4567 | break; |
| 4568 | } |
| 4569 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4570 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4571 | vex_printf("dis_memsync(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4572 | return False; |
| 4573 | } |
| 4574 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4575 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4576 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4577 | vex_printf("dis_memsync(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4578 | return False; |
| 4579 | } |
| 4580 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | |
| 4584 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4585 | /* |
| 4586 | Integer Shift Instructions |
| 4587 | */ |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4588 | static Bool dis_int_shift ( UInt theInstr ) |
| 4589 | { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4590 | /* X-Form, XS-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4591 | UChar opc1 = ifieldOPC(theInstr); |
| 4592 | UChar rS_addr = ifieldRegDS(theInstr); |
| 4593 | UChar rA_addr = ifieldRegA(theInstr); |
| 4594 | UChar rB_addr = ifieldRegB(theInstr); |
| 4595 | UChar sh_imm = rB_addr; |
| 4596 | UInt opc2 = ifieldOPClo10(theInstr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4597 | UChar b1 = ifieldBIT1(theInstr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4598 | UChar flag_rC = ifieldBIT0(theInstr); |
| 4599 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4600 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4601 | IRTemp rA = newTemp(ty); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4602 | IRTemp rS = newTemp(ty); |
| 4603 | IRTemp rB = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4604 | IRTemp outofrange = newTemp(Ity_I8); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4605 | IRTemp rS_lo32 = newTemp(Ity_I32); |
| 4606 | IRTemp rB_lo32 = newTemp(Ity_I32); |
| 4607 | IRExpr* e_tmp; |
| 4608 | |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4609 | assign( rS, getIReg(rS_addr) ); |
| 4610 | assign( rB, getIReg(rB_addr) ); |
| 4611 | assign( rS_lo32, mkSzNarrow32(ty, mkexpr(rS)) ); |
| 4612 | assign( rB_lo32, mkSzNarrow32(ty, mkexpr(rB)) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4613 | |
| 4614 | if (opc1 == 0x1F) { |
| 4615 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4616 | case 0x018: { // slw (Shift Left Word, PPC32 p505) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4617 | DIP("slw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4618 | rA_addr, rS_addr, rB_addr); |
| 4619 | /* rA = rS << rB */ |
| 4620 | /* ppc32 semantics are: |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4621 | slw(x,y) = (x << (y & 31)) -- primary result |
| 4622 | & ~((y << 26) >>s 31) -- make result 0 |
| 4623 | for y in 32 .. 63 |
| 4624 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4625 | e_tmp = |
| 4626 | binop( Iop_And32, |
| 4627 | binop( Iop_Shl32, |
| 4628 | mkexpr(rS_lo32), |
| 4629 | unop( Iop_32to8, |
| 4630 | binop(Iop_And32, |
| 4631 | mkexpr(rB_lo32), mkU32(31)))), |
| 4632 | unop( Iop_Not32, |
| 4633 | binop( Iop_Sar32, |
| 4634 | binop(Iop_Shl32, mkexpr(rB_lo32), mkU8(26)), |
| 4635 | mkU8(31))) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4636 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4637 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4640 | case 0x318: { // sraw (Shift Right Alg Word, PPC32 p506) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4641 | IRTemp sh_amt = newTemp(Ity_I32); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4642 | DIP("sraw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4643 | rA_addr, rS_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4644 | /* JRS: my reading of the (poorly worded) PPC32 doc p506 is: |
| 4645 | amt = rB & 63 |
| 4646 | rA = Sar32( rS, amt > 31 ? 31 : amt ) |
| 4647 | XER.CA = amt > 31 ? sign-of-rS : (computation as per srawi) |
| 4648 | */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4649 | assign( sh_amt, binop(Iop_And32, mkU32(0x3F), |
| 4650 | mkexpr(rB_lo32)) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4651 | assign( outofrange, |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 4652 | unop( Iop_1Uto8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4653 | binop(Iop_CmpLT32U, mkU32(31), |
| 4654 | mkexpr(sh_amt)) )); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4655 | e_tmp = binop( Iop_Sar32, |
| 4656 | mkexpr(rS_lo32), |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 4657 | unop( Iop_32to8, |
| 4658 | IRExpr_Mux0X( mkexpr(outofrange), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4659 | mkexpr(sh_amt), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4660 | mkU32(31)) ) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4661 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */True) ); |
| 4662 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4663 | set_XER_CA( ty, PPCG_FLAG_OP_SRAW, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4664 | mkexpr(rA), |
| 4665 | mkSzWiden32(ty, mkexpr(rS_lo32), True), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4666 | mkSzWiden32(ty, mkexpr(sh_amt), True ), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4667 | mkSzWiden32(ty, getXER_CA32(), True) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4668 | break; |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4669 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4670 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4671 | case 0x338: // srawi (Shift Right Alg Word Immediate, PPC32 p507) |
| 4672 | DIP("srawi%s r%u,r%u,%d\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4673 | rA_addr, rS_addr, sh_imm); |
| 4674 | vassert(sh_imm < 32); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4675 | if (mode64) { |
| 4676 | assign( rA, binop(Iop_Sar64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4677 | binop(Iop_Shl64, getIReg(rS_addr), |
| 4678 | mkU8(32)), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4679 | mkU8(32 + sh_imm)) ); |
| 4680 | } else { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4681 | assign( rA, binop(Iop_Sar32, mkexpr(rS_lo32), |
| 4682 | mkU8(sh_imm)) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4683 | } |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4684 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4685 | set_XER_CA( ty, PPCG_FLAG_OP_SRAWI, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4686 | mkexpr(rA), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4687 | mkSzWiden32(ty, mkexpr(rS_lo32), /* Syned */True), |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4688 | mkSzImm(ty, sh_imm), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4689 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4690 | break; |
| 4691 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4692 | case 0x218: // srw (Shift Right Word, PPC32 p508) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4693 | DIP("srw%s r%u,r%u,r%u\n", flag_rC ? ".":"", |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4694 | rA_addr, rS_addr, rB_addr); |
| 4695 | /* rA = rS >>u rB */ |
| 4696 | /* ppc32 semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4697 | srw(x,y) = (x >>u (y & 31)) -- primary result |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4698 | & ~((y << 26) >>s 31) -- make result 0 |
| 4699 | for y in 32 .. 63 |
| 4700 | */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4701 | e_tmp = |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4702 | binop( |
| 4703 | Iop_And32, |
| 4704 | binop( Iop_Shr32, |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4705 | mkexpr(rS_lo32), |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4706 | unop( Iop_32to8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4707 | binop(Iop_And32, mkexpr(rB_lo32), |
| 4708 | mkU32(31)))), |
sewardj | dfb1144 | 2005-10-08 19:58:48 +0000 | [diff] [blame] | 4709 | unop( Iop_Not32, |
| 4710 | binop( Iop_Sar32, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4711 | binop(Iop_Shl32, mkexpr(rB_lo32), |
| 4712 | mkU8(26)), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4713 | mkU8(31)))); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4714 | assign( rA, mkSzWiden32(ty, e_tmp, /* Signed */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4715 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4716 | |
| 4717 | |
| 4718 | /* 64bit Shifts */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4719 | case 0x01B: // sld (Shift Left DWord, PPC64 p568) |
| 4720 | DIP("sld%s r%u,r%u,r%u\n", |
| 4721 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4722 | /* rA = rS << rB */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4723 | /* ppc64 semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4724 | slw(x,y) = (x << (y & 63)) -- primary result |
| 4725 | & ~((y << 57) >>s 63) -- make result 0 |
| 4726 | for y in 64 .. |
| 4727 | */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4728 | assign( rA, |
| 4729 | binop( |
| 4730 | Iop_And64, |
| 4731 | binop( Iop_Shl64, |
| 4732 | mkexpr(rS), |
| 4733 | unop( Iop_64to8, |
| 4734 | binop(Iop_And64, mkexpr(rB), mkU64(63)))), |
| 4735 | unop( Iop_Not64, |
| 4736 | binop( Iop_Sar64, |
| 4737 | binop(Iop_Shl64, mkexpr(rB), mkU8(57)), |
| 4738 | mkU8(63)))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4739 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4740 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4741 | case 0x31A: { // srad (Shift Right Alg DWord, PPC64 p570) |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4742 | IRTemp sh_amt = newTemp(Ity_I64); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4743 | DIP("srad%s r%u,r%u,r%u\n", |
| 4744 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4745 | /* amt = rB & 127 |
| 4746 | rA = Sar64( rS, amt > 63 ? 63 : amt ) |
| 4747 | XER.CA = amt > 63 ? sign-of-rS : (computation as per srawi) |
| 4748 | */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4749 | assign( sh_amt, binop(Iop_And64, mkU64(0x7F), mkexpr(rB)) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4750 | assign( outofrange, |
| 4751 | unop( Iop_1Uto8, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4752 | binop(Iop_CmpLT64U, mkU64(63), |
| 4753 | mkexpr(sh_amt)) )); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4754 | assign( rA, |
| 4755 | binop( Iop_Sar64, |
| 4756 | mkexpr(rS), |
| 4757 | unop( Iop_64to8, |
| 4758 | IRExpr_Mux0X( mkexpr(outofrange), |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4759 | mkexpr(sh_amt), |
| 4760 | mkU64(63)) )) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4761 | ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4762 | set_XER_CA( ty, PPCG_FLAG_OP_SRAD, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4763 | mkexpr(rA), mkexpr(rS), mkexpr(sh_amt), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4764 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4768 | case 0x33A: case 0x33B: // sradi (Shr Alg DWord Imm, PPC64 p571) |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4769 | sh_imm |= b1<<5; |
| 4770 | vassert(sh_imm < 64); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4771 | DIP("sradi%s r%u,r%u,%u\n", |
| 4772 | flag_rC ? ".":"", rA_addr, rS_addr, sh_imm); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4773 | assign( rA, binop(Iop_Sar64, getIReg(rS_addr), mkU8(sh_imm)) ); |
| 4774 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4775 | set_XER_CA( ty, PPCG_FLAG_OP_SRADI, |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4776 | mkexpr(rA), |
| 4777 | getIReg(rS_addr), |
| 4778 | mkU64(sh_imm), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4779 | mkSzWiden32(ty, getXER_CA32(), /* Syned */False) ); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4780 | break; |
| 4781 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4782 | case 0x21B: // srd (Shift Right DWord, PPC64 p574) |
| 4783 | DIP("srd%s r%u,r%u,r%u\n", |
| 4784 | flag_rC ? ".":"", rA_addr, rS_addr, rB_addr); |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4785 | /* rA = rS >>u rB */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4786 | /* ppc semantics are: |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4787 | srw(x,y) = (x >>u (y & 63)) -- primary result |
| 4788 | & ~((y << 57) >>s 63) -- make result 0 |
| 4789 | for y in 64 .. 127 |
| 4790 | */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4791 | assign( rA, |
| 4792 | binop( |
| 4793 | Iop_And64, |
| 4794 | binop( Iop_Shr64, |
| 4795 | mkexpr(rS), |
| 4796 | unop( Iop_64to8, |
| 4797 | binop(Iop_And64, mkexpr(rB), mkU64(63)))), |
| 4798 | unop( Iop_Not64, |
| 4799 | binop( Iop_Sar64, |
| 4800 | binop(Iop_Shl64, mkexpr(rB), mkU8(57)), |
| 4801 | mkU8(63)))) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 4802 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4803 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4804 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4805 | vex_printf("dis_int_shift(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4806 | return False; |
| 4807 | } |
| 4808 | } else { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4809 | vex_printf("dis_int_shift(ppc)(opc1)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4810 | return False; |
| 4811 | } |
cerion | 0d330c5 | 2005-02-28 16:43:16 +0000 | [diff] [blame] | 4812 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4813 | putIReg( rA_addr, mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4814 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4815 | if (flag_rC) { |
| 4816 | set_CR0( mkexpr(rA) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4817 | } |
| 4818 | return True; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | |
| 4822 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4823 | /* |
| 4824 | Integer Load/Store Reverse Instructions |
| 4825 | */ |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4826 | static IRExpr* /* :: Ity_I32 */ gen_byterev32 ( IRTemp t ) |
| 4827 | { |
| 4828 | vassert(typeOfIRTemp(irbb->tyenv, t) == Ity_I32); |
| 4829 | return |
| 4830 | binop(Iop_Or32, |
| 4831 | binop(Iop_Shl32, mkexpr(t), mkU8(24)), |
| 4832 | binop(Iop_Or32, |
| 4833 | binop(Iop_And32, binop(Iop_Shl32, mkexpr(t), mkU8(8)), |
| 4834 | mkU32(0x00FF0000)), |
| 4835 | binop(Iop_Or32, |
| 4836 | binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(8)), |
| 4837 | mkU32(0x0000FF00)), |
| 4838 | binop(Iop_And32, binop(Iop_Shr32, mkexpr(t), mkU8(24)), |
| 4839 | mkU32(0x000000FF) ) |
| 4840 | ))); |
| 4841 | } |
| 4842 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4843 | static Bool dis_int_ldst_rev ( UInt theInstr ) |
| 4844 | { |
| 4845 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4846 | UChar opc1 = ifieldOPC(theInstr); |
| 4847 | UChar rD_addr = ifieldRegDS(theInstr); |
| 4848 | UChar rS_addr = rD_addr; |
| 4849 | UChar rA_addr = ifieldRegA(theInstr); |
| 4850 | UChar rB_addr = ifieldRegB(theInstr); |
| 4851 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4852 | UChar b0 = ifieldBIT0(theInstr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4853 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4854 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 4855 | IRTemp EA = newTemp(ty); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4856 | IRTemp w1 = newTemp(Ity_I32); |
| 4857 | IRTemp w2 = newTemp(Ity_I32); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4858 | |
| 4859 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4860 | vex_printf("dis_int_ldst_rev(ppc)(opc1|b0)\n"); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4861 | return False; |
| 4862 | } |
sewardj | afe8583 | 2005-09-09 10:25:39 +0000 | [diff] [blame] | 4863 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4864 | assign( EA, ea_rAor0_idxd( rA_addr, rB_addr ) ); |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4865 | |
| 4866 | switch (opc2) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4867 | //zz case 0x316: // lhbrx (Load Half Word Byte-Reverse Indexed, PPC32 p449) |
| 4868 | //zz vassert(0); |
| 4869 | //zz |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4870 | //zz DIP("lhbrx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4871 | //zz assign( byte0, loadBE(Ity_I8, mkexpr(EA)) ); |
| 4872 | //zz assign( byte1, loadBE(Ity_I8, binop(Iop_Add32, mkexpr(EA),mkU32(1))) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4873 | //zz assign( rD, binop(Iop_Or32, |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4874 | //zz binop(Iop_Shl32, mkexpr(byte1), mkU8(8)), |
| 4875 | //zz mkexpr(byte0)) ); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4876 | //zz putIReg( rD_addr, mkexpr(rD)); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4877 | //zz break; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4878 | |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4879 | case 0x216: // lwbrx (Load Word Byte-Reverse Indexed, PPC32 p459) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4880 | DIP("lwbrx r%u,r%u,r%u\n", rD_addr, rA_addr, rB_addr); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4881 | assign( w1, loadBE(Ity_I32, mkexpr(EA)) ); |
| 4882 | assign( w2, gen_byterev32(w1) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4883 | putIReg( rD_addr, mkSzWiden32(ty, mkexpr(w2), |
| 4884 | /* Signed */False) ); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4885 | break; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4886 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4887 | //zz case 0x396: // sthbrx (Store Half Word Byte-Reverse Indexed, PPC32 p523) |
| 4888 | //zz vassert(0); |
| 4889 | //zz |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4890 | //zz DIP("sthbrx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4891 | //zz assign( rS, getIReg(rS_addr) ); |
| 4892 | //zz assign( byte0, binop(Iop_And32, mkexpr(rS), mkU32(0x00FF)) ); |
| 4893 | //zz assign( byte1, binop(Iop_And32, mkexpr(rS), mkU32(0xFF00)) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 4894 | //zz |
| 4895 | //zz assign( tmp16, |
| 4896 | //zz unop(Iop_32to16, |
| 4897 | //zz binop(Iop_Or32, |
| 4898 | //zz binop(Iop_Shl32, mkexpr(byte0), mkU8(8)), |
| 4899 | //zz binop(Iop_Shr32, mkexpr(byte1), mkU8(8)))) ); |
| 4900 | //zz storeBE( mkexpr(EA), getIReg(tmp16) ); |
| 4901 | //zz break; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4902 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4903 | case 0x296: // stwbrx (Store Word Byte-Reverse Indxd, PPC32 p531) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4904 | DIP("stwbrx r%u,r%u,r%u\n", rS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4905 | assign( w1, mkSzNarrow32(ty, getIReg(rS_addr)) ); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4906 | storeBE( mkexpr(EA), gen_byterev32(w1) ); |
| 4907 | break; |
| 4908 | |
| 4909 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4910 | vex_printf("dis_int_ldst_rev(ppc)(opc2)\n"); |
sewardj | fb95797 | 2005-09-08 17:53:03 +0000 | [diff] [blame] | 4911 | return False; |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 4912 | } |
| 4913 | return True; |
| 4914 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 4915 | |
| 4916 | |
| 4917 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 4918 | /* |
| 4919 | Processor Control Instructions |
| 4920 | */ |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 4921 | static Bool dis_proc_ctl ( UInt theInstr ) |
| 4922 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4923 | UChar opc1 = ifieldOPC(theInstr); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4924 | |
| 4925 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4926 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 4927 | UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 4928 | UChar rD_addr = ifieldRegDS(theInstr); |
| 4929 | UInt b11to20 = IFIELD( theInstr, 11, 10 ); |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4930 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4931 | /* XFX-Form */ |
| 4932 | UChar rS_addr = rD_addr; |
| 4933 | UInt SPR = b11to20; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4934 | UInt TBR = b11to20; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4935 | UChar b20 = toUChar( IFIELD( theInstr, 20, 1 ) ); |
| 4936 | UInt CRM = IFIELD( theInstr, 12, 8 ); |
| 4937 | UChar b11 = toUChar( IFIELD( theInstr, 11, 1 ) ); |
| 4938 | |
| 4939 | UInt opc2 = ifieldOPClo10(theInstr); |
| 4940 | UChar b0 = ifieldBIT0(theInstr); |
| 4941 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4942 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 4943 | IRTemp rS = newTemp(ty); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4944 | assign( rS, getIReg(rS_addr) ); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 4945 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4946 | /* Reorder SPR field as per PPC32 p470 */ |
| 4947 | SPR = ((SPR & 0x1F) << 5) | ((SPR >> 5) & 0x1F); |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 4948 | /* Reorder TBR field as per PPC32 p475 */ |
| 4949 | TBR = ((TBR & 31) << 5) | ((TBR >> 5) & 31); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4950 | |
| 4951 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4952 | vex_printf("dis_proc_ctl(ppc)(opc1|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4953 | return False; |
| 4954 | } |
| 4955 | |
| 4956 | switch (opc2) { |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 4957 | /* X-Form */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4958 | case 0x200: { // mcrxr (Move to Cond Register from XER, PPC32 p466) |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 4959 | if (b21to22 != 0 || b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4960 | vex_printf("dis_proc_ctl(ppc)(mcrxr,b21to22|b11to20)\n"); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 4961 | return False; |
| 4962 | } |
| 4963 | DIP("mcrxr crf%d\n", crfD); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4964 | /* Move XER[0-3] (the top 4 bits of XER) to CR[crfD] */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4965 | putGST_field( PPC_GST_CR, |
| 4966 | getGST_field( PPC_GST_XER, 7 ), |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4967 | crfD ); |
sewardj | 55ccc3e | 2005-09-09 19:45:02 +0000 | [diff] [blame] | 4968 | |
| 4969 | // Clear XER[0-3] |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 4970 | putXER_SO( mkU8(0) ); |
| 4971 | putXER_OV( mkU8(0) ); |
| 4972 | putXER_CA( mkU8(0) ); |
cerion | cb14e73 | 2005-09-09 16:38:19 +0000 | [diff] [blame] | 4973 | break; |
sewardj | 55ccc3e | 2005-09-09 19:45:02 +0000 | [diff] [blame] | 4974 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4975 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4976 | case 0x013: // mfcr (Move from Cond Register, PPC32 p467) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4977 | if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 4978 | vex_printf("dis_proc_ctl(ppc)(mfcr,b11to20)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4979 | return False; |
| 4980 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4981 | DIP("mfcr r%u\n", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4982 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_CR ), |
| 4983 | /* Signed */False) ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4984 | break; |
| 4985 | |
| 4986 | /* XFX-Form */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 4987 | case 0x153: // mfspr (Move from Special-Purpose Register, PPC32 p470) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 4988 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 4989 | switch (SPR) { // Choose a register... |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4990 | case 0x1: |
| 4991 | DIP("mfxer r%u\n", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 4992 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_XER ), |
| 4993 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 4994 | break; |
| 4995 | case 0x8: |
| 4996 | DIP("mflr r%u\n", rD_addr); |
| 4997 | putIReg( rD_addr, getGST( PPC_GST_LR ) ); |
| 4998 | break; |
| 4999 | case 0x9: |
| 5000 | DIP("mfctr r%u\n", rD_addr); |
| 5001 | putIReg( rD_addr, getGST( PPC_GST_CTR ) ); |
| 5002 | break; |
| 5003 | case 0x100: |
| 5004 | DIP("mfvrsave r%u\n", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5005 | putIReg( rD_addr, mkSzWiden32(ty, getGST( PPC_GST_VRSAVE ), |
| 5006 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5007 | break; |
| 5008 | |
| 5009 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5010 | vex_printf("dis_proc_ctl(ppc)(mfspr,SPR)(0x%x)\n", SPR); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5011 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5012 | } |
| 5013 | break; |
| 5014 | |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5015 | case 0x173: { // mftb (Move from Time Base, PPC32 p475) |
| 5016 | IRTemp val = newTemp(Ity_I64); |
| 5017 | IRExpr** args = mkIRExprVec_0(); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5018 | IRDirty* d = unsafeIRDirty_1_N( val, |
| 5019 | 0/*regparms*/, |
| 5020 | "ppcg_dirtyhelper_MFTB", |
| 5021 | &ppcg_dirtyhelper_MFTB, |
| 5022 | args ); |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5023 | /* execute the dirty call, dumping the result in val. */ |
| 5024 | stmt( IRStmt_Dirty(d) ); |
| 5025 | |
| 5026 | switch (TBR) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5027 | case 269: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5028 | DIP("mftbu r%u", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5029 | putIReg( rD_addr, |
| 5030 | mkSzWiden32(ty, unop(Iop_64HIto32, mkexpr(val)), |
| 5031 | /* Signed */False) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5032 | break; |
| 5033 | case 268: |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5034 | DIP("mftb r%u", rD_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5035 | putIReg( rD_addr, (mode64) ? mkexpr(val) : |
| 5036 | unop(Iop_64to32, mkexpr(val)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5037 | break; |
| 5038 | default: |
| 5039 | return False; /* illegal instruction */ |
sewardj | 73a9197 | 2005-09-06 10:25:46 +0000 | [diff] [blame] | 5040 | } |
| 5041 | break; |
| 5042 | } |
| 5043 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5044 | case 0x090: { // mtcrf (Move to Cond Register Fields, PPC32 p477) |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5045 | Int cr; |
| 5046 | UChar shft; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5047 | if (b11 != 0 || b20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5048 | vex_printf("dis_proc_ctl(ppc)(mtcrf,b11|b20)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5049 | return False; |
| 5050 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5051 | DIP("mtcrf 0x%x,r%u\n", CRM, rS_addr); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5052 | /* Write to each field specified by CRM */ |
| 5053 | for (cr = 0; cr < 8; cr++) { |
| 5054 | if ((CRM & (1 << (7-cr))) == 0) |
| 5055 | continue; |
| 5056 | shft = 4*(7-cr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5057 | putGST_field( PPC_GST_CR, |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5058 | binop(Iop_Shr32, |
| 5059 | mkSzNarrow32(ty, mkexpr(rS)), |
| 5060 | mkU8(shft)), cr ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5061 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5062 | break; |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5063 | } |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5064 | |
| 5065 | case 0x1D3: // mtspr (Move to Special-Purpose Register, PPC32 p483) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5066 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5067 | switch (SPR) { // Choose a register... |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5068 | case 0x1: |
| 5069 | DIP("mtxer r%u\n", rS_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5070 | putGST( PPC_GST_XER, mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5071 | break; |
| 5072 | case 0x8: |
| 5073 | DIP("mtlr r%u\n", rS_addr); |
| 5074 | putGST( PPC_GST_LR, mkexpr(rS) ); |
| 5075 | break; |
| 5076 | case 0x9: |
| 5077 | DIP("mtctr r%u\n", rS_addr); |
| 5078 | putGST( PPC_GST_CTR, mkexpr(rS) ); |
| 5079 | break; |
| 5080 | case 0x100: |
| 5081 | DIP("mtvrsave r%u\n", rS_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5082 | putGST( PPC_GST_VRSAVE, mkSzNarrow32(ty, mkexpr(rS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5083 | break; |
| 5084 | |
| 5085 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5086 | vex_printf("dis_proc_ctl(ppc)(mtspr,SPR)(%u)\n", SPR); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5087 | return False; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5088 | } |
| 5089 | break; |
| 5090 | |
| 5091 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5092 | vex_printf("dis_proc_ctl(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5093 | return False; |
| 5094 | } |
| 5095 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5099 | /* |
| 5100 | Cache Management Instructions |
| 5101 | */ |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5102 | static Bool dis_cache_manage ( UInt theInstr, |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 5103 | DisResult* dres, |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5104 | VexArchInfo* guest_archinfo ) |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5105 | { |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5106 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5107 | UChar opc1 = ifieldOPC(theInstr); |
| 5108 | UChar b21to25 = ifieldRegDS(theInstr); |
| 5109 | UChar rA_addr = ifieldRegA(theInstr); |
| 5110 | UChar rB_addr = ifieldRegB(theInstr); |
| 5111 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5112 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5113 | UInt lineszB = guest_archinfo->ppc_cache_line_szB; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5114 | |
| 5115 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5116 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5117 | if (opc1 != 0x1F || b21to25 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5118 | vex_printf("dis_cache_manage(ppc)(opc1|b21to25|b0)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5119 | return False; |
| 5120 | } |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5121 | |
| 5122 | /* stay sane .. */ |
| 5123 | vassert(lineszB == 32 || lineszB == 128); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5124 | |
| 5125 | switch (opc2) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5126 | //zz case 0x2F6: // dcba (Data Cache Block Allocate, PPC32 p380) |
| 5127 | //zz vassert(0); /* AWAITING TEST CASE */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5128 | //zz DIP("dcba r%u,r%u\n", rA_addr, rB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5129 | //zz if (0) vex_printf("vex ppc->IR: kludged dcba\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5130 | //zz break; |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5131 | |
| 5132 | case 0x056: // dcbf (Data Cache Block Flush, PPC32 p382) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5133 | DIP("dcbf r%u,r%u\n", rA_addr, rB_addr); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5134 | /* nop as far as vex is concerned */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5135 | if (0) vex_printf("vex ppc->IR: kludged dcbf\n"); |
sewardj | 20ef547 | 2005-07-21 14:48:31 +0000 | [diff] [blame] | 5136 | break; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5137 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5138 | case 0x036: // dcbst (Data Cache Block Store, PPC32 p384) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5139 | DIP("dcbst r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5140 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5141 | break; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5142 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5143 | case 0x116: // dcbt (Data Cache Block Touch, PPC32 p385) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5144 | DIP("dcbt r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5145 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5146 | break; |
| 5147 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 5148 | case 0x0F6: // dcbtst (Data Cache Block Touch for Store, PPC32 p386) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5149 | DIP("dcbtst r%u,r%u\n", rA_addr, rB_addr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5150 | /* nop as far as vex is concerned */ |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5151 | break; |
| 5152 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5153 | case 0x3F6: { // dcbz (Data Cache Block Clear to Zero, PPC32 p387) |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5154 | /* Clear all bytes in cache block at (rA|0) + rB. */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5155 | IRTemp EA = newTemp(ty); |
| 5156 | IRTemp addr = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5157 | IRExpr* irx_addr; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5158 | UInt i; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5159 | DIP("dcbz r%u,r%u\n", rA_addr, rB_addr); |
sewardj | cb1f68e | 2005-12-30 03:39:14 +0000 | [diff] [blame^] | 5160 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5161 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5162 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5163 | if (mode64) { |
| 5164 | /* Round EA down to the start of the containing block. */ |
| 5165 | assign( addr, binop( Iop_And64, |
| 5166 | mkexpr(EA), |
| 5167 | mkU64( ~((ULong)lineszB-1) )) ); |
| 5168 | |
| 5169 | for (i = 0; i < lineszB / 8; i++) { |
| 5170 | irx_addr = binop( Iop_Add64, mkexpr(addr), mkU64(i*8) ); |
| 5171 | storeBE( irx_addr, mkU64(0) ); |
| 5172 | } |
| 5173 | } else { |
| 5174 | /* Round EA down to the start of the containing block. */ |
| 5175 | assign( addr, binop( Iop_And32, |
| 5176 | mkexpr(EA), |
| 5177 | mkU32( ~(lineszB-1) )) ); |
| 5178 | |
| 5179 | for (i = 0; i < lineszB / 4; i++) { |
| 5180 | irx_addr = binop( Iop_Add32, mkexpr(addr), mkU32(i*4) ); |
| 5181 | storeBE( irx_addr, mkU32(0) ); |
| 5182 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5183 | } |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5184 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5185 | } |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5186 | |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5187 | case 0x3D6: { |
| 5188 | // icbi (Instruction Cache Block Invalidate, PPC32 p431) |
| 5189 | /* Invalidate all translations containing code from the cache |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 5190 | block at (rA|0) + rB. */ |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5191 | IRTemp EA = newTemp(ty); |
| 5192 | IRTemp addr = newTemp(ty); |
| 5193 | DIP("icbi r%u,r%u\n", rA_addr, rB_addr); |
| 5194 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5195 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5196 | /* Round EA down to the start of the containing block. */ |
| 5197 | assign( addr, binop( mkSzOp(ty, Iop_And8), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5198 | mkexpr(EA), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5199 | mkSzImm(ty, ~(((ULong)lineszB)-1) )) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5200 | putGST( PPC_GST_TISTART, mkexpr(addr) ); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5201 | putGST( PPC_GST_TILEN, mkSzImm(ty, lineszB) ); |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5202 | |
sewardj | a8078f6 | 2005-03-15 18:27:40 +0000 | [diff] [blame] | 5203 | /* be paranoid ... */ |
| 5204 | stmt( IRStmt_MFence() ); |
| 5205 | |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5206 | irbb->jumpkind = Ijk_TInval; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5207 | irbb->next = mkSzImm(ty, nextInsnAddr()); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 5208 | dres->whatNext = Dis_StopHere; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5209 | break; |
sewardj | 7ce9d15 | 2005-03-15 16:54:13 +0000 | [diff] [blame] | 5210 | } |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5211 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5212 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5213 | vex_printf("dis_cache_manage(ppc)(opc2)\n"); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 5214 | return False; |
| 5215 | } |
| 5216 | return True; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5220 | /*------------------------------------------------------------*/ |
| 5221 | /*--- Floating Point Helpers ---*/ |
| 5222 | /*------------------------------------------------------------*/ |
| 5223 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5224 | /* --------- Synthesise a 2-bit FPU rounding mode. --------- */ |
| 5225 | /* Produces a value in 0 .. 3, which is encoded as per the type |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5226 | IRRoundingMode. PPCRoundingMode encoding is different to |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5227 | IRRoundingMode, so need to map it. |
| 5228 | */ |
| 5229 | static IRExpr* /* :: Ity_I32 */ get_roundingmode ( void ) |
| 5230 | { |
| 5231 | /* |
| 5232 | rounding mode | PPC | IR |
| 5233 | ------------------------ |
| 5234 | to nearest | 00 | 00 |
| 5235 | to zero | 01 | 11 |
| 5236 | to +infinity | 10 | 10 |
| 5237 | to -infinity | 11 | 01 |
| 5238 | */ |
| 5239 | IRTemp rm_PPC32 = newTemp(Ity_I32); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5240 | assign( rm_PPC32, getGST_masked( PPC_GST_FPSCR, MASK_FPSCR_RN ) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5241 | |
| 5242 | // rm_IR = XOR( rm_PPC32, (rm_PPC32 << 1) & 2) |
| 5243 | return binop(Iop_Xor32, mkexpr(rm_PPC32), |
| 5244 | binop(Iop_And32, mkU32(2), |
| 5245 | binop(Iop_Shl32, mkexpr(rm_PPC32), mkU8(1)))); |
| 5246 | } |
| 5247 | |
| 5248 | /* Round float to single precision |
| 5249 | - returns type Ity_F64 */ |
| 5250 | static IRExpr* roundToSgl ( IRExpr* src ) |
| 5251 | { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5252 | return unop(Iop_F32toF64, |
| 5253 | binop(Iop_F64toF32, get_roundingmode(), src)); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5254 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5255 | |
| 5256 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5257 | /*------------------------------------------------------------*/ |
| 5258 | /*--- Floating Point Instruction Translation ---*/ |
| 5259 | /*------------------------------------------------------------*/ |
| 5260 | |
| 5261 | /* |
| 5262 | Floating Point Load Instructions |
| 5263 | */ |
| 5264 | static Bool dis_fp_load ( UInt theInstr ) |
| 5265 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5266 | /* X-Form, D-Form */ |
| 5267 | UChar opc1 = ifieldOPC(theInstr); |
| 5268 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5269 | UChar rA_addr = ifieldRegA(theInstr); |
| 5270 | UChar rB_addr = ifieldRegB(theInstr); |
| 5271 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5272 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5273 | UInt uimm16 = ifieldUIMM16(theInstr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5274 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5275 | Int simm16 = extend_s_16to32(uimm16); |
| 5276 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 5277 | IRTemp EA = newTemp(ty); |
| 5278 | IRTemp rA = newTemp(ty); |
| 5279 | IRTemp rB = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5280 | |
| 5281 | assign( rA, getIReg(rA_addr) ); |
| 5282 | assign( rB, getIReg(rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5283 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5284 | |
| 5285 | switch(opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5286 | case 0x30: // lfs (Load Float Single, PPC32 p441) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5287 | DIP("lfs fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5288 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5289 | putFReg( frD_addr, |
| 5290 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5291 | break; |
| 5292 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5293 | case 0x31: // lfsu (Load Float Single, Update, PPC32 p442) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5294 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5295 | vex_printf("dis_fp_load(ppc)(instr,lfsu)\n"); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5296 | return False; |
| 5297 | } |
| 5298 | DIP("lfsu fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5299 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5300 | putFReg( frD_addr, |
| 5301 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5302 | putIReg( rA_addr, mkexpr(EA) ); |
| 5303 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5304 | |
| 5305 | case 0x32: // lfd (Load Float Double, PPC32 p437) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5306 | DIP("lfd fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5307 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5308 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5309 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5310 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5311 | case 0x33: // lfdu (Load Float Double, Update, PPC32 p438) |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5312 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5313 | vex_printf("dis_fp_load(ppc)(instr,lfdu)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5314 | return False; |
| 5315 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5316 | DIP("lfdu fr%u,%d(r%u)\n", frD_addr, simm16, rA_addr); |
| 5317 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5318 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5319 | putIReg( rA_addr, mkexpr(EA) ); |
| 5320 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5321 | |
| 5322 | case 0x1F: |
| 5323 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5324 | vex_printf("dis_fp_load(ppc)(instr,b0)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5325 | return False; |
| 5326 | } |
| 5327 | |
| 5328 | switch(opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5329 | case 0x217: // lfsx (Load Float Single Indexed, PPC32 p444) |
| 5330 | DIP("lfsx fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5331 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5332 | putFReg( frD_addr, unop( Iop_F32toF64, |
| 5333 | loadBE(Ity_F32, mkexpr(EA))) ); |
| 5334 | break; |
| 5335 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5336 | case 0x237: // lfsux (Load Float Single, Update Indxd, PPC32 p443) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5337 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5338 | vex_printf("dis_fp_load(ppc)(instr,lfsux)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5339 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5340 | } |
| 5341 | DIP("lfsux fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5342 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5343 | putFReg( frD_addr, |
| 5344 | unop(Iop_F32toF64, loadBE(Ity_F32, mkexpr(EA))) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5345 | putIReg( rA_addr, mkexpr(EA) ); |
| 5346 | break; |
| 5347 | |
| 5348 | case 0x257: // lfdx (Load Float Double Indexed, PPC32 p440) |
| 5349 | DIP("lfdx fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5350 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5351 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5352 | break; |
| 5353 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5354 | case 0x277: // lfdux (Load Float Double, Update Indxd, PPC32 p439) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5355 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5356 | vex_printf("dis_fp_load(ppc)(instr,lfdux)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5357 | return False; |
| 5358 | } |
| 5359 | DIP("lfdux fr%u,r%u,r%u\n", frD_addr, rA_addr, rB_addr); |
| 5360 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
| 5361 | putFReg( frD_addr, loadBE(Ity_F64, mkexpr(EA)) ); |
| 5362 | putIReg( rA_addr, mkexpr(EA) ); |
| 5363 | break; |
| 5364 | |
| 5365 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5366 | vex_printf("dis_fp_load(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5367 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5368 | } |
| 5369 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5370 | |
| 5371 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5372 | vex_printf("dis_fp_load(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5373 | return False; |
| 5374 | } |
| 5375 | return True; |
| 5376 | } |
| 5377 | |
| 5378 | |
| 5379 | |
| 5380 | /* |
| 5381 | Floating Point Store Instructions |
| 5382 | */ |
| 5383 | static Bool dis_fp_store ( UInt theInstr ) |
| 5384 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5385 | /* X-Form, D-Form */ |
| 5386 | UChar opc1 = ifieldOPC(theInstr); |
| 5387 | UChar frS_addr = ifieldRegDS(theInstr); |
| 5388 | UChar rA_addr = ifieldRegA(theInstr); |
| 5389 | UChar rB_addr = ifieldRegB(theInstr); |
| 5390 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5391 | UChar b0 = ifieldBIT0(theInstr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5392 | Int uimm16 = ifieldUIMM16(theInstr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5393 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5394 | Int simm16 = extend_s_16to32(uimm16); |
| 5395 | IRTemp frS = newTemp(Ity_F64); |
| 5396 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 5397 | IRTemp EA = newTemp(ty); |
| 5398 | IRTemp rA = newTemp(ty); |
| 5399 | IRTemp rB = newTemp(ty); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5400 | |
| 5401 | assign( frS, getFReg(frS_addr) ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5402 | assign( rA, getIReg(rA_addr) ); |
| 5403 | assign( rB, getIReg(rB_addr) ); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5404 | |
| 5405 | switch(opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5406 | |
| 5407 | case 0x34: // stfs (Store Float Single, PPC32 p518) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5408 | DIP("stfs fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5409 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5410 | /* TODO |
| 5411 | This implementation ends up rounding twice, losing accuracy. |
| 5412 | - first via F64toF32, and then by the backend fp store (stfs) |
| 5413 | */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5414 | storeBE( mkexpr(EA), |
| 5415 | binop(Iop_F64toF32, get_roundingmode(), mkexpr(frS)) ); |
| 5416 | break; |
| 5417 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5418 | case 0x35: // stfsu (Store Float Single, Update, PPC32 p519) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5419 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5420 | vex_printf("dis_fp_store(ppc)(instr,stfsu)\n"); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5421 | return False; |
| 5422 | } |
| 5423 | DIP("stfsu fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5424 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5425 | /* This implementation loses accuracy - see note for stfs */ |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5426 | storeBE( mkexpr(EA), |
| 5427 | binop(Iop_F64toF32, get_roundingmode(), mkexpr(frS)) ); |
| 5428 | putIReg( rA_addr, mkexpr(EA) ); |
| 5429 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5430 | |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5431 | case 0x36: // stfd (Store Float Double, PPC32 p513) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5432 | DIP("stfd fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5433 | assign( EA, ea_rAor0_simm(rA_addr, simm16) ); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5434 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5435 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5436 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5437 | case 0x37: // stfdu (Store Float Double, Update, PPC32 p514) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5438 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5439 | vex_printf("dis_fp_store(ppc)(instr,stfdu)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5440 | return False; |
| 5441 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5442 | DIP("stfdu fr%u,%d(r%u)\n", frS_addr, simm16, rA_addr); |
| 5443 | assign( EA, ea_rA_simm(rA_addr, simm16) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5444 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5445 | putIReg( rA_addr, mkexpr(EA) ); |
| 5446 | break; |
| 5447 | |
| 5448 | case 0x1F: |
| 5449 | if (b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5450 | vex_printf("dis_fp_store(ppc)(instr,b0)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5451 | return False; |
| 5452 | } |
| 5453 | |
| 5454 | switch(opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5455 | case 0x297: // stfsx (Store Float Single Indexed, PPC32 p521) |
| 5456 | DIP("stfsx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5457 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5458 | /* This implementation loses accuracy - see note for stfs */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5459 | storeBE( mkexpr(EA), binop(Iop_F64toF32, |
| 5460 | get_roundingmode(), mkexpr(frS)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5461 | break; |
| 5462 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5463 | case 0x2B7: // stfsux (Store Float Sgl, Update Indxd, PPC32 p520) |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5464 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5465 | vex_printf("dis_fp_store(ppc)(instr,stfsux)\n"); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5466 | return False; |
| 5467 | } |
| 5468 | DIP("stfsux fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5469 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5470 | /* This implementation loses accuracy - see note for stfs */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5471 | storeBE( mkexpr(EA), binop(Iop_F64toF32, |
| 5472 | get_roundingmode(), mkexpr(frS)) ); |
cerion | 729edb7 | 2005-12-02 16:03:46 +0000 | [diff] [blame] | 5473 | putIReg( rA_addr, mkexpr(EA) ); |
| 5474 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5475 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5476 | case 0x2D7: // stfdx (Store Float Double Indexed, PPC32 p516) |
| 5477 | DIP("stfdx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5478 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5479 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5480 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5481 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5482 | case 0x2F7: // stfdux (Store Float Dbl, Update Indxd, PPC32 p515) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5483 | if (rA_addr == 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5484 | vex_printf("dis_fp_store(ppc)(instr,stfdux)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5485 | return False; |
| 5486 | } |
| 5487 | DIP("stfdux fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5488 | assign( EA, ea_rA_idxd(rA_addr, rB_addr) ); |
| 5489 | storeBE( mkexpr(EA), mkexpr(frS) ); |
| 5490 | putIReg( rA_addr, mkexpr(EA) ); |
| 5491 | break; |
sewardj | 5f63c0c | 2005-09-09 10:36:55 +0000 | [diff] [blame] | 5492 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 5493 | //zz case 0x3D7: // stfiwx (Store Float as Int, Indexed, PPC32 p517) |
| 5494 | //zz DIP("stfiwx fr%u,r%u,r%u\n", frS_addr, rA_addr, rB_addr); |
| 5495 | //zz assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 5496 | //zz storeBE( mkexpr(EA), |
| 5497 | //zz unop(Iop_64to32, unop(Iop_ReinterpF64asI64, mkexpr(frS))) ); |
| 5498 | //zz break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5499 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5500 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5501 | vex_printf("dis_fp_store(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5502 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5503 | } |
| 5504 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5505 | |
| 5506 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5507 | vex_printf("dis_fp_store(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5508 | return False; |
| 5509 | } |
| 5510 | return True; |
| 5511 | } |
| 5512 | |
| 5513 | |
| 5514 | |
| 5515 | /* |
| 5516 | Floating Point Arith Instructions |
| 5517 | */ |
| 5518 | static Bool dis_fp_arith ( UInt theInstr ) |
| 5519 | { |
| 5520 | /* A-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5521 | UChar opc1 = ifieldOPC(theInstr); |
| 5522 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5523 | UChar frA_addr = ifieldRegA(theInstr); |
| 5524 | UChar frB_addr = ifieldRegB(theInstr); |
| 5525 | UChar frC_addr = ifieldRegC(theInstr); |
| 5526 | UChar opc2 = ifieldOPClo5(theInstr); |
| 5527 | UChar flag_rC = ifieldBIT0(theInstr); |
| 5528 | // Note: flag_rC ignored as fp exceptions not supported. |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5529 | |
| 5530 | IRTemp frD = newTemp(Ity_F64); |
| 5531 | IRTemp frA = newTemp(Ity_F64); |
| 5532 | IRTemp frB = newTemp(Ity_F64); |
| 5533 | IRTemp frC = newTemp(Ity_F64); |
| 5534 | |
| 5535 | assign( frA, getFReg(frA_addr)); |
| 5536 | assign( frB, getFReg(frB_addr)); |
| 5537 | assign( frC, getFReg(frC_addr)); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5538 | |
| 5539 | switch (opc1) { |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5540 | case 0x3B: |
| 5541 | switch (opc2) { |
| 5542 | case 0x12: // fdivs (Floating Divide Single, PPC32 p407) |
| 5543 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5544 | vex_printf("dis_fp_arith(ppc)(instr,fdivs)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5545 | return False; |
| 5546 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5547 | DIP("fdivs%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5548 | frD_addr, frA_addr, frB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5549 | assign( frD, roundToSgl( binop(Iop_DivF64, |
| 5550 | mkexpr(frA), mkexpr(frB)) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5551 | break; |
| 5552 | |
| 5553 | case 0x14: // fsubs (Floating Subtract Single, PPC32 p430) |
| 5554 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5555 | vex_printf("dis_fp_arith(ppc)(instr,fsubs)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5556 | return False; |
| 5557 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5558 | DIP("fsubs%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5559 | frD_addr, frA_addr, frB_addr); |
| 5560 | assign( frD, roundToSgl( |
| 5561 | binop(Iop_SubF64, mkexpr(frA), mkexpr(frB)) )); |
| 5562 | break; |
| 5563 | |
| 5564 | case 0x15: // fadds (Floating Add Single, PPC32 p401) |
| 5565 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5566 | vex_printf("dis_fp_arith(ppc)(instr,fadds)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5567 | return False; |
| 5568 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5569 | DIP("fadds%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5570 | frD_addr, frA_addr, frB_addr); |
| 5571 | assign( frD, roundToSgl( |
| 5572 | binop(Iop_AddF64, mkexpr(frA), mkexpr(frB)) )); |
| 5573 | break; |
| 5574 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5575 | //zz case 0x16: // fsqrts (Floating SqRt (Single-Precision), PPC32 p428) |
| 5576 | //zz if (frA_addr != 0 || frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5577 | //zz vex_printf("dis_fp_arith(ppc)(instr,fsqrts)\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5578 | //zz return False; |
| 5579 | //zz } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5580 | //zz DIP("fsqrts%s fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5581 | //zz frD_addr, frB_addr); |
| 5582 | //zz assign( frD, roundToSgl( unop(Iop_SqrtF64, mkexpr(frB)) )); |
| 5583 | //zz break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5584 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5585 | //zz case 0x18: // fres (Floating Reciprocal Estimate Single, PPC32 p421) |
| 5586 | //zz if (frA_addr != 0 || frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5587 | //zz vex_printf("dis_fp_arith(ppc)(instr,fres)\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5588 | //zz return False; |
| 5589 | //zz } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5590 | //zz DIP("fres%s fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5591 | //zz frD_addr, frB_addr); |
| 5592 | //zz DIP(" => not implemented\n"); |
| 5593 | //zz // CAB: Can we use one of the 128 bit SIMD Iop_Recip32F ops? |
| 5594 | //zz return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5595 | |
| 5596 | case 0x19: // fmuls (Floating Multiply Single, PPC32 p414) |
| 5597 | if (frB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5598 | vex_printf("dis_fp_arith(ppc)(instr,fmuls)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5599 | return False; |
| 5600 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5601 | DIP("fmuls%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5602 | frD_addr, frA_addr, frC_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5603 | assign( frD, roundToSgl( binop(Iop_MulF64, |
| 5604 | mkexpr(frA), mkexpr(frC)) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5605 | break; |
| 5606 | |
| 5607 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5608 | vex_printf("dis_fp_arith(ppc)(3B: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5609 | return False; |
| 5610 | } |
| 5611 | break; |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5612 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5613 | case 0x3F: |
| 5614 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5615 | case 0x12: // fdiv (Floating Div (Double-Precision), PPC32 p406) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5616 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5617 | vex_printf("dis_fp_arith(ppc)(instr,fdiv)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5618 | return False; |
| 5619 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5620 | DIP("fdiv%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5621 | frD_addr, frA_addr, frB_addr); |
| 5622 | assign( frD, binop( Iop_DivF64, mkexpr(frA), mkexpr(frB) ) ); |
| 5623 | break; |
| 5624 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5625 | case 0x14: // fsub (Floating Sub (Double-Precision), PPC32 p429) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5626 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5627 | vex_printf("dis_fp_arith(ppc)(instr,fsub)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5628 | return False; |
| 5629 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5630 | DIP("fsub%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5631 | frD_addr, frA_addr, frB_addr); |
| 5632 | assign( frD, binop( Iop_SubF64, mkexpr(frA), mkexpr(frB) ) ); |
| 5633 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5634 | |
| 5635 | case 0x15: // fadd (Floating Add (Double-Precision), PPC32 p400) |
| 5636 | if (frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5637 | vex_printf("dis_fp_arith(ppc)(instr,fadd)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5638 | return False; |
| 5639 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5640 | DIP("fadd%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5641 | frD_addr, frA_addr, frB_addr); |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5642 | assign( frD, binop( Iop_AddF64, mkexpr(frA), mkexpr(frB) ) ); |
| 5643 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5644 | |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5645 | case 0x16: // fsqrt (Floating SqRt (Double-Precision), PPC32 p427) |
| 5646 | if (frA_addr != 0 || frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5647 | vex_printf("dis_fp_arith(ppc)(instr,fsqrt)\n"); |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5648 | return False; |
| 5649 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5650 | DIP("fsqrt%s fr%u,fr%u\n", flag_rC ? ".":"", |
cerion | 876ef41 | 2005-12-14 22:00:53 +0000 | [diff] [blame] | 5651 | frD_addr, frB_addr); |
| 5652 | assign( frD, unop( Iop_SqrtF64, mkexpr(frB) ) ); |
| 5653 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5654 | |
| 5655 | case 0x17: { // fsel (Floating Select, PPC32 p426) |
| 5656 | IRTemp cc = newTemp(Ity_I32); |
| 5657 | IRTemp cc_b0 = newTemp(Ity_I32); |
| 5658 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5659 | DIP("fsel%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5660 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5661 | |
| 5662 | // cc: UN == 0x41, LT == 0x01, GT == 0x00, EQ == 0x40 |
| 5663 | // => GT|EQ == (cc & 0x1 == 0) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5664 | assign( cc, binop(Iop_CmpF64, mkexpr(frA), |
| 5665 | IRExpr_Const(IRConst_F64(0))) ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5666 | assign( cc_b0, binop(Iop_And32, mkexpr(cc), mkU32(1)) ); |
| 5667 | |
| 5668 | // frD = (frA >= 0.0) ? frC : frB |
| 5669 | // = (cc_b0 == 0) ? frC : frB |
| 5670 | assign( frD, |
| 5671 | IRExpr_Mux0X( |
| 5672 | unop(Iop_1Uto8, |
| 5673 | binop(Iop_CmpEQ32, mkexpr(cc_b0), mkU32(0))), |
| 5674 | mkexpr(frB), |
| 5675 | mkexpr(frC) )); |
| 5676 | break; |
| 5677 | } |
| 5678 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5679 | case 0x19: // fmul (Floating Mult (Double Precision), PPC32 p413) |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5680 | if (frB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5681 | vex_printf("dis_fp_arith(ppc)(instr,fmul)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5682 | return False; |
| 5683 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5684 | DIP("fmul%s fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5685 | frD_addr, frA_addr, frC_addr); |
| 5686 | assign( frD, binop( Iop_MulF64, mkexpr(frA), mkexpr(frC) ) ); |
| 5687 | break; |
| 5688 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5689 | //zz case 0x1A: // frsqrte (Floating Recip SqRt Est., PPC32 p424) |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5690 | //zz if (frA_addr != 0 || frC_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5691 | //zz vex_printf("dis_fp_arith(ppc)(instr,frsqrte)\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5692 | //zz return False; |
| 5693 | //zz } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5694 | //zz DIP("frsqrte%s fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 5695 | //zz frD_addr, frB_addr); |
| 5696 | //zz DIP(" => not implemented\n"); |
| 5697 | //zz // CAB: Iop_SqrtF64, then one of the 128 bit SIMD Iop_Recip32F ops? |
| 5698 | //zz return False; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5699 | |
| 5700 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5701 | vex_printf("dis_fp_arith(ppc)(3F: opc2)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5702 | return False; |
| 5703 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5704 | break; |
| 5705 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5706 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5707 | vex_printf("dis_fp_arith(ppc)(opc1)\n"); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5708 | return False; |
| 5709 | } |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 5710 | |
| 5711 | putFReg( frD_addr, mkexpr(frD) ); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 5712 | return True; |
| 5713 | } |
| 5714 | |
| 5715 | |
| 5716 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5717 | /* |
| 5718 | Floating Point Mult-Add Instructions |
| 5719 | */ |
| 5720 | static Bool dis_fp_multadd ( UInt theInstr ) |
| 5721 | { |
| 5722 | /* A-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5723 | UChar opc1 = ifieldOPC(theInstr); |
| 5724 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5725 | UChar frA_addr = ifieldRegA(theInstr); |
| 5726 | UChar frB_addr = ifieldRegB(theInstr); |
| 5727 | UChar frC_addr = ifieldRegC(theInstr); |
| 5728 | UChar opc2 = ifieldOPClo5(theInstr); |
| 5729 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5730 | |
| 5731 | IRTemp frD = newTemp(Ity_F64); |
| 5732 | IRTemp frA = newTemp(Ity_F64); |
| 5733 | IRTemp frB = newTemp(Ity_F64); |
| 5734 | IRTemp frC = newTemp(Ity_F64); |
| 5735 | |
| 5736 | assign( frA, getFReg(frA_addr)); |
| 5737 | assign( frB, getFReg(frB_addr)); |
| 5738 | assign( frC, getFReg(frC_addr)); |
| 5739 | |
| 5740 | switch (opc1) { |
| 5741 | case 0x3B: |
| 5742 | switch (opc2) { |
| 5743 | case 0x1C: // fmsubs (Floating Mult-Subtr Single, PPC32 p412) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5744 | DIP("fmsubs%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5745 | frD_addr, frA_addr, frC_addr, frB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5746 | assign( frD, roundToSgl( binop( Iop_SubF64, |
| 5747 | binop(Iop_MulF64, mkexpr(frA), |
| 5748 | mkexpr(frC)), |
| 5749 | mkexpr(frB)) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5750 | break; |
| 5751 | |
| 5752 | case 0x1D: // fmadds (Floating Mult-Add Single, PPC32 p409) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5753 | DIP("fmadds%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5754 | frD_addr, frA_addr, frC_addr, frB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5755 | assign( frD, roundToSgl( binop( Iop_AddF64, |
| 5756 | binop(Iop_MulF64, mkexpr(frA), |
| 5757 | mkexpr(frC)), |
| 5758 | mkexpr(frB)) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5759 | break; |
| 5760 | |
| 5761 | case 0x1E: // fnmsubs (Float Neg Mult-Subtr Single, PPC32 p420) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5762 | DIP("fnmsubs%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5763 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5764 | assign( frD, roundToSgl( |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5765 | unop(Iop_NegF64, |
| 5766 | binop(Iop_SubF64, |
| 5767 | binop(Iop_MulF64, mkexpr(frA), |
| 5768 | mkexpr(frC)), |
| 5769 | mkexpr(frB))) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5770 | break; |
| 5771 | |
| 5772 | case 0x1F: // fnmadds (Floating Negative Multiply-Add Single, PPC32 p418) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5773 | DIP("fnmadds%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5774 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5775 | assign( frD, roundToSgl( |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5776 | unop(Iop_NegF64, |
| 5777 | binop(Iop_AddF64, |
| 5778 | binop(Iop_MulF64, mkexpr(frA), |
| 5779 | mkexpr(frC)), |
| 5780 | mkexpr(frB))) )); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5781 | break; |
| 5782 | |
| 5783 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5784 | vex_printf("dis_fp_multadd(ppc)(3B: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5785 | return False; |
| 5786 | } |
| 5787 | break; |
| 5788 | |
| 5789 | case 0x3F: |
| 5790 | switch (opc2) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5791 | case 0x1C: // fmsub (Float Mult-Sub (Dbl Precision), PPC32 p411) |
| 5792 | DIP("fmsub%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5793 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5794 | assign( frD, binop( Iop_SubF64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5795 | binop( Iop_MulF64, mkexpr(frA), |
| 5796 | mkexpr(frC) ), |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5797 | mkexpr(frB) )); |
| 5798 | break; |
| 5799 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5800 | case 0x1D: // fmadd (Float Mult-Add (Dbl Precision), PPC32 p408) |
| 5801 | DIP("fmadd%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5802 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5803 | assign( frD, binop( Iop_AddF64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5804 | binop( Iop_MulF64, mkexpr(frA), |
| 5805 | mkexpr(frC) ), |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5806 | mkexpr(frB) )); |
| 5807 | break; |
| 5808 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5809 | case 0x1E: // fnmsub (Float Neg Mult-Subtr (Dbl Precision), PPC32 p419) |
| 5810 | DIP("fnmsub%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5811 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5812 | assign( frD, unop( Iop_NegF64, |
| 5813 | binop( Iop_SubF64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5814 | binop( Iop_MulF64, mkexpr(frA), |
| 5815 | mkexpr(frC) ), |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5816 | mkexpr(frB) ))); |
| 5817 | break; |
| 5818 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5819 | case 0x1F: // fnmadd (Float Neg Mult-Add (Dbl Precision), PPC32 p417) |
| 5820 | DIP("fnmadd%s fr%u,fr%u,fr%u,fr%u\n", flag_rC ? ".":"", |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5821 | frD_addr, frA_addr, frC_addr, frB_addr); |
| 5822 | assign( frD, unop( Iop_NegF64, |
| 5823 | binop( Iop_AddF64, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5824 | binop( Iop_MulF64, mkexpr(frA), |
| 5825 | mkexpr(frC) ), |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 5826 | mkexpr(frB) ))); |
| 5827 | break; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5828 | |
| 5829 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5830 | vex_printf("dis_fp_multadd(ppc)(3F: opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5831 | return False; |
| 5832 | } |
| 5833 | break; |
| 5834 | |
| 5835 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5836 | vex_printf("dis_fp_multadd(ppc)(opc1)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5837 | return False; |
| 5838 | } |
| 5839 | |
| 5840 | putFReg( frD_addr, mkexpr(frD) ); |
| 5841 | return True; |
| 5842 | } |
| 5843 | |
| 5844 | |
| 5845 | |
| 5846 | /* |
| 5847 | Floating Point Compare Instructions |
| 5848 | */ |
| 5849 | static Bool dis_fp_cmp ( UInt theInstr ) |
| 5850 | { |
| 5851 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5852 | UChar opc1 = ifieldOPC(theInstr); |
| 5853 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 5854 | UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 5855 | UChar frA_addr = ifieldRegA(theInstr); |
| 5856 | UChar frB_addr = ifieldRegB(theInstr); |
| 5857 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5858 | UChar b0 = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5859 | |
| 5860 | IRTemp ccIR = newTemp(Ity_I32); |
| 5861 | IRTemp ccPPC32 = newTemp(Ity_I32); |
| 5862 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5863 | IRTemp frA = newTemp(Ity_F64); |
| 5864 | IRTemp frB = newTemp(Ity_F64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5865 | |
| 5866 | if (opc1 != 0x3F || b21to22 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5867 | vex_printf("dis_fp_cmp(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5868 | return False; |
| 5869 | } |
| 5870 | |
| 5871 | assign( frA, getFReg(frA_addr)); |
| 5872 | assign( frB, getFReg(frB_addr)); |
| 5873 | |
| 5874 | assign( ccIR, binop(Iop_CmpF64, mkexpr(frA), mkexpr(frB)) ); |
| 5875 | |
| 5876 | /* Map compare result from IR to PPC32 */ |
| 5877 | /* |
| 5878 | FP cmp result | PPC | IR |
| 5879 | -------------------------- |
| 5880 | UN | 0x1 | 0x45 |
| 5881 | EQ | 0x2 | 0x40 |
| 5882 | GT | 0x4 | 0x00 |
| 5883 | LT | 0x8 | 0x01 |
| 5884 | */ |
| 5885 | |
| 5886 | // ccPPC32 = Shl(1, (0x2 & ~(ccIR>>5)) || (0x1 & (XOR(ccIR, ccIR>>6)))) |
| 5887 | assign( |
| 5888 | ccPPC32, |
| 5889 | binop(Iop_Shl32, mkU32(1), |
| 5890 | unop(Iop_32to8, |
| 5891 | binop(Iop_Or32, |
| 5892 | binop(Iop_And32, mkU32(2), |
| 5893 | unop(Iop_Not32, |
| 5894 | binop(Iop_Shr32, mkexpr(ccIR), mkU8(5)))), |
| 5895 | binop(Iop_And32, mkU32(1), |
| 5896 | binop(Iop_Xor32, mkexpr(ccIR), |
| 5897 | binop(Iop_Shr32, mkexpr(ccIR), mkU8(6))))))) |
| 5898 | ); |
| 5899 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5900 | putGST_field( PPC_GST_CR, mkexpr(ccPPC32), crfD ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5901 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5902 | /* CAB: TODO?: Support writing cc to FPSCR->FPCC ? |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5903 | putGST_field( PPC_GST_FPSCR, mkexpr(ccPPC32), 4 ); |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5904 | */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5905 | |
cerion | edf7fc5 | 2005-11-18 20:57:41 +0000 | [diff] [blame] | 5906 | /* Note: Differences between fcmpu and fcmpo are only in exception |
| 5907 | flag settings, which aren't supported anyway. */ |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5908 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5909 | case 0x000: // fcmpu (Floating Compare Unordered, PPC32 p403) |
| 5910 | DIP("fcmpu crf%d,fr%u,fr%u\n", crfD, frA_addr, frB_addr); |
| 5911 | break; |
| 5912 | case 0x020: // fcmpo (Floating Compare Ordered, PPC32 p402) |
| 5913 | DIP("fcmpo crf%d,fr%u,fr%u\n", crfD, frA_addr, frB_addr); |
| 5914 | break; |
| 5915 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5916 | vex_printf("dis_fp_cmp(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5917 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5918 | } |
| 5919 | return True; |
| 5920 | } |
| 5921 | |
| 5922 | |
| 5923 | |
| 5924 | /* |
| 5925 | Floating Point Rounding/Conversion Instructions |
| 5926 | */ |
| 5927 | static Bool dis_fp_round ( UInt theInstr ) |
| 5928 | { |
| 5929 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 5930 | UChar opc1 = ifieldOPC(theInstr); |
| 5931 | UChar frD_addr = ifieldRegDS(theInstr); |
| 5932 | UChar b16to20 = ifieldRegA(theInstr); |
| 5933 | UChar frB_addr = ifieldRegB(theInstr); |
| 5934 | UInt opc2 = ifieldOPClo10(theInstr); |
| 5935 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5936 | |
| 5937 | IRTemp frD = newTemp(Ity_F64); |
| 5938 | IRTemp frB = newTemp(Ity_F64); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5939 | IRTemp r_tmp32 = newTemp(Ity_I32); |
| 5940 | IRTemp r_tmp64 = newTemp(Ity_I64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5941 | |
| 5942 | if (opc1 != 0x3F || b16to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5943 | vex_printf("dis_fp_round(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5944 | return False; |
| 5945 | } |
| 5946 | |
| 5947 | assign( frB, getFReg(frB_addr)); |
| 5948 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5949 | switch (opc2) { |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5950 | case 0x00C: // frsp (Float Round to Single, PPC32 p423) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5951 | DIP("frsp%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5952 | assign( frD, roundToSgl( mkexpr(frB) )); |
| 5953 | break; |
| 5954 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5955 | case 0x00E: // fctiw (Float Conv to Int, PPC32 p404) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5956 | DIP("fctiw%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
| 5957 | assign( r_tmp32, |
| 5958 | binop(Iop_F64toI32, get_roundingmode(), mkexpr(frB)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5959 | assign( frD, unop( Iop_ReinterpI64asF64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5960 | unop( Iop_32Uto64, mkexpr(r_tmp32)))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5961 | break; |
| 5962 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5963 | case 0x00F: // fctiwz (Float Conv to Int, Round to Zero, PPC32 p405) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5964 | DIP("fctiwz%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5965 | assign( r_tmp32, binop(Iop_F64toI32, mkU32(0x3), mkexpr(frB)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5966 | assign( frD, unop( Iop_ReinterpI64asF64, |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5967 | unop( Iop_32Uto64, mkexpr(r_tmp32)))); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5968 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5969 | |
| 5970 | |
| 5971 | /* 64bit FP conversions */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5972 | case 0x32E: // fctid (Float Conv to Int DWord, PPC64 p437) |
| 5973 | DIP("fctid%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
| 5974 | assign( r_tmp64, |
| 5975 | binop(Iop_F64toI64, get_roundingmode(), mkexpr(frB)) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5976 | assign( frD, unop( Iop_ReinterpI64asF64, mkexpr(r_tmp64)) ); |
| 5977 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5978 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5979 | case 0x32F: // fctidz (Float Conv to Int DWord, Round to Zero, PPC64 p437) |
| 5980 | DIP("fctidz%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5981 | assign( r_tmp64, binop(Iop_F64toI64, mkU32(0x3), mkexpr(frB)) ); |
| 5982 | assign( frD, unop( Iop_ReinterpI64asF64, mkexpr(r_tmp64)) ); |
| 5983 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5984 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5985 | case 0x34E: // fcfid (Float Conv from Int DWord, PPC64 p434) |
| 5986 | DIP("fcfid%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5987 | assign( r_tmp64, unop( Iop_ReinterpF64asI64, mkexpr(frB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5988 | assign( frD, binop(Iop_I64toF64, get_roundingmode(), |
| 5989 | mkexpr(r_tmp64)) ); |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 5990 | break; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 5991 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5992 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 5993 | vex_printf("dis_fp_round(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 5994 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | putFReg( frD_addr, mkexpr(frD) ); |
| 5998 | return True; |
| 5999 | } |
| 6000 | |
| 6001 | |
| 6002 | |
| 6003 | /* |
| 6004 | Floating Point Move Instructions |
| 6005 | */ |
| 6006 | static Bool dis_fp_move ( UInt theInstr ) |
| 6007 | { |
| 6008 | /* X-Form */ |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6009 | UChar opc1 = ifieldOPC(theInstr); |
| 6010 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6011 | UChar b16to20 = ifieldRegA(theInstr); |
| 6012 | UChar frB_addr = ifieldRegB(theInstr); |
| 6013 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6014 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6015 | |
| 6016 | IRTemp frD = newTemp(Ity_F64); |
| 6017 | IRTemp frB = newTemp(Ity_F64); |
| 6018 | |
| 6019 | if (opc1 != 0x3F || b16to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6020 | vex_printf("dis_fp_move(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6021 | return False; |
| 6022 | } |
| 6023 | |
| 6024 | assign( frB, getFReg(frB_addr)); |
| 6025 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6026 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6027 | case 0x028: // fneg (Floating Negate, PPC32 p416) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6028 | DIP("fneg%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6029 | assign( frD, unop( Iop_NegF64, mkexpr(frB) )); |
| 6030 | break; |
| 6031 | |
| 6032 | case 0x048: // fmr (Floating Move Register, PPC32 p410) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6033 | DIP("fmr%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6034 | assign( frD, mkexpr(frB) ); |
| 6035 | break; |
| 6036 | |
| 6037 | case 0x088: // fnabs (Floating Negative Absolute Value, PPC32 p415) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6038 | DIP("fnabs%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6039 | assign( frD, unop( Iop_NegF64, unop( Iop_AbsF64, mkexpr(frB) ))); |
| 6040 | break; |
| 6041 | |
| 6042 | case 0x108: // fabs (Floating Absolute Value, PPC32 p399) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6043 | DIP("fabs%s fr%u,fr%u\n", flag_rC ? ".":"", frD_addr, frB_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6044 | assign( frD, unop( Iop_AbsF64, mkexpr(frB) )); |
| 6045 | break; |
| 6046 | |
| 6047 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6048 | vex_printf("dis_fp_move(ppc)(opc2)\n"); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6049 | return False; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | putFReg( frD_addr, mkexpr(frD) ); |
| 6053 | return True; |
| 6054 | } |
| 6055 | |
| 6056 | |
| 6057 | |
| 6058 | /* |
| 6059 | Floating Point Status/Control Register Instructions |
| 6060 | */ |
| 6061 | static Bool dis_fp_scr ( UInt theInstr ) |
| 6062 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6063 | /* Many forms - see each switch case */ |
| 6064 | UChar opc1 = ifieldOPC(theInstr); |
| 6065 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6066 | UChar flag_rC = ifieldBIT0(theInstr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6067 | |
| 6068 | if (opc1 != 0x3F) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6069 | vex_printf("dis_fp_scr(ppc)(instr)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6070 | return False; |
| 6071 | } |
| 6072 | |
| 6073 | switch (opc2) { |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6074 | //zz case 0x026: { // mtfsb1 (Move to FPSCR Bit 1, PPC32 p479) |
| 6075 | //zz // Bit crbD of the FPSCR is set. |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6076 | //zz UChar crbD = ifieldRegDS(theInstr); |
| 6077 | //zz UInt b11to20 = IFIELD(theInstr, 11, 10); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6078 | //zz |
| 6079 | //zz if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6080 | //zz vex_printf("dis_fp_scr(ppc)(instr,mtfsb1)\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6081 | //zz return False; |
| 6082 | //zz } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6083 | //zz DIP("mtfsb1%s crb%d \n", flag_rC ? ".":"", crbD); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6084 | //zz putGST_masked( PPC_GST_FPSCR, mkU32(1<<(31-crbD)), 1<<(31-crbD) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6085 | //zz break; |
| 6086 | //zz } |
| 6087 | //zz |
| 6088 | //zz case 0x040: { // mcrfs (Move to Condition Register from FPSCR, PPC32 p465) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6089 | //zz UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 6090 | //zz UChar b21to22 = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 6091 | //zz UChar crfS = toUChar( IFIELD( theInstr, 18, 3 ) ); |
| 6092 | //zz UChar b11to17 = toUChar( IFIELD( theInstr, 11, 7 ) ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6093 | //zz |
| 6094 | //zz IRTemp tmp = newTemp(Ity_I32); |
| 6095 | //zz |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6096 | //zz if (b21to22 != 0 || b11to17 != 0 || flag_rC != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6097 | //zz vex_printf("dis_fp_scr(ppc)(instr,mcrfs)\n"); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6098 | //zz return False; |
| 6099 | //zz } |
| 6100 | //zz DIP("mcrfs crf%d,crf%d\n", crfD, crfS); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6101 | //zz assign( tmp, getGST_field( PPC_GST_FPSCR, crfS ) ); |
| 6102 | //zz putGST_field( PPC_GST_CR, mkexpr(tmp), crfD ); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 6103 | //zz break; |
| 6104 | //zz } |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6105 | |
| 6106 | case 0x046: { // mtfsb0 (Move to FPSCR Bit 0, PPC32 p478) |
| 6107 | // Bit crbD of the FPSCR is cleared. |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6108 | UChar crbD = ifieldRegDS(theInstr); |
| 6109 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6110 | |
| 6111 | if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6112 | vex_printf("dis_fp_scr(ppc)(instr,mtfsb0)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6113 | return False; |
| 6114 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6115 | DIP("mtfsb0%s crb%d\n", flag_rC ? ".":"", crbD); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6116 | putGST_masked( PPC_GST_FPSCR, mkU32(0), 1<<(31-crbD) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6117 | break; |
| 6118 | } |
| 6119 | |
| 6120 | case 0x086: { // mtfsfi (Move to FPSCR Field Immediate, PPC32 p481) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6121 | UChar crfD = toUChar( IFIELD( theInstr, 23, 3 ) ); |
| 6122 | UChar b16to22 = toUChar( IFIELD( theInstr, 16, 7 ) ); |
| 6123 | UChar IMM = toUChar( IFIELD( theInstr, 12, 4 ) ); |
| 6124 | UChar b11 = toUChar( IFIELD( theInstr, 11, 1 ) ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6125 | |
| 6126 | if (b16to22 != 0 || b11 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6127 | vex_printf("dis_fp_scr(ppc)(instr,mtfsfi)\n"); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6128 | return False; |
| 6129 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6130 | DIP("mtfsfi%s crf%d,%d\n", flag_rC ? ".":"", crfD, IMM); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6131 | putGST_field( PPC_GST_FPSCR, mkU32(IMM), crfD ); |
sewardj | 0e2cc67 | 2005-07-29 21:58:51 +0000 | [diff] [blame] | 6132 | break; |
| 6133 | } |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6134 | |
| 6135 | case 0x247: { // mffs (Move from FPSCR, PPC32 p468) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6136 | UChar frD_addr = ifieldRegDS(theInstr); |
| 6137 | UInt b11to20 = IFIELD(theInstr, 11, 10); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6138 | |
| 6139 | if (b11to20 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6140 | vex_printf("dis_fp_scr(ppc)(instr,mffs)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6141 | return False; |
| 6142 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6143 | DIP("mffs%s fr%u\n", flag_rC ? ".":"", frD_addr); |
| 6144 | putFReg( frD_addr, |
| 6145 | unop( Iop_ReinterpI64asF64, |
| 6146 | unop( Iop_32Uto64, |
| 6147 | getGST_masked( PPC_GST_FPSCR, MASK_FPSCR_RN ) ))); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6148 | break; |
| 6149 | } |
| 6150 | |
| 6151 | case 0x2C7: { // mtfsf (Move to FPSCR Fields, PPC32 p480) |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6152 | UChar b25 = toUChar( IFIELD(theInstr, 25, 1) ); |
| 6153 | UChar FM = toUChar( IFIELD(theInstr, 17, 8) ); |
| 6154 | UChar b16 = toUChar( IFIELD(theInstr, 16, 1) ); |
| 6155 | UChar frB_addr = ifieldRegB(theInstr); |
| 6156 | IRTemp frB = newTemp(Ity_F64); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6157 | IRTemp rB_32 = newTemp(Ity_I32); |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6158 | Int i, mask; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6159 | |
| 6160 | if (b25 != 0 || b16 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6161 | vex_printf("dis_fp_scr(ppc)(instr,mtfsf)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6162 | return False; |
| 6163 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6164 | DIP("mtfsf%s %d,fr%u\n", flag_rC ? ".":"", FM, frB_addr); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6165 | assign( frB, getFReg(frB_addr)); |
| 6166 | assign( rB_32, unop( Iop_64to32, |
| 6167 | unop( Iop_ReinterpF64asI64, mkexpr(frB) ))); |
| 6168 | // Build 32bit mask from FM: |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6169 | mask = 0; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6170 | for (i=0; i<8; i++) { |
| 6171 | if ((FM & (1<<(7-i))) == 1) { |
| 6172 | mask |= 0xF << (7-i); |
| 6173 | } |
| 6174 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6175 | putGST_masked( PPC_GST_FPSCR, mkexpr(rB_32), mask ); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6176 | break; |
| 6177 | } |
| 6178 | |
| 6179 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6180 | vex_printf("dis_fp_scr(ppc)(opc2)\n"); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 6181 | return False; |
| 6182 | } |
| 6183 | return True; |
| 6184 | } |
| 6185 | |
| 6186 | |
| 6187 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6188 | /*------------------------------------------------------------*/ |
| 6189 | /*--- AltiVec Instruction Translation ---*/ |
| 6190 | /*------------------------------------------------------------*/ |
| 6191 | |
| 6192 | /* |
| 6193 | Altivec Cache Control Instructions (Data Streams) |
| 6194 | */ |
| 6195 | static Bool dis_av_datastream ( UInt theInstr ) |
| 6196 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6197 | /* X-Form */ |
| 6198 | UChar opc1 = ifieldOPC(theInstr); |
| 6199 | UChar flag_T = toUChar( IFIELD( theInstr, 25, 1 ) ); |
| 6200 | UChar flag_A = flag_T; |
| 6201 | UChar b23to24 = toUChar( IFIELD( theInstr, 23, 2 ) ); |
| 6202 | UChar STRM = toUChar( IFIELD( theInstr, 21, 2 ) ); |
| 6203 | UChar rA_addr = ifieldRegA(theInstr); |
| 6204 | UChar rB_addr = ifieldRegB(theInstr); |
| 6205 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6206 | UChar b0 = ifieldBIT0(theInstr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6207 | |
| 6208 | if (opc1 != 0x1F || b23to24 != 0 || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6209 | vex_printf("dis_av_datastream(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6210 | return False; |
| 6211 | } |
| 6212 | |
| 6213 | switch (opc2) { |
| 6214 | case 0x156: // dst (Data Stream Touch, AV p115) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6215 | DIP("dst%s r%u,r%u,%d\n", flag_T ? "t" : "", |
| 6216 | rA_addr, rB_addr, STRM); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6217 | DIP(" => not implemented\n"); |
| 6218 | return False; |
| 6219 | |
| 6220 | case 0x176: // dstst (Data Stream Touch for Store, AV p117) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6221 | DIP("dstst%s r%u,r%u,%d\n", flag_T ? "t" : "", |
| 6222 | rA_addr, rB_addr, STRM); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6223 | DIP(" => not implemented\n"); |
| 6224 | return False; |
| 6225 | |
| 6226 | case 0x336: // dss (Data Stream Stop, AV p114) |
| 6227 | if (rA_addr != 0 || rB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6228 | vex_printf("dis_av_datastream(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6229 | return False; |
| 6230 | } |
| 6231 | if (flag_A == 0) { |
| 6232 | DIP("dss %d\n", STRM); |
| 6233 | DIP(" => not implemented\n"); |
| 6234 | } else { |
| 6235 | DIP("dssall\n"); |
| 6236 | DIP(" => not implemented\n"); |
| 6237 | } |
| 6238 | return False; |
| 6239 | |
| 6240 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6241 | vex_printf("dis_av_datastream(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6242 | return False; |
| 6243 | } |
| 6244 | return True; |
| 6245 | } |
| 6246 | |
| 6247 | /* |
| 6248 | AltiVec Processor Control Instructions |
| 6249 | */ |
| 6250 | static Bool dis_av_procctl ( UInt theInstr ) |
| 6251 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6252 | /* VX-Form */ |
| 6253 | UChar opc1 = ifieldOPC(theInstr); |
| 6254 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6255 | UChar vA_addr = ifieldRegA(theInstr); |
| 6256 | UChar vB_addr = ifieldRegB(theInstr); |
| 6257 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6258 | |
| 6259 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6260 | vex_printf("dis_av_procctl(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6261 | return False; |
| 6262 | } |
| 6263 | |
| 6264 | switch (opc2) { |
| 6265 | case 0x604: // mfvscr (Move from VSCR, AV p129) |
| 6266 | if (vA_addr != 0 || vB_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6267 | vex_printf("dis_av_procctl(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6268 | return False; |
| 6269 | } |
| 6270 | DIP("mfvscr v%d\n", vD_addr); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6271 | putVReg( vD_addr, unop(Iop_32UtoV128, getGST( PPC_GST_VSCR )) ); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6272 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6273 | |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6274 | case 0x644: { // mtvscr (Move to VSCR, AV p130) |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 6275 | IRTemp vB = newTemp(Ity_V128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6276 | if (vD_addr != 0 || vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6277 | vex_printf("dis_av_procctl(ppc)(opc2,dst)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6278 | return False; |
| 6279 | } |
| 6280 | DIP("mtvscr v%d\n", vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6281 | assign( vB, getVReg(vB_addr)); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6282 | putGST( PPC_GST_VSCR, unop(Iop_V128to32, mkexpr(vB)) ); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6283 | break; |
| 6284 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6285 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6286 | vex_printf("dis_av_procctl(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6287 | return False; |
| 6288 | } |
| 6289 | return True; |
| 6290 | } |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6291 | |
| 6292 | /* |
| 6293 | AltiVec Load Instructions |
| 6294 | */ |
| 6295 | static Bool dis_av_load ( UInt theInstr ) |
| 6296 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6297 | /* X-Form */ |
| 6298 | UChar opc1 = ifieldOPC(theInstr); |
| 6299 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6300 | UChar rA_addr = ifieldRegA(theInstr); |
| 6301 | UChar rB_addr = ifieldRegB(theInstr); |
| 6302 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6303 | UChar b0 = ifieldBIT0(theInstr); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6304 | |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6305 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 6306 | IRTemp EA = newTemp(ty); |
| 6307 | IRTemp EA_align16 = newTemp(ty); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6308 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6309 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6310 | vex_printf("dis_av_load(ppc)(instr)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6311 | return False; |
| 6312 | } |
| 6313 | |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6314 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
| 6315 | assign( EA_align16, addr_align( mkexpr(EA), 16 ) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 6316 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6317 | switch (opc2) { |
| 6318 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6319 | case 0x006: { // lvsl (Load Vector for Shift Left, AV p123) |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6320 | IRDirty* d; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6321 | UInt vD_off = vectorGuestRegOffset(vD_addr); |
| 6322 | IRExpr** args = mkIRExprVec_3( |
| 6323 | mkU32(vD_off), |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6324 | binop(Iop_And32, mkSzNarrow32(ty, mkexpr(EA)), |
| 6325 | mkU32(0xF)), |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6326 | mkU32(0)/*left*/ ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6327 | if (!mode64) { |
| 6328 | d = unsafeIRDirty_0_N ( 0/*regparms*/, |
| 6329 | "ppc32g_dirtyhelper_LVS", |
| 6330 | &ppc32g_dirtyhelper_LVS, |
| 6331 | args ); |
| 6332 | } else { |
| 6333 | d = unsafeIRDirty_0_N ( 0/*regparms*/, |
| 6334 | "ppc64g_dirtyhelper_LVS", |
| 6335 | &ppc64g_dirtyhelper_LVS, |
| 6336 | args ); |
| 6337 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6338 | DIP("lvsl v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6339 | /* declare guest state effects */ |
| 6340 | d->needsBBP = True; |
| 6341 | d->nFxState = 1; |
| 6342 | d->fxState[0].fx = Ifx_Write; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6343 | d->fxState[0].offset = vD_off; |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6344 | d->fxState[0].size = sizeof(U128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6345 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6346 | /* execute the dirty call, side-effecting guest state */ |
| 6347 | stmt( IRStmt_Dirty(d) ); |
| 6348 | break; |
| 6349 | } |
| 6350 | case 0x026: { // lvsr (Load Vector for Shift Right, AV p125) |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6351 | IRDirty* d; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6352 | UInt vD_off = vectorGuestRegOffset(vD_addr); |
| 6353 | IRExpr** args = mkIRExprVec_3( |
| 6354 | mkU32(vD_off), |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6355 | binop(Iop_And32, mkSzNarrow32(ty, mkexpr(EA)), |
| 6356 | mkU32(0xF)), |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6357 | mkU32(1)/*right*/ ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6358 | if (!mode64) { |
| 6359 | d = unsafeIRDirty_0_N ( 0/*regparms*/, |
| 6360 | "ppc32g_dirtyhelper_LVS", |
| 6361 | &ppc32g_dirtyhelper_LVS, |
| 6362 | args ); |
| 6363 | } else { |
| 6364 | d = unsafeIRDirty_0_N ( 0/*regparms*/, |
| 6365 | "ppc64g_dirtyhelper_LVS", |
| 6366 | &ppc64g_dirtyhelper_LVS, |
| 6367 | args ); |
| 6368 | } |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6369 | DIP("lvsr v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6370 | /* declare guest state effects */ |
| 6371 | d->needsBBP = True; |
| 6372 | d->nFxState = 1; |
| 6373 | d->fxState[0].fx = Ifx_Write; |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 6374 | d->fxState[0].offset = vD_off; |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6375 | d->fxState[0].size = sizeof(U128); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6376 | |
cerion | 6f6c6a0 | 2005-09-13 18:41:09 +0000 | [diff] [blame] | 6377 | /* execute the dirty call, side-effecting guest state */ |
| 6378 | stmt( IRStmt_Dirty(d) ); |
| 6379 | break; |
| 6380 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6381 | case 0x007: // lvebx (Load Vector Element Byte Indexed, AV p119) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6382 | DIP("lvebx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6383 | /* loads addressed byte into vector[EA[0:3] |
| 6384 | since all other destination bytes are undefined, |
| 6385 | can simply load entire vector from 16-aligned EA */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6386 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6387 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6388 | |
| 6389 | case 0x027: // lvehx (Load Vector Element Half Word Indexed, AV p121) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6390 | DIP("lvehx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6391 | /* see note for lvebx */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6392 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6393 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6394 | |
| 6395 | case 0x047: // lvewx (Load Vector Element Word Indexed, AV p122) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6396 | DIP("lvewx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6397 | /* see note for lvebx */ |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6398 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6399 | break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6400 | |
| 6401 | case 0x067: // lvx (Load Vector Indexed, AV p127) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6402 | DIP("lvx v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | fb197c4 | 2005-12-24 12:32:10 +0000 | [diff] [blame] | 6403 | putVReg( vD_addr, loadBE(Ity_V128, mkexpr(EA_align16)) ); |
cerion | a50fde5 | 2005-07-01 21:16:10 +0000 | [diff] [blame] | 6404 | break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6405 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6406 | case 0x167: // lvxl (Load Vector Indexed LRU, AV p128) |
| 6407 | // XXX: lvxl gives explicit control over cache block replacement |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6408 | DIP("lvxl v%d,r%u,r%u\n", vD_addr, rA_addr, rB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6409 | DIP(" => not implemented\n"); |
| 6410 | return False; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6411 | |
| 6412 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6413 | vex_printf("dis_av_load(ppc)(opc2)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6414 | return False; |
| 6415 | } |
| 6416 | return True; |
| 6417 | } |
| 6418 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6419 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6420 | /* |
| 6421 | AltiVec Store Instructions |
| 6422 | */ |
| 6423 | static Bool dis_av_store ( UInt theInstr ) |
| 6424 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6425 | /* X-Form */ |
| 6426 | UChar opc1 = ifieldOPC(theInstr); |
| 6427 | UChar vS_addr = ifieldRegDS(theInstr); |
| 6428 | UChar rA_addr = ifieldRegA(theInstr); |
| 6429 | UChar rB_addr = ifieldRegB(theInstr); |
| 6430 | UInt opc2 = ifieldOPClo10(theInstr); |
| 6431 | UChar b0 = ifieldBIT0(theInstr); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6432 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6433 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
| 6434 | IRTemp EA = newTemp(ty); |
| 6435 | IRTemp addr_aligned = newTemp(Ity_I32); |
| 6436 | IRTemp vS = newTemp(Ity_V128); |
| 6437 | IRTemp eb = newTemp(Ity_I8); |
| 6438 | IRTemp idx = newTemp(Ity_I8); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6439 | |
| 6440 | if (opc1 != 0x1F || b0 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6441 | vex_printf("dis_av_store(ppc)(instr)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6442 | return False; |
| 6443 | } |
| 6444 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6445 | assign( vS, getVReg(vS_addr)); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6446 | assign( EA, ea_rAor0_idxd(rA_addr, rB_addr) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6447 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6448 | switch (opc2) { |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6449 | case 0x087: { // stvebx (Store Vector Byte Indexed, AV p131) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6450 | DIP("stvebx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6451 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6452 | unop(Iop_32to8, |
| 6453 | mkSzNarrow32(ty, mkexpr(EA)) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6454 | assign( idx, binop(Iop_Shl8, |
| 6455 | binop(Iop_Sub8, mkU8(15), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6456 | mkU8(3)) ); |
| 6457 | storeBE( mkexpr(EA), |
| 6458 | unop(Iop_32to8, unop(Iop_V128to32, |
| 6459 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx)))) ); |
| 6460 | break; |
| 6461 | } |
| 6462 | case 0x0A7: { // stvehx (Store Vector Half Word Indexed, AV p132) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6463 | DIP("stvehx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6464 | assign( addr_aligned, |
| 6465 | mkSzNarrow32(ty, addr_align(mkexpr(EA), 2)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6466 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6467 | unop(Iop_32to8, mkexpr(addr_aligned) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6468 | assign( idx, binop(Iop_Shl8, |
| 6469 | binop(Iop_Sub8, mkU8(14), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6470 | mkU8(3)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6471 | storeBE( mkexpr(addr_aligned), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6472 | unop(Iop_32to16, unop(Iop_V128to32, |
| 6473 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx)))) ); |
| 6474 | break; |
| 6475 | } |
| 6476 | case 0x0C7: { // stvewx (Store Vector Word Indexed, AV p133) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6477 | DIP("stvewx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 6478 | assign( addr_aligned, |
| 6479 | mkSzNarrow32(ty, addr_align(mkexpr(EA), 4)) ); |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6480 | assign( eb, binop(Iop_And8, mkU8(0xF), |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6481 | unop(Iop_32to8, mkexpr(addr_aligned) )) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6482 | assign( idx, binop(Iop_Shl8, |
| 6483 | binop(Iop_Sub8, mkU8(12), mkexpr(eb)), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6484 | mkU8(3)) ); |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6485 | storeBE( mkexpr(addr_aligned), |
cerion | 61c9274 | 2005-09-14 22:59:26 +0000 | [diff] [blame] | 6486 | unop(Iop_V128to32, |
| 6487 | binop(Iop_ShrV128, mkexpr(vS), mkexpr(idx))) ); |
| 6488 | break; |
| 6489 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6490 | |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6491 | case 0x0E7: // stvx (Store Vector Indexed, AV p134) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6492 | DIP("stvx v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
| 6493 | storeBE( addr_align( mkexpr(EA), 16 ), mkexpr(vS) ); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6494 | break; |
| 6495 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6496 | case 0x1E7: // stvxl (Store Vector Indexed LRU, AV p135) |
| 6497 | // XXX: stvxl can give explicit control over cache block replacement |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6498 | DIP("stvxl v%d,r%u,r%u\n", vS_addr, rA_addr, rB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6499 | DIP(" => not implemented\n"); |
| 6500 | return False; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 6501 | // STORE(vS, 16, addr_align( mkexpr(EA), 16 )); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6502 | // break; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6503 | |
| 6504 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6505 | vex_printf("dis_av_store(ppc)(opc2)\n"); |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 6506 | return False; |
| 6507 | } |
| 6508 | return True; |
| 6509 | } |
| 6510 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6511 | /* |
| 6512 | AltiVec Arithmetic Instructions |
| 6513 | */ |
| 6514 | static Bool dis_av_arith ( UInt theInstr ) |
| 6515 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6516 | /* VX-Form */ |
| 6517 | UChar opc1 = ifieldOPC(theInstr); |
| 6518 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6519 | UChar vA_addr = ifieldRegA(theInstr); |
| 6520 | UChar vB_addr = ifieldRegB(theInstr); |
| 6521 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6522 | |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 6523 | IRTemp vA = newTemp(Ity_V128); |
| 6524 | IRTemp vB = newTemp(Ity_V128); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6525 | IRTemp z3 = newTemp(Ity_I64); |
| 6526 | IRTemp z2 = newTemp(Ity_I64); |
| 6527 | IRTemp z1 = newTemp(Ity_I64); |
| 6528 | IRTemp z0 = newTemp(Ity_I64); |
| 6529 | IRTemp aEvn, aOdd; |
| 6530 | IRTemp a15, a14, a13, a12, a11, a10, a9, a8; |
| 6531 | IRTemp a7, a6, a5, a4, a3, a2, a1, a0; |
| 6532 | IRTemp b3, b2, b1, b0; |
| 6533 | |
| 6534 | aEvn = aOdd = IRTemp_INVALID; |
| 6535 | a15 = a14 = a13 = a12 = a11 = a10 = a9 = a8 = IRTemp_INVALID; |
| 6536 | a7 = a6 = a5 = a4 = a3 = a2 = a1 = a0 = IRTemp_INVALID; |
| 6537 | b3 = b2 = b1 = b0 = IRTemp_INVALID; |
| 6538 | |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 6539 | assign( vA, getVReg(vA_addr)); |
| 6540 | assign( vB, getVReg(vB_addr)); |
| 6541 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6542 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6543 | vex_printf("dis_av_arith(ppc)(opc1 != 0x4)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6544 | return False; |
| 6545 | } |
| 6546 | |
| 6547 | switch (opc2) { |
| 6548 | /* Add */ |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 6549 | case 0x180: { // vaddcuw (Add Carryout Unsigned Word, AV p136) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6550 | DIP("vaddcuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6551 | /* unsigned_ov(x+y) = (y >u not(x)) */ |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 6552 | putVReg( vD_addr, binop(Iop_ShrN32x4, |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6553 | binop(Iop_CmpGT32Ux4, mkexpr(vB), |
| 6554 | unop(Iop_NotV128, mkexpr(vA))), |
cerion | d3e5241 | 2005-09-14 21:15:40 +0000 | [diff] [blame] | 6555 | mkU8(31)) ); |
| 6556 | break; |
| 6557 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6558 | case 0x000: // vaddubm (Add Unsigned Byte Modulo, AV p141) |
| 6559 | DIP("vaddubm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6560 | putVReg( vD_addr, binop(Iop_Add8x16, mkexpr(vA), mkexpr(vB)) ); |
| 6561 | break; |
| 6562 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6563 | case 0x040: // vadduhm (Add Unsigned Half Word Modulo, AV p143) |
| 6564 | DIP("vadduhm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6565 | putVReg( vD_addr, binop(Iop_Add16x8, mkexpr(vA), mkexpr(vB)) ); |
| 6566 | break; |
| 6567 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6568 | case 0x080: // vadduwm (Add Unsigned Word Modulo, AV p145) |
| 6569 | DIP("vadduwm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6570 | putVReg( vD_addr, binop(Iop_Add32x4, mkexpr(vA), mkexpr(vB)) ); |
| 6571 | break; |
| 6572 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6573 | case 0x200: // vaddubs (Add Unsigned Byte Saturate, AV p142) |
| 6574 | DIP("vaddubs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6575 | putVReg( vD_addr, binop(Iop_QAdd8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 6576 | // TODO: set VSCR[SAT], perhaps via new primop: Iop_SatOfQAdd8Ux16 |
| 6577 | break; |
| 6578 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6579 | case 0x240: // vadduhs (Add Unsigned Half Word Saturate, AV p144) |
| 6580 | DIP("vadduhs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6581 | putVReg( vD_addr, binop(Iop_QAdd16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 6582 | // TODO: set VSCR[SAT] |
| 6583 | break; |
| 6584 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6585 | case 0x280: // vadduws (Add Unsigned Word Saturate, AV p146) |
| 6586 | DIP("vadduws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6587 | putVReg( vD_addr, binop(Iop_QAdd32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 6588 | // TODO: set VSCR[SAT] |
| 6589 | break; |
| 6590 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6591 | case 0x300: // vaddsbs (Add Signed Byte Saturate, AV p138) |
| 6592 | DIP("vaddsbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6593 | putVReg( vD_addr, binop(Iop_QAdd8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 6594 | // TODO: set VSCR[SAT] |
| 6595 | break; |
| 6596 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6597 | case 0x340: // vaddshs (Add Signed Half Word Saturate, AV p139) |
| 6598 | DIP("vaddshs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6599 | putVReg( vD_addr, binop(Iop_QAdd16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 6600 | // TODO: set VSCR[SAT] |
| 6601 | break; |
| 6602 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6603 | case 0x380: // vaddsws (Add Signed Word Saturate, AV p140) |
| 6604 | DIP("vaddsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6605 | putVReg( vD_addr, binop(Iop_QAdd32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 6606 | // TODO: set VSCR[SAT] |
| 6607 | break; |
| 6608 | |
| 6609 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6610 | /* Subtract */ |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6611 | case 0x580: { // vsubcuw (Subtract Carryout Unsigned Word, AV p260) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6612 | DIP("vsubcuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6613 | /* unsigned_ov(x-y) = (y >u x) */ |
| 6614 | putVReg( vD_addr, binop(Iop_ShrN32x4, |
| 6615 | unop(Iop_NotV128, |
| 6616 | binop(Iop_CmpGT32Ux4, mkexpr(vB), |
| 6617 | mkexpr(vA))), |
| 6618 | mkU8(31)) ); |
| 6619 | break; |
| 6620 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6621 | case 0x400: // vsububm (Subtract Unsigned Byte Modulo, AV p265) |
| 6622 | DIP("vsububm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6623 | putVReg( vD_addr, binop(Iop_Sub8x16, mkexpr(vA), mkexpr(vB)) ); |
| 6624 | break; |
| 6625 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6626 | case 0x440: // vsubuhm (Subtract Unsigned Half Word Modulo, AV p267) |
| 6627 | DIP("vsubuhm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6628 | putVReg( vD_addr, binop(Iop_Sub16x8, mkexpr(vA), mkexpr(vB)) ); |
| 6629 | break; |
| 6630 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6631 | case 0x480: // vsubuwm (Subtract Unsigned Word Modulo, AV p269) |
| 6632 | DIP("vsubuwm v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6633 | putVReg( vD_addr, binop(Iop_Sub32x4, mkexpr(vA), mkexpr(vB)) ); |
| 6634 | break; |
| 6635 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6636 | case 0x600: // vsububs (Subtract Unsigned Byte Saturate, AV p266) |
| 6637 | DIP("vsububs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6638 | putVReg( vD_addr, binop(Iop_QSub8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 6639 | // TODO: set VSCR[SAT] |
| 6640 | break; |
| 6641 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6642 | case 0x640: // vsubuhs (Subtract Unsigned HWord Saturate, AV p268) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6643 | DIP("vsubuhs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6644 | putVReg( vD_addr, binop(Iop_QSub16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 6645 | // TODO: set VSCR[SAT] |
| 6646 | break; |
| 6647 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6648 | case 0x680: // vsubuws (Subtract Unsigned Word Saturate, AV p270) |
| 6649 | DIP("vsubuws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6650 | putVReg( vD_addr, binop(Iop_QSub32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 6651 | // TODO: set VSCR[SAT] |
| 6652 | break; |
| 6653 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6654 | case 0x700: // vsubsbs (Subtract Signed Byte Saturate, AV p262) |
| 6655 | DIP("vsubsbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6656 | putVReg( vD_addr, binop(Iop_QSub8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 6657 | // TODO: set VSCR[SAT] |
| 6658 | break; |
| 6659 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6660 | case 0x740: // vsubshs (Subtract Signed Half Word Saturate, AV p263) |
| 6661 | DIP("vsubshs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6662 | putVReg( vD_addr, binop(Iop_QSub16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 6663 | // TODO: set VSCR[SAT] |
| 6664 | break; |
| 6665 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6666 | case 0x780: // vsubsws (Subtract Signed Word Saturate, AV p264) |
| 6667 | DIP("vsubsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6668 | putVReg( vD_addr, binop(Iop_QSub32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 6669 | // TODO: set VSCR[SAT] |
| 6670 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6671 | |
| 6672 | |
| 6673 | /* Maximum */ |
| 6674 | case 0x002: // vmaxub (Maximum Unsigned Byte, AV p182) |
| 6675 | DIP("vmaxub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6676 | putVReg( vD_addr, binop(Iop_Max8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 6677 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6678 | |
| 6679 | case 0x042: // vmaxuh (Maximum Unsigned Half Word, AV p183) |
| 6680 | DIP("vmaxuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6681 | putVReg( vD_addr, binop(Iop_Max16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 6682 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6683 | |
| 6684 | case 0x082: // vmaxuw (Maximum Unsigned Word, AV p184) |
| 6685 | DIP("vmaxuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6686 | putVReg( vD_addr, binop(Iop_Max32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 6687 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6688 | |
| 6689 | case 0x102: // vmaxsb (Maximum Signed Byte, AV p179) |
| 6690 | DIP("vmaxsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6691 | putVReg( vD_addr, binop(Iop_Max8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 6692 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6693 | |
| 6694 | case 0x142: // vmaxsh (Maximum Signed Half Word, AV p180) |
| 6695 | DIP("vmaxsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6696 | putVReg( vD_addr, binop(Iop_Max16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 6697 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6698 | |
| 6699 | case 0x182: // vmaxsw (Maximum Signed Word, AV p181) |
| 6700 | DIP("vmaxsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6701 | putVReg( vD_addr, binop(Iop_Max32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 6702 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6703 | |
| 6704 | |
| 6705 | /* Minimum */ |
| 6706 | case 0x202: // vminub (Minimum Unsigned Byte, AV p191) |
| 6707 | DIP("vminub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6708 | putVReg( vD_addr, binop(Iop_Min8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 6709 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6710 | |
| 6711 | case 0x242: // vminuh (Minimum Unsigned Half Word, AV p192) |
| 6712 | DIP("vminuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6713 | putVReg( vD_addr, binop(Iop_Min16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 6714 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6715 | |
| 6716 | case 0x282: // vminuw (Minimum Unsigned Word, AV p193) |
| 6717 | DIP("vminuw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6718 | putVReg( vD_addr, binop(Iop_Min32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 6719 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6720 | |
| 6721 | case 0x302: // vminsb (Minimum Signed Byte, AV p188) |
| 6722 | DIP("vminsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6723 | putVReg( vD_addr, binop(Iop_Min8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 6724 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6725 | |
| 6726 | case 0x342: // vminsh (Minimum Signed Half Word, AV p189) |
| 6727 | DIP("vminsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6728 | putVReg( vD_addr, binop(Iop_Min16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 6729 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6730 | |
| 6731 | case 0x382: // vminsw (Minimum Signed Word, AV p190) |
| 6732 | DIP("vminsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6733 | putVReg( vD_addr, binop(Iop_Min32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 6734 | break; |
| 6735 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6736 | |
| 6737 | /* Average */ |
| 6738 | case 0x402: // vavgub (Average Unsigned Byte, AV p152) |
| 6739 | DIP("vavgub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6740 | putVReg( vD_addr, binop(Iop_Avg8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 6741 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6742 | |
| 6743 | case 0x442: // vavguh (Average Unsigned Half Word, AV p153) |
| 6744 | DIP("vavguh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6745 | putVReg( vD_addr, binop(Iop_Avg16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 6746 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6747 | |
| 6748 | case 0x482: // vavguw (Average Unsigned Word, AV p154) |
| 6749 | DIP("vavguw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6750 | putVReg( vD_addr, binop(Iop_Avg32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 6751 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6752 | |
| 6753 | case 0x502: // vavgsb (Average Signed Byte, AV p149) |
| 6754 | DIP("vavgsb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6755 | putVReg( vD_addr, binop(Iop_Avg8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 6756 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6757 | |
| 6758 | case 0x542: // vavgsh (Average Signed Half Word, AV p150) |
| 6759 | DIP("vavgsh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6760 | putVReg( vD_addr, binop(Iop_Avg16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 6761 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6762 | |
| 6763 | case 0x582: // vavgsw (Average Signed Word, AV p151) |
| 6764 | DIP("vavgsw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6765 | putVReg( vD_addr, binop(Iop_Avg32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 6766 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6767 | |
| 6768 | |
| 6769 | /* Multiply */ |
| 6770 | case 0x008: // vmuloub (Multiply Odd Unsigned Byte, AV p213) |
| 6771 | DIP("vmuloub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6772 | putVReg( vD_addr, |
| 6773 | binop(Iop_MullEven8Ux16, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6774 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6775 | |
| 6776 | case 0x048: // vmulouh (Multiply Odd Unsigned Half Word, AV p214) |
| 6777 | DIP("vmulouh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6778 | putVReg( vD_addr, |
| 6779 | binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6780 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6781 | |
| 6782 | case 0x108: // vmulosb (Multiply Odd Signed Byte, AV p211) |
| 6783 | DIP("vmulosb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6784 | putVReg( vD_addr, |
| 6785 | binop(Iop_MullEven8Sx16, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6786 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6787 | |
| 6788 | case 0x148: // vmulosh (Multiply Odd Signed Half Word, AV p212) |
| 6789 | DIP("vmulosh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6790 | putVReg( vD_addr, |
| 6791 | binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB))); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6792 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6793 | |
| 6794 | case 0x208: // vmuleub (Multiply Even Unsigned Byte, AV p209) |
| 6795 | DIP("vmuleub v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 6796 | putVReg( vD_addr, MK_Iop_MullOdd8Ux16( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6797 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6798 | |
| 6799 | case 0x248: // vmuleuh (Multiply Even Unsigned Half Word, AV p210) |
| 6800 | DIP("vmuleuh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 6801 | putVReg( vD_addr, MK_Iop_MullOdd16Ux8( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6802 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6803 | |
| 6804 | case 0x308: // vmulesb (Multiply Even Signed Byte, AV p207) |
| 6805 | DIP("vmulesb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 6806 | putVReg( vD_addr, MK_Iop_MullOdd8Sx16( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6807 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6808 | |
| 6809 | case 0x348: // vmulesh (Multiply Even Signed Half Word, AV p208) |
| 6810 | DIP("vmulesh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 6811 | putVReg( vD_addr, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
cerion | 36991ef | 2005-09-15 12:42:16 +0000 | [diff] [blame] | 6812 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6813 | |
| 6814 | |
| 6815 | /* Sum Across Partial */ |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6816 | case 0x608: { // vsum4ubs (Sum Partial (1/4) UB Saturate, AV p275) |
| 6817 | IRTemp aEE, aEO, aOE, aOO; |
| 6818 | aEE = aEO = aOE = aOO = IRTemp_INVALID; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6819 | DIP("vsum4ubs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6820 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6821 | /* vA: V128_8Ux16 -> 4 x V128_32Ux4, sign-extended */ |
| 6822 | expand8Ux16( mkexpr(vA), &aEvn, &aOdd ); // (15,13...),(14,12...) |
| 6823 | expand16Ux8( mkexpr(aEvn), &aEE, &aEO ); // (15,11...),(13, 9...) |
| 6824 | expand16Ux8( mkexpr(aOdd), &aOE, &aOO ); // (14,10...),(12, 8...) |
| 6825 | |
| 6826 | /* break V128 to 4xI32's, zero-extending to I64's */ |
| 6827 | breakV128to4x64U( mkexpr(aEE), &a15, &a11, &a7, &a3 ); |
| 6828 | breakV128to4x64U( mkexpr(aOE), &a14, &a10, &a6, &a2 ); |
| 6829 | breakV128to4x64U( mkexpr(aEO), &a13, &a9, &a5, &a1 ); |
| 6830 | breakV128to4x64U( mkexpr(aOO), &a12, &a8, &a4, &a0 ); |
| 6831 | breakV128to4x64U( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 6832 | |
| 6833 | /* add lanes */ |
| 6834 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6835 | binop(Iop_Add64, |
| 6836 | binop(Iop_Add64, mkexpr(a15), mkexpr(a14)), |
| 6837 | binop(Iop_Add64, mkexpr(a13), mkexpr(a12)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6838 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6839 | binop(Iop_Add64, |
| 6840 | binop(Iop_Add64, mkexpr(a11), mkexpr(a10)), |
| 6841 | binop(Iop_Add64, mkexpr(a9), mkexpr(a8)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6842 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6843 | binop(Iop_Add64, |
| 6844 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)), |
| 6845 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6846 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6847 | binop(Iop_Add64, |
| 6848 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 6849 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6850 | |
| 6851 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 6852 | putVReg( vD_addr, mkV128from4x64U( mkexpr(z3), mkexpr(z2), |
| 6853 | mkexpr(z1), mkexpr(z0)) ); |
| 6854 | break; |
| 6855 | } |
| 6856 | case 0x708: { // vsum4sbs (Sum Partial (1/4) SB Saturate, AV p273) |
| 6857 | IRTemp aEE, aEO, aOE, aOO; |
| 6858 | aEE = aEO = aOE = aOO = IRTemp_INVALID; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6859 | DIP("vsum4sbs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6860 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6861 | /* vA: V128_8Sx16 -> 4 x V128_32Sx4, sign-extended */ |
| 6862 | expand8Sx16( mkexpr(vA), &aEvn, &aOdd ); // (15,13...),(14,12...) |
| 6863 | expand16Sx8( mkexpr(aEvn), &aEE, &aEO ); // (15,11...),(13, 9...) |
| 6864 | expand16Sx8( mkexpr(aOdd), &aOE, &aOO ); // (14,10...),(12, 8...) |
| 6865 | |
| 6866 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 6867 | breakV128to4x64S( mkexpr(aEE), &a15, &a11, &a7, &a3 ); |
| 6868 | breakV128to4x64S( mkexpr(aOE), &a14, &a10, &a6, &a2 ); |
| 6869 | breakV128to4x64S( mkexpr(aEO), &a13, &a9, &a5, &a1 ); |
| 6870 | breakV128to4x64S( mkexpr(aOO), &a12, &a8, &a4, &a0 ); |
| 6871 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 6872 | |
| 6873 | /* add lanes */ |
| 6874 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6875 | binop(Iop_Add64, |
| 6876 | binop(Iop_Add64, mkexpr(a15), mkexpr(a14)), |
| 6877 | binop(Iop_Add64, mkexpr(a13), mkexpr(a12)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6878 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6879 | binop(Iop_Add64, |
| 6880 | binop(Iop_Add64, mkexpr(a11), mkexpr(a10)), |
| 6881 | binop(Iop_Add64, mkexpr(a9), mkexpr(a8)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6882 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6883 | binop(Iop_Add64, |
| 6884 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)), |
| 6885 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6886 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6887 | binop(Iop_Add64, |
| 6888 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 6889 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6890 | |
| 6891 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 6892 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 6893 | mkexpr(z1), mkexpr(z0)) ); |
| 6894 | break; |
| 6895 | } |
| 6896 | case 0x648: { // vsum4shs (Sum Partial (1/4) SHW Saturate, AV p274) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6897 | DIP("vsum4shs v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6898 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6899 | /* vA: V128_16Sx8 -> 2 x V128_32Sx4, sign-extended */ |
| 6900 | expand16Sx8( mkexpr(vA), &aEvn, &aOdd ); // (7,5...),(6,4...) |
| 6901 | |
| 6902 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 6903 | breakV128to4x64S( mkexpr(aEvn), &a7, &a5, &a3, &a1 ); |
| 6904 | breakV128to4x64S( mkexpr(aOdd), &a6, &a4, &a2, &a0 ); |
| 6905 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 6906 | |
| 6907 | /* add lanes */ |
| 6908 | assign( z3, binop(Iop_Add64, mkexpr(b3), |
| 6909 | binop(Iop_Add64, mkexpr(a7), mkexpr(a6)))); |
| 6910 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
| 6911 | binop(Iop_Add64, mkexpr(a5), mkexpr(a4)))); |
| 6912 | assign( z1, binop(Iop_Add64, mkexpr(b1), |
| 6913 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)))); |
| 6914 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
| 6915 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))); |
| 6916 | |
| 6917 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 6918 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 6919 | mkexpr(z1), mkexpr(z0)) ); |
| 6920 | break; |
| 6921 | } |
| 6922 | case 0x688: { // vsum2sws (Sum Partial (1/2) SW Saturate, AV p272) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6923 | DIP("vsum2sws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6924 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6925 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 6926 | breakV128to4x64S( mkexpr(vA), &a3, &a2, &a1, &a0 ); |
| 6927 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 6928 | |
| 6929 | /* add lanes */ |
| 6930 | assign( z2, binop(Iop_Add64, mkexpr(b2), |
| 6931 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2))) ); |
| 6932 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
| 6933 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0))) ); |
| 6934 | |
| 6935 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 6936 | putVReg( vD_addr, mkV128from4x64S( mkU64(0), mkexpr(z2), |
| 6937 | mkU64(0), mkexpr(z0)) ); |
| 6938 | break; |
| 6939 | } |
| 6940 | case 0x788: { // vsumsws (Sum SW Saturate, AV p271) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6941 | DIP("vsumsws v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6942 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6943 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 6944 | breakV128to4x64S( mkexpr(vA), &a3, &a2, &a1, &a0 ); |
| 6945 | breakV128to4x64S( mkexpr(vB), &b3, &b2, &b1, &b0 ); |
| 6946 | |
| 6947 | /* add lanes */ |
| 6948 | assign( z0, binop(Iop_Add64, mkexpr(b0), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6949 | binop(Iop_Add64, |
| 6950 | binop(Iop_Add64, mkexpr(a3), mkexpr(a2)), |
| 6951 | binop(Iop_Add64, mkexpr(a1), mkexpr(a0)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 6952 | |
| 6953 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 6954 | putVReg( vD_addr, mkV128from4x64S( mkU64(0), mkU64(0), |
| 6955 | mkU64(0), mkexpr(z0)) ); |
| 6956 | break; |
| 6957 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6958 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6959 | vex_printf("dis_av_arith(ppc)(opc2=0x%x)\n", opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6960 | return False; |
| 6961 | } |
| 6962 | return True; |
| 6963 | } |
| 6964 | |
| 6965 | /* |
| 6966 | AltiVec Logic Instructions |
| 6967 | */ |
| 6968 | static Bool dis_av_logic ( UInt theInstr ) |
| 6969 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6970 | /* VX-Form */ |
| 6971 | UChar opc1 = ifieldOPC(theInstr); |
| 6972 | UChar vD_addr = ifieldRegDS(theInstr); |
| 6973 | UChar vA_addr = ifieldRegA(theInstr); |
| 6974 | UChar vB_addr = ifieldRegB(theInstr); |
| 6975 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6976 | |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6977 | IRTemp vA = newTemp(Ity_V128); |
| 6978 | IRTemp vB = newTemp(Ity_V128); |
| 6979 | assign( vA, getVReg(vA_addr)); |
| 6980 | assign( vB, getVReg(vB_addr)); |
| 6981 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6982 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 6983 | vex_printf("dis_av_logic(ppc)(opc1 != 0x4)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6984 | return False; |
| 6985 | } |
| 6986 | |
| 6987 | switch (opc2) { |
| 6988 | case 0x404: // vand (And, AV p147) |
| 6989 | DIP("vand v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 6990 | putVReg( vD_addr, binop(Iop_AndV128, mkexpr(vA), mkexpr(vB)) ); |
| 6991 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6992 | |
| 6993 | case 0x444: // vandc (And, AV p148) |
| 6994 | DIP("vandc v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 6995 | putVReg( vD_addr, binop(Iop_AndV128, mkexpr(vA), |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 6996 | unop(Iop_NotV128, mkexpr(vB))) ); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 6997 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 6998 | |
| 6999 | case 0x484: // vor (Or, AV p217) |
| 7000 | DIP("vor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7001 | putVReg( vD_addr, binop(Iop_OrV128, mkexpr(vA), mkexpr(vB)) ); |
| 7002 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7003 | |
| 7004 | case 0x4C4: // vxor (Xor, AV p282) |
| 7005 | DIP("vxor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 7006 | putVReg( vD_addr, binop(Iop_XorV128, mkexpr(vA), mkexpr(vB)) ); |
| 7007 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7008 | |
| 7009 | case 0x504: // vnor (Nor, AV p216) |
| 7010 | DIP("vnor v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7011 | putVReg( vD_addr, |
| 7012 | unop(Iop_NotV128, binop(Iop_OrV128, mkexpr(vA), mkexpr(vB))) ); |
| 7013 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7014 | |
| 7015 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7016 | vex_printf("dis_av_logic(ppc)(opc2=0x%x)\n", opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7017 | return False; |
| 7018 | } |
| 7019 | return True; |
| 7020 | } |
| 7021 | |
| 7022 | /* |
| 7023 | AltiVec Compare Instructions |
| 7024 | */ |
| 7025 | static Bool dis_av_cmp ( UInt theInstr ) |
| 7026 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7027 | /* VXR-Form */ |
| 7028 | UChar opc1 = ifieldOPC(theInstr); |
| 7029 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7030 | UChar vA_addr = ifieldRegA(theInstr); |
| 7031 | UChar vB_addr = ifieldRegB(theInstr); |
| 7032 | UChar flag_rC = ifieldBIT10(theInstr); |
| 7033 | UInt opc2 = IFIELD( theInstr, 0, 10 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7034 | |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7035 | IRTemp vA = newTemp(Ity_V128); |
| 7036 | IRTemp vB = newTemp(Ity_V128); |
| 7037 | IRTemp vD = newTemp(Ity_V128); |
| 7038 | assign( vA, getVReg(vA_addr)); |
| 7039 | assign( vB, getVReg(vB_addr)); |
| 7040 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7041 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7042 | vex_printf("dis_av_cmp(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7043 | return False; |
| 7044 | } |
| 7045 | |
| 7046 | switch (opc2) { |
| 7047 | case 0x006: // vcmpequb (Compare Equal-to Unsigned B, AV p160) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7048 | DIP("vcmpequb%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7049 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7050 | assign( vD, binop(Iop_CmpEQ8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7051 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7052 | |
| 7053 | case 0x046: // vcmpequh (Compare Equal-to Unsigned HW, AV p161) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7054 | DIP("vcmpequh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7055 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7056 | assign( vD, binop(Iop_CmpEQ16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7057 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7058 | |
| 7059 | case 0x086: // vcmpequw (Compare Equal-to Unsigned W, AV p162) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7060 | DIP("vcmpequw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7061 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7062 | assign( vD, binop(Iop_CmpEQ32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7063 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7064 | |
| 7065 | case 0x206: // vcmpgtub (Compare Greater-than Unsigned B, AV p168) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7066 | DIP("vcmpgtub%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7067 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7068 | assign( vD, binop(Iop_CmpGT8Ux16, mkexpr(vA), mkexpr(vB)) ); |
| 7069 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7070 | |
| 7071 | case 0x246: // vcmpgtuh (Compare Greater-than Unsigned HW, AV p169) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7072 | DIP("vcmpgtuh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7073 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7074 | assign( vD, binop(Iop_CmpGT16Ux8, mkexpr(vA), mkexpr(vB)) ); |
| 7075 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7076 | |
| 7077 | case 0x286: // vcmpgtuw (Compare Greater-than Unsigned W, AV p170) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7078 | DIP("vcmpgtuw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7079 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7080 | assign( vD, binop(Iop_CmpGT32Ux4, mkexpr(vA), mkexpr(vB)) ); |
| 7081 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7082 | |
| 7083 | case 0x306: // vcmpgtsb (Compare Greater-than Signed B, AV p165) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7084 | DIP("vcmpgtsb%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7085 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7086 | assign( vD, binop(Iop_CmpGT8Sx16, mkexpr(vA), mkexpr(vB)) ); |
| 7087 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7088 | |
| 7089 | case 0x346: // vcmpgtsh (Compare Greater-than Signed HW, AV p166) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7090 | DIP("vcmpgtsh%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7091 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7092 | assign( vD, binop(Iop_CmpGT16Sx8, mkexpr(vA), mkexpr(vB)) ); |
| 7093 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7094 | |
| 7095 | case 0x386: // vcmpgtsw (Compare Greater-than Signed W, AV p167) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7096 | DIP("vcmpgtsw%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 7097 | vD_addr, vA_addr, vB_addr); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7098 | assign( vD, binop(Iop_CmpGT32Sx4, mkexpr(vA), mkexpr(vB)) ); |
| 7099 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7100 | |
| 7101 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7102 | vex_printf("dis_av_cmp(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7103 | return False; |
| 7104 | } |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7105 | |
| 7106 | putVReg( vD_addr, mkexpr(vD) ); |
| 7107 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7108 | if (flag_rC) { |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 7109 | set_AV_CR6( mkexpr(vD), True ); |
cerion | 0c43922 | 2005-09-15 14:22:58 +0000 | [diff] [blame] | 7110 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7111 | return True; |
| 7112 | } |
| 7113 | |
| 7114 | /* |
| 7115 | AltiVec Multiply-Sum Instructions |
| 7116 | */ |
| 7117 | static Bool dis_av_multarith ( UInt theInstr ) |
| 7118 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7119 | /* VA-Form */ |
| 7120 | UChar opc1 = ifieldOPC(theInstr); |
| 7121 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7122 | UChar vA_addr = ifieldRegA(theInstr); |
| 7123 | UChar vB_addr = ifieldRegB(theInstr); |
| 7124 | UChar vC_addr = ifieldRegC(theInstr); |
| 7125 | UChar opc2 = toUChar( IFIELD( theInstr, 0, 6 ) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7126 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7127 | IRTemp vA = newTemp(Ity_V128); |
| 7128 | IRTemp vB = newTemp(Ity_V128); |
| 7129 | IRTemp vC = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7130 | IRTemp zeros = newTemp(Ity_V128); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7131 | IRTemp aLo = newTemp(Ity_V128); |
| 7132 | IRTemp bLo = newTemp(Ity_V128); |
| 7133 | IRTemp cLo = newTemp(Ity_V128); |
| 7134 | IRTemp zLo = newTemp(Ity_V128); |
| 7135 | IRTemp aHi = newTemp(Ity_V128); |
| 7136 | IRTemp bHi = newTemp(Ity_V128); |
| 7137 | IRTemp cHi = newTemp(Ity_V128); |
| 7138 | IRTemp zHi = newTemp(Ity_V128); |
| 7139 | IRTemp abEvn = newTemp(Ity_V128); |
| 7140 | IRTemp abOdd = newTemp(Ity_V128); |
| 7141 | IRTemp z3 = newTemp(Ity_I64); |
| 7142 | IRTemp z2 = newTemp(Ity_I64); |
| 7143 | IRTemp z1 = newTemp(Ity_I64); |
| 7144 | IRTemp z0 = newTemp(Ity_I64); |
| 7145 | IRTemp ab7, ab6, ab5, ab4, ab3, ab2, ab1, ab0; |
| 7146 | IRTemp c3, c2, c1, c0; |
| 7147 | |
| 7148 | ab7 = ab6 = ab5 = ab4 = ab3 = ab2 = ab1 = ab0 = IRTemp_INVALID; |
| 7149 | c3 = c2 = c1 = c0 = IRTemp_INVALID; |
| 7150 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7151 | assign( vA, getVReg(vA_addr)); |
| 7152 | assign( vB, getVReg(vB_addr)); |
| 7153 | assign( vC, getVReg(vC_addr)); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7154 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7155 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7156 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7157 | vex_printf("dis_av_multarith(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7158 | return False; |
| 7159 | } |
| 7160 | |
| 7161 | switch (opc2) { |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7162 | /* Multiply-Add */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7163 | case 0x20: { // vmhaddshs (Mult Hi, Add Signed HW Saturate, AV p185) |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7164 | IRTemp cSigns = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7165 | DIP("vmhaddshs v%d,v%d,v%d,v%d\n", |
| 7166 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7167 | assign(cSigns, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vC))); |
| 7168 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7169 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7170 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(cSigns),mkexpr(vC))); |
| 7171 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7172 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7173 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(cSigns),mkexpr(vC))); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7174 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7175 | assign( zLo, binop(Iop_Add32x4, mkexpr(cLo), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7176 | binop(Iop_SarN32x4, |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7177 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7178 | mkexpr(aLo), mkexpr(bLo)), |
| 7179 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7180 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7181 | assign( zHi, binop(Iop_Add32x4, mkexpr(cHi), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7182 | binop(Iop_SarN32x4, |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7183 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7184 | mkexpr(aHi), mkexpr(bHi)), |
| 7185 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7186 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7187 | putVReg( vD_addr, |
| 7188 | binop(Iop_QNarrow32Sx4, mkexpr(zHi), mkexpr(zLo)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7189 | break; |
| 7190 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7191 | case 0x21: { // vmhraddshs (Mult High Round, Add Signed HW Saturate, AV p186) |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7192 | IRTemp zKonst = newTemp(Ity_V128); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7193 | IRTemp cSigns = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7194 | DIP("vmhraddshs v%d,v%d,v%d,v%d\n", |
| 7195 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7196 | assign(cSigns, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vC)) ); |
| 7197 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7198 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7199 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(cSigns),mkexpr(vC))); |
| 7200 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7201 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7202 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(cSigns),mkexpr(vC))); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7203 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7204 | /* shifting our const avoids store/load version of Dup */ |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7205 | assign( zKonst, binop(Iop_ShlN32x4, unop(Iop_Dup32x4, mkU32(0x1)), |
| 7206 | mkU8(14)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7207 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7208 | assign( zLo, binop(Iop_Add32x4, mkexpr(cLo), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7209 | binop(Iop_SarN32x4, |
| 7210 | binop(Iop_Add32x4, mkexpr(zKonst), |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7211 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7212 | mkexpr(aLo), mkexpr(bLo))), |
| 7213 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7214 | |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7215 | assign( zHi, binop(Iop_Add32x4, mkexpr(cHi), |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7216 | binop(Iop_SarN32x4, |
| 7217 | binop(Iop_Add32x4, mkexpr(zKonst), |
cerion | 1ac656a | 2005-11-04 19:44:48 +0000 | [diff] [blame] | 7218 | binop(Iop_MullEven16Sx8, |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7219 | mkexpr(aHi), mkexpr(bHi))), |
| 7220 | mkU8(15))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7221 | |
| 7222 | putVReg( vD_addr, binop(Iop_QNarrow32Sx4, mkexpr(zHi), mkexpr(zLo)) ); |
| 7223 | break; |
| 7224 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7225 | case 0x22: { // vmladduhm (Mult Low, Add Unsigned HW Modulo, AV p194) |
| 7226 | DIP("vmladduhm v%d,v%d,v%d,v%d\n", |
| 7227 | vD_addr, vA_addr, vB_addr, vC_addr); |
| 7228 | assign(aLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vA))); |
| 7229 | assign(bLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vB))); |
| 7230 | assign(cLo, binop(Iop_InterleaveLO16x8, mkexpr(zeros), mkexpr(vC))); |
| 7231 | assign(aHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vA))); |
| 7232 | assign(bHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vB))); |
| 7233 | assign(cHi, binop(Iop_InterleaveHI16x8, mkexpr(zeros), mkexpr(vC))); |
| 7234 | assign(zLo, binop(Iop_Add32x4, |
| 7235 | binop(Iop_MullEven16Ux8, mkexpr(aLo), mkexpr(bLo)), |
| 7236 | mkexpr(cLo)) ); |
| 7237 | assign(zHi, binop(Iop_Add32x4, |
| 7238 | binop(Iop_MullEven16Ux8, mkexpr(aHi), mkexpr(bHi)), |
| 7239 | mkexpr(cHi))); |
| 7240 | putVReg(vD_addr, binop(Iop_Narrow32x4, mkexpr(zHi), mkexpr(zLo))); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7241 | break; |
| 7242 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7243 | |
| 7244 | |
| 7245 | /* Multiply-Sum */ |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7246 | case 0x24: { // vmsumubm (Multiply Sum Unsigned B Modulo, AV p204) |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7247 | IRTemp abEE, abEO, abOE, abOO; |
| 7248 | abEE = abEO = abOE = abOO = IRTemp_INVALID; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7249 | DIP("vmsumubm v%d,v%d,v%d,v%d\n", |
| 7250 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7251 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7252 | /* multiply vA,vB (unsigned, widening) */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7253 | assign( abEvn, MK_Iop_MullOdd8Ux16( mkexpr(vA), mkexpr(vB) )); |
| 7254 | assign( abOdd, binop(Iop_MullEven8Ux16, mkexpr(vA), mkexpr(vB)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7255 | |
| 7256 | /* evn,odd: V128_16Ux8 -> 2 x V128_32Ux4, zero-extended */ |
| 7257 | expand16Ux8( mkexpr(abEvn), &abEE, &abEO ); |
| 7258 | expand16Ux8( mkexpr(abOdd), &abOE, &abOO ); |
| 7259 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7260 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7261 | binop(Iop_Add32x4, mkexpr(vC), |
| 7262 | binop(Iop_Add32x4, |
| 7263 | binop(Iop_Add32x4, mkexpr(abEE), mkexpr(abEO)), |
| 7264 | binop(Iop_Add32x4, mkexpr(abOE), mkexpr(abOO)))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7265 | break; |
| 7266 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7267 | case 0x25: { // vmsummbm (Multiply Sum Mixed-Sign B Modulo, AV p201) |
| 7268 | IRTemp aEvn, aOdd, bEvn, bOdd; |
| 7269 | IRTemp abEE = newTemp(Ity_V128); |
| 7270 | IRTemp abEO = newTemp(Ity_V128); |
| 7271 | IRTemp abOE = newTemp(Ity_V128); |
| 7272 | IRTemp abOO = newTemp(Ity_V128); |
| 7273 | aEvn = aOdd = bEvn = bOdd = IRTemp_INVALID; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7274 | DIP("vmsummbm v%d,v%d,v%d,v%d\n", |
| 7275 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7276 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7277 | /* sign-extend vA, zero-extend vB, for mixed-sign multiply |
| 7278 | (separating out adjacent lanes to different vectors) */ |
| 7279 | expand8Sx16( mkexpr(vA), &aEvn, &aOdd ); |
| 7280 | expand8Ux16( mkexpr(vB), &bEvn, &bOdd ); |
| 7281 | |
| 7282 | /* multiply vA, vB, again separating adjacent lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7283 | assign( abEE, MK_Iop_MullOdd16Sx8( mkexpr(aEvn), mkexpr(bEvn) )); |
| 7284 | assign( abEO, binop(Iop_MullEven16Sx8, mkexpr(aEvn), mkexpr(bEvn)) ); |
| 7285 | assign( abOE, MK_Iop_MullOdd16Sx8( mkexpr(aOdd), mkexpr(bOdd) )); |
| 7286 | assign( abOO, binop(Iop_MullEven16Sx8, mkexpr(aOdd), mkexpr(bOdd)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7287 | |
| 7288 | /* add results together, + vC */ |
| 7289 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7290 | binop(Iop_QAdd32Sx4, mkexpr(vC), |
| 7291 | binop(Iop_QAdd32Sx4, |
| 7292 | binop(Iop_QAdd32Sx4, mkexpr(abEE), mkexpr(abEO)), |
| 7293 | binop(Iop_QAdd32Sx4, mkexpr(abOE), mkexpr(abOO)))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7294 | break; |
| 7295 | } |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7296 | case 0x26: { // vmsumuhm (Multiply Sum Unsigned HW Modulo, AV p205) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7297 | DIP("vmsumuhm v%d,v%d,v%d,v%d\n", |
| 7298 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7299 | assign( abEvn, MK_Iop_MullOdd16Ux8( mkexpr(vA), mkexpr(vB) )); |
| 7300 | assign( abOdd, binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7301 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7302 | binop(Iop_Add32x4, mkexpr(vC), |
| 7303 | binop(Iop_Add32x4, mkexpr(abEvn), mkexpr(abOdd))) ); |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7304 | break; |
| 7305 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7306 | case 0x27: { // vmsumuhs (Multiply Sum Unsigned HW Saturate, AV p206) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7307 | DIP("vmsumuhs v%d,v%d,v%d,v%d\n", |
| 7308 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7309 | /* widening multiply, separating lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7310 | assign( abEvn, MK_Iop_MullOdd16Ux8(mkexpr(vA), mkexpr(vB) )); |
| 7311 | assign( abOdd, binop(Iop_MullEven16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7312 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7313 | /* break V128 to 4xI32's, zero-extending to I64's */ |
| 7314 | breakV128to4x64U( mkexpr(abEvn), &ab7, &ab5, &ab3, &ab1 ); |
| 7315 | breakV128to4x64U( mkexpr(abOdd), &ab6, &ab4, &ab2, &ab0 ); |
| 7316 | breakV128to4x64U( mkexpr(vC), &c3, &c2, &c1, &c0 ); |
| 7317 | |
| 7318 | /* add lanes */ |
| 7319 | assign( z3, binop(Iop_Add64, mkexpr(c3), |
| 7320 | binop(Iop_Add64, mkexpr(ab7), mkexpr(ab6)))); |
| 7321 | assign( z2, binop(Iop_Add64, mkexpr(c2), |
| 7322 | binop(Iop_Add64, mkexpr(ab5), mkexpr(ab4)))); |
| 7323 | assign( z1, binop(Iop_Add64, mkexpr(c1), |
| 7324 | binop(Iop_Add64, mkexpr(ab3), mkexpr(ab2)))); |
| 7325 | assign( z0, binop(Iop_Add64, mkexpr(c0), |
| 7326 | binop(Iop_Add64, mkexpr(ab1), mkexpr(ab0)))); |
| 7327 | |
| 7328 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7329 | putVReg( vD_addr, mkV128from4x64U( mkexpr(z3), mkexpr(z2), |
| 7330 | mkexpr(z1), mkexpr(z0)) ); |
| 7331 | |
cerion | 6f1cc0f | 2005-09-16 16:02:11 +0000 | [diff] [blame] | 7332 | break; |
| 7333 | } |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7334 | case 0x28: { // vmsumshm (Multiply Sum Signed HW Modulo, AV p202) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7335 | DIP("vmsumshm v%d,v%d,v%d,v%d\n", |
| 7336 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7337 | assign( abEvn, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
| 7338 | assign( abOdd, binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7339 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7340 | binop(Iop_Add32x4, mkexpr(vC), |
| 7341 | binop(Iop_Add32x4, mkexpr(abOdd), mkexpr(abEvn))) ); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7342 | break; |
| 7343 | } |
| 7344 | case 0x29: { // vmsumshs (Multiply Sum Signed HW Saturate, AV p203) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7345 | DIP("vmsumshs v%d,v%d,v%d,v%d\n", |
| 7346 | vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7347 | /* widening multiply, separating lanes */ |
cerion | 24d06f1 | 2005-11-09 21:34:20 +0000 | [diff] [blame] | 7348 | assign( abEvn, MK_Iop_MullOdd16Sx8( mkexpr(vA), mkexpr(vB) )); |
| 7349 | assign( abOdd, binop(Iop_MullEven16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7350 | |
cerion | 4a49b03 | 2005-11-08 16:23:07 +0000 | [diff] [blame] | 7351 | /* break V128 to 4xI32's, sign-extending to I64's */ |
| 7352 | breakV128to4x64S( mkexpr(abEvn), &ab7, &ab5, &ab3, &ab1 ); |
| 7353 | breakV128to4x64S( mkexpr(abOdd), &ab6, &ab4, &ab2, &ab0 ); |
| 7354 | breakV128to4x64S( mkexpr(vC), &c3, &c2, &c1, &c0 ); |
| 7355 | |
| 7356 | /* add lanes */ |
| 7357 | assign( z3, binop(Iop_Add64, mkexpr(c3), |
| 7358 | binop(Iop_Add64, mkexpr(ab7), mkexpr(ab6)))); |
| 7359 | assign( z2, binop(Iop_Add64, mkexpr(c2), |
| 7360 | binop(Iop_Add64, mkexpr(ab5), mkexpr(ab4)))); |
| 7361 | assign( z1, binop(Iop_Add64, mkexpr(c1), |
| 7362 | binop(Iop_Add64, mkexpr(ab3), mkexpr(ab2)))); |
| 7363 | assign( z0, binop(Iop_Add64, mkexpr(c0), |
| 7364 | binop(Iop_Add64, mkexpr(ab1), mkexpr(ab0)))); |
| 7365 | |
| 7366 | /* saturate-narrow to 32bit, and combine to V128 */ |
| 7367 | putVReg( vD_addr, mkV128from4x64S( mkexpr(z3), mkexpr(z2), |
| 7368 | mkexpr(z1), mkexpr(z0)) ); |
| 7369 | break; |
| 7370 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7371 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7372 | vex_printf("dis_av_multarith(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7373 | return False; |
| 7374 | } |
| 7375 | return True; |
| 7376 | } |
| 7377 | |
| 7378 | /* |
| 7379 | AltiVec Shift/Rotate Instructions |
| 7380 | */ |
| 7381 | static Bool dis_av_shift ( UInt theInstr ) |
| 7382 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7383 | /* VX-Form */ |
| 7384 | UChar opc1 = ifieldOPC(theInstr); |
| 7385 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7386 | UChar vA_addr = ifieldRegA(theInstr); |
| 7387 | UChar vB_addr = ifieldRegB(theInstr); |
| 7388 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7389 | |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7390 | IRTemp vA = newTemp(Ity_V128); |
| 7391 | IRTemp vB = newTemp(Ity_V128); |
| 7392 | assign( vA, getVReg(vA_addr)); |
| 7393 | assign( vB, getVReg(vB_addr)); |
| 7394 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7395 | if (opc1 != 0x4){ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7396 | vex_printf("dis_av_shift(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7397 | return False; |
| 7398 | } |
| 7399 | |
| 7400 | switch (opc2) { |
| 7401 | /* Rotate */ |
| 7402 | case 0x004: // vrlb (Rotate Left Integer B, AV p234) |
| 7403 | DIP("vrlb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7404 | putVReg( vD_addr, binop(Iop_Rol8x16, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7405 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7406 | |
| 7407 | case 0x044: // vrlh (Rotate Left Integer HW, AV p235) |
| 7408 | DIP("vrlh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7409 | putVReg( vD_addr, binop(Iop_Rol16x8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7410 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7411 | |
| 7412 | case 0x084: // vrlw (Rotate Left Integer W, AV p236) |
| 7413 | DIP("vrlw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7414 | putVReg( vD_addr, binop(Iop_Rol32x4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7415 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7416 | |
| 7417 | |
| 7418 | /* Shift Left */ |
| 7419 | case 0x104: // vslb (Shift Left Integer B, AV p240) |
| 7420 | DIP("vslb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7421 | putVReg( vD_addr, binop(Iop_Shl8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7422 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7423 | |
| 7424 | case 0x144: // vslh (Shift Left Integer HW, AV p242) |
| 7425 | DIP("vslh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7426 | putVReg( vD_addr, binop(Iop_Shl16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7427 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7428 | |
| 7429 | case 0x184: // vslw (Shift Left Integer W, AV p244) |
| 7430 | DIP("vslw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7431 | putVReg( vD_addr, binop(Iop_Shl32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7432 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7433 | |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7434 | case 0x1C4: { // vsl (Shift Left, AV p239) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7435 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7436 | DIP("vsl v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7437 | assign( sh, binop(Iop_And8, mkU8(0x7), |
| 7438 | unop(Iop_32to8, |
| 7439 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7440 | putVReg( vD_addr, |
| 7441 | binop(Iop_ShlV128, mkexpr(vA), mkexpr(sh)) ); |
| 7442 | break; |
| 7443 | } |
| 7444 | case 0x40C: { // vslo (Shift Left by Octet, AV p243) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7445 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7446 | DIP("vslo v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7447 | assign( sh, binop(Iop_And8, mkU8(0x78), |
| 7448 | unop(Iop_32to8, |
| 7449 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7450 | putVReg( vD_addr, |
| 7451 | binop(Iop_ShlV128, mkexpr(vA), mkexpr(sh)) ); |
| 7452 | break; |
| 7453 | } |
| 7454 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7455 | |
| 7456 | /* Shift Right */ |
| 7457 | case 0x204: // vsrb (Shift Right B, AV p256) |
| 7458 | DIP("vsrb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7459 | putVReg( vD_addr, binop(Iop_Shr8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7460 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7461 | |
| 7462 | case 0x244: // vsrh (Shift Right HW, AV p257) |
| 7463 | DIP("vsrh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7464 | putVReg( vD_addr, binop(Iop_Shr16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7465 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7466 | |
| 7467 | case 0x284: // vsrw (Shift Right W, AV p259) |
| 7468 | DIP("vsrw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7469 | putVReg( vD_addr, binop(Iop_Shr32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7470 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7471 | |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7472 | case 0x2C4: { // vsr (Shift Right, AV p251) |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7473 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7474 | DIP("vsr v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7475 | assign( sh, binop(Iop_And8, mkU8(0x7), |
| 7476 | unop(Iop_32to8, |
| 7477 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7478 | putVReg( vD_addr, |
| 7479 | binop(Iop_ShrV128, mkexpr(vA), mkexpr(sh)) ); |
| 7480 | break; |
| 7481 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7482 | case 0x304: // vsrab (Shift Right Alg B, AV p253) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7483 | DIP("vsrab v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7484 | putVReg( vD_addr, binop(Iop_Sar8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7485 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7486 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7487 | case 0x344: // vsrah (Shift Right Alg HW, AV p254) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7488 | DIP("vsrah v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7489 | putVReg( vD_addr, binop(Iop_Sar16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7490 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7491 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7492 | case 0x384: // vsraw (Shift Right Alg W, AV p255) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7493 | DIP("vsraw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7494 | putVReg( vD_addr, binop(Iop_Sar32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7495 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7496 | |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7497 | case 0x44C: { // vsro (Shift Right by Octet, AV p258) |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7498 | IRTemp sh = newTemp(Ity_I8); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7499 | DIP("vsro v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 0a7b4f4 | 2005-09-16 07:54:40 +0000 | [diff] [blame] | 7500 | assign( sh, binop(Iop_And8, mkU8(0x78), |
| 7501 | unop(Iop_32to8, |
| 7502 | unop(Iop_V128to32, mkexpr(vB)))) ); |
| 7503 | putVReg( vD_addr, |
| 7504 | binop(Iop_ShrV128, mkexpr(vA), mkexpr(sh)) ); |
| 7505 | break; |
| 7506 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7507 | |
| 7508 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7509 | vex_printf("dis_av_shift(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7510 | return False; |
| 7511 | } |
| 7512 | return True; |
| 7513 | } |
| 7514 | |
| 7515 | /* |
| 7516 | AltiVec Permute Instructions |
| 7517 | */ |
| 7518 | static Bool dis_av_permute ( UInt theInstr ) |
| 7519 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7520 | /* VA-Form, VX-Form */ |
| 7521 | UChar opc1 = ifieldOPC(theInstr); |
| 7522 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7523 | UChar vA_addr = ifieldRegA(theInstr); |
| 7524 | UChar UIMM_5 = vA_addr; |
| 7525 | UChar vB_addr = ifieldRegB(theInstr); |
| 7526 | UChar vC_addr = ifieldRegC(theInstr); |
| 7527 | UChar b10 = ifieldBIT10(theInstr); |
| 7528 | UChar SHB_uimm4 = toUChar( IFIELD( theInstr, 6, 4 ) ); |
| 7529 | UInt opc2 = toUChar( IFIELD( theInstr, 0, 6 ) ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7530 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7531 | UChar SIMM_8 = extend_s_5to8(UIMM_5); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7532 | |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7533 | IRTemp vA = newTemp(Ity_V128); |
| 7534 | IRTemp vB = newTemp(Ity_V128); |
| 7535 | IRTemp vC = newTemp(Ity_V128); |
| 7536 | assign( vA, getVReg(vA_addr)); |
| 7537 | assign( vB, getVReg(vB_addr)); |
| 7538 | assign( vC, getVReg(vC_addr)); |
| 7539 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7540 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7541 | vex_printf("dis_av_permute(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7542 | return False; |
| 7543 | } |
| 7544 | |
| 7545 | switch (opc2) { |
| 7546 | case 0x2A: // vsel (Conditional Select, AV p238) |
| 7547 | DIP("vsel v%d,v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr, vC_addr); |
cerion | 6e7a0ea | 2005-09-13 13:34:09 +0000 | [diff] [blame] | 7548 | /* vD = (vA & ~vC) | (vB & vC) */ |
| 7549 | putVReg( vD_addr, binop(Iop_OrV128, |
| 7550 | binop(Iop_AndV128, mkexpr(vA), unop(Iop_NotV128, mkexpr(vC))), |
| 7551 | binop(Iop_AndV128, mkexpr(vB), mkexpr(vC))) ); |
| 7552 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7553 | |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7554 | case 0x2B: { // vperm (Permute, AV p218) |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7555 | /* limited to two args for IR, so have to play games... */ |
sewardj | dc1f913 | 2005-10-22 12:49:49 +0000 | [diff] [blame] | 7556 | IRTemp a_perm = newTemp(Ity_V128); |
| 7557 | IRTemp b_perm = newTemp(Ity_V128); |
| 7558 | IRTemp mask = newTemp(Ity_V128); |
| 7559 | IRTemp vC_andF = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7560 | DIP("vperm v%d,v%d,v%d,v%d\n", |
| 7561 | vD_addr, vA_addr, vB_addr, vC_addr); |
sewardj | dc1f913 | 2005-10-22 12:49:49 +0000 | [diff] [blame] | 7562 | /* Limit the Perm8x16 steering values to 0 .. 15 as that is what |
| 7563 | IR specifies, and also to hide irrelevant bits from |
| 7564 | memcheck */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7565 | assign( vC_andF, |
| 7566 | binop(Iop_AndV128, mkexpr(vC), |
| 7567 | unop(Iop_Dup8x16, mkU8(0xF))) ); |
| 7568 | assign( a_perm, |
| 7569 | binop(Iop_Perm8x16, mkexpr(vA), mkexpr(vC_andF)) ); |
| 7570 | assign( b_perm, |
| 7571 | binop(Iop_Perm8x16, mkexpr(vB), mkexpr(vC_andF)) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7572 | // mask[i8] = (vC[i8]_4 == 1) ? 0xFF : 0x0 |
| 7573 | assign( mask, binop(Iop_SarN8x16, |
| 7574 | binop(Iop_ShlN8x16, mkexpr(vC), mkU8(3)), |
| 7575 | mkU8(7)) ); |
| 7576 | // dst = (a & ~mask) | (b & mask) |
| 7577 | putVReg( vD_addr, binop(Iop_OrV128, |
| 7578 | binop(Iop_AndV128, mkexpr(a_perm), |
| 7579 | unop(Iop_NotV128, mkexpr(mask))), |
| 7580 | binop(Iop_AndV128, mkexpr(b_perm), |
| 7581 | mkexpr(mask))) ); |
| 7582 | return True; |
| 7583 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7584 | case 0x2C: // vsldoi (Shift Left Double by Octet Imm, AV p241) |
| 7585 | if (b10 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7586 | vex_printf("dis_av_permute(ppc)(vsldoi)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7587 | return False; |
| 7588 | } |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7589 | DIP("vsldoi v%d,v%d,v%d,%d\n", |
| 7590 | vD_addr, vA_addr, vB_addr, SHB_uimm4); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7591 | if (SHB_uimm4 == 0) |
| 7592 | putVReg( vD_addr, mkexpr(vA) ); |
| 7593 | else |
| 7594 | putVReg( vD_addr, |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7595 | binop(Iop_OrV128, |
| 7596 | binop(Iop_ShlV128, mkexpr(vA), mkU8(SHB_uimm4*8)), |
| 7597 | binop(Iop_ShrV128, mkexpr(vB), mkU8((16-SHB_uimm4)*8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7598 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7599 | |
| 7600 | default: |
| 7601 | break; // Fall through... |
| 7602 | } |
| 7603 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7604 | opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7605 | switch (opc2) { |
| 7606 | |
| 7607 | /* Merge */ |
| 7608 | case 0x00C: // vmrghb (Merge High B, AV p195) |
| 7609 | DIP("vmrghb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7610 | putVReg( vD_addr, |
| 7611 | binop(Iop_InterleaveHI8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7612 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7613 | |
| 7614 | case 0x04C: // vmrghh (Merge High HW, AV p196) |
| 7615 | DIP("vmrghh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7616 | putVReg( vD_addr, |
| 7617 | binop(Iop_InterleaveHI16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7618 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7619 | |
| 7620 | case 0x08C: // vmrghw (Merge High W, AV p197) |
| 7621 | DIP("vmrghw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7622 | putVReg( vD_addr, |
| 7623 | binop(Iop_InterleaveHI32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7624 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7625 | |
| 7626 | case 0x10C: // vmrglb (Merge Low B, AV p198) |
| 7627 | DIP("vmrglb v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7628 | putVReg( vD_addr, |
| 7629 | binop(Iop_InterleaveLO8x16, mkexpr(vA), mkexpr(vB)) ); |
| 7630 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7631 | |
| 7632 | case 0x14C: // vmrglh (Merge Low HW, AV p199) |
| 7633 | DIP("vmrglh v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7634 | putVReg( vD_addr, |
| 7635 | binop(Iop_InterleaveLO16x8, mkexpr(vA), mkexpr(vB)) ); |
| 7636 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7637 | |
| 7638 | case 0x18C: // vmrglw (Merge Low W, AV p200) |
| 7639 | DIP("vmrglw v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7640 | putVReg( vD_addr, |
| 7641 | binop(Iop_InterleaveLO32x4, mkexpr(vA), mkexpr(vB)) ); |
| 7642 | break; |
| 7643 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7644 | |
| 7645 | /* Splat */ |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7646 | case 0x20C: { // vspltb (Splat Byte, AV p245) |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7647 | /* vD = Dup8x16( vB[UIMM_5] ) */ |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 7648 | UChar sh_uimm = (15 - (UIMM_5 & 15)) * 8; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7649 | DIP("vspltb v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7650 | putVReg( vD_addr, unop(Iop_Dup8x16, |
| 7651 | unop(Iop_32to8, unop(Iop_V128to32, |
| 7652 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm))))) ); |
| 7653 | break; |
| 7654 | } |
| 7655 | case 0x24C: { // vsplth (Splat Half Word, AV p246) |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 7656 | UChar sh_uimm = (7 - (UIMM_5 & 7)) * 16; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7657 | DIP("vsplth v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7658 | putVReg( vD_addr, unop(Iop_Dup16x8, |
| 7659 | unop(Iop_32to16, unop(Iop_V128to32, |
| 7660 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm))))) ); |
| 7661 | break; |
| 7662 | } |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7663 | case 0x28C: { // vspltw (Splat Word, AV p250) |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7664 | /* vD = Dup32x4( vB[UIMM_5] ) */ |
sewardj | d147094 | 2005-10-22 02:01:16 +0000 | [diff] [blame] | 7665 | UChar sh_uimm = (3 - (UIMM_5 & 3)) * 32; |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7666 | DIP("vspltw v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | 27b3d7e | 2005-09-14 20:35:47 +0000 | [diff] [blame] | 7667 | putVReg( vD_addr, unop(Iop_Dup32x4, |
| 7668 | unop(Iop_V128to32, |
| 7669 | binop(Iop_ShrV128, mkexpr(vB), mkU8(sh_uimm)))) ); |
| 7670 | break; |
| 7671 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7672 | case 0x30C: // vspltisb (Splat Immediate Signed B, AV p247) |
| 7673 | DIP("vspltisb v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7674 | putVReg( vD_addr, unop(Iop_Dup8x16, mkU8(SIMM_8)) ); |
| 7675 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7676 | |
| 7677 | case 0x34C: // vspltish (Splat Immediate Signed HW, AV p248) |
| 7678 | DIP("vspltish v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7679 | putVReg( vD_addr, |
| 7680 | unop(Iop_Dup16x8, mkU16(extend_s_8to32(SIMM_8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7681 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7682 | |
| 7683 | case 0x38C: // vspltisw (Splat Immediate Signed W, AV p249) |
| 7684 | DIP("vspltisw v%d,%d\n", vD_addr, (Char)SIMM_8); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7685 | putVReg( vD_addr, |
| 7686 | unop(Iop_Dup32x4, mkU32(extend_s_8to32(SIMM_8))) ); |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 7687 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7688 | |
| 7689 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7690 | vex_printf("dis_av_permute(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7691 | return False; |
| 7692 | } |
| 7693 | return True; |
| 7694 | } |
| 7695 | |
| 7696 | /* |
| 7697 | AltiVec Pack/Unpack Instructions |
| 7698 | */ |
| 7699 | static Bool dis_av_pack ( UInt theInstr ) |
| 7700 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7701 | /* VX-Form */ |
| 7702 | UChar opc1 = ifieldOPC(theInstr); |
| 7703 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7704 | UChar vA_addr = ifieldRegA(theInstr); |
| 7705 | UChar vB_addr = ifieldRegB(theInstr); |
| 7706 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7707 | |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7708 | IRTemp signs = IRTemp_INVALID; |
| 7709 | IRTemp zeros = IRTemp_INVALID; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7710 | IRTemp vA = newTemp(Ity_V128); |
| 7711 | IRTemp vB = newTemp(Ity_V128); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7712 | assign( vA, getVReg(vA_addr)); |
| 7713 | assign( vB, getVReg(vB_addr)); |
| 7714 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7715 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7716 | vex_printf("dis_av_pack(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7717 | return False; |
| 7718 | } |
| 7719 | |
| 7720 | switch (opc2) { |
| 7721 | /* Packing */ |
| 7722 | case 0x00E: // vpkuhum (Pack Unsigned HW Unsigned Modulo, AV p224) |
| 7723 | DIP("vpkuhum v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7724 | putVReg( vD_addr, binop(Iop_Narrow16x8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7725 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7726 | |
| 7727 | case 0x04E: // vpkuwum (Pack Unsigned W Unsigned Modulo, AV p226) |
| 7728 | DIP("vpkuwum v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7729 | putVReg( vD_addr, binop(Iop_Narrow32x4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7730 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7731 | |
| 7732 | case 0x08E: // vpkuhus (Pack Unsigned HW Unsigned Saturate, AV p225) |
| 7733 | DIP("vpkuhus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7734 | putVReg( vD_addr, |
| 7735 | binop(Iop_QNarrow16Ux8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7736 | // TODO: set VSCR[SAT] |
| 7737 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7738 | |
| 7739 | case 0x0CE: // vpkuwus (Pack Unsigned W Unsigned Saturate, AV p227) |
| 7740 | DIP("vpkuwus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7741 | putVReg( vD_addr, |
| 7742 | binop(Iop_QNarrow32Ux4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7743 | // TODO: set VSCR[SAT] |
| 7744 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7745 | |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7746 | case 0x10E: { // vpkshus (Pack Signed HW Unsigned Saturate, AV p221) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7747 | // This insn does a signed->unsigned saturating conversion. |
| 7748 | // Conversion done here, then uses unsigned->unsigned vpk insn: |
| 7749 | // => UnsignedSaturatingNarrow( x & ~ (x >>s 15) ) |
| 7750 | IRTemp vA_tmp = newTemp(Ity_V128); |
| 7751 | IRTemp vB_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7752 | DIP("vpkshus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7753 | assign( vA_tmp, binop(Iop_AndV128, mkexpr(vA), |
| 7754 | unop(Iop_NotV128, |
| 7755 | binop(Iop_SarN16x8, |
| 7756 | mkexpr(vA), mkU8(15)))) ); |
| 7757 | assign( vB_tmp, binop(Iop_AndV128, mkexpr(vB), |
| 7758 | unop(Iop_NotV128, |
| 7759 | binop(Iop_SarN16x8, |
| 7760 | mkexpr(vB), mkU8(15)))) ); |
| 7761 | putVReg( vD_addr, binop(Iop_QNarrow16Ux8, |
| 7762 | mkexpr(vA_tmp), mkexpr(vB_tmp)) ); |
| 7763 | // TODO: set VSCR[SAT] |
| 7764 | return True; |
| 7765 | } |
| 7766 | case 0x14E: { // vpkswus (Pack Signed W Unsigned Saturate, AV p223) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7767 | // This insn does a signed->unsigned saturating conversion. |
| 7768 | // Conversion done here, then uses unsigned->unsigned vpk insn: |
| 7769 | // => UnsignedSaturatingNarrow( x & ~ (x >>s 31) ) |
| 7770 | IRTemp vA_tmp = newTemp(Ity_V128); |
| 7771 | IRTemp vB_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7772 | DIP("vpkswus v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7773 | assign( vA_tmp, binop(Iop_AndV128, mkexpr(vA), |
| 7774 | unop(Iop_NotV128, |
| 7775 | binop(Iop_SarN32x4, |
| 7776 | mkexpr(vA), mkU8(31)))) ); |
| 7777 | assign( vB_tmp, binop(Iop_AndV128, mkexpr(vB), |
| 7778 | unop(Iop_NotV128, |
| 7779 | binop(Iop_SarN32x4, |
| 7780 | mkexpr(vB), mkU8(31)))) ); |
| 7781 | putVReg( vD_addr, binop(Iop_QNarrow32Ux4, |
| 7782 | mkexpr(vA_tmp), mkexpr(vB_tmp)) ); |
| 7783 | // TODO: set VSCR[SAT] |
| 7784 | return True; |
| 7785 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7786 | case 0x18E: // vpkshss (Pack Signed HW Signed Saturate, AV p220) |
| 7787 | DIP("vpkshss v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7788 | putVReg( vD_addr, |
| 7789 | binop(Iop_QNarrow16Sx8, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7790 | // TODO: set VSCR[SAT] |
| 7791 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7792 | |
| 7793 | case 0x1CE: // vpkswss (Pack Signed W Signed Saturate, AV p222) |
| 7794 | DIP("vpkswss v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7795 | putVReg( vD_addr, |
| 7796 | binop(Iop_QNarrow32Sx4, mkexpr(vA), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7797 | // TODO: set VSCR[SAT] |
| 7798 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7799 | |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7800 | case 0x30E: { // vpkpx (Pack Pixel, AV p219) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7801 | /* CAB: Worth a new primop? */ |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7802 | /* Using shifts to compact pixel elements, then packing them */ |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7803 | IRTemp a1 = newTemp(Ity_V128); |
| 7804 | IRTemp a2 = newTemp(Ity_V128); |
| 7805 | IRTemp a3 = newTemp(Ity_V128); |
| 7806 | IRTemp a_tmp = newTemp(Ity_V128); |
| 7807 | IRTemp b1 = newTemp(Ity_V128); |
| 7808 | IRTemp b2 = newTemp(Ity_V128); |
| 7809 | IRTemp b3 = newTemp(Ity_V128); |
| 7810 | IRTemp b_tmp = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7811 | DIP("vpkpx v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7812 | assign( a1, binop(Iop_ShlN16x8, |
| 7813 | binop(Iop_ShrN32x4, mkexpr(vA), mkU8(19)), |
| 7814 | mkU8(10)) ); |
| 7815 | assign( a2, binop(Iop_ShlN16x8, |
| 7816 | binop(Iop_ShrN16x8, mkexpr(vA), mkU8(11)), |
| 7817 | mkU8(5)) ); |
| 7818 | assign( a3, binop(Iop_ShrN16x8, |
| 7819 | binop(Iop_ShlN16x8, mkexpr(vA), mkU8(8)), |
| 7820 | mkU8(11)) ); |
| 7821 | assign( a_tmp, binop(Iop_OrV128, mkexpr(a1), |
| 7822 | binop(Iop_OrV128, mkexpr(a2), mkexpr(a3))) ); |
| 7823 | |
| 7824 | assign( b1, binop(Iop_ShlN16x8, |
| 7825 | binop(Iop_ShrN32x4, mkexpr(vB), mkU8(19)), |
| 7826 | mkU8(10)) ); |
| 7827 | assign( b2, binop(Iop_ShlN16x8, |
| 7828 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(11)), |
| 7829 | mkU8(5)) ); |
| 7830 | assign( b3, binop(Iop_ShrN16x8, |
| 7831 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(8)), |
| 7832 | mkU8(11)) ); |
| 7833 | assign( b_tmp, binop(Iop_OrV128, mkexpr(b1), |
| 7834 | binop(Iop_OrV128, mkexpr(b2), mkexpr(b3))) ); |
| 7835 | |
sewardj | 1bee561 | 2005-11-10 18:10:58 +0000 | [diff] [blame] | 7836 | putVReg( vD_addr, binop(Iop_Narrow32x4, |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7837 | mkexpr(a_tmp), mkexpr(b_tmp)) ); |
| 7838 | return True; |
| 7839 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7840 | |
| 7841 | default: |
| 7842 | break; // Fall through... |
| 7843 | } |
| 7844 | |
| 7845 | |
| 7846 | if (vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7847 | vex_printf("dis_av_pack(ppc)(vA_addr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7848 | return False; |
| 7849 | } |
| 7850 | |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7851 | signs = newTemp(Ity_V128); |
| 7852 | zeros = newTemp(Ity_V128); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7853 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
| 7854 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7855 | switch (opc2) { |
| 7856 | /* Unpacking */ |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7857 | case 0x20E: { // vupkhsb (Unpack High Signed B, AV p277) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7858 | DIP("vupkhsb v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7859 | assign( signs, binop(Iop_CmpGT8Sx16, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7860 | putVReg( vD_addr, |
| 7861 | binop(Iop_InterleaveHI8x16, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7862 | break; |
| 7863 | } |
| 7864 | case 0x24E: { // vupkhsh (Unpack High Signed HW, AV p278) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7865 | DIP("vupkhsh v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7866 | assign( signs, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7867 | putVReg( vD_addr, |
| 7868 | binop(Iop_InterleaveHI16x8, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7869 | break; |
| 7870 | } |
| 7871 | case 0x28E: { // vupklsb (Unpack Low Signed B, AV p280) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7872 | DIP("vupklsb v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7873 | assign( signs, binop(Iop_CmpGT8Sx16, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7874 | putVReg( vD_addr, |
| 7875 | binop(Iop_InterleaveLO8x16, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7876 | break; |
| 7877 | } |
| 7878 | case 0x2CE: { // vupklsh (Unpack Low Signed HW, AV p281) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7879 | DIP("vupklsh v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7880 | assign( signs, binop(Iop_CmpGT16Sx8, mkexpr(zeros), mkexpr(vB)) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7881 | putVReg( vD_addr, |
| 7882 | binop(Iop_InterleaveLO16x8, mkexpr(signs), mkexpr(vB)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7883 | break; |
| 7884 | } |
| 7885 | case 0x34E: { // vupkhpx (Unpack High Pixel16, AV p276) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7886 | /* CAB: Worth a new primop? */ |
| 7887 | /* Using shifts to isolate pixel elements, then expanding them */ |
| 7888 | IRTemp z0 = newTemp(Ity_V128); |
| 7889 | IRTemp z1 = newTemp(Ity_V128); |
| 7890 | IRTemp z01 = newTemp(Ity_V128); |
| 7891 | IRTemp z2 = newTemp(Ity_V128); |
| 7892 | IRTemp z3 = newTemp(Ity_V128); |
| 7893 | IRTemp z23 = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7894 | DIP("vupkhpx v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7895 | assign( z0, binop(Iop_ShlN16x8, |
| 7896 | binop(Iop_SarN16x8, mkexpr(vB), mkU8(15)), |
| 7897 | mkU8(8)) ); |
| 7898 | assign( z1, binop(Iop_ShrN16x8, |
| 7899 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(1)), |
| 7900 | mkU8(11)) ); |
| 7901 | assign( z01, binop(Iop_InterleaveHI16x8, mkexpr(zeros), |
| 7902 | binop(Iop_OrV128, mkexpr(z0), mkexpr(z1))) ); |
| 7903 | assign( z2, binop(Iop_ShrN16x8, |
| 7904 | binop(Iop_ShlN16x8, |
| 7905 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(5)), |
| 7906 | mkU8(11)), |
| 7907 | mkU8(3)) ); |
| 7908 | assign( z3, binop(Iop_ShrN16x8, |
| 7909 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(11)), |
| 7910 | mkU8(11)) ); |
| 7911 | assign( z23, binop(Iop_InterleaveHI16x8, mkexpr(zeros), |
| 7912 | binop(Iop_OrV128, mkexpr(z2), mkexpr(z3))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7913 | putVReg( vD_addr, |
| 7914 | binop(Iop_OrV128, |
| 7915 | binop(Iop_ShlN32x4, mkexpr(z01), mkU8(16)), |
| 7916 | mkexpr(z23)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7917 | break; |
| 7918 | } |
| 7919 | case 0x3CE: { // vupklpx (Unpack Low Pixel16, AV p279) |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7920 | /* identical to vupkhpx, except interleaving LO */ |
| 7921 | IRTemp z0 = newTemp(Ity_V128); |
| 7922 | IRTemp z1 = newTemp(Ity_V128); |
| 7923 | IRTemp z01 = newTemp(Ity_V128); |
| 7924 | IRTemp z2 = newTemp(Ity_V128); |
| 7925 | IRTemp z3 = newTemp(Ity_V128); |
| 7926 | IRTemp z23 = newTemp(Ity_V128); |
sewardj | 197bd17 | 2005-10-12 11:34:33 +0000 | [diff] [blame] | 7927 | DIP("vupklpx v%d,v%d\n", vD_addr, vB_addr); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7928 | assign( z0, binop(Iop_ShlN16x8, |
| 7929 | binop(Iop_SarN16x8, mkexpr(vB), mkU8(15)), |
| 7930 | mkU8(8)) ); |
| 7931 | assign( z1, binop(Iop_ShrN16x8, |
| 7932 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(1)), |
| 7933 | mkU8(11)) ); |
| 7934 | assign( z01, binop(Iop_InterleaveLO16x8, mkexpr(zeros), |
| 7935 | binop(Iop_OrV128, mkexpr(z0), mkexpr(z1))) ); |
| 7936 | assign( z2, binop(Iop_ShrN16x8, |
| 7937 | binop(Iop_ShlN16x8, |
| 7938 | binop(Iop_ShrN16x8, mkexpr(vB), mkU8(5)), |
| 7939 | mkU8(11)), |
| 7940 | mkU8(3)) ); |
| 7941 | assign( z3, binop(Iop_ShrN16x8, |
| 7942 | binop(Iop_ShlN16x8, mkexpr(vB), mkU8(11)), |
| 7943 | mkU8(11)) ); |
| 7944 | assign( z23, binop(Iop_InterleaveLO16x8, mkexpr(zeros), |
| 7945 | binop(Iop_OrV128, mkexpr(z2), mkexpr(z3))) ); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7946 | putVReg( vD_addr, |
| 7947 | binop(Iop_OrV128, |
| 7948 | binop(Iop_ShlN32x4, mkexpr(z01), mkU8(16)), |
| 7949 | mkexpr(z23)) ); |
cerion | 3c05279 | 2005-09-16 07:13:44 +0000 | [diff] [blame] | 7950 | break; |
| 7951 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7952 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7953 | vex_printf("dis_av_pack(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7954 | return False; |
| 7955 | } |
| 7956 | return True; |
| 7957 | } |
| 7958 | |
| 7959 | |
| 7960 | /* |
| 7961 | AltiVec Floating Point Arithmetic Instructions |
| 7962 | */ |
| 7963 | static Bool dis_av_fp_arith ( UInt theInstr ) |
| 7964 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7965 | /* VA-Form */ |
| 7966 | UChar opc1 = ifieldOPC(theInstr); |
| 7967 | UChar vD_addr = ifieldRegDS(theInstr); |
| 7968 | UChar vA_addr = ifieldRegA(theInstr); |
| 7969 | UChar vB_addr = ifieldRegB(theInstr); |
| 7970 | UChar vC_addr = ifieldRegC(theInstr); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7971 | UInt opc2=0; |
| 7972 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 7973 | IRTemp vA = newTemp(Ity_V128); |
| 7974 | IRTemp vB = newTemp(Ity_V128); |
| 7975 | IRTemp vC = newTemp(Ity_V128); |
| 7976 | assign( vA, getVReg(vA_addr)); |
| 7977 | assign( vB, getVReg(vB_addr)); |
| 7978 | assign( vC, getVReg(vC_addr)); |
| 7979 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7980 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7981 | vex_printf("dis_av_fp_arith(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7982 | return False; |
| 7983 | } |
| 7984 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 7985 | opc2 = IFIELD( theInstr, 0, 6 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7986 | switch (opc2) { |
| 7987 | case 0x2E: // vmaddfp (Multiply Add FP, AV p177) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7988 | DIP("vmaddfp v%d,v%d,v%d,v%d\n", |
| 7989 | vD_addr, vA_addr, vC_addr, vB_addr); |
| 7990 | putVReg( vD_addr, |
| 7991 | binop(Iop_Add32Fx4, mkexpr(vB), |
| 7992 | binop(Iop_Mul32Fx4, mkexpr(vA), mkexpr(vC))) ); |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 7993 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 7994 | |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 7995 | case 0x2F: { // vnmsubfp (Negative Multiply-Subtract FP, AV p215) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 7996 | DIP("vnmsubfp v%d,v%d,v%d,v%d\n", |
| 7997 | vD_addr, vA_addr, vC_addr, vB_addr); |
| 7998 | putVReg( vD_addr, |
| 7999 | binop(Iop_Sub32Fx4, |
| 8000 | mkexpr(vB), |
| 8001 | binop(Iop_Mul32Fx4, mkexpr(vA), mkexpr(vC))) ); |
cerion | f3f173c | 2005-11-14 02:37:44 +0000 | [diff] [blame] | 8002 | return True; |
| 8003 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8004 | |
| 8005 | default: |
| 8006 | break; // Fall through... |
| 8007 | } |
| 8008 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8009 | opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8010 | switch (opc2) { |
| 8011 | case 0x00A: // vaddfp (Add FP, AV p137) |
| 8012 | DIP("vaddfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8013 | putVReg( vD_addr, binop(Iop_Add32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8014 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8015 | |
| 8016 | case 0x04A: // vsubfp (Subtract FP, AV p261) |
| 8017 | DIP("vsubfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8018 | putVReg( vD_addr, binop(Iop_Sub32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8019 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8020 | |
| 8021 | case 0x40A: // vmaxfp (Maximum FP, AV p178) |
| 8022 | DIP("vmaxfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8023 | putVReg( vD_addr, binop(Iop_Max32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8024 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8025 | |
| 8026 | case 0x44A: // vminfp (Minimum FP, AV p187) |
| 8027 | DIP("vminfp v%d,v%d,v%d\n", vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8028 | putVReg( vD_addr, binop(Iop_Min32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8029 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8030 | |
| 8031 | default: |
| 8032 | break; // Fall through... |
| 8033 | } |
| 8034 | |
| 8035 | |
| 8036 | if (vA_addr != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8037 | vex_printf("dis_av_fp_arith(ppc)(vA_addr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8038 | return False; |
| 8039 | } |
| 8040 | |
| 8041 | switch (opc2) { |
| 8042 | case 0x10A: // vrefp (Reciprocal Esimate FP, AV p228) |
| 8043 | DIP("vrefp v%d,v%d\n", vD_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8044 | putVReg( vD_addr, unop(Iop_Recip32Fx4, mkexpr(vB)) ); |
| 8045 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8046 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8047 | case 0x14A: // vrsqrtefp (Reciprocal Sqrt Estimate FP, AV p237) |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8048 | DIP("vrsqrtefp v%d,v%d\n", vD_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8049 | putVReg( vD_addr, unop(Iop_RSqrt32Fx4, mkexpr(vB)) ); |
| 8050 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8051 | |
| 8052 | case 0x18A: // vexptefp (2 Raised to the Exp Est FP, AV p173) |
| 8053 | DIP("vexptefp v%d,v%d\n", vD_addr, vB_addr); |
| 8054 | DIP(" => not implemented\n"); |
| 8055 | return False; |
| 8056 | |
| 8057 | case 0x1CA: // vlogefp (Log2 Estimate FP, AV p175) |
| 8058 | DIP("vlogefp v%d,v%d\n", vD_addr, vB_addr); |
| 8059 | DIP(" => not implemented\n"); |
| 8060 | return False; |
| 8061 | |
| 8062 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8063 | vex_printf("dis_av_fp_arith(ppc)(opc2=0x%x)\n",opc2); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8064 | return False; |
| 8065 | } |
| 8066 | return True; |
| 8067 | } |
| 8068 | |
| 8069 | /* |
| 8070 | AltiVec Floating Point Compare Instructions |
| 8071 | */ |
| 8072 | static Bool dis_av_fp_cmp ( UInt theInstr ) |
| 8073 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8074 | /* VXR-Form */ |
| 8075 | UChar opc1 = ifieldOPC(theInstr); |
| 8076 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8077 | UChar vA_addr = ifieldRegA(theInstr); |
| 8078 | UChar vB_addr = ifieldRegB(theInstr); |
| 8079 | UChar flag_rC = ifieldBIT10(theInstr); |
| 8080 | UInt opc2 = IFIELD( theInstr, 0, 10 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8081 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8082 | Bool cmp_bounds = False; |
| 8083 | |
| 8084 | IRTemp vA = newTemp(Ity_V128); |
| 8085 | IRTemp vB = newTemp(Ity_V128); |
| 8086 | IRTemp vD = newTemp(Ity_V128); |
| 8087 | assign( vA, getVReg(vA_addr)); |
| 8088 | assign( vB, getVReg(vB_addr)); |
| 8089 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8090 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8091 | vex_printf("dis_av_fp_cmp(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8092 | return False; |
| 8093 | } |
| 8094 | |
| 8095 | switch (opc2) { |
| 8096 | case 0x0C6: // vcmpeqfp (Compare Equal-to FP, AV p159) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8097 | DIP("vcmpeqfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8098 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8099 | assign( vD, binop(Iop_CmpEQ32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8100 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8101 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8102 | case 0x1C6: // vcmpgefp (Compare Greater-than-or-Equal-to, AV p163) |
| 8103 | DIP("vcmpgefp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8104 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8105 | assign( vD, binop(Iop_CmpGE32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8106 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8107 | |
| 8108 | case 0x2C6: // vcmpgtfp (Compare Greater-than FP, AV p164) |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8109 | DIP("vcmpgtfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8110 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8111 | assign( vD, binop(Iop_CmpGT32Fx4, mkexpr(vA), mkexpr(vB)) ); |
| 8112 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8113 | |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8114 | case 0x3C6: { // vcmpbfp (Compare Bounds FP, AV p157) |
| 8115 | IRTemp gt = newTemp(Ity_V128); |
| 8116 | IRTemp lt = newTemp(Ity_V128); |
| 8117 | IRTemp zeros = newTemp(Ity_V128); |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8118 | DIP("vcmpbfp%s v%d,v%d,v%d\n", (flag_rC ? ".":""), |
| 8119 | vD_addr, vA_addr, vB_addr); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8120 | cmp_bounds = True; |
| 8121 | assign( zeros, unop(Iop_Dup32x4, mkU32(0)) ); |
| 8122 | |
| 8123 | /* Note: making use of fact that the ppc backend for compare insns |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8124 | return zero'd lanes if either of the corresponding arg lanes is |
| 8125 | a nan. |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8126 | |
| 8127 | Perhaps better to have an irop Iop_isNan32Fx4, but then we'd |
| 8128 | need this for the other compares too (vcmpeqfp etc)... |
| 8129 | Better still, tighten down the spec for compare irops. |
| 8130 | */ |
| 8131 | assign( gt, unop(Iop_NotV128, |
| 8132 | binop(Iop_CmpLE32Fx4, mkexpr(vA), mkexpr(vB))) ); |
| 8133 | assign( lt, unop(Iop_NotV128, |
| 8134 | binop(Iop_CmpGE32Fx4, mkexpr(vA), |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8135 | binop(Iop_Sub32Fx4, mkexpr(zeros), |
| 8136 | mkexpr(vB)))) ); |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8137 | |
| 8138 | // finally, just shift gt,lt to correct position |
| 8139 | assign( vD, binop(Iop_ShlN32x4, |
| 8140 | binop(Iop_OrV128, |
| 8141 | binop(Iop_AndV128, mkexpr(gt), |
| 8142 | unop(Iop_Dup32x4, mkU32(0x2))), |
| 8143 | binop(Iop_AndV128, mkexpr(lt), |
| 8144 | unop(Iop_Dup32x4, mkU32(0x1)))), |
| 8145 | mkU8(30)) ); |
| 8146 | break; |
| 8147 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8148 | |
| 8149 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8150 | vex_printf("dis_av_fp_cmp(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8151 | return False; |
| 8152 | } |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8153 | |
| 8154 | putVReg( vD_addr, mkexpr(vD) ); |
| 8155 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8156 | if (flag_rC) { |
cerion | 8ea0d3e | 2005-11-14 00:44:47 +0000 | [diff] [blame] | 8157 | set_AV_CR6( mkexpr(vD), !cmp_bounds ); |
| 8158 | } |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8159 | return True; |
| 8160 | } |
| 8161 | |
| 8162 | /* |
| 8163 | AltiVec Floating Point Convert/Round Instructions |
| 8164 | */ |
| 8165 | static Bool dis_av_fp_convert ( UInt theInstr ) |
| 8166 | { |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8167 | /* VX-Form */ |
| 8168 | UChar opc1 = ifieldOPC(theInstr); |
| 8169 | UChar vD_addr = ifieldRegDS(theInstr); |
| 8170 | UChar UIMM_5 = ifieldRegA(theInstr); |
| 8171 | UChar vB_addr = ifieldRegB(theInstr); |
| 8172 | UInt opc2 = IFIELD( theInstr, 0, 11 ); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8173 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8174 | IRTemp vB = newTemp(Ity_V128); |
| 8175 | IRTemp vScale = newTemp(Ity_V128); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8176 | IRTemp vInvScale = newTemp(Ity_V128); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8177 | |
| 8178 | float scale, inv_scale; |
| 8179 | |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8180 | assign( vB, getVReg(vB_addr)); |
| 8181 | |
| 8182 | /* scale = 2^UIMM, cast to float, reinterpreted as uint */ |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8183 | scale = (float)( (unsigned int) 1<<UIMM_5 ); |
sewardj | 2ead522 | 2005-11-23 03:53:45 +0000 | [diff] [blame] | 8184 | assign( vScale, unop(Iop_Dup32x4, mkU32( float_to_bits(scale) )) ); |
sewardj | 41a7b70 | 2005-11-18 22:18:23 +0000 | [diff] [blame] | 8185 | inv_scale = 1/scale; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8186 | assign( vInvScale, |
| 8187 | unop(Iop_Dup32x4, mkU32( float_to_bits(inv_scale) )) ); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8188 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8189 | if (opc1 != 0x4) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8190 | vex_printf("dis_av_fp_convert(ppc)(instr)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8191 | return False; |
| 8192 | } |
| 8193 | |
| 8194 | switch (opc2) { |
| 8195 | case 0x30A: // vcfux (Convert from Unsigned Fixed-Point W, AV p156) |
| 8196 | DIP("vcfux v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8197 | putVReg( vD_addr, binop(Iop_Mul32Fx4, |
| 8198 | unop(Iop_I32UtoFx4, mkexpr(vB)), |
| 8199 | mkexpr(vInvScale)) ); |
| 8200 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8201 | |
| 8202 | case 0x34A: // vcfsx (Convert from Signed Fixed-Point W, AV p155) |
| 8203 | DIP("vcfsx v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8204 | |
| 8205 | putVReg( vD_addr, binop(Iop_Mul32Fx4, |
| 8206 | unop(Iop_I32StoFx4, mkexpr(vB)), |
| 8207 | mkexpr(vInvScale)) ); |
| 8208 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8209 | |
| 8210 | case 0x38A: // vctuxs (Convert to Unsigned Fixed-Point W Saturate, AV p172) |
| 8211 | DIP("vctuxs v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8212 | putVReg( vD_addr, |
| 8213 | unop(Iop_QFtoI32Ux4_RZ, |
| 8214 | binop(Iop_Mul32Fx4, mkexpr(vB), mkexpr(vScale))) ); |
| 8215 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8216 | |
| 8217 | case 0x3CA: // vctsxs (Convert to Signed Fixed-Point W Saturate, AV p171) |
| 8218 | DIP("vctsxs v%d,v%d,%d\n", vD_addr, vB_addr, UIMM_5); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8219 | putVReg( vD_addr, |
| 8220 | unop(Iop_QFtoI32Sx4_RZ, |
| 8221 | binop(Iop_Mul32Fx4, mkexpr(vB), mkexpr(vScale))) ); |
| 8222 | return True; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8223 | |
| 8224 | default: |
| 8225 | break; // Fall through... |
| 8226 | } |
| 8227 | |
| 8228 | if (UIMM_5 != 0) { |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8229 | vex_printf("dis_av_fp_convert(ppc)(UIMM_5)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8230 | return False; |
| 8231 | } |
| 8232 | |
| 8233 | switch (opc2) { |
| 8234 | case 0x20A: // vrfin (Round to FP Integer Nearest, AV p231) |
| 8235 | DIP("vrfin v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8236 | putVReg( vD_addr, unop(Iop_RoundF32x4_RN, mkexpr(vB)) ); |
| 8237 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8238 | |
| 8239 | case 0x24A: // vrfiz (Round to FP Integer toward zero, AV p233) |
| 8240 | DIP("vrfiz v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8241 | putVReg( vD_addr, unop(Iop_RoundF32x4_RZ, mkexpr(vB)) ); |
| 8242 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8243 | |
| 8244 | case 0x28A: // vrfip (Round to FP Integer toward +inf, AV p232) |
| 8245 | DIP("vrfip v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8246 | putVReg( vD_addr, unop(Iop_RoundF32x4_RP, mkexpr(vB)) ); |
| 8247 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8248 | |
| 8249 | case 0x2CA: // vrfim (Round to FP Integer toward -inf, AV p230) |
| 8250 | DIP("vrfim v%d,v%d\n", vD_addr, vB_addr); |
cerion | d963eb4 | 2005-11-16 18:02:58 +0000 | [diff] [blame] | 8251 | putVReg( vD_addr, unop(Iop_RoundF32x4_RM, mkexpr(vB)) ); |
| 8252 | break; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8253 | |
| 8254 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8255 | vex_printf("dis_av_fp_convert(ppc)(opc2)\n"); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8256 | return False; |
| 8257 | } |
| 8258 | return True; |
| 8259 | } |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8260 | |
| 8261 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8262 | |
| 8263 | |
| 8264 | |
| 8265 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8266 | /*------------------------------------------------------------*/ |
| 8267 | /*--- Disassemble a single instruction ---*/ |
| 8268 | /*------------------------------------------------------------*/ |
| 8269 | |
| 8270 | /* Disassemble a single instruction into IR. The instruction |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8271 | is located in host memory at &guest_code[delta]. */ |
| 8272 | |
| 8273 | static |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8274 | DisResult disInstr_PPC_WRK ( |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8275 | Bool put_IP, |
| 8276 | Bool (*resteerOkFn) ( Addr64 ), |
| 8277 | Long delta64, |
| 8278 | VexArchInfo* archinfo |
| 8279 | ) |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8280 | { |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8281 | UChar opc1; |
| 8282 | UInt opc2; |
| 8283 | DisResult dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8284 | UInt theInstr; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8285 | IRType ty = mode64 ? Ity_I64 : Ity_I32; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8286 | |
sewardj | 059601a | 2005-11-13 00:53:05 +0000 | [diff] [blame] | 8287 | /* What insn variants are we supporting today? */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8288 | Bool allow_FP = archinfo->subarch == VexSubArchPPC32_FI || |
| 8289 | archinfo->subarch == VexSubArchPPC32_VFI || |
| 8290 | archinfo->subarch == VexSubArchPPC64_FI || |
| 8291 | archinfo->subarch == VexSubArchPPC64_VFI; |
sewardj | 059601a | 2005-11-13 00:53:05 +0000 | [diff] [blame] | 8292 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8293 | Bool allow_VMX = archinfo->subarch == VexSubArchPPC32_VFI || |
| 8294 | archinfo->subarch == VexSubArchPPC64_VFI; |
sewardj | 059601a | 2005-11-13 00:53:05 +0000 | [diff] [blame] | 8295 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8296 | /* The running delta */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8297 | Long delta = (Long)mkSzAddr(ty, (ULong)delta64); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8298 | |
| 8299 | /* Set result defaults. */ |
| 8300 | dres.whatNext = Dis_Continue; |
| 8301 | dres.len = 0; |
| 8302 | dres.continueAt = 0; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8303 | |
cerion | 1515db9 | 2005-01-25 17:21:23 +0000 | [diff] [blame] | 8304 | /* At least this is simple on PPC32: insns are all 4 bytes long, and |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8305 | 4-aligned. So just fish the whole thing out of memory right now |
| 8306 | and have done. */ |
cerion | cf00446 | 2005-01-31 15:24:55 +0000 | [diff] [blame] | 8307 | theInstr = getUIntBigendianly( (UChar*)(&guest_code[delta]) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8308 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8309 | // vex_printf("insn: 0x%x\n", theInstr); |
| 8310 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8311 | if (mode64) { |
| 8312 | DIP("\t0x%llx: ", guest_CIA_curr_instr); |
| 8313 | } else { |
| 8314 | DIP("\t0x%x: ", (Addr32)guest_CIA_curr_instr); |
| 8315 | } |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8316 | |
| 8317 | /* We may be asked to update the guest CIA before going further. */ |
| 8318 | if (put_IP) |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8319 | putGST( PPC_GST_CIA, mkSzImm(ty, guest_CIA_curr_instr) ); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8320 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8321 | /* Spot the client-request magic sequence. */ |
| 8322 | // Essentially a v. unlikely sequence of noops that we can catch |
| 8323 | { |
sewardj | 2f52de4 | 2005-07-03 01:51:29 +0000 | [diff] [blame] | 8324 | UChar* code = (UChar*)(&guest_code[delta]); |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8325 | |
| 8326 | /* Spot this: |
sewardj | 2f52de4 | 2005-07-03 01:51:29 +0000 | [diff] [blame] | 8327 | 0x7C03D808 tw 0,3,27 => trap word if (0) => nop |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8328 | 0x5400E800 rlwinm 0,0,29,0,0 => r0 = rotl(r0,29) |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8329 | 0x54001800 rlwinm 0,0, 3,0,0 => r0 = rotl(r0, 3) |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8330 | 0x54006800 rlwinm 0,0,13,0,0 => r0 = rotl(r0,13) |
| 8331 | 0x54009800 rlwinm 0,0,19,0,0 => r0 = rotl(r0,19) |
cerion | 0fe6b7e | 2005-06-20 16:28:32 +0000 | [diff] [blame] | 8332 | 0x60000000 nop |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8333 | */ |
sewardj | 2f52de4 | 2005-07-03 01:51:29 +0000 | [diff] [blame] | 8334 | if (getUIntBigendianly(code+ 0) == 0x7C03D808 && |
| 8335 | getUIntBigendianly(code+ 4) == 0x5400E800 && |
| 8336 | getUIntBigendianly(code+ 8) == 0x54001800 && |
| 8337 | getUIntBigendianly(code+12) == 0x54006800 && |
| 8338 | getUIntBigendianly(code+16) == 0x54009800 && |
| 8339 | getUIntBigendianly(code+20) == 0x60000000) { |
cerion | 84ad616 | 2005-06-23 15:25:57 +0000 | [diff] [blame] | 8340 | DIP("%%r3 = client_request ( %%r31 )\n"); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8341 | dres.len = 24; |
cerion | ed623db | 2005-06-20 12:42:04 +0000 | [diff] [blame] | 8342 | delta += 24; |
| 8343 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8344 | irbb->next = mkSzImm( ty, guest_CIA_bbstart + delta ); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8345 | irbb->jumpkind = Ijk_ClientReq; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8346 | dres.whatNext = Dis_StopHere; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8347 | goto decode_success; |
| 8348 | } |
| 8349 | } |
| 8350 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8351 | opc1 = ifieldOPC(theInstr); |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8352 | opc2 = ifieldOPClo10(theInstr); |
cerion | 932ad94 | 2005-01-30 10:18:50 +0000 | [diff] [blame] | 8353 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8354 | // Note: all 'reserved' bits must be cleared, else invalid |
| 8355 | switch (opc1) { |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8356 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8357 | /* Integer Arithmetic Instructions */ |
| 8358 | case 0x0C: case 0x0D: case 0x0E: // addic, addic., addi |
| 8359 | case 0x0F: case 0x07: case 0x08: // addis, mulli, subfic |
| 8360 | if (dis_int_arith( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8361 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8362 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8363 | /* Integer Compare Instructions */ |
| 8364 | case 0x0B: case 0x0A: // cmpi, cmpli |
| 8365 | if (dis_int_cmp( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8366 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8367 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8368 | /* Integer Logical Instructions */ |
| 8369 | case 0x1C: case 0x1D: case 0x18: // andi., andis., ori |
| 8370 | case 0x19: case 0x1A: case 0x1B: // oris, xori, xoris |
| 8371 | if (dis_int_logic( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8372 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8373 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8374 | /* Integer Rotate Instructions */ |
| 8375 | case 0x14: case 0x15: case 0x17: // rlwimi, rlwinm, rlwnm |
| 8376 | if (dis_int_rot( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8377 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8378 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8379 | /* 64bit Integer Rotate Instructions */ |
| 8380 | case 0x1E: // rldcl, rldcr, rldic, rldicl, rldicr, rldimi |
| 8381 | if (dis_int_rot( theInstr )) goto decode_success; |
| 8382 | goto decode_failure; |
| 8383 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8384 | /* Integer Load Instructions */ |
| 8385 | case 0x22: case 0x23: case 0x2A: // lbz, lbzu, lha |
| 8386 | case 0x2B: case 0x28: case 0x29: // lhau, lhz, lhzu |
| 8387 | case 0x20: case 0x21: // lwz, lwzu |
| 8388 | if (dis_int_load( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8389 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8390 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8391 | /* Integer Store Instructions */ |
| 8392 | case 0x26: case 0x27: case 0x2C: // stb, stbu, sth |
| 8393 | case 0x2D: case 0x24: case 0x25: // sthu, stw, stwu |
| 8394 | if (dis_int_store( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8395 | goto decode_failure; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 8396 | |
sewardj | 7787af4 | 2005-08-04 18:32:19 +0000 | [diff] [blame] | 8397 | /* Integer Load and Store Multiple Instructions */ |
| 8398 | case 0x2E: case 0x2F: // lmw, stmw |
| 8399 | if (dis_int_ldst_mult( theInstr )) goto decode_success; |
| 8400 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8401 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8402 | /* Branch Instructions */ |
| 8403 | case 0x12: case 0x10: // b, bc |
sewardj | 9d540e5 | 2005-10-08 11:28:16 +0000 | [diff] [blame] | 8404 | if (dis_branch(theInstr, &dres, resteerOkFn)) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8405 | goto decode_failure; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8406 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8407 | /* System Linkage Instructions */ |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 8408 | case 0x11: // sc |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8409 | if (dis_syslink(theInstr, &dres)) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8410 | goto decode_failure; |
cerion | 26d07b2 | 2005-02-02 17:13:28 +0000 | [diff] [blame] | 8411 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8412 | //zz /* Trap Instructions */ |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8413 | //zz case 0x02: // tdi |
| 8414 | //zz DIP("trap op (tdi) => not implemented\n"); |
| 8415 | //zz goto decode_failure; |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8416 | //zz case 0x03: // twi |
| 8417 | //zz DIP("trap op (twi) => not implemented\n"); |
| 8418 | //zz goto decode_failure; |
cerion | 8c3adda | 2005-01-31 11:54:05 +0000 | [diff] [blame] | 8419 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8420 | /* Floating Point Load Instructions */ |
cerion | 094d139 | 2005-06-20 13:45:57 +0000 | [diff] [blame] | 8421 | case 0x30: case 0x31: case 0x32: // lfs, lfsu, lfd |
| 8422 | case 0x33: // lfdu |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8423 | if (!allow_FP) goto decode_noFP; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8424 | if (dis_fp_load( theInstr )) goto decode_success; |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8425 | goto decode_failure; |
cerion | 995bc36 | 2005-02-03 11:03:31 +0000 | [diff] [blame] | 8426 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8427 | /* Floating Point Store Instructions */ |
| 8428 | case 0x34: case 0x35: case 0x36: // stfsx, stfsux, stfdx |
| 8429 | case 0x37: // stfdux |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8430 | if (!allow_FP) goto decode_noFP; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8431 | if (dis_fp_store( theInstr )) goto decode_success; |
| 8432 | goto decode_failure; |
| 8433 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8434 | /* 64bit Integer Loads */ |
| 8435 | case 0x3A: // ld, ldu, lwa |
| 8436 | if (!mode64) goto decode_failure; |
| 8437 | if (dis_int_load( theInstr )) goto decode_success; |
| 8438 | goto decode_failure; |
| 8439 | |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8440 | case 0x3B: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8441 | if (!allow_FP) goto decode_noFP; |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8442 | |
| 8443 | opc2 = IFIELD(theInstr, 1, 5); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8444 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8445 | /* Floating Point Arith Instructions */ |
| 8446 | case 0x12: case 0x14: case 0x15: // fdivs, fsubs, fadds |
| 8447 | case 0x16: case 0x18: case 0x19: // fsqrts, fres, fmuls |
| 8448 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8449 | goto decode_failure; |
| 8450 | |
| 8451 | /* Floating Point Mult-Add Instructions */ |
| 8452 | case 0x1C: case 0x1D: case 0x1E: // fmsubs, fmadds, fnmsubs |
| 8453 | case 0x1F: // fnmadds |
| 8454 | if (dis_fp_multadd(theInstr)) goto decode_success; |
| 8455 | goto decode_failure; |
| 8456 | |
| 8457 | default: |
| 8458 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8459 | } |
| 8460 | break; |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8461 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8462 | /* 64bit Integer Stores */ |
| 8463 | case 0x3E: // std, stdu |
| 8464 | if (!mode64) goto decode_failure; |
| 8465 | if (dis_int_store( theInstr )) goto decode_success; |
| 8466 | goto decode_failure; |
| 8467 | |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8468 | case 0x3F: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8469 | if (!allow_FP) goto decode_noFP; |
| 8470 | /* Instrs using opc[1:5] never overlap instrs using opc[1:10], |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8471 | so we can simply fall through the first switch statement */ |
| 8472 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8473 | opc2 = IFIELD(theInstr, 1, 5); |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8474 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8475 | /* Floating Point Arith Instructions */ |
| 8476 | case 0x12: case 0x14: case 0x15: // fdiv, fsub, fadd |
| 8477 | case 0x16: case 0x17: case 0x19: // fsqrt, fsel, fmul |
| 8478 | case 0x1A: // frsqrte |
| 8479 | if (dis_fp_arith(theInstr)) goto decode_success; |
| 8480 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8481 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8482 | /* Floating Point Mult-Add Instructions */ |
| 8483 | case 0x1C: case 0x1D: case 0x1E: // fmsub, fmadd, fnmsub |
| 8484 | case 0x1F: // fnmadd |
| 8485 | if (dis_fp_multadd(theInstr)) goto decode_success; |
| 8486 | goto decode_failure; |
| 8487 | |
| 8488 | default: |
| 8489 | break; // Fall through |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8490 | } |
| 8491 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8492 | opc2 = IFIELD(theInstr, 1, 10); |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8493 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8494 | /* Floating Point Compare Instructions */ |
| 8495 | case 0x000: // fcmpu |
| 8496 | case 0x020: // fcmpo |
| 8497 | if (dis_fp_cmp(theInstr)) goto decode_success; |
| 8498 | goto decode_failure; |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8499 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8500 | /* Floating Point Rounding/Conversion Instructions */ |
| 8501 | case 0x00C: // frsp |
| 8502 | case 0x00E: // fctiw |
| 8503 | case 0x00F: // fctiwz |
| 8504 | if (dis_fp_round(theInstr)) goto decode_success; |
| 8505 | goto decode_failure; |
| 8506 | |
| 8507 | /* Floating Point Move Instructions */ |
| 8508 | case 0x028: // fneg |
| 8509 | case 0x048: // fmr |
| 8510 | case 0x088: // fnabs |
| 8511 | case 0x108: // fabs |
| 8512 | if (dis_fp_move( theInstr )) goto decode_success; |
| 8513 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8514 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8515 | /* Floating Point Status/Control Register Instructions */ |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8516 | //zz case 0x026: // mtfsb1 |
| 8517 | //zz case 0x040: // mcrfs |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8518 | case 0x046: // mtfsb0 |
| 8519 | case 0x086: // mtfsfi |
| 8520 | case 0x247: // mffs |
| 8521 | case 0x2C7: // mtfsf |
| 8522 | if (dis_fp_scr( theInstr )) goto decode_success; |
| 8523 | goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8524 | |
| 8525 | /* 64bit FP conversions */ |
| 8526 | case 0x32E: // fctid |
| 8527 | case 0x32F: // fctidz |
| 8528 | case 0x34E: // fcfid |
| 8529 | if (!mode64) goto decode_failure; |
| 8530 | if (dis_fp_round(theInstr)) goto decode_success; |
| 8531 | goto decode_failure; |
| 8532 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8533 | default: |
| 8534 | goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8535 | } |
cerion | 3d870a3 | 2005-03-18 12:23:33 +0000 | [diff] [blame] | 8536 | break; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8537 | |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8538 | case 0x13: |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8539 | switch (opc2) { |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8540 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8541 | /* Condition Register Logical Instructions */ |
| 8542 | case 0x101: case 0x081: case 0x121: // crand, crandc, creqv |
| 8543 | case 0x0E1: case 0x021: case 0x1C1: // crnand, crnor, cror |
| 8544 | case 0x1A1: case 0x0C1: case 0x000: // crorc, crxor, mcrf |
| 8545 | if (dis_cond_logic( theInstr )) goto decode_success; |
| 8546 | goto decode_failure; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8547 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8548 | /* Branch Instructions */ |
| 8549 | case 0x210: case 0x010: // bcctr, bclr |
| 8550 | if (dis_branch(theInstr, &dres, resteerOkFn)) goto decode_success; |
| 8551 | goto decode_failure; |
| 8552 | |
| 8553 | /* Memory Synchronization Instructions */ |
| 8554 | case 0x096: // isync |
| 8555 | if (dis_memsync( theInstr )) goto decode_success; |
| 8556 | goto decode_failure; |
| 8557 | |
| 8558 | default: |
| 8559 | goto decode_failure; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8560 | } |
| 8561 | break; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8562 | |
| 8563 | |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8564 | case 0x1F: |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8565 | |
| 8566 | /* For arith instns, bit10 is the OE flag (overflow enable) */ |
| 8567 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8568 | opc2 = IFIELD(theInstr, 1, 9); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8569 | switch (opc2) { |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8570 | /* Integer Arithmetic Instructions */ |
| 8571 | case 0x10A: case 0x00A: case 0x08A: // add, addc, adde |
| 8572 | case 0x0EA: case 0x0CA: case 0x1EB: // addme, addze, divw |
| 8573 | case 0x1CB: case 0x04B: case 0x00B: // divwu, mulhw, mulhwu |
| 8574 | case 0x0EB: case 0x068: case 0x028: // mullw, neg, subf |
| 8575 | case 0x008: case 0x088: case 0x0E8: // subfc, subfe, subfme |
| 8576 | case 0x0C8: // subfze |
| 8577 | if (dis_int_arith( theInstr )) goto decode_success; |
| 8578 | goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8579 | |
| 8580 | /* 64bit Integer Arithmetic */ |
| 8581 | case 0x009: case 0x049: case 0x0E9: // mulhdu, mulhd, mulld |
| 8582 | case 0x1C9: case 0x1E9: // divdu, divd |
| 8583 | if (!mode64) goto decode_failure; |
| 8584 | if (dis_int_arith( theInstr )) goto decode_success; |
| 8585 | goto decode_failure; |
| 8586 | |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8587 | default: |
| 8588 | break; // Fall through... |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8589 | } |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8590 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8591 | /* All remaining opcodes use full 10 bits. */ |
| 8592 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8593 | opc2 = IFIELD(theInstr, 1, 10); |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8594 | switch (opc2) { |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8595 | /* Integer Compare Instructions */ |
| 8596 | case 0x000: case 0x020: // cmp, cmpl |
| 8597 | if (dis_int_cmp( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8598 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8599 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8600 | /* Integer Logical Instructions */ |
| 8601 | case 0x01C: case 0x03C: case 0x01A: // and, andc, cntlzw |
| 8602 | case 0x11C: case 0x3BA: case 0x39A: // eqv, extsb, extsh |
| 8603 | case 0x1DC: case 0x07C: case 0x1BC: // nand, nor, or |
| 8604 | case 0x19C: case 0x13C: // orc, xor |
| 8605 | if (dis_int_logic( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8606 | goto decode_failure; |
cerion | 932ad94 | 2005-01-30 10:18:50 +0000 | [diff] [blame] | 8607 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8608 | /* 64bit Integer Logical Instructions */ |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 8609 | case 0x3DA: case 0x03A: // extsw, cntlzd |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8610 | if (!mode64) goto decode_failure; |
| 8611 | if (dis_int_logic( theInstr )) goto decode_success; |
| 8612 | goto decode_failure; |
| 8613 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8614 | /* Integer Shift Instructions */ |
| 8615 | case 0x018: case 0x318: case 0x338: // slw, sraw, srawi |
| 8616 | case 0x218: // srw |
| 8617 | if (dis_int_shift( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8618 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8619 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8620 | /* 64bit Integer Shift Instructions */ |
| 8621 | case 0x01B: case 0x31A: // sld, srad |
cerion | 07b07a9 | 2005-12-22 14:32:35 +0000 | [diff] [blame] | 8622 | case 0x33A: case 0x33B: // sradi |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8623 | case 0x21B: // srd |
| 8624 | if (!mode64) goto decode_failure; |
| 8625 | if (dis_int_shift( theInstr )) goto decode_success; |
| 8626 | goto decode_failure; |
| 8627 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8628 | /* Integer Load Instructions */ |
| 8629 | case 0x057: case 0x077: case 0x157: // lbzx, lbzux, lhax |
| 8630 | case 0x177: case 0x117: case 0x137: // lhaux, lhzx, lhzux |
| 8631 | case 0x017: case 0x037: // lwzx, lwzux |
| 8632 | if (dis_int_load( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8633 | goto decode_failure; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8634 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8635 | /* 64bit Integer Load Instructions */ |
| 8636 | case 0x035: case 0x015: // ldux, ldx |
| 8637 | case 0x175: case 0x155: // lwaux, lwax |
| 8638 | if (!mode64) goto decode_failure; |
| 8639 | if (dis_int_load( theInstr )) goto decode_success; |
| 8640 | goto decode_failure; |
| 8641 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8642 | /* Integer Store Instructions */ |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8643 | case 0x0F7: case 0x0D7: case 0x1B7: // stbux, stbx, sthux |
| 8644 | case 0x197: case 0x0B7: case 0x097: // sthx, stwux, stwx |
| 8645 | if (dis_int_store( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8646 | goto decode_failure; |
cerion | 91ad536 | 2005-01-27 23:02:41 +0000 | [diff] [blame] | 8647 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8648 | /* 64bit Integer Store Instructions */ |
| 8649 | case 0x0B5: case 0x095: // stdux, stdx |
| 8650 | if (!mode64) goto decode_failure; |
| 8651 | if (dis_int_store( theInstr )) goto decode_success; |
| 8652 | goto decode_failure; |
| 8653 | |
sewardj | 602857d | 2005-09-06 09:10:09 +0000 | [diff] [blame] | 8654 | /* Integer Load and Store with Byte Reverse Instructions */ |
| 8655 | case 0x316: case 0x216: case 0x396: // lhbrx, lwbrx, sthbrx |
| 8656 | case 0x296: // stwbrx |
| 8657 | if (dis_int_ldst_rev( theInstr )) goto decode_success; |
| 8658 | goto decode_failure; |
| 8659 | |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 8660 | /* Integer Load and Store String Instructions */ |
| 8661 | case 0x255: case 0x215: case 0x2D5: // lswi, lswx, stswi |
| 8662 | case 0x295: { // stswx |
| 8663 | Bool stopHere = False; |
| 8664 | Bool ok = dis_int_ldst_str( theInstr, &stopHere ); |
| 8665 | if (!ok) goto decode_failure; |
| 8666 | if (stopHere) { |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8667 | irbb->next = mkSzImm(ty, nextInsnAddr()); |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 8668 | irbb->jumpkind = Ijk_Boring; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8669 | dres.whatNext = Dis_StopHere; |
sewardj | 87e651f | 2005-09-09 08:31:18 +0000 | [diff] [blame] | 8670 | } |
| 8671 | goto decode_success; |
| 8672 | } |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8673 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8674 | /* Memory Synchronization Instructions */ |
| 8675 | case 0x356: case 0x014: case 0x096: // eieio, lwarx, stwcx. |
| 8676 | case 0x256: // sync |
| 8677 | if (dis_memsync( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8678 | goto decode_failure; |
| 8679 | |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8680 | /* 64bit Memory Synchronization Instructions */ |
| 8681 | case 0x054: case 0x0D6: // ldarx, stdcx. |
| 8682 | if (!mode64) goto decode_failure; |
| 8683 | if (dis_memsync( theInstr )) goto decode_success; |
| 8684 | goto decode_failure; |
| 8685 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8686 | /* Processor Control Instructions */ |
| 8687 | case 0x200: case 0x013: case 0x153: // mcrxr, mfcr, mfspr |
| 8688 | case 0x173: case 0x090: case 0x1D3: // mftb, mtcrf, mtspr |
| 8689 | if (dis_proc_ctl( theInstr )) goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8690 | goto decode_failure; |
cerion | 645c930 | 2005-01-31 10:09:59 +0000 | [diff] [blame] | 8691 | |
cerion | e9d361a | 2005-03-04 17:35:29 +0000 | [diff] [blame] | 8692 | /* Cache Management Instructions */ |
| 8693 | case 0x2F6: case 0x056: case 0x036: // dcba, dcbf, dcbst |
| 8694 | case 0x116: case 0x0F6: case 0x3F6: // dcbt, dcbtst, dcbz |
| 8695 | case 0x3D6: // icbi |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8696 | if (dis_cache_manage( theInstr, &dres, archinfo )) |
sewardj | d94b73a | 2005-06-30 12:08:48 +0000 | [diff] [blame] | 8697 | goto decode_success; |
cerion | b85e8bb | 2005-02-16 08:54:33 +0000 | [diff] [blame] | 8698 | goto decode_failure; |
cerion | d23be4e | 2005-01-31 07:23:07 +0000 | [diff] [blame] | 8699 | |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8700 | //zz /* External Control Instructions */ |
| 8701 | //zz case 0x136: case 0x1B6: // eciwx, ecowx |
| 8702 | //zz DIP("external control op => not implemented\n"); |
| 8703 | //zz goto decode_failure; |
| 8704 | //zz |
| 8705 | //zz /* Trap Instructions */ |
| 8706 | //zz case 0x004: // tw |
| 8707 | //zz DIP("trap op (tw) => not implemented\n"); |
| 8708 | //zz goto decode_failure; |
cerion | f0de28c | 2005-12-13 20:21:11 +0000 | [diff] [blame] | 8709 | //zz case 0x044: // td |
| 8710 | //zz DIP("trap op (td) => not implemented\n"); |
| 8711 | //zz goto decode_failure; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8712 | |
| 8713 | /* Floating Point Load Instructions */ |
| 8714 | case 0x217: case 0x237: case 0x257: // lfsx, lfsux, lfdx |
| 8715 | case 0x277: // lfdux |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8716 | if (!allow_FP) goto decode_noFP; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8717 | if (dis_fp_load( theInstr )) goto decode_success; |
| 8718 | goto decode_failure; |
| 8719 | |
| 8720 | /* Floating Point Store Instructions */ |
| 8721 | case 0x297: case 0x2B7: case 0x2D7: // stfs, stfsu, stfd |
| 8722 | case 0x2F7: case 0x3D7: // stfdu, stfiwx |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8723 | if (!allow_FP) goto decode_noFP; |
sewardj | e14bb9f | 2005-07-22 09:39:02 +0000 | [diff] [blame] | 8724 | if (dis_fp_store( theInstr )) goto decode_success; |
| 8725 | goto decode_failure; |
| 8726 | |
| 8727 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8728 | /* AltiVec instructions */ |
| 8729 | |
| 8730 | /* AV Cache Control - Data streams */ |
| 8731 | case 0x156: case 0x176: case 0x336: // dst, dstst, dss |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8732 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8733 | if (dis_av_datastream( theInstr )) goto decode_success; |
| 8734 | goto decode_failure; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 8735 | |
| 8736 | /* AV Load */ |
| 8737 | case 0x006: case 0x026: // lvsl, lvsr |
| 8738 | case 0x007: case 0x027: case 0x047: // lvebx, lvehx, lvewx |
| 8739 | case 0x067: case 0x167: // lvx, lvxl |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8740 | if (!allow_VMX) goto decode_noVMX; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 8741 | if (dis_av_load( theInstr )) goto decode_success; |
| 8742 | goto decode_failure; |
| 8743 | |
| 8744 | /* AV Store */ |
| 8745 | case 0x087: case 0x0A7: case 0x0C7: // stvebx, stvehx, stvewx |
| 8746 | case 0x0E7: case 0x1E7: // stvx, stvxl |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8747 | if (!allow_VMX) goto decode_noVMX; |
cerion | a982c05 | 2005-06-28 17:23:09 +0000 | [diff] [blame] | 8748 | if (dis_av_store( theInstr )) goto decode_success; |
| 8749 | goto decode_failure; |
| 8750 | |
| 8751 | default: |
| 8752 | goto decode_failure; |
| 8753 | } |
| 8754 | break; |
| 8755 | |
| 8756 | |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8757 | case 0x04: |
| 8758 | /* AltiVec instructions */ |
| 8759 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8760 | opc2 = IFIELD(theInstr, 0, 6); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8761 | switch (opc2) { |
| 8762 | /* AV Mult-Add, Mult-Sum */ |
| 8763 | case 0x20: case 0x21: case 0x22: // vmhaddshs, vmhraddshs, vmladduhm |
| 8764 | case 0x24: case 0x25: case 0x26: // vmsumubm, vmsummbm, vmsumuhm |
| 8765 | case 0x27: case 0x28: case 0x29: // vmsumuhs, vmsumshm, vmsumshs |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8766 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8767 | if (dis_av_multarith( theInstr )) goto decode_success; |
| 8768 | goto decode_failure; |
| 8769 | |
| 8770 | /* AV Permutations */ |
| 8771 | case 0x2A: // vsel |
| 8772 | case 0x2B: // vperm |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8773 | case 0x2C: // vsldoi |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8774 | if (!allow_VMX) goto decode_noVMX; |
cerion | 92d9d87 | 2005-09-15 21:58:50 +0000 | [diff] [blame] | 8775 | if (dis_av_permute( theInstr )) goto decode_success; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8776 | goto decode_failure; |
| 8777 | |
| 8778 | /* AV Floating Point Mult-Add/Sub */ |
| 8779 | case 0x2E: case 0x2F: // vmaddfp, vnmsubfp |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8780 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8781 | if (dis_av_fp_arith( theInstr )) goto decode_success; |
| 8782 | goto decode_failure; |
| 8783 | |
| 8784 | default: |
| 8785 | break; // Fall through... |
| 8786 | } |
| 8787 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8788 | opc2 = IFIELD(theInstr, 0, 11); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8789 | switch (opc2) { |
| 8790 | /* AV Arithmetic */ |
| 8791 | case 0x180: // vaddcuw |
| 8792 | case 0x000: case 0x040: case 0x080: // vaddubm, vadduhm, vadduwm |
| 8793 | case 0x200: case 0x240: case 0x280: // vaddubs, vadduhs, vadduws |
| 8794 | case 0x300: case 0x340: case 0x380: // vaddsbs, vaddshs, vaddsws |
| 8795 | case 0x580: // vsubcuw |
| 8796 | case 0x400: case 0x440: case 0x480: // vsububm, vsubuhm, vsubuwm |
| 8797 | case 0x600: case 0x640: case 0x680: // vsububs, vsubuhs, vsubuws |
| 8798 | case 0x700: case 0x740: case 0x780: // vsubsbs, vsubshs, vsubsws |
| 8799 | case 0x402: case 0x442: case 0x482: // vavgub, vavguh, vavguw |
| 8800 | case 0x502: case 0x542: case 0x582: // vavgsb, vavgsh, vavgsw |
| 8801 | case 0x002: case 0x042: case 0x082: // vmaxub, vmaxuh, vmaxuw |
| 8802 | case 0x102: case 0x142: case 0x182: // vmaxsb, vmaxsh, vmaxsw |
| 8803 | case 0x202: case 0x242: case 0x282: // vminub, vminuh, vminuw |
| 8804 | case 0x302: case 0x342: case 0x382: // vminsb, vminsh, vminsw |
| 8805 | case 0x008: case 0x048: // vmuloub, vmulouh |
| 8806 | case 0x108: case 0x148: // vmulosb, vmulosh |
| 8807 | case 0x208: case 0x248: // vmuleub, vmuleuh |
| 8808 | case 0x308: case 0x348: // vmulesb, vmulesh |
| 8809 | case 0x608: case 0x708: case 0x648: // vsum4ubs, vsum4sbs, vsum4shs |
| 8810 | case 0x688: case 0x788: // vsum2sws, vsumsws |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8811 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8812 | if (dis_av_arith( theInstr )) goto decode_success; |
| 8813 | goto decode_failure; |
| 8814 | |
| 8815 | /* AV Rotate, Shift */ |
| 8816 | case 0x004: case 0x044: case 0x084: // vrlb, vrlh, vrlw |
| 8817 | case 0x104: case 0x144: case 0x184: // vslb, vslh, vslw |
| 8818 | case 0x204: case 0x244: case 0x284: // vsrb, vsrh, vsrw |
| 8819 | case 0x304: case 0x344: case 0x384: // vsrab, vsrah, vsraw |
| 8820 | case 0x1C4: case 0x2C4: // vsl, vsr |
| 8821 | case 0x40C: case 0x44C: // vslo, vsro |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8822 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8823 | if (dis_av_shift( theInstr )) goto decode_success; |
| 8824 | goto decode_failure; |
| 8825 | |
| 8826 | /* AV Logic */ |
| 8827 | case 0x404: case 0x444: case 0x484: // vand, vandc, vor |
| 8828 | case 0x4C4: case 0x504: // vxor, vnor |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8829 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8830 | if (dis_av_logic( theInstr )) goto decode_success; |
| 8831 | goto decode_failure; |
| 8832 | |
| 8833 | /* AV Processor Control */ |
| 8834 | case 0x604: case 0x644: // mfvscr, mtvscr |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8835 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8836 | if (dis_av_procctl( theInstr )) goto decode_success; |
| 8837 | goto decode_failure; |
| 8838 | |
| 8839 | /* AV Floating Point Arithmetic */ |
| 8840 | case 0x00A: case 0x04A: // vaddfp, vsubfp |
| 8841 | case 0x10A: case 0x14A: case 0x18A: // vrefp, vrsqrtefp, vexptefp |
| 8842 | case 0x1CA: // vlogefp |
| 8843 | case 0x40A: case 0x44A: // vmaxfp, vminfp |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8844 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8845 | if (dis_av_fp_arith( theInstr )) goto decode_success; |
| 8846 | goto decode_failure; |
| 8847 | |
| 8848 | /* AV Floating Point Round/Convert */ |
| 8849 | case 0x20A: case 0x24A: case 0x28A: // vrfin, vrfiz, vrfip |
| 8850 | case 0x2CA: // vrfim |
| 8851 | case 0x30A: case 0x34A: case 0x38A: // vcfux, vcfsx, vctuxs |
| 8852 | case 0x3CA: // vctsxs |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8853 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8854 | if (dis_av_fp_convert( theInstr )) goto decode_success; |
| 8855 | goto decode_failure; |
| 8856 | |
| 8857 | /* AV Merge, Splat */ |
| 8858 | case 0x00C: case 0x04C: case 0x08C: // vmrghb, vmrghh, vmrghw |
| 8859 | case 0x10C: case 0x14C: case 0x18C: // vmrglb, vmrglh, vmrglw |
| 8860 | case 0x20C: case 0x24C: case 0x28C: // vspltb, vsplth, vspltw |
| 8861 | case 0x30C: case 0x34C: case 0x38C: // vspltisb, vspltish, vspltisw |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8862 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8863 | if (dis_av_permute( theInstr )) goto decode_success; |
| 8864 | goto decode_failure; |
| 8865 | |
| 8866 | /* AV Pack, Unpack */ |
| 8867 | case 0x00E: case 0x04E: case 0x08E: // vpkuhum, vpkuwum, vpkuhus |
| 8868 | case 0x0CE: // vpkuwus |
| 8869 | case 0x10E: case 0x14E: case 0x18E: // vpkshus, vpkswus, vpkshss |
| 8870 | case 0x1CE: // vpkswss |
| 8871 | case 0x20E: case 0x24E: case 0x28E: // vupkhsb, vupkhsh, vupklsb |
| 8872 | case 0x2CE: // vupklsh |
| 8873 | case 0x30E: case 0x34E: case 0x3CE: // vpkpx, vupkhpx, vupklpx |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8874 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8875 | if (dis_av_pack( theInstr )) goto decode_success; |
| 8876 | goto decode_failure; |
| 8877 | |
| 8878 | default: |
| 8879 | break; // Fall through... |
| 8880 | } |
| 8881 | |
cerion | 76de5cf | 2005-11-18 18:25:12 +0000 | [diff] [blame] | 8882 | opc2 = IFIELD(theInstr, 0, 10); |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8883 | switch (opc2) { |
| 8884 | |
| 8885 | /* AV Compare */ |
| 8886 | case 0x006: case 0x046: case 0x086: // vcmpequb, vcmpequh, vcmpequw |
| 8887 | case 0x206: case 0x246: case 0x286: // vcmpgtub, vcmpgtuh, vcmpgtuw |
| 8888 | case 0x306: case 0x346: case 0x386: // vcmpgtsb, vcmpgtsh, vcmpgtsw |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8889 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8890 | if (dis_av_cmp( theInstr )) goto decode_success; |
| 8891 | goto decode_failure; |
| 8892 | |
| 8893 | /* AV Floating Point Compare */ |
| 8894 | case 0x0C6: case 0x1C6: case 0x2C6: // vcmpeqfp, vcmpgefp, vcmpgtfp |
| 8895 | case 0x3C6: // vcmpbfp |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8896 | if (!allow_VMX) goto decode_noVMX; |
cerion | 32aad40 | 2005-09-10 12:02:24 +0000 | [diff] [blame] | 8897 | if (dis_av_fp_cmp( theInstr )) goto decode_success; |
| 8898 | goto decode_failure; |
| 8899 | |
| 8900 | default: |
| 8901 | goto decode_failure; |
| 8902 | } |
| 8903 | break; |
cerion | 7aa4bbc | 2005-01-29 09:32:07 +0000 | [diff] [blame] | 8904 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8905 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8906 | decode_noFP: |
| 8907 | vassert(!allow_FP); |
| 8908 | vex_printf("disInstr(ppc): Floating Point insns disabled for this arch.\n"); |
| 8909 | goto decode_failure; |
| 8910 | |
| 8911 | decode_noVMX: |
| 8912 | vassert(!allow_VMX); |
| 8913 | vex_printf("disInstr(ppc): AltiVec insns disabled for this arch.\n"); |
| 8914 | goto decode_failure; |
| 8915 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8916 | decode_failure: |
| 8917 | /* All decode failures end up here. */ |
cerion | 225a034 | 2005-09-12 20:49:09 +0000 | [diff] [blame] | 8918 | opc2 = (theInstr) & 0x7FF; |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8919 | vex_printf("disInstr(ppc): unhandled instruction: " |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8920 | "0x%x\n", theInstr); |
sewardj | c7cd214 | 2005-09-09 22:31:49 +0000 | [diff] [blame] | 8921 | vex_printf(" primary %d(0x%x), secondary %u(0x%x)\n", |
sewardj | b51f0f4 | 2005-07-18 11:38:02 +0000 | [diff] [blame] | 8922 | opc1, opc1, opc2, opc2); |
cerion | 995bc36 | 2005-02-03 11:03:31 +0000 | [diff] [blame] | 8923 | |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 8924 | /* Tell the dispatcher that this insn cannot be decoded, and so has |
| 8925 | not been executed, and (is currently) the next to be executed. |
| 8926 | CIA should be up-to-date since it made so at the start of each |
| 8927 | insn, but nevertheless be paranoid and update it again right |
| 8928 | now. */ |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8929 | putGST( PPC_GST_CIA, mkSzImm(ty, guest_CIA_curr_instr) ); |
| 8930 | irbb->next = mkSzImm(ty, guest_CIA_curr_instr); |
sewardj | 01a9e80 | 2005-02-01 20:46:00 +0000 | [diff] [blame] | 8931 | irbb->jumpkind = Ijk_NoDecode; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8932 | dres.whatNext = Dis_StopHere; |
| 8933 | dres.len = 0; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8934 | return dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8935 | |
| 8936 | } /* switch (opc) for the main (primary) opcode switch. */ |
| 8937 | |
| 8938 | decode_success: |
| 8939 | /* All decode successes end up here. */ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8940 | DIP("\n"); |
| 8941 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8942 | dres.len = 4; |
| 8943 | return dres; |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 8944 | } |
| 8945 | |
| 8946 | #undef DIP |
| 8947 | #undef DIS |
| 8948 | |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8949 | |
| 8950 | /*------------------------------------------------------------*/ |
| 8951 | /*--- Top-level fn ---*/ |
| 8952 | /*------------------------------------------------------------*/ |
| 8953 | |
| 8954 | /* Disassemble a single instruction into IR. The instruction |
| 8955 | is located in host memory at &guest_code[delta]. */ |
| 8956 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8957 | DisResult disInstr_PPC ( IRBB* irbb_IN, |
| 8958 | Bool put_IP, |
| 8959 | Bool (*resteerOkFn) ( Addr64 ), |
| 8960 | UChar* guest_code_IN, |
| 8961 | Long delta, |
| 8962 | Addr64 guest_IP, |
| 8963 | VexArchInfo* archinfo, |
| 8964 | Bool host_bigendian_IN ) |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8965 | { |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 8966 | IRType ty; |
| 8967 | DisResult dres; |
| 8968 | VexSubArch gsa = archinfo->subarch; |
| 8969 | |
| 8970 | /* Figure out whether we're being ppc32 or ppc64 today. */ |
| 8971 | switch (gsa) { |
| 8972 | case VexSubArchPPC32_VFI: |
| 8973 | case VexSubArchPPC32_FI: |
| 8974 | case VexSubArchPPC32_I: |
| 8975 | mode64 = False; |
| 8976 | break; |
| 8977 | case VexSubArchPPC64_VFI: |
| 8978 | case VexSubArchPPC64_FI: |
| 8979 | mode64 = True; |
| 8980 | break; |
| 8981 | default: |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8982 | vpanic("disInstr_PPC(): illegal subarch"); |
sewardj | 5df65bb | 2005-11-29 14:47:04 +0000 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | ty = mode64 ? Ity_I64 : Ity_I32; |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8986 | |
| 8987 | /* Set globals (see top of this file) */ |
| 8988 | guest_code = guest_code_IN; |
| 8989 | irbb = irbb_IN; |
| 8990 | host_is_bigendian = host_bigendian_IN; |
cerion | d953ebb | 2005-11-29 13:27:20 +0000 | [diff] [blame] | 8991 | |
cerion | 2831b00 | 2005-11-30 19:55:22 +0000 | [diff] [blame] | 8992 | guest_CIA_curr_instr = mkSzAddr(ty, guest_IP); |
| 8993 | guest_CIA_bbstart = mkSzAddr(ty, guest_IP - delta); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8994 | |
cerion | 5b2325f | 2005-12-23 00:55:09 +0000 | [diff] [blame] | 8995 | dres = disInstr_PPC_WRK ( put_IP, resteerOkFn, |
| 8996 | delta, archinfo ); |
sewardj | 9e6491a | 2005-07-02 19:24:10 +0000 | [diff] [blame] | 8997 | |
| 8998 | return dres; |
| 8999 | } |
| 9000 | |
| 9001 | |
sewardj | c808ef7 | 2005-08-18 11:50:43 +0000 | [diff] [blame] | 9002 | /*------------------------------------------------------------*/ |
| 9003 | /*--- Unused stuff ---*/ |
| 9004 | /*------------------------------------------------------------*/ |
| 9005 | |
| 9006 | ///* A potentially more memcheck-friendly implementation of Clz32, with |
| 9007 | // the boundary case Clz32(0) = 32, which is what ppc requires. */ |
| 9008 | // |
| 9009 | //static IRExpr* /* :: Ity_I32 */ verbose_Clz32 ( IRTemp arg ) |
| 9010 | //{ |
| 9011 | // /* Welcome ... to SSA R Us. */ |
| 9012 | // IRTemp n1 = newTemp(Ity_I32); |
| 9013 | // IRTemp n2 = newTemp(Ity_I32); |
| 9014 | // IRTemp n3 = newTemp(Ity_I32); |
| 9015 | // IRTemp n4 = newTemp(Ity_I32); |
| 9016 | // IRTemp n5 = newTemp(Ity_I32); |
| 9017 | // IRTemp n6 = newTemp(Ity_I32); |
| 9018 | // IRTemp n7 = newTemp(Ity_I32); |
| 9019 | // IRTemp n8 = newTemp(Ity_I32); |
| 9020 | // IRTemp n9 = newTemp(Ity_I32); |
| 9021 | // IRTemp n10 = newTemp(Ity_I32); |
| 9022 | // IRTemp n11 = newTemp(Ity_I32); |
| 9023 | // IRTemp n12 = newTemp(Ity_I32); |
| 9024 | // |
| 9025 | // /* First, propagate the most significant 1-bit into all lower |
| 9026 | // positions in the word. */ |
| 9027 | // /* unsigned int clz ( unsigned int n ) |
| 9028 | // { |
| 9029 | // n |= (n >> 1); |
| 9030 | // n |= (n >> 2); |
| 9031 | // n |= (n >> 4); |
| 9032 | // n |= (n >> 8); |
| 9033 | // n |= (n >> 16); |
| 9034 | // return bitcount(~n); |
| 9035 | // } |
| 9036 | // */ |
| 9037 | // assign(n1, mkexpr(arg)); |
| 9038 | // assign(n2, binop(Iop_Or32, mkexpr(n1), binop(Iop_Shr32, mkexpr(n1), mkU8(1)))); |
| 9039 | // assign(n3, binop(Iop_Or32, mkexpr(n2), binop(Iop_Shr32, mkexpr(n2), mkU8(2)))); |
| 9040 | // assign(n4, binop(Iop_Or32, mkexpr(n3), binop(Iop_Shr32, mkexpr(n3), mkU8(4)))); |
| 9041 | // assign(n5, binop(Iop_Or32, mkexpr(n4), binop(Iop_Shr32, mkexpr(n4), mkU8(8)))); |
| 9042 | // assign(n6, binop(Iop_Or32, mkexpr(n5), binop(Iop_Shr32, mkexpr(n5), mkU8(16)))); |
| 9043 | // /* This gives a word of the form 0---01---1. Now invert it, giving |
| 9044 | // a word of the form 1---10---0, then do a population-count idiom |
| 9045 | // (to count the 1s, which is the number of leading zeroes, or 32 |
| 9046 | // if the original word was 0. */ |
| 9047 | // assign(n7, unop(Iop_Not32, mkexpr(n6))); |
| 9048 | // |
| 9049 | // /* unsigned int bitcount ( unsigned int n ) |
| 9050 | // { |
| 9051 | // n = n - ((n >> 1) & 0x55555555); |
| 9052 | // n = (n & 0x33333333) + ((n >> 2) & 0x33333333); |
| 9053 | // n = (n + (n >> 4)) & 0x0F0F0F0F; |
| 9054 | // n = n + (n >> 8); |
| 9055 | // n = (n + (n >> 16)) & 0x3F; |
| 9056 | // return n; |
| 9057 | // } |
| 9058 | // */ |
| 9059 | // assign(n8, |
| 9060 | // binop(Iop_Sub32, |
| 9061 | // mkexpr(n7), |
| 9062 | // binop(Iop_And32, |
| 9063 | // binop(Iop_Shr32, mkexpr(n7), mkU8(1)), |
| 9064 | // mkU32(0x55555555)))); |
| 9065 | // assign(n9, |
| 9066 | // binop(Iop_Add32, |
| 9067 | // binop(Iop_And32, mkexpr(n8), mkU32(0x33333333)), |
| 9068 | // binop(Iop_And32, |
| 9069 | // binop(Iop_Shr32, mkexpr(n8), mkU8(2)), |
| 9070 | // mkU32(0x33333333)))); |
| 9071 | // assign(n10, |
| 9072 | // binop(Iop_And32, |
| 9073 | // binop(Iop_Add32, |
| 9074 | // mkexpr(n9), |
| 9075 | // binop(Iop_Shr32, mkexpr(n9), mkU8(4))), |
| 9076 | // mkU32(0x0F0F0F0F))); |
| 9077 | // assign(n11, |
| 9078 | // binop(Iop_Add32, |
| 9079 | // mkexpr(n10), |
| 9080 | // binop(Iop_Shr32, mkexpr(n10), mkU8(8)))); |
| 9081 | // assign(n12, |
| 9082 | // binop(Iop_Add32, |
| 9083 | // mkexpr(n11), |
| 9084 | // binop(Iop_Shr32, mkexpr(n11), mkU8(16)))); |
| 9085 | // return |
| 9086 | // binop(Iop_And32, mkexpr(n12), mkU32(0x3F)); |
| 9087 | //} |
| 9088 | |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9089 | /*--------------------------------------------------------------------*/ |
cerion | d0eae2d | 2005-12-23 11:43:01 +0000 | [diff] [blame] | 9090 | /*--- end guest-ppc/toIR.c ---*/ |
cerion | 896a137 | 2005-01-25 12:24:25 +0000 | [diff] [blame] | 9091 | /*--------------------------------------------------------------------*/ |