@@ -123,9 +123,9 @@ template <typename T> struct FModExceptionalInputHandler {
123
123
" FModCStandardWrapper instantiated with invalid type." );
124
124
125
125
LIBC_INLINE static bool pre_check (T x, T y, T &out) {
126
- using FPB = fputil::FPBits<T>;
127
- const T quiet_nan = FPB ::build_quiet_nan (0 );
128
- FPB sx (x), sy (y);
126
+ using FPBits = fputil::FPBits<T>;
127
+ const T quiet_nan = FPBits ::build_quiet_nan (0 );
128
+ FPBits sx (x), sy (y);
129
129
if (LIBC_LIKELY (!sy.is_zero () && !sy.is_inf_or_nan () &&
130
130
!sx.is_inf_or_nan ())) {
131
131
return false ;
@@ -167,11 +167,11 @@ template <typename T> struct FModFastMathWrapper {
167
167
168
168
template <typename T> class FModDivisionSimpleHelper {
169
169
private:
170
- using intU_t = typename FPBits<T>::UIntType;
170
+ using UIntType = typename FPBits<T>::UIntType;
171
171
172
172
public:
173
- LIBC_INLINE constexpr static intU_t
174
- execute (int exp_diff, int sides_zeroes_count, intU_t m_x, intU_t m_y) {
173
+ LIBC_INLINE constexpr static UIntType
174
+ execute (int exp_diff, int sides_zeroes_count, UIntType m_x, UIntType m_y) {
175
175
while (exp_diff > sides_zeroes_count) {
176
176
exp_diff -= sides_zeroes_count;
177
177
m_x <<= sides_zeroes_count;
@@ -185,24 +185,24 @@ template <typename T> class FModDivisionSimpleHelper {
185
185
186
186
template <typename T> class FModDivisionInvMultHelper {
187
187
private:
188
- using FPB = FPBits<T>;
189
- using intU_t = typename FPB ::UIntType;
188
+ using FPBits = FPBits<T>;
189
+ using UIntType = typename FPBits ::UIntType;
190
190
191
191
public:
192
- LIBC_INLINE constexpr static intU_t
193
- execute (int exp_diff, int sides_zeroes_count, intU_t m_x, intU_t m_y) {
192
+ LIBC_INLINE constexpr static UIntType
193
+ execute (int exp_diff, int sides_zeroes_count, UIntType m_x, UIntType m_y) {
194
194
if (exp_diff > sides_zeroes_count) {
195
- intU_t inv_hy = (cpp::numeric_limits<intU_t >::max () / m_y);
195
+ UIntType inv_hy = (cpp::numeric_limits<UIntType >::max () / m_y);
196
196
while (exp_diff > sides_zeroes_count) {
197
197
exp_diff -= sides_zeroes_count;
198
- intU_t hd =
199
- (m_x * inv_hy) >> (FPB::FloatProp ::BIT_WIDTH - sides_zeroes_count);
198
+ UIntType hd =
199
+ (m_x * inv_hy) >> (FPBits ::BIT_WIDTH - sides_zeroes_count);
200
200
m_x <<= sides_zeroes_count;
201
201
m_x -= hd * m_y;
202
202
while (LIBC_UNLIKELY (m_x > m_y))
203
203
m_x -= m_y;
204
204
}
205
- intU_t hd = (m_x * inv_hy) >> (FPB::FloatProp ::BIT_WIDTH - exp_diff);
205
+ UIntType hd = (m_x * inv_hy) >> (FPBits ::BIT_WIDTH - exp_diff);
206
206
m_x <<= exp_diff;
207
207
m_x -= hd * m_y;
208
208
while (LIBC_UNLIKELY (m_x > m_y))
@@ -222,44 +222,44 @@ class FMod {
222
222
" FMod instantiated with invalid type." );
223
223
224
224
private:
225
- using FPB = FPBits<T>;
226
- using intU_t = typename FPB ::UIntType;
225
+ using FPBits = FPBits<T>;
226
+ using UIntType = typename FPBits ::UIntType;
227
227
228
- LIBC_INLINE static constexpr FPB eval_internal (FPB sx, FPB sy) {
228
+ LIBC_INLINE static constexpr FPBits eval_internal (FPBits sx, FPBits sy) {
229
229
230
230
if (LIBC_LIKELY (sx.uintval () <= sy.uintval ())) {
231
231
if (sx.uintval () < sy.uintval ())
232
- return sx; // |x|<|y| return x
233
- return FPB ( FPB ::zero ()); // |x|=|y| return 0.0
232
+ return sx; // |x|<|y| return x
233
+ return FPBits ( FPBits ::zero ()); // |x|=|y| return 0.0
234
234
}
235
235
236
236
int e_x = sx.get_biased_exponent ();
237
237
int e_y = sy.get_biased_exponent ();
238
238
239
239
// Most common case where |y| is "very normal" and |x/y| < 2^EXPONENT_WIDTH
240
- if (LIBC_LIKELY (e_y > int (FPB::FloatProp ::MANTISSA_WIDTH) &&
241
- e_x - e_y <= int (FPB::FloatProp ::EXPONENT_WIDTH))) {
242
- intU_t m_x = sx.get_explicit_mantissa ();
243
- intU_t m_y = sy.get_explicit_mantissa ();
244
- intU_t d = (e_x == e_y) ? (m_x - m_y) : (m_x << (e_x - e_y)) % m_y;
240
+ if (LIBC_LIKELY (e_y > int (FPBits ::MANTISSA_WIDTH) &&
241
+ e_x - e_y <= int (FPBits ::EXPONENT_WIDTH))) {
242
+ UIntType m_x = sx.get_explicit_mantissa ();
243
+ UIntType m_y = sy.get_explicit_mantissa ();
244
+ UIntType d = (e_x == e_y) ? (m_x - m_y) : (m_x << (e_x - e_y)) % m_y;
245
245
if (d == 0 )
246
- return FPB ( FPB ::zero ());
246
+ return FPBits ( FPBits ::zero ());
247
247
// iy - 1 because of "zero power" for number with power 1
248
- return FPB ::make_value (d, e_y - 1 );
248
+ return FPBits ::make_value (d, e_y - 1 );
249
249
}
250
250
/* Both subnormal special case. */
251
251
if (LIBC_UNLIKELY (e_x == 0 && e_y == 0 )) {
252
- FPB d;
252
+ FPBits d;
253
253
d.set_mantissa (sx.uintval () % sy.uintval ());
254
254
return d;
255
255
}
256
256
257
257
// Note that hx is not subnormal by conditions above.
258
- intU_t m_x = sx.get_explicit_mantissa ();
258
+ UIntType m_x = sx.get_explicit_mantissa ();
259
259
e_x--;
260
260
261
- intU_t m_y = sy.get_explicit_mantissa ();
262
- int lead_zeros_m_y = FPB::FloatProp ::EXPONENT_WIDTH;
261
+ UIntType m_y = sy.get_explicit_mantissa ();
262
+ int lead_zeros_m_y = FPBits ::EXPONENT_WIDTH;
263
263
if (LIBC_LIKELY (e_y > 0 )) {
264
264
e_y--;
265
265
} else {
@@ -282,34 +282,34 @@ class FMod {
282
282
283
283
{
284
284
// Shift hx left until the end or n = 0
285
- int left_shift = exp_diff < int (FPB::FloatProp ::EXPONENT_WIDTH)
285
+ int left_shift = exp_diff < int (FPBits ::EXPONENT_WIDTH)
286
286
? exp_diff
287
- : FPB::FloatProp ::EXPONENT_WIDTH;
287
+ : FPBits ::EXPONENT_WIDTH;
288
288
m_x <<= left_shift;
289
289
exp_diff -= left_shift;
290
290
}
291
291
292
292
m_x %= m_y;
293
293
if (LIBC_UNLIKELY (m_x == 0 ))
294
- return FPB ( FPB ::zero ());
294
+ return FPBits ( FPBits ::zero ());
295
295
296
296
if (exp_diff == 0 )
297
- return FPB ::make_value (m_x, e_y);
297
+ return FPBits ::make_value (m_x, e_y);
298
298
299
299
/* hx next can't be 0, because hx < hy, hy % 2 == 1 hx * 2^i % hy != 0 */
300
300
m_x = DivisionHelper::execute (exp_diff, sides_zeroes_count, m_x, m_y);
301
- return FPB ::make_value (m_x, e_y);
301
+ return FPBits ::make_value (m_x, e_y);
302
302
}
303
303
304
304
public:
305
305
LIBC_INLINE static T eval (T x, T y) {
306
306
if (T out; Wrapper::pre_check (x, y, out))
307
307
return out;
308
- FPB sx (x), sy (y);
308
+ FPBits sx (x), sy (y);
309
309
bool sign = sx.get_sign ();
310
310
sx.set_sign (false );
311
311
sy.set_sign (false );
312
- FPB result = eval_internal (sx, sy);
312
+ FPBits result = eval_internal (sx, sy);
313
313
result.set_sign (sign);
314
314
return result.get_val ();
315
315
}
0 commit comments