@@ -124,6 +124,9 @@ public:
124
124
bfloat16(const bfloat16 &) = default;
125
125
~bfloat16() = default;
126
126
127
+ // Explicit initialization
128
+ static bfloat16 from_bits(const storage_t &a);
129
+
127
130
// Explicit conversion functions
128
131
static storage_t from_float(const float &a);
129
132
static float to_float(const storage_t &a);
@@ -132,15 +135,16 @@ public:
132
135
bfloat16(const float &a);
133
136
bfloat16 &operator=(const float &a);
134
137
135
- // Convert from bfloat16 to float
138
+ // Convert bfloat16 to floating-point types
136
139
operator float() const;
140
+ operator sycl::half() const
137
141
138
- // Get bfloat16 as uint16.
139
- operator storage_t() const;
140
-
141
- // Convert to bool type
142
+ // Convert bfloat16 to bool type
142
143
explicit operator bool();
143
144
145
+ // Get bfloat16 as raw bits.
146
+ storage_t raw() const;
147
+
144
148
friend bfloat16 operator-(bfloat16 &bf) { /* ... */ }
145
149
146
150
// OP is: prefix ++, --
@@ -177,6 +181,9 @@ Table 1. Member functions of `bfloat16` class.
177
181
|===
178
182
| Member Function | Description
179
183
184
+ | `static bfloat16 from_bits(const storage_t &a);`
185
+ | Create `bfloat16` with the `value` equals to `a`.
186
+
180
187
| `static storage_t from_float(const float &a);`
181
188
| Explicitly convert from `float` to `bfloat16`.
182
189
@@ -192,13 +199,16 @@ Table 1. Member functions of `bfloat16` class.
192
199
| `operator float() const;`
193
200
| Return `bfloat16` value converted to `float`.
194
201
195
- | `operator storage_t () const;`
196
- | Return `uint16_t ` value, whose bits represent `bfloat16` value .
202
+ | `operator sycl::half () const;`
203
+ | Return `bfloat16 ` value converted to `sycl::half` .
197
204
198
205
| `explicit operator bool() { /* ... */ }`
199
- | Convert `bfloat16` to `bool` type. Return `false` if the value equals to
206
+ | Convert `bfloat16` to `bool` type. Return `false` if the ` value` equals to
200
207
zero, return `true` otherwise.
201
208
209
+ | `storage_t raw() const`
210
+ | Return raw bits representing the `bfloat16` value.
211
+
202
212
| `friend bfloat16 operator-(bfloat16 &bf) { /* ... */ }`
203
213
| Construct new instance of `bfloat16` class with negated value of the `bf`.
204
214
@@ -329,4 +339,7 @@ None.
329
339
Add operator overloadings +
330
340
Apply code review suggestions
331
341
|3|2021-08-18|Alexey Sotkin |Remove `uint16_t` constructor
342
+ |4|2021-12-30|Alexey Sotkin |Add methods to explicitly set/get the value
343
+ with/as raw bits. +
344
+ Add `operator sycl::half()`
332
345
|========================================
0 commit comments