From 91f3b0edee9873b3f727bc9fc372a362b59480b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Thu, 12 Oct 2023 09:20:42 +0200 Subject: [PATCH] Use mul and div instead of bitshifts to calculate srtt There was a microoptimization for smoothing srtt with bitshifts. Revert the code to use * 98 / 100, it doesn't really make that difference on modern CPUs, for comparison here: muldiv: imul eax, edi, 98 imul rax, rax, 1374389535 shr rax, 37 ret shift: mov eax, edi sal eax, 9 sub eax, edi shr eax, 9 ret --- lib/dns/adb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/dns/adb.c b/lib/dns/adb.c index a589519f6e..65904e0f5d 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -3052,10 +3052,8 @@ adjustsrtt(dns_adbaddrinfo_t *addr, unsigned int rtt, unsigned int factor, if (factor == DNS_ADB_RTTADJAGE) { if (atomic_load(&addr->entry->lastage) != now) { - new_srtt = addr->entry->srtt; - new_srtt <<= 9; - new_srtt -= addr->entry->srtt; - new_srtt >>= 9; + new_srtt = (uint64_t)atomic_load(&addr->entry->srtt) * + 98 / 100; atomic_store(&addr->entry->lastage, now); atomic_store(&addr->entry->srtt, new_srtt); addr->srtt = new_srtt;