diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-10-12 03:54:29 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-10-12 03:54:29 +0000 |
commit | b305bf616804db7176601bc2acd3495f0217e1c4 (patch) | |
tree | 872d15cd162204ec273199e7d0495bb163daa1b4 | |
parent | 4fa9aa58a926275c2db31a4cc98122e7883c714a (diff) | |
download | skalibs-b305bf616804db7176601bc2acd3495f0217e1c4.tar.gz skalibs-b305bf616804db7176601bc2acd3495f0217e1c4.tar.xz skalibs-b305bf616804db7176601bc2acd3495f0217e1c4.zip |
Add UINT??_BSWAP as constexp macro; rip off typedef uint?? bandaid
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/headers/bits-bendian | 4 | ||||
-rw-r--r-- | src/headers/bits-footer | 2 | ||||
-rw-r--r-- | src/headers/bits-lendian | 5 | ||||
-rw-r--r-- | src/headers/bits-template | 1 | ||||
-rw-r--r-- | src/headers/uint16-bswap | 2 | ||||
-rw-r--r-- | src/headers/uint32-bswap | 2 | ||||
-rw-r--r-- | src/headers/uint64-bswap | 2 | ||||
-rw-r--r-- | src/headers/uint64-include | 1 | ||||
-rw-r--r-- | src/libstddjb/ntp_from_tain.c | 6 | ||||
-rw-r--r-- | src/libstddjb/uint16_bswap.c | 3 | ||||
-rw-r--r-- | src/libstddjb/uint32_bswap.c | 7 | ||||
-rw-r--r-- | src/libstddjb/uint64_bswap.c | 10 | ||||
-rwxr-xr-x | tools/gen-bits.sh | 1 |
14 files changed, 26 insertions, 26 deletions
diff --git a/Makefile b/Makefile index a08f06a..ea0f133 100644 --- a/Makefile +++ b/Makefile @@ -138,13 +138,13 @@ libskarnet.so.xyzzy: $(ALL_DOBJS) src/include/$(package)/sysdeps.h: $(sysdeps)/sysdeps $(sysdeps)/target exec tools/gen-sysdepsh.sh `cat $(sysdeps)/target` < $(sysdeps)/sysdeps > $@ -src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h +src/include/$(package)/uint16.h: $(sysdeps)/sysdeps src/headers/uint16-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h exec tools/gen-bits.sh $(sysdeps)/sysdeps 16 6 7 5 17 > $@ -src/include/$(package)/uint32.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h +src/include/$(package)/uint32.h: $(sysdeps)/sysdeps src/headers/uint32-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-include src/include/$(package)/uint64.h exec tools/gen-bits.sh $(sysdeps)/sysdeps 32 11 13 9 33 > $@ -src/include/$(package)/uint64.h: $(sysdeps)/sysdeps src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-ulong64 src/headers/uint64-noulong64 src/headers/uint64-defs src/headers/uint64-macros +src/include/$(package)/uint64.h: $(sysdeps)/sysdeps src/headers/uint64-bswap src/headers/bits-header src/headers/bits-footer src/headers/bits-lendian src/headers/bits-bendian src/headers/bits-template src/headers/uint64-ulong64 src/headers/uint64-noulong64 src/headers/uint64-defs src/headers/uint64-macros exec tools/gen-bits.sh $(sysdeps)/sysdeps 64 21 25 17 65 > $@ src/include/$(package)/types.h: src/include/$(package)/uint16.h src/include/$(package)/uint32.h src/include/$(package)/uint64.h $(sysdeps)/sysdeps src/headers/types-header src/headers/types-footer src/headers/unsigned-template src/headers/signed-template diff --git a/src/headers/bits-bendian b/src/headers/bits-bendian index ac1169f..19b4bff 100644 --- a/src/headers/bits-bendian +++ b/src/headers/bits-bendian @@ -1,3 +1,7 @@ + +#define UINT@BITS@_LITTLE(u) UINT@BITS@_BSWAP(u) +#define UINT@BITS@_BIG(u) (u) + #define uint@BITS@_little(u) uint@BITS@_bswap(u) #define uint@BITS@_big(u) (u) diff --git a/src/headers/bits-footer b/src/headers/bits-footer index b6f75a9..ddd5dae 100644 --- a/src/headers/bits-footer +++ b/src/headers/bits-footer @@ -1,4 +1,2 @@ -typedef uint@BITS@_t uint@BITS@ ; - #endif diff --git a/src/headers/bits-lendian b/src/headers/bits-lendian index e2358d3..e0017f5 100644 --- a/src/headers/bits-lendian +++ b/src/headers/bits-lendian @@ -1,3 +1,7 @@ + +#define UINT@BITS@_LITTLE(u) (u) +#define UINT@BITS@_BIG(u) UINT@BITS@_BSWAP(u) + #define uint@BITS@_little(u) (u) #define uint@BITS@_big(u) uint@BITS@_bswap(u) @@ -6,4 +10,3 @@ #define uint@BITS@_littlen(array, n) #define uint@BITS@_bign(array, n) uint@BITS@_bswapn(array, n) - diff --git a/src/headers/bits-template b/src/headers/bits-template index 23222d6..f0b71df 100644 --- a/src/headers/bits-template +++ b/src/headers/bits-template @@ -1,3 +1,4 @@ + extern void uint@BITS@_pack (char *, uint@BITS@_t) ; extern void uint@BITS@_pack_big (char *, uint@BITS@_t) ; extern void uint@BITS@_unpack (char const *, uint@BITS@_t *) ; diff --git a/src/headers/uint16-bswap b/src/headers/uint16-bswap new file mode 100644 index 0000000..2bf5c8e --- /dev/null +++ b/src/headers/uint16-bswap @@ -0,0 +1,2 @@ + +#define UINT16_BSWAP(a) (((a) & 0x00ffu) << 8 | ((a) & 0xff00u) >> 8) diff --git a/src/headers/uint32-bswap b/src/headers/uint32-bswap new file mode 100644 index 0000000..4ba4d9b --- /dev/null +++ b/src/headers/uint32-bswap @@ -0,0 +1,2 @@ + +#define UINT32_BSWAP(a) (((a) & 0x000000ffu) << 24 | ((a) & 0x0000ff00u) << 8 | ((a) & 0x00ff0000u) >> 8 | ((a) & 0xff000000u) >> 24) diff --git a/src/headers/uint64-bswap b/src/headers/uint64-bswap new file mode 100644 index 0000000..3ebd512 --- /dev/null +++ b/src/headers/uint64-bswap @@ -0,0 +1,2 @@ + +#define UINT64_BSWAP(a) (((a) & 0x00000000000000ffull) << 56 | ((a) & 0x000000000000ff00ull) << 40 | ((a) & 0x0000000000ff0000ull) << 24 | ((a) & 0x00000000ff000000ull) << 8 | ((a) & 0x000000ff00000000ull) >> 8 | ((a) & 0x0000ff0000000000ull) >> 24 | ((a) & 0x00ff000000000000ull) >> 40 | ((a) & 0xff00000000000000ull) >> 56) diff --git a/src/headers/uint64-include b/src/headers/uint64-include index 12a0936..079bc2d 100644 --- a/src/headers/uint64-include +++ b/src/headers/uint64-include @@ -1 +1,2 @@ + #include <skalibs/uint64.h> diff --git a/src/libstddjb/ntp_from_tain.c b/src/libstddjb/ntp_from_tain.c index 85a338a..5fc0a57 100644 --- a/src/libstddjb/ntp_from_tain.c +++ b/src/libstddjb/ntp_from_tain.c @@ -12,9 +12,9 @@ int ntp_from_tain (uint64_t *u, tain const *a) secs += NTP_OFFSET ; if (secs < TAI_MAGIC + 2147483648UL) goto ifail ; secs -= TAI_MAGIC ; - if (secs >= ((uint64)3 << 31)) goto ifail ; - secs &= (secs < ((uint64)1 << 32)) ? 0xFFFFFFFFUL : 0x7FFFFFFFUL ; - frac = ((uint64)a->nano << 32) / 1000000000UL ; + if (secs >= ((uint64_t)3 << 31)) goto ifail ; + secs &= (secs < ((uint64_t)1 << 32)) ? 0xFFFFFFFFUL : 0x7FFFFFFFUL ; + frac = ((uint64_t)a->nano << 32) / 1000000000UL ; *u = (secs << 32) + frac ; return 1 ; ifail: diff --git a/src/libstddjb/uint16_bswap.c b/src/libstddjb/uint16_bswap.c index 6ab96ed..9cc0df0 100644 --- a/src/libstddjb/uint16_bswap.c +++ b/src/libstddjb/uint16_bswap.c @@ -1,9 +1,8 @@ /* ISC license. */ -#include <stdint.h> #include <skalibs/uint16.h> uint16_t uint16_bswap (uint16_t a) { - return (a & 0x00ffu) << 8 | (a & 0xff00u) >> 8 ; + return UINT16_BSWAP(a) ; } diff --git a/src/libstddjb/uint32_bswap.c b/src/libstddjb/uint32_bswap.c index b9dbcab..5348a5a 100644 --- a/src/libstddjb/uint32_bswap.c +++ b/src/libstddjb/uint32_bswap.c @@ -1,13 +1,8 @@ /* ISC license. */ -#include <stdint.h> #include <skalibs/uint32.h> uint32_t uint32_bswap (uint32_t a) { - return - (a & 0x000000ffu) << 24 | - (a & 0x0000ff00u) << 8 | - (a & 0x00ff0000u) >> 8 | - (a & 0xff000000u) >> 24 ; + return UINT32_BSWAP(a) ; } diff --git a/src/libstddjb/uint64_bswap.c b/src/libstddjb/uint64_bswap.c index 3dfaf18..948d905 100644 --- a/src/libstddjb/uint64_bswap.c +++ b/src/libstddjb/uint64_bswap.c @@ -4,13 +4,5 @@ uint64_t uint64_bswap (uint64_t a) { - return - (a & 0x00000000000000ffull) << 56 | - (a & 0x000000000000ff00ull) << 40 | - (a & 0x0000000000ff0000ull) << 24 | - (a & 0x00000000ff000000ull) << 8 | - (a & 0x000000ff00000000ull) >> 8 | - (a & 0x0000ff0000000000ull) >> 24 | - (a & 0x00ff000000000000ull) >> 40 | - (a & 0xff00000000000000ull) >> 56 ; + return UINT64_BSWAP(a) ; } diff --git a/tools/gen-bits.sh b/tools/gen-bits.sh index 01aa9b8..f406cc3 100755 --- a/tools/gen-bits.sh +++ b/tools/gen-bits.sh @@ -36,6 +36,7 @@ else ./crash fi +cat "src/headers/uint${bits}-bswap" tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-${endian}endian gen_bits "$bits" "$dfmt" "$ofmt" "$xfmt" "$bfmt" exec tools/gen-types-internal.sh "" "" "$bits" < src/headers/bits-footer |