lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK7LNATg+cnvs9P5Ud6FPAoqQUozrGif5SJm+Pw7cs5qJ1C3gw@mail.gmail.com>
Date:   Mon, 25 Sep 2023 23:24:11 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     Fangrui Song <maskray@...gle.com>
Cc:     Jack Brennen <jbrennen@...gle.com>,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Nicolas Schier <nicolas@...sle.eu>, Tom Rix <trix@...hat.com>,
        linux-kernel@...r.kernel.org, linux-kbuild@...r.kernel.org,
        llvm@...ts.linux.dev
Subject: Re: [PATCH] modpost: Optimize symbol search from linear to binary search

On Mon, Sep 25, 2023 at 7:20 AM Fangrui Song <maskray@...gle.com> wrote:

> However, the `- 1` part in `unsigned int hi = elf->symsearch->table_size - 1;` can be improved.
> I'd prefer an implementation similar to typical C++ https://en.cppreference.com/w/cpp/algorithm/upper_bound implementation.
>
> lo = 0;
> hi = n;  // or replace hi with count
> while (lo < hi) {
>    mid = (lo + hi) / 2;  // we don't care about (lo+hi) overflow
>    if (less_or_eq(&table[mid], &target))
>      lo = mid+1;
>    else
>      hi = mid;
> }
>
> // lo == hi: the index of the first element that is > target
> // if elements equal to target are present, they are on the left of lo


Ah, it is much more elegant!

Thanks.



-- 
Best Regards
Masahiro Yamada

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ