summaryrefslogtreecommitdiff
path: root/silk/MacroDebug.h
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@jmvalin.ca>2012-04-12 16:35:19 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-04-12 16:35:19 -0400
commit94a4989cdbb07e310d3e9486fa3e81a8b2e68bf9 (patch)
treef7a3e81e996f532fbf83e838ffb17cf8b5628794 /silk/MacroDebug.h
parent367c39486618fe6a6f9ffe85e834d59cae241253 (diff)
downloadopus-94a4989cdbb07e310d3e9486fa3e81a8b2e68bf9.tar.gz
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).
Diffstat (limited to 'silk/MacroDebug.h')
-rw-r--r--silk/MacroDebug.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/silk/MacroDebug.h b/silk/MacroDebug.h
index f804902c..e1f4defc 100644
--- a/silk/MacroDebug.h
+++ b/silk/MacroDebug.h
@@ -98,7 +98,7 @@ static inline opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
#undef silk_ADD_SAT32
static inline opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
opus_int32 res;
- res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
+ res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \
((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
silk_assert( res == silk_SAT32( (opus_int64)a32 + (opus_int64)b32 ) );
@@ -133,7 +133,7 @@ static inline opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
#undef silk_SUB_SAT32
static inline opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
opus_int32 res;
- res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
+ res = ((((opus_uint32)(a32)-(opus_uint32)(b32)) & 0x80000000) == 0 ? \
(( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
silk_assert( res == silk_SAT32( (opus_int64)a32 - (opus_int64)b32 ) );