You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
Get the saturated sum of two unsigned integers @return Returns saturated sum of a+b
*/
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) {
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return -(OPJ_UINT32)(sum >> 32) | (OPJ_UINT32)sum;
}
'opj_uint_adds()' is always the first value of:
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
return a < b ? a : b;
}
This means: the value returned MUST not be negative.
Should the '-' sign in 'opj_uint_adds()' be removed?
winfried
The text was updated successfully, but these errors were encountered:
Strictly C speaking, it's questionable. However, I don't know of any hardware that openjpeg will run on that does not use 2's complement arithmetic.
The high 32 bits part of sum is either 1 or 0 depending on overflow.
If an overflow occurs, -(OPJ_UINT32)(sum >> 32) == (OPJ_UINT32)-1 == UINT32_MAX, that's all ones so once ORed with the low part, it's still UINT32_MAX.
If no overflow occurs, -(OPJ_UINT32)(sum >> 32) == 0, overall result is low part of sum.
'opj_uintmath.h' contains the lines:
/**
Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+b
*/
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) {
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return -(OPJ_UINT32)(sum >> 32) | (OPJ_UINT32)sum;
}
'opj_uint_adds()' is always the first value of:
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
return a < b ? a : b;
}
This means: the value returned MUST not be negative.
Should the '-' sign in 'opj_uint_adds()' be removed?
winfried
The text was updated successfully, but these errors were encountered: