Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CN: Multiplication overflow check slow #856

Open
lwli11 opened this issue Feb 7, 2025 · 2 comments
Open

CN: Multiplication overflow check slow #856

lwli11 opened this issue Feb 7, 2025 · 2 comments

Comments

@lwli11
Copy link

lwli11 commented Feb 7, 2025

This check against multiplication overflow seems very slow as well. Any ideas how to speed this up?

#include <limits.h>
int test(int a, int b){
        if (a > 0 && b>0 && INT_MAX / b > a){
                return a*b;
        }
        return 0;
}

 

time cn verify mult_overflow.c
[1/1]: test -- pass

real    11m30.198s
@lwli11
Copy link
Author

lwli11 commented Feb 9, 2025

And checking all possible conditions:

real 70m27.931s
user 0m0.197s
sys 0m0.080s

#include <limits.h>
int test(int a, int b){
        if (a==0 || b==0){
                return 0;
        }
        else if (a > 0 && b>0 && INT_MAX / b > a){
                return a*b;
        }
        else if (a>0 && b <0 && b > INT_MIN/a){
                return a*b;
        }
        else if (a<0 && b>0 && a > INT_MIN / b){
                return a*b;
        }
        else if (a<0 && b<0 && b > INT_MAX / a){
                return a*b;
        }
        return 0;
}

@septract
Copy link
Collaborator

These both seem to be sending queries to the solver that it is hanging on for a long time.

The first is a bit quicker with --solver-type=cvc5 - a couple of minutes on my Macbook. The second is very slow with CVC5.

@dc-mak dc-mak changed the title Multiplication overflow check slow CN: Multiplication overflow check slow Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants