@@ -1249,6 +1249,27 @@ HWY_API V MulByFloorPow2(V v, V exp) {
1249
1249
1250
1250
#endif // HWY_NATIVE_MUL_BY_POW2
1251
1251
1252
+ // ------------------------------ GetBiasedExponent
1253
+ #if (defined(HWY_NATIVE_GET_BIASED_EXPONENT) == defined(HWY_TARGET_TOGGLE))
1254
+ #ifdef HWY_NATIVE_GET_BIASED_EXPONENT
1255
+ #undef HWY_NATIVE_GET_BIASED_EXPONENT
1256
+ #else
1257
+ #define HWY_NATIVE_GET_BIASED_EXPONENT
1258
+ #endif
1259
+
1260
+ template <class V , HWY_IF_FLOAT_V(V)>
1261
+ HWY_API VFromD<RebindToUnsigned<DFromV<V>>> GetBiasedExponent (V v) {
1262
+ using T = TFromV<V>;
1263
+
1264
+ const DFromV<V> d;
1265
+ const RebindToUnsigned<decltype (d)> du;
1266
+
1267
+ constexpr int kNumOfMantBits = MantissaBits<T>();
1268
+ return ShiftRight<kNumOfMantBits >(BitCast (du, Abs (v)));
1269
+ }
1270
+
1271
+ #endif
1272
+
1252
1273
// ------------------------------ GetExponent
1253
1274
1254
1275
#if (defined(HWY_NATIVE_GET_EXPONENT) == defined(HWY_TARGET_TOGGLE))
@@ -1262,14 +1283,12 @@ template <class V, HWY_IF_FLOAT_V(V)>
1262
1283
HWY_API V GetExponent (V v) {
1263
1284
const DFromV<V> d;
1264
1285
using T = TFromV<V>;
1265
- const RebindToUnsigned<decltype (d)> du;
1266
1286
const RebindToSigned<decltype (d)> di;
1267
1287
1268
- constexpr uint8_t mantissa_bits = MantissaBits<T>();
1269
1288
const auto exponent_offset = Set (di, MaxExponentField<T>() >> 1 );
1270
1289
1271
1290
// extract exponent bits as integer
1272
- const auto encoded_exponent = ShiftRight<mantissa_bits>( BitCast (du, Abs (v)) );
1291
+ const auto encoded_exponent = GetBiasedExponent (v );
1273
1292
const auto exponent_int = Sub (BitCast (di, encoded_exponent), exponent_offset);
1274
1293
1275
1294
// convert integer to original type
0 commit comments