]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use mul and div instead of bitshifts to calculate srtt
authorOndřej Surý <ondrej@isc.org>
Thu, 12 Oct 2023 07:20:42 +0000 (09:20 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 12 Oct 2023 10:35:00 +0000 (12:35 +0200)
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

index a589519f6eec7574368a1a078b93a11123a32f66..65904e0f5d622af6a28fdcf69955a9bcaa91315c 100644 (file)
@@ -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;