Setting the FPU control word?
Bill Baxter
dnewsgroup at billbaxter.com
Mon Mar 10 18:25:35 PDT 2008
Jarrett Billingsley wrote:
> "Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
> news:fr3k2f$30b5$1 at digitalmars.com...
>> Anyone know how to translate these instructions to D? (specifically
>> DMD/Win flavor of D, but GDC/Win also appreciated if different):
>>
>> http://www.cs.cmu.edu/~quake/robust.pc.html
>>
>> --bb
>
> Would std.c.fenv (or tango.stdc.fenv, same module) be of any use here?
Ah, fsetprec(FE_DOUBLE) does indeed seem to be intended to be the thing.
Except, it doesn't work. The asm fldcw thing does seem to work though.
----
module fpctrl;
import std.c.fenv;
import std.stdio;
enum FPPrecision : short
{
Single = 0x0000,
Double = 0x0200,
Real = 0x0300,
Mask = 0x0300,
}
void setFPControlWord(FPPrecision precision)
{
FPPrecision oldcw;
asm
{
fstcw oldcw;
fwait;
fldcw precision;
}
writefln("oldcw was: 0x%x", oldcw);
}
void main()
{
fesetround(FE_FLTPREC); // should set ctrl word to 0x_2__
setFPControlWord(FPPrecision.Double); // prints 0x_3__, the default
}
--bb
More information about the Digitalmars-d-learn
mailing list