mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-06 16:40:47 +00:00
Fix the logic which determines if the destination Q variable can represent the source Q variable's value with full accuracy.
The new logic is mostly self explanatory except for the value fit checks. If b has fewer integer bits than a, 0 == (Q_GIABSVAL(a) & (~Q_TC(a, 0) << Q_NIBITS(b))) is checking that a's integer value does not have high-order bits set above what b is capable of storing. If b has fewer fractional bits than a, 0 == (Q_GFABSVAL(a) & ~(~Q_TC(a, 0) << (Q_NFBITS(a) - Q_NFBITS(b))))) is checking that a's fractional value does not have low-order bits set below what b is capable of storing. Obtained from: Netflix, Inc. MFC afer: 1 week
This commit is contained in:
parent
2db2566f55
commit
743d4b7cc5
|
@ -1,5 +1,5 @@
|
|||
/*-
|
||||
* Copyright (c) 2018 Netflix, Inc.
|
||||
* Copyright (c) 2018-2024 Netflix, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -378,15 +378,18 @@ typedef u64q_t umaxq_t;
|
|||
#define Q_QMINQ(a, b) (Q_LT(a, b) ? (a) : (b))
|
||||
|
||||
/*
|
||||
* Test if 'a' can be represented by 'b' with full accuracy (T) or not (F).
|
||||
* The type casting has to be done to a's type so that any truncation caused by
|
||||
* the casts will not affect the logic.
|
||||
* Test if 'a' can be represented by 'b' with full accuracy (0) or not
|
||||
* (EOVERFLOW). If 'b' has fewer integer and/or fractional bits than 'a',
|
||||
* the integer and fractional values stored in 'a' must fit in the available
|
||||
* number of integer and fractional bits in 'b'.
|
||||
*/
|
||||
#define Q_QCANREPQ(a, b) \
|
||||
((((Q_LTZ(a) && Q_SIGNED(b)) || !Q_LTZ(a)) && \
|
||||
Q_GIABSVAL(a) <= Q_TC(a, Q_IMAXVAL(b)) && \
|
||||
Q_GFABSVAL(a) <= Q_TC(a, Q_FMAXVAL(b))) ? \
|
||||
0 : EOVERFLOW)
|
||||
#define Q_QCANREPQ(a, b) (( \
|
||||
(!Q_LTZ(a) || Q_SIGNED(b)) \
|
||||
&& ( Q_NIBITS(a) <= Q_NIBITS(b) \
|
||||
|| 0 == (Q_GIABSVAL(a) & (~Q_TC(a, 0) << Q_NIBITS(b)))) \
|
||||
&& ( Q_NFBITS(a) <= Q_NFBITS(b) \
|
||||
|| 0 == (Q_GFABSVAL(a) & ~(~Q_TC(a, 0) << (Q_NFBITS(a) - Q_NFBITS(b))))) \
|
||||
) ? 0 : EOVERFLOW)
|
||||
|
||||
/* Test if raw integer value 'i' can be represented by 'q' (T) or not (F). */
|
||||
#define Q_QCANREPI(q, i) \
|
||||
|
|
Loading…
Reference in a new issue