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

Modulo (operator%) does not give correct result #61

Closed
silverscampi opened this issue Aug 1, 2020 · 2 comments · Fixed by #62
Closed

Modulo (operator%) does not give correct result #61

silverscampi opened this issue Aug 1, 2020 · 2 comments · Fixed by #62
Assignees

Comments

@silverscampi
Copy link

silverscampi commented Aug 1, 2020

I noticed in a larger program that I compiled JIT with amacc, which relies on modulo for prng, that the results were wrong. So I made a small test program, and tried a freshly cloned amacc on it - as you can see below the results are completely wrong.

(Here is a hacky fix for now, which requires the use of mod(a, b) instead of a % b - it gives the correct results for the shown small test program)

$ git clone git@github.com:jserv/amacc.git
Cloning into 'amacc'...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (71/71), done.
remote: Compressing objects: 100% (51/51), done.
remote: Total 734 (delta 33), reused 52 (delta 19), pack-reused 663
Receiving objects: 100% (734/734), 297.06 KiB | 1.18 MiB/s, done.
Resolving deltas: 100% (411/411), done.
$ cd amacc/
$ make
  CC+LD		amacc
  CC+LD		amacc-native
amacc.c:2107:5: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 int main(int argc, char **argv)
     ^~~~
amacc.c:2107:5: warning: first argument of ‘main’ should be ‘int’ [-Wmain]
$ ./amacc ~/tmp/modtest.c 
39628
1015073
3
2
$ more ~/tmp/modtest.c 
int main() {
	int a = 2131119850;
	int b = 53777;
	printf("%d\n", (a % b));

	int c = 841495917;
	int d = 829;
	printf("%d\n", (c % d));

	int e = 100;
	int f = 26;
	printf("%d\n", e % f);

	int g = 2;
	int h = 1;
	printf("%d\n", g % h);

	return 0;
}

@jserv
Copy link
Owner

jserv commented Aug 1, 2020

@lecopzer, can you help verify and resolve EABI specific modulo operation?

@lecopzer
Copy link
Contributor

lecopzer commented Aug 3, 2020

OK, I need some time to figure out this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants