MLton inline assembler etc.?
Anoq of the Sun
anoq@HardcoreProcessing.com
Tue, 27 Feb 2001 16:36:26 +0100
Hello!
I've just been thinking a little - right
now I've got some realtime 3D up and running
on MLton, and the only thing written in
C is the bindings to SDL (to open a Window
and get access to the framebuffer address)
and a write pixel function.
The write pixel function is something like:
#define HcP_WritePixel(address, r, g, b) ...
// Doing some bit-shifting and an assignment to the address.
I guess the reason this is efficient to do is that
MLton generates C-code from the ML source and
that the C-compiler can optimize all the code
at the same time.
Now, if the next version of MLton generates
native assembler, then this advantage might
disappear. So I'm thinking that it might
be a good idea to support inline assember...
Maybe something like:
val f = _primAsm "word inreg ADDRESS \n
int inreg R \n
int inreg G \n
int inreg B \n
... (Do the RGB shifting here)
MOV ADDRESS,RESULT":
word * int * int * int -> unit;
And also with some kind of support for
returning a value (outreg?). Maybe
a different syntax, but anyways...
I guess the only thing required to do it
would be to instruct the register allocator
about the ML function's input and output variables
and to allow for creating temporary
registers which are guaranteed to be unique.
I know that all which would be needed to
do graphics would be a peek and poke
function (which we talked about earlier) -
but having full support for inline assembler
would also allow for all the nasty typecasts
in efficient ways (and the RGB bit-shifting...).
What do you think? :)
Cheers
--
http://www.HardcoreProcessing.com