gem5  v20.1.0.0
floating.hh
Go to the documentation of this file.
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 
29 #ifndef __ARCH_POWER_INSTS_FLOATING_HH__
30 #define __ARCH_POWER_INSTS_FLOATING_HH__
31 
33 #include "base/bitfield.hh"
34 #include "base/cprintf.hh"
35 
36 namespace PowerISA
37 {
38 
42 class FloatOp : public PowerStaticInst
43 {
44  protected:
45 
46  bool rcSet;
47 
49  FloatOp(const char *mnem, MachInst _machInst, OpClass __opClass)
50  : PowerStaticInst(mnem, _machInst, __opClass)
51  {
52  }
53 
54  // Test for NaN (maximum biased exponent & non-zero fraction)
55  inline bool
56  isNan(uint32_t val_bits) const
57  {
58  return ((bits(val_bits, 30, 23) == 0xFF) && bits(val_bits, 22, 0));
59  }
60 
61  inline bool
62  isNan(uint64_t val_bits) const
63  {
64  return ((bits(val_bits, 62, 52) == 0x7FF) && bits(val_bits, 51, 0));
65  }
66 
67  inline bool
68  isNan(float val) const
69  {
70  void *val_ptr = &val;
71  uint32_t val_bits = *(uint32_t *) val_ptr;
72  return isNan(val_bits);
73  }
74 
75  inline bool
76  isNan(double val) const
77  {
78  void *val_ptr = &val;
79  uint64_t val_bits = *(uint64_t *) val_ptr;
80  return isNan(val_bits);
81  }
82 
83  // Test for SNaN (NaN with high order bit of fraction set to 0)
84  inline bool
85  isSnan(uint32_t val_bits) const
86  {
87  return ((bits(val_bits, 30, 22) == 0x1FE) && bits(val_bits, 22, 0));
88  }
89 
90  // Test for QNaN (NaN with high order bit of fraction set to 1)
91  inline bool
92  isQnan(uint32_t val_bits) const
93  {
94  return (bits(val_bits, 30, 22) == 0x1FF);
95  }
96 
97  // Test for infinity (maximum biased exponent and zero fraction)
98  inline bool
99  isInfinity(uint32_t val_bits) const
100  {
101  return ((bits(val_bits, 30, 23) == 0xFF) && !bits(val_bits, 22, 0));
102  }
103 
104  // Test for normalized numbers (biased exponent in the range 1 to 254)
105  inline bool
106  isNormalized(uint32_t val_bits) const
107  {
108  return ((bits(val_bits, 30, 23) != 0xFF) && bits(val_bits, 22, 0));
109  }
110 
111  // Test for denormalized numbers (biased exponent of zero and
112  // non-zero fraction)
113  inline bool
114  isDenormalized(uint32_t val_bits) const
115  {
116  return (!bits(val_bits, 30, 23) && bits(val_bits, 22, 0));
117  }
118 
119  // Test for zero (biased exponent of zero and fraction of zero)
120  inline bool
121  isZero(uint32_t val_bits) const
122  {
123  return (!bits(val_bits, 30, 23) && !bits(val_bits, 22, 0));
124  }
125 
126  // Test for negative
127  inline bool
128  isNegative(uint32_t val_bits) const
129  {
130  return (bits(val_bits, 31));
131  }
132 
133  // Compute the CR field
134  inline uint32_t
135  makeCRField(double a, double b) const
136  {
137  uint32_t c = 0;
138  if (isNan(a) || isNan(b)) { c = 0x1; }
139  else if (a < b) { c = 0x8; }
140  else if (a > b) { c = 0x4; }
141  else { c = 0x2; }
142  return c;
143  }
144 
145  std::string generateDisassembly(
146  Addr pc, const Loader::SymbolTable *symtab) const override;
147 };
148 
149 } // namespace PowerISA
150 
151 #endif //__ARCH_POWER_INSTS_FLOATING_HH__
PowerISA::FloatOp::isNormalized
bool isNormalized(uint32_t val_bits) const
Definition: floating.hh:106
PowerISA::FloatOp::rcSet
bool rcSet
Definition: floating.hh:46
PowerISA::FloatOp::isZero
bool isZero(uint32_t val_bits) const
Definition: floating.hh:121
Loader::SymbolTable
Definition: symtab.hh:59
PowerISA::MachInst
uint32_t MachInst
Definition: types.hh:39
PowerISA::FloatOp
Base class for floating point operations.
Definition: floating.hh:42
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
PowerISA::FloatOp::isNegative
bool isNegative(uint32_t val_bits) const
Definition: floating.hh:128
PowerISA
Definition: decoder.cc:31
bitfield.hh
PowerISA::FloatOp::isNan
bool isNan(uint64_t val_bits) const
Definition: floating.hh:62
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
PowerISA::FloatOp::isNan
bool isNan(double val) const
Definition: floating.hh:76
cprintf.hh
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
PowerISA::FloatOp::isQnan
bool isQnan(uint32_t val_bits) const
Definition: floating.hh:92
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
PowerISA::FloatOp::makeCRField
uint32_t makeCRField(double a, double b) const
Definition: floating.hh:135
ArmISA::b
Bitfield< 7 > b
Definition: miscregs_types.hh:376
PowerISA::FloatOp::isNan
bool isNan(uint32_t val_bits) const
Definition: floating.hh:56
PowerISA::FloatOp::FloatOp
FloatOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: floating.hh:49
PowerISA::FloatOp::isNan
bool isNan(float val) const
Definition: floating.hh:68
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
PowerISA::FloatOp::isSnan
bool isSnan(uint32_t val_bits) const
Definition: floating.hh:85
PowerISA::PowerStaticInst
Definition: static_inst.hh:38
PowerISA::FloatOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: floating.cc:34
static_inst.hh
PowerISA::FloatOp::isInfinity
bool isInfinity(uint32_t val_bits) const
Definition: floating.hh:99
PowerISA::FloatOp::isDenormalized
bool isDenormalized(uint32_t val_bits) const
Definition: floating.hh:114
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17