jserv / amacc

Small C Compiler generating ELF executable Arm architecture, supporting JIT execution
Other
1.01k stars 160 forks source link

Optimize power of 2 literal constant div, mod, mul operators. #69

Closed HPCguy closed 3 years ago

HPCguy commented 3 years ago

Added cool tests. If this goes through, I will work to submit my peephole optimizer for review. It produces amacc code faster than gcc -O0.

HPCguy commented 3 years ago

I can see there is an error trying to deref a Num on line 491, I can't access the failing environment, so need more guidance. No problem seen on my system (Pi 4B).

HPCguy commented 3 years ago

I was finally able to reproduce the failure locally. I can compile just about anything and have it run, but when I try to bootstrap compile amacc.c with the code on this branch, I keep getting the dereference failure. I have tried a number of workarounds and tests, but I'm still unable to trace the source of the failure.

jserv commented 3 years ago

Added cool tests. If this goes through, I will work to submit my peephole optimizer for review. It produces amacc code faster than gcc -O0.

I think this optimization makes sense. Would you continue? Also, how about peephole optimizer? Will it be part of proposed AMaCC change or as a standalone program?

HPCguy commented 3 years ago

Sorry... my github account is not linked to any email account, and I have neglected looking here for a week.

I was thinking of adding a peephole optimizer pull request in a new directory that doesn't touch any amacc code. The directory would be called squint. We can either submit that branch as-is, or create a new branch after we discuss it, since you may want to call the squint code from the JIT compile. I have been thinking about restructuring squint to further shrink/simplify it, and that may take me a week. It generates code faster than gcc -O0 at this point, and will likely generate code that runs a little faster still after my restructuring.

Thank you for your patience, and sorry I haven't looked here.