diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2012-04-19 14:01:29 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2012-04-19 14:01:29 -0400 |
commit | 5e053d66e2056a6b818ef62e4c33dcd7c44182e5 (patch) | |
tree | 498562792d961ee5f828b12488d02cddf1e6821f /bits.c | |
parent | 95af9817588787371e8c440aeeec53519737efb6 (diff) | |
download | gpsd-5e053d66e2056a6b818ef62e4c33dcd7c44182e5.tar.gz |
Clean up, since we have good regression tests.
Diffstat (limited to 'bits.c')
-rw-r--r-- | bits.c | 36 |
1 files changed, 3 insertions, 33 deletions
@@ -7,16 +7,14 @@ * a byte index - and width is a bit width. The width is bounded above by * 64 bits. * - * The sbits() function assumes twos-complement arithmetic. + * The sbebits() function assumes twos-complement + * arithmetic. ubebits() and sbebits() assume no padding in + * integers. */ #include <assert.h> #include <stdint.h> #include "bits.h" -#ifdef DEBUG -#include <stdio.h> -#include "gpsd.h" -#endif /* DEBUG */ #define BITS_PER_BYTE 8 @@ -33,33 +31,15 @@ uint64_t ubebits(char buf[], unsigned int start, unsigned int width) fld <<= BITS_PER_BYTE; fld |= (unsigned char)buf[i]; } -#ifdef DEBUG - (void)printf("ubebits: %d:%d from %s:\n", start, width, gpsd_hexdump(buf, 32)); -#endif -#ifdef DEBUG - (void)printf(" segment=0x%llx,", fld); -#endif /* DEBUG */ end = (start + width) % BITS_PER_BYTE; if (end != 0) { fld >>= (BITS_PER_BYTE - end); -#ifdef DEBUG - (void)printf(" after downshifting by %d bits: 0x%llx", - BITS_PER_BYTE - end, fld); -#endif /* UDEBUG */ } -#ifdef DEBUG - (void)printf(" = %lld\n", fld); -#endif /* UDEBUG */ /*@ -shiftimplementation @*/ fld &= ~(-1LL << width); /*@ +shiftimplementation @*/ -#ifdef DEBUG - (void) - printf(" after selecting out the bottom %u bits: 0x%llx = %lld\n", - width, fld, fld); -#endif /* DEBUG */ return fld; } @@ -69,22 +49,12 @@ int64_t sbebits(char buf[], unsigned int start, unsigned int width) { uint64_t fld = ubebits(buf, start, width); -#ifdef __UNUSED_DEBUG__ - (void)fprintf(stderr, "sbebits(%d, %d) extracts %llx\n", start, width, fld); -#endif /* __UNUSED_DEBUG__ */ /*@ +relaxtypes */ if (fld & (1LL << (width - 1))) { -#ifdef __UNUSED_DEBUG__ - (void)fprintf(stderr, "%llx is signed\n", fld); -#endif /* __UNUSED_DEBUG__ */ /*@ -shiftimplementation @*/ fld |= (-1LL << (width - 1)); /*@ +shiftimplementation @*/ } -#ifdef __UNUSED_DEBUG__ - (void)fprintf(stderr, "sbebits(%d, %d) returns %lld\n", start, width, - (int64_t)fld); -#endif /* __UNUSED_DEBUG__ */ return (int64_t)fld; /*@ -relaxtypes */ } |