integer.hh revision 6691
1/* 2 * Copyright (c) 2009 The University of Edinburgh 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Timothy M. Jones 29 */ 30 31#ifndef __ARCH_POWER_INSTS_INTEGER_HH__ 32#define __ARCH_POWER_INSTS_INTEGER_HH__ 33 34#include "arch/power/insts/static_inst.hh" 35#include "base/cprintf.hh" 36#include "base/bitfield.hh" 37 38namespace PowerISA 39{ 40 41/** 42 * We provide a base class for integer operations and then inherit for 43 * several other classes. These specialise for instructions using immediate 44 * values and also rotate instructions. We also need to have versions that 45 * consider the Rc and OE bits. 46 */ 47 48/** 49 * Base class for integer operations. 50 */ 51class IntOp : public PowerStaticInst 52{ 53 protected: 54 55 bool rcSet; 56 bool oeSet; 57 58 // Needed for srawi only 59 uint32_t sh; 60 61 /// Constructor 62 IntOp(const char *mnem, MachInst _machInst, OpClass __opClass) 63 : PowerStaticInst(mnem, _machInst, __opClass), 64 rcSet(false), oeSet(false) 65 { 66 } 67 68 /* Compute the CR (condition register) field using signed comparison */ 69 inline uint32_t 70 makeCRField(int32_t a, int32_t b, uint32_t xerSO) const 71 { 72 uint32_t c = xerSO; 73 74 /* We've pre-shifted the immediate values here */ 75 if (a < b) { c += 0x8; } 76 else if (a > b) { c += 0x4; } 77 else { c += 0x2; } 78 return c; 79 } 80 81 /* Compute the CR (condition register) field using unsigned comparison */ 82 inline uint32_t 83 makeCRField(uint32_t a, uint32_t b, uint32_t xerSO) const 84 { 85 uint32_t c = xerSO; 86 87 /* We've pre-shifted the immediate values here */ 88 if (a < b) { c += 0x8; } 89 else if (a > b) { c += 0x4; } 90 else { c += 0x2; } 91 return c; 92 } 93 94 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 95}; 96 97 98/** 99 * Class for integer immediate (signed and unsigned) operations. 100 */ 101class IntImmOp : public IntOp 102{ 103 protected: 104 105 int32_t imm; 106 uint32_t uimm; 107 108 /// Constructor 109 IntImmOp(const char *mnem, MachInst _machInst, OpClass __opClass) 110 : IntOp(mnem, _machInst, __opClass), 111 imm(sext<16>(machInst.si)), 112 uimm(machInst.si) 113 { 114 } 115 116 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 117}; 118 119 120/** 121 * Class for integer operations with a shift. 122 */ 123class IntShiftOp : public IntOp 124{ 125 protected: 126 127 uint32_t sh; 128 129 /// Constructor 130 IntShiftOp(const char *mnem, MachInst _machInst, OpClass __opClass) 131 : IntOp(mnem, _machInst, __opClass), 132 sh(machInst.sh) 133 { 134 } 135 136 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 137}; 138 139 140/** 141 * Class for integer rotate operations. 142 */ 143class IntRotateOp : public IntShiftOp 144{ 145 protected: 146 147 uint32_t mb; 148 uint32_t me; 149 uint32_t fullMask; 150 151 /// Constructor 152 IntRotateOp(const char *mnem, MachInst _machInst, OpClass __opClass) 153 : IntShiftOp(mnem, _machInst, __opClass), 154 mb(machInst.mb), 155 me(machInst.me) 156 { 157 if (me >= mb) { 158 fullMask = mask(31 - mb, 31 - me); 159 } else { 160 fullMask = ~mask(31 - (me + 1), 31 - (mb - 1)); 161 } 162 } 163 164 uint32_t 165 rotateValue(uint32_t rs, uint32_t shift) const 166 { 167 uint32_t n = shift & 31; 168 return (rs << n) | (rs >> (32 - n)); 169 } 170 171 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 172}; 173 174} // PowerISA namespace 175 176#endif //__ARCH_POWER_INSTS_INTEGER_HH__ 177