X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Futil.c;h=984ab45708e0abe331f43569b771f2e4f947cfc9;hb=5054d6fd32d5dd3354c1aed1bfa9fb2b7979324e;hp=76f4cd6a06d3b25fb4d6ec32b5778c328dbb610e;hpb=8c9479030386430afd781bba4b926b177ffeac63;p=sliver-openvswitch.git diff --git a/lib/util.c b/lib/util.c index 76f4cd6a0..984ab4570 100644 --- a/lib/util.c +++ b/lib/util.c @@ -67,7 +67,7 @@ ovs_assert_failure(const char *where, const char *function, case 0: VLOG_ABORT("%s: assertion %s failed in %s()", where, condition, function); - NOT_REACHED(); + OVS_NOT_REACHED(); case 1: fprintf(stderr, "%s: assertion %s failed in %s()", @@ -537,24 +537,6 @@ str_to_llong(const char *s, int base, long long *x) } } -bool -str_to_uint(const char *s, int base, unsigned int *u) -{ - return str_to_int(s, base, (int *) u); -} - -bool -str_to_ulong(const char *s, int base, unsigned long *ul) -{ - return str_to_long(s, base, (long *) ul); -} - -bool -str_to_ullong(const char *s, int base, unsigned long long *ull) -{ - return str_to_llong(s, base, (long long *) ull); -} - /* Converts floating-point string 's' into a double. If successful, stores * the double in '*d' and returns true; on failure, stores 0 in '*d' and * returns false. @@ -901,14 +883,7 @@ raw_clz64(uint64_t n) } #endif -/* Returns the number of 1-bits in 'x', between 0 and 32 inclusive. */ -static unsigned int -count_1bits_32(uint32_t x) -{ - /* In my testing, this implementation is over twice as fast as any other - * portable implementation that I tried, including GCC 4.4 - * __builtin_popcount(), although nonportable asm("popcnt") was over 50% - * faster. */ +#if NEED_COUNT_1BITS_8 #define INIT1(X) \ ((((X) & (1 << 0)) != 0) + \ (((X) & (1 << 1)) != 0) + \ @@ -925,22 +900,10 @@ count_1bits_32(uint32_t x) #define INIT32(X) INIT16(X), INIT16((X) + 16) #define INIT64(X) INIT32(X), INIT32((X) + 32) - static const uint8_t count_1bits_8[256] = { - INIT64(0), INIT64(64), INIT64(128), INIT64(192) - }; - - return (count_1bits_8[x & 0xff] + - count_1bits_8[(x >> 8) & 0xff] + - count_1bits_8[(x >> 16) & 0xff] + - count_1bits_8[x >> 24]); -} - -/* Returns the number of 1-bits in 'x', between 0 and 64 inclusive. */ -unsigned int -count_1bits(uint64_t x) -{ - return count_1bits_32(x) + count_1bits_32(x >> 32); -} +const uint8_t count_1bits_8[256] = { + INIT64(0), INIT64(64), INIT64(128), INIT64(192) +}; +#endif /* Returns true if the 'n' bytes starting at 'p' are zeros. */ bool @@ -1397,7 +1360,7 @@ scan_float(const char *s, const struct scan_spec *spec, va_list *args) case SCAN_INTMAX_T: case SCAN_PTRDIFF_T: case SCAN_SIZE_T: - NOT_REACHED(); + OVS_NOT_REACHED(); } return s; } @@ -1502,7 +1465,7 @@ scan_chars(const char *s, const struct scan_spec *spec, va_list *args) /* This is an implementation of the standard sscanf() function, with the * following exceptions: * - * - It returns true if the entire template was successfully scanned and + * - It returns true if the entire format was successfully scanned and * converted, false if any conversion failed. * * - The standard doesn't define sscanf() behavior when an out-of-range value @@ -1519,15 +1482,15 @@ scan_chars(const char *s, const struct scan_spec *spec, va_list *args) * - %p is not supported. */ bool -ovs_scan(const char *s, const char *template, ...) +ovs_scan(const char *s, const char *format, ...) { const char *const start = s; bool ok = false; const char *p; va_list args; - va_start(args, template); - p = template; + va_start(args, format); + p = format; while (*p != '\0') { struct scan_spec spec; unsigned char c = *p++;