gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
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
214inline float16_t
215fsgnj16(float16_t a, float16_t b, bool n, bool x) {
216 if (n) b.v = ~b.v;
217 else if (x) b.v = a.v ^ b.v;
218 return f16(insertBits(b.v, 14, 0, a.v));
219}
220
221inline float32_t
222fsgnj32(float32_t a, float32_t b, bool n, bool x) {
223 if (n) b.v = ~b.v;
224 else if (x) b.v = a.v ^ b.v;
225 return f32(insertBits(b.v, 30, 0, a.v));
226}
227
228inline float64_t
229fsgnj64(float64_t a, float64_t b, bool n, bool x) {
230 if (n) b.v = ~b.v;
231 else if (x) b.v = a.v ^ b.v;
232 return f64(insertBits(b.v, 62, 0, a.v));
233}
234
235} // namespace RiscvISA
236} // namespace gem5
237
238#endif // __ARCH_RISCV_REGS_FLOAT_HH__
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
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:79
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition bitfield.hh:185
Bitfield< 31 > n
Bitfield< 7 > b
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
float32_t fsgnj32(float32_t a, float32_t b, bool n, bool x)
Definition float.hh:222
float16_t fsgnj16(float16_t a, float16_t b, bool n, bool x)
Definition float.hh:215
float64_t freg_t
Definition float.hh:69
static constexpr float32_t f32(uint32_t v)
Definition float.hh:98
Bitfield< 6 > a
Definition pagetable.hh:69
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
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
float64_t fsgnj64(float64_t a, float64_t b, bool n, bool x)
Definition float.hh:229
Bitfield< 3 > x
Definition pagetable.hh:73
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
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint16_t RegIndex
Definition types.hh:176
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
constexpr char FloatRegClassName[]
Definition reg_class.hh:76

Generated on Tue Jun 18 2024 16:23:59 for gem5 by doxygen 1.11.0