Makes silk_ADD_SAT32() conform to the C standard

This changes the saturation test to ensure that it relies on the
unsigned overflow behaviour (which is allowed) rather than the signed
overflow behaviour (which is undefined).
This commit is contained in:
Jean-Marc Valin 2012-04-12 16:35:19 -04:00
parent 367c394866
commit 94a4989cdb
2 changed files with 4 additions and 4 deletions

View file

@ -68,11 +68,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define silk_SMLAWW(a32, b32, c32) silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16))
/* add/subtract with output saturated */
#define silk_ADD_SAT32(a, b) ((((a) + (b)) & 0x80000000) == 0 ? \
#define silk_ADD_SAT32(a, b) ((((opus_uint32)(a) + (opus_uint32)(b)) & 0x80000000) == 0 ? \
((((a) & (b)) & 0x80000000) != 0 ? silk_int32_MIN : (a)+(b)) : \
((((a) | (b)) & 0x80000000) == 0 ? silk_int32_MAX : (a)+(b)) )
#define silk_SUB_SAT32(a, b) ((((a)-(b)) & 0x80000000) == 0 ? \
#define silk_SUB_SAT32(a, b) ((((opus_uint32)(a)-(opus_uint32)(b)) & 0x80000000) == 0 ? \
(( (a) & ((b)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a)-(b)) : \
((((a)^0x80000000) & (b) & 0x80000000) ? silk_int32_MAX : (a)-(b)) )