From: Ondřej Surý Date: Thu, 12 Oct 2023 07:20:42 +0000 (+0200) Subject: Use mul and div instead of bitshifts to calculate srtt X-Git-Tag: v9.19.18~47^2~1 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=91f3b0edee9873b3f727bc9fc372a362b59480b1;p=thirdparty%2Fbind9.git 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 --- diff --git a/lib/dns/adb.c b/lib/dns/adb.c index a589519f6ee..65904e0f5d6 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;