Floating Point + Threads?

Don nospam at nospam.com
Wed Apr 20 05:06:56 PDT 2011


Sean Kelly wrote:
> On Apr 16, 2011, at 1:02 PM, Robert Jacques wrote:
> 
>> On Sat, 16 Apr 2011 15:32:12 -0400, Walter Bright <newshound2 at digitalmars.com> wrote:
>>>
>>> The dmd startup code (actually the C startup code) does an fninit. I never thought about new thread starts. So, yeah, druntime should do an fninit on thread creation.
>> The documentation I've found on fninit seems to indicate it defaults to 64-bit precision, which means that by default we aren't seeing the benefit of D's reals. I'd much prefer 80-bit precision by default.
> 
> There is no option to set "80-bit precision" via the FPU control word.  

??? Yes there is.

enum PrecisionControl : short {
     PRECISION80 = 0x300,
     PRECISION64 = 0x200,
     PRECISION32 = 0x000
};

/** Set the number of bits of precision used by 'real'.
  *
  * Returns: the old precision.
  * This is not supported on all platforms.
  */
PrecisionControl reduceRealPrecision(PrecisionControl prec) {
    version(D_InlineAsm_X86) {
         short cont;
         asm {
             fstcw cont;
             mov CX, cont;
             mov AX, cont;
             and EAX, 0x0300; // Form the return value
             and CX,  0xFCFF;
             or  CX,  prec;
             mov cont, CX;
             fldcw cont;
         }
     } else {
            assert(0, "Not yet supported");
     }
}


More information about the Digitalmars-d mailing list