23 |
/* |
/* |
24 |
* Integer add with overflow detection. |
* Integer add with overflow detection. |
25 |
*/ |
*/ |
26 |
static IL_INLINE int IAddOvf(ILInt32 *result, ILInt32 a, ILInt32 b) |
static IL_INLINE int IAddOvf(volatile ILInt32 *result, ILInt32 a, ILInt32 b) |
27 |
{ |
{ |
28 |
if(a >= 0 && b >= 0) |
if(a >= 0 && b >= 0) |
29 |
{ |
{ |
43 |
/* |
/* |
44 |
* Unsigned integer add with overflow detection. |
* Unsigned integer add with overflow detection. |
45 |
*/ |
*/ |
46 |
static IL_INLINE int IUAddOvf(ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
static IL_INLINE int IUAddOvf(volatile ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
47 |
{ |
{ |
48 |
return ((*result = a + b) >= a); |
return ((*result = a + b) >= a); |
49 |
} |
} |
51 |
/* |
/* |
52 |
* Integer subtract with overflow detection. |
* Integer subtract with overflow detection. |
53 |
*/ |
*/ |
54 |
static IL_INLINE int ISubOvf(ILInt32 *result, ILInt32 a, ILInt32 b) |
static IL_INLINE int ISubOvf(volatile ILInt32 *result, ILInt32 a, ILInt32 b) |
55 |
{ |
{ |
56 |
if(a >= 0 && b >= 0) |
if(a >= 0 && b >= 0) |
57 |
{ |
{ |
76 |
/* |
/* |
77 |
* Unsigned integer subtract with overflow detection. |
* Unsigned integer subtract with overflow detection. |
78 |
*/ |
*/ |
79 |
static IL_INLINE int IUSubOvf(ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
static IL_INLINE int IUSubOvf(volatile ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
80 |
{ |
{ |
81 |
return ((*result = a - b) <= a); |
return ((*result = a - b) <= a); |
82 |
} |
} |
84 |
/* |
/* |
85 |
* Integer multiply with overflow detection. |
* Integer multiply with overflow detection. |
86 |
*/ |
*/ |
87 |
static IL_INLINE int IMulOvf(ILInt32 *result, ILInt32 a, ILInt32 b) |
static IL_INLINE int IMulOvf(volatile ILInt32 *result, ILInt32 a, ILInt32 b) |
88 |
{ |
{ |
89 |
ILInt64 temp = ((ILInt64)a) * ((ILInt64)b); |
ILInt64 temp = ((ILInt64)a) * ((ILInt64)b); |
90 |
if(temp >= (ILInt64)IL_MIN_INT32 && temp <= (ILInt64)IL_MAX_INT32) |
if(temp >= (ILInt64)IL_MIN_INT32 && temp <= (ILInt64)IL_MAX_INT32) |
101 |
/* |
/* |
102 |
* Unsigned integer multiply with overflow detection. |
* Unsigned integer multiply with overflow detection. |
103 |
*/ |
*/ |
104 |
static IL_INLINE int IUMulOvf(ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
static IL_INLINE int IUMulOvf(volatile ILUInt32 *result, ILUInt32 a, ILUInt32 b) |
105 |
{ |
{ |
106 |
ILUInt64 temp = ((ILUInt64)a) * ((ILUInt64)b); |
ILUInt64 temp = ((ILUInt64)a) * ((ILUInt64)b); |
107 |
if(temp <= (ILUInt64)IL_MAX_UINT32) |
if(temp <= (ILUInt64)IL_MAX_UINT32) |