Skip to content

Commit

Permalink
x86_64 FPU: Set 64-bit precision for fadd/fsub/fsqrt etc.
Browse files Browse the repository at this point in the history
On AMD64, GCC and the ABI expects the x87 unit to be running in 80/64
mode rather than 64/53 mode seen on i386.  This corrects errors seen
in long double tests involving runtime calculations.  Previously, the
results of these runtime calculations would get rounded due to use
of 53-bit mantissas.
  • Loading branch information
John Marino authored and jrmarino committed Jul 14, 2012
1 parent b4ff333 commit 4e1f876
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sys/platform/pc64/x86_64/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ exec_setregs(u_long entry, u_long stack, u_long ps_strings)
wrmsr(MSR_KGSBASE, 0);

/* Initialize the npx (if any) for the current process. */
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);
crit_exit();

pcb->pcb_ds = _udatasel;
Expand Down
2 changes: 1 addition & 1 deletion sys/platform/pc64/x86_64/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ init_secondary(void)
initializecpu();

/* set up FPU state on the AP */
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);

/* disable the APIC, just to be SURE */
lapic->svr &= ~APIC_SVR_ENABLE;
Expand Down
2 changes: 1 addition & 1 deletion sys/platform/pc64/x86_64/npx.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ npxdna(void)
crit_enter();
if ((td->td_flags & (TDF_USINGFP | TDF_KERNELFP)) == 0) {
td->td_flags |= TDF_USINGFP;
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);
didinit = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion sys/platform/vkernel64/x86_64/cpu_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ exec_setregs(u_long entry, u_long stack, u_long ps_strings)
pcb->pcb_fsbase = 0; /* Values loaded from PCB on switch */
pcb->pcb_gsbase = 0;
/* Initialize the npx (if any) for the current process. */
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);
crit_exit();

/*
Expand Down
4 changes: 2 additions & 2 deletions sys/platform/vkernel64/x86_64/npx.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
int
npx_attach(device_t dev)
{
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);
return (0);
}
#endif
Expand Down Expand Up @@ -357,7 +357,7 @@ npxdna(struct trapframe *frame)
*/
if ((curthread->td_flags & TDF_USINGFP) == 0) {
curthread->td_flags |= TDF_USINGFP;
npxinit(__INITIAL_NPXCW__);
npxinit(__INITIAL_FPUCW__);
didinit = 1;
}

Expand Down

0 comments on commit 4e1f876

Please sign in to comment.