TM Research Journal

Friday, April 07, 2006

Magic Instructions in Sun

After getting a grasp of how inlining works, I had to figure out how to write the so called "magic" instructions as specified here in Solaris. What this code does is that it left shifts the parameter service by 16 and then loads it into the upper 22 bits of the register g0. Registre g0 is normally a 0 register, but is used by Gems as a signaling register as well when writing to it.

Since in Sun's Inline Templates, code is passed in registers, what I did was left shift the value of register o0 by 26 (16 for the initial shift and 10 for the sethi compensation) and store the result in g0.

sll %o0, 26, %g0

The problem is, in the GCC code, this assembly portion is marked as volatile - which means that the compiler should not attempt to optimise it out (if it deems its unneccessary) nor should it move it around.

When I compiled the code, I tried it with a file along with the -g flag

cc -g -O new_ruby_magic_call.il testil.c

It was supposed to show me whether the code was being late inlined or not (which as I understand it means whether its being optimised or not), but appearantly it's not.

I have posted a question on the Solaris forums (had to create a new account since for some reason I cannot log in using my old one). Hopefully someone will answer.

Unanswered questions which I have asked Kevin (from U Wisconsin) are why register l0 is considered as clobbered even though it's not, and why is a parameter r being passed as 0.

I think these two things might be just code that was kept there from a previous version or something like that.

0 Comments:

Post a Comment

<< Home