]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: time: avoid u64 needlessly expensive computations for the 32-bit now_ms
authorWilly Tarreau <w@1wt.eu>
Fri, 23 Apr 2021 14:04:18 +0000 (16:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Apr 2021 16:03:06 +0000 (18:03 +0200)
The compiler cannot guess that tv_sec or tv_usec might have unused
parts, so the multiply by 1000 and the divide by 1000 are both
performed using 64-bit constants to stick to the common type. This is
not needed since we only keep the final 32 bits, let's help the compiler
here by casting these fields to uint. The tv_update_date() code is much
cleaner (48 bytes smaller in the CAS loop) as it avoids some register
spilling at a location where that's really unwanted.

include/haproxy/time.h

index 0ce06decc0e335c9d2057464b398f5ce4f27ddfa..a556af2a50dcc283e888b40471f60c46a5ed974a 100644 (file)
@@ -140,14 +140,14 @@ static inline struct timeval *tv_zero(struct timeval *tv) {
 #define tv_iszero(tv)           (((tv)->tv_sec | (tv)->tv_usec) == 0)
 
 /*
- * Converts a struct timeval to a number of milliseconds.
+ * Converts a struct timeval to a wrapping number of milliseconds.
  */
-static inline unsigned long __tv_to_ms(const struct timeval *tv)
+static inline uint __tv_to_ms(const struct timeval *tv)
 {
-       unsigned long ret;
+       unsigned int ret;
 
-       ret  = tv->tv_sec * 1000;
-       ret += tv->tv_usec / 1000;
+       ret  = (uint)tv->tv_sec  * 1000;
+       ret += (uint)tv->tv_usec / 1000;
        return ret;
 }