Skip to content

Implement gcc integer overflow builtins. #4701

Closed

Description

@danielsn

Now that we have the overflow primitives, it would make sense to implement all the gcc builtins https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html

Activity

  1. added
    aws
    on Nov 15, 2019
  2. danielsn commented on Nov 15, 2019

    @danielsn
    ContributorAuthor

    @tautschnig may have solved this already; if so, feel free to close the ticket

  3. danielsn commented on Feb 6, 2020

    @danielsn
    ContributorAuthor

    Note: the current overflow primitives lead to a significant performance cost when used in the naïve way, since they require the user to do a multiplication, keep the overflow bit but throw away the result, and do it again to get the result. Fixing this would help performance.

  4. martin-cs commented on Feb 6, 2020

    @martin-cs
    Collaborator

    Maybe. In some cases the back-end will cache the two things back together. More importantly though, there are way better encodings of multiply overflow check than doing the full multiply.

  5. hannes-steffenhagen-diffblue commented on Feb 7, 2020

    @hannes-steffenhagen-diffblue
    Contributor

    @martin-cs What are the way better encodings for multiply overflow check?

  6. martin-cs commented on Feb 7, 2020

    @martin-cs
    Collaborator

    @hannes-steffenhagen-diffblue Somewhere there is a Z3 paper from ... '09 or so with a more compact encoding but, as it's Friday, let's see what we can do in a comment.

    First do the unsigned case as it's easier. Assume bit-vectors are length n. Consider the easy cases first:
    *. If either x or y is 1 or 0 then it trivially it doesn't overflow.
    *. If both are under sqrt(2^n - 1) then it trivially doesn't overflow. This is just a simple bit test and removes a number of bits from consideration outright.
    *. Consider the ith and jth bits of x and y (apart from the ones above) with i + j >= n if they are both 1 then it overflows. This removes a maybe half of the partial product terms.
    *. You can sum all of the remaining bits in the usual way but I think we can do better than that. I'd start building a tree (well, DAG, so cache) of ways that top bit can overflow. Either of it is a 1 and one of the lower log(n) bits carry a 1 up to it's position or it is a 0 and 2 or more of the lower log(n) bits carry up a 1 ... apply this recursively and you have a tree. This could probably be built stepwise as a refinement for the best encoding as I suspect it is rarely needed.

    @danielsn / @hannes-steffenhagen-diffblue If either of you have interest and a set of real-world performance critical benchmarks that depend on this I can try to turn this into code and / or talk one of you through doing it.

  7. danpoe commented on Jul 1, 2020

    @danpoe
    Contributor

    @danielsn The primitives have been implemented in PRs #5233, #5235, #5236, #5249 which have all been merged. What could still be done is implement some of the ideas for speeding up the checks. I would suggest we close this ticket here, and if the performance improvements are still required we can create a separate issue/ticket.

  8. danielsn commented on Jul 2, 2020

    @danielsn
    ContributorAuthor
  9. danpoe commented on Jul 2, 2020

    @danpoe
    Contributor

    Issue for the performance improvements: #5405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    aws

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions