diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-28 18:16:50 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-28 18:16:50 +0100 |
commit | 32dfcc109c6bb10465015a77b51f06856c2a7d95 (patch) | |
tree | 9e8ae45db386b8a7cdedd8a8ab47153aa7456385 | |
parent | fc81cda96bce85a8cb0a312c724cd144e6375b58 (diff) | |
download | ovm-32dfcc109c6bb10465015a77b51f06856c2a7d95.tar.gz ovm-32dfcc109c6bb10465015a77b51f06856c2a7d95.tar.bz2 ovm-32dfcc109c6bb10465015a77b51f06856c2a7d95.zip |
Added macro to do safe subtractions on a word
Default C just lets overflows occur for subtraction, so this macro
will default to 0 if the subtraction causes an overflow.
-rw-r--r-- | lib/base.h | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -49,9 +49,10 @@ typedef enum DATA_TYPE_WORD, } data_type_t; -#define DBYTE(BYTE) ((data_t){.as_byte = (BYTE)}) -#define DHWORD(HWORD) ((data_t){.as_hword = (HWORD)}) -#define DWORD(WORD) ((data_t){.as_word = (WORD)}) +#define DBYTE(BYTE) ((data_t){.as_byte = (BYTE)}) +#define DHWORD(HWORD) ((data_t){.as_hword = (HWORD)}) +#define DWORD(WORD) ((data_t){.as_word = (WORD)}) +#define WORD_SAFE_SUB(W, SUB) ((W) > (SUB) ? ((W) - (SUB)) : 0) #define HWORD_SIZE sizeof(hword) #define WORD_SIZE sizeof(word) |