gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Timothy M. Jones
29  * Korey Sewell
30  */
31 
32 #ifndef __ARCH_POWER_INSTS_FLOATING_HH__
33 #define __ARCH_POWER_INSTS_FLOATING_HH__
34 
36 #include "base/bitfield.hh"
37 #include "base/cprintf.hh"
38 
39 namespace PowerISA
40 {
41 
45 class FloatOp : public PowerStaticInst
46 {
47  protected:
48 
49  bool rcSet;
50 
52  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(Addr pc, const SymbolTable *symtab) const;
149 };
150 
151 } // namespace PowerISA
152 
153 #endif //__ARCH_POWER_INSTS_FLOATING_HH__
FloatOp(const char *mnem, MachInst _machInst, OpClass __opClass)
Constructor.
Definition: floating.hh:52
bool isNan(double val) const
Definition: floating.hh:79
Bitfield< 8 > a
Definition: miscregs.hh:1377
bool isDenormalized(uint32_t val_bits) const
Definition: floating.hh:117
bool isNan(float val) const
Definition: floating.hh:71
bool isNegative(uint32_t val_bits) const
Definition: floating.hh:131
Bitfield< 63 > val
Definition: misc.hh:770
Bitfield< 7 > b
Definition: miscregs.hh:1564
bool isNan(uint64_t val_bits) const
Definition: floating.hh:65
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
Definition: floating.cc:36
uint32_t MachInst
Definition: types.hh:41
bool isInfinity(uint32_t val_bits) const
Definition: floating.hh:102
uint32_t makeCRField(double a, double b) const
Definition: floating.hh:138
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Base class for floating point operations.
Definition: floating.hh:45
bool isNan(uint32_t val_bits) const
Definition: floating.hh:59
Bitfield< 29 > c
Definition: miscregs.hh:1365
bool isZero(uint32_t val_bits) const
Definition: floating.hh:124
bool isSnan(uint32_t val_bits) const
Definition: floating.hh:88
IntReg pc
Definition: remote_gdb.hh:91
bool isNormalized(uint32_t val_bits) const
Definition: floating.hh:109
bool isQnan(uint32_t val_bits) const
Definition: floating.hh:95
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:67

Generated on Fri Jun 9 2017 13:03:40 for gem5 by doxygen 1.8.6