| | 31 | /* Returns the smallest signed integer in two's complement with the sizeof x */ |
| | 32 | #define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) |
| | 33 | |
| | 34 | /* Checks if a sequence number x is a predecessor/successor of y. |
| | 35 | they handle overflows/underflows and can correctly check for a |
| | 36 | predecessor/successor unless the variable sequence number has grown by |
| | 37 | more then 2**(bitwidth(x)-1)-1. |
| | 38 | This means that for a uint8_t with the maximum value 255, it would think: |
| | 39 | * when adding nothing - it is neither a predecessor nor a successor |
| | 40 | * before adding more than 127 to the starting value - it is a predecessor, |
| | 41 | * when adding 128 - it is neither a predecessor nor a successor, |
| | 42 | * after adding more than 127 to the starting value - it is a successor */ |
| | 43 | #define seq_before(x,y) ({typeof(x) _dummy = (x - y); \ |
| | 44 | _dummy > smallest_signed_int(_dummy); }) |
| | 45 | #define seq_after(x,y) seq_before(y,x) |
| | 46 | |