-static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) {
- OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
- temp += 4096;
- assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
- assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
- return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ;
+static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b)
+{
+#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
+ OPJ_INT64 temp = __emul(a, b);
+#else
+ OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
+#endif
+ temp += 4096;
+ assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
+ assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF -
+ (OPJ_INT64)1));
+ return (OPJ_INT32)(temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ;
+}
+
+/**
+Addition two signed integers with a wrap-around behaviour.
+Assumes complement-to-two signed integers.
+@param a
+@param b
+@return Returns a + b
+*/
+static INLINE OPJ_INT32 opj_int_add_no_overflow(OPJ_INT32 a, OPJ_INT32 b)
+{
+ void* pa = &a;
+ void* pb = &b;
+ OPJ_UINT32* upa = (OPJ_UINT32*)pa;
+ OPJ_UINT32* upb = (OPJ_UINT32*)pb;
+ OPJ_UINT32 ures = *upa + *upb;
+ void* pures = &ures;
+ OPJ_INT32* ipres = (OPJ_INT32*)pures;
+ return *ipres;
+}
+
+/**
+Subtract two signed integers with a wrap-around behaviour.
+Assumes complement-to-two signed integers.
+@param a
+@param b
+@return Returns a - b
+*/
+static INLINE OPJ_INT32 opj_int_sub_no_overflow(OPJ_INT32 a, OPJ_INT32 b)
+{
+ void* pa = &a;
+ void* pb = &b;
+ OPJ_UINT32* upa = (OPJ_UINT32*)pa;
+ OPJ_UINT32* upb = (OPJ_UINT32*)pb;
+ OPJ_UINT32 ures = *upa - *upb;
+ void* pures = &ures;
+ OPJ_INT32* ipres = (OPJ_INT32*)pures;
+ return *ipres;