gem5 v23.0.0.1
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
60namespace gem5
61{
62
63namespace RiscvISA
64{
65
66/* Conversion functions for working with softfloat. */
67
68// Generic floating point value type.
69using freg_t = float64_t;
70
71// Extract a 16 bit float packed into a 64 bit value.
72static constexpr uint16_t
73unboxF16(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.
83static constexpr uint32_t
84unboxF32(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
93static constexpr uint64_t boxF16(uint16_t v) { return mask(63, 16) | v; }
94static 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.
97static constexpr float16_t f16(uint16_t v) { return {v}; }
98static constexpr float32_t f32(uint32_t v) { return {v}; }
99static constexpr float64_t f64(uint64_t v) { return {v}; }
100static constexpr float16_t f16(freg_t r) { return {unboxF16(r.v)}; }
101static constexpr float32_t f32(freg_t r) { return {unboxF32(r.v)}; }
102static constexpr float64_t f64(freg_t r) { return r; }
103
104// Create generic floating point values from fixed size floats.
105static constexpr freg_t freg(float16_t f) { return {boxF16(f.v)}; }
106static constexpr freg_t freg(float32_t f) { return {boxF32(f.v)}; }
107static constexpr freg_t freg(float64_t f) { return f; }
108static constexpr freg_t freg(uint_fast64_t f) { return {f}; }
109
110namespace float_reg
111{
112
113enum : RegIndex
114{
123
126
135
146
151
152 NumRegs
154
155} // namespace float_reg
156
158 float_reg::NumRegs, debug::FloatRegs);
159
160namespace float_reg
161{
162
163inline 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__
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:93
STL vector class.
Definition stl.hh:37
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
Bitfield< 6 > f
Definition misc_types.hh:68
constexpr RegId Fa0
Definition float.hh:176
constexpr RegId Fs8
Definition float.hh:191
constexpr RegId Ft6
Definition float.hh:170
constexpr RegId Ft4
Definition float.hh:168
constexpr RegId Fs1
Definition float.hh:174
constexpr RegId Ft7
Definition float.hh:171
constexpr RegId Ft2
Definition float.hh:166
constexpr RegId Fa7
Definition float.hh:183
constexpr RegId Fa5
Definition float.hh:181
constexpr RegId Fa6
Definition float.hh:182
constexpr RegId Fs9
Definition float.hh:192
constexpr RegId Fs6
Definition float.hh:189
constexpr RegId Ft11
Definition float.hh:199
constexpr RegId Ft9
Definition float.hh:197
constexpr RegId Fs3
Definition float.hh:186
constexpr RegId Fa1
Definition float.hh:177
const std::vector< std::string > RegNames
Definition float.hh:201
constexpr RegId Ft10
Definition float.hh:198
constexpr RegId Fs5
Definition float.hh:188
constexpr RegId Ft0
Definition float.hh:164
constexpr RegId Fs7
Definition float.hh:190
constexpr RegId Ft1
Definition float.hh:165
constexpr RegId Fa2
Definition float.hh:178
constexpr RegId Fs4
Definition float.hh:187
constexpr RegId Fs0
Definition float.hh:173
constexpr RegId Ft3
Definition float.hh:167
constexpr RegId Fs11
Definition float.hh:194
constexpr RegId Fs10
Definition float.hh:193
constexpr RegId Fa3
Definition float.hh:179
constexpr RegId Ft8
Definition float.hh:196
constexpr RegId Fa4
Definition float.hh:180
constexpr RegId Ft5
Definition float.hh:169
constexpr RegId Fs2
Definition float.hh:185
static constexpr float32_t f32(uint32_t v)
Definition float.hh:98
static constexpr freg_t freg(float16_t f)
Definition float.hh:105
static constexpr float16_t f16(uint16_t v)
Definition float.hh:97
static constexpr uint16_t unboxF16(uint64_t v)
Definition float.hh:73
float64_t freg_t
Definition float.hh:69
static constexpr uint64_t boxF32(uint32_t v)
Definition float.hh:94
Bitfield< 0 > v
Definition pagetable.hh:76
static constexpr uint64_t boxF16(uint16_t v)
Definition float.hh:93
static constexpr float64_t f64(uint64_t v)
Definition float.hh:99
static constexpr uint32_t unboxF32(uint64_t v)
Definition float.hh:84
Bitfield< 1 > r
Definition pagetable.hh:75
constexpr RegClass floatRegClass
Definition float.hh:143
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint16_t RegIndex
Definition types.hh:176
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:61
constexpr char FloatRegClassName[]
Definition reg_class.hh:75

Generated on Mon Jul 10 2023 15:31:59 for gem5 by doxygen 1.9.7