Search the web
Sign In
New User? Sign Up
compilers101 · Compilers 101
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
I got my intel code generator working!   Message List  
Reply | Forward Message #1317 of 1320 |
Re: [compilers101] I got my intel code generator working!

On Sat, Jun 6, 2009 at 1:01 PM, Neil Bradley <nb@...> wrote:
> Graham, as usual, you are THE MAN. This is really cool! For extra bonus
> points, you should work in register calling conventions. ;-)

When I do a native code generator, I'll do that and throw all the
optimising tricks at it, but as long as I'm treating the x86 as a
simple stack machine, the rest of the generated code is so inefficient
that it is not worth the effort.

But for teaching/demo purposes, I can do quite a few optimisations at
the virtual stack machine level, such as CSE etc.

Here's a trick I learned from the KDF9 guys:

to increment to top of stack: NOT; NEG

to decrement it: NEG; NOT

:-)

relies on 2's complement arithmetic of course, but that's pretty much
a given nowadays.

It's interesting to look at the generated code and see just what most
of the instructions are... pushes and pulls, obviously, but the
remainder being a few adds, and comparisons/branches. You can see how
the RISC guys came to the conclusions they did. Compare this to the
KDF9's instruction set which is CISC in the extreme and you ask
yourself why did they bother?

It'll be interesting to do an encoding of the stack machine as a byte
code and see how small I can make the binaries. (Of course the real
test is combined size of byte code plus interpreter)

G



Sat Jun 6, 2009 8:08 pm

graham_toal
Offline Offline
Send Email Send Email

Forward
Message #1317 of 1320 |
Expand Messages Author Sort by Date

It took about 2 days of programming and 2 days of debugging (one of which was Rainer's :-) ) to get an x86 code generator working for the toy compiler I wrote...
Graham Toal
graham_toal
Offline Send Email
Jun 6, 2009
2:40 pm

... Graham, as usual, you are THE MAN. This is really cool! For extra bonus points, you should work in register calling conventions. ;-) -->Neil ... C. Neil...
Neil Bradley
cneilbradley
Offline Send Email
Jun 6, 2009
6:02 pm

... When I do a native code generator, I'll do that and throw all the optimising tricks at it, but as long as I'm treating the x86 as a simple stack machine,...
Graham Toal
graham_toal
Offline Send Email
Jun 6, 2009
8:10 pm

... next development - I'm using the stack-based code as an intermediate code from which to generate more traditional x86 instructions in a load/store format;...
Graham Toal
graham_toal
Offline Send Email
Jun 11, 2009
7:07 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help