In this issue 
https://github.com/cloudius-systems/osv/issues/827#issuecomment-271140573 Nadav 
points out that for whatever reason we are NOT initializing FPU control set 
in init_fpu(). I think that by default FNINIT operation does set it to this 
value - *0x037f *- which per this 
(https://sites.uclouvain.be/SystInfo/usr/include/fpu_control.h.html) sets 
double extended precision, nearest rounding control and masks all FPU 
exceptions. 

But I think it would not hurt to set this explicitly (I looked up the 
FreeBSD code which does this). 

diff --git a/arch/x64/processor.hh b/arch/x64/processor.hh
index a26fb028..142742ca 100644
--- a/arch/x64/processor.hh
+++ b/arch/x64/processor.hh
@@ -391,7 +391,9 @@ inline u64 read_xcr(u32 reg)
inline void init_fpu()
{
    asm volatile ("fninit" ::: "memory");
-    unsigned int csr = 0x1f80;
+    u16 cw = 0x037f;
+    asm volatile ("fldcw %0" : : "m" (cw));
+    u32 csr = 0x1f80;
    asm volatile ("ldmxcsr %0" : : "m" (csr));
}


What do you think?

Waldek

PS. The diff above also changes csr type to u32 to make it consistent to 
changes made by this patch 
- 
https://github.com/cloudius-systems/osv/commit/d5cf37af8be57beed4c78c7fa95ac135d96640e8
 
- adding capability for feenableexcept 

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to