Sven Panne writes:
> During some experiments with GreenCard I stumbled across a serious
> restriction in GHC. Here a short example (an small part of a program
> generated by GreenCard):
> 
> --------------------------------------------------------------
> module Foo where
> bar :: Double -> Double -> Double -> IO ()
> bar a0 a1 a2 = _casm_GC_ ``bar(%0,%1,%2);'' a0 a1 a2
> --------------------------------------------------------------
> 
>    panne@liesl: > ghc-3.01 -c -fglasgow-exts Foo.hs
> 
>    panic! (the `impossible' happened):
>            Cannot allocate enough registers for primop ..
> 
>
> \begin{code}
> #define MAX_VANILLA_REG 8
> #define MAX_FLOAT_REG 4
> #define MAX_DOUBLE_REG 2
> \end{code}
> ...
> 
> The questions are: Why are these constants so small? Can GhcConstants.lh
> simply be edited to give the STG machine more registers? I really wish
> it would be that easy!

No, afraid not - those constants are only used to tell the code
generator how many registers the RTS implements. You'll also need to
modify various RTS structures plus define mappings for the new
registers & update the call wrappers.  (I'm sure there's more to it
than that; I've never tried to tweak this.)

Do you really need to use _casm_GC_? If you do, then what about
just hacking up something like this:

bar :: Double -> Double -> Double -> IO ()
bar a0 a1 a2 = do
   _casm_ `` arg = %0; arg1=%1; arg2=%2; '' a0 a1 a2
   _casm_GC_ ``bar(arg0,arg1,arg2);''

where arg0,...,arg2 are global vars. Not a beauty contest contender,
but it'll do the job.

--Sigbjorn

Reply via email to