gem5  v20.1.0.0
utility.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 MIPS Technologies, Inc.
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 #include "arch/mips/utility.hh"
30 
31 #include <cmath>
32 
33 #include "arch/mips/isa_traits.hh"
34 #include "arch/mips/registers.hh"
35 #include "base/bitfield.hh"
36 #include "base/logging.hh"
37 #include "cpu/static_inst.hh"
38 #include "cpu/thread_context.hh"
39 #include "sim/serialize.hh"
40 
41 using namespace MipsISA;
42 using namespace std;
43 
44 namespace MipsISA {
45 
46 uint64_t
47 getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
48 {
49  panic("getArgument() not implemented\n");
50  M5_DUMMY_RETURN
51 }
52 
53 uint64_t
54 fpConvert(ConvertType cvt_type, double fp_val)
55 {
56 
57  switch (cvt_type)
58  {
59  case SINGLE_TO_DOUBLE:
60  {
61  double sdouble_val = fp_val;
62  void *sdouble_ptr = &sdouble_val;
63  uint64_t sdp_bits = *(uint64_t *) sdouble_ptr;
64  return sdp_bits;
65  }
66 
67  case SINGLE_TO_WORD:
68  {
69  int32_t sword_val = (int32_t) fp_val;
70  void *sword_ptr = &sword_val;
71  uint64_t sword_bits= *(uint32_t *) sword_ptr;
72  return sword_bits;
73  }
74 
75  case WORD_TO_SINGLE:
76  {
77  float wfloat_val = fp_val;
78  void *wfloat_ptr = &wfloat_val;
79  uint64_t wfloat_bits = *(uint32_t *) wfloat_ptr;
80  return wfloat_bits;
81  }
82 
83  case WORD_TO_DOUBLE:
84  {
85  double wdouble_val = fp_val;
86  void *wdouble_ptr = &wdouble_val;
87  uint64_t wdp_bits = *(uint64_t *) wdouble_ptr;
88  return wdp_bits;
89  }
90 
91  default:
92  panic("Invalid Floating Point Conversion Type (%d). See \"types.hh\" for List of Conversions\n",cvt_type);
93  return 0;
94  }
95 }
96 
97 double
98 roundFP(double val, int digits)
99 {
100  double digit_offset = pow(10.0,digits);
101  val = val * digit_offset;
102  val = val + 0.5;
103  val = floor(val);
104  val = val / digit_offset;
105  return val;
106 }
107 
108 double
109 truncFP(double val)
110 {
111  int trunc_val = (int) val;
112  return (double) trunc_val;
113 }
114 
115 bool
116 getCondCode(uint32_t fcsr, int cc_idx)
117 {
118  int shift = (cc_idx == 0) ? 23 : cc_idx + 24;
119  bool cc_val = (fcsr >> shift) & 0x00000001;
120  return cc_val;
121 }
122 
123 uint32_t
124 genCCVector(uint32_t fcsr, int cc_num, uint32_t cc_val)
125 {
126  int cc_idx = (cc_num == 0) ? 23 : cc_num + 24;
127 
128  fcsr = bits(fcsr, 31, cc_idx + 1) << (cc_idx + 1) |
129  cc_val << cc_idx |
130  bits(fcsr, cc_idx - 1, 0);
131 
132  return fcsr;
133 }
134 
135 uint32_t
136 genInvalidVector(uint32_t fcsr_bits)
137 {
138  //Set FCSR invalid in "flag" field
139  int invalid_offset = Invalid + Flag_Field;
140  fcsr_bits = fcsr_bits | (1 << invalid_offset);
141 
142  //Set FCSR invalid in "cause" flag
143  int cause_offset = Invalid + Cause_Field;
144  fcsr_bits = fcsr_bits | (1 << cause_offset);
145 
146  return fcsr_bits;
147 }
148 
149 bool
150 isNan(void *val_ptr, int size)
151 {
152  switch (size)
153  {
154  case 32:
155  {
156  uint32_t val_bits = *(uint32_t *) val_ptr;
157  return (bits(val_bits, 30, 23) == 0xFF);
158  }
159 
160  case 64:
161  {
162  uint64_t val_bits = *(uint64_t *) val_ptr;
163  return (bits(val_bits, 62, 52) == 0x7FF);
164  }
165 
166  default:
167  panic("Type unsupported. Size mismatch\n");
168  }
169 }
170 
171 
172 bool
173 isQnan(void *val_ptr, int size)
174 {
175  switch (size)
176  {
177  case 32:
178  {
179  uint32_t val_bits = *(uint32_t *) val_ptr;
180  return (bits(val_bits, 30, 22) == 0x1FE);
181  }
182 
183  case 64:
184  {
185  uint64_t val_bits = *(uint64_t *) val_ptr;
186  return (bits(val_bits, 62, 51) == 0xFFE);
187  }
188 
189  default:
190  panic("Type unsupported. Size mismatch\n");
191  }
192 }
193 
194 bool
195 isSnan(void *val_ptr, int size)
196 {
197  switch (size)
198  {
199  case 32:
200  {
201  uint32_t val_bits = *(uint32_t *) val_ptr;
202  return (bits(val_bits, 30, 22) == 0x1FF);
203  }
204 
205  case 64:
206  {
207  uint64_t val_bits = *(uint64_t *) val_ptr;
208  return (bits(val_bits, 62, 51) == 0xFFF);
209  }
210 
211  default:
212  panic("Type unsupported. Size mismatch\n");
213  }
214 }
215 
216 void
218 {
219  // First loop through the integer registers.
220  for (int i = 0; i < NumIntRegs; i++)
221  dest->setIntRegFlat(i, src->readIntRegFlat(i));
222 
223  // Then loop through the floating point registers.
224  for (int i = 0; i < NumFloatRegs; i++)
225  dest->setFloatRegFlat(i, src->readFloatRegFlat(i));
226 
227  // Would need to add condition-code regs if implemented
228  assert(NumCCRegs == 0);
229 
230  // Copy misc. registers
231  for (int i = 0; i < NumMiscRegs; i++)
233 
234  // Copy over the PC State
235  dest->pcState(src->pcState());
236 }
237 
238 void
240 {
241  panic("Copy Misc. Regs Not Implemented Yet\n");
242 }
243 
244 } // namespace MipsISA
ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
ThreadContext::readIntRegFlat
virtual RegVal readIntRegFlat(RegIndex idx) const =0
Flat register interfaces.
MipsISA::genCCVector
uint32_t genCCVector(uint32_t fcsr, int cc_num, uint32_t cc_val)
Definition: utility.cc:124
MipsISA::truncFP
double truncFP(double val)
Definition: utility.cc:109
serialize.hh
registers.hh
MipsISA::NumIntRegs
const int NumIntRegs
Definition: registers.hh:55
MipsISA::NumCCRegs
const int NumCCRegs
Definition: registers.hh:61
MipsISA::WORD_TO_DOUBLE
@ WORD_TO_DOUBLE
Definition: types.hh:59
MipsISA::Cause_Field
@ Cause_Field
Definition: registers.hh:86
MipsISA::SINGLE_TO_DOUBLE
@ SINGLE_TO_DOUBLE
Definition: types.hh:45
MipsISA::roundFP
double roundFP(double val, int digits)
Definition: utility.cc:98
ThreadContext::setFloatRegFlat
virtual void setFloatRegFlat(RegIndex idx, RegVal val)=0
MipsISA
Definition: decoder.cc:31
MipsISA::fp
Bitfield< 0 > fp
Definition: pra_constants.hh:244
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
bitfield.hh
ArmISA::shift
Bitfield< 6, 5 > shift
Definition: types.hh:126
ThreadContext::setIntRegFlat
virtual void setIntRegFlat(RegIndex idx, RegVal val)=0
MipsISA::fpConvert
uint64_t fpConvert(ConvertType cvt_type, double fp_val)
Definition: utility.cc:54
MipsISA::WORD_TO_SINGLE
@ WORD_TO_SINGLE
Definition: types.hh:58
MipsISA::isNan
bool isNan(void *val_ptr, int size)
Definition: utility.cc:150
utility.hh
static_inst.hh
ThreadContext::readFloatRegFlat
virtual RegVal readFloatRegFlat(RegIndex idx) const =0
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
MipsISA::NumFloatRegs
const int NumFloatRegs
Definition: registers.hh:56
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
MipsISA::Invalid
@ Invalid
Definition: registers.hh:79
MipsISA::SINGLE_TO_WORD
@ SINGLE_TO_WORD
Definition: types.hh:46
MipsISA::i
Bitfield< 2 > i
Definition: pra_constants.hh:276
MipsISA::NumMiscRegs
const int NumMiscRegs
Definition: registers.hh:280
MipsISA::ConvertType
ConvertType
Definition: types.hh:44
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
MipsISA::getCondCode
bool getCondCode(uint32_t fcsr, int cc_idx)
Definition: utility.cc:116
MipsISA::getArgument
uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
Definition: utility.cc:47
MipsISA::copyMiscRegs
void copyMiscRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:239
MipsISA::copyRegs
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:217
logging.hh
isa_traits.hh
MipsISA::isQnan
bool isQnan(void *val_ptr, int size)
Definition: utility.cc:173
ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
MipsISA::isSnan
bool isSnan(void *val_ptr, int size)
Definition: utility.cc:195
MipsISA::Flag_Field
@ Flag_Field
Definition: registers.hh:84
thread_context.hh
MipsISA::genInvalidVector
uint32_t genInvalidVector(uint32_t fcsr_bits)
Definition: utility.cc:136
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
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:01 for gem5 by doxygen 1.8.17