[R] Questions about Preserving registers

Duncan Murdoch dmurdoch at pair.com
Sat Jun 12 14:28:35 CEST 2004


On Fri, 11 Jun 2004 10:27:51 +0200, David Lennartsson
<david.lennartsson at saida-med.com> wrote:
> I have not
>bothered to dig deeper and I have no idea of how to get and set the FPU 
>control word in the wrapper. Is there
>a compiler macro or does it have to be done with assembler?

Which compiler are you using?  The minGW gcc has a function
_controlfp() to get and set the control word.  Here's the code that R
uses to check for changes during a DLL load and fix them.

Here is the function R uses to set things up in the first place:

void Rwin_fpset()
{
    _fpreset();
    _controlfp(_MCW_EM, _MCW_EM);
    _controlfp(_PC_64, _MCW_PC);
}

And here is the code R  uses to preserve the control word across a DLL
load:

rcw = _controlfp(0,0) & ~_MCW_IC;  /* Infinity control is ignored */
_clearfp();
tdlh = LoadLibrary(path);
dllcw = _controlfp(0,0) & ~_MCW_IC;
if (dllcw != rcw) {
    _controlfp(rcw, _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC);
    ...

Duncan Murdoch




More information about the R-help mailing list