From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1botSQ-0007Dc-7a for qemu-devel@nongnu.org; Tue, 27 Sep 2016 10:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1botSP-0005dP-7i for qemu-devel@nongnu.org; Tue, 27 Sep 2016 10:34:06 -0400 In-Reply-To: References: <34249C6D-327A-4ED4-BB2D-8E2F532A5720@gmail.com> Mime-Version: 1.0 (Apple Message framework v753.1) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: G 3 Date: Tue, 27 Sep 2016 10:33:46 -0400 Subject: Re: [Qemu-devel] How to add my implementation of the fmadds instruction to QEMU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: "list@suse.de:PowerPC list:PowerPC" , qemu-devel qemu-devel On Sep 27, 2016, at 7:43 AM, Peter Maydell wrote: > On 26 September 2016 at 18:05, G 3 wrote: >> I made my own experimental implementation of the fmadds >> instruction that I >> would like to add to QEMU. How would I do this? >> >> My implementation would probably look like this: >> >> void fmadds(float *frD, float frA, float frC, float frB) >> { >> *frD = frA * frC + frB; >> } > > This isn't portable, because different host CPUs can have > different implementations of floating point arithmetic > with subtle differences (notably in corner cases like > subnormals and also related to the floating point exception > flags). This is why we use the softfloat library in fpu/, > which (although slow) is guaranteed to give the right results. > We did use to have a version of the fpu functions which > used a "just do a C float or double operation", but we > removed it many years ago for this reason. > > In particular, for fmadds, it is important that there > is no intermediate rounding done between the multiply > and the addition. This means that you need to effectively > do the multiply and the addition at a higher precision than > the input arguments, so simple multiplication and addition > of floats will give you wrong answers. It sounds like I should change my argument types to double. I still want to try implementing this function. I'm thinking rewriting the helper_fmadd() function in target-ppc/fpu_helper.c. Does that sound correct?