rcx

library of miscellaneous bits of C code
git clone git://git.rr3.xyz/rcx
Log | Files | Refs | README | LICENSE

commit 131dddce750beae49daa3d26c2057a7caa44eff9
parent 4645170dfe013ea8d59fe588b63d4bb9c6620dce
Author: robert <robertrussell.72001@gmail.com>
Date:   Fri, 19 Aug 2022 19:38:40 -0700

Add {i,u}word typedefs

For the architectures I care about, these are just typedefs to
{,u}intptr_t, but the names {i,u}word document intent better.

These might get removed if I don't end up using them, but I thought I
should add them as an experiment. They probably will at least be useful
as the type of a hash.

Diffstat:
Minc/cext/def.h | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/inc/cext/def.h b/inc/cext/def.h @@ -21,6 +21,18 @@ #define unlikely(x) (x) #endif +/* Here, roughly speaking, "word" means the largest unit that the machine can + * operate on in one instruction (typically the same width as registers and + * the bus). This detection is probably wrong on some weird machines, but this + * is the best we can do in C. */ +#if UINTPTR_MAX == UINT32_MAX +#define WORD_SIZE 4 +#elif UINTPTR_MAX == UINT64_MAX +#define WORD_SIZE 8 +#else /* This won't happen except on weird archs */ +#error "Could not determine machine word size" +#endif + /* Correct the mistakes of whoever named these macros */ #define SHORT_MIN SHRT_MIN #define SHORT_MAX SHRT_MAX @@ -72,6 +84,15 @@ typedef int64_t isize; #error "Could not find suitable type for isize" #endif +#define IWORD_MIN INTPTR_MIN +#define IWORD_MAX INTPTR_MAX +#if WORD_SIZE == 4 +#define IWORD_C INT32_C +#else /* WORD_SIZE == 8 */ +#define IWORD_C INT64_C +#endif +typedef intptr_t iword; + #define U8_MAX UINT8_MAX #define U8_C UINT8_C typedef uint8_t u8; @@ -98,6 +119,14 @@ typedef uintptr_t uptr; #define USIZE_MAX SIZE_MAX typedef size_t usize; +#define UWORD_MAX UINTPTR_MAX +#if WORD_SIZE == 4 +#define UWORD_C UINT32_C +#else /* WORD_SIZE == 8 */ +#define UWORD_C UINT64_C +#endif +typedef uintptr_t uword; + #if !defined(__STRICT_ANSI__) && defined(__SIZEOF_INT128__) #define CEXT_HAVE_128 1