From owner-freebsd-amd64@FreeBSD.ORG Tue Jun 1 23:48:52 2004 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3392216A4CE for ; Tue, 1 Jun 2004 23:48:52 -0700 (PDT) Received: from VARK.homeunix.com (ar59.lsanca2-4.27.98.47.lsanca2.dsl-verizon.net [4.27.98.47]) by mx1.FreeBSD.org (Postfix) with ESMTP id E63BA43D1D for ; Tue, 1 Jun 2004 23:48:51 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Received: from VARK.homeunix.com (localhost [127.0.0.1]) by VARK.homeunix.com (8.12.10/8.12.10) with ESMTP id i526mlkj006232 for ; Tue, 1 Jun 2004 23:48:47 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.homeunix.com (8.12.11/8.12.10/Submit) id i526ml8G006231 for amd64@FreeBSD.ORG; Tue, 1 Jun 2004 23:48:47 -0700 (PDT) (envelope-from das@FreeBSD.ORG) Date: Tue, 1 Jun 2004 23:48:46 -0700 From: David Schultz To: amd64@FreeBSD.ORG Message-ID: <20040602064846.GA6124@VARK.homeunix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: Initial FP exception flags incorrect on amd64 X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jun 2004 06:48:52 -0000 I discovered that new processes on amd64 have the inexact flag raised by default, at least on sledge. However, all the sticky flags should be clear initially. Here is a program that demonstrates the problem: #include int main(int argc, char *argv[]) { int r; __asm("stmxcsr %0" : "=m" (r)); printf("got 0x%02x, expecting 0x00\n", r & 0x3f); } I don't have any amd64 hardware of my own to test kernel patches on, but if I were to make a wild guess as to how to solve the problem, it would be the following patch. I would appreciate it if someone could address the problem, or at least let me know whether my proposed fix works. Index: sys/amd64/amd64/fpu.c =================================================================== RCS file: /cvs/src/sys/amd64/amd64/fpu.c,v retrieving revision 1.149 diff -u -r1.149 fpu.c --- fpu.c 5 Apr 2004 21:25:51 -0000 1.149 +++ fpu.c 2 Jun 2004 06:08:34 -0000 @@ -73,6 +73,7 @@ #define fnstsw(addr) __asm __volatile("fnstsw %0" : "=m" (*(addr))) #define fxrstor(addr) __asm("fxrstor %0" : : "m" (*(addr))) #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) +#define stmxcsr(addr) __asm("stmxcsr %0" : "=m" (*(addr))) #define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \ : : "n" (CR0_TS) : "ax") #define stop_emulating() __asm("clts") @@ -119,6 +120,8 @@ fninit(); control = __INITIAL_FPUCW__; fldcw(&control); + control = __INITIAL_MXCSR__; + stmxcsr(&control); fxsave(&fpu_cleanstate); start_emulating(); fpu_cleanstate_ready = 1;