gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
float.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * Copyright (c) 2014-2015 Sven Karlsson
4  * Copyright (c) 2019 Yifei Liu
5  * Copyright (c) 2020 Barkhausen Institut
6  * Copyright (c) 2021 StreamComputing Corp
7  * All rights reserved
8  *
9  * The license below extends only to copyright in the software and shall
10  * not be construed as granting a license to any other intellectual
11  * property including but not limited to intellectual property relating
12  * to a hardware implementation of the functionality of the software
13  * licensed hereunder. You may use the software subject to the license
14  * terms below provided that you ensure that this notice is replicated
15  * unmodified and in its entirety in all distributions of the software,
16  * modified or unmodified, in source code or in binary form.
17  *
18  * Copyright (c) 2016 RISC-V Foundation
19  * Copyright (c) 2016 The University of Virginia
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are
24  * met: redistributions of source code must retain the above copyright
25  * notice, this list of conditions and the following disclaimer;
26  * redistributions in binary form must reproduce the above copyright
27  * notice, this list of conditions and the following disclaimer in the
28  * documentation and/or other materials provided with the distribution;
29  * neither the name of the copyright holders nor the names of its
30  * contributors may be used to endorse or promote products derived from
31  * this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  */
45 
46 #ifndef __ARCH_RISCV_REGS_FLOAT_HH__
47 #define __ARCH_RISCV_REGS_FLOAT_HH__
48 
49 #include <softfloat.h>
50 #include <specialize.h>
51 
52 #include <cstdint>
53 #include <string>
54 #include <vector>
55 
56 #include "base/bitfield.hh"
57 #include "cpu/reg_class.hh"
58 #include "debug/FloatRegs.hh"
59 
60 namespace gem5
61 {
62 
63 namespace RiscvISA
64 {
65 
66 /* Conversion functions for working with softfloat. */
67 
68 // Generic floating point value type.
69 using freg_t = float64_t;
70 
71 // Extract a 16 bit float packed into a 64 bit value.
72 static constexpr uint16_t
73 unboxF16(uint64_t v)
74 {
75  // The upper 48 bits should all be ones.
76  if (bits(v, 63, 16) == mask(48))
77  return bits(v, 15, 0);
78  else
79  return defaultNaNF16UI;
80 }
81 
82 // Extract a 32 bit float packed into a 64 bit value.
83 static constexpr uint32_t
84 unboxF32(uint64_t v)
85 {
86  // The upper 32 bits should all be ones.
87  if (bits(v, 63, 32) == mask(32))
88  return bits(v, 31, 0);
89  else
90  return defaultNaNF32UI;
91 }
92 
93 static constexpr uint64_t boxF16(uint16_t v) { return mask(63, 16) | v; }
94 static constexpr uint64_t boxF32(uint32_t v) { return mask(63, 32) | v; }
95 
96 // Create fixed size floats from raw bytes or generic floating point values.
97 static constexpr float16_t f16(uint16_t v) { return {v}; }
98 static constexpr float32_t f32(uint32_t v) { return {v}; }
99 static constexpr float64_t f64(uint64_t v) { return {v}; }
100 static constexpr float16_t f16(freg_t r) { return {unboxF16(r.v)}; }
101 static constexpr float32_t f32(freg_t r) { return {unboxF32(r.v)}; }
102 static constexpr float64_t f64(freg_t r) { return r; }
103 
104 // Create generic floating point values from fixed size floats.
105 static constexpr freg_t freg(float16_t f) { return {boxF16(f.v)}; }
106 static constexpr freg_t freg(float32_t f) { return {boxF32(f.v)}; }
107 static constexpr freg_t freg(float64_t f) { return f; }
108 static constexpr freg_t freg(uint_fast64_t f) { return {f}; }
109 
110 namespace float_reg
111 {
112 
113 enum : RegIndex
114 {
123 
126 
135 
146 
151 
153 };
154 
155 } // namespace float_reg
156 
158  float_reg::NumRegs, debug::FloatRegs);
159 
160 namespace float_reg
161 {
162 
163 inline constexpr RegId
172 
175 
184 
195 
200 
202  "ft0", "ft1", "ft2", "ft3",
203  "ft4", "ft5", "ft6", "ft7",
204  "fs0", "fs1", "fa0", "fa1",
205  "fa2", "fa3", "fa4", "fa5",
206  "fa6", "fa7", "fs2", "fs3",
207  "fs4", "fs5", "fs6", "fs7",
208  "fs8", "fs9", "fs10", "fs11",
209  "ft8", "ft9", "ft10", "ft11"
210 };
211 
212 } // namespace float_reg
213 
214 } // namespace RiscvISA
215 } // namespace gem5
216 
217 #endif // __ARCH_RISCV_REGS_FLOAT_HH__
gem5::RiscvISA::float_reg::Ft5
constexpr RegId Ft5
Definition: float.hh:169
gem5::RiscvISA::f32
static constexpr float32_t f32(uint32_t v)
Definition: float.hh:98
gem5::VegaISA::f
Bitfield< 56 > f
Definition: pagetable.hh:53
gem5::RiscvISA::float_reg::Fs4
constexpr RegId Fs4
Definition: float.hh:187
gem5::RiscvISA::float_reg::_Fs11Idx
@ _Fs11Idx
Definition: float.hh:145
gem5::RiscvISA::unboxF32
static constexpr uint32_t unboxF32(uint64_t v)
Definition: float.hh:84
gem5::RiscvISA::float_reg::Fa4
constexpr RegId Fa4
Definition: float.hh:180
gem5::RiscvISA::float_reg::Fa0
constexpr RegId Fa0
Definition: float.hh:176
gem5::RiscvISA::float_reg::_Fa4Idx
@ _Fa4Idx
Definition: float.hh:131
gem5::RiscvISA::float_reg::_Ft8Idx
@ _Ft8Idx
Definition: float.hh:147
gem5::RiscvISA::float_reg::Fs3
constexpr RegId Fs3
Definition: float.hh:186
gem5::RiscvISA::float_reg::Ft4
constexpr RegId Ft4
Definition: float.hh:168
gem5::RiscvISA::float_reg::Fa7
constexpr RegId Fa7
Definition: float.hh:183
gem5::RiscvISA::freg_t
float64_t freg_t
Definition: float.hh:69
gem5::RiscvISA::float_reg::Ft7
constexpr RegId Ft7
Definition: float.hh:171
std::vector< std::string >
gem5::RiscvISA::float_reg::_Fs7Idx
@ _Fs7Idx
Definition: float.hh:141
gem5::RiscvISA::float_reg::_Fs10Idx
@ _Fs10Idx
Definition: float.hh:144
gem5::RiscvISA::float_reg::Ft9
constexpr RegId Ft9
Definition: float.hh:197
gem5::RiscvISA::float_reg::_Fa0Idx
@ _Fa0Idx
Definition: float.hh:127
gem5::RiscvISA::float_reg::_Ft1Idx
@ _Ft1Idx
Definition: float.hh:116
gem5::RiscvISA::float_reg::Ft0
constexpr RegId Ft0
Definition: float.hh:164
gem5::RiscvISA::float_reg::Fs0
constexpr RegId Fs0
Definition: float.hh:173
gem5::FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
gem5::RiscvISA::float_reg::_Fs5Idx
@ _Fs5Idx
Definition: float.hh:139
gem5::RiscvISA::float_reg::_Fs0Idx
@ _Fs0Idx
Definition: float.hh:124
gem5::RiscvISA::float_reg::Ft8
constexpr RegId Ft8
Definition: float.hh:196
gem5::RiscvISA::float_reg::_Fa7Idx
@ _Fa7Idx
Definition: float.hh:134
gem5::RiscvISA::float_reg::Fa5
constexpr RegId Fa5
Definition: float.hh:181
bitfield.hh
gem5::RiscvISA::v
Bitfield< 0 > v
Definition: pagetable.hh:76
gem5::RiscvISA::float_reg::_Ft5Idx
@ _Ft5Idx
Definition: float.hh:120
gem5::RiscvISA::float_reg::Fa1
constexpr RegId Fa1
Definition: float.hh:177
gem5::RiscvISA::f64
static constexpr float64_t f64(uint64_t v)
Definition: float.hh:99
gem5::RiscvISA::float_reg::Ft10
constexpr RegId Ft10
Definition: float.hh:198
gem5::RiscvISA::float_reg::NumRegs
@ NumRegs
Definition: float.hh:152
gem5::RiscvISA::float_reg::Ft1
constexpr RegId Ft1
Definition: float.hh:165
gem5::RiscvISA::float_reg::_Ft9Idx
@ _Ft9Idx
Definition: float.hh:148
gem5::RiscvISA::float_reg::_Fs9Idx
@ _Fs9Idx
Definition: float.hh:143
gem5::bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
gem5::RiscvISA::r
Bitfield< 1 > r
Definition: pagetable.hh:75
gem5::RiscvISA::float_reg::Fs6
constexpr RegId Fs6
Definition: float.hh:189
gem5::RiscvISA::mask
mask
Definition: pra_constants.hh:73
gem5::RiscvISA::float_reg::Fs2
constexpr RegId Fs2
Definition: float.hh:185
gem5::RiscvISA::float_reg::_Ft0Idx
@ _Ft0Idx
Definition: float.hh:115
gem5::RiscvISA::float_reg::_Ft7Idx
@ _Ft7Idx
Definition: float.hh:122
gem5::RiscvISA::float_reg::_Ft2Idx
@ _Ft2Idx
Definition: float.hh:117
gem5::RegClass
Definition: reg_class.hh:184
gem5::RiscvISA::float_reg::_Fs1Idx
@ _Fs1Idx
Definition: float.hh:125
gem5::RiscvISA::float_reg::Fs11
constexpr RegId Fs11
Definition: float.hh:194
gem5::RiscvISA::float_reg::_Ft10Idx
@ _Ft10Idx
Definition: float.hh:149
gem5::RiscvISA::float_reg::Fa3
constexpr RegId Fa3
Definition: float.hh:179
gem5::RiscvISA::unboxF16
static constexpr uint16_t unboxF16(uint64_t v)
Definition: float.hh:73
gem5::RiscvISA::float_reg::_Fs3Idx
@ _Fs3Idx
Definition: float.hh:137
gem5::RiscvISA::float_reg::_Ft6Idx
@ _Ft6Idx
Definition: float.hh:121
gem5::RiscvISA::float_reg::_Fa1Idx
@ _Fa1Idx
Definition: float.hh:128
gem5::RiscvISA::float_reg::_Fs8Idx
@ _Fs8Idx
Definition: float.hh:142
gem5::RiscvISA::float_reg::_Fa6Idx
@ _Fa6Idx
Definition: float.hh:133
gem5::RiscvISA::float_reg::_Ft4Idx
@ _Ft4Idx
Definition: float.hh:119
gem5::RiscvISA::float_reg::_Fs2Idx
@ _Fs2Idx
Definition: float.hh:136
gem5::RiscvISA::float_reg::_Ft3Idx
@ _Ft3Idx
Definition: float.hh:118
gem5::RiscvISA::float_reg::Ft11
constexpr RegId Ft11
Definition: float.hh:199
gem5::RiscvISA::float_reg::Ft6
constexpr RegId Ft6
Definition: float.hh:170
gem5::RiscvISA::float_reg::Ft2
constexpr RegId Ft2
Definition: float.hh:166
gem5::RiscvISA::float_reg::_Fa5Idx
@ _Fa5Idx
Definition: float.hh:132
gem5::RiscvISA::float_reg::_Fa3Idx
@ _Fa3Idx
Definition: float.hh:130
gem5::RiscvISA::float_reg::Fs1
constexpr RegId Fs1
Definition: float.hh:174
reg_class.hh
gem5::RiscvISA::float_reg::_Fs4Idx
@ _Fs4Idx
Definition: float.hh:138
gem5::RiscvISA::boxF16
static constexpr uint64_t boxF16(uint16_t v)
Definition: float.hh:93
gem5::RiscvISA::boxF32
static constexpr uint64_t boxF32(uint32_t v)
Definition: float.hh:94
gem5::RiscvISA::float_reg::_Fa2Idx
@ _Fa2Idx
Definition: float.hh:129
gem5::RiscvISA::float_reg::Fa2
constexpr RegId Fa2
Definition: float.hh:178
gem5::RegIndex
uint16_t RegIndex
Definition: types.hh:176
gem5::RiscvISA::float_reg::_Ft11Idx
@ _Ft11Idx
Definition: float.hh:150
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::RiscvISA::floatRegClass
constexpr RegClass floatRegClass(FloatRegClass, FloatRegClassName, float_reg::NumRegs, debug::FloatRegs)
gem5::RiscvISA::float_reg::_Fs6Idx
@ _Fs6Idx
Definition: float.hh:140
gem5::RiscvISA::freg
static constexpr freg_t freg(float16_t f)
Definition: float.hh:105
gem5::FloatRegClassName
constexpr char FloatRegClassName[]
Definition: reg_class.hh:75
gem5::RiscvISA::float_reg::RegNames
const std::vector< std::string > RegNames
Definition: float.hh:201
gem5::RiscvISA::f16
static constexpr float16_t f16(uint16_t v)
Definition: float.hh:97
gem5::RiscvISA::float_reg::Ft3
constexpr RegId Ft3
Definition: float.hh:167
gem5::RiscvISA::float_reg::Fa6
constexpr RegId Fa6
Definition: float.hh:182
gem5::RiscvISA::float_reg::Fs7
constexpr RegId Fs7
Definition: float.hh:190
gem5::RiscvISA::float_reg::Fs10
constexpr RegId Fs10
Definition: float.hh:193
gem5::RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:92
gem5::RiscvISA::float_reg::Fs8
constexpr RegId Fs8
Definition: float.hh:191
gem5::RiscvISA::float_reg::Fs9
constexpr RegId Fs9
Definition: float.hh:192
gem5::RiscvISA::float_reg::Fs5
constexpr RegId Fs5
Definition: float.hh:188

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17