Ring1_Intrinsic_add
Compute the sum of two values detecting numeric overflows.
Ring1_Result
Ring1_Intrinsic_add_suffix
(
type *result,
type x,
type y
)
The following table denotes the valid combinations of suffix and type
suffix |
type |
u8 |
uint8_t |
u16 |
uint16_t |
u32 |
uint32_t |
u64 |
uint64_t |
s8 |
int8_t |
s16 |
int16_t |
s32 |
int32_t |
s64 |
int64_t |
sz |
size_t |
Parameter Variables
x
- The first value aka augend.
y
- The second value aka addend.
result
- A pointer to a variable. For the assigned value see remarks section.
Return Values
Ring1_Result_Success
on success,
Ring1_Result_Failure
on failure.
Post Conditions
If this function fails, then it sets the by-thread status variable.
Below is a list of failure conditions and the status codes indicating them.
Ring1_Status_InvalidArgument
result
wasNULL
.Ring1_Status_NumericOverflow
- a numeric overflow occurred.
Remarks
For the function variants for uintn_t and size_t, the value assigned to the variable are the lower n bits of the mathematical sum of the addend and the augend. (This means x + y is reduced modulo MAX + 1 where MAX is UINTn_MAX or SIZE_MAX, respectively.
For the function variants for intn_t, the value assigned to the variable are the lower n bits of the 2's complements sum of the addend and the augend.
Consequently, these functions can be used to perform safe addition of signed and unsigned integers.