Skip to content

There exists significantly faster division algorithms for certain CPUs #265

Closed
@AaronKutch

Description

@AaronKutch

Over the past few months I have been looking at different division algorithms, and I believe that this one is the fastest for 128 bit division on CPUs with a fast 64 bit hardware divider. I made a crate for it, specialized-div-rem. I initially thought that the crate would have more than one algorithm in it, but it turns out that the compiler likes inlining the appropriate branches in cases where its important.
The only thing I might add to it is a simple binary division algorithm for when the most significant bits of the dividend and divisor are <6 bits from each other and located in the higher 64 bits. I don't know if it is worth it to have more conditional branches for that use case, I think this algorithm has the fewest branches encountered by program flow of any algorithm out there.
I also expect that the 64 bit division algorithm in that crate is useful for 32 bit computers but I don't have one to test it out.
Sidenote that I also made a more general version for the apint crate but I need to put much more recursive work into that one before it becomes competitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions