Setting the FPU control word?
Don Clugston
dac at nospam.com.au
Wed Mar 12 09:04:20 PDT 2008
Bill Baxter wrote:
> 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
I've got something similar in tango.math.IEEE.
reduceRealPrecision()
setIeeeRounding()
ieeeFlags();
Mostly only works for x86 (no inline asm yet for other CPUs?)
More information about the Digitalmars-d-learn
mailing list