From owner-freebsd-sparc Fri Jan 17 5:29:20 2003 Delivered-To: freebsd-sparc@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1AF1E37B401 for ; Fri, 17 Jan 2003 05:29:18 -0800 (PST) Received: from mail.gmx.net (mail.gmx.net [213.165.65.60]) by mx1.FreeBSD.org (Postfix) with SMTP id 6A62543F3F for ; Fri, 17 Jan 2003 05:29:16 -0800 (PST) (envelope-from tmoestl@gmx.net) Received: (qmail 7869 invoked by uid 0); 17 Jan 2003 13:29:15 -0000 Received: from p508E75C4.dip.t-dialin.net (HELO galatea.local) (80.142.117.196) by mail.gmx.net (mp002-rz3) with SMTP; 17 Jan 2003 13:29:15 -0000 Received: from localhost ([127.0.0.1] helo=galatea.local) by galatea.local with esmtp (Exim 4.12 #1) id 18ZWaO-0000OS-00; Fri, 17 Jan 2003 14:31:05 +0100 Received: (from tmm@localhost) by galatea.local (8.12.6/8.12.6/Submit) id h0HDUtQR001515; Fri, 17 Jan 2003 14:30:55 +0100 (CET) Date: Fri, 17 Jan 2003 14:30:55 +0100 From: Thomas Moestl To: John Polstra Cc: sparc@freebsd.org Subject: Re: Sparc64 floating point questions Message-ID: <20030117133055.GA304@crow.dom2ip.de> Mail-Followup-To: John Polstra , sparc@freebsd.org References: <20030115003013.GA3536@crow.dom2ip.de> <200301150047.h0F0lNFc037477@vashon.polstra.com> <20030115021706.GA5902@crow.dom2ip.de> <200301170216.h0H2G0PZ040597@vashon.polstra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200301170216.h0H2G0PZ040597@vashon.polstra.com> User-Agent: Mutt/1.4i Sender: owner-freebsd-sparc@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Thu, 2003/01/16 at 18:16:00 -0800, John Polstra wrote: > In article <20030115021706.GA5902@crow.dom2ip.de>, > Thomas Moestl wrote: > > > > Oh, I should have mentioned that %fprs is a bit special; the kernel > > uses the FEF bit to test whether floating point support is enabled for > > the process, and will only save the state across context switches in > > that case. It will also lazily restore the context, i.e. it will > > disable the FEF bit and reload the registers only when the process > > uses floating point operations for the next time (which triggers an > > exception in that case). > > That means that %fprs must be restored first, otherwise this might > > clear FEF and cause stale values to be reloaded later. > > In fact, you do not need to save it at all; the only other bits in > > that register are the DU (upper fp register file half dirty) and DL > > (lower half dirty) bits, which are automatically maintained. > > For performance, it would probably be best to always just set the FEF > > bit before reloading the other registers (this is not required > > though), like: > > > > wr %g0, FPRS_FEF, %fprs > > I'm a little bit confused about this. Won't the instruction above > clear the DU and DL bits? Yes. > And isn't that a bad thing to do? It seems like the state > maintained in those bits is per-process rather than per-thread. Since you are going to write to all fp registers anyway, both will get set automatically. These bits are not used by the hardware and exist only to allow software to skip saving unused registers. The kernel does not currently make use of them. However, if it (or a userland thread manager) did, and a switch was to take place before all registers were restored, the missing dirty bits would indicate that the yet unaccessed parts of the registers need not be saved, which does not matter at all since their old values will not be used any more. The kernel itself does never clear DU and DL, so it is possible to use them in user land to skip unnecessary saving (and unneccesary reloading if one of the halves was not accessed at all); in this case it would be necessary to clear the bits explicitely after reloading. Both will however get set currently each time the fp registers are restored after a (kernel) context switch, so this does probably not really pay off. Also, things would break if the kernel started to use them for saving decisions. Setting FEF explicitely before reloading makes sure that a fp state that was saved on a previous context switch and that might not have been restored yet will not be restored due to the following register accesses. Since all registers will be overwritten anyway, this would just eat cycles unnecessarily. - Thomas -- Thomas Moestl http://www.tu-bs.de/~y0015675/ http://people.FreeBSD.org/~tmm/ PGP fingerprint: 1C97 A604 2BD0 E492 51D0 9C0F 1FE6 4F1D 419C 776C To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-sparc" in the body of the message