floating.hh revision 12616:4b463b4dc098
112244Sgabeblack@google.com/* 212244Sgabeblack@google.com * Copyright (c) 2009 The University of Edinburgh 312244Sgabeblack@google.com * All rights reserved. 412244Sgabeblack@google.com * 512244Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612244Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712244Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812244Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912244Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012244Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112244Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212244Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312244Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412244Sgabeblack@google.com * this software without specific prior written permission. 1512244Sgabeblack@google.com * 1612244Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712244Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812244Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912244Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012244Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112244Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212244Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312244Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412244Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512244Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612244Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712244Sgabeblack@google.com * 2812244Sgabeblack@google.com * Authors: Timothy M. Jones 2912244Sgabeblack@google.com * Korey Sewell 3012244Sgabeblack@google.com */ 3112244Sgabeblack@google.com 3212244Sgabeblack@google.com#ifndef __ARCH_POWER_INSTS_FLOATING_HH__ 3312244Sgabeblack@google.com#define __ARCH_POWER_INSTS_FLOATING_HH__ 3412244Sgabeblack@google.com 3512244Sgabeblack@google.com#include "arch/power/insts/static_inst.hh" 3612244Sgabeblack@google.com#include "base/bitfield.hh" 3712244Sgabeblack@google.com#include "base/cprintf.hh" 3812244Sgabeblack@google.com 3912244Sgabeblack@google.comnamespace PowerISA 4012244Sgabeblack@google.com{ 4112244Sgabeblack@google.com 4212244Sgabeblack@google.com/** 4312244Sgabeblack@google.com * Base class for floating point operations. 4412244Sgabeblack@google.com */ 4512246Sgabeblack@google.comclass FloatOp : public PowerStaticInst 4612246Sgabeblack@google.com{ 4712244Sgabeblack@google.com protected: 4812244Sgabeblack@google.com 4912244Sgabeblack@google.com bool rcSet; 5012246Sgabeblack@google.com 5112246Sgabeblack@google.com /// Constructor 5212246Sgabeblack@google.com FloatOp(const char *mnem, MachInst _machInst, OpClass __opClass) 53 : PowerStaticInst(mnem, _machInst, __opClass) 54 { 55 } 56 57 // Test for NaN (maximum biased exponent & non-zero fraction) 58 inline bool 59 isNan(uint32_t val_bits) const 60 { 61 return ((bits(val_bits, 30, 23) == 0xFF) && bits(val_bits, 22, 0)); 62 } 63 64 inline bool 65 isNan(uint64_t val_bits) const 66 { 67 return ((bits(val_bits, 62, 52) == 0x7FF) && bits(val_bits, 51, 0)); 68 } 69 70 inline bool 71 isNan(float val) const 72 { 73 void *val_ptr = &val; 74 uint32_t val_bits = *(uint32_t *) val_ptr; 75 return isNan(val_bits); 76 } 77 78 inline bool 79 isNan(double val) const 80 { 81 void *val_ptr = &val; 82 uint64_t val_bits = *(uint64_t *) val_ptr; 83 return isNan(val_bits); 84 } 85 86 // Test for SNaN (NaN with high order bit of fraction set to 0) 87 inline bool 88 isSnan(uint32_t val_bits) const 89 { 90 return ((bits(val_bits, 30, 22) == 0x1FE) && bits(val_bits, 22, 0)); 91 } 92 93 // Test for QNaN (NaN with high order bit of fraction set to 1) 94 inline bool 95 isQnan(uint32_t val_bits) const 96 { 97 return (bits(val_bits, 30, 22) == 0x1FF); 98 } 99 100 // Test for infinity (maximum biased exponent and zero fraction) 101 inline bool 102 isInfinity(uint32_t val_bits) const 103 { 104 return ((bits(val_bits, 30, 23) == 0xFF) && !bits(val_bits, 22, 0)); 105 } 106 107 // Test for normalized numbers (biased exponent in the range 1 to 254) 108 inline bool 109 isNormalized(uint32_t val_bits) const 110 { 111 return ((bits(val_bits, 30, 23) != 0xFF) && bits(val_bits, 22, 0)); 112 } 113 114 // Test for denormalized numbers (biased exponent of zero and 115 // non-zero fraction) 116 inline bool 117 isDenormalized(uint32_t val_bits) const 118 { 119 return (!bits(val_bits, 30, 23) && bits(val_bits, 22, 0)); 120 } 121 122 // Test for zero (biased exponent of zero and fraction of zero) 123 inline bool 124 isZero(uint32_t val_bits) const 125 { 126 return (!bits(val_bits, 30, 23) && !bits(val_bits, 22, 0)); 127 } 128 129 // Test for negative 130 inline bool 131 isNegative(uint32_t val_bits) const 132 { 133 return (bits(val_bits, 31)); 134 } 135 136 // Compute the CR field 137 inline uint32_t 138 makeCRField(double a, double b) const 139 { 140 uint32_t c = 0; 141 if (isNan(a) || isNan(b)) { c = 0x1; } 142 else if (a < b) { c = 0x8; } 143 else if (a > b) { c = 0x4; } 144 else { c = 0x2; } 145 return c; 146 } 147 148 std::string generateDisassembly( 149 Addr pc, const SymbolTable *symtab) const override; 150}; 151 152} // namespace PowerISA 153 154#endif //__ARCH_POWER_INSTS_FLOATING_HH__ 155