April 04, 2006 8087 precision and _beginthread | ||||
---|---|---|---|---|
| ||||
Hi All Here's a nasty little bug in the runtime library: In the DM C++ startup code, the 80x87 control word is intialized to 0x137F such that arithmetic is performed with 80 bit precision. But when a new thread is started, it is initialized to 0x027F which specifies only 64 bit precision. This is probably a default set by Windows. So the results of floating opertions can differ according to whether they are performed in the main application thread, or in a worker thread!!! The code in thread.c seems to initialize a t->f_env structure, but this isn't the same as actually loading the value in the 80x87 control word; I'm a little loath to modify this code as I don't know exactly the purpose of t->fenv i.e. when it is loaded into the FCPU. Meanwhile you can do WORD newcw 0x137F asm fldcw newcw; at the start of worker threads to correctly initialize them for 80 bit precision. Best Regards John |
Copyright © 1999-2021 by the D Language Foundation